Main Content

Using Time-Base Counter Synchronization to Synchronize ePWMs and eCAPS

This example shows how to use time-base counter synchronization in C2000™ Microcontroller Blockset.

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.

  • Synchronize ePWM4 with ePWM1 with a phase shift when ePWM is in Up-Down mode.


Complete the following tutorials:

Required Hardware

TI Delfino F28379D LaunchPad or TI F2838x control card

Available Models


Open the f2837x_TimeBaseSync.slx model.

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 the 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.

Time Base Sychronization in Up-Down Mode

Open the f2837xTimeBaseSyncUpDownMode.slx model.

Calculation of Phase Shift in Up-Down

Delay (counts) = 2 x Time base period x $\phi$/ 360

  • Ensure that $\phi$ value is in between 0 to 180 degree.

  • To achieve a phase shift greater than 180, the delay counts should be same as the number calculated when the phase shift is equal to 360 - $\phi$. However, its important to consider the direction change of ePWM counter which is visible from the following figure.

From the figure,

  • Observe that at point A, the second ePWM counter will start from the value delay after synchronization from ePWM1 is received.

  • For a positive phase shift (lead) we can observe that the 2nd ePWM counter will count down (Orange dotted line).

  • For a negative phase shift (lag) we can observe that the 2nd ePWM counter will count up (Blue dotted line).

In the model, this is achieved by using the Register Read/write block, where we change the corresponding register field PHSDIR of EPwm4Regs which controls the direction of ePWM counter after synchronization.

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