Driver API for Timer/Counter.
The functions and other declarations used in this part of the driver are in cy_tcpwm_counter.h. You can also include cy_pdl.h to get access to all functions and declarations in the PDL.
Use Timer/Counter mode whenever a specific timing interval or measurement is needed. Examples include:
- Creating a periodic interrupt for running other system tasks
- Measuring frequency of an input signal
- Measuring pulse width of an input signal
- Measuring time between two external events
- Counting events
- Triggering other system resources after x number events
- Capturing time stamps when events occur
The Timer/Counter has the following features:
- 16- or 32-bit Timer/Counter.
- Programmable Period Register.
- Programmable Compare Register. Compare value can be swapped with a buffered compare value on comparison event.
- Capture with buffer register.
- Count Up, Count Down, or Count Up and Down Counting modes.
- Continuous or One Shot Run modes.
- Interrupt on Terminal Count and Compare or Capture 0. Interrupt on Compare or Capture 1 is only available in TCPWM Version 2.
- Start, Reload, Stop, Capture, and Count Inputs.
- 2 compare (CC0/CC1) registers with double buffer, Capture 1 event. Second compare register and Capture 1 event are available only in TCPWM Version 2.
- Two programmable trigger outputs, trig_out0 and trig_out1 that generate a trigger on one of the following events Overflow, Underflow, Terminal Count, and Compare Match 0/1. The available triggers are dependent on the Timer/Counter mode. All these features are only available in TCPWM Version 2.
- Overflow, Underflow, and Compare(cc_match) trigger outputs are only available in TCPWM Version 1.
- Second Compare Match (CC_MATCH1) event is only available in TCPWM Version 2.
Configuration Considerations
The Counter configuration can be divided to number of sequential steps listed below:
Configure Counter
To configure Counter, provide the configuration parameters in the cy_stc_tcpwm_counter_config_t structure. The Configuration structure can be modified through software, but if the configurator in ModusToolbox is used then the configuration structure will be updated with the users input. To initialize the driver, call Cy_TCPWM_Counter_Init function providing a pointer to the populated cy_stc_tcpwm_counter_config_t structure.
For TCPWM V1 Configuration
{
99UL,
33UL,
66UL,
true,
};
#define MY_TCPWM_CNT_NUM (0UL)
{
}
#define CY_TCPWM_COUNTER_PRESCALER_DIVBY_4
Divide by 4.
Definition: cy_tcpwm_counter.h:212
#define CY_TCPWM_COUNTER_MODE_COMPARE
Timer/Counter is in Compare Mode.
Definition: cy_tcpwm_counter.h:225
#define CY_TCPWM_COUNTER_COUNT_UP
Counter counts up.
Definition: cy_tcpwm_counter.h:198
#define CY_TCPWM_COUNTER_CONTINUOUS
Counter runs forever.
Definition: cy_tcpwm_counter.h:191
Counter Timer configuration structure.
Definition: cy_tcpwm_counter.h:137
@ CY_TCPWM_SUCCESS
Successful.
Definition: cy_tcpwm.h:399
__STATIC_INLINE void Cy_TCPWM_TriggerStart_Single(TCPWM_Type *base, uint32_t cntNum)
Triggers a software start on the selected TCPWM.
Definition: cy_tcpwm.h:888
__STATIC_INLINE void Cy_TCPWM_Counter_Enable(TCPWM_Type *base, uint32_t cntNum)
Enables the counter in the TCPWM block for the Counter operation.
Definition: cy_tcpwm_counter.h:313
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.
Definition: cy_tcpwm_counter.c:58
#define CY_TCPWM_INT_NONE
No Interrupt.
Definition: cy_tcpwm.h:302
TCPWM V2 Configuration
{
99UL,
33UL,
66UL,
true,
false,
0,
0,
};
#define MY_TCPWM_CNT_NUM (0UL)
{
}
#define CY_TCPWM_CNT_TRIGGER_ON_DISABLED
Output trigger disabled.
Definition: cy_tcpwm.h:294
Assign Clock Divider
The clock source must be connected to proper working. Any of the peripheral clock dividers could be used. Use the SysClk (System Clock) driver API to do that.
Enable Counter
Counter has to be enabled before starting
#define MY_TCPWM_COUNTER_NUM (0UL)
__STATIC_INLINE void Cy_TCPWM_PWM_Enable(TCPWM_Type *base, uint32_t cntNum)
Enables the counter in the TCPWM block for the PWM operation.
Definition: cy_tcpwm_pwm.h:519
Start Counter
Counter has to be started
#define MY_TCPWM_COUNTER_NUM (0UL)