ADC-PWM Synchronization via ADC Interrupt
This example shows how to use the ADC and PWM blocks. In the generated code, changes in the voltage of the ADC input alter the duty cycle of the PWM output. The period of the PWM waveform remains constant. This example also shows how to use the Hardware Interrupt block to synchronize the update of the PWM duty cycle with the ADC conversion.
- 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
- Function generator
Available versions of this example:
- F281x based board: c281x_adcpwmasynctest_ert.slx
- F280x/F2823x/F2833x based board: c280x_2833x_adcpwmasynctest_ert.slx
- Piccolo F2802x/F2803x/F2806x or Concerto F28M35x/F28M36x based board: c280xx_adcpwmasynctest_ert.slx
- Piccolo F2807x or Delfino F2837xS/F2837xD based board: c2807x_2837xx_adcpwmasynctest_ert.slx
The following figure shows the example model:
This example shows how to use the ADC block to sample an analog voltage and how to use the PWM block to generate a pulse waveform. The analog voltage controls the duty cycle of the PWM waveform. Duty cycle changes can be observed on the oscilloscope. "Hardware Interrupt" installs an Interrupt Service Routine (ISR) for ADC interrupt and schedules the execution of the connected subsystem (ADC-PWM Subsystem) when ADC interrupt (ADCINT) is received.
"ADC-PWM Subsystem" consists of an ADC driving the duty cycle input port of the PWM. PWM is configured to trigger ADC start of conversion (SOC).
Connect the function generator output to the ADC input ADCINA0 on the board. Connect the GPIO pin corresponding to PWM1A to the analog input of the oscilloscope.
How to run the model on the hardware board
1. Open the model corresponding to the target hardware you are using. Each model is configured for a default target hardware. To select a different target hardware, browse to Model Configuration Parameters > Hardware Implementation > Hardware board.
2. Click Build Model to generate, build, load, and run the program.
3. Observe the change of the PWM waveform on the oscilloscope.