Position: Index > Inverter Circuit >

Generate sine wave modulated PWM with AVR microcontroller

2015-01-01 00:00  
Declaration:We aim to transmit more information by carrying articles . We will delete it soon, if we are involved in the problems of article content ,copyright or other problems.

This example will show how ease can sinewave modulated PWM modulated using AVR microcontroller and few lines of code. For this example I used Atmega8 MCU. All project is set up in VMLAB simulator.

To achieve this I saved sinewave lookup table in a Program memory (don’t forget to include interrupt.h header file):

const uint8_t sinewave[] PROGMEM= //256 values {0×80,0×83,0×86,…};

PWM is generated by using Phase and frequency correct PWM using 16 bit timer in Atmega8. Modulation is done by updating OCR1A value with one from sinewave table each time when compare matches.

Reading from flash program memory is done simply:

OCR1A=pgm_read_byte(&sinewave[i]);

The line above is placed inside the output compare interrupt for OCR1A service routine.

Resulting signal in scope simulator:

sinewave_PWM.PNG

Download project Sinewave modulated PWM source code if you want to try it by yourself.

This way you can modulate PWM with any signal shape that is stored in lookup table.

Updated AVRStudio4 project files!


Reprinted Url Of This Article:
http://www.scienceprog.com/generate-sine-wave-modulated-pwm-with-avr-microcontroller/