# [time-nuts] How to get 32.768KHz from 10MHz.

Tom Van Baak tvb at LeapSecond.com
Wed Jul 23 16:17:08 EDT 2008

```> Since synchronization is more important than jitter in this
> application it's easy to generate 32 kHz from 10 MHz.
>
> A 10 MHz clock into a PIC gives a 400 ns/instruction time.
>
> To produce 32.768 kHz you flip an output pin put every 38
> instructions, except that 9632 times per second you make
> it 39 instructions instead.
>
> The result is 65536 bit flips per second (giving a frequency
> of exactly 32768 Hz) consuming 2 500 000 instructions per
> second. The output accuracy equals the input accuracy.
> The output jitter is as most 400 ns.
>
> /tvb

I just prototyped this PIC algorithm and it works perfectly:
Exactly 10 MHz in gives exactly 32.768 kHz out.

There are several ways to manage the variable 38 vs. 39
instruction cycle duration of the output waveform.

The crude way, for every 65536 half-cycles, is to generate the
first 9632 using 39 instructions and the remaining 55904 using
38 instructions. This uses a total of (9632*39) + (55904*38) =
2500000 instructions (10 MHz) to generate a 32768 Hz output
clock.

But if you note that 2500000 / 65536 = 38.14697265625 and
think about leap years, there are cute ways to distribute these
"leap cycles" more evenly throughout successive one second
periods, if that is desired.

/tvb

```