This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

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

Model

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

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

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.

Configure and Run the 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 External Mode.

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. Click the Run button to run the model in external mode. 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

C280x/C2802x/C2803x/C2805x/C2806x/C2833x/C2834x/F28M3x/F2807x/F2837xD/F2837xS/F28004x ePWM