Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

generate and vary duty cycle of a pwm from atmega 32

Status
Not open for further replies.

sasidhar60

Newbie level 6
Newbie level 6
Joined
May 17, 2012
Messages
13
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,358
hi,
i want to know how to program for atmega 32 in avr srudio to generate a specific pwm and to vary its duty ratio automatically in steps until my error comparing a measured value wit reference value is zero please help me out
 

Hi sasidhar60,

this is may help you

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

enjoy :)
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top