nmea refclock not locking to the pps

Tony Hain tony at tndh.net
Sat Mar 4 01:20:43 UTC 2017


Gary E. Miller wrote:
> Yo Tony!
> 
> On Fri, 3 Mar 2017 01:00:23 -0800
> "Tony Hain" <tony at tndh.net> wrote:
> 
> > Not clear if this is an ntpsec issue, or comes from upstream, but the
> > pps lock on the nmea stream never converges to a reasonable offset or
> > apparently itself.
> 
> Fiar warning: I always recommend people not to use that refclok.

Well I tried gpsd with no luck, so I switched back, and the nmea driver was working up through 4.2.4p5, (which I was using because I couldn't get gpsd to work with ntpd back then either). In both cases I can get gpsd to show it is getting the correct feed from the gps, I just can't make it play well with ntpd. 

I don't know if the offset shown in 4.2.8p9 is due to changes in that driver, or something in the BBB dmtpps driver implementation. I will be taking that up on the FreeBSD arm list, but I was less concerned about that than the fact that the ntp-sec nmea driver appears to behave very differently from 4.2.8p9 nmea driver on the same hardware. I assumed that driver would have come down without changes other than device identifier, but clearly something is different.

> 
> > # ntpd --version
> > ntpd - NTP daemon program - Ver. 4.2.4p5
> 

That was the local reference clock on a i386 system. The version on the BBB is 4.2.8p9 which was at the very end of the list.

> > # ntpd -V
> > ntpd ntpsec-0.9.6+536 2017-02-22T20:26:50Z
> 
> That should be a good verion.
> 
> > oPPS(0)          .PPS.            0 l    7    8  377   0.0000   0.0001
> > 0.0001
> > xNMEA(0)         .GPS.            0 l    6    8  377   0.0000 -52.1062
> > 1.4493
> > *2001:470:e930:7 .GPS.            1 u   58   64  377   0.8173  -0.9772
> > 1.9614
> 
> Clearly the PPS got outvoted.

The behavior in that configuration is what I expected because the nmea start time jitter is high. It is the configurations where the pps flag is turned on for the nmea interface that are not working as expected.	

> 
> You neglected the most important par of a bug report: your ntp.conf.

Well it appears from the copy I got back that the message format was garbled. I only included the 2 relevant lines for the pps & nmea refclocks, for each configuration with the cooresponding ntpmon results. Most of the file is comments, but here it is:

# Stripped down ntp.conf with refclock changes for ntpsec parser
#

# PPS Device
#     This driver is enabled only when a prefer peer other than this
#     driver is among the survivors
#
# Beaglebone FreeBSD
# loader.conf needs:
#   am335x_dmtpps_load="YES"
#   hw.am335x_dmtpps.input="P8-7"
#
# devfs.conf
# link dmtpps /dev/pps0
#
# flag 2 specifies PPS signal 'on-time' edge 0=assert 1=clear
#    am335x_dmtpps & linux drivers only recognize assert edge
# Time1 -- measured pps pulse shape/level box in to RS232 DCD low out 1760ns
# Time1 -- measured pps pulse shape/level box in to 555 DCD out high 200ns
# 15' cable on MR350p module                                                    
#        1.76us +  4.5720m cable (@ 5ns/m =  22.860ns) = 0.000001782860
#        0.20us +  4.5720m cable (@ 5ns/m =  22.860ns) = 0.000000222860
# 90' cable on MR350p module
#        1.76us + 27.4320m cable (@ 5ns/m = 137.160ns) = 0.000001897160
#        0.20us + 27.4320m cable (@ 5ns/m = 137.160ns) = 0.000000337160
# 96' cable on MR350p module
#        1.76us + 29.2608m cable (@ 5ns/m = 146.304ns) = 0.000001906304
#        0.20us + 29.2608m cable (@ 5ns/m = 146.304ns) = 0.000000346304
#
# NTPsec parser
#refclock pps stratum 0 refid PPS minpoll 4 maxpoll 4 prefer time1 0.000000337160
#
# trying different values to see how it shifts
refclock pps stratum 0 refid PPS minpoll 3 maxpoll 6 prefer time1 0.000000337160

# NMEA GPS Device
# Local GPS NMEA -- ZDA + GGA + GSA @ 4800 bps
# ZDA mode 8
#
# Beaglebone FreeBSD
#   may need to enable serial dev in FDT DTB
#      dtc -I dtb -O dts /boot/dtb/beaglebone-black.dtb -o \
#             /root/beaglebone-black.dts
#      edit /root/beaglebone-black.dts
#         serial at 481aa000 {
#            ...
#            status = "okay";
#         };
#      dtc -I dts -O dtb /root/beaglebone-black.dts -o \
#             /boot/dtb/beaglebone-black.dtb.serial5
#      save dist dtb, replace w/...dtb.serial5
#
# Set serial port speed
#      stty -f /dev/ttyu1.init 4800
#
# Flag1 -- enable PPS coorelation (1)
# Flag2 -- measure trailing edge of DCD (1) (set for RS232 dcd since level converter is inverted)
# Flag3 -- use kernel discipline (1)
# Time1 -- Output of shaper 232 -> (1.76us after PPS) 544ms low  456ms high
# Time1 -- Output of shaper 555 -> (0.20us after PPS) 544ms high  456ms low
# Time2 -- end of ZDA incl chksum/crlf:   35 char @4800bps(480cps) 0.072916667
# Time2 -- end of GGA incl chksum/crlf:  +81 char @4800bps(480cps) 0.241666667
# Time2 -- end of GSA incl chksum/crlf: +(38-62)~50 char @4800bps(480cps) 0.345833333
#
# ZDA
# from Global-Sat SIRF manual
# ZDA Outputs the time associated with the current 1 PPS pulse. Each message
# is output within a few hundred ms after the 1 PPS pulse is output and tells
#           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# the time of the pulse that just occurred. (appears to avg. ~370ms delay to first char at this location)
#
# NTPsec parser
#refclock nmea refid GPS baud 4800 mode 8 minpoll 3 maxpoll 4 prefer flag1 1 flag4 1 time1 0.000000337160 time2 0.072916667
# 
# trying different values to see if it will converge
#refclock nmea refid GPS baud 4800 mode 8 minpoll 3 maxpoll 6 prefer flag1 0 flag4 1 time2 0.442916667
refclock nmea refid GPS baud 4800 mode 8 minpoll 3 maxpoll 6 prefer flag1 1 flag4 1 time1 0.000000337160 time2 0.072916667

# NTPsec parser for shared memory function in GPSd
# --- makes no obvious difference from direct device readings, and offers less control
#refclock shm unit 0 refid PPS
#refclock shm unit 1 refid GPS

# GPSd-ng  socket based (not SHM avove)  - turn off device 20 & 22 to use this
# GPSd active between serial port and NTP
#    unit numbers are mod-128 with low (primary time data) / high (secondary PPS-only) pairs
# FLag1 -- Secondary unit is potential PPS peer when PPS is active
# Flag2 -- Primary unit disable PPS for testing
# Flag3 -- Primary unit disable log throttle so all errors are logged.
# Flag4 -- Primary unit record timestamp each second (1) for diviation plots
# Time1 -- PPS event to output of pulse shaper -> 1.76us + cable (544ms low  456ms high)
# Time2 -- (primary unit) end of GGA incl. chksum/crlf : 81 char @4800bps(480 char/sec) 0.242
#
# NTPsec parser
# --- never could make this work due to JSON errors
# refclock gpsd mode 2

# Network time servers
#
# Local NTP pool
#
# BBG clone of this system locked to ntp2 & pps
server 2603:3023:102:1e00:8a4a:eaff:fef5:a20e minpoll 3 maxpoll 5
#
#server 2001:470:e930:2240:7ef8:9baf:4b03:1abc
#server ntp1.tndh.net  minpoll 4
server ntp2.tndh.net  minpoll 4 prefer
#server ntp3.tndh.net  minpoll 4
#server isle-of-pines.tndh.net minpoll 4
# use local router for startup burst
#server midway.tndh.net iburst

#
# The following three servers will give you a random set of three
# NTP servers geographically close to you.
# See http://www.pool.ntp.org/ for details. Note, the pool encourages
# users with a static IP and good upstream NTP servers to add a server
# to the pool. See http://www.pool.ntp.org/join.html if you are interested.
#
# The option `iburst' is used for faster initial synchronisation.
# The option `maxpoll 9' is used to prevent PLL/FLL flipping on FreeBSD.
#
server 0.freebsd.pool.ntp.org iburst maxpoll 8
#server 1.freebsd.pool.ntp.org iburst maxpoll 8
#server 2.freebsd.pool.ntp.org iburst maxpoll 8
#server 3.freebsd.pool.ntp.org iburst maxpoll 8
#server 2.us.pool.ntp.org maxpoll 8

#Calibration reference clocks
#
# Reference ACTS
server time.nist.gov minpoll 8
#
# Reference USNO  
#  --- serious path asymmetry makes these less than useful
#server tick.usno.navy.mil minpoll 8
#server tock.usno.navy.mil minpoll 8
#
# Reference CDMA
# ESnet
#server 198.124.252.90
#server 2001:400:6000:2::2
#server 198.129.252.38
#server 2001:400:15:1::2
# Hurricane Electric IPv6
#server 216.218.192.202
server 2001:470:0:50::2 minpoll 6
#
# Reference GPS
#server 149.20.64.28 minpoll 6
server clock.isc.org minpoll 6
server bigben.cac.washington.edu minpoll 6
#
# Reference IPv6 
# SIXXS IPv6 servers
# Chicago
#server 2001:4978:1:400:202:b3ff:feb4:59cb
# Dallas
#server 2001:4de0:1000:a3::2
#
# Vendor time servers
server time0.apple.com minpoll 5
#server time.windows.com minpoll 5

# Set up the drift file to compensate local errors
#   moved to /var/log/ntp ramdisk mount to minimize SD card writes
driftfile /var/log/ntp/ntp.drift

# Set up the leap seconds file from nist
#   moved to /var/log/ntp to minimize SD card writes : replaced /etc  w/ln -s
leapfile /var/log/ntp/leap-seconds.list

# Set up a log file
logfile /var/log/ntp/ntp.log

# Stats directory
statsdir /var/log/ntp/stats

filegen peerstats file peerstats type day enable
filegen loopstats file loopstats type day enable
filegen clockstats file clockstats type day enable

statistics clockstats peerstats loopstats

#
# Security: Only accept NTP traffic from the following hosts.
# The following configuration example only accepts traffic from the
# above defined servers.
#
# Please note that this example doesn't work for the servers in
# the pool.ntp.org domain since they return multiple A records.
# (This is the reason that by default they are commented out)
#
#restrict default ignore
#restrict 0.pool.ntp.org nomodify nopeer noquery notrap
#restrict 1.pool.ntp.org nomodify nopeer noquery notrap
#restrict 2.pool.ntp.org nomodify nopeer noquery notrap
#restrict 127.0.0.1
#restrict -6 ::1
#restrict 127.127.1.0

# Jan. 2014 - ddos reflection attack protection
restrict 127.0.0.1
restrict -6 ::1
restrict 127.127.0.0 mask 255.255.0.0
restrict 172.16.0.0 mask 255.240.0.0
restrict -6 2001:470:e930:: mask ffff:ffff:ffff:ffff::
restrict default kod limited nomodify notrap nopeer
restrict -6 default kod limited nomodify notrap nopeer

> 
> I'm guessing you do not have prefer set on your PPS?  You'll also want to set
> the mib- and max-poll on the PPS to much less than the for the nmea driver.

Prefer is set on the pps & nmea, as well as the reference i386 system which is what it keep locking to. I had turned the poll time up to see if that would help smooth out the jumps due to satellite visibility. I have since turned off GSA to reduce the overall transmission length variability in case the start time jitter was due to processing to build the extra message, but that doesn't appear to make a difference. 

So right now the relevant lines are:
refclock pps stratum 0 refid PPS minpoll 3 maxpoll 6 prefer time1 0.000000337160
refclock nmea refid GPS baud 4800 mode 8 minpoll 3 maxpoll 6 prefer flag1 1 flag4 1 time1 0.000000337160 time2 0.072916667
server ntp2.tndh.net  minpoll 4 prefer

and at 8 hours since the last restart ntpmon shows:
     remote           refid      st t when poll reach   delay   offset   jitter
xPPS(0)          .PPS.            0 l    5   16  377   0.0000   0.6479   0.0285
oNMEA(0)         .GPS.            0 l   20   64  377   0.0000   0.6605   0.1383
+2603:3023:102:1 .PPS.            1 u    9   32  377   1.3298   0.7057   1.9306
-clock.fmt.he.ne .CDMA.           1 u   23   64  377  31.3820   2.9104   2.0771
*2001:470:e930:7 .GPS.            1 u   14   64  377   0.9124   0.7978   0.1790
-tor1.wtfismyip. 129.69.1.153     2 u    -   64  377 156.4694   1.8861   1.4848
-2610:20:6f15:15 .ACTS.           1 u  275  256  366 143.2063  45.1714   3.6223
-clock.isc.org   .SHM.            1 u   92   64  376  31.1883   3.5011   1.7152
+omega.s.uw.edu  172.22.16.38     2 u   44   64  377  15.5121   1.2483   2.9961
-time0.apple.com 17.253.26.253    2 u   17   64  377  24.9052   0.9498   2.8544
ntpd ntpsec-0.9.6+536 2017-02-22T20:26:50Z  Last update: 2017-03-03T17:19:15

where last night 4.2.8p9 with over 8 hours runtime had the offset on the nmea driver at 0.023 (which itself is an order of magnitude higher than 4.2.4p5 on the i386 including its sloppy rs232 slew rate introducing jitter). 

Is it possible that something in the interpretation of refclock nmea vs. peer 127.127.20.0 would account for the difference in handling the pps event? 

If it would be useful I can try switching back to gpsd to show what that is doing. It has been awhile so I don't recall exactly off the top of my head. 

PS:   a web page for gpsd with ntpsec {can't find it right now} says to ensure 3.17+, but the gpsd download page only offers 3.16-. That page also says that FreeBSD ports is ok, but that is only 3.14. I had planned to mention that as soon as I got ntp-sec working, but I expected that to be awhile ago and basically forgot about it until now). After git clone from savannah my build is:    gpsd: 3.17~dev (revision release-3.16-585-g26e2f525) 

PPS:   tried ntpviz this morning, and it failed due to variance in stats path assumption. I see from the command line help that command line and a config file is an option, and that is good because I will likely post-process these somewhere else because the clock system doesn't have gnuplot installed (2nd failure) and my cross-build system ran out of disk (3rd failure, done for the day). That said, I had expected that ntpviz would read the ntp.conf file for the location of the stats dir, so maybe have it try its command line option, then its config file, then ntp.conf, then the existing default, would allow for post-processing while tracking with where ntpd has been told to put the stats, if it was told something specific.

Tony



> 
> RGDS
> GARY
> ---------------------------------------------------------------------------
> Gary E. Miller Rellim 109 NW Wilmington Ave., Suite E, Bend, OR 97703
> 	gem at rellim.com  Tel:+1 541 382 8588
> 
> 	    Veritas liberabit vos. -- Quid est veritas?
>     "If you can’t measure it, you can’t improve it." - Lord Kelvin



More information about the bugs mailing list