This code example demonstrates how to trigger multiple TCPWM channels simultaneously by software.
The device used in this code example (CE) is:
The board used for testing is:
- TRAVEO™ T2G evaluation kit (KIT_T2G-B-H_EVK, KIT_T2G-B-H_LITE)
In this example, the LED-A and LED-B on the target board connected to the PWM output pin and blink at the rate of 2Hz with different duty cycles. These PWMs are made by TCPWM (Timer, Counter, and PWM) and simultaneously activated by software via Trigger Multiplexer.
TCPWM
The TCPWM block consists of 16-bit (102 channels) and 32-bit (16 channels) counters with user-programmable period. Fifteen of the 16-bit counters are optimized for motor-control operations. Each TCPWM counter contains a capture register to record the count at the time of an event, a period register (used to either stop or auto-reload the counter when its count is equal to the period register), and compare registers to generate signals that are used as PWM duty-cycle outputs.
- Up to 102 16-bit and 16 32-bit Timer/Counter Pulse-Width Modulator (TCPWM) blocks
- Up to 15 16-bit counters for motor control
- Up to 87 16-bit counters and 16 32-bit counters for regular operations
- Supports timer, capture, quadrature decoding, pulse-width modulation (PWM), PWM with dead time (PWM_DT), pseudo-random PWM (PWM_PR), and shift-register (SR) modes.
Trigger Multiplexer
The Trigger Multiplexer supports connecting various peripherals using trigger signals. Triggers are used to inform a peripheral of the occurrence of an event or change of state. These triggers are used to affect or initiate some action in other peripherals. The trigger multiplexer is used to route triggers from a source peripheral to a destination. Triggers provide active logic functionality and are typically supported in Active mode.
- Ability to connect any trigger signal from one peripheral to another
- Provides up to 16 multiplexer-based trigger groups and up to 16 one-to-one trigger groups
- Supports a software trigger, which can trigger any signal in the block
- Ability to configure a trigger multiplexer with trigger manipulation features in hardware such as inversion and edge/level detection
More details can be found in Technical Reference Manual (TRM), Registers TRM and Data Sheet.
This CE has been developed for:
- TRAVEO™ T2G evaluation kit (KIT_T2G-B-H_EVK)
No changes are required from the board's default settings. Output signals are output from the following pins respectively:
PWM_LEDA PWM_LEDB P16[2] (LED2) P16[1] (LED1)
- TRAVEO™ T2G Body High Lite evaluation kit ([KIT_T2G-B-H_LITE](https://www.infineon.com/cms/en/product/evaluation-boards/kit_t2g-b-h_lite/))
No changes are required from the board's default settings. Output signals are output from the following pins respectively:
PWM_LEDA | PWM_LEDB |
---|---|
P5[1] (LED2) | P5[2] (LED3) |
TCPWM waveform
The PWM waves are configured to produce a 2-Hz PWM output. In this example, the output duty cycle is set to 70% for PWM_LEDA and 30% for PWM_LEDB, which generates a square wave. The output of the PWM_LEDA and PWM_LEDB are connected to LEDs that blinks at 500 ms (inverse of the PWM output frequency, 2 Hz). The configuration is done in a custom design.modus file. This can be opened by Device Configurator, also can be modified. If saved, all settings will be reflected to codes.
To vary the frequency and duty cycle of the PWM outputs, change the parameter on Device Configurator then rebuild and program the application. Observe the change in LED blink pattern.
- Initialize and enable the TCPWM
- The configuration of each channels is output as PWM_LEDA_config and PWM_LEDB_config respectively. First, configure the .startInput and .startInputMode to get triggered by group trigger of Trigger Multiplexer.
- Initialization of the TCPWM is done once in the Cy_TCPWM_PWM_Init() function, then enables the TCPWM in the Cy_TCPWM_PWM_Enable() function. Note that the TCPWM operation clock starts at this point; if the TCPWM clock is set to divide the source clock, each channel starts operating at this timing, so even if simultaneous startup is performed by Trigger Multiplexer, the output PWM waveforms may not start same time.
- Start the PWM
- Starts both the TCPWM channel simultaneously in the Cy_TCPWM_TriggerStart_Single() function
Miscellaneous settings
-
STDIN / STDOUT setting
- Calling cy_retarget_io_init() function to use UART as STDIN / STDOUT
- Initialize the port defined as CYBSP_DEBUG_UART_TX as UART TX, defined as CYBSP_DEBUG_UART_RX as UART RX (these pins are connected to KitProg3 COM port)
- The serial port parameters become to 8N1 and 115200 baud
- Calling cy_retarget_io_init() function to use UART as STDIN / STDOUT
For this CE, a terminal emulator is required for displaying outputs and get inputs. Install a terminal emulator if you do not have one. Instructions in this document use Tera Term.
After code compilation, perform the following steps to flashing the device:
-
Connect the board to your PC using the provided USB cable through the KitProg3 USB connector.
-
Open a terminal program and select the KitProg3 COM port. Set the serial port parameters to 8N1 and 115200 baud.
-
Program the board using one of the following:
- Select the CE project in the Project Explorer.
- In the Quick Panel, scroll down, and click [Project Name] Program (KitProg3_MiniProg4).
-
After programming, the CE starts automatically. Confirm that the messages are displayed on the UART terminal.
-
The waveform that can be observed by the probe will be as follows, and the rising edges of both channels should be at the same timing:
-
You can debug the example to step through the code. In the IDE, use the [Project Name] Debug (KitProg3_MiniProg4) configuration in the Quick Panel. For details, see the "Program and debug" section in the Eclipse IDE for ModusToolbox™ software user guide.
Note: (Only while debugging) On the CM7 CPU, some code in main() may execute before the debugger halts at the beginning of main(). This means that some code executes twice: once before the debugger stops execution, and again after the debugger resets the program counter to the beginning of main(). See KBA231071 to learn about this and for the workaround.
Relevant Application notes are:
- AN235305 - GETTING STARTED WITH TRAVEO™ T2G FAMILY MCUS IN MODUSTOOLBOX™
- AN220224 - How to Use Timer, Counter, and PWM (TCPWM) in TRAVEO™ II Family
- AN228104 - How to Use Trigger Multiplexer in TRAVEO™ II family
- AN224434 - Clock configuration setup in TRAVEO™ T2G family CYT4B series
ModusToolbox™ is available online:
Associated TRAVEO™ T2G MCUs can be found on:
More code examples can be found on the GIT repository:
For additional trainings, visit our webpage:
For questions and support, use the TRAVEO™ T2G Forum: