Driver API for PWM.
The functions and other declarations used in this part of the driver are in cy_tcpwm_pwm.h. You can also include cy_pdl.h to get access to all functions and declarations in the PDL.
Use PWM mode when an output square wave is needed with a specific period and duty cycle, such as:
- Creating arbitrary square wave outputs
- Driving an LED (changing the brightness)
- Driving Motors (dead time assertion available)
The PWM has the following features:
- 16- or 32-bit Counter.
- Two Programmable Period registers that can be swapped.
- Two Output Compare registers that can be swapped on overflow and/or underflow.
- Left Aligned, Right Aligned, Center Aligned, and Asymmetric Aligned modes
- Continuous or One Shot run modes.
- Pseudo Random mode.
- Two PWM outputs with Dead Time insertion, and programmable polarity.
- Interrupt on Terminal Count and Compare or Capture 0. Interrupt on Compare or Capture 1 is only available in TCPWM Version 2.
- Start, Reload, Stop, Swap (Capture), and Count Inputs.
- Immediate Kill, Kill 0 Input, Kill 1 Input, PWM output on Disable, PWM outputs, PWM Dead Time Clocks, Taps Enabled. All these features are only available in TCPWM Version 2.
- Multiple Components can be synchronized together for applications. such as three phase motor control.
- Two programmable trigger outputs, trig_out0 and trig_out1 that generate a trigger on one of the following events Overflow, Underflow, Terminal Count, Compare Match 0/1, and PWM output. The available triggers are dependent on the PWM mode. All these features are only available in TCPWM Version 2.
- Overflow, Underflow, and Compare(cc_match) trigger outputs are only available in TCPWM Version 1.
- Second Compare Match (CC_MATCH1) event is only available in TCPWM Version 2.
Configuration Considerations
The PWM configuration can be divided to number of sequential steps listed below:
Configure PWM
To configure PWM, provide the configuration parameters in the cy_stc_tcpwm_pwm_config_t structure. The Configuration structure can be modified through software, but if the configurator in ModusToolbox is used then the configuration structure will be updated with the users input. To initialize the driver, call Cy_TCPWM_PWM_Init function providing a pointer to the populated cy_stc_tcpwm_pwm_config_t structure.
For TCPWM V1 Configuration
{
0UL,
99UL,
199UL,
true,
33UL,
66UL,
true,
0UL,
0UL,
false,
};
#define MY_TCPWM_PWM_NUM (0UL)
#define MY_TCPWM_PWM_MASK (1UL << MY_TCPWM_PWM_NUM)
{
}
For TCPWM V2 Configuration
{
0UL,
99UL,
199UL,
true,
33UL,
66UL,
true,
0UL,
0UL,
false,
false,
0x00UL,
33UL,
66UL,
true,
true,
true,
true,
true,
true,
5U,
};
#define MY_TCPWM_PWM_NUM (0UL)
#define MY_TCPWM_PWM_MASK (1UL << MY_TCPWM_PWM_NUM)
{
}
Assign Clock Divider
The clock source must be connected to proper working. Any of the peripheral clock dividers could be used. Use the SysClk (System Clock) driver API to do that.
Enable PWM
PWM has to be enabled before starting
#define MY_TCPWM_PWM_NUM (0UL)
Start PWM
PWM has to be started
#define MY_TCPWM_PWM_NUM (0UL)