DisgruntledGoat.com
Please smash forehead on keyboard to continue
- - - - -
Most popular:
Menu:
:: Home
:: Fascinations
:: Goat Labs
:: Miscellany
:: RANT!
:: Silly stuff
:: Useful stuff
:: Cars & Driving
Hosted by
Web Without Wires from Zycomm
:: Printable version
Custom Search

Building a Stratum One timeserver using a GPS reference clock

Last updated: 9th February 2009

Why?

Same answer as for most of the other useless crap I fiddle with - because I can :-D

I'd been fiddling with NTP at work and the whole concept started to fascinate me. I wanted to see if I could build a robust, authoritative top-level NTP time source for a deal less than people like Galleon seem to like charging. Don't get me wrong - their products look very good, but they cost money :-P

Having decided to take the cheapskate route and done some rummaging on the internets, the following bill of "materials" (read: tat) was decided upon:

  • Machine to act as the time server
  • GPS unit that supports a PPS output
  • Antenna for GPS

Any bill of materials that is three items long is fine by me! So...

The time machine

Meet Minion.
Minion!

Minion is, according to some random dictionary: An obsequious or servile dependent or agent of another. Minion's job is indeed to do the kind of tedious-yet-important jobs on my network that need to be done all of the time with the minimum of both fuss and power consumption (I refer you to the above regarding the cheapskate concept).

As such, amongst other things, Minion spends its time acting as a syslog server, downloading DVD install images of random BSD distributions, recording SNMP stats and generally causing no fuss whatsoever. It had uptime of nearly a year before I decided to rearrange my office the other day and hence is firmly categorised as "suitably reliable". It spins its disks down when not in use and, when bored and clocked down to a few hundred MHz, pulls a whopping 24 watts from the wall.

The Reference Clock

In order to become a stratum one time source, you need a direct connection to a so-called reference clock. These reference clocks are effectively stratum zero - they are the closest reference to an absolute time source that describes UTC.

Various reference clocks exist and have various pros and cons to them:

Reference clock type NTP reference Pros Cons
GPS .GPS. Very accurate
Cheap as upmarket chips
GPS receivers with an accurate PPS output can be expensive
For decent performance, an outdoor, well located antenna is requried

So, it comes down to GPS, GPS or GPS :-)

I had a quick peruse through eBay and found a Trimble GPS gadget that had a PPS output for about £20 from this eBay seller. I've also seen similar modules for sale from this chap and this chap, too.

Interfacing the reference clock

Initial circuit diagram of GPS level converter board (probably broken):

GPS level converter schematic

Surprisingly, this all appeared to work first time! Here's a photo of the finished prototype:

First prototype

It's as tatty as hell, but it does the job. It performs three basic functions:

  • Smooth, stable 5v power supply
  • TTL-to-RS232 level conversion
  • A bit of signal snooping, monitoring the PPS, TXD and RXD lines

An L7805 provides a 5v rail. The input and output of the reg is bridged by a 470μF and a 10μF capacitor respectively to try and smooth things out a bit. The 5v rail created by the L7805 then powers the MAX232 level shifter and the GPS module itself.

Thee light-duty transistors have their bases coupled to the TTL-side of the MAX232 PPS, TXD and RXD lines, which in turn drive three LEDs to give some indication that the device is doing what it should.

Once the thing was proven to work, it was time to build a version small enough to squeeze along side the GPS module within Minion's chassis. The same basic design was employed, but this time without the LEDs:

Second prototype - top view

The new converter board was piggybacked to the GPS enclosure and the whole shebang squeezed into Minion's case:

Second prototype installed

Rather than using the external serial port, I made up a 10-pin PCB header cable to attach directly to the EPIA MII's internal serial port. Overall the effect is quite pleasing:

Second prototype - final install

Power is taken from the spare molex provided by the PicoPSU's trailing cable and attaches to a header directly infront of the reg. All in all, it has proved to be a suspiciously neat install!

Software configuration

Linux Kernel

In order to take advantage of accurate PPS timing, the Linux kernel needs to be patched for PPS support. At the time of writing, the latest Gentoo kernel in Gentoo's unstable branch is gentoo-sources-2.6.28-r2, so I'm going to work against that.

First of all, you need to download the LinuxPPS patch here. I found this site a tad slow, so I've mirrored this patch here.

Apply the patch in the time-honoured tradition:

# cd /usr/src/gentoo-sources-2.6.28-r2
# patch -p1 < /path/to/patch/ntp-pps-2.6.28-rc6-ter.diff

The patch applied cleanly with me, so no additional fiddling around was required. Using your favourite kernel config method, make sure PPS support is enabled:

<M> PPS support
[ ]   Use low level IRQ timestamps
[ ]   PPS debugging messages
      *** PPS clients support ***
<M>   Kernel timer client (Testing client, use for debug)
<M>   PPS line discipline
[ ]   Parallel printer support     

Build your kernel as normal, install it and reboot.

In order for apps to compile against the extra functionality in the kernel, we now have to fiddle around with the header files a tad:

# cd /usr/include
# mv linux linux.old
# mv asm asm.old
# mv asm-generic asm-generic.old
# ln -s /lib/modules/$(uname -r)/build/include/linux linux
# ln -s /lib/modules/$(uname -r)/build/arch/x86/include/asm asm
# ln -s /lib/modules/$(uname -r)/build/include/asm-generic asm-generic
# cp /lib/modules/$(uname -r)/build/Documentation/pps/timepps.h timepps.h
This will allow the userland tools and things like the patched version of NTPd (see next section) to complile correctly.



This page was last updated: 23rd February 2009 at 10:33pm GMT
© 1998 - 2009 disgruntledgoat.com, all rights reserved. Privacy info