Functions

group group_tcpwm_functions_shiftreg

Functions

cy_en_tcpwm_status_t Cy_TCPWM_ShiftReg_Init(TCPWM_Type const *base, uint32_t cntNum, cy_stc_tcpwm_shiftreg_config_t const *config)

Initializes the counter in the TCPWM block for the Shift Register operation.


    /* Scenario: Initialize the first (index = 0) of TCPWM 0 block
     * as Shift Register with configuration settings
     */
    cy_stc_tcpwm_shiftreg_config_t shiftreg_config =
    {
       /* .clockPrescaler       = */CY_TCPWM_SHIFTREG_PRESCALER_DIVBY_1,
       /* .tapsEnabled          = */0x80000000UL,
       /* .compare0             = */16384UL,
       /* .compareBuf0          = */16384UL,
       /* .enableCompare0Swap   = */false,
       /* .compare1             = */16384UL,
       /* .compareBuf1          = */16384UL,
       /* .enableCompare1Swap   = */false,
       /* .interruptSources     = */CY_TCPWM_INT_ON_CC0,                /* Interrupt will rise on CC0 Match*/
       /* .invertShiftRegOut    = */CY_TCPWM_SHIFTREG_INVERT_DISABLE,   /* Not inverted */
       /* .invertShiftRegOutN   = */CY_TCPWM_SHIFTREG_INVERT_DISABLE,   /* Not inverted */
       /* .reloadInputMode      = */CY_TCPWM_INPUT_LEVEL,               /* This input is NOT used, leave it in default state (CY_TCPWM_INPUT_LEVEL) */
       /* .reloadInput          = */CY_TCPWM_INPUT_0,
       /* .startInputMode       = */CY_TCPWM_INPUT_LEVEL,               /* This input is NOT used, leave it in default state (CY_TCPWM_INPUT_LEVEL) */
       /* .startInput           = */CY_TCPWM_INPUT_0,
       /* .killInputMode        = */CY_TCPWM_INPUT_LEVEL,               /* This input is NOT used, leave it in default state (CY_TCPWM_INPUT_LEVEL) */
       /* .killInput            = */CY_TCPWM_INPUT_0,
       /* .shiftInputMode       = */CY_TCPWM_INPUT_LEVEL,               /* Set this input to LEVEL and 1 (high logic level) */
       /* .shiftInput           = */CY_TCPWM_INPUT_1,                   /* Shift Register will run forever */
       /* .serialInputMode      = */CY_TCPWM_INPUT_LEVEL,               /* This input is NOT used, leave it in default state (CY_TCPWM_INPUT_LEVEL) */
       /* .serialInput          = */CY_TCPWM_INPUT_0,
       /* .shiftRegOnDisable    = */CY_TCPWM_SHIFTREG_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_SHIFTREG_NUM   (0UL)

    if (CY_TCPWM_SUCCESS != Cy_TCPWM_ShiftReg_Init(TCPWM0, MY_TCPWM_SHIFTREG_NUM, &shiftreg_config))
    {
        /* Handle possible errors */
    }
Return

error / status code. See cy_en_tcpwm_status_t.

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_shiftreg_config_t.

void Cy_TCPWM_ShiftReg_DeInit(TCPWM_Type const *base, uint32_t cntNum, cy_stc_tcpwm_shiftreg_config_t const *config)

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

    /* Scenario: there is need to deinitialize the previously initialized shift register */
    #define MY_TCPWM_SHIFTREG_NUM   (0UL)

    /* Disable the shift register prior to deinitializing */
    Cy_TCPWM_ShiftReg_Disable(TCPWM0, MY_TCPWM_SHIFTREG_NUM);
    Cy_TCPWM_ShiftReg_DeInit(TCPWM0, MY_TCPWM_SHIFTREG_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_shiftreg_config_t.

__STATIC_INLINE void Cy_TCPWM_ShiftReg_Enable (TCPWM_Type *base, uint32_t cntNum)

Enables the counter in the TCPWM block for the Shift Register operation.

    /* Scenario: Enable Shift Register */
    #define MY_TCPWM_SHIFTREG_NUM   (0UL)

    Cy_TCPWM_ShiftReg_Enable(TCPWM0, MY_TCPWM_SHIFTREG_NUM);
Parameters
  • base: The pointer to a TCPWM instance.

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

__STATIC_INLINE void Cy_TCPWM_ShiftReg_Disable (TCPWM_Type *base, uint32_t cntNum)

Disables the counter in the TCPWM block.

    /* Scenario: Disable Shift Register */
    #define MY_TCPWM_SHIFTREG_NUM   (0UL)

    Cy_TCPWM_ShiftReg_Disable(TCPWM0, MY_TCPWM_SHIFTREG_NUM);
Parameters
  • base: The pointer to a TCPWM instance.

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

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

Returns the status of the Shift Register whether it is running or not.

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

    if (0UL != (CY_TCPWM_SHIFTREG_STATUS_RUNNING &
                Cy_TCPWM_ShiftReg_GetStatus(TCPWM0, MY_TCPWM_SHIFTREG_NUM)))
    {
        /* Shift Register is running */
    }
Return

The status. See Shift Register Status

Parameters
  • base: The pointer to a TCPWM instance.

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

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

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

    /* Scenario: there is a need to set the Compare 0 value of
     * the first (index = 0) Shift Register of the TCPWM0 block.
     */
    #define MY_TCPWM_SHIFTREG_NUM   (0UL)

    /* Get the currently existing compare value */
    uint32_t compare = Cy_TCPWM_ShiftReg_GetCompare0Val(TCPWM0, MY_TCPWM_SHIFTREG_NUM);
    /* Modify the compare value here */
    Cy_TCPWM_ShiftReg_SetCompare0Val(TCPWM0, MY_TCPWM_SHIFTREG_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_ShiftReg_GetCompare0Val (TCPWM_Type const *base, uint32_t cntNum)

Returns compare 0 value.

    /* Scenario: there is a need to set the Compare 0 value of
     * the first (index = 0) Shift Register of the TCPWM0 block.
     */
    #define MY_TCPWM_SHIFTREG_NUM   (0UL)

    /* Get the currently existing compare value */
    uint32_t compare = Cy_TCPWM_ShiftReg_GetCompare0Val(TCPWM0, MY_TCPWM_SHIFTREG_NUM);
    /* Modify the compare value here */
    Cy_TCPWM_ShiftReg_SetCompare0Val(TCPWM0, MY_TCPWM_SHIFTREG_NUM, compare);
Return

Compare 0 value.

Parameters
  • base: The pointer to a TCPWM instance.

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

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

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

    /* Scenario: there is a need to modify buffered compare 0 value
     * for the first (index = 0) Shift Register 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_SHIFTREG_NUM   (0UL)

    /* Get the currently existing compare value */
    uint32_t compare = Cy_TCPWM_ShiftReg_GetCompare0BufVal(TCPWM0, MY_TCPWM_SHIFTREG_NUM);
    /* Modify the compare value here */
    Cy_TCPWM_ShiftReg_SetCompare0BufVal(TCPWM0, MY_TCPWM_SHIFTREG_NUM, compare);
    /* Now the compare 0 and buffered compare 0 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_ShiftReg_GetCompare0BufVal (TCPWM_Type const *base, uint32_t cntNum)

Returns the buffered compare 0 value.

    /* Scenario: there is a need to modify buffered compare 0 value
     * for the first (index = 0) Shift Register 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_SHIFTREG_NUM   (0UL)

    /* Get the currently existing compare value */
    uint32_t compare = Cy_TCPWM_ShiftReg_GetCompare0BufVal(TCPWM0, MY_TCPWM_SHIFTREG_NUM);
    /* Modify the compare value here */
    Cy_TCPWM_ShiftReg_SetCompare0BufVal(TCPWM0, MY_TCPWM_SHIFTREG_NUM, compare);
    /* Now the compare 0 and buffered compare 0 values can be swapped using either HW input or Cy_TCPWM_TriggerCaptureOrSwap_Single */
Return

Buffered compare 0 value.

Parameters
  • base: The pointer to a TCPWM instance.

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

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

Enables the comparison swap of compare 0 and compareBuf 0 on corresponding command or external trigger.

    /* Scenario: There is a need to enable the compare swapping feature for
     * the first (index = 0) Shift Register 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_SHIFTREG_NUM   (0UL)

    Cy_TCPWM_ShiftReg_EnableCompare0Swap(TCPWM0, MY_TCPWM_SHIFTREG_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_ShiftReg_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 Compare 1 value.

__STATIC_INLINE uint32_t Cy_TCPWM_ShiftReg_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_ShiftReg_SetCompare1BufVal (TCPWM_Type *base, uint32_t cntNum, uint32_t compareBuf1)

Sets the buffered 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.

  • compareBuf1: The buffered Compare 1 value.

__STATIC_INLINE uint32_t Cy_TCPWM_ShiftReg_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_ShiftReg_EnableCompare1Swap (TCPWM_Type *base, uint32_t cntNum, bool enable)

Enables the comparison swap of compare 1 and compareBuf 1 on corresponding command or external trigger.

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_ShiftReg_SetCounter (TCPWM_Type *base, uint32_t cntNum, uint32_t count)

Sets the value of the counter.

    /* Scenario: there is a need to set the counter value for
     * the first (index = 0) counter of the TCPWM0 block
     */
    #define MY_TCPWM_SHIFTREG_NUM   (0UL)
    #define MY_TCPWM_SHIFTREG_MASK  (1UL << MY_TCPWM_SHIFTREG_NUM)
    #define MY_TCPWM_SHIFTREG_VAL   (100UL)
    uint32_t count;

    Cy_TCPWM_TriggerStopOrKill_Single(TCPWM0, MY_TCPWM_SHIFTREG_MASK);
    Cy_TCPWM_ShiftReg_SetCounter(TCPWM0, MY_TCPWM_SHIFTREG_NUM, MY_TCPWM_SHIFTREG_VAL);

    count = Cy_TCPWM_ShiftReg_GetCounter(TCPWM0, MY_TCPWM_SHIFTREG_NUM);
    if( count == MY_TCPWM_SHIFTREG_VAL)
    {
        /* Counter value is set correctly */
    }

    Cy_TCPWM_TriggerReloadOrIndex_Single(TCPWM0, MY_TCPWM_SHIFTREG_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_ShiftReg_GetCounter (TCPWM_Type const *base, uint32_t cntNum)

Returns the value in the counter.

    /* Scenario: there is a need to set the counter value for
     * the first (index = 0) counter of the TCPWM0 block
     */
    #define MY_TCPWM_SHIFTREG_NUM   (0UL)
    #define MY_TCPWM_SHIFTREG_MASK  (1UL << MY_TCPWM_SHIFTREG_NUM)
    #define MY_TCPWM_SHIFTREG_VAL   (100UL)
    uint32_t count;

    Cy_TCPWM_TriggerStopOrKill_Single(TCPWM0, MY_TCPWM_SHIFTREG_MASK);
    Cy_TCPWM_ShiftReg_SetCounter(TCPWM0, MY_TCPWM_SHIFTREG_NUM, MY_TCPWM_SHIFTREG_VAL);

    count = Cy_TCPWM_ShiftReg_GetCounter(TCPWM0, MY_TCPWM_SHIFTREG_NUM);
    if( count == MY_TCPWM_SHIFTREG_VAL)
    {
        /* Counter value is set correctly */
    }

    Cy_TCPWM_TriggerReloadOrIndex_Single(TCPWM0, MY_TCPWM_SHIFTREG_MASK);
Return

The current counter value.

Parameters
  • base: The pointer to a TCPWM instance.

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

__STATIC_INLINE void Cy_TCPWM_ShiftReg_SetTaps (TCPWM_Type *base, uint32_t cntNum, uint32_t taps)

Sets which taps are enabled.

    /* Scenario: there is a need to set the taps value for
     * the first (index = 0) counter of the TCPWM0 block
     */
    #define MY_TCPWM_SHIFTREG_NUM   (0UL)
    #define MY_TCPWM_SHIFTREG_MASK  (1UL << MY_TCPWM_SHIFTREG_NUM)
    #define MY_TCPWM_SHIFTREG_TAPS  (1UL)
    uint32_t tapsEnabled;

    Cy_TCPWM_TriggerStopOrKill_Single(TCPWM0, MY_TCPWM_SHIFTREG_MASK);
    Cy_TCPWM_ShiftReg_SetTaps(TCPWM0, MY_TCPWM_SHIFTREG_NUM, MY_TCPWM_SHIFTREG_VAL);

    tapsEnabled = Cy_TCPWM_ShiftReg_GetTaps(TCPWM0, MY_TCPWM_SHIFTREG_NUM);
    if( tapsEnabled == MY_TCPWM_SHIFTREG_TAPS)
    {
        /* taps value is set correctly */
    }

    Cy_TCPWM_TriggerReloadOrIndex_Single(TCPWM0, MY_TCPWM_SHIFTREG_MASK);
Parameters
  • base: The pointer to a TCPWM instance.

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

  • taps: The taps that will be enabled.

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

Returns which taps are enabled.

    /* Scenario: there is a need to set the taps value for
     * the first (index = 0) counter of the TCPWM0 block
     */
    #define MY_TCPWM_SHIFTREG_NUM   (0UL)
    #define MY_TCPWM_SHIFTREG_MASK  (1UL << MY_TCPWM_SHIFTREG_NUM)
    #define MY_TCPWM_SHIFTREG_TAPS  (1UL)
    uint32_t tapsEnabled;

    Cy_TCPWM_TriggerStopOrKill_Single(TCPWM0, MY_TCPWM_SHIFTREG_MASK);
    Cy_TCPWM_ShiftReg_SetTaps(TCPWM0, MY_TCPWM_SHIFTREG_NUM, MY_TCPWM_SHIFTREG_VAL);

    tapsEnabled = Cy_TCPWM_ShiftReg_GetTaps(TCPWM0, MY_TCPWM_SHIFTREG_NUM);
    if( tapsEnabled == MY_TCPWM_SHIFTREG_TAPS)
    {
        /* taps value is set correctly */
    }

    Cy_TCPWM_TriggerReloadOrIndex_Single(TCPWM0, MY_TCPWM_SHIFTREG_MASK);
Return

Returns which taps are enabled.

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

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

__STATIC_INLINE uint32_t Cy_TCPWM_ShiftReg_LineOutStatus (TCPWM_Type const *base, uint32_t cntNum, uint32_t shiftRegOutSelect)

Returns the current level of the selected Shift Register output line.

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

    if (Cy_TCPWM_ShiftReg_LineOutStatus(TCPWM0, MY_TCPWM_SHIFTREG_NUM, CY_TCPWM_SHIFTREG_LINE_OUT))
    {
        /* Shift Register Line is High */
    }
    else
    {
        /* Shift Register Line is Low */
    }
Return

The current Shift Register output line level.

Parameters
  • base: The pointer to a TCPWM instance.

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

  • shiftRegOutSelect: Defines which Shift Register output line is being checked: line_out or line_out_inv.