SPI-Based Control of PWM Duty Cycle

This example shows how to the use of the SPI Receive, SPI Transmit, PWM, and Memory Copy blocks to generate a PWM waveform.

Required Hardware:

Available versions of this example:

Note: This model only runs with "Code Composer Studio v3.3"

Contents

Model

The following figure shows the example model:

Description

Memory Copy block labeled "Read Duty Cycle" reads duty cycle value stored at the memory location 0x8FF0. "C28xx SPI Transmit" block transmits this value, while "C28xx SPI Receive" receives it. The duty cycle value is then sent to the PWM1. The duty cycle of the generated pulse waveform is determined by the relative ratio of the received pulse width value and the pulse period which is fixed at 64000 clock cycles. The duty cycle toggles between 25%, 50%, and 75% based on user selection.

PWM Duty Cycle can be changed while the generated code is running using "write" method of the IDE Link component. This method writes selected value to the memory location 0x8FF0. Select either 25%, 50%, or 75% value from the GUI that opens up when "Build/Reload & Run" is pressed.

"Enable loopback" mode is selected for "SPI_A". This is required to get the transmitted data back to the processor. If this mode is disabled, SPI_A transmitter and receiver have to be physically connected for the example to work.

Note that "Simulate Duty Cycle Change" and "Simulate PWM Waveform" are dedicated to simulation only. Use these blocks to simulate and observe effects achieved with the generated code.

Hardware Connections

Connect the output of PWM1 on the board to the analog input of the oscilloscope.

Note that SPI module is set to work in "loopback" mode. No external SPI hardware is needed. As an alternative, the user may disable SPI loopback mode and bridge SPI transmit and receive pins on each of the following:

How to Run the Example in Simulation

How to Run the Example on the Board

LocalWords: SPI eZdsp SPI eZdsp GPIO SOMI SIMO