PSoC 4 Peripheral Driver Library - Alpha
TCPWM (Timer Counter PWM)

General Description

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 (ModusToolbox only) 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:

Configuration Considerations

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.

Note

Assign and Configure Pins

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.

/* Scenario: P3[0] is the dedicated pin for the first counter of the TCPWM block: */
Cy_GPIO_Pin_FastInit(GPIO_PRT3, 0UL, CY_GPIO_DM_STRONG, 0UL, P3_0_TCPWM_LINE0);

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.

/* Scenario: Assign the first 16-bit peripheral clock divider with
* divide ratio = 100 to the first counter of the TCPWM block:
*/

More Information

For more information on the TCPWM peripheral, refer to the technical reference manual (TRM).

MISRA-C Compliance

The TCPWM driver does not have any specific deviations.

Changelog

VersionChangesReason for Change
1.0 Initial version

API Reference

 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.