[time-nuts] 10 MHz to 32.768 kHz converter

Tom Van Baak tvb at LeapSecond.com
Sun Mar 20 19:57:13 EDT 2016


Martyn, Hal, Magnus,

The PIC code for perfect 10 MHz to 32768 Hz division is here:

http://leapsecond.com/pic/src/pd30.asm

For PIC division of 10 MHz to 32768 Hz, each second you want 55904 short half-cycles of 38 instructions (38 x 400 ns = 15.2 us) and 9632 long half-cycles of 39 instructions (39 x 400 ns = 15.6 us). The average is then exactly 65536 half-cycles per second which gives you a 32768 Hz square wave.

Now, when you write code for this, one way is to do all the short cycles and then do all the long cycles. The problem with this approach is that the phase drifts horribly within each second, by up to 3 milliseconds! It's possible the device you feed this signal into will not like that much drift during each second.

So an alternative way is to intersperse short cycles and long cycles as optimally as possible -- using a binary method reminiscent of the leap year algorithm. This keeps the jitter down to within 400 ns. Doing this all within 38 instructions is a challenge but I came up with a way to do it. See the link above.

True, both methods give an average of 32 kHz over 1 second. But the leap cycle method has 8000 times less phase drift during each second.

I tested with three "4-pin" PIC dividers:
1) divide 10 MHz ref to 1 Hz with PD07
2) divide 10 MHz ref to 32768 Hz with PD30 and then divide that 32768 Hz to 1 Hz with PD33
3) compare 1PPS output of PD07 with 1PPS output of PD33

Documentation / source / hex code:
http://leapsecond.com/pic/src/pd07.asm pd07.hex
http://leapsecond.com/pic/src/pd30.asm pd30.hex
http://leapsecond.com/pic/src/pd33.asm pd33.hex

/tvb


More information about the time-nuts mailing list