Paul Kennedy
Posts: 38
Joined: Tue Aug 07, 2012 12:12 am

Re: NTP PPS

Sat Sep 01, 2012 1:32 am

I have figured out what the issue is with this device. It runs at a very slow baud of 4800. While that is not a problem in itself, the device appears to be hardwired to output various NMEA sentences. The first one it outputs is $GPGSA (the satellites in view).

Unfortunately, this sentence has a highly variable length. at 4800 baud, each char takes ~2millisecs to transmit, therefore when a new satellite comes or goes, the GPGSA string length will change, resulting in delays for RMC, GGA etc. Basically, if I cannot disable the unwanted strings, I might as well use this GPS as a doorstop.

Code: Select all

per epoch...
$GPGSA,A,3,03,11,32,22,31,01,,,,,,,5.8,2.1,5.4*3C
$GPRMC,011922.000,A,3152.2913,S,11545.2102,E,0.00,,010912,,,A*66
$GPGGA,011923.000,3152.2913,S,11545.2102,E,1,06,2.1,-35.7,M,-29.5,M,,0000*7A
$GPGLL,3152.2913,S,11545.2102,E,011923.000,A,A*45
repeated on the next epoch...
See the commas in the string above - they get populated as satellites appear. :cry:

User avatar
aquarat
Posts: 73
Joined: Thu Jul 26, 2012 2:32 pm
Location: Cape Town, South Africa

Re: NTP PPS

Thu Sep 06, 2012 4:11 pm

Hey Paul

Considering the price of the GPS a jitter of 5ms is fairly impressive :) .
EOF

Paul Kennedy
Posts: 38
Joined: Tue Aug 07, 2012 12:12 am

Re: NTP PPS

Fri Sep 07, 2012 8:52 am

Hi
travelling this week, but I believe I can improve this. My goal is 1 millisecond. The GPS manufacturer kindly provided the instruction set to manage output sentences and baud rates. I will be able to test my theory next week. Will also seek out a static IP. If this all works, I will have a very cost effective solution in place for our operations.

User avatar
aquarat
Posts: 73
Joined: Thu Jul 26, 2012 2:32 pm
Location: Cape Town, South Africa

Re: NTP PPS

Fri Sep 07, 2012 5:26 pm

Hey Paul

Revelation! The NMEA driver in ntpd reads the PPS too... so only one "server" line is required to get both NMEA and PPS data into ntpd.

Indeed ntpq -p now selects the NMEA source with an 'o' which indicates a PPS source.
EOF

User avatar
aquarat
Posts: 73
Joined: Thu Jul 26, 2012 2:32 pm
Location: Cape Town, South Africa

Re: NTP PPS

Fri Sep 07, 2012 6:09 pm

And how about this :

Code: Select all

     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
oGPS_NMEA(0)     .GPS.            0 l    6    8  377    0.000    0.002   0.002
yay :D
EOF

User avatar
aquarat
Posts: 73
Joined: Thu Jul 26, 2012 2:32 pm
Location: Cape Town, South Africa

Re: NTP PPS

Fri Sep 07, 2012 9:52 pm

The Raspberry Pi NMEA/PPS combination is proving to be more reliable than my x86/GPS-OCXO combination :
Image
This graph is from The NTP Pool Project. I grabbed it at around 23:50 7th September 2012 GMT+2. I switched my NTP routing over to the Raspberry Pi at just after "18" on the graph on the right side. The result is far less jitter.
EOF

User avatar
aquarat
Posts: 73
Joined: Thu Jul 26, 2012 2:32 pm
Location: Cape Town, South Africa

Re: NTP PPS

Sat Sep 08, 2012 3:37 pm

And a further update :
Image
You can clearly see a very large improvement between the x86/GPS-OXCO combination and the Pi/GPS-PPS solution.

The x86 system read the PPS using the DCD line on the RS232 port.
EOF

User avatar
peterwillcn
Posts: 22
Joined: Sun Sep 09, 2012 10:21 am
Contact: Website

Re: NTP PPS

Mon Sep 10, 2012 5:15 am

aquarat wrote:Pic : (hosted on a pi)
Image
hey
the gps module type ?
Last edited by peterwillcn on Fri Jan 03, 2014 3:11 am, edited 1 time in total.

User avatar
aquarat
Posts: 73
Joined: Thu Jul 26, 2012 2:32 pm
Location: Cape Town, South Africa

Re: NTP PPS

Mon Sep 10, 2012 7:34 am

peterwillcn wrote:
aquarat wrote:Pic : (hosted on a pi)
Image
hey
the gps module type ? plesae hardware wiring diagram, write a wizard, I also want to build a list in accordance with the practice as well as hardware.
I don't really understand what you're saying peterwillcn ? But I'll probably make a new thread with a guide on how I did it.
EOF

User avatar
peterwillcn
Posts: 22
Joined: Sun Sep 09, 2012 10:21 am
Contact: Website

Re: NTP PPS

Mon Sep 10, 2012 7:55 am

hey aquarat
Thank you very much.
Last edited by peterwillcn on Fri Jan 03, 2014 3:12 am, edited 2 times in total.

User avatar
aquarat
Posts: 73
Joined: Thu Jul 26, 2012 2:32 pm
Location: Cape Town, South Africa

Re: NTP PPS

Mon Sep 10, 2012 8:15 am

Some hiccups, I don't know how to "elegantly" persistently link (ln) /dev/ttyAMA0 [target] to /dev/gps0 and ln /dev/pps0 to /dev/gpspps0.

At the moment I'm doing it with a cron job.
EOF

User avatar
peterwillcn
Posts: 22
Joined: Sun Sep 09, 2012 10:21 am
Contact: Website

Re: NTP PPS

Mon Sep 10, 2012 8:31 am

aquarat wrote:Some hiccups, I don't know how to "elegantly" persistently link (ln) /dev/ttyAMA0 [target] to /dev/gps0 and ln /dev/pps0 to /dev/gpspps0.

At the moment I'm doing it with a cron job.
I hope the following reference can do for help you.

# /etc/udev/rules.d/09.oncore.rules
KERNEL==”ttyUSB[0-4]“, ATTRS{idVendor}==”067b”, ATTRS{idProduct}==”2303″, OWNER=”root”, GROUP=”dialout”, SYMLINK+=”oncore.serial.0″, MODE=”0666″
KERNEL==”pps0″, ATTR{name}==”pps_parport”, OWNER=”root”, GROUP=”root”, SYMLINK+=”oncore.pps.0″, MODE=”0660″

Fixme: But here udev often does not work (the plug the ttyUSB not appear oncore.serial.0) I sometimes direct ln-s then chmod solved.
Last edited by peterwillcn on Fri Jan 03, 2014 3:13 am, edited 2 times in total.

Paul Kennedy
Posts: 38
Joined: Tue Aug 07, 2012 12:12 am

Re: NTP PPS

Mon Sep 10, 2012 3:23 pm

Hi Aquarat,
Just got back from my work travels. I had another crack with this small dongle GPS (I received the manual form usglobalsat) and I managed to change bauds, remove superfluous sentences etc. So far the results are a significant improvement over my previous posts, but they are still at the millisecond level, whereas you have blown me away with your pps. very inspiring.

I am still awaiting a better quality GPS from the folks at Sure. My dongle does not appear to support pps.

Interesting the built-in NMEA is so good. I have had lots of comms with Dave Hart (the author of the NMEA driver under windows) and he steered me well away from it as runs in user-land, not kernel land. Therefore my burnign question is have you attempted to use this with regular raspian, or are you still using the custom kernel?

Looking fwd to getting my PPS/GPS.

http://secondthoughts.no-ip.org/index.php

Your plots look great. Well done.

btw, this is how I ensure the symbolic link form my USB to a serial device. I edited my /etc/init.d/ntp file with the following...

Code: Select all

#!/bin/sh

### BEGIN INIT INFO
# Provides:        ntp
# Required-Start:  $network $remote_fs $syslog
# Required-Stop:   $network $remote_fs $syslog
# Default-Start:   2 3 4 5
# Default-Stop:
# Short-Description: Start NTP daemon
### END INIT INFO

################################
#make the symbolic link before NTP starts so we can access the USB dongle GPS
if [ ! -e /dev/ttyUSB0 ]; then
    ln -s /dev/ttyUSB0 /dev/gps1
fi
# end of hack from pkpk
#################################

User avatar
aquarat
Posts: 73
Joined: Thu Jul 26, 2012 2:32 pm
Location: Cape Town, South Africa

Re: NTP PPS

Mon Sep 10, 2012 3:37 pm

Hey Paul

I'm currently using the custom kernel on the Raspbian distribution. I just connected an external GPS antenna to my Adafruit GPS receiver, so that might further improve the jitter (although I don't think ntpd can go below 0.002?) .

If it makes a difference I run ntpd as root.

The first time I tried running an ntpd server system I tried using a USB GPS Dongle. It tended to have very high jitter, your system seems to be fairing much better than that, well done :) .

Would you, by any chance, be willing to give me the code for your web interface? The graphs ? I promise I won't give it to anyone else if you wish and obviously I wouldn't remove your name from it. I'd love to have some stats on my server but I don't really have the motivation to go and work out how to do it :P (or rather it isn't a high enough priority at the moment).

On another note, this is my draft guide to re-creating this, so if peterwillcn would like to let me know if this works... that'd be great :

This is a short guide detailing how I got my Pi to act as a stratum 1 NTP server using an Adafruit GPS with PPS output. This same guide should work with almost any other TTL GPS with PPS output.

Firstly, buy a GPS with a TTL UART for NMEA and a PPS output on 3.3V : http://adafruit.com/products/746 .
You might also want to buy a u.FL adaptor and GPS antenna.

Prepare a new Raspberry Pi with a Raspbian SD card installation.
Boot the Pi and prepare it to your liking (set up networking, ssh, etc.)
Download the following :
modules.tar.gz
and
kernel.tar.gz
The above tar.gz files were provided by chrisrpt. They contain custom compiled modules and a kernel image which support PPS on one of the Pi's GPIO pins (GPIO23).

In a suitable directory, extract the contents of the kernel.tar.gz file and move the results into place :

Code: Select all

tar -xvf kernel.tar.gz
mv /boot/kernel.img /boot/kernel.img.old
mv Image /boot/kernel.img
Once again, extract the contents of the modules.tar.gz file :

Code: Select all

tar -xvf modules.tar.gz
mv lib /
Now you just need NTPd ;) .

Get the latest production source code of ntp : http://www.ntp.org/downloads.html . At the time of this post's writing it was ntp-4.2.6p5 .

Extract this file : tar -xvf ntp-4.2.6p5.tar.gz
Change into the new directory : cd ntp-4.2.6p5
Configure : ./configure --enable-ATOM --enable-NMEA
Eventually : make
and finally : make install

You may be missing dependencies, if you are configure will tell you.

Edit the init.d script for ntp : nano /etc/init.d/ntp
and add hashes/lines so that you have the following lines :

Code: Select all

#if [ -e /var/lib/ntp/ntp.conf.dhcp ]; then
#       NTPD_OPTS="$NTPD_OPTS -c /var/lib/ntp/ntp.conf.dhcp"
#fi

NTPD_OPTS="$NTPD_OPTS -g"
This prevents NTP from listening to your DHCP server, if you have one.
Change the "RUNASUSER" variable to "root".

Press Ctrl + X and press Y to exit and save.

Now remove any references to ttyAMA0 from your inittab :
nano /etc/inittab
Comment the following out so that it looks like this :

Code: Select all

#Spawn a getty on Raspberry Pi serial line
#T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
Once again, Ctrl + X and then press Y to save.

nano /boot/cmdline.txt
Remove any arguments that reference "ttyAMA0" so that the conent of the file looks like this :

Code: Select all

dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
Edit /etc/ntp.conf and add the configuration for your GPS as well as (optionally) another time source as a backup.
nano /etc/ntp.conf
Example ntp.conf file :

Code: Select all

# /etc/ntp.conf, configuration for ntpd; see ntp.conf(5) for help
driftfile /var/lib/ntp/ntp.drift
statsdir /var/log/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

server 127.127.20.0 mode 24 minpoll 3 iburst true prefer #use ZDA only!
fudge 127.127.20.0 flag1 1 time2 0.350

server 0.pool.ntp.org
server 1.pool.ntp.org

restrict -4 default kod notrap nomodify nopeer noquery
restrict -6 default kod notrap nomodify nopeer noquery

restrict 127.0.0.1
restrict ::1
Mode 24 restricts ntp to using $GPZDA NMEA outputs only. Mode 24 also specifies the baud rate of the GPS at 9600bps, which is also the default of the Adafruit GPSs.

Finally, connect the following cables :

Code: Select all

GPS      PI
------------------------------
GND      GND (Pin 6          )
VIN      +5V (Pin 2          )
TX       RX  (Pin 10, GPIO 15)
RX       TX  (Pin 8 , GPIO 14)
PPS      PPS (Pin 16, GPIO 23)
Edit /etc/modules and add "pps-gpio" to the end of the file :
echo "pps-gpio" >> /etc/modules

Create a new file in /etc/udev/rules.d/09.pps.rules.
Populate this file with the following :

Code: Select all

KERNEL=="ttyAMA0", SYMLINK+="gps0"
KERNEL=="pps0", OWNER="root", GROUP="tty", MODE="0777", SYMLINK+="gpspps0"
Restart the Pi.
EOF

bytecounter
Posts: 1
Joined: Tue Aug 28, 2012 7:46 pm

Re: NTP PPS

Mon Sep 10, 2012 8:58 pm

aquarat, I can verify that what you posted works -- we are on the same track except for some minor differences. :mrgreen:

I was using Adafruit's modified Raspbian distribution to do this. I forked their kernel modifications and hacked on the gpio pps modifications which worked easily.. I will get around to making a neat tarball of the modules and kernel.img soon.

And just a quick note for anybody stuck with a v2: 1PPS output was there. I just soldered a small patch wire from the exposed pad after reading the datasheet (taking care to tape it down with something like polyimide tape).

User avatar
aquarat
Posts: 73
Joined: Thu Jul 26, 2012 2:32 pm
Location: Cape Town, South Africa

Re: NTP PPS

Mon Sep 10, 2012 10:43 pm

Thanks bytecounter :)

I'm busy downloading the various tools/source to compile the kernel myself... but my objective is mdadm support :P .
EOF

Paul Kennedy
Posts: 38
Joined: Tue Aug 07, 2012 12:12 am

Re: NTP PPS

Tue Sep 11, 2012 2:42 pm

aquarat,
I am busy tidying up some of my experimental code, and will provide it to yourself when I am happy with it. It has been running a couple of weeks without failure, but I have quite a few log files in place for monitoring purposes.
You will need a web server (I use nginx) php (I use php-fpm).

regards
pk

User avatar
peterwillcn
Posts: 22
Joined: Sun Sep 09, 2012 10:21 am
Contact: Website

Re: NTP PPS

Tue Sep 11, 2012 2:43 pm

Thank you very much aquarat
Last edited by peterwillcn on Fri Jan 03, 2014 3:23 am, edited 2 times in total.

User avatar
aquarat
Posts: 73
Joined: Thu Jul 26, 2012 2:32 pm
Location: Cape Town, South Africa

Re: NTP PPS

Tue Sep 11, 2012 4:10 pm

Thanks Paul, there's no rush :) .

@ peterwillcn : I have a Motorola Oncore UT+, but as yet I haven't been able to get this working with ntpd. I haven't tried very hard. The GPS I'm using uses NMEA over ttyAMA0 whereas the Motorola GPSs use the Motorola Binary protocol... NTPd does support this but I have no idea how you'd try and configure it.

I don't remove the old ntpd before installing the new one. While this is probably very bad in principal, in practise the two packages are extremely similar and so apt-get remove ntp removes the result of "make install" quite nicely. In addition, leaving the old ntpd in place and just overwriting it retains all the default configuration and init.d scripts.
EOF

User avatar
peterwillcn
Posts: 22
Joined: Sun Sep 09, 2012 10:21 am
Contact: Website

Re: NTP PPS

Sun Sep 16, 2012 1:53 am

:P wow...

Code: Select all

root@raspberrypi:/var/log/ntpstats# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
oGPS                       .GPS.            0 l   15   16  376    0.000   -0.435   0.041
+202.131.74.126  133.100.11.8     3 u    5   64  377   90.431  -12.514  20.793
+ns2.telecom.lt  212.59.3.3       2 u    8   64  377  406.134    0.379  19.598
root@raspberrypi:/var/log/ntpstats# ntpdc -c peers
     remote           local      st poll reach  delay   offset    disp
=======================================================================
=ns2.telecom.lt  192.168.1.9      2   64  377 0.39742  0.003573 0.04735
=202.131.74.126  192.168.1.9      3   64  377 0.08026 -0.006893 0.06621
*GPS                      127.0.0.1        0   16  377 0.00000 -0.000053 0.01524
Last edited by peterwillcn on Fri Jan 03, 2014 3:05 am, edited 2 times in total.

User avatar
peterwillcn
Posts: 22
Joined: Sun Sep 09, 2012 10:21 am
Contact: Website

Re: NTP PPS

Sun Sep 16, 2012 3:17 pm

i find ntp driver issues
3.1.9-pps+ kernel is not support HARDPPS Mode
ntpd source

Code: Select all

/* If HARDPPS is on, we tell kernel */

	if (instance->hardpps) {
		int	i;

		oncore_log(instance, LOG_INFO, "HARDPPS Set.");

		if (instance->assert)
			i = PPS_CAPTUREASSERT;
		else
			i = PPS_CAPTURECLEAR;

		/* we know that 'i' is legal from above */

		if (time_pps_kcbind(instance->pps_h, PPS_KC_HARDPPS, i,
		    PPS_TSFMT_TSPEC) < 0) {
			oncore_log(instance, LOG_ERR, "time_pps_kcbind failed: %m");
			oncore_log(instance, LOG_ERR, "HARDPPS failed, abort...");
			return (0);
		}
		pps_enable = 1;
	}
	return(1);
}
http://linuxpps.org/wiki/index.php/Linu ... stallation
Last edited by peterwillcn on Fri Jan 03, 2014 3:24 am, edited 2 times in total.

Paul Kennedy
Posts: 38
Joined: Tue Aug 07, 2012 12:12 am

Re: NTP PPS

Mon Sep 17, 2012 12:03 am

Hi Peter,
your last post was rather confusing. I am not sure what you were attempting to state. My sure gps arrived on Saturday morning. The USB connectivity worked out of the box. I then wired up the serial RS232 and it also worked without trouble. I have contacted the manufacturers to see if I can enable the ZDA sentence, disable all other sentences, and increase the baud rate beyond 9600. I prefer to have a clean serial signal which contains exactly what I need rather than a hit and miss approach. The unit currently outputs several sentences, none of which provide the date.

I will then focus on the PPS. I need to sort out the correct wiring, and install the patched kernel. I intend to repeat the process of rebuilding the kernel so I fully understand the process Chris performed so well....

Paul Kennedy
Posts: 38
Joined: Tue Aug 07, 2012 12:12 am

Re: NTP PPS

Mon Sep 17, 2012 3:02 pm

Had a bit of a win today. I have been waiting for my gps from sure for almost a month. One turned up on Saturday - at last. Guess what, another one turned up Monday. I guess it must have self replicated while on the long boat from China. I will ask them if they would like me to send it back. I have both working just fine in both serial and USB mode. Just prepping my macbook to compile raspi kernel from scratch...

User avatar
peterwillcn
Posts: 22
Joined: Sun Sep 09, 2012 10:21 am
Contact: Website

Re: NTP PPS

Tue Sep 18, 2012 1:21 am

hi Paul Kennedy, your gps device models?
Last edited by peterwillcn on Fri Jan 03, 2014 3:17 am, edited 2 times in total.

Paul Kennedy
Posts: 38
Joined: Tue Aug 07, 2012 12:12 am

Re: NTP PPS

Tue Sep 18, 2012 2:33 am

Hi,
my apologies. I am using the GPS from SureElectronics.
http://www.sureelectronics.net/goods.php?id=99

It is pretty easy to get up and running, but I am starting to find some limitations, specifically with the control of NMEA sentences. It looks like I cannot configure the sentences. All I need is ZDA, but I presently receive everything but ZDA.

Return to “Other projects”