Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Friday, May 8, 2015

Large Display for GPS Disciplined Time Server


Since building my own GPS disciplined local time server I have wanted a large display of some sort to display my super accurate clock. The primary purpose of doing this was really just because it would be rally really cool looking. I also have a personal issue with any clock that does not set itself from the WWVB or support NTP, in 2015 we shouldn't have to manually set clocks anymore. A secondary use for doing this would be for ham radio purposes. A nice large clock that is always accurate so I can easily and quickly log contacts in UTC would be very useful. Ultimately I ended up with a very nice solution and here is the result:

ESE ES-166 timecode display used for GPS clock

Searching for someone who makes such a clock was frustrating. It seems either you can have a large format clock for cheap that does not support NTP, or you can have one that does support NTP but costs hundreds of dollars. Designing and building my own was the next option that I had considered for awhile. A simple PIC based device that drives some large 7 segment led displays would be trivial to build, but I couldn't get into the project. It just didn't excite me, It's one of those things that would be so simple and mundane that I just couldn't drive myself to do it. It would be like a software engineer being assigned the task of writing a word processor. It's already been done so many times and is such an unfulfilling project you can just never get excited about it.

So on to Plan C. Let's see what's already available and either modify or make it work for my intended use. Basically I would be looking for a large LED, backlit LCD, or big VFD display of some sort that would be able to easily display time. Input can be via various means, ethernet or serial would be first choices, some other parallel type interfaces would be not ideal although I could still make it work if needed. Luckily having some experience is professional video editing when I was in college, I looked towards something I felt might me the perfect solution: Timecode displays.

Upon scrounging around I found a perfect device on eBay, an ESE-166 remote timecode display. These can be found for less than $50 at times are are beautiful pieces of gear. It is a big 2U rack mount enclosure with a nice large format LED display on the front panel. This display is designed for displaying accurate time code for video editing systems. The particular display I purchased had hour, minute, and second digits which would be perfect. Many time code displays also include a 4th digit section for frames which this one did not as I did not need it for my purpose. The inputs on these devices are typically a single 75ohm timecode serial input for SMPTE timecode. I was fine with this as designing some hardware to convert an rs232 serial stream to SMPTE timecode actually sounded pretty fun, but I ended up not needing to. This specific display also included an rs232 serial input that supports a few ASCII time formats. This would be a perfect solution, just have a script that takes my local time directly off of the time server itself and dump it out the serial port to this display. There would be some very minimal latency with this obviously, but regardless this solution would be perfect! The ASCII format I chose to use is as follows:

Format #0: (CR)(LF)I(^)(^)DDD(^)HH:MM:SS(^)DTZ=XX(CR)(LF)

As for getting the time data into the ESE, it has two runtime options set by some dip switches inside. The first is a free running clock that when the serial port receives a time string, it updates the internal clock to the time received. The second option does not free run, you simply continuously provide the time signals to update at the interval you specify. In this option, you would need to provide the time signal at least once a second to keep the display real time. For now, I went with the first option. I have the ESE free running with a cron dumping data from my NTP server sending an rs232 time string via cron every five minutes. The noticeable time drift of this clock over a five minute period is not noticeable at all and this solution keeps the clock up to date on five minute intervals without having to constantly send it serial data.

For those that are curious what is inside the ESE ES-166, it is pretty basic:


There is a whole lot of room in that chassis with not very much there. Just a mains transformer and simple analog rectified power supply with a handful of logic to decode the SMPTE / serial port data and drive the display. I'm planning on moving my Trimble GPS receiver inside of this case as there would be plenty of room for it. This would consolidate some of the hardware laying in the back of my server rack.

Additionally the manual for the ES-166 includes a schematic which is also nice to see. There was one part of the design that I really loved, the rs232 to TTL translation:


There is no serial driver there, MAX232 or equivalent. Just a simple level converter based on a 2n2222 with a diode and resistor. I love it! You see MAX232s in everything these days when they are often just not needed for serial RX conversion.

Further plans include racking this unit in my server rack and possibly getting a second unit so I can display both local time and UTC.

Friday, December 5, 2014

Stratum 1 Time Server Based on a Trimble Placer GPS 450 with PPS Output

Setting up GPS disciplined stratum-1 timeservers are not a new or technically difficult task, plenty of articles are already available including some excellent ones from David Taylor's satsignal.eu site. The basic idea behind using a GPS device as a stratum-0 reference is the ability to have a very low latency and low jitter accurate local time source. The only complicated part is finding or modifying a GPS receiver that can provide a precise 1 pulse per second source.

This post is going to focus on a simple, inexpensive, and somewhat elegant solution based on a Trimble Placer 450 GPS receiver. The Trimble 450 is by no means a modern device. It was originally produced in the 1990s and used within vehicles for fleet management purposes. It is large compared to modern units and is also only an 8 channel receiver that uses only satellites in the US GPS satellite constellation. The reasons why I really like the Trimble 450 are that is is very rugged and well designed (as it was to be used in the field). It can also run off of a wide voltage supply range and it is easily modified for a true precise 1 pulse per second (PPS) output which is the key part to having an accurate stratum-1 time server.



Trimble Placer GPS 450s are plentiful (there are available on eBay all the time for less than $15 including shipping). I had a unit myself sitting in a parts box for maybe 10 years that I picked up somewhere for free, this is why I went with this unit to begin with as my time source. I also love re-purposing old and somewhat obsolete inexpensive hardware. You will need an external active GPS antenna to use with it, any cheap ones from China will work, the one I purchased was $6. Note you will need an antenna with an MCX connector (or adapter) to interface to it. One additional nice thing about the 450 is you can easily replace the on-board MCX connector with an SMA, BNC, etc if you wish.

By default the Placer 450 outputs a Trimble ASCII Interface Protocol (TAIP) serial datastream, but this is easily changeable to NMEA-0183 strings. Going through the docs I believe gpsd is capable of decoding TAIP messages, but I didn't spend the time to try. TAIP is a binary format and while it is a brief and compact data format, I like the human readable NMEA output strings as they can provide visual output of  your GPS devices status. The Placer 450 can be switched to NMEA with the following commands:

       
>SPR:NMEA=TT<
>SRTSAVE<


Once switched to NMEA, it will provide the following standard strings: GPZDA, GPGGA, GPGLL, GPGSA, GPVTG, and GPRMC. I recommend reading the Trimble Placer 450 manual as it does have good information if you are unable to successfully communicate to the device via RS-232. There is also an old dos based configuration utility available that you can use to program it and switch its output to NMEA format. You will need a machine running win98 or older to run it though. I keep an ancient Pentium 133 machine around for programming old Motorola radios and I had no issues using it for programming the 450.

If your Placer 450 has been sitting around for years without being used, its internal GPS almanac is going to be extremely outdated. This resulted in a cold start of mine taking about an hour to finally acquire four satellites for 3D navigation and update its GPS almanac. Any subsequent warm starts after this will lock on within about 60 seconds. This would also be a good time to check the internal lithium battery. The memory in the Placer 450 is volatile and if the battery is bad every power on will result in a cold start. Checking on my receiver, the battery was fine.

PPS Output

Utilizing the PPS output of a GPS receiver is really the most important part of having a truly disciplined stratum-1 time server. Not all GPS receivers offer a true 1-PPS reference, fortunately the Placer 450 does, it just isn't where it needs to be. While the NMEA strings that come off of the GPS receiver contain accurate time data, various delays through the serial communication result in a time reference that has significant latency and jitter. This usually ends up being no better time keeping than just pointing your time server to another stratum-1 server. That said, the GPS time is still useful for events where internet connectivity is lost or unreliable.

The PPS output provides an extremely accurate time pulse that occurs once per second. Ntpd ( or your time server software of choice) can use this pulse to keep extremely accurate time. I will only be discussing the integration of ntpd in this post. The Placer 450 does indeed have a PPS output, unfortunately this output is on a separate DB-9 data connector. Probing its output on a scope, this pulse is clearly visible and has a very fast falling edge when it occurs (1.1 microseconds on average).



Now that we know we have an accurate PPS pulse, we need to get it into the computer running ntpd as quickly and with as little latency as we can afford. The solution to this is to send the pulse across the serial port on an unused pin (data carrier detect is standard to use in this case) which will drive an interrupt on the ntpd machine. In regards to the Placer 450, I decided to take this negative edge pulse, feed it into a max232 serial driver and send it down the unused DCD pin on the serial port. This worked perfect as the max232 inverts the data and results with a positive ~+15V RS-232 compliant pulse. The final setup of this is shown here:


The small blue board I added contains the max3232c serial driver and necessary charge pump capacitors. I pulled +5 volts off of a positive rail on the Placer 450 along with ground. Since the DCD pin on the RS-232 connector was unused, this modification was very simple. I also removed the original 3 pin power connector and hardwired it to +12v as there is no reason to worry about sourcing an original power cable. Since these devices are usually pulled from service, the original wiring harnesses usually never stay with the unit. Here is the resulting outgoing pulse through the max3232c:


Now that we have the pulse going to the NTP server via the DCD pin over RS-232, we need to verify its operation. Any modern Linux distribution will have PPS support built into the kernel, the serial module for PPS will just have to be loaded. To verify the arriving pulses, you can use pps-tools which is available for most distributions. The following output from ppstest shows my arriving 1 PPS pulse indicating my hardware modification is working.

       
[root@time01 ~]# ppstest /dev/pps0
trying PPS source "/dev/pps0"
found PPS source "/dev/pps0"
ok, found 1 source(s), now start fetching data...
source 0 - assert 1417642033.999999820, sequence: 226503 - clear  1417642033.000028598, sequence: 173333
source 0 - assert 1417642035.000000722, sequence: 226504 - clear  1417642034.000021949, sequence: 173334
source 0 - assert 1417642035.999999642, sequence: 226505 - clear  1417642035.000022821, sequence: 173335
source 0 - assert 1417642036.999999339, sequence: 226506 - clear  1417642036.000023328, sequence: 173336


One note regarding serial to USB adapters. I was using one initially and was not seeing the pulse arriving on my machine. Once I switched to the onboard serial port (/dev/ttyS0) my pulses were immediately visible. If you are going to use a USB adapter, make sure that it supports the DCD pin as mine did not.

A few more prerequisites are needed including having gpsd installed along with ntp. The ntpd configuration is really the last critical step, in the case of my Placer 450, the following configuration is used:

       
# GPS reference
server 127.127.28.0 prefer
fudge 127.127.28.0 refid GPS

# PPS reference
server 127.127.22.0 minpoll 4 maxpoll 4
fudge 127.127.22.0  flag3 1  refid PPS


How this configuration works and what it should be set to could be an entire separate discussion, luckily it is documented very well. Basically the ip addresses shown above are driver interfaces to the gps NMEA serial interface and the kernel PPS. Once ntpd is restarted, checking ntp's status you will see the following:

       
[root@time01 ~]# ntpq -p

     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
-time3.chpc.utah 198.60.22.240    2 u    2   64  377   71.766   14.708   0.200
-time.tritn.com  66.220.9.122     2 u   39   64  377   71.081    2.188   3.051
+segfault.boom.n 216.218.254.202  2 u   25   64  377   45.549   -4.891   0.548
+50.7.72.4       128.138.141.172  2 u   31   64  377   58.978   -4.452   0.654
*SHM(0)          .GPS.            0 l    8   64  377    0.000  -71.444   4.780
oPPS(0)          .PPS.            0 l   12   16  377    0.000   -0.001   0.001


A few things to note in the above output:

1. Both the GPS and PPS sources now show up in the ntp output.
2. The tally flag for the GPS source is '*' indicating it is a system peer.
3. The tally flag for the PPS source is 'o' indicating the system sync is derived from a PPS signal.
4. Jitter on the PPS source is significantly lower than the other network based sources.
5. The jitter and offset for the GPS source are higher than other sources, this is expected as the serial communication latency between the Placer 450s NMEA strings and server is not guaranteed.

The next steps are to monitor and log the time servers accuracy and precision over time to see how much drift there is with the GPS source and without. After some basic testing it seems to be much improved but only time will tell.

Friday, January 11, 2008

Broadcast ping

A really cool feature of the 'ping' implementation under most UNIX and Linux distributions is the ability to ping your subnets broadcast address.

[root@proxy /]# ping -b 10.70.0.255
WARNING: pinging broadcast address
PING 10.70.0.255 (10.70.0.255) 56(84) bytes of data.
64 bytes from 10.70.0.3: icmp_seq=0 ttl=64 time=0.058 ms
64 bytes from 10.70.0.10: icmp_seq=0 ttl=255 time=0.198 ms (DUP!)
64 bytes from 10.70.0.12: icmp_seq=0 ttl=64 time=0.205 ms (DUP!)
64 bytes from 10.70.0.48: icmp_seq=0 ttl=255 time=0.248 ms (DUP!)
64 bytes from 10.70.0.19: icmp_seq=0 ttl=255 time=0.254 ms (DUP!)
64 bytes from 10.70.0.16: icmp_seq=0 ttl=255 time=0.258 ms (DUP!)
64 bytes from 10.70.0.30: icmp_seq=0 ttl=255 time=0.262 ms (DUP!)
64 bytes from 10.70.0.46: icmp_seq=0 ttl=255 time=0.287 ms (DUP!)
64 bytes from 10.70.0.43: icmp_seq=0 ttl=255 time=0.292 ms (DUP!)
64 bytes from 10.70.0.35: icmp_seq=0 ttl=255 time=0.297 ms (DUP!)
64 bytes from 10.70.0.44: icmp_seq=0 ttl=255 time=0.302 ms (DUP!)
64 bytes from 10.70.0.57: icmp_seq=0 ttl=255 time=0.310 ms (DUP!)
64 bytes from 10.70.0.64: icmp_seq=0 ttl=255 time=0.336 ms (DUP!)
64 bytes from 10.70.0.253: icmp_seq=0 ttl=64 time=0.341 ms (DUP!)
64 bytes from 10.70.0.45: icmp_seq=0 ttl=255 time=0.346 ms (DUP!)
64 bytes from 10.70.0.222: icmp_seq=0 ttl=255 time=0.662 ms (DUP!)
64 bytes from 10.70.0.22: icmp_seq=0 ttl=64 time=0.669 ms (DUP!)
64 bytes from 10.70.0.229: icmp_seq=0 ttl=64 time=0.674 ms (DUP!)
64 bytes from 10.70.0.210: icmp_seq=0 ttl=64 time=0.678 ms (DUP!)
64 bytes from 10.70.0.216: icmp_seq=0 ttl=64 time=0.698 ms (DUP!)
64 bytes from 10.70.0.209: icmp_seq=0 ttl=255 time=1.42 ms (DUP!)
64 bytes from 10.70.0.40: icmp_seq=0 ttl=255 time=1.43 ms (DUP!)
64 bytes from 10.70.0.217: icmp_seq=0 ttl=60 time=1.43 ms (DUP!)
64 bytes from 10.70.0.246: icmp_seq=0 ttl=255 time=2.82 ms (DUP!)
64 bytes from 10.70.0.223: icmp_seq=0 ttl=60 time=2.85 ms (DUP!)
64 bytes from 10.70.0.252: icmp_seq=0 ttl=255 time=2.85 ms (DUP!)
64 bytes from 10.70.0.244: icmp_seq=0 ttl=60 time=4.13 ms (DUP!)
64 bytes from 10.70.0.248: icmp_seq=0 ttl=255 time=5.25 ms (DUP!)
64 bytes from 10.70.0.240: icmp_seq=0 ttl=255 time=15.4 ms (DUP!)

--- 10.70.0.255 ping statistics ---
1 packets transmitted, 1 received, +28 duplicates, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.058/1.554/15.486/2.926 ms, pipe 2

A couple interesting things about this. First, the only responding hosts are hosts that are set to reply to ICMP broadcast pings. On this network this includes my UNIX and Linux hosts routers and switches, along with a couple other random hosts such as firewalls and a few network based cameras. Now it would be nice to see all of the windows hosts as well, but as part of the windows TCP/IP stack they are set to not reply to ICMP broadcast pings. This seems unfortunate, as if Microsoft did not implement their TCP/IP stack according to RFC guidelines. But upon further research, in RFC-1122 (Requirements for Internet Hosts) This behavior is allowed:

"An ICMP Echo Request destined to an IP broadcast or
IP multicast address MAY be silently discarded."
The other interesting thing about a broadcast ping is the ordering of replies. The hosts that replied the quickest are the hosts that are the physically closest to the sending host. The hosts that took the longest to reply are the physically farthest away from the sending host. The hosts that have gigabit links, even though physically farther than others appear near the top of the list. It's just cool to see propagation delay at work...