PSoC 6 Peripheral Driver Library

General Description

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. More...
 
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. More...
 
__STATIC_INLINE void Cy_TCPWM_PWM_Enable (TCPWM_Type *base, uint32_t cntNum)
 Enables the counter in the TCPWM block for the PWM operation. More...
 
__STATIC_INLINE void Cy_TCPWM_PWM_Disable (TCPWM_Type *base, uint32_t cntNum)
 Disables the counter in the TCPWM block. More...
 
__STATIC_INLINE uint32_t Cy_TCPWM_PWM_GetStatus (TCPWM_Type const *base, uint32_t cntNum)
 Returns the status of the PWM. More...
 
__STATIC_INLINE void Cy_TCPWM_PWM_SetCompare0 (TCPWM_Type *base, uint32_t cntNum, uint32_t compare0)
 Sets the compare value for Compare0 when the compare mode enabled. More...
 
__STATIC_INLINE uint32_t Cy_TCPWM_PWM_GetCompare0 (TCPWM_Type const *base, uint32_t cntNum)
 Returns compare value 0. More...
 
__STATIC_INLINE void Cy_TCPWM_PWM_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_PWM_GetCompare1 (TCPWM_Type const *base, uint32_t cntNum)
 Returns compare value 1. More...
 
__STATIC_INLINE void Cy_TCPWM_PWM_EnableCompareSwap (TCPWM_Type *base, uint32_t cntNum, bool enable)
 Enables the comparison swap on OV and/or UN, depending on the PWM alignment. More...
 
__STATIC_INLINE void Cy_TCPWM_PWM_SetCounter (TCPWM_Type *base, uint32_t cntNum, uint32_t count)
 Sets the value of the counter. More...
 
__STATIC_INLINE uint32_t Cy_TCPWM_PWM_GetCounter (TCPWM_Type const *base, uint32_t cntNum)
 Returns the value in the counter. More...
 
__STATIC_INLINE void Cy_TCPWM_PWM_SetPeriod0 (TCPWM_Type *base, uint32_t cntNum, uint32_t period0)
 Sets the value of the period register. More...
 
__STATIC_INLINE uint32_t Cy_TCPWM_PWM_GetPeriod0 (TCPWM_Type const *base, uint32_t cntNum)
 Returns the value in the period register. More...
 
__STATIC_INLINE void Cy_TCPWM_PWM_SetPeriod1 (TCPWM_Type *base, uint32_t cntNum, uint32_t period1)
 Sets the value of the period register. More...
 
__STATIC_INLINE uint32_t Cy_TCPWM_PWM_GetPeriod1 (TCPWM_Type const *base, uint32_t cntNum)
 Returns the value in the period register. More...
 
__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. More...
 

Function Documentation

◆ Cy_TCPWM_PWM_Init()

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.

Parameters
baseThe pointer to a TCPWM instance.
cntNumThe Counter instance number in the selected TCPWM.
configThe pointer to a configuration structure. See cy_stc_tcpwm_pwm_config_t.
Returns
error / status code. See cy_en_tcpwm_status_t.
Function Usage
{
/* .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 */
};
/* Scenario: there is need to initialize
* the first (index = 0) PWM of the TCPWM0 block
* with the previously defined configuration settings
*/
#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, &config))
{
/* Handle possible errors */
}
/* Enable the initialized PWM */
Cy_TCPWM_PWM_Enable(TCPWM0, MY_TCPWM_PWM_NUM);
/* Then start the PWM */
Cy_TCPWM_TriggerReloadOrIndex(TCPWM0, MY_TCPWM_PWM_MASK);

◆ Cy_TCPWM_PWM_DeInit()

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.

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

◆ Cy_TCPWM_PWM_Enable()

__STATIC_INLINE void Cy_TCPWM_PWM_Enable ( TCPWM_Type base,
uint32_t  cntNum 
)

Enables the counter in the TCPWM block for the PWM 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) PWM of the TCPWM0 block
* with the previously defined configuration settings
*/
#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, &config))
{
/* Handle possible errors */
}
/* Enable the initialized PWM */
Cy_TCPWM_PWM_Enable(TCPWM0, MY_TCPWM_PWM_NUM);
/* Then start the PWM */
Cy_TCPWM_TriggerReloadOrIndex(TCPWM0, MY_TCPWM_PWM_MASK);

◆ Cy_TCPWM_PWM_Disable()

__STATIC_INLINE void Cy_TCPWM_PWM_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_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);

◆ Cy_TCPWM_PWM_GetStatus()

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

Returns the status of the PWM.

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

◆ Cy_TCPWM_PWM_SetCompare0()

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

Sets the compare value for Compare0 when the compare mode 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 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_GetCompare0(TCPWM0, MY_TCPWM_PWM_NUM);
/* Modify the compare value here */
Cy_TCPWM_PWM_SetCompare0(TCPWM0, MY_TCPWM_PWM_NUM, compare);

◆ Cy_TCPWM_PWM_GetCompare0()

__STATIC_INLINE uint32_t Cy_TCPWM_PWM_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 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_GetCompare0(TCPWM0, MY_TCPWM_PWM_NUM);
/* Modify the compare value here */
Cy_TCPWM_PWM_SetCompare0(TCPWM0, MY_TCPWM_PWM_NUM, compare);

◆ Cy_TCPWM_PWM_SetCompare1()

__STATIC_INLINE void Cy_TCPWM_PWM_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 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_GetCompare1(TCPWM0, MY_TCPWM_PWM_NUM);
/* Modify the compare value here */
Cy_TCPWM_PWM_SetCompare1(TCPWM0, MY_TCPWM_PWM_NUM, compare);
/* Now the compare 0 and 1 values can be swapped using either HW input or Cy_TCPWM_TriggerCaptureOrSwap */

◆ Cy_TCPWM_PWM_GetCompare1()

__STATIC_INLINE uint32_t Cy_TCPWM_PWM_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 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_GetCompare1(TCPWM0, MY_TCPWM_PWM_NUM);
/* Modify the compare value here */
Cy_TCPWM_PWM_SetCompare1(TCPWM0, MY_TCPWM_PWM_NUM, compare);
/* Now the compare 0 and 1 values can be swapped using either HW input or Cy_TCPWM_TriggerCaptureOrSwap */

◆ Cy_TCPWM_PWM_EnableCompareSwap()

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

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

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) 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_EnableCompareSwap(TCPWM0, MY_TCPWM_PWM_NUM, true);
/* Now the compare 0 and 1 values can be swapped using either HW input or Cy_TCPWM_TriggerCaptureOrSwap */

◆ Cy_TCPWM_PWM_SetCounter()

__STATIC_INLINE void Cy_TCPWM_PWM_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_PWM_NUM (0UL)
#define MY_TCPWM_PWM_MASK (1UL << MY_TCPWM_PWM_NUM)
#define MY_TCPWM_PWM_VAL (100UL)
Cy_TCPWM_TriggerStopOrKill(TCPWM0, MY_TCPWM_PWM_MASK);
Cy_TCPWM_PWM_SetCounter(TCPWM0, MY_TCPWM_PWM_NUM, MY_TCPWM_PWM_VAL);
Cy_TCPWM_TriggerReloadOrIndex(TCPWM0, MY_TCPWM_PWM_MASK);

◆ Cy_TCPWM_PWM_GetCounter()

__STATIC_INLINE uint32_t Cy_TCPWM_PWM_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
* 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);

◆ Cy_TCPWM_PWM_SetPeriod0()

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

Sets the value of the period register.

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

◆ Cy_TCPWM_PWM_GetPeriod0()

__STATIC_INLINE uint32_t Cy_TCPWM_PWM_GetPeriod0 ( 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 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 Period0 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 Period1.
*/
#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);

◆ Cy_TCPWM_PWM_SetPeriod1()

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

Sets the value of the period register.

Parameters
baseThe pointer to a TCPWM instance.
cntNumThe Counter instance number in the selected TCPWM.
period1The value to write into a period1.
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 */

◆ Cy_TCPWM_PWM_GetPeriod1()

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

Returns the value in the period register.

Parameters
baseThe pointer to a COUNTER PWM instance.
cntNumThe Counter instance number in the selected TCPWM.
Returns
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 */

◆ Cy_TCPWM_PWM_EnablePeriodSwap()

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

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 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 */