PWM for the ATMEGA328

Your source for all things Atmel.

Moderator: phalanx

Post Reply
Posts: 12
Joined: Thu Jan 28, 2010 7:20 am

PWM for the ATMEGA328

Post by imsmooth » Sat Jan 30, 2010 3:22 pm

I was reading

Am I correct in reading that if I write my own PWM routine, I don't have to be limited by 255 resolution?

AnalogWrite(127) is about 50% duty cycle, and each increment has a resolution of 1/256. If I want a higher resolution, like 1024 can I just write a loop that counts up to 1024, setting the outputpin high and low depending where I am in the loop without suspending other operations (math, interrupts,...)? There is an example in the community code section for timer/pwm routines.

Finally, were are the ports defined such as these:
TCCR2A = _BV(COM2A1) | _BV(COM2B1) | _BV(WGM20);
TCCR2B = _BV(CS22);
OCR2A = 180;
OCR2B = 50;

Posts: 237
Joined: Thu Jul 05, 2007 8:32 am

Post by frank26080115 » Sat Jan 30, 2010 4:19 pm

only timer1 is 16 bit, timer0 and timer2 are still 8 bit

the prescaler values have nothing to do with resolution
Recently graduated from UW for EE!

Post Reply