Functions

group group_tcpwm_functions_pwm

Functions

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.

Return

error / status code. See cy_en_tcpwm_status_t.

Function Usage

    /* 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_TriggerReloadOrIndex_Single(TCPWM0, MY_TCPWM_PWM_MASK);
    /* 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*/
    };

    #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_TriggerReloadOrIndex_Single(TCPWM0, MY_TCPWM_PWM_MASK);

Parameters
  • base: The pointer to a TCPWM instance.

  • cntNum: The Counter instance number in the selected TCPWM.

  • config: The pointer to a configuration structure. See cy_stc_tcpwm_pwm_config_t.

void Cy_TCPWM_PWM_DeInit(TCPWM_Type *base, uint32_t cntNum, cy_stc_tcpwm_pwm_config_t const *config)

De-initializes the counter in the TCPWM block, returns register values to default.

Function Usage

    /* Scenario: there is need to deinitialize the previously initialized counter */
    #define MY_TCPWM_PWM_NUM   (0UL)

    /* Disable the counter prior to deinitializing */
    Cy_TCPWM_PWM_Disable(TCPWM0, MY_TCPWM_PWM_NUM);
    Cy_TCPWM_PWM_DeInit(TCPWM0, MY_TCPWM_PWM_NUM, &config);

Parameters
  • base: The pointer to a TCPWM instance.

  • cntNum: The Counter instance number in the selected TCPWM.

  • config: The pointer to a configuration structure. See cy_stc_tcpwm_pwm_config_t.

__STATIC_INLINE void Cy_TCPWM_PWM_Enable (TCPWM_Type *base, uint32_t cntNum)

Enables the counter in the TCPWM block for the PWM operation.

Function Usage

    /* 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_TriggerReloadOrIndex_Single(TCPWM0, MY_TCPWM_PWM_MASK);
    /* 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*/
    };

    #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_TriggerReloadOrIndex_Single(TCPWM0, MY_TCPWM_PWM_MASK);

Parameters
  • base: The pointer to a TCPWM instance.

  • cntNum: The Counter instance number in the selected TCPWM.

__STATIC_INLINE void Cy_TCPWM_PWM_Disable (TCPWM_Type *base, uint32_t cntNum)

Disables the counter in the TCPWM block.

Function Usage

    /* Scenario: there is need to deinitialize the previously initialized counter */
    #define MY_TCPWM_PWM_NUM   (0UL)

    /* Disable the counter prior to deinitializing */
    Cy_TCPWM_PWM_Disable(TCPWM0, MY_TCPWM_PWM_NUM);
    Cy_TCPWM_PWM_DeInit(TCPWM0, MY_TCPWM_PWM_NUM, &config);

Parameters
  • base: The pointer to a TCPWM instance.

  • cntNum: The Counter instance number in the selected TCPWM.

__STATIC_INLINE uint32_t Cy_TCPWM_PWM_GetStatus (TCPWM_Type const *base, uint32_t cntNum)

Returns the status of the PWM whether it is running or not.

In case the PWM is running, status will also provide information on counting up/down. This is useful when the PWM Alignment mode set to Center/Asymmetric Alignments.

Return

The status. See PWM Status

Function Usage

    /* Scenario: there is a need to check if
     * the first (index = 0) counter of the TCPWM0 block is running or not.
     */
    #define MY_TCPWM_PWM_NUM   (0UL)

    uint32_t status = Cy_TCPWM_PWM_GetStatus(TCPWM0, MY_TCPWM_CNT_NUM);

    if ((CY_TCPWM_PWM_STATUS_COUNTER_RUNNING & status) && (CY_TCPWM_PWM_STATUS_UP_COUNTING & status))
    {
        /* Up Counting */
    }
    else if ((CY_TCPWM_PWM_STATUS_COUNTER_RUNNING & status) && (CY_TCPWM_PWM_STATUS_DOWN_COUNTING & status))
    {
        /* Down Counting */
    }
    else
    {
        /* PWM is not running */
    }

Parameters
  • base: The pointer to a TCPWM instance.

  • cntNum: The Counter instance number in the selected TCPWM.

__STATIC_INLINE void Cy_TCPWM_PWM_SetCompare0Val (TCPWM_Type *base, uint32_t cntNum, uint32_t compare0)

Sets the compare value for Compare 0 when the compare mode enabled.

Function Usage

    /* Scenario: there is a need to increment the Compare 0 value of
     * the first (index = 0) PWM of the TCPWM0 block.
     */
    #define MY_TCPWM_PWM_NUM   (0UL)

    /* Get the currently existing compare value */
    uint32_t compare = Cy_TCPWM_PWM_GetCompare0Val(TCPWM0, MY_TCPWM_PWM_NUM);
    /* Modify the compare value here */
    Cy_TCPWM_PWM_SetCompare0Val(TCPWM0, MY_TCPWM_PWM_NUM, compare);

Parameters
  • base: The pointer to a TCPWM instance.

  • cntNum: The Counter instance number in the selected TCPWM.

  • compare0: The Compare 0 value.

__STATIC_INLINE uint32_t Cy_TCPWM_PWM_GetCompare0Val (TCPWM_Type const *base, uint32_t cntNum)

Returns compare 0 value.

Return

Compare 0 value.

Function Usage

    /* Scenario: there is a need to increment the Compare 0 value of
     * the first (index = 0) PWM of the TCPWM0 block.
     */
    #define MY_TCPWM_PWM_NUM   (0UL)

    /* Get the currently existing compare value */
    uint32_t compare = Cy_TCPWM_PWM_GetCompare0Val(TCPWM0, MY_TCPWM_PWM_NUM);
    /* Modify the compare value here */
    Cy_TCPWM_PWM_SetCompare0Val(TCPWM0, MY_TCPWM_PWM_NUM, compare);

Parameters
  • base: The pointer to a TCPWM instance.

  • cntNum: The Counter instance number in the selected TCPWM.

__STATIC_INLINE void Cy_TCPWM_PWM_SetCompare0BufVal (TCPWM_Type *base, uint32_t cntNum, uint32_t compareBuf0)

Sets the buffered compare value for Compare 0 when the compare mode enabled.

Function Usage

    /* Scenario: there is a need to modify the alternative compare value
     * (Compare 1) for the first (index = 0) counter of the TCPWM0 block.
     * Note: the compare swapping feature should be enabled.
     * This can be used to change the compare value on the fly without a
     * modification of the compare value itself.
     */
    #define MY_TCPWM_PWM_NUM   (0UL)

    /* Get the currently existing compare value */
    uint32_t compare = Cy_TCPWM_PWM_GetCompare0BufVal(TCPWM0, MY_TCPWM_PWM_NUM);
    /* Modify the compare value here */
    Cy_TCPWM_PWM_SetCompare0BufVal(TCPWM0, MY_TCPWM_PWM_NUM, compare);
    /* Now the compare 0 and 1 values can be swapped using either HW input or Cy_TCPWM_TriggerCaptureOrSwap_Single */

Parameters
  • base: The pointer to a TCPWM instance.

  • cntNum: The Counter instance number in the selected TCPWM.

  • compareBuf0: The buffered Compare 0 value.

__STATIC_INLINE uint32_t Cy_TCPWM_PWM_GetCompare0BufVal (TCPWM_Type const *base, uint32_t cntNum)

Returns the buffered compare 0 value.

Return

Buffered compare 0 value.

Function Usage

    /* Scenario: there is a need to modify the alternative compare value
     * (Compare 1) for the first (index = 0) counter of the TCPWM0 block.
     * Note: the compare swapping feature should be enabled.
     * This can be used to change the compare value on the fly without a
     * modification of the compare value itself.
     */
    #define MY_TCPWM_PWM_NUM   (0UL)

    /* Get the currently existing compare value */
    uint32_t compare = Cy_TCPWM_PWM_GetCompare0BufVal(TCPWM0, MY_TCPWM_PWM_NUM);
    /* Modify the compare value here */
    Cy_TCPWM_PWM_SetCompare0BufVal(TCPWM0, MY_TCPWM_PWM_NUM, compare);
    /* Now the compare 0 and 1 values can be swapped using either HW input or Cy_TCPWM_TriggerCaptureOrSwap_Single */

Parameters
  • base: The pointer to a TCPWM instance.

  • cntNum: The Counter instance number in the selected TCPWM.

__STATIC_INLINE void Cy_TCPWM_PWM_EnableCompare0Swap (TCPWM_Type *base, uint32_t cntNum, bool enable)

Enables the comparison swap of compare 0 and compareBuf 0 on OV and/or UN, depending on the PWM alignment.

Function Usage

    /* Scenario: there is a need to enable the compare swapping feature for
     * the first (index = 0) PWM of the TCPWM0 block
     * This can be used to change the compare value on the fly without a
     * modification of the compare value itself.
     */
    #define MY_TCPWM_PWM_NUM   (0UL)

    Cy_TCPWM_PWM_EnableCompare0Swap(TCPWM0, MY_TCPWM_PWM_NUM, true);

    /* Now the compare 0 and 1 values can be swapped using either HW input or Cy_TCPWM_TriggerCaptureOrSwap_Single */

Parameters
  • base: The pointer to a TCPWM instance.

  • cntNum: The Counter instance number in the selected TCPWM.

  • enable: true = swap enabled; false = swap disabled

__STATIC_INLINE void Cy_TCPWM_PWM_SetCounter (TCPWM_Type *base, uint32_t cntNum, uint32_t count)

Sets the value of the counter.

Function Usage

    /* Scenario: there is a need to set the counter value for
     * the first (index = 0) counter of the TCPWM0 block
     */
    #define MY_TCPWM_PWM_NUM   (0UL)
    #define MY_TCPWM_PWM_MASK  (1UL << MY_TCPWM_PWM_NUM)
    #define MY_TCPWM_PWM_VAL   (100UL)

    Cy_TCPWM_TriggerStopOrKill_Single(TCPWM0, MY_TCPWM_PWM_MASK);
    Cy_TCPWM_PWM_SetCounter(TCPWM0, MY_TCPWM_PWM_NUM, MY_TCPWM_PWM_VAL);
    Cy_TCPWM_TriggerReloadOrIndex_Single(TCPWM0, MY_TCPWM_PWM_MASK);

Parameters
  • base: The pointer to a TCPWM instance.

  • cntNum: The Counter instance number in the selected TCPWM.

  • count: The value to write into the counter.

__STATIC_INLINE uint32_t Cy_TCPWM_PWM_GetCounter (TCPWM_Type const *base, uint32_t cntNum)

Returns the value in the counter.

Return

The current counter value.

Function Usage

    /* Scenario: there is a need to get the current counter value of
     * the first (index = 0) counter of the TCPWM0 block
     * This can be used instead of capture mechanism,
     * when the time latency is not critical, etc.
     */
    #define MY_TCPWM_PWM_NUM   (0UL)

    uint32_t count = Cy_TCPWM_PWM_GetCounter(TCPWM0, MY_TCPWM_PWM_NUM);

Parameters
  • base: The pointer to a TCPWM instance.

  • cntNum: The Counter instance number in the selected TCPWM.

__STATIC_INLINE void Cy_TCPWM_PWM_SetPeriod0 (TCPWM_Type *base, uint32_t cntNum, uint32_t period0)

Sets the value of the period register.

Function Usage

    /* Scenario: there is a need to modify the Period 0 value of
     * the first (index = 0) PWM of the TCPWM0 block.
     * This can be used to change the PWM signal frequency.
     * Note: prior to Period 0 changing either should be done:
     * - the PWM should be disabled (if the period swapping feature is not used).
     * - the period swapping feature should be enabled and the current "working" period should be the Period 1.
     */
    #define MY_TCPWM_PWM_NUM   (0UL)

    /* Get the currently existing period value */
    uint32_t period = Cy_TCPWM_PWM_GetPeriod0(TCPWM0, MY_TCPWM_PWM_NUM);
    /* Modify the period value here */
    Cy_TCPWM_PWM_SetPeriod0(TCPWM0, MY_TCPWM_PWM_NUM, period);

Parameters
  • base: The pointer to a TCPWM instance.

  • cntNum: The Counter instance number in the selected TCPWM.

  • period0: The value to write into a period.

__STATIC_INLINE uint32_t Cy_TCPWM_PWM_GetPeriod0 (TCPWM_Type const *base, uint32_t cntNum)

Returns the value in the period register.

Return

The current period value.

Function Usage

    /* Scenario: there is a need to modify the Period 0 value of
     * the first (index = 0) PWM of the TCPWM0 block.
     * This can be used to change the PWM signal frequency.
     * Note: prior to Period 0 changing either should be done:
     * - the PWM should be disabled (if the period swapping feature is not used).
     * - the period swapping feature should be enabled and the current "working" period should be the Period 1.
     */
    #define MY_TCPWM_PWM_NUM   (0UL)

    /* Get the currently existing period value */
    uint32_t period = Cy_TCPWM_PWM_GetPeriod0(TCPWM0, MY_TCPWM_PWM_NUM);
    /* Modify the period value here */
    Cy_TCPWM_PWM_SetPeriod0(TCPWM0, MY_TCPWM_PWM_NUM, period);

Parameters
  • base: The pointer to a TCPWM instance.

  • cntNum: The Counter instance number in the selected TCPWM.

__STATIC_INLINE void Cy_TCPWM_PWM_SetPeriod1 (TCPWM_Type *base, uint32_t cntNum, uint32_t period1)

Sets the value of the period register.

In pseudo random mode period 1 sets which taps are enabled.

Function Usage

    /* Scenario: there is a need to modify the alternative period value
     * (Period 1) of the first (index = 0) PWM of the TCPWM0 block.
     * Note: the period swapping feature should be enabled.
     * This can be used to change the PWM signal frequency on the fly without a
     * modification of the period value itself.
     */
    #define MY_TCPWM_CNT_NUM   (0UL)

    /* Get the currently existing period value */
    uint32_t period = Cy_TCPWM_PWM_GetPeriod1(TCPWM0, MY_TCPWM_PWM_NUM);
    /* Modify the period value here */
    Cy_TCPWM_PWM_SetPeriod1(TCPWM0, MY_TCPWM_PWM_NUM, period);
    /* Now the Period 0 and 1 values can be swapped using Cy_TCPWM_TriggerCaptureOrSwap_Single */

Parameters
  • base: The pointer to a TCPWM instance.

  • cntNum: The Counter instance number in the selected TCPWM.

  • period1: The value to write into a period 1.

__STATIC_INLINE uint32_t Cy_TCPWM_PWM_GetPeriod1 (TCPWM_Type const *base, uint32_t cntNum)

Returns the value in the period register.

Return

The current period value.

Function Usage

    /* Scenario: there is a need to modify the alternative period value
     * (Period 1) of the first (index = 0) PWM of the TCPWM0 block.
     * Note: the period swapping feature should be enabled.
     * This can be used to change the PWM signal frequency on the fly without a
     * modification of the period value itself.
     */
    #define MY_TCPWM_CNT_NUM   (0UL)

    /* Get the currently existing period value */
    uint32_t period = Cy_TCPWM_PWM_GetPeriod1(TCPWM0, MY_TCPWM_PWM_NUM);
    /* Modify the period value here */
    Cy_TCPWM_PWM_SetPeriod1(TCPWM0, MY_TCPWM_PWM_NUM, period);
    /* Now the Period 0 and 1 values can be swapped using Cy_TCPWM_TriggerCaptureOrSwap_Single */

Parameters
  • base: The pointer to a COUNTER PWM instance.

  • cntNum: The Counter instance number in the selected TCPWM.

__STATIC_INLINE void Cy_TCPWM_PWM_EnablePeriodSwap (TCPWM_Type *base, uint32_t cntNum, bool enable)

Enables a period swap on OV and/or UN, depending on the PWM alignment.

Function Usage

    /* Scenario: there is a need to enable the period swapping feature for
     * the first (index = 0) PWM of the TCPWM0 block
     * This can be used to change the period value on the fly without a
     * modification of the period value itself.
     */
    #define MY_TCPWM_PWM_NUM   (0UL)

    Cy_TCPWM_PWM_EnablePeriodSwap(TCPWM0, MY_TCPWM_PWM_NUM, true);
    /* Now the Period 0 and 1 values can be swapped using either Swap HW input or Cy_TCPWM_TriggerCaptureOrSwap_Single */

Parameters
  • base: The pointer to a TCPWM instance.

  • cntNum: The Counter instance number in the selected TCPWM.

  • enable: true = swap enabled; false = swap disabled

__STATIC_INLINE uint32_t Cy_TCPWM_PWM_GetDtCounter (TCPWM_Type const *base, uint32_t cntNum)

Returns the dead time count when the PWM is configured in dead time mode.

note

supported only in TCPWM_ver2

Return

The dead time counter.

Function Usage

    /* Scenario: When the PWM is configured in dead time mode, get the dead time counter value*/
    #define MY_TCPWM_PWM_NUM   (0UL)

    uint32_t count = Cy_TCPWM_PWM_GetDtCounter(TCPWM0, MY_TCPWM_PWM_NUM);

Parameters
  • base: The pointer to a TCPWM instance.

  • cntNum: The Counter instance number in the selected TCPWM.

__STATIC_INLINE uint32_t Cy_TCPWM_PWM_LineOutStatus (TCPWM_Type const *base, uint32_t cntNum, uint32_t pwmOutSelect)

Returns the current level of the selected pwm output line.

note

supported only in TCPWM_ver2

Return

The current pwm output line level.

Function Usage


    /* Scenario: there is a need to check current level of
     * PWM Line output for the first (index = 0) counter of the TCPWM0 block
     */
    #define MY_TCPWM_PWM_NUM   (0UL)

    if (Cy_TCPWM_PWM_LineOutStatus(TCPWM0, MY_TCPWM_PWM_NUM, CY_TCPWM_PWM_LINE_PWM))
    {
        /* PWM Line is High */
    }
    else
    {
        /* PWM Line is Low */
    }

Parameters
  • base: The pointer to a TCPWM instance.

  • cntNum: The Counter instance number in the selected TCPWM.

  • pwmOutSelect: Defines which pwm output line is being checked pwm or pwm_n.

__STATIC_INLINE void Cy_TCPWM_PWM_PWMDeadTime (TCPWM_Type const *base, uint32_t cntNum, uint32_t deadTime)

Writes the dead time value for PWM.

This is the number of clock cycles between PWM_n (line_compl) going LOW and PWM (line) going HIGH.

Function Usage


    /* Scenario: there is a need to update deadTimeClocks for line_out
     * and line_compl_out for the first (index = 0) counter of the TCPWM0 block
     */
    #define MY_TCPWM_PWM_NUM   (0UL)

    Cy_TCPWM_PWM_PWMDeadTime(TCPWM0, MY_TCPWM_PWM_NUM, 10U);
    Cy_TCPWM_PWM_PWMDeadTimeN(TCPWM0, MY_TCPWM_PWM_NUM, 10U);
    

Parameters
  • base: The pointer to a TCPWM instance.

  • cntNum: The Counter instance number in the selected TCPWM.

  • deadTime: The dead time value.

__STATIC_INLINE void Cy_TCPWM_PWM_PWMDeadTimeN (TCPWM_Type const *base, uint32_t cntNum, uint32_t deadTime)

Writes the dead time value for PWM_n.

This is the number of clock cycles between PWM (line) going LOW and PWM_n (line_compl) going HIGH.

Function Usage


    /* Scenario: there is a need to update deadTimeClocks for line_out
     * and line_compl_out for the first (index = 0) counter of the TCPWM0 block
     */
    #define MY_TCPWM_PWM_NUM   (0UL)

    Cy_TCPWM_PWM_PWMDeadTime(TCPWM0, MY_TCPWM_PWM_NUM, 10U);
    Cy_TCPWM_PWM_PWMDeadTimeN(TCPWM0, MY_TCPWM_PWM_NUM, 10U);
    

Parameters
  • base: The pointer to a TCPWM instance.

  • cntNum: The Counter instance number in the selected TCPWM.

  • deadTime: The dead time value.

__STATIC_INLINE void Cy_TCPWM_PWM_SetCompare1Val (TCPWM_Type *base, uint32_t cntNum, uint32_t compare1)

Sets the compare value for Compare 1 when the compare mode enabled.

Parameters
  • base: The pointer to a TCPWM instance.

  • cntNum: The Counter instance number in the selected TCPWM.

  • compare1: The Compare1 value.

__STATIC_INLINE uint32_t Cy_TCPWM_PWM_GetCompare1Val (TCPWM_Type const *base, uint32_t cntNum)

Returns compare 1 value.

Return

Compare 1 value.

Parameters
  • base: The pointer to a TCPWM instance.

  • cntNum: The Counter instance number in the selected TCPWM.

__STATIC_INLINE void Cy_TCPWM_PWM_SetCompare1BufVal (TCPWM_Type *base, uint32_t cntNum, uint32_t compareBuf1)

Sets the buffered compare value for Compare1 when the compare mode enabled.

Parameters
  • base: The pointer to a TCPWM instance.

  • cntNum: The Counter instance number in the selected TCPWM.

  • compareBuf1: The buffered Compare 1 value.

__STATIC_INLINE uint32_t Cy_TCPWM_PWM_GetCompare1BufVal (TCPWM_Type const *base, uint32_t cntNum)

Returns the buffered compare 1 value.

Return

Buffered compare 1 value.

Parameters
  • base: The pointer to a TCPWM instance.

  • cntNum: The Counter instance number in the selected TCPWM.

__STATIC_INLINE void Cy_TCPWM_PWM_EnableCompare1Swap (TCPWM_Type *base, uint32_t cntNum, bool enable)

Enables the comparison swap of compare1 and compareBuf1 on OV and/or UN, depending on the PWM alignment.

Parameters
  • base: The pointer to a TCPWM instance.

  • cntNum: The Counter instance number in the selected TCPWM.

  • enable: true = swap enabled; false = swap disabled