Grumpy_Mike:
I hope you did it with a spread sheet.
Lua actually.
for i = 1, 256 do
print ("OCR2A =", i - 1 .. ", frequency =", round (16e6 / 8/ i), "Hz")
end -- for
This does the same thing without an ISR:
const byte LED = 3; // Timer 2 "B" output: OC2B
const long frequency = 20000L; // Hz
void setup()
{
pinMode (LED, OUTPUT);
TCCR2A = _BV (WGM20) | _BV (WGM21) | _BV (COM2B1); // fast PWM, clear OC2B on compare
TCCR2B = _BV (WGM22) | _BV (CS21); // fast PWM, prescaler of 8
OCR2A = (F_CPU / 8) / frequency - 1; // zero relative
OCR2B = ((OCR2A + 1) / 2) - 1; // 50% duty cycle
} // end of setup
void loop()
{
// do other stuff here
}
Plug your desired frequency into "frequency".
With the prescaler of 8 you can generate frequencies in the range 7813 Hz to 1 MHz.
Testing appears to confirm that OCR2A being zero doesn't work. It wouldn't with PWM modes because there is no "half" point (of zero) for the PWM duty cycle to be in. You could use OCR2A of zero for other modes. Since that register is zero-relative, an entry of zero means the timer does a single count.