Building a better clock (part 1)
For many years, Enigma IT Solutions has developed and operated a number of highly accurate time network clocks. Our latest project is based around the Raspberry Pi, a low-cost single board computer. But don’t let the size (or price) fool you – for the cost, they’re quite a powerful machine and perfect for tinkering.
Unfortunately, one of the cost savings the Pi designers made was not to give it a real-time clock – a method of keeping its own clock running when it is turned off. In most cases, that’s not a huge issue – as the machine boots up, it will fetch it’s time from other time servers on the Internet. But, in this case we want to BE one of those magical Internet time servers, so adding a Real Time Clock was a must. After some research, I settled on the ChronoDot from Adafruit.
My choice was swayed by two main factors: it is temperature stabilised (oscillating/timing crystals can run at slightly different rates depending on the ambient temperature), and it offers a Square Wave output. The second point is important because it can be set to output a pulse at (precisely) 1 second intervals. The Raspberry Pi can use this feature as a timing source to help maintain the precision of it’s own operating clock.
——–
Of course, keeping the time precise is one issue, but we have to be able to set the time accurately in the first place (and maintain it).
From a previous project, I already had a GPS breakout board and an external antenna, so I decided to re-use these. For those not familiar with GPS timekeeping, the short version is that each Global Positioning System satellite has (at least) 3 atomic clocks on board. Each satellite continuously broadcasts its current position and the precise time. In order to get a fix on your location, it is necessary to see at least 4 satellites. Once you’ve established your exact position on Earth, getting an exact time is a matter of calculating the distance between your position and each satellite, and adding the time it takes to transmit the radio signal (the speed of light over that distance) to the time being broadcast.
The GPS breakout board connects via the Raspberry Pi’s serial port pins, and like the ChronoDot also offers a Pulse-per-Second output which can be wired to the Pi’s GPIO pins.
I spent a bit of time researching which of the two I should use – I couldn’t find the exact specifications of the ChronoDot’s tolerance but the GPS chip is regarded as accurate to within 10 nanoseconds. Anecdotally, ChronoDot is about the same the so I’ve decided at the moment to use BOTH, and let the NTP (Network Time Protocol) algorithm decide for itself which it prefers. Realistically, I’m running on an original series Raspberry Pi Model B, which is a single core Atom processor. I’d be surprised if I actually get 10 nanosecond accuracy and if I don’t, the bottleneck will not be caused by the choice of which of the two signals I’m referencing.
So, that’s the design work for Part 1 – The input side. In Part 2, we’ll look at the output side and conclude with putting it all together.