SV Chronometer – a GPS based, interactive master clock

November 5th, 2008

    svchrono1  svchrono2  svchrono3

The finished SV Chronometer.

Time. We are all obsessed by it and it catches up with us all in the end. Especially women who don’t moisturise their elbows properly! I have my own little obsession with time. I often have a stop watch in my pocket, just so I can time things, I wear a 24 hour analogue watch (they are cheap on eBay!) and I get very, very annoyed that all the clocks in my house all show different times! You can set them all to the same time but eventually they all drift.

For example the exact time now is 17:34. The clock/weather station beside my PC shows 17:32. My wristwatch shows 17:35. My mobile phone shows 17:32. The living room clock shows 17:37. The microwave shows 17:35. The video shows –:–. And my Spanked Woman Rotating Legs clock shows 8:55. I suspect her batteries have gone flat! Speaking of time you might need a bit to read all of this. It is a somewhat rambling discussion of how this thing works!

The drifting problem is something I just have to live with. I have no control over the actual timepieces so they are all going to drift over time and I know I have to keep resetting them. They question is when I do reset them what do I reset them to? What is the correct time? This little project is to solve that problem.

I decided to build a stand-alone clock that I can use as a master time source to set all my other timepieces to. All it has to do is show me the correct time but I wanted it to be interesting to look at and interesting to use. A plastic box with an LCD display on it would be effective but not nearly as much fun! I decided to build some kind of mantel clock and I wanted to base my design on an old art deco Hammond clock. The time is displayed on a screen inside the box which is only visible when the user peers though the eye pieces and cranks a handle on the side of the casing. The name of the device, SV Chronometer, comes from the fact that it is using GPS satellites to receive the time. In GPS language the satellites are referred to as Space Vehicles.

There are various ways other to get accurate time. Radio clocks are one method. Network Time Protocol (NTP) is another. Accurate time signals, called PIPS,  are often broadcast over radio stations. And there are speaking clocks available as well. The Measurement Standards Laboratory has a list of the various time standards available here in New Zealand.

To be honest my PC would probably be the easiest way to get an accurate time signal. Microsoft provide simple(!) instructions for setting up Windows XP to use NTP. As my computer is always on and always connected to the Internet I should always have an accurate time source. Instructions on the easy way to do this in NZ are available from MSL. Another easy way to get accurate time in Auckland at least is the bus stops. I suspect these might be using GPS time also as they are always in sync with my watch!

I should point out here that when I say accurate I am meaning only to within a second or so. I am using the time to set physical clocks some of which can only be set to within a minute or so accuracy anyway. If all my clocks are accurate to within a minute I am happy.

Once upon a time I worked for Navman,  a company that makes GPS navigation devices. Having played with GPS there and knowing a bit about how it all works (for a REALLY good explanation have a look at the Trimble GPS site) I knew you can get a very accurate time signal from a simple GPS module. I happened to have such a module from my time at Navman. Actually as it turns out that one was a lame duck but I managed to find an exact  replacement cheaply on TradeMe.

 GPSModule1 GPS Module.

This particular GPS module is pretty simple. It has an onboard antenna as well as a connector to attach an external antenna. It runs off 5 volts and it has a very simple serial interface. I think most GPS modules available these days work in a similar way. The serial interface on this module outputs NMEA 0183 sentences. Basically the module is spitting out ASCII text that is giving you the GPS information. There are different sentences containing various pieces of information. Things like position, heading, speed, satellite information and, of course, time. Not all receivers give out all of the different sentences but time is one of the most basic so I think all GPS modules should have this available. Some pieces of information are available in multiple messages. Here is a complete list of the NMEA messages available.

The first thing I did was connect up my hand-held Garmin eTrek GPS unit to my PC using it’s serial cable. I was easily able to get that working and see the raw data in HyperTerminal. Next I tried connecting my Navman module up to the serial port on my PC to see what sentences it was giving me. I used a MAX232 chip between the module and the serial port to do the signal level conversion. I was rewarded with a nice stream of NMEA sentences.It provides the GPRMC, GPGGA, GPGSA and GPGSV messages.

One thing about the Navman module is that it runs at a very high serial speed, 57600bps. This was to make things interesting later on. From the NMEA messages I was getting I could see I could pull out the data I wanted. I can use the GPRMC message to get th time and the GPGSA message to get the fix accuracy.

This is an example of the actual GPS raw data the module outputs:


Once I knew the information was there the question was how to get at it inside a stand-alone clock. I decided I could use a PIC16F628 microprocessor to receive the NMEA messages from the GPS module then parse them to get the bits of data I wanted. The PIC is well suited for such a job as it has a built in serial port, it’s own memory and it can easily be programmed (using assembler) to drive an LCD module which is what I decided to use to display the actual time.

circuit1 Circuit and GPS module during testing.

Basically how it works is the GPS module sends out a group of NMEA messages every second. The PIC receives the serial data and writes it all into an internal buffer. I maintain an index to my position in the buffer. NMEA sentences can vary in length and the PIC only has limited memory but I worked out that the information I need is always in the first 13 bytes of the message. I made my buffer long enough to fit just the bytes I need. As the bytes of the sentence are received from the serial port they are put into the buffer until the buffer is full. If I receieve a ‘$’ character I restart at the beginning of the buffer as I know this is the start of a NMEA sentence. When the buffer is full everything else is then dropped.

As the bytes come in the PIC looks out for a ‘*’ character in the sentence. This happens regardless of whether the characters were written to the buffer or not. This character indicates  the check sum at the end of the NMEA message. I don’t use the checksum but I do use this character to indicate  I can examine what I have in the buffer from the message I have just received.

By examining the first few characters in the buffer I can determine what sentence I received. If it is one I am interested in I then copy the relevant bytes from the buffer into storage variables. . In my case I simply want the time, which is always UTC time, and the fix information, which tells me how accurate my satellite fix is. 

Because the Navman GPS module is running at a fast serial rate I found I didn’t have much time (measured in clock cycles) for parsing the messages. Luckily there was just enough time to extract out the time and fix data. It might have been nice to get the date also but that would cause other problem later on when I need to work out what time zone I am in.

Even though the serial data itself is transmitted very quickly the burst of data only happens every second. This gives me lots of time to actually manipulate and display the data between bursts once I have it.  To know when I can start displaying data I use one of the PICs internal timers. Timer 1 is set up so that it is reset each time a byte is received from the serial port. As data is received the timer is being continually reset. Once the serial data stops however the timer is left to run and eventually trigger an interrupt and I set about displaying the data. This will happen once a second after the data burst from the module.

Originally I was going to have the clock display as much information as I could. GPS could give me the location, heading, speed over ground, etc but really none of this information is very useful on a mantel clock that doesn’t move! In the end I decided to display only a minimum of information. The clock will show me the current UTC time, the time zone corrected time and the fix information. Time is displayed on a  2 line LCD display. The fix information is shown on the analogue meter on the front of the clock. When you don’t have a GPS fix the module will still output time but it is its own internal time. This is probably accurate enough for my purposes during the periods when the clock doesn’t have a real GPS fix.

backplate1 Assembled on back plate.

Displaying the time on the display makes use of some simple LCD routines I wrote for the PIC. The UTC time is displayed almost exactly as it was received from the GPS module only formatted in hh:mm:ss 24 hour format. The local time is displayed by adding on a  time zone correction to the UTC time.

That was actually an interesting problem. My clock won’t work for all time zones because I had to simplify how I handle the time zones in the PIC and also due to my almost non-existent user interface. I don’t actually store a time zone as such. All I do is store a value from 0 t0 23 in the PIC to represent the hour correction that needs to be added to the UTC time. This is enough to cover most of the time zones in the world as most are at hour offsets from UTC. There are a few odd time zones in the world with half or even quarter hour differences. I figured the chances of me moving to such a place is slim!

To change the time zone I have a simple push button on the back of the clock case. Each push of the button increments the internal value. When it goes above 23 I reset to 0 again. This value is stored in EEPROM on the PIC so even if the power goes off it remembers your time zone when it restarts. To display the local time I simple add on this value to UTC. This is where not displaying a date makes things very easy. Being able to correctly show a local date worked out from a UTC date with a time zone correction is actually quite tricky. You need to take into account if the time zone is a positive or a negative offset then you need to adjust the day appropriately. When you adjust the day you need to account for the start and end of a month and adjust that appropriately. And once you do that you need to account for leap years. It all starts getting complicated and needing look up tables and so on which is a little more than my poor PIC can handle. Also I generally know what day it is anyway! You also have to account for daylight savings time which is another complication if you wish to do it automatically. On my clock you simply change it manually. Hell, it’s only 2 button pushes once a year and 22 button pushes six months later! Or is it 23? I am always off by 1!

display1 The display (showing ‘Estimate’ instead of the UTC time).

The other main parts of the circuit don’t involve the PIC at all. The first is simply the MAX232 chip which I left in circuit between the GPS module and the PIC. On the back of the clock case is a RS232 port so I can connect the clock to any PC and see the raw NMEA messages if I want to. The second is more to do with the aesthetics of the clock which take some explaining.

The outer housing of the clock is obviously inspired (actually shamelessly copied) from the art deco Hammond clock. It is made from MDF which I then paint with thinned down polyurethane as a sealer then I spray ti with gloss black enamel paint. I didn’t want a simple clock face though. That would be far too boring. Instead what I have is a box you have to peer into in order to see the display. The front plate is painted steel and the eyepieces were made from a set of old, broken binoculars I removed the lenses from. To make the display look distant from the user and give the insides some depth there is a periscope system made up of two mirrors inside the casing . The display isn’t actually behind the eye pieces but is instead at the bottom of the casing and you are viewing it via the mirrors.

inside1 The inside showing mirror periscope.

To further obfuscate things (and this is where the interactive part comes in) the display isn’t actually visible if you just peer into the box. To actually read the time you need to crank a handle that is fixed to  the side of the housing. I was inspired by old fashioned “what the butler saw”  machines (actually called Mutoscope machines). Originally I played around with a mechanical shutter system where the crank flipped a little metal plate up and out of the way of the display so you could see it. The plate  was ‘bounced” by a cam so that you couldn’t simply turn the handle to one position to lift the shutter out of the way. You had to be actually rotating the crank for the screen to be visible.

inside2 The flywheel and switch.

The mechanical system worked but was finicky and also it made a horrible rattling noise! It occurred to me I could achieve the same effect electronically. Since the box is almost light tight and dark inside you have to use an LCD screen with a back light in order to see the display. To simulate the flickering effect I simply turn the back light on and off!  It worked out to be an elegant solution.

The crank handle is held to the case on a bearing carrier (something from something I junked so long ago I can’t remember what it was). I made the handle from a piece of steel suitably cut and drilled welded to an 8mm shaft. The shaft is held in place by a hex nut on the inside of the case. Attached to the inside of the case wall is a micro-switch with a lever on it. The lever runs against the hex nut and as the nut turns the switch is turned on and off six times per revolution. It also makes a great mechanical clicking noise which adds greatly to the whole cranking experience. To make the crank feel balanced I made a heavy lead fly wheel by melting down collected wheel balancing weights (I must admit I have a habit of collecting them off the road) and casting a rough disc. I machined that on the lathe to make a nice, heavy flywheel. One side has the lead hollowed out to help balance the handle and give a nice, smooth turning motion. Machining lead is not really a nice thing to be doing so I made sure I was wearing gloves, face mask and goggles (which you do for any machining of course). By keeping the speed right down I avoided chips flying all around the workshop and when I was done I was able to collect all the stray lead pieces and re-melt them into one lump. The lead is very easy to machine being so soft. The flywheel was then painted black to seal it.

flywheel1 Machining the lead flywheel.

The LCD back light isn’t connected directly to the micro switch. If I did that then you could stop the handle in one of 6 positions and read the display which ruins the interactivity of the whole project. Instead the switch is connected to a small circuit. The circuit uses every electronics hackers favourite friend the 555 timer! The timer is used to send a fixed length pulse via a transistor switch to the back light to turn it on briefly. A largish capacitor is connected across the back light LED to smooth out the pulse so instead of the display harshly flickering on and off it tends to rapidly fade in and out. The 555 is wired up slightly differently to what would be a normal monostable setup though to account for the fact that the trigger pulse can be longer than the timed pulse. Normally the trigger has to be shorter. This addition means stopping the crank in a position where the switch is pressed still only results in one quick pulse rather than the back light staying on.

The meter on the front of the box is used to display the fix information as previously mentioned. The meter will show no fix, a 2D fix or a 3D fix by flicking the meter needle on a 0 – 400 scale. 0 – 100 for no fix, 0 – 200 for a 2D fix and 0 – 300 for a 3D fix. I use the PICs built in PWM module to generate a 25%, 50% or 75% PWM signal that drives the meter to the correct position. If you have no fix the LCD will also display ‘ESTIMATE’ for the UTC time. Since the clock is updated every second between data bursts the meter needle flicks every second also. 

One quirk of the meter is when there is no fix the meter needle doesn’t move properly back to the zero position. This is due to it being 1, old and 2. dropped. Several times! The back of the meter housing was shattered so I had to repair it with a small piece of plastic. I have developed a habit of coming up and tapping the glass on the front of the meter when there is no fix to unstuck it and get it moving properly again. I find this just adds to the character of the clock!

A further addition is a simple LED inside the box which flashes in time to the meter on the front of the box. I used an ultra bright orange LED and this creates a nice, neon like glow that at night is visible flashing deep inside the box when you are lined up just right with the eye pieces.

Back1 Back plate.

On the back of the casing is a simple panel with connections for power, the external GPS antenna and the serial port as well as the time zone push button. The power supply has a bridge rectifier and a regulator so you can plug any ac/dc power supply up to about 15 volts or so in to power the clock. You can use any cheap power supply such as an old phone charger or wall power supply. The serial port is wired up to use a straight through cable. The external antenna connection means I can use an antenna on the roof to get a nice 360 degree view of the sky although I find it actually works pretty well inside on the window sill even though the view is limited. An external antenna is required since the actual module is mounted inside the box and it has no view of the sky.

inside3 Closing the back showing the internal layout.

And here is a link to a little YouTube video of the SV Chronometer in action. It is very hard to film it on my digital camera in such a way to show exactly how it works but hopefully you get the idea from this.




Posted in Projects | | Top Of Page

3 Responses to “SV Chronometer – a GPS based, interactive master clock”

  1. Michelle Says:

    Forget the GPS clock. Where can I get a spanking woman rotating legs clock?

  2. John Hills Says:

    Great idea – any chance of details on the circuit and code. Thanks.

  3. Adriaan Schreuder Says:

    Hello there,

    For now I have a GPS reciever board, I am very interresred in a schematic to translate the info from the GPS reciever into a clock module with a 7 segment LED display..
    Are you able to help me with this?
    I will very preciate this.