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)
{
}
TCPWM V2 Configuration
{
99UL,
33UL,
66UL,
true,
false,
0,
0,
};
#define MY_TCPWM_CNT_NUM (0UL)
{
}
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)
Start Counter
Counter has to be started
#define MY_TCPWM_COUNTER_NUM (0UL)