On Oct 10, 2011, at 8:34 PM, Philippe Habib wrote: > 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. > There are modes where the timer resets based on the value in one compare register or, perhaps, the capture register. Most of these timers have two compare registers. This allows you to use one to set the period and the other to set the PWM time. Jim Wagner Oregon Research Electronics [Non-text portions of this message have been removed]
Message
Re: [AVR-Chat] Setting PWM period
2011-10-11 by Jim Wagner
Attachments
- No local attachments were found for this message.