Generate sine wave modulated PWM with AVR microcontroller
This example will show how ease can sinewave modulated PWM modulated using an AVR microcontroller and a few code lines. For this example, I used Atmega8 MCU. All project is set up in VMLAB simulator. To achieve this, I saved a sinewave lookup table in a Program memory (don’t forget to include interrupt.h header file): PWM is generated by using Phase and frequency correct PWM using a 16-bit timer in Atmega8. Modulation is done by updating the OCR1A value with one from the sinewave table when comparing matches. Reading from flash program memory is done simply: The line above is placed inside the output compare interrupt for OCR1A service routine. Resulting signal in scope simulator: 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 the lookup table. Updated AVRStudio4 project files!