LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 09-13-2006, 04:43 AM   #1
AwesomeMachine
Senior Member
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian jessie/sid; OpenSuSE; Fedora
Posts: 1,592

Rep: Reputation: 162Reputation: 162
Post How To Use A Garmin 18 GPS Unit As An NTP Server With Microsecond Precision


It took me a bit of experimentation to figure out how to get 1 us
precision with the Garmin 18 LVC on linux.

Ingredients:

Garmin 18 LVC, soldered on a DB-9 connector for serial comm and PPS, and
a USB cable for 5 V power according to Terje:


http://lists.ntp.isc.org/pipermail/q...er/007878.html

Rodolfo's Git repo for LinuxPPS:

Git://git.enneenne.com/linuxpps

Udo van den Heuvel's ntpd NMEA patch:

http://time.qnan.org/linux2.6-pps/ntpd-nmea.patch

Linux 2.8.18.3 Kernel:

ftp://www.kernel.org/pub/linux/kerne....6.18.3.tar.gz

ntp-2.2.2p4.tar.gz:


http://www.ntp.org/downloads.html

CD 1 of Debian "testing" - Etch:

http://cdimage.debian.org/cdimage/we...s/i386/iso-cd/


I stuck the gps unit out the window on a flat piece of steel about 3
feet long, fastened to the aluminum storm and screen sill with self
tapping sheet metal screws. It only requires the flimsiest piece of
steel, with the edges bent downwards for rigidity and to brace the steel
against the storm and screen unit and keep it from flopping down. The
Garmin unit is magnetic, and stuck on the steel plate stock by itself.
This configuration has stood up to high winds, and a blizzard. I used
the 18 LVC 5 meter cable model for extra reach. To check if your unit
is connected right you can do:

cat /dev/ttyS0

and you should see some NMEA sentences on the screen every second.
There is an MS Windows program called SNSRCFG.exe available from Garmin
if you go to the OEM section of their site. (I knew there was some
reason for that XP partition) I have three 18 LVC's, and none of them
came from the factory with PPS activated. I downloaded SNSRCFG.exe:

http://www.garmin.com/products/gps18oem/

and ran it from a Windows XP installation. It was weird, but Windows
detected the Garmin as a serial mouse, and the cursor moved wantonly,
all over the desktop, creating mayhem; driven by the gps NMEA sentences.
So, I connected the gps after Windows booted. Then Windows didn't think
it was a mouse. Launch SNSRCFG, Leave baud rate on auto, and select com
1. I only want sentences $GPGGA, $GPGLL, and $GPRMC; and so disabled
the rest. I activated PPS, leaving everything else just the way it is.
I checked if the unit was in NMEA mode, and it was. The default 200 ms
PPS length seems adequate, and the assert edge of the signal is what
Garmin calibrates to UTC. I didn't need to know that for SNSRCFG.exe,
but I did for ntp.conf.

The 18 LVC and 18 5 Hz are the only Garmin 18s that have PPS signals. I
tried getting PPS activated on a 18 PC model and it wouldn't work. The
USB model doesn't even have enough wires (only 4) to physically be able
to have a separate PPS signal wire.

Rodolfo's git repository instructions:


http://www.wraith.sf.ca.us/ntp/linuxpps.html

to build a kernel patch for kernel 2.6.18.3. Rodolfo's LinuxPPS wiki is
here:


http://wiki.enneenne.com/index.php/LinuxPPS_support

A very helpful page is Philip M. White's:

http://time.qnan.org

Which describes an excellent method of building a Garmin 18 LVC
reference clock. The ntp-nmea.patch is on his site, although I'm fairly
sure that is not his real name.

I copied the linux-2.6.18.3.tar.bz2 kernel sources:
curl -O ftp://www.kernel.org/pub/linux/kerne...6.18.3.tar.bz2

Curl puts the file in current working directory, and is fast. I used
Debian Etch installed using CD 1 with a Debian mirror chosen during the
install for the bulk of necessary files. Debian Etch is a lean mean
distro, and easy to work with.

cp linux-2.6.18.3.tar.bz2 /usr/src

Install qt development packages, kernel-package,
linux-patch-debian-2.6.17, git-core and yaird with:

dselect

I needed to do an access and update with dselect, so have the URL of at
least 1 Debian mirror written down. I use:

ftp://ftp.egr.msu.edu/debian/

for an apt source. I also get rid of CDROM as a source or Debian always
asks for it when I install software. If I keep it in the drive it boots
the machine from the CD whenever I reboot. So, I just take it out. I
extract the kernel sources in /usr/src with:

tar xvfj *3*

because there is nothing in /usr/src with a 3 in the filename besides
linux-2.6.18.3.tar.bz2. After the file extracts it makes a directory
called linux-2.6.18.3, which I make a symlink to like this:

debian3:/usr/src # ln -s *3 linux

because the directory I want to symlink to is the only thing in /usr/src
that ends with 3. I made the LinuxPPS patch from the LinuxPPS git
repository, which, because I read the instructions in the instructions
link I gave earlier, was resident on my HDD. I copied the patch
to /usr/src/linux. I needed to make the patch from inside the
directory /home/sam/linuxpps.

To patch the kernel:

debian3:/usr/src/linux # patch -p1 -i <linuxpps-patch>

/usr/src/linux/include/linux/netlink.h

failed to patch correctly. I opened the patch file in one terminal,
searched for netlink.h, and found the part of the patch that referred to
netlink.h. In nano this function is "ctrl w". Then, I
opened /usr/src/linux/include/linux/netlink.h, and did a search for the
line and column number where the patch was supposed to go. In nano you
do "ctrl-shift-_", and enter line, column. It is fairly easy from this
point to manually patch netlink.h with the PPS line.

cp /boot/config-2.6.xx.y /usr/src/linux/.config

make xconfig

I don't try to change things I don't have to. You need to check "Prompt
for experimental drivers" to have the PPS module visible down the list.
I compiled serial drivers in with the kernel. I needed to select PPS
drivers to be compiled with the kernel also. PPS 8250 support is
needed. I can select both as modules, but can't make one a module and
one compiled in with the kernel. I save the .config file, and do:

make-kpkg --added-patches=debian --revision=xyz kernel_image

This will make a .deb file of the kernel image in /usr/src. When the
compile is done, I cd .. out of /usr/src/linux into /usr/src and do:

dpkg -i *.deb

Then do:

yaird --output=/boot/initrd.img-2.6.18.3<space>2.6.18.3

Then do:

nano /boot/grub/men*

and change the new kernel entry to reflect an initrd file named
initrd.img-2.6.18.3 by adding an initrd line after the kernel line in
the first boot entry. I edit the kernel line to read noapic nolapic
acpi=off noapm at the end of the line because I don't want any of that
running with the time server when I reboot. Reboot with the new kernel.

cp /usr/src/linux-2.6.18.3/include/linux/timepps.h timex.h /usr/include/

I used ntp-4.2.2p4.tar.gz from the ntp.org site. You need the
ntp-nmea.patch file from Philip M. White's http://time.qnan.org page.
After you extract the ntp-4.2.2p4.tar.gz file with

cd /home/sam

or wherever the ntp archive file is.

tar zxvf *2p4*

cd *4

cp ../*nm* ntp-nmea.patch

patch -p1 -i *.patch

./configure --disable-all-clocks --disable-parse-clocks --enable-NMEA
--enable-LOCAL-CLOCK --enable-linuxcaps

make

nano /etc/ntp.conf


#ntp.conf, ntp configuration

restrict default nomodify

restrict 127.0.0.1

server 127.127.20.0 minpoll 4 prefer
fudge 127.127.20.0 time1 0.0 flag3 1 flag2 0

server time-a.nist.gov
server time-b.nist.gov
server time-c.timefreq.bldrdoc.gov

driftfile /var/lib/ntp/drift

keys /etc/ntp/keys

logconfig = +syncall +clockall +sysall +peerall
logfile /var/log/ntpd.log

statsdir /var/lib/ntp/ntpstats/
statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable

save the file and exit

mkdir /etc/ntp
touch /etc/ntp/keys

mkdir /var/lib/ntp
touch /var/lib/ntp/drift
chmod g+w /var/lib/ntp/drift

mkdir /var/lib/ntp/ntpstats
touch /var/lib/ntp/ntpstats/loopstats
touch /var/lib/ntp/ntpstats/clockstats
touch /var/lib/ntp/ntpstats/peerstats

touch /var/log/ntpd.log

ln -s /dev/ttyS0 /dev/gps0

from the ntp directory where I configure and make the ntp programs, as
root:

ntpd/./ntpd -g

And in a tabbed terminal:

tail -f /var/log/ntpd.log
tail -f /var/lib/ntp/ntpstats/peerstats
tail -f /var/lib/ntp/ntpstats/loopstats
tail -f /var/lib/ntp/ntpstats/clockstats

then try ntpq/./ntpq -c rv -p

I've gotten excellent performance with this method:

debian1:/home/tom/time/ntp-4.2.2p4# ntpq/./ntpq -c rv -p
assID=0 status=0444 leap_none, sync_uhf_clock, 4 events,
event_peer/strat_chg,
version="ntpd 4.2.2p4 at 1.1585-o Wed Nov 29 23:30:04 UTC 2006 (1)",
processor="i686", system="Linux/2.6.18.3pps", leap=00, stratum=1,
precision=-20, rootdelay=0.000, rootdispersion=0.376, peer=7197,
refid=GPS, reftime=c918dda8.2ecfb2e2 Wed, Nov 29 2006 22:33:44.182,
poll=5, clock=c918ddb0.cf8c2d4d Wed, Nov 29 2006 22:33:52.810, state=4,
offset=0.000, frequency=57.894, jitter=0.003, noise=0.001,
stability=0.001, tai=0
remote refid st t when poll reach delay offset
jitter
==============================================================================
*GPS_NMEA(0) .GPS. 0 l 8 16 377 0.000 0.000
0.003
+time.nist.gov .ACTS. 1 u 64 64 377 50.920 1.247
2.821
-time-a.nist.gov .ACTS. 1 u 59 64 377 60.612 3.590
1.838
-time-b.nist.gov .ACTS. 1 u 50 64 367 61.990 4.104
7.483
+time-c.timefreq .ACTS. 1 u 1 64 377 50.955 1.217
1.725

debian1:/home/tom/time/ntp-4.2.2p4# ntpdc/./ntpdc
ntpdc> kern
pll offset: 0 s
pll frequency: 57.894 ppm
maximum error: 0.001504 s
estimated error: 1e-06 s
status: 0001 pll
pll time constant: 1
precision: 1e-06 s
frequency tolerance: 512 ppm

ntpdc> sysinfo
system peer: GPS_NMEA(0)
system peer mode: client
leap indicator: 00
stratum: 1
precision: -20
root distance: 0.00000 s
root dispersion: 0.00035 s
reference ID: [GPS]
reference time: c918ddb8.2f086614 Wed, Nov 29 2006 22:34:00.183
system flags: auth monitor ntp kernel stats
jitter: 0.000000 s
stability: 0.000 ppm
broadcastdelay: 0.003998 s
authdelay: 0.000000 s
ntpdc>


Cheers,

Tom

If PPS is working, tail /var/log/syslog should reveal a pps source was
found after ntpd -g is started. If you compiled pps debug into the
kernel, dmesg should show pps events. /proc/pps/sources should show 4
entries.


If I messed up and said something wrong people might want to read to the
end of this thread before they accept this method as foolproof. I know
how to do this this exact way, but before a reader undertakes to get an
ntp server up they should have some idea of what ntp does, and how it
works because once the server is up it has to be taken care of. Ntp
servers are not magical. There are problems encountered along the way.
I'll try to watch this thread, but I'm writing a book right now so am
quite busy. I do, however, know what time it is. I have two machines
configured the exact same way, and I get 1 us accuracy on both. One is
an AMD athlon, and one is a Pentium 4. You also want to turn off spread
spectrum in the bios setup program.

Last edited by AwesomeMachine; 02-08-2007 at 11:52 AM. Reason: New Data
 
Old 09-13-2006, 04:19 PM   #2
J.W.
LQ Veteran
 
Registered: Mar 2003
Location: Milwaukee, WI
Distribution: Mint
Posts: 6,642

Rep: Reputation: 69
You might want to consider submitting this as a Linux Answer. Please click on the Linux Tutorials link in the upper right hand "Main Menu" box
 
Old 09-17-2006, 11:00 PM   #3
AwesomeMachine
Senior Member
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian jessie/sid; OpenSuSE; Fedora
Posts: 1,592

Original Poster
Rep: Reputation: 162Reputation: 162
I tried making a howto out of it, but it didn't work. I couldn't preview it. So, I'm leaving it here for now.
 
Old 02-08-2007, 11:55 AM   #4
AwesomeMachine
Senior Member
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian jessie/sid; OpenSuSE; Fedora
Posts: 1,592

Original Poster
Rep: Reputation: 162Reputation: 162
This op is completely redone, so I'm replying.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Debian 3.1 and Garmin GPS ekimyerac Linux - General 2 03-27-2006 07:52 AM
Audigy2 ZS PRO external unit Synesthesia Linux - Hardware 2 01-21-2006 05:25 PM
Garmin GPS V and NTPD figadiablo Linux - Hardware 1 04-08-2005 03:58 PM
External DVD-RW unit, Firewire/USB but does it work? davecs Linux - Hardware 0 02-26-2005 02:58 PM
Garmin GPS-18 - Need a Driver mWare Linux - Hardware 0 06-15-2004 10:21 PM


All times are GMT -5. The time now is 01:13 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration