MTB CAT1 Peripheral driver library

General Description

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:

The PWM has the following features:

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

/* Scenario: there is need to initialize
* the first (index = 0) PWM of the TCPWM0 block
* with the below configuration settings
*/
cy_stc_tcpwm_pwm_config_t tcpwm_v1_pwm_config =
{
/* .pwmMode = */ CY_TCPWM_PWM_MODE_PWM, /* Simple PWM Mode */
/* .clockPrescaler = */ CY_TCPWM_PWM_PRESCALER_DIVBY_4, /* Clk_counter = Clk_input / 4 */
/* .pwmAlignment = */ CY_TCPWM_PWM_LEFT_ALIGN, /* PWM signal is left aligned, meaning it starts high */
/* .deadTimeClocks = */ 0UL, /* dead time feature is disabled */
/* .runMode = */ CY_TCPWM_PWM_CONTINUOUS, /* Wrap around at terminal count. */
/* .period0 = */ 99UL, /* Period of 100 (0-99). Terminal count event when rolls over back to 0. */
/* .period1 = */ 199UL, /* Period of 200 (0-199). Terminal count event when rolls over back to 0. */
/* .enablePeriodSwap = */ true, /* period swapping feature is enabled */
/* .compare0 = */ 33UL, /* duty cycle 33% (with period 100) */
/* .compare1 = */ 66UL, /* duty cycle 33% (with period 200) */
/* .enableCompareSwap = */ true, /* compare swapping feature is enabled */
/* .interruptSources = */ CY_TCPWM_INT_ON_TC, /* interrupt will rise on terminal count */
/* .invertPWMOut = */ 0UL, /* Not invert */
/* .invertPWMOutN = */ 0UL, /* Not invert */
/* .killMode = */ CY_TCPWM_PWM_STOP_ON_KILL, /* PWM stops counting on kill */
/* .swapInputMode = */ CY_TCPWM_INPUT_RISINGEDGE, /* This input is NOT used, leave it in default state (CY_TCPWM_INPUT_RISINGEDGE = 0UL) */
/* .swapInput = */ CY_TCPWM_INPUT_0,
/* .reloadInputMode = */ CY_TCPWM_INPUT_RISINGEDGE, /* This input is NOT used, leave it in default state (CY_TCPWM_INPUT_RISINGEDGE = 0UL) */
/* .reloadInput = */ CY_TCPWM_INPUT_0,
/* .startInputMode = */ CY_TCPWM_INPUT_RISINGEDGE, /* This input is NOT used, leave it in default state (CY_TCPWM_INPUT_RISINGEDGE = 0UL) */
/* .startInput = */ CY_TCPWM_INPUT_0,
/* .killInputMode = */ CY_TCPWM_INPUT_RISINGEDGE, /* This input is NOT used, leave it in default state (CY_TCPWM_INPUT_RISINGEDGE = 0UL) */
/* .killInput = */ CY_TCPWM_INPUT_0,
/* .countInputMode = */ CY_TCPWM_INPUT_LEVEL, /* Set this input to LEVEL and 1 (high logic level) */
/* .countInput = */ CY_TCPWM_INPUT_1, /* So the PWM will be enabled forever */
/* .swapOverflowUnderflow = */ false, /* Use default overflow/underflow behavior */
};
#define MY_TCPWM_PWM_NUM (0UL)
#define MY_TCPWM_PWM_MASK (1UL << MY_TCPWM_PWM_NUM)
if (CY_TCPWM_SUCCESS != Cy_TCPWM_PWM_Init(TCPWM0, MY_TCPWM_PWM_NUM, &tcpwm_v1_pwm_config))
{
/* Handle possible errors */
}
/* Enable the initialized PWM */
Cy_TCPWM_PWM_Enable(TCPWM0, MY_TCPWM_PWM_NUM);
/* Then start the PWM */
Cy_TCPWM_TriggerStart_Single(TCPWM0, MY_TCPWM_PWM_NUM);

For TCPWM V2 Configuration

/* Scenario: there is need to initialize
* the first (index = 0) PWM of the TCPWM0 block
* with the below configuration settings
*/
cy_stc_tcpwm_pwm_config_t tcpwm_v2_pwm_config =
{
/* .pwmMode = */ CY_TCPWM_PWM_MODE_PWM, /* Simple PWM Mode */
/* .clockPrescaler = */ CY_TCPWM_PWM_PRESCALER_DIVBY_4, /* Clk_counter = Clk_input / 4 */
/* .pwmAlignment = */ CY_TCPWM_PWM_LEFT_ALIGN, /* PWM signal is left aligned, meaning it starts high */
/* .deadTimeClocks = */ 0UL, /* dead time feature is disabled */
/* .runMode = */ CY_TCPWM_PWM_CONTINUOUS, /* Wrap around at terminal count. */
/* .period0 = */ 99UL, /* Period of 100 (0-99). Terminal count event when rolls over back to 0. */
/* .period1 = */ 199UL, /* Period of 200 (0-199). Terminal count event when rolls over back to 0. */
/* .enablePeriodSwap = */ true, /* period swapping feature is enabled */
/* .compare0 = */ 33UL, /* duty cycle 33% (with period 100) */
/* .compare1 = */ 66UL, /* duty cycle 33% (with period 200) */
/* .enableCompareSwap = */ true, /* compare swapping feature is enabled */
/* .interruptSources = */ CY_TCPWM_INT_ON_TC, /* interrupt will rise on terminal count */
/* .invertPWMOut = */ 0UL, /* Not invert */
/* .invertPWMOutN = */ 0UL, /* Not invert */
/* .killMode = */ CY_TCPWM_PWM_STOP_ON_KILL, /* PWM stops counting on kill */
/* .swapInputMode = */ CY_TCPWM_INPUT_RISINGEDGE, /* This input is NOT used, leave it in default state (CY_TCPWM_INPUT_RISINGEDGE = 0UL) */
/* .swapInput = */ CY_TCPWM_INPUT_0,
/* .reloadInputMode = */ CY_TCPWM_INPUT_RISINGEDGE, /* This input is NOT used, leave it in default state (CY_TCPWM_INPUT_RISINGEDGE = 0UL) */
/* .reloadInput = */ CY_TCPWM_INPUT_0,
/* .startInputMode = */ CY_TCPWM_INPUT_RISINGEDGE, /* This input is NOT used, leave it in default state (CY_TCPWM_INPUT_RISINGEDGE = 0UL) */
/* .startInput = */ CY_TCPWM_INPUT_0,
/* .killInputMode = */ CY_TCPWM_INPUT_RISINGEDGE, /* This input is NOT used, leave it in default state (CY_TCPWM_INPUT_RISINGEDGE = 0UL) */
/* .killInput = */ CY_TCPWM_INPUT_0,
/* .countInputMode = */ CY_TCPWM_INPUT_LEVEL, /* Set this input to LEVEL and 1 (high logic level) */
/* .countInput = */ CY_TCPWM_INPUT_1, /* So the PWM will be enabled forever */
/* .swapOverflowUnderflow = */ false, /* Use default overflow/underflow behavior */
/* .immediateKill = */ false, /* Specifies whether the kill event immediately deactivates the dt_line_out and dt_line_compl_out or with the next module clock */
/* .tapsEnabled = */ 0x00UL, /* In pseudo random mode this sets the enabled taps.*/
/* .compare2 = */ 33UL, /* duty cycle 33% (with period 100) */
/* .compare3 = */ 66UL, /* duty cycle 33% (with period 200) */
/* .enableCompare1Swap = */ true, /* Not implemented yet*/
/* .compare0MatchUp = */ true, /* Not implemented yet*/
/* .compare0MatchDown = */ true, /* Not implemented yet*/
/* .compare1MatchUp = */ true, /* Not implemented yet*/
/* .compare1MatchDown = */ true, /* Not implemented yet*/
/* .kill1InputMode = */ CY_TCPWM_INPUT_RISINGEDGE, /* This input is NOT used, leave it in default s tate (CY_TCPWM_INPUT_RISINGEDGE = 0UL) */
/* .kill1Input = */ CY_TCPWM_INPUT_0,
/* .pwmOnDisable = */ CY_TCPWM_PWM_OUTPUT_HIGHZ, /* Default High impedance mode*/
/* .trigger0Event = */ CY_TCPWM_CNT_TRIGGER_ON_DISABLED, /* Disable output trigger0 event generation*/
/* .trigger1Event = */ CY_TCPWM_CNT_TRIGGER_ON_DISABLED, /* Disable output trigger1 event generation*/
/* .reloadLineSelect = */ true, /* Configures how the reload line select */
/* line_out_sel = */ CY_TCPWM_OUTPUT_CONSTANT_0,
/* linecompl_out_sel = */ CY_TCPWM_OUTPUT_CONSTANT_0,
/* line_out_sel_buff = */ CY_TCPWM_OUTPUT_CONSTANT_0,
/* linecompl_out_sel_buff = */ CY_TCPWM_OUTPUT_CONSTANT_0,
/* deadTimeClocks_linecompl_out = */ 5U,
};
#define MY_TCPWM_PWM_NUM (0UL)
#define MY_TCPWM_PWM_MASK (1UL << MY_TCPWM_PWM_NUM)
if (CY_TCPWM_SUCCESS != Cy_TCPWM_PWM_Init(TCPWM0, MY_TCPWM_PWM_NUM, &tcpwm_v2_pwm_config))
{
/* Handle possible errors */
}
/* Enable the initialized PWM */
Cy_TCPWM_PWM_Enable(TCPWM0, MY_TCPWM_PWM_NUM);
/* Then start the PWM */
Cy_TCPWM_TriggerStart_Single(TCPWM0, 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

/* Scenario: Enable PWM */
#define MY_TCPWM_PWM_NUM (0UL)
Cy_TCPWM_PWM_Enable(TCPWM0, MY_TCPWM_PWM_NUM);

Start PWM

PWM has to be started

/* Scenario: Start PWM operation */
#define MY_TCPWM_PWM_NUM (0UL)
Cy_TCPWM_TriggerStart_Single(TCPWM0, MY_TCPWM_PWM_NUM);

API Reference

 Macros
 
 Functions
 
 Data Structures