Syncing Arduino with GPS time

Most people have little need to synchronize clocks to the minute, much less to the millisecond….. but if you do need it, here is how to get millisecond (ms) accuracy in absolute time with Arduino using GPS.

We start with the 1pps signal from the GPS receiver.  The 1pps signal is available from most GPS modules, but double check if you are ordering one for this purpose.  1pps stands for 1 pulse per second.  The pulse is a very short (20 uS = 20/1,000,000 seconds) pulse whose rising edge coincides with the beginning of a second in GPS time.

For some reason, the GPS shield I got from spark fun, did not connect to the 1pps signal even though it had a spot for it.  Checking further showed that only one of the three GPS headers was connected to the 1pps signal.  I red-wired the missing link.

 

I hooked this 1pps signal into digital pin 2 (INT0) so that I could use the hardware interrupt to capture the rising edge of that pulse.  Using this as the absolute 1 second reference, we can measure the drift of the DS3231 real time clock chip.  This is the same chip that is used in the ChronoDot.

I did this by hooking up the 1Hz square wave to digital pin 3 (INT1) and used interrupts to measure time drift DS3231.  My initial test showed it to be loosing about second per year to the GPS time.  Not bad considering they only claim to be accurate to about a minute per year.  Another way to look at the drift is that it will take about 6 hours to loose a milli second (1/1000 of a second).   As long as we can sync with GPS once every 6 hours, we should be able to maintain timing precision and accuracy to a millisecond.

One thought on “Syncing Arduino with GPS time

  1. Pingback: Bald Wisdom » Blog Archive » Using GPS with AlaMode

Leave a Reply