[time-nuts] precision timing pulse
Tom Van Baak
tvb at LeapSecond.com
Wed Nov 16 18:27:42 EST 2016
Chris & Chris,
Yes the "TVB dividers" are instruction loops where every cycle is counted by hand, and then verified with a simulator, and then checked with a time interval counter. All the code is out there at www.leapsecond.com/pic/
I use PIC's for historical and technical reasons. Modern CPU's and MCU's have so many layers of optimization that they are no longer deterministic at the cycle level. This makes them worthless for precise time applications. In addition many of them use clock edge or PLL tricks to increase speed, but this introduces jitter. Or they enable interrupts which kills precise timing. The PIC's are old-school, fully synchronous and use only one clock edge so the jitter is down at the picosecond level. My code is isochronous and doesn't use interrupts for timing. It acts like a poor man's FPGA.
Arduino probably uses compiled code, external libraries, and interrupts so that also is a no-no for precise time. I'm not sure about bare metal AVR. I hope someone can do measurements on an AVR divider one day so we can compare PIC and AVR jitter. I worry about how AVR implements the clock. So this is an open question. But I know how PIC's work so that's what I use. BTW, these are "ancient" PIC 12F parts. It's possible modern 16- and 32-bit PIC's also go to the dark side and optimize for performance rather than picosecond determinism. Another open question.
Realize that using a MCU for a frequency divider is a weird niche use of the chip, so none of what I say applies if you plan to use any of these as a general purpose computing system.
Also, we don't know if OP is looking for microsecond, nanosecond, or picosecond precision in his timing pulses.
> I'm wondering why everyone seems to be assuming a PIC is the right
> processor. Of course it could work for this but I'd select whatever is
> the easiest to program and debug. Those tend to the they little single
> board development systems that sell for under $10. They typically have USB
> connections to a computer and don't require any specialized equipment to
> program. The Arduino is the prime example of these although I've moved to
> ARM based uP because they can be less expensive with an order of magnitude
> better performance and can use the same Arduino IDE and run Arduino
> sketches. The PIC is not so beginner friendly and requires some study
> before it can be used. But if you as said of course a PIC could work,
> this is a pretty simple application
> You could use AVR (arduino), but once you get to most of the ARM
> processors it is harder to make them deterministic because of caches. You
> want a processor where the number of clocks is constant for all or almost
> all instructions, and is easy enough that you can code the loops by hand.
> Code like TVB's divider probably doesn't even use interrupts, it's just a
> tight loop where the number of instructions is counted to give the
> behavior wanted.
More information about the time-nuts