Setting PWM period
2011-10-11 by Philippe Habib
Thanks to all of the help I got a couple of weeks ago with timers, I have been able to get my PWM stuff (mostly) working.
I assume it is possible to tune the PWM period beyond the blunt instrument of the div by registers but I don't see how to do it.
Here are my settings, which give me a 500Hz frequency with an 8M clock. I would like to get that to between 200 and 300 Hz if I can. Am I missing a setting that lets me do that, or is it not possible.
DDRD |= (1 << PD6); // enable PWM (OC0A, PD6 ) output pin
OCR0A = 0; // set PWM % 0= off 255 = full
TCCR0A = (1 << COM0A1) | (0 << COM0A0) | // OC0A in PWM mode
(0 << COM0B1) | (0 << COM0B0) | // OC2B is not used
(1 << WGM01) | (1 << WGM00); // PWM mode
TCCR0B = (0 << CS00) | (1 << CS01) | (0 << CS02); // div 8 on clock
TCCR0B |= (0 << WGM02); // more PWM mode
Thank you.