Recently I was working on a project involving an ARM processor and a Bluetooth module which required a clock signal at 32.768 kHz. To avoid adding an external oscillator, we tried to use the ARM processor as a clock source. The clock speed on the ARM was 72 MHz, with a user specified 16 bit pre-scaler and 16 bit compare register. To determine what pre-scaler and compare values could be used to get closest to the required frequency, I wrote the following small program:
In less than 20 seconds, it found out that with a prescaler of 2197 and a compare value of 1, the output frequency would be 32881 Hz. Unfortunately that was not within the tolerances of the bluetooth module, so an external oscillator was added to the schematic.