Main Content

Using Time-Base Counter Synchronization to Synchronize ePWMs and eCAPS

This example shows how to use time-base counter synchronization in Embedded Coder® Support Package for Texas Instruments® C2000 Processors.

In this example you will learn how to:

  • Synchronize ePWM4 with ePWM1 with a phase delay of 120 degrees

  • Synchronize eCAP1 with ePWM4 with a phase delay of 120 degrees

Prerequisites

Complete the following tutorials:

Required Hardware

TI Delfino F28379D LaunchPad or TI F2838x control card

Available Models

Model

To open the model, type the following command in the MATLAB® command prompt.

open_system('f2837x_TimeBaseSync.slx');

In the model, the ePWM1 and ePWM4 blocks are configured to generate a signal of time period 1 second and duty cycle of 50 %. Similarly, the eCAP1 is configured to work in the APWM mode and generate a signal of period 1 second and duty cycle of 50 %. The ePWM4 block is synchronized with the ePWM1 with a phase shift of 120 degrees, and eCAP1 is synchronized with the ePWM4 with a phase shift of 120 degrees.

eCAP2, eCAP3 and eCAP4 are used to capture the waveform generated by the time-base synchronization module and display it in the Scope block.

Configure ePWM and eCAP Modules for Time-Base Counter Synchronization

  • Configure the ePWM1 block to send the signal by setting the Synchronization output (SYNCO) parameter to Counter equals to zero (CRT=Zero)

  • ePWM4 is configured to have synchronization input from ePWM1 SYNCOUT in the Configuration Parameters.

  • The ePWM4 block is configured for phase offset value and send the SYNCOUT signal when CTR=Zero.

  • eCAP1 block is configured to operate in APWM mode and enabled to have synchronization input in the block. The counter phase offset value is also set in the block parameter as shown.

  • eCAP1 is configured to have synchronization input from ePWM4 SYNCOUT in Configuration Parameters.

Configure eCAP blocks to Capture PWM Waveforms

  • Hardware interrupts eCAP2, eCAP3 and eCAP4 are configured to capture the generated PWM waveforms on the Scope block. The eCAP blocks are configured in eCAP mode to capture two events i.e. Rising edge and Falling edge of the signal.

  • The PWM signals (ePWM1 at GPIO0, ePWM4 at GPIO6 and eCAP1 at GPIO24) are given as input to eCAP through Input X-BAR under Hardware Implementation > Target hardware resources > Input X-BAR.

  • You can also verify the GPIO signals in Configuration Parameters.

Note: The Scope block displays signals only when you specify the time period in seconds. For higher frequency signals, use the digital source oscilloscope (DSO) to view the signals.

Phase Offset Calculation

The counter phase offset value determines the phase lead or lag.

Phase is calculated using the equation

where PRD = Timer period, CTRPHS = counter phase offset value.

Note: This formula is applicable in case of up or down count mode only. In case of up-down counter mode, the phase depends on the mode of the controller as well as the direction after synchronization.

Time delay based on the phase value is given by,

Configure the Model

1. Open the model. The model in this example is configured for TI Delfino F28379D LaunchPad hardware.

2. To run the model on other TI C2000 processors, press Ctrl+E to open the Configuration Parameters dialog box and select the required hardware board by navigating to Hardware Implementation > Hardware board.

3. Ensure that Communication interface is set to XCP on Serial.

Run the Model

When you perform the Monitor & Tune action for the model, the host computer communicates with the target on which the generated executable runs.

1. On the Hardware tab of the model click Monitor & Tune.

2. Use the diagnostic viewer to follow the build progress and wait until the code loads and runs on the target hardware.

3. Observe the waveforms in the Scope block.

Other things to try

  • Change the time Period to 20 kHz and monitor the signal in a DSO.

  • Try synchronization between other ePWM and eCAP modules.

  • Try different phase shifts and lead and lag by providing different counter phase offset value.

  • In the Model Properties dialog box, navigate to the Callbacks tab > c28xgetPhaseOffsetValue to find the file for calculation of phase offset value based on phase delay needed between ePWM and eCAP modules.

More About