SPI-Based Control of PWM Duty Cycle
This example shows how to the use of the SPI Receive, SPI Transmit and PWM to generate a PWM waveform.
Required Hardware(Any of the below):
- 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
- Texas Instruments™ F28M35xx/F28M36xx ControlCARD(To use F28M35x/F28M36x you need Texas Instruments C2000 Concerto Support Package)
- Texas Instruments™ F2807x/F2837xS/F2837xD ControlCARD or LaunchPad
- Oscilloscope and probes
Available versions of this example:
- F281x based board: c281x_spitest_ert.slx
- F280x/F2823x/F2833x based board: c280x_2833x_spitest_ert.slx
- Piccolo F2802x/F2803x/F2806x based board: c280xx_spitest_ert.slx
- Concerto F28M35xx/F28M36xx based board: c280xx_spitest_ert.slx
- Piccolo F2807x or Delfino F2837xS/F2837xD based board: c2807x_2837xx_spitest_ert.slx
The following figure shows the example model:
The block labeled "Read Duty Cycle" sends the appropriate duty cycle value to "C28xx SPI Transmit" block. "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.
"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.
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)
- Texas Instruments Concerto F28M35xx/F28M36xx controlCARD with docking station (Pin Numbers can be found in config set)
How to Run the Example on the Board
- Open the model corresponding to the target hardware you are using.
- Each model is configured for default target hardware. To select different target hardware open the Model Configuration Parameters dialog and select the Hardware Implementation pane. Next, select your target hardware in the Hardware board drop-down list.
- Select Hardware Implementation > Target Hardware Resources > "SPI_A". Check "Enable loopback". If your target hardware is F2803x/F2806x, select "GPIO16" for "SOMI pin assignment" and "GPIO17" for "SIMO pin assignment". If your target hardware is F28M35xx/F28M36xx/F2807x/F2837xx, select from the dropdown for "SOMI pin assignment" and "SIMO pin assignment".
- Select a new duty cycle value using the block labeled "Read Duty Cycle".
- Click Build Model to generate, build, load and run the program.
- Observe the PWM waveform on the oscilloscope.
LocalWords: SPI eZdsp SPI eZdsp GPIO SOMI SIMO