Main Content

ADC-PWM Synchronization Using ADC Interrupt

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.

You can also use the model c2838x_adcpwmasync_TopModel to perform Model Reference workflow. For more information, see Model Reference support for C2000 Processors.

Required Hardware

  • Spectrum Digital F2808/F2812/F28335 eZdsp or Texas Instruments™ LaunchPad/controlSTICK/controlCARD with docking station

  • Oscilloscope and probes

  • Function generator

Hardware Connections

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.

Available Models

These are the Simulink® models available for different C2000 processors:

Note: To use the F28M35x/F28M36x controlCARD, you need C2000™ Microcontroller Blockset.


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.

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 Configuration Parameters > Hardware Implementation > Hardware board

  2. On the Hardware tab, Click Build, Deploy & Start > Build Stand-Alone to generate, build, load, and run the program.

  3. Observe the changes to the PWM waveform on the oscilloscope.

More About