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)
{
}
PWM configuration structure.
Definition: cy_tcpwm_pwm.h:181
@ CY_TCPWM_SUCCESS
Successful.
Definition: cy_tcpwm.h:399
__STATIC_INLINE void Cy_TCPWM_TriggerStart_Single(TCPWM_Type *base, uint32_t cntNum)
Triggers a software start on the selected TCPWM.
Definition: cy_tcpwm.h:888
cy_en_tcpwm_status_t Cy_TCPWM_PWM_Init(TCPWM_Type *base, uint32_t cntNum, cy_stc_tcpwm_pwm_config_t const *config)
Initializes the counter in the TCPWM block for the PWM operation.
Definition: cy_tcpwm_pwm.c:76
__STATIC_INLINE void Cy_TCPWM_PWM_Enable(TCPWM_Type *base, uint32_t cntNum)
Enables the counter in the TCPWM block for the PWM operation.
Definition: cy_tcpwm_pwm.h:519
#define CY_TCPWM_INT_ON_TC
Interrupt on Terminal count(TC)
Definition: cy_tcpwm.h:303
#define CY_TCPWM_PWM_LEFT_ALIGN
PWM is left aligned, meaning it starts high.
Definition: cy_tcpwm_pwm.h:283
#define CY_TCPWM_PWM_PRESCALER_DIVBY_4
Divide by 4.
Definition: cy_tcpwm_pwm.h:326
#define CY_TCPWM_PWM_STOP_ON_KILL
PWM stops counting on kill.
Definition: cy_tcpwm_pwm.h:297
#define CY_TCPWM_PWM_MODE_PWM
Standard PWM Mode.
Definition: cy_tcpwm_pwm.h:274
#define CY_TCPWM_PWM_CONTINUOUS
Counter runs forever.
Definition: cy_tcpwm_pwm.h:267
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)
{
}
@ CY_TCPWM_OUTPUT_CONSTANT_0
Output signal is 0.
Definition: cy_tcpwm_pwm.h:170
#define CY_TCPWM_CNT_TRIGGER_ON_DISABLED
Output trigger disabled.
Definition: cy_tcpwm.h:294
#define CY_TCPWM_PWM_OUTPUT_HIGHZ
PWM output (default) high impedance.
Definition: cy_tcpwm_pwm.h:306
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)