PSoC 6 Peripheral Driver Library
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 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: P0[0] is the dedicated pin for the first counter of the TCPWM0 block: */
Cy_GPIO_Pin_FastInit(GPIO_PRT0, 0UL, CY_GPIO_DM_STRONG_IN_OFF, 0UL, P0_0_TCPWM0_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 8-bit peripheral clock divider with
* divide ratio = 100 to the first counter of the TCPWM0 block:
*/

More Information

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

MISRA-C Compliance

MISRA Rule Rule Class (Required/Advisory) Rule Description Description of Deviation(s)
14.2 R All non-null statements shall either: a) have at least one side-effect however executed, or b) cause control flow to change. The unused function parameters are cast to void. This statement has no side-effect and is used to suppress a compiler warning.

Changelog

VersionChangesReason for Change
1.10.2 Minor documentation updates. Documentation enhancement.
1.10.1 Added header guards CY_IP_MXTCPWM. To enable the PDL compilation with wounded out IP blocks.
1.10 Flattened the organization of the driver source code into the single source directory and the single include directory. Driver library directory-structure simplification.
Added register access layer. Use register access macros instead of direct register access using dereferenced pointers. Makes register access device-independent, so that the PDL does not need to be recompiled for each supported part number.
1.0.1 Added a deviation to the MISRA Compliance section. Added function-level code snippets. Documentation update and clarification
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.