View RSS Feed

alexan_e

PWM in ATMEGA

Rate this Entry
The atmega has a few different PWM modes, the frequency and duty ratio depend on the mode and values used, this is a description of the way to calculate them.

In fast PWM top=ICR1, the output PWM frequency=timer clock/(ICR1+1) and the duty=OCR1A(B)/ICR1
In fast PWM top=0h00ff, the output PWM frequency=timer clock/256 and the duty=OCR1A(B)/256
In fast PWM top=0h01ff, the output PWM frequency=timer clock/512 and the duty=OCR1A(B)/512
In fast PWM top=0h03ff, the output PWM frequency=timer clock/1024 and the duty=OCR1A(B)/1024

In phase correct or phase & freq correct top=ICR1, the output PWM frequency=timer clock/(ICR1*2) and the duty=OCR1A(B)/ICR1
In phase correct or phase & freq correct top=0h00ff, the output PWM frequency=timer clock/(255*2) and the duty=OCR1A(B)/256
In phase correct or phase & freq correct top=0h01ff, the output PWM frequency=timer clock/(511*2) and the duty=OCR1A(B)/512
In phase correct or phase & freq correct top=0h03ff, the output PWM frequency=timer clock/(1023*2) and the duty=OCR1A(B)/1024

OCR1A(B) means OCR1A or OCR1B because there are two registers you can use to generate two PMW duty cycles of the same frequency.

Alex
Tags: None Add / Edit Tags
Categories
AVR

Comments