CTC output at 32.768kHz

All,

Quick question, is it possible to generate a clock with the CTC outputs on the Arduino with accuracy between 32759.8 Hz and 32776.2 Hz?

Thanks,

JD

16000000/(21(1+243)) = 32786.8852459 ...too high.
16000000/(21(1+244)) = 32653.0612245 ...too low.

Not using an 8 bit timer.

The formula is the same for 16 bit timers.

So... looks like I need to build an external clock.

I appreciate the help!

You can generate an average frequency of 32768 Hz as follows. Use an 8-bit timer to generate the clock, with TOP switching between 243 and 244 such that the average value is 243.140625. To do this, program the timer to generate an interrupt every time the counter reaches TOP, and use the interrupt to switch TOP between 243 and 244 when required. For example, if every 7 interrupts you set TOP to 244, and you set TOP to 243 the remaining 6 times, then you will average 243.14285, giving you a frequency of 32767.004 Hz. There will be a small amount of jitter in the output, but if it's feeding a clock or a timer than that's unlikely to matter.

Bear in mind that most Arduinos use a ceramic resonator to generate the clock, which means that the clock frequency can be up to 0.5% out.

[EDIT: the maths is slightly wrong in the above because you can't just take the average count, so using 243 and 244 in the ratio 6:1 actually gives a frequency of 32767.70 Hz.]