This example shows how to use the ADC block to sample an analog voltage and use the PWM block to generate a pulse waveform. This example also shows how to use the Hardware Interrupt block to synchronize the change in the PWM duty cycle with analog to digital conversion of voltage. 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.
Spectrum Digital F2808/F2812/F28335 eZdsp or Texas Instruments™ LaunchPad/controlSTICK/controlCARD with docking station
Oscilloscope and probes
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.
These are the Simulink models available for different C2000 processors:
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
Piccolo F28004x-based board: c28004x_adcpwmasynctest_ert.slx
Note: To use the F28M35x/F28M36x controlCARD, you need Embedded Coder® Support Package for Texas Instruments C2000™ F28M3x Concerto™ Processors.
The following figure shows the example model.
The analog voltage from the function generator controls the duty cycle of the PWM waveform. Duty cycle changes can be observed on the oscilloscope. The Hardware Interrupt block triggers an interrupt service routine (ISR) and schedules the execution of the connected subsystem (ADC-PWM Subsystem) when the processor receives the ADC interrupt (ADCINT).
The ADC-PWM Subsystem consists of an ADC block that drives the duty cycle input port of the PWM block. The PWM block is configured to trigger the start of conversion (SOC) of the ADC block.
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 Configuration Parameters > Hardware Implementation > Hardware board.
On the Hardware tab, Click Build, Deploy & Start > Build Stand-Alone to generate, build, load, and run the program.
Observe the changes to the PWM waveform on the oscilloscope.