PSoC 6 Peripheral Driver Library

General Description

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. More...
 
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. More...
 
__STATIC_INLINE void Cy_TCPWM_Counter_Enable (TCPWM_Type *base, uint32_t cntNum)
 Enables the counter in the TCPWM block for the Counter operation. More...
 
__STATIC_INLINE void Cy_TCPWM_Counter_Disable (TCPWM_Type *base, uint32_t cntNum)
 Disables the counter in the TCPWM block. More...
 
__STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetStatus (TCPWM_Type const *base, uint32_t cntNum)
 Returns the status of the Counter Timer. More...
 
__STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetCapture (TCPWM_Type const *base, uint32_t cntNum)
 Returns the capture value when the capture mode is enabled. More...
 
__STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetCaptureBuf (TCPWM_Type const *base, uint32_t cntNum)
 Returns the buffered capture value when the capture mode is enabled. More...
 
__STATIC_INLINE void Cy_TCPWM_Counter_SetCompare0 (TCPWM_Type *base, uint32_t cntNum, uint32_t compare0)
 Sets the compare value for Compare0 when the compare mode is enabled. More...
 
__STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetCompare0 (TCPWM_Type const *base, uint32_t cntNum)
 Returns compare value 0. More...
 
__STATIC_INLINE void Cy_TCPWM_Counter_SetCompare1 (TCPWM_Type *base, uint32_t cntNum, uint32_t compare1)
 Sets the compare value for Compare1 when the compare mode is enabled. More...
 
__STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetCompare1 (TCPWM_Type const *base, uint32_t cntNum)
 Returns compare value 1. More...
 
__STATIC_INLINE void Cy_TCPWM_Counter_EnableCompareSwap (TCPWM_Type *base, uint32_t cntNum, bool enable)
 Enables the comparison swap when the comparison value is true. More...
 
__STATIC_INLINE void Cy_TCPWM_Counter_SetCounter (TCPWM_Type *base, uint32_t cntNum, uint32_t count)
 Sets the value of the counter. More...
 
__STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetCounter (TCPWM_Type const *base, uint32_t cntNum)
 Returns the value in the counter. More...
 
__STATIC_INLINE void Cy_TCPWM_Counter_SetPeriod (TCPWM_Type *base, uint32_t cntNum, uint32_t period)
 Sets the value of the period register. More...
 
__STATIC_INLINE uint32_t Cy_TCPWM_Counter_GetPeriod (TCPWM_Type const *base, uint32_t cntNum)
 Returns the value in the period register. More...
 

Function Documentation

◆ Cy_TCPWM_Counter_Init()

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.

Parameters
baseThe pointer to a TCPWM instance.
cntNumThe Counter instance number in the selected TCPWM.
configThe pointer to configuration structure. See cy_stc_tcpwm_counter_config_t.
Returns
error / status code. See cy_en_tcpwm_status_t.
Function Usage
{
/* .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 Compare0 */
/* .compare0 = */ 33UL,
/* .compare1 = */ 66UL,
/* .enableCompareSwap = */ true, /* Upon a compare event, swap the Compare0 and Compare1 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) */
};
/* Scenario: there is need to initialize
* the first (index = 0) counter of the TCPWM0 block
* with the previously defined configuration settings
*/
#define MY_TCPWM_CNT_NUM (0UL)
#define MY_TCPWM_CNT_MASK (1UL << MY_TCPWM_CNT_NUM)
if (CY_TCPWM_SUCCESS != Cy_TCPWM_Counter_Init(TCPWM0, MY_TCPWM_CNT_NUM, &config))
{
/* Handle possible errors */
}
/* Enable the initialized counter */
Cy_TCPWM_Counter_Enable(TCPWM0, MY_TCPWM_CNT_NUM);
/* Then start the counter */
Cy_TCPWM_TriggerStart(TCPWM0, MY_TCPWM_CNT_MASK);

◆ Cy_TCPWM_Counter_DeInit()

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.

Parameters
baseThe pointer to a TCPWM instance.
cntNumThe Counter instance number in the selected TCPWM.
configThe pointer to configuration structure. See cy_stc_tcpwm_counter_config_t.
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);

◆ Cy_TCPWM_Counter_Enable()

__STATIC_INLINE void Cy_TCPWM_Counter_Enable ( TCPWM_Type base,
uint32_t  cntNum 
)

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

Parameters
baseThe pointer to a TCPWM instance.
cntNumThe Counter instance number in the selected TCPWM.
Function Usage
/* Scenario: there is need to initialize
* the first (index = 0) counter of the TCPWM0 block
* with the previously defined configuration settings
*/
#define MY_TCPWM_CNT_NUM (0UL)
#define MY_TCPWM_CNT_MASK (1UL << MY_TCPWM_CNT_NUM)
if (CY_TCPWM_SUCCESS != Cy_TCPWM_Counter_Init(TCPWM0, MY_TCPWM_CNT_NUM, &config))
{
/* Handle possible errors */
}
/* Enable the initialized counter */
Cy_TCPWM_Counter_Enable(TCPWM0, MY_TCPWM_CNT_NUM);
/* Then start the counter */
Cy_TCPWM_TriggerStart(TCPWM0, MY_TCPWM_CNT_MASK);

◆ Cy_TCPWM_Counter_Disable()

__STATIC_INLINE void Cy_TCPWM_Counter_Disable ( TCPWM_Type base,
uint32_t  cntNum 
)

Disables the counter in the TCPWM block.

Parameters
baseThe pointer to a TCPWM instance.
cntNumThe Counter instance number in the selected TCPWM.
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);

◆ Cy_TCPWM_Counter_GetStatus()

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

Returns the status of the Counter Timer.

Parameters
baseThe pointer to a TCPWM instance.
cntNumThe Counter instance number in the selected TCPWM.
Returns
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
*/
#define MY_TCPWM_CNT_NUM (0UL)
Cy_TCPWM_Counter_GetStatus(TCPWM0, MY_TCPWM_CNT_NUM)))
{
/* The Counter is running */
}

◆ Cy_TCPWM_Counter_GetCapture()

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

Returns the capture value when the capture mode is enabled.

Parameters
baseThe pointer to a TCPWM instance.
cntNumThe Counter instance number in the selected TCPWM.
Returns
The capture 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)
#define MY_TCPWM_CNT_MASK (1UL << MY_TCPWM_CNT_NUM)
Cy_TCPWM_TriggerCaptureOrSwap(TCPWM0, MY_TCPWM_CNT_MASK);
/* after some time */
Cy_TCPWM_TriggerCaptureOrSwap(TCPWM0, MY_TCPWM_CNT_MASK);
/* Now we can get the latest captured value
* (captured during the second call of Cy_TCPWM_TriggerCaptureOrSwap)
*/
uint32_t capture = Cy_TCPWM_Counter_GetCapture(TCPWM0, MY_TCPWM_CNT_NUM);
/* Also the previous captured value
* (captured during the first call of Cy_TCPWM_TriggerCaptureOrSwap)
* is available by the next way
*/
uint32_t captureBuf = Cy_TCPWM_Counter_GetCaptureBuf(TCPWM0, MY_TCPWM_CNT_NUM);

◆ Cy_TCPWM_Counter_GetCaptureBuf()

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

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

Parameters
baseThe pointer to a TCPWM instance.
cntNumThe Counter instance number in the selected TCPWM.
Returns
The buffered capture 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)
#define MY_TCPWM_CNT_MASK (1UL << MY_TCPWM_CNT_NUM)
Cy_TCPWM_TriggerCaptureOrSwap(TCPWM0, MY_TCPWM_CNT_MASK);
/* after some time */
Cy_TCPWM_TriggerCaptureOrSwap(TCPWM0, MY_TCPWM_CNT_MASK);
/* Now we can get the latest captured value
* (captured during the second call of Cy_TCPWM_TriggerCaptureOrSwap)
*/
uint32_t capture = Cy_TCPWM_Counter_GetCapture(TCPWM0, MY_TCPWM_CNT_NUM);
/* Also the previous captured value
* (captured during the first call of Cy_TCPWM_TriggerCaptureOrSwap)
* is available by the next way
*/
uint32_t captureBuf = Cy_TCPWM_Counter_GetCaptureBuf(TCPWM0, MY_TCPWM_CNT_NUM);

◆ Cy_TCPWM_Counter_SetCompare0()

__STATIC_INLINE void Cy_TCPWM_Counter_SetCompare0 ( TCPWM_Type base,
uint32_t  cntNum,
uint32_t  compare0 
)

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

Parameters
baseThe pointer to a TCPWM instance.
cntNumThe Counter instance number in the selected TCPWM.
compare0The Compare0 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)
#define MY_TCPWM_CNT_MASK (1UL << MY_TCPWM_CNT_NUM)
/* Stop the counter for clear transition */
Cy_TCPWM_TriggerStopOrKill(TCPWM0, MY_TCPWM_CNT_MASK);
/* Get the currently existing Compare0 value */
uint32_t compare = Cy_TCPWM_Counter_GetCompare0(TCPWM0, MY_TCPWM_CNT_NUM);
/* Modify the compare value here */
Cy_TCPWM_Counter_SetCompare0(TCPWM0, MY_TCPWM_CNT_NUM, compare);
/* Restart the counter with the new Compare0 value */
Cy_TCPWM_TriggerReloadOrIndex(TCPWM0, MY_TCPWM_CNT_MASK);

◆ Cy_TCPWM_Counter_GetCompare0()

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

Returns compare value 0.

Parameters
baseThe pointer to a TCPWM instance.
cntNumThe Counter instance number in the selected TCPWM.
Returns
Compare value 0.
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)
#define MY_TCPWM_CNT_MASK (1UL << MY_TCPWM_CNT_NUM)
/* Stop the counter for clear transition */
Cy_TCPWM_TriggerStopOrKill(TCPWM0, MY_TCPWM_CNT_MASK);
/* Get the currently existing Compare0 value */
uint32_t compare = Cy_TCPWM_Counter_GetCompare0(TCPWM0, MY_TCPWM_CNT_NUM);
/* Modify the compare value here */
Cy_TCPWM_Counter_SetCompare0(TCPWM0, MY_TCPWM_CNT_NUM, compare);
/* Restart the counter with the new Compare0 value */
Cy_TCPWM_TriggerReloadOrIndex(TCPWM0, MY_TCPWM_CNT_MASK);

◆ Cy_TCPWM_Counter_SetCompare1()

__STATIC_INLINE void Cy_TCPWM_Counter_SetCompare1 ( TCPWM_Type base,
uint32_t  cntNum,
uint32_t  compare1 
)

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

Parameters
baseThe pointer to a TCPWM instance.
cntNumThe Counter instance number in the selected TCPWM.
compare1The Compare1 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 Compare1 value */
uint32_t compare = Cy_TCPWM_Counter_GetCompare1(TCPWM0, MY_TCPWM_CNT_NUM);
/* Modify the compare value here */
Cy_TCPWM_Counter_SetCompare1(TCPWM0, MY_TCPWM_CNT_NUM, compare);
/* Now the Compare0 and Compare1 values can be swapped using Cy_TCPWM_TriggerCaptureOrSwap */

◆ Cy_TCPWM_Counter_GetCompare1()

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

Returns compare value 1.

Parameters
baseThe pointer to a TCPWM instance.
cntNumThe Counter instance number in the selected TCPWM.
Returns
Compare value 1.
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 Compare1 value */
uint32_t compare = Cy_TCPWM_Counter_GetCompare1(TCPWM0, MY_TCPWM_CNT_NUM);
/* Modify the compare value here */
Cy_TCPWM_Counter_SetCompare1(TCPWM0, MY_TCPWM_CNT_NUM, compare);
/* Now the Compare0 and Compare1 values can be swapped using Cy_TCPWM_TriggerCaptureOrSwap */

◆ Cy_TCPWM_Counter_EnableCompareSwap()

__STATIC_INLINE void Cy_TCPWM_Counter_EnableCompareSwap ( TCPWM_Type base,
uint32_t  cntNum,
bool  enable 
)

Enables the comparison swap when the comparison value is true.

Parameters
baseThe pointer to a TCPWM instance.
cntNumThe Counter instance number in the selected TCPWM.
enabletrue = swap enabled, false = swap disabled
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_EnableCompareSwap(TCPWM0, MY_TCPWM_CNT_NUM, true);
/* Now the Compare0 and Compare1 values can be swapped using Cy_TCPWM_TriggerCaptureOrSwap */

◆ Cy_TCPWM_Counter_SetCounter()

__STATIC_INLINE void Cy_TCPWM_Counter_SetCounter ( TCPWM_Type base,
uint32_t  cntNum,
uint32_t  count 
)

Sets the value of the counter.

Parameters
baseThe pointer to a TCPWM instance.
cntNumThe Counter instance number in the selected TCPWM.
countThe value to write into 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_MASK (1UL << MY_TCPWM_CNT_NUM)
#define MY_TCPWM_CNT_VAL (100UL)
Cy_TCPWM_TriggerStopOrKill(TCPWM0, MY_TCPWM_CNT_MASK);
Cy_TCPWM_Counter_SetCounter(TCPWM0, MY_TCPWM_CNT_NUM, MY_TCPWM_CNT_VAL);
Cy_TCPWM_TriggerStart(TCPWM0, MY_TCPWM_CNT_MASK);

◆ Cy_TCPWM_Counter_GetCounter()

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

Returns the value in the counter.

Parameters
baseThe pointer to a TCPWM instance.
cntNumThe Counter instance number in the selected TCPWM.
Returns
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);

◆ Cy_TCPWM_Counter_SetPeriod()

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

Sets the value of the period register.

Parameters
baseThe pointer to a TCPWM instance.
cntNumThe Counter instance number in the selected TCPWM.
periodThe value to write into a period.
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);

◆ Cy_TCPWM_Counter_GetPeriod()

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

Returns the value in the period register.

Parameters
baseThe pointer to a TCPWM instance.
cntNumThe Counter instance number in the selected TCPWM.
Returns
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);