Microsecond Precision From Garmin 18 LVC GPS unit with PPS Signal And NTP
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
By AwesomeMachine at 2006-10-08 17:23
The Garmin 18 LVC is one of the slickest devices to use as a very accurate clock. It costs about $85 USA, It is a snap to configure, but Garmin makes it difficult to use these devices as reference clocks because they refuse to connect the PPS signal wire on any of their prewired versions. The bare wire Garmin 18 LVC is the only variation of the Garmin 18 line which has PPS (pulse per second) capability. This post uses Fedora Core 5 because ntp is already patched with the gps NMEA driver patch in FC5. If you want to run a time server I recommend FC5.
Buy only the 'Garmin 18 LVC' model, which is an OEM unit. The fattest black and red wires are for power. You strip those and connect them to the red and black leads from a USB cable that is bare wire on one end. You can make your own. Just chop a USB cable in half, and use the half that plugs into the PC chassis. That's the part you solder on to the Garmin 18 power leads.
The rest of the wiring is according to http://lists.ntp.isc.org/pipermail/q...er/007878.html
The pin numbers are printed on the connector, really tiny. If you are looking at the holes in the female connector, with the row of 5 pins up, pin 1 is on the right of the 5 pins. Moving to the left are pins 2, 3, 4, and 5, like this: 54321. The other 4 pins you don't use.
pin signal colour
1 PPS yellow
2 TX white
3 RX green
5 GND black
When you flip the serial connector over to solder the leads, pin 1 jumps to the far left, if the row of 5 pins is on top. You might want to buy a few extra female DB-9 serial connectors, and tin the leads on the Garmin 18 LVC before you try to put them in the little soldering holes. Use about a 75 watt iron, with some flux core solder, the smallest diameter you can get. When you solder you need to get the metal you are soldering together hot enough to melt solder. You don't melt the solder on the metal to be bonded. You place the soldering iron tip against the soldering hole in the DB-9 connector and touch the solder to the metal soldering hole on the connector. When the solder melts the connector is hot enough to bond with solder. For a soldering vise I use a pliers with a rubber band around the handles. Close everything up, turn the computer off, plug the serial connector in the PC chassis, plug the power cable into a USB port. It doesn't matter if it is USB 1.1 or USB 2.0. And, BTW, the Garmin 18 uses 5volt power. Put the GPS unit where it can see some of the sky, and turn on the computer. Leave it for a few minutes so it can get a fix on some GPS satellites, and get the PPS going accurately.
Make this entry in /etc/ntp.conf, or install ntp and then do it:
# NMEA Clock using Garmin GPS
server 127.127.20.0 mode 1 version 4 prefer
fudge 127.127.20.0 refid PPS flag2 1 flag3 1 time1 0.000 stratum 1
And, add some pool servers:
Then, make a softlink to /dev/ttyS0:
ln -s ttyS0 gps0
Issue the following command:
/usr/sbin/ntpq -c rv -p
And you should see something at least remotely similar to this:
But, the specs should be a little more respectable because mine can only see 1/10 of the sky. This clock configuration, if it can see 1/3 of the sky, is accurate to 15 microseconds every second. When the system clock is off by an entire second, ntp will set the clock to the accurate time, using the GPS. It took me two hours to do this, so I hope many people; who want accurate time can easily build a stratum 1 time server. Or for accurate time on a network this clock can be used as a primary ntp source. Reference clocks sell for $5,000.00 on up, until now that is. Now they're $85.00. So, buy a few for your friends, and wire them up.
Up to this point we are using the $GPGGA string from the GPS unit to get the time. There is a way to use the PPS pulse from the gps to keep even more accurate time. A gps system in NMEA mode outputs lines of text you can see in a terminal program, such as minicom. If you get minicom, install it, and type:
a menu will pop up, and you can set what serial port to use, among other things. You want settings:
4800 8 - N - 1
and the com port your gps is connected to, which is probably:
It is ttyS0 or ttyS1
You don't want minicom to initialize the gps, so after you have it configured you always launch it with:
and it will not send an initialization string, used for a modem, to the gps. The gps doesn't really care, but it might mess something up if you keep doing it without theoswitch. When you want to quit minicom:
If you get minicom configured correctly you will scrolling lines of gps output going pretty fast. Now you should read the classic page by Philip M. White here: http://time.qnan.org/#hardware . That's QNAN.org, not QUAN.org. There is some rough explanation on that page of how to use the LinuxPPS kernel patch. I use pristine kernel sources from kernel.org because the Fedora kernel source wouldn't patch. PPS means pulse per second, I think. The rise of the PPS signal on the Garmin 18 is the exact second, withing 1 microsecond, or millionth of a second. So, bookmark this page, read Philip White's page, and then come back here.
Once you get the proper version kernel source from kernel.org, put the compressed file in the directory with all you other kernel sources, which is usually:
But, it can also be:
In the case of Redhat or Fedora Core 5. Expand the compressed kernel sources, and copy the LinuxPPS patch you got from Philip White's page to the resulting directory. Apply the patch with:
patch -p1 -i <ntp-pps-rc7.diff>
The patch should not cause problems. What is going to cause problems is getting a .config file. The FC5 config files in /boot will not work because Fedora applies so many patches to the kernel the config file contains things that aren't in Kconfig of the pristine kernel sources. The 2.6.15 config file in Debian Etch worked for me. You simply copy the file that begins with config-2.6.15 from /boot to the new kernel sources directory as .config and run:
From the new kernel sources directory. If xconfig complains about Kconfig, just edit out the parts of Kconfig it doesn't like. You have to configure everything under PPS, and 8250/16550 serial port support as a module, or dot, not a check mark. If you compile the serial drivers with a check mark, or as part of the kernel, they will load before pps_core, which needs to load first in order for this to work. These configuration options must have dots next to them. In the processor section of the xconfig program there are 3 numbers: 100, 250, 1000. Down the list a ways. You want 100. 1000 does not make the machine go faster, in fact, 1000 gives a big performance hit, and the major linux distros all have it set there. That setting is why linux gets slower and slower with new versions. I compliment Fedora for setting this at 250, which isn't too bad. But, for timing with PPS you want 100. Anyone who is compiling a kernel for a desktop system does not want 1000. Once you are done configuring the kernel, and don't touch anything if you don't know what it is, you issue the following commands:
This will take between 20 minutes and 4 hours. The rest goes pretty fast. As root:
After make install there is a command that is put on the screen, which begins with sh. Highlight that with the mouse, and use the copy function from the edit menu, and then paste, enter. This will make initrd, configure grub, and install the kernel and System.mapin/boot. Now you can boot with the new kernel.
FC5 ntp has NMEA support built in. You just:
yum install ntp
Edit /etc/ntp.conf adding these lines and commenting out the previous NMEA server and fudge lines:
#script to set up LinuxPPS on ntp NMEA driver
#ntp dies when restarted if it is running when gps0 is linked up to ttyS0
#so stop ntpd first
#load PPS and 8250 serial modules
#softlink to ttyS0 needed by ntp NMEA driver
#this must be gps0, and must be linked after
ln -s /dev/ttyS0 /dev/gps0
#start ntpd daemon
#PPS will be read from gps
And don't run the script more than once per boot, or you will load the modules multiple times. Copy:
Read Philip Whites excellent paper: http://time.qnan.org/#hardware to learn what your outputs from should be if the kernel modules load correctly, and ntp is truly receiving the PPS signal from the gps device. For the rest of this tutorial, use Philip Whites excellent paper. Now you have a stratum 1 time server, and you can join the pool. Plus, your computer clock will always tell the correct time, even if you lose internet for a while. To make this paper a little expandable into the future, as of 9/17/06, gpsd was nearing the point it would read and output PPS from a gps. Gpsd might be a simpler better choice in the future. It certainly is less complicated than patching the kernel. Gpsd uses localhost:2947.