Functions

group group_tcpwm_functions_counter

Functions

cy_en_tcpwm_status_t Cy_TCPWM_Counter_Init(TCPWM_Type *base, uint32_t cntNum, cy_stc_tcpwm_counter_config_t const *config)

Initializes the counter in the TCPWM block for the Counter operation.

Return

error / status code. See cy_en_tcpwm_status_t.

Function Usage

    /* Scenario: there is need to initialize
     * the first (index = 0) counter of the TCPWM0 block
     * with the below configuration settings
     */
    cy_stc_tcpwm_counter_config_t tcpwm_v1_counter_config =
    {
        /* .period            = */ 99UL, /* Period of 100 (0-99). Terminal count event when rolls over back to 0. */
        /* .clockPrescaler    = */ CY_TCPWM_COUNTER_PRESCALER_DIVBY_4, /* Clk_counter = Clk_input / 4 */
        /* .runMode           = */ CY_TCPWM_COUNTER_CONTINUOUS, /* Wrap around at terminal count. */
        /* .countDirection    = */ CY_TCPWM_COUNTER_COUNT_UP, /* Up counter, counting from 0 to period value. */
        /* .compareOrCapture  = */ CY_TCPWM_COUNTER_MODE_COMPARE, /* Trigger interrupt/event signal when Counter value is equal to Compare 0 */
        /* .compare0          = */ 33UL,
        /* .compare1          = */ 66UL,
        /* .enableCompareSwap = */ true, /* Upon a compare event, swap the Compare 0 and Compare 1 values. */
        /* .interruptSources  = */ CY_TCPWM_INT_NONE,
        /* .captureInputMode  = */ CY_TCPWM_INPUT_RISINGEDGE, /* This input is NOT used, leave it in default state (CY_TCPWM_INPUT_RISINGEDGE = 0UL) */
        /* .captureInput      = */ 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,
        /* .stopInputMode     = */ CY_TCPWM_INPUT_RISINGEDGE, /* This input is NOT used, leave it in default state (CY_TCPWM_INPUT_RISINGEDGE = 0UL) */
        /* .stopInput         = */ 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 counter will count input clock periods (Clk_counter, taking into account the clock prescaler) */
    };

    #define MY_TCPWM_CNT_NUM   (0UL)

    if (CY_TCPWM_SUCCESS != Cy_TCPWM_Counter_Init(TCPWM0, MY_TCPWM_CNT_NUM, &tcpwm_v1_counter_config))
    {
        /* Handle possible errors */
    }
    /* Enable the initialized counter */
    Cy_TCPWM_Counter_Enable(TCPWM0, MY_TCPWM_CNT_NUM);

    /* Then start the counter */
    Cy_TCPWM_TriggerStart_Single(TCPWM0, MY_TCPWM_CNT_NUM);
    /* Scenario: there is need to initialize
     * the first (index = 0) counter of the TCPWM0 block
     * with the below configuration settings
     */
    cy_stc_tcpwm_counter_config_t tcpwm_v2_counter_config =
    {
        /* .period            = */ 99UL, /* Period of 100 (0-99). Terminal count event when rolls over back to 0. */
        /* .clockPrescaler    = */ CY_TCPWM_COUNTER_PRESCALER_DIVBY_4, /* Clk_counter = Clk_input / 4 */
        /* .runMode           = */ CY_TCPWM_COUNTER_CONTINUOUS, /* Wrap around at terminal count. */
        /* .countDirection    = */ CY_TCPWM_COUNTER_COUNT_UP, /* Up counter, counting from 0 to period value. */
        /* .compareOrCapture  = */ CY_TCPWM_COUNTER_MODE_COMPARE, /* Trigger interrupt/event signal when Counter value is equal to Compare 0 */
        /* .compare0          = */ 33UL,
        /* .compare1          = */ 66UL,
        /* .enableCompareSwap = */ true, /* Upon a compare event, swap the Compare 0 and Compare 1 values. */
        /* .interruptSources  = */ CY_TCPWM_INT_NONE,
        /* .captureInputMode  = */ CY_TCPWM_INPUT_RISINGEDGE, /* This input is NOT used, leave it in default state (CY_TCPWM_INPUT_RISINGEDGE = 0UL) */
        /* .captureInput      = */ 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,
        /* .stopInputMode     = */ CY_TCPWM_INPUT_RISINGEDGE, /* This input is NOT used, leave it in default state (CY_TCPWM_INPUT_RISINGEDGE = 0UL) */
        /* .stopInput         = */ 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 counter will count input clock periods (Clk_counter, taking into account the clock prescaler) */
        /* .capture1InputMode = */ CY_TCPWM_INPUT_RISINGEDGE, /* This input is NOT used, leave it in default state (CY_TCPWM_INPUT_RISINGEDGE = 0UL) */
        /* .capture1Input     = */ CY_TCPWM_INPUT_0,
        /* .enableCompare1Swap= */ false, /* Disable CC1 */
        /* .compare2          = */ 0,
        /* .compare3          = */ 0,
        /* .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_CNT_NUM   (0UL)
    
    if (CY_TCPWM_SUCCESS != Cy_TCPWM_Counter_Init(TCPWM0, MY_TCPWM_CNT_NUM, &tcpwm_v2_counter_config))
    {
        /* Handle possible errors */
    }
    /* Enable the initialized counter */
    Cy_TCPWM_Counter_Enable(TCPWM0, MY_TCPWM_CNT_NUM);
    
    /* Then start the counter */
    Cy_TCPWM_TriggerStart_Single(TCPWM0, MY_TCPWM_CNT_NUM);

Parameters
  • base: The pointer to a TCPWM instance.

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

  • config: The pointer to configuration structure. See cy_stc_tcpwm_counter_config_t.

void Cy_TCPWM_Counter_DeInit(TCPWM_Type *base, uint32_t cntNum, cy_stc_tcpwm_counter_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_CNT_NUM   (0UL)
    
    /* Disable the counter prior to deinitializing */
    Cy_TCPWM_Counter_Disable(TCPWM0, MY_TCPWM_CNT_NUM);
    Cy_TCPWM_Counter_DeInit(TCPWM0, MY_TCPWM_CNT_NUM, &config);

Parameters
  • base: The pointer to a TCPWM instance.

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

  • config: The pointer to configuration structure. See cy_stc_tcpwm_counter_config_t.

__STATIC_INLINE void Cy_TCPWM_Counter_Enable (TCPWM_Type *base, uint32_t cntNum)

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

Function Usage

    /* Scenario: there is need to initialize
     * the first (index = 0) counter of the TCPWM0 block
     * with the below configuration settings
     */
    cy_stc_tcpwm_counter_config_t tcpwm_v1_counter_config =
    {
        /* .period            = */ 99UL, /* Period of 100 (0-99). Terminal count event when rolls over back to 0. */
        /* .clockPrescaler    = */ CY_TCPWM_COUNTER_PRESCALER_DIVBY_4, /* Clk_counter = Clk_input / 4 */
        /* .runMode           = */ CY_TCPWM_COUNTER_CONTINUOUS, /* Wrap around at terminal count. */
        /* .countDirection    = */ CY_TCPWM_COUNTER_COUNT_UP, /* Up counter, counting from 0 to period value. */
        /* .compareOrCapture  = */ CY_TCPWM_COUNTER_MODE_COMPARE, /* Trigger interrupt/event signal when Counter value is equal to Compare 0 */
        /* .compare0          = */ 33UL,
        /* .compare1          = */ 66UL,
        /* .enableCompareSwap = */ true, /* Upon a compare event, swap the Compare 0 and Compare 1 values. */
        /* .interruptSources  = */ CY_TCPWM_INT_NONE,
        /* .captureInputMode  = */ CY_TCPWM_INPUT_RISINGEDGE, /* This input is NOT used, leave it in default state (CY_TCPWM_INPUT_RISINGEDGE = 0UL) */
        /* .captureInput      = */ 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,
        /* .stopInputMode     = */ CY_TCPWM_INPUT_RISINGEDGE, /* This input is NOT used, leave it in default state (CY_TCPWM_INPUT_RISINGEDGE = 0UL) */
        /* .stopInput         = */ 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 counter will count input clock periods (Clk_counter, taking into account the clock prescaler) */
    };

    #define MY_TCPWM_CNT_NUM   (0UL)

    if (CY_TCPWM_SUCCESS != Cy_TCPWM_Counter_Init(TCPWM0, MY_TCPWM_CNT_NUM, &tcpwm_v1_counter_config))
    {
        /* Handle possible errors */
    }
    /* Enable the initialized counter */
    Cy_TCPWM_Counter_Enable(TCPWM0, MY_TCPWM_CNT_NUM);

    /* Then start the counter */
    Cy_TCPWM_TriggerStart_Single(TCPWM0, MY_TCPWM_CNT_NUM);
    /* Scenario: there is need to initialize
     * the first (index = 0) counter of the TCPWM0 block
     * with the below configuration settings
     */
    cy_stc_tcpwm_counter_config_t tcpwm_v2_counter_config =
    {
        /* .period            = */ 99UL, /* Period of 100 (0-99). Terminal count event when rolls over back to 0. */
        /* .clockPrescaler    = */ CY_TCPWM_COUNTER_PRESCALER_DIVBY_4, /* Clk_counter = Clk_input / 4 */
        /* .runMode           = */ CY_TCPWM_COUNTER_CONTINUOUS, /* Wrap around at terminal count. */
        /* .countDirection    = */ CY_TCPWM_COUNTER_COUNT_UP, /* Up counter, counting from 0 to period value. */
        /* .compareOrCapture  = */ CY_TCPWM_COUNTER_MODE_COMPARE, /* Trigger interrupt/event signal when Counter value is equal to Compare 0 */
        /* .compare0          = */ 33UL,
        /* .compare1          = */ 66UL,
        /* .enableCompareSwap = */ true, /* Upon a compare event, swap the Compare 0 and Compare 1 values. */
        /* .interruptSources  = */ CY_TCPWM_INT_NONE,
        /* .captureInputMode  = */ CY_TCPWM_INPUT_RISINGEDGE, /* This input is NOT used, leave it in default state (CY_TCPWM_INPUT_RISINGEDGE = 0UL) */
        /* .captureInput      = */ 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,
        /* .stopInputMode     = */ CY_TCPWM_INPUT_RISINGEDGE, /* This input is NOT used, leave it in default state (CY_TCPWM_INPUT_RISINGEDGE = 0UL) */
        /* .stopInput         = */ 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 counter will count input clock periods (Clk_counter, taking into account the clock prescaler) */
        /* .capture1InputMode = */ CY_TCPWM_INPUT_RISINGEDGE, /* This input is NOT used, leave it in default state (CY_TCPWM_INPUT_RISINGEDGE = 0UL) */
        /* .capture1Input     = */ CY_TCPWM_INPUT_0,
        /* .enableCompare1Swap= */ false, /* Disable CC1 */
        /* .compare2          = */ 0,
        /* .compare3          = */ 0,
        /* .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_CNT_NUM   (0UL)
    
    if (CY_TCPWM_SUCCESS != Cy_TCPWM_Counter_Init(TCPWM0, MY_TCPWM_CNT_NUM, &tcpwm_v2_counter_config))
    {
        /* Handle possible errors */
    }
    /* Enable the initialized counter */
    Cy_TCPWM_Counter_Enable(TCPWM0, MY_TCPWM_CNT_NUM);
    
    /* Then start the counter */
    Cy_TCPWM_TriggerStart_Single(TCPWM0, MY_TCPWM_CNT_NUM);

Parameters
  • base: The pointer to a TCPWM instance.

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

__STATIC_INLINE void Cy_TCPWM_Counter_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_CNT_NUM   (0UL)
    
    /* Disable the counter prior to deinitializing */
    Cy_TCPWM_Counter_Disable(TCPWM0, MY_TCPWM_CNT_NUM);
    Cy_TCPWM_Counter_DeInit(TCPWM0, MY_TCPWM_CNT_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_Counter_GetStatus (TCPWM_Type const *base, uint32_t cntNum)

Returns the status of the Counter Timer whether it is running or not.

In case the Counter is running, status will also provide information on counting up/down. This is useful when the counter mode is set to UP_DOWN_1 or UP_DOWN_2.

Return

The status. See Counter 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_CNT_NUM   (0UL)

    uint32_t status = Cy_TCPWM_Counter_GetStatus(TCPWM0, MY_TCPWM_CNT_NUM);

    if ((CY_TCPWM_COUNTER_STATUS_COUNTER_RUNNING & status) && (CY_TCPWM_COUNTER_STATUS_UP_COUNTING & status))
    {
        /* Up Counting */
    }
    else if ((CY_TCPWM_COUNTER_STATUS_COUNTER_RUNNING & status) && (CY_TCPWM_COUNTER_STATUS_DOWN_COUNTING & status))
    {
        /* Down Counting */
    }
    else
    {
        /* Counter is not running */
    }

Parameters
  • base: The pointer to a TCPWM instance.

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

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

Returns the capture 0 value when the capture mode is enabled.

Return

The capture 0 value.

Function Usage

    /* Scenario: there is a need to trigger software capture events for
     * the first (index = 0) counter of the TCPWM0 block.
     * Note: the counter should run in the Capture Mode.
     */
    #define MY_TCPWM_CNT_NUM   (0UL)

    Cy_TCPWM_TriggerCaptureOrSwap_Single(TCPWM0, MY_TCPWM_CNT_NUM);
    /* after some time */
    Cy_TCPWM_TriggerCaptureOrSwap_Single(TCPWM0, MY_TCPWM_CNT_NUM);

    /* Now we can get the latest captured value
     * (captured during the second call of Cy_TCPWM_TriggerCaptureOrSwap_Single)
     */
    uint32_t capture = Cy_TCPWM_Counter_GetCapture0Val(TCPWM0, MY_TCPWM_CNT_NUM);
    /* Also the previous captured value
     * (captured during the first call of Cy_TCPWM_TriggerCaptureOrSwap_Single)
     * is available by the next way
     */
    uint32_t captureBuf = Cy_TCPWM_Counter_GetCapture0BufVal(TCPWM0, MY_TCPWM_CNT_NUM);

Parameters
  • base: The pointer to a TCPWM instance.

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

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

Returns the buffered capture 0 value when the capture mode is enabled.

Return

The buffered capture 0 value.

Function Usage

    /* Scenario: there is a need to trigger software capture events for
     * the first (index = 0) counter of the TCPWM0 block.
     * Note: the counter should run in the Capture Mode.
     */
    #define MY_TCPWM_CNT_NUM   (0UL)

    Cy_TCPWM_TriggerCaptureOrSwap_Single(TCPWM0, MY_TCPWM_CNT_NUM);
    /* after some time */
    Cy_TCPWM_TriggerCaptureOrSwap_Single(TCPWM0, MY_TCPWM_CNT_NUM);

    /* Now we can get the latest captured value
     * (captured during the second call of Cy_TCPWM_TriggerCaptureOrSwap_Single)
     */
    uint32_t capture = Cy_TCPWM_Counter_GetCapture0Val(TCPWM0, MY_TCPWM_CNT_NUM);
    /* Also the previous captured value
     * (captured during the first call of Cy_TCPWM_TriggerCaptureOrSwap_Single)
     * is available by the next way
     */
    uint32_t captureBuf = Cy_TCPWM_Counter_GetCapture0BufVal(TCPWM0, MY_TCPWM_CNT_NUM);

Parameters
  • base: The pointer to a TCPWM instance.

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

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

Sets the compare value for Compare0 when the compare mode is enabled.

Function Usage

    /* Scenario: there is a need to modify the Compare 0 value of 
     * the first (index = 0) counter of the TCPWM0 block.
     * Note: the counter should run in the Compare Mode.
     */
    #define MY_TCPWM_CNT_NUM   (0UL)
    
    /* Stop the counter for clear transition */
    Cy_TCPWM_TriggerStopOrKill_Single(TCPWM0, MY_TCPWM_CNT_NUM);
    /* Get the currently existing Compare 0 value */
    uint32_t compare = Cy_TCPWM_Counter_GetCompare0Val(TCPWM0, MY_TCPWM_CNT_NUM);
    /* Modify the compare value here */
    Cy_TCPWM_Counter_SetCompare0Val(TCPWM0, MY_TCPWM_CNT_NUM, compare);
    /* Restart the counter with the new Compare 0 value */
    Cy_TCPWM_TriggerReloadOrIndex_Single(TCPWM0, MY_TCPWM_CNT_NUM);

Parameters
  • base: The pointer to a TCPWM instance.

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

  • compare0: The Compare0 value.

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

Returns compare 0 value.

Return

Compare 0 value.

Function Usage

    /* Scenario: there is a need to modify the Compare 0 value of 
     * the first (index = 0) counter of the TCPWM0 block.
     * Note: the counter should run in the Compare Mode.
     */
    #define MY_TCPWM_CNT_NUM   (0UL)
    
    /* Stop the counter for clear transition */
    Cy_TCPWM_TriggerStopOrKill_Single(TCPWM0, MY_TCPWM_CNT_NUM);
    /* Get the currently existing Compare 0 value */
    uint32_t compare = Cy_TCPWM_Counter_GetCompare0Val(TCPWM0, MY_TCPWM_CNT_NUM);
    /* Modify the compare value here */
    Cy_TCPWM_Counter_SetCompare0Val(TCPWM0, MY_TCPWM_CNT_NUM, compare);
    /* Restart the counter with the new Compare 0 value */
    Cy_TCPWM_TriggerReloadOrIndex_Single(TCPWM0, MY_TCPWM_CNT_NUM);

Parameters
  • base: The pointer to a TCPWM instance.

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

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

Sets the compare value for Compare1 when the compare mode is 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 counter should run in the Compare Mode.
     * Note: the compare swapping feature should be enabled.
     */
    #define MY_TCPWM_CNT_NUM   (0UL)

    /* Get the currently existing Compare 1 value */
    uint32_t compare = Cy_TCPWM_Counter_GetCompare0BufVal(TCPWM0, MY_TCPWM_CNT_NUM);
    /* Modify the compare value here */
    Cy_TCPWM_Counter_SetCompare0BufVal(TCPWM0, MY_TCPWM_CNT_NUM, compare);
    /* Now the Compare 0 and Compare 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.

  • compare1: The Compare1 value.

__STATIC_INLINE uint32_t Cy_TCPWM_Counter_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 counter should run in the Compare Mode.
     * Note: the compare swapping feature should be enabled.
     */
    #define MY_TCPWM_CNT_NUM   (0UL)

    /* Get the currently existing Compare 1 value */
    uint32_t compare = Cy_TCPWM_Counter_GetCompare0BufVal(TCPWM0, MY_TCPWM_CNT_NUM);
    /* Modify the compare value here */
    Cy_TCPWM_Counter_SetCompare0BufVal(TCPWM0, MY_TCPWM_CNT_NUM, compare);
    /* Now the Compare 0 and Compare 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.

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

Enables the comparison swap when the comparison value is true.

Function Usage

    /* Scenario: there is a need to enable the compare swapping feature for
     * the first (index = 0) counter of the TCPWM0 block.
     */
    #define MY_TCPWM_CNT_NUM   (0UL)
    
    Cy_TCPWM_Counter_EnableCompare0Swap(TCPWM0, MY_TCPWM_CNT_NUM, true);
    /* Now the Compare 0 and Compare 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.

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

__STATIC_INLINE void Cy_TCPWM_Counter_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_CNT_NUM   (0UL)
    #define MY_TCPWM_CNT_VAL   (100UL)

    Cy_TCPWM_TriggerStopOrKill_Single(TCPWM0, MY_TCPWM_CNT_NUM);
    Cy_TCPWM_Counter_SetCounter(TCPWM0, MY_TCPWM_CNT_NUM, MY_TCPWM_CNT_VAL);
    Cy_TCPWM_TriggerStart_Single(TCPWM0, MY_TCPWM_CNT_NUM);

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_Counter_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
     */
    #define MY_TCPWM_CNT_NUM   (0UL)
    
    uint32_t count = Cy_TCPWM_Counter_GetCounter(TCPWM0, MY_TCPWM_CNT_NUM);

Parameters
  • base: The pointer to a TCPWM instance.

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

__STATIC_INLINE void Cy_TCPWM_Counter_SetPeriod (TCPWM_Type *base, uint32_t cntNum, uint32_t period)

Sets the value of the period register.

Function Usage

    /* Scenario: there is a need to modify the period of 
     * the first (index = 0) counter of the TCPWM0 block.
     */
    #define MY_TCPWM_CNT_NUM   (0UL)
    
    /* Get the currently existing period value */
    uint32_t period = Cy_TCPWM_Counter_GetPeriod(TCPWM0, MY_TCPWM_CNT_NUM);
    /* Modify the period value here */
    Cy_TCPWM_Counter_SetPeriod(TCPWM0, MY_TCPWM_CNT_NUM, period);

Parameters
  • base: The pointer to a TCPWM instance.

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

  • period: The value to write into a period.

__STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetPeriod (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 of 
     * the first (index = 0) counter of the TCPWM0 block.
     */
    #define MY_TCPWM_CNT_NUM   (0UL)
    
    /* Get the currently existing period value */
    uint32_t period = Cy_TCPWM_Counter_GetPeriod(TCPWM0, MY_TCPWM_CNT_NUM);
    /* Modify the period value here */
    Cy_TCPWM_Counter_SetPeriod(TCPWM0, MY_TCPWM_CNT_NUM, period);

Parameters
  • base: The pointer to a TCPWM instance.

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

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

Returns capture 1 value when capture mode is enabled.

Return

Capture 1 value.

Parameters
  • base: The pointer to a TCPWM instance.

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

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

Returns the buffered capture1 value when capture mode is enabled.

Return

Buffered capture1 value.

Parameters
  • base: The pointer to a TCPWM instance.

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

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

Returns compare 1 value.

Return

Compare 1 value.

Function Usage

    /* Scenario: there is a need to modify the alternative compare value
     * (Compare 1) for the first (index = 256) counter of Group 1 of the TCPWM0 block.
     * Note: the counter should run in the Compare Mode.
     * Note: the compare swapping feature should be enabled.
     */
    #define MY_TCPWM_GRP1_CNT0_NUM   (256UL)

    /* Get the currently existing Compare 1 value and set a new Compare 1 Val */
    uint32_t compare1 = Cy_TCPWM_Counter_GetCompare1Val(TCPWM0, MY_TCPWM_GRP1_CNT0_NUM);
    /* Modify the compare value here */
    Cy_TCPWM_Counter_SetCompare1Val(TCPWM0, MY_TCPWM_GRP1_CNT0_NUM, compare1);

    /* Get the currently existing Compare1Buf value and set a new Compare1Buf Val */
    uint32_t compareBuf1 = Cy_TCPWM_Counter_GetCompare1BufVal(TCPWM0, MY_TCPWM_GRP1_CNT0_NUM);
    /* Modify the compare1Buff value here */
    Cy_TCPWM_Counter_SetCompare1BufVal(TCPWM0, MY_TCPWM_GRP1_CNT0_NUM, compareBuf1);

Parameters
  • base: The pointer to a TCPWM instance.

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

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

Returns the buffered compare1 value.

Return

Buffered compare1 value.

Function Usage

    /* Scenario: there is a need to modify the alternative compare value
     * (Compare 1) for the first (index = 256) counter of Group 1 of the TCPWM0 block.
     * Note: the counter should run in the Compare Mode.
     * Note: the compare swapping feature should be enabled.
     */
    #define MY_TCPWM_GRP1_CNT0_NUM   (256UL)

    /* Get the currently existing Compare 1 value and set a new Compare 1 Val */
    uint32_t compare1 = Cy_TCPWM_Counter_GetCompare1Val(TCPWM0, MY_TCPWM_GRP1_CNT0_NUM);
    /* Modify the compare value here */
    Cy_TCPWM_Counter_SetCompare1Val(TCPWM0, MY_TCPWM_GRP1_CNT0_NUM, compare1);

    /* Get the currently existing Compare1Buf value and set a new Compare1Buf Val */
    uint32_t compareBuf1 = Cy_TCPWM_Counter_GetCompare1BufVal(TCPWM0, MY_TCPWM_GRP1_CNT0_NUM);
    /* Modify the compare1Buff value here */
    Cy_TCPWM_Counter_SetCompare1BufVal(TCPWM0, MY_TCPWM_GRP1_CNT0_NUM, compareBuf1);

Parameters
  • base: The pointer to a TCPWM instance.

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

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

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

Function Usage

    /* Scenario: there is a need to modify the alternative compare value
     * (Compare 1) for the first (index = 256) counter of Group 1 of the TCPWM0 block.
     * Note: the counter should run in the Compare Mode.
     * Note: the compare swapping feature should be enabled.
     */
    #define MY_TCPWM_GRP1_CNT0_NUM   (256UL)

    /* Get the currently existing Compare 1 value and set a new Compare 1 Val */
    uint32_t compare1 = Cy_TCPWM_Counter_GetCompare1Val(TCPWM0, MY_TCPWM_GRP1_CNT0_NUM);
    /* Modify the compare value here */
    Cy_TCPWM_Counter_SetCompare1Val(TCPWM0, MY_TCPWM_GRP1_CNT0_NUM, compare1);

    /* Get the currently existing Compare1Buf value and set a new Compare1Buf Val */
    uint32_t compareBuf1 = Cy_TCPWM_Counter_GetCompare1BufVal(TCPWM0, MY_TCPWM_GRP1_CNT0_NUM);
    /* Modify the compare1Buff value here */
    Cy_TCPWM_Counter_SetCompare1BufVal(TCPWM0, MY_TCPWM_GRP1_CNT0_NUM, compareBuf1);

Parameters
  • base: The pointer to a TCPWM instance.

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

  • compare1: The Compare1 value.

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

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

Function Usage

    /* Scenario: there is a need to modify the alternative compare value
     * (Compare 1) for the first (index = 256) counter of Group 1 of the TCPWM0 block.
     * Note: the counter should run in the Compare Mode.
     * Note: the compare swapping feature should be enabled.
     */
    #define MY_TCPWM_GRP1_CNT0_NUM   (256UL)

    /* Get the currently existing Compare 1 value and set a new Compare 1 Val */
    uint32_t compare1 = Cy_TCPWM_Counter_GetCompare1Val(TCPWM0, MY_TCPWM_GRP1_CNT0_NUM);
    /* Modify the compare value here */
    Cy_TCPWM_Counter_SetCompare1Val(TCPWM0, MY_TCPWM_GRP1_CNT0_NUM, compare1);

    /* Get the currently existing Compare1Buf value and set a new Compare1Buf Val */
    uint32_t compareBuf1 = Cy_TCPWM_Counter_GetCompare1BufVal(TCPWM0, MY_TCPWM_GRP1_CNT0_NUM);
    /* Modify the compare1Buff value here */
    Cy_TCPWM_Counter_SetCompare1BufVal(TCPWM0, MY_TCPWM_GRP1_CNT0_NUM, compareBuf1);

Parameters
  • base: The pointer to a TCPWM instance.

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

  • compareBuf1: The buffered Compare1 value.

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

Enables the comparison swap of compare1 and compareBuf1 when the comparision value is true.

Function Usage

    /* Scenario: there is a need to enable the compare swapping feature for
     * the first (index = 256) counter of Group 1 of TCPWM0 block.
     */
    #define MY_TCPWM_GRP1_CNT0_NUM   (256UL)

    Cy_TCPWM_Counter_EnableCompare1Swap(TCPWM0, MY_TCPWM_GRP1_CNT0_NUM, true);
    /* Now the Compare1Val and Compare1BufVal values can be swapped using Cy_TCPWM_TriggerCapture1 */

Parameters
  • base: The pointer to a TCPWM instance.

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

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