Functions¶
-
group
group_tcpwm_functions_common
Functions
-
__STATIC_INLINE void Cy_TCPWM_Enable_Multiple (TCPWM_Type *base, uint32_t counters)
Enables the counter(s) in the TCPWM block.
Multiple blocks can be started simultaneously.
note
supported only in TCPWM_ver1
- Function Usage
/* Scenario: there is a need to enable counters #1, #5 and #6 in the TCPWM0 * block. * Multiple counters will be enabled simultaneously using * MY_TCPWM_CNT_MULT_MASK (multiple bit masks ORed together). */ #define MY_TCPWM_CNT_1 (1UL) #define MY_TCPWM_CNT_5 (5UL) #define MY_TCPWM_CNT_6 (6UL) #define MY_TCPWM_CNT_MULT_MASK (uint32_t)((1UL << MY_TCPWM_CNT_1) |\ (1UL << MY_TCPWM_CNT_5) |\ (1UL << MY_TCPWM_CNT_6)) Cy_TCPWM_Enable_Multiple(TCPWM0, MY_TCPWM_CNT_MULT_MASK); /* Scenario: These counters are configured to generate signals that have a phase * dependency to each other. These must all be enabled at the same time * to preserve this phase relationship. */ Cy_TCPWM_TriggerStart(TCPWM0, MY_TCPWM_CNT_MULT_MASK);
- Parameters
base – The pointer to a TCPWM instance.
counters – A bit field representing each counter in the TCPWM block.
-
__STATIC_INLINE void Cy_TCPWM_Disable_Multiple (TCPWM_Type *base, uint32_t counters)
Disables the counter(s) in the TCPWM block.
Multiple TCPWM can be disabled simultaneously.
note
supported only in TCPWM_ver1
- Function Usage
/* Scenario: there is a need to disable counters #1, #5 and #6 in the TCPWM0 * block. */ #define MY_TCPWM_CNT_1 (1UL) #define MY_TCPWM_CNT_5 (5UL) #define MY_TCPWM_CNT_6 (6UL) #define MY_TCPWM_CNT_MULT_MASK (uint32_t)((1UL << MY_TCPWM_CNT_1) |\ (1UL << MY_TCPWM_CNT_5) |\ (1UL << MY_TCPWM_CNT_6)) Cy_TCPWM_Disable_Multiple(TCPWM0, MY_TCPWM_CNT_MULT_MASK);
- Parameters
base – The pointer to a TCPWM instance.
counters – A bit field representing each counter in the TCPWM block.
-
__STATIC_INLINE void Cy_TCPWM_TriggerStart (TCPWM_Type *base, uint32_t counters)
Triggers a software start on the selected TCPWMs.
note
supported only in TCPWM_ver1
- Function Usage
/* Scenario: there is a need to enable counters #1, #5 and #6 in the TCPWM0 * block. * Multiple counters will be enabled simultaneously using * MY_TCPWM_CNT_MULT_MASK (multiple bit masks ORed together). */ #define MY_TCPWM_CNT_1 (1UL) #define MY_TCPWM_CNT_5 (5UL) #define MY_TCPWM_CNT_6 (6UL) #define MY_TCPWM_CNT_MULT_MASK (uint32_t)((1UL << MY_TCPWM_CNT_1) |\ (1UL << MY_TCPWM_CNT_5) |\ (1UL << MY_TCPWM_CNT_6)) Cy_TCPWM_Enable_Multiple(TCPWM0, MY_TCPWM_CNT_MULT_MASK); /* Scenario: These counters are configured to generate signals that have a phase * dependency to each other. These must all be enabled at the same time * to preserve this phase relationship. */ Cy_TCPWM_TriggerStart(TCPWM0, MY_TCPWM_CNT_MULT_MASK);
- Parameters
base – The pointer to a TCPWM instance.
counters – A bit field representing each counter in the TCPWM block.
-
__STATIC_INLINE void Cy_TCPWM_TriggerReloadOrIndex (TCPWM_Type *base, uint32_t counters)
Triggers a software reload event (or index in QuadDec mode).
note
supported only in TCPWM_ver1
- Function Usage
/* Scenario: there is a need to trigger a software reload event for * the first (index = 0) counter of the TCPWM0 block. * This causes the reloading of the counter register with the period value. */ #define MY_TCPWM_CNT_NUM (0UL) #define MY_TCPWM_CNT_MASK (1UL << MY_TCPWM_CNT_NUM) Cy_TCPWM_TriggerReloadOrIndex(TCPWM0, MY_TCPWM_CNT_MASK);
- Parameters
base – The pointer to a TCPWM instance
counters – A bit field representing each counter in the TCPWM block.
-
__STATIC_INLINE void Cy_TCPWM_TriggerStopOrKill (TCPWM_Type *base, uint32_t counters)
Triggers a stop in the Timer Counter mode, or a kill in the PWM mode.
note
supported only in TCPWM_ver1
- Function Usage
/* Scenario: there is a need to kill 3 PWM signals * (PWM runs in \ref CY_TCPWM_PWM_STOP_ON_KILL mode) at the same time * as they are all used e.g. to drive an RGB LED. So there will be a clean * transition from white light to no light. */ #define MY_TCPWM_CNT_1 (1UL) #define MY_TCPWM_CNT_5 (5UL) #define MY_TCPWM_CNT_6 (6UL) #define MY_TCPWM_CNT_MULT_MASK (uint32_t)((1UL << MY_TCPWM_CNT_1) |\ (1UL << MY_TCPWM_CNT_5) |\ (1UL << MY_TCPWM_CNT_6)) Cy_TCPWM_TriggerStopOrKill(TCPWM0, MY_TCPWM_CNT_MULT_MASK); /* Then continue to operate from the point they have been stopped. */ Cy_TCPWM_TriggerStart(TCPWM0, MY_TCPWM_CNT_MULT_MASK);
- Parameters
base – The pointer to a TCPWM instance.
counters – A bit field representing each counter in the TCPWM block.
-
__STATIC_INLINE void Cy_TCPWM_TriggerCaptureOrSwap (TCPWM_Type *base, uint32_t counters)
Triggers a Capture in the Timer Counter mode, and a Swap in the PWM mode.
note
supported only in TCPWM_ver1
- 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.
counters – A bit field representing each counter in the TCPWM block.
-
__STATIC_INLINE void Cy_TCPWM_Enable_Single (TCPWM_Type *base, uint32_t cntNum)
Enables specified counter.
- Parameters
base – The pointer to a TCPWM instance.
cntNum – The Counter instance number in the selected TCPWM.
-
__STATIC_INLINE void Cy_TCPWM_Disable_Single (TCPWM_Type *base, uint32_t cntNum)
Disable specified counter.
- Parameters
base – The pointer to a TCPWM instance.
cntNum – The Counter instance number in the selected TCPWM.
-
__STATIC_INLINE uint32_t Cy_TCPWM_GetInterruptStatus (TCPWM_Type const *base, uint32_t cntNum)
Returns which event triggered the interrupt.
- Function Usage
/* Scenario: there is a need to check all the pending interrupts of * the first (index = 0) counter of the TCPWM0 block. */ #define MY_TCPWM_CNT_NUM (0UL) uint32_t interrupts = Cy_TCPWM_GetInterruptStatus(TCPWM0, MY_TCPWM_CNT_NUM); /* Now the 'interrupts' contains all the currently pending interrupt masks */ if(0UL != (CY_TCPWM_INT_ON_TC & interrupts)) { /* There is a pending Terminal Count interrupt */ }
- Parameters
base – The pointer to a TCPWM instance.
cntNum – The Counter instance number in the selected TCPWM.
- Returns
-
__STATIC_INLINE void Cy_TCPWM_ClearInterrupt (TCPWM_Type *base, uint32_t cntNum, uint32_t source)
Clears Active Interrupt Source.
- Function Usage
/* Scenario: inside the TCPWM interrupt handler for * the first (index = 0) counter of the TCPWM0 block. */ #define MY_TCPWM_CNT_NUM (0UL) /* Get all the enabled pending interrupts */ uint32_t interrupts = Cy_TCPWM_GetInterruptStatusMasked(TCPWM0, MY_TCPWM_CNT_NUM); if (0UL != (CY_TCPWM_INT_ON_TC & interrupts)) { /* Handle the Terminal Count event */ } if (0UL != (CY_TCPWM_INT_ON_CC & interrupts)) { /* Handle the Compare/Capture event */ } /* Clear the interrupt */ Cy_TCPWM_ClearInterrupt(TCPWM0, MY_TCPWM_CNT_NUM, interrupts);
- Parameters
base – The pointer to a TCPWM instance.
cntNum – The Counter instance number in the selected TCPWM.
source – source to clear. See Interrupt Sources
-
__STATIC_INLINE void Cy_TCPWM_SetInterrupt (TCPWM_Type *base, uint32_t cntNum, uint32_t source)
Triggers an interrupt via a software write.
- Function Usage
/* Scenario: there is a need to set a terminal count interrupt by SW for * the first (index = 0) counter of the TCPWM0 block. */ #define MY_TCPWM_CNT_NUM (0UL) /* Check if the desired interrupt is enabled prior to triggering */ if (0UL != (CY_TCPWM_INT_ON_TC & Cy_TCPWM_GetInterruptMask(TCPWM0, MY_TCPWM_CNT_NUM))) { Cy_TCPWM_SetInterrupt(TCPWM0, MY_TCPWM_CNT_NUM, CY_TCPWM_INT_ON_TC); } else { /* The terminal count interrupt is not enabled, so there is no sense to trigger it */ }
- Parameters
base – The pointer to a TCPWM instance.
cntNum – The Counter instance number in the selected TCPWM.
source – The source to set an interrupt. See Interrupt Sources.
-
__STATIC_INLINE void Cy_TCPWM_SetInterruptMask (TCPWM_Type *base, uint32_t cntNum, uint32_t mask)
Sets an interrupt mask.
A 1 means that when the event occurs, it will cause an interrupt; a 0 means no interrupt will be triggered.
- Function Usage
/* Scenario: there is a need to set the Compare/Capture interrupt mask for * the first (index = 0) counter of the TCPWM0 block. */ #define MY_TCPWM_CNT_NUM (0UL) Cy_TCPWM_SetInterruptMask(TCPWM0, MY_TCPWM_CNT_NUM, CY_TCPWM_INT_ON_CC | Cy_TCPWM_GetInterruptMask(TCPWM0, MY_TCPWM_CNT_NUM));
- Parameters
base – The pointer to a TCPWM instance.
cntNum – The Counter instance number in the selected TCPWM.
mask – . See Interrupt Sources
-
__STATIC_INLINE uint32_t Cy_TCPWM_GetInterruptMask (TCPWM_Type const *base, uint32_t cntNum)
Returns the interrupt mask.
- Function Usage
/* Scenario: there is a need to set the Compare/Capture interrupt mask for * the first (index = 0) counter of the TCPWM0 block. */ #define MY_TCPWM_CNT_NUM (0UL) Cy_TCPWM_SetInterruptMask(TCPWM0, MY_TCPWM_CNT_NUM, CY_TCPWM_INT_ON_CC | Cy_TCPWM_GetInterruptMask(TCPWM0, MY_TCPWM_CNT_NUM));
- Parameters
base – The pointer to a TCPWM instance.
cntNum – The Counter instance number in the selected TCPWM.
- Returns
Interrupt Mask. See Interrupt Sources
-
__STATIC_INLINE uint32_t Cy_TCPWM_GetInterruptStatusMasked (TCPWM_Type const *base, uint32_t cntNum)
Returns which masked interrupt triggered the interrupt.
- Function Usage
/* Scenario: inside the TCPWM interrupt handler for * the first (index = 0) counter of the TCPWM0 block. */ #define MY_TCPWM_CNT_NUM (0UL) /* Get all the enabled pending interrupts */ uint32_t interrupts = Cy_TCPWM_GetInterruptStatusMasked(TCPWM0, MY_TCPWM_CNT_NUM); if (0UL != (CY_TCPWM_INT_ON_TC & interrupts)) { /* Handle the Terminal Count event */ } if (0UL != (CY_TCPWM_INT_ON_CC & interrupts)) { /* Handle the Compare/Capture event */ } /* Clear the interrupt */ Cy_TCPWM_ClearInterrupt(TCPWM0, MY_TCPWM_CNT_NUM, interrupts);
- Parameters
base – The pointer to a TCPWM instance.
cntNum – The Counter instance number in the selected TCPWM.
- Returns
Interrupt Mask. See Interrupt Sources
-
__STATIC_INLINE void Cy_TCPWM_TriggerStart_Single (TCPWM_Type *base, uint32_t cntNum)
Triggers a software start on the selected TCPWM.
- Function Usage
/* Scenario: Use software trigger to start Shift Register operation */ #define MY_TCPWM_SHIFTREG_NUM (0UL) Cy_TCPWM_TriggerStart_Single(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_TriggerReloadOrIndex_Single (TCPWM_Type *base, uint32_t cntNum)
Triggers a software reload event (or index 0 in QuadDec mode) on selected TCPWM.
- Parameters
base – The pointer to a TCPWM instance.
cntNum – The Counter instance number in the selected TCPWM.
-
__STATIC_INLINE void Cy_TCPWM_TriggerStopOrKill_Single (TCPWM_Type *base, uint32_t cntNum)
Triggers a stop in the Timer Counter mode, or a kill in the PWM mode on selected TCPWM.
- Parameters
base – The pointer to a TCPWM instance.
cntNum – The Counter instance number in the selected TCPWM.
-
__STATIC_INLINE void Cy_TCPWM_TriggerCaptureOrSwap_Single (TCPWM_Type *base, uint32_t cntNum)
Triggers a Capture 0 in the Timer Counter mode, and a Swap in the PWM mode on selected TCPWM.
- Parameters
base – The pointer to a TCPWM instance.
cntNum – The Counter instance number in the selected TCPWM.
-
__STATIC_INLINE void Cy_TCPWM_TriggerCapture0 (TCPWM_Type *base, uint32_t cntNum)
Triggers a Capture 0 on the selected counter.
- Parameters
base – The pointer to a TCPWM instance.
cntNum – The Counter instance number in the selected TCPWM.
-
__STATIC_INLINE void Cy_TCPWM_TriggerCapture1 (TCPWM_Type *base, uint32_t cntNum)
Triggers a Capture 1 in Timer Counter and QuadDec Mode.
In PWM mode this acts as a second kill input.
- Parameters
base – The pointer to a TCPWM instance.
cntNum – The Counter instance number in the selected TCPWM.
-
__STATIC_INLINE bool Cy_TCPWM_GetTrigPinLevel (TCPWM_Type const *base, uint32_t cntNum, cy_en_tcpwm_trigselect_t triggerSelect)
Returns the current level of the selected input trigger.
- Function Usage
/* Scenario: there is a need to check current level of pin connected to * start trigger for the first (index = 0) counter of the TCPWM0 block */ #define MY_TCPWM_PWM_NUM (0UL) if (Cy_TCPWM_GetTrigPinLevel(TCPWM0, MY_TCPWM_PWM_NUM, CY_TCPWM_INPUT_TR_START)) { /* Level on pin that is connected to the Start Trigger input is High */ } else { /* Level on pin that is connected to the Start Trigger input is Low */ }
- Parameters
base – The pointer to a TCPWM instance.
cntNum – The Counter instance number in the selected TCPWM.
triggerSelect – Defines which trigger status is being checked, Start, Reload, Stop/Kill, Count, Capture 0 or Capture 1
- Returns
The trigger level
-
__STATIC_INLINE void Cy_TCPWM_InputTriggerSetup (TCPWM_Type *base, uint32 cntNum, cy_en_tcpwm_trigselect_t triggerSelect, uint32_t edgeSelect, uint32_t triggerSignal)
Sets up a trigger input signal for a specific TCPWM counter.
This API is used to handle software triggering of multiple counters synchronously.
- Function Usage
/* Scenario: Start multiple counters synchronously */ #define GRP0_CNT0_NUM (0UL) #define GRP0_CNT1_NUM (1UL) #define GRP0_CNT2_NUM (2UL) #define TCPWM0_TR_IN0 (0x40000200u) /* tcpwm[0].tr_in[0] */ /* Set up input trigger start for all 3 counters to CY_TCPWM_INPUT_TRIG_1 */ Cy_TCPWM_InputTriggerSetup(TCPWM0, GRP0_CNT0_NUM, CY_TCPWM_INPUT_TR_START, CY_TCPWM_INPUT_LEVEL, CY_TCPWM_INPUT_TRIG_1); Cy_TCPWM_InputTriggerSetup(TCPWM0, GRP0_CNT1_NUM, CY_TCPWM_INPUT_TR_START, CY_TCPWM_INPUT_LEVEL, CY_TCPWM_INPUT_TRIG_1); Cy_TCPWM_InputTriggerSetup(TCPWM0, GRP0_CNT2_NUM, CY_TCPWM_INPUT_TR_START, CY_TCPWM_INPUT_LEVEL, CY_TCPWM_INPUT_TRIG_1); /* Trigger through Software to start all 3 counters synchronously */ Cy_TrigMux_SwTrigger(TCPWM0_TR_IN0, CY_TRIGGER_TWO_CYCLES);
- Parameters
base – The pointer to a TCPWM instance.
cntNum – The Counter instance number in the selected TCPWM.
triggerSelect – Defines which trigger is being setup, Start, Reload, Stop/Kill, Count, Capture 0 or Capture 1 see cy_en_tcpwm_trigselect_t
edgeSelect – Sets the trigger edge detection, Rising, Falling, Both, No edge detect. see Input Modes
triggerSignal – Selects what trigger signal is connected to the selected input trigger.
-
__STATIC_INLINE cy_en_tcpwm_status_t Cy_TCPWM_SetDebugFreeze (TCPWM_Type *base, uint32 cntNum, bool enable)
Enables/disables the Debug Freeze feature for the specified counter.
- Function Usage
/* Scenario: Enable Debug Freeze capability for the first * (index = 0) counter of the TCPWM0 block. */ #define MY_TCPWM_CNT_NUM (0UL) Cy_TCPWM_SetDebugFreeze (TCPWM0, MY_TCPWM_CNT_NUM, true); /* Now the counter value will be frozen when the tr_dbg_freeze signal is activated. * Usually the tr_dbg_freeze signal is intended to be activated from the cpuss.cti_tr_out[x] signal, for example: */ Cy_TrigMux_Connect(TRIG_IN_MUX_7_CTI_TR_OUT0, TRIG_OUT_MUX_7_TCPWM_DEBUG_FREEZE_TR_IN, false, TRIGGER_TYPE_LEVEL); /* However it can be activated just with software triggering: */ Cy_TrigMux_SwTrigger(TRIG_OUT_MUX_7_TCPWM_DEBUG_FREEZE_TR_IN, CY_TRIGGER_INFINITE); /* Get the counter value */ getVal = Cy_TCPWM_Counter_GetCounter(TCPWM0,(uint32_t)0U); /* Observe value is not changed from previous read */ getVal = Cy_TCPWM_Counter_GetCounter(TCPWM0,(uint32_t)0U); /* Scenario: Disable a Debug Freeze feature */ Cy_TCPWM_SetDebugFreeze (TCPWM0, MY_TCPWM_CNT_NUM, false); /* Deactivate trigger */ Cy_TrigMux_SwTrigger(TRIG_OUT_MUX_7_TCPWM_DEBUG_FREEZE_TR_IN, CY_TRIGGER_DEACTIVATE); /* Get the counter value */ getVal = Cy_TCPWM_Counter_GetCounter(TCPWM0,(uint32_t)0U); /* Observe value is changed from previous read */ getVal = Cy_TCPWM_Counter_GetCounter(TCPWM0,(uint32_t)0U);
- Parameters
base – The pointer to a TCPWM instance.
cntNum – The Counter instance number in the selected TCPWM.
enable – true: The Debug Free feature is enabled false: The Debug Freeze feature is disabled
- Returns
Error / Status code. See cy_en_tcpwm_status_t.
-