Page 1 of 1

PWM for the ATMEGA328

Posted: Sat Jan 30, 2010 3:22 pm
by imsmooth
I was reading http://arduino.cc/en/Tutorial/SecretsOfArduinoPWM

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;

Posted: Sat Jan 30, 2010 4:19 pm
by frank26080115
only timer1 is 16 bit, timer0 and timer2 are still 8 bit

the prescaler values have nothing to do with resolution