Main Content

Modify Duty Cycle of ePWM Using DMA

This example shows how to configure the direct memory access (DMA) parameters to modify the ePWM duty cycle. Using DMA, the sine wave data is copied from a look-up table to the ePWM compare register.

You can observe the duty cycle changes by connecting the ePWM pin (GPIO2) to:

  • An oscilloscope to monitor the changes in the duty cycle.

  • The LED (GPIO31/GPIO34) to observe the dimming of the LED.

The example consists of a model and a callback script. The script runs when the model is initialized. The callback script (sineTableCalculation.m) generates a sine wave of 500 samples, and then scales the sine wave to the range of zero to the value of the ePWM period register.

Required Hardware

F2833x, F2806x, F2807x, F2837x, or F28004x controlCARD/LaunchPad.

Available Models


The c28x7x_c28004x_dma_epwm model consists of the duty_cycle_table look-up table defined using the Data Store Memory, ePWM, and Memory Copy blocks. The duty_cycle_table look-up table stores the sine wave samples generated by the callback script.

The ePWM block is configured in up-down mode for a period of 0.002 seconds. For more information, see General.

The ePWM block is also configured to generate a start of conversion event for module A (SOCA). For more information, see Event Trigger.

The DMA parameters are configured to transfer 500 sine wave samples from the duty_cycle_table look-up table to the ePWM compare register. DMA transfers one sample at a time when triggered by the ePWM2SOCA event. To configure the DMA parameters, browse to Configuration Parameters > Hardware Implementation > Target hardware resources > DMA_ch1.

The Memory Copy block provides the value of the ePWM compare register to the Scope block.

Configure and Run Model

1. In the Configuration Parameters window, click Hardware Implementation > Target hardware resources.

2. Click SCI_A, and set the Desired baud rate in bits/sec parameter to 1.25e6.

3. Click External mode, and set the Serial port parameter to the COM port at Device Manager > Ports (COM & LTP) in Windows. For more information, see Parameter Tuning and Signal Logging with Serial Communication.

4. To ensure that enough memory is present to run the model in external mode, click Code Generation > Optimization in the Configuration Parameters window.

5. Set the Default parameter behavior parameter to Inlined, and click OK.

6. Open Hardware tab and click Monitor & Tune. Observe the sine wave values on the scope.

7. You can connect the ePWM pin (GPIO2) to:

  • An oscilloscope to monitor the changes in the duty cycle.

  • The LED (GPIO31/GPIO34) to observe the dimming of the LED.

More About

ePWM Type 1-4