The TCPWM driver is a multifunction driver that implements Timer Counter, PWM, and Quadrature Decoder functionality using the TCPWM block. More...
Modules | |
Common | |
Common API for the Timer Counter PWM Block. | |
Timer/Counter (TCPWM) | |
Driver API for Timer/Counter. | |
PWM (TCPWM) | |
Driver API for PWM. | |
Quadrature Decoder (TCPWM) | |
Driver API for Quadrature Decoder. | |
The TCPWM driver is a multifunction driver that implements Timer Counter, PWM, and Quadrature Decoder functionality using the TCPWM block.
The functions and other declarations used in this driver are in cy_tcpwm_counter.h, cy_tcpwm_pwm.h, cy_tcpwm_quaddec.h respectively. Include cy_pdl.h to get access to all functions and declarations in the PDL.
Each TCPWM block is a collection of counters that can all be triggered simultaneously. For each function call, the base register address of the TCPWM being used must be passed first, followed by the index of the counter you want to touch next. For some functions, you can manage multiple counters simultaneously. You provide a bit field representing each counter, rather than the single counter index).
The TCPWM supports three operating modes:
Timer/Counter
Use this mode whenever a specific timing interval or measurement is needed. Examples include:
The Timer/Counter has the following features:
PWM
Use this mode when an output square wave is needed with a specific period and duty cycle, such as:
The PWM has the following features:
Quadrature Decoder
A quadrature decoder is used to decode the output of a quadrature encoder. A quadrature encoder senses the position, velocity, and direction of an object (for example a rotating axle, or a spinning mouse ball). A quadrature decoder can also be used for precision measurement of speed, acceleration, and position of a motor's rotor, or with a rotary switch to determine user input.
The Quadrature Decoder has the following features:
For each mode, the TCPWM driver has a configuration structure, an Init function, and an Enable function.
Provide the configuration parameters in the appropriate structure (see Counter Data Structures, PWM Data Structures, or QuadDec Data Structures). Then call the appropriate Init function: Cy_TCPWM_Counter_Init, Cy_TCPWM_PWM_Init, or Cy_TCPWM_QuadDec_Init. Provide the address of the filled structure as a parameter. To enable the counter, call the appropriate Enable function: Cy_TCPWM_Counter_Enable, Cy_TCPWM_PWM_Enable, or Cy_TCPWM_QuadDec_Enable).
Many functions work with an individual counter. You can also manage multiple counters simultaneously for certain functions. These are listed in the Functions section of the TCPWM. You can enable, disable, or trigger (in various ways) multiple counters simultaneously. For these functions you provide a bit field representing each counter in the TCPWM you want to control. You can represent the bit field as an ORed mask of each counter, like ((1U << cntNumX) | (1U << cntNumX) | (1U << cntNumX)), where X is the counter number from 0 to 31.
The dedicated TCPWM pins can be used. The HSIOM register must be configured to connect the block to the pins. Use the GPIO (General Purpose Input Output) driver API to do that.
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.
The TCPWM configuration is not recovered after Deep Sleep. User need to initialize TCPWM after deep sleep.
For more information on the TCPWM peripheral, refer to the technical reference manual (TRM).
Version | Changes | Reason for Change |
---|---|---|
1.10.2 | Update the paths to the code snippets. | PDL structure update. |
Minor documentation updates. Code snippets were updated. | Documentation enhancement. | |
1.10.1 | Updated documentation of PWM mode. | Documentation enhancement. |
1.10 | Fixed Cy_TCPWM_Counter_Disable, Cy_TCPWM_PWM_Disable, and Cy_TCPWM_QuadDec_Disable functions to clear enable bit. | Fixed issue with disabling TCPWM in the Counter, PWM, and Quadrature Decoder modes. |
1.0 | Initial version |