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:
- Spectrum Digital F2808/F2812/F28335 eZdsp
- Texas Instruments™ F2808/F28027/F28035/F28044/F28069/F28335/F28343/F28346 ControlCARD with docking station
- Texas Instruments™ F28027/F28069 ControlSTICK
- Oscilloscope and probes
Available versions of this example:
- F281x based board: c281x_spitest.mdl
- F280x/F2823x/F2833x based board: c280x_2833x_spitest.mdl
- Piccolo F2802x/F2803x/F2806x based board: c280xx_spitest.mdl
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:
- F2812eZdsp (connector P8 pins 23 and 24)
- F2808 eZdsp (connector P8 pins 9 and 10)
- F28335 eZdsp connector P8 pins 9 and 10)
- Texas Instruments F28027/F28069 controlSTICK (connector J1 pins 20 and 24)
- Texas Instruments controlCARD with docking station (GPIO 16 and 17)
How to Run the Example in Simulation
- Open this model.
- Click "Start simulation" button.
- Double-click on the "Duty Cycle Change" block and select a new duty cycle value.
- Observe the PWM waveform change.
How to Run the Example on the Board
- Open the model corresponding to the family of processor you are using.
- Each model is configured for a default processor. To select a different processor open the Model Configuration Parameters dialog and select "Coder Target" under "Code Generation". Next, click "Target Hardware Resources" dialog and select processor that matches your hardware.
- Go to "Peripherals" and select "SPI_A". Check "Enable loopback". If your processor is F2803x/F2806x, select "GPIO16" for "SOMI pin assignment" and "GPIO17" for "SIMO pin assignment".
- Click "Build/Reload & Run" to generate, build, load and run the program.
- Select a new duty cycle value in the dialog that opens.
- Observe the PWM waveform on the oscilloscope.
LocalWords: SPI eZdsp SPI eZdsp GPIO SOMI SIMO