Configuring NTP and PPS on Windows

Configuring NTP and PPS on Windows

The guide is about the steps needed for configuring NTP and PPS on Windows, particularly Windows 10 and later versions of the NTP software.

Obtain the NTP software

The nice folks at Meinberg have built and packaged up the NTP source distribution for Windows with a GUI installer. This is available at https://www.meinbergglobal.com/english/sw/ntp.htm; there is probably no reason not to get the Current stable version.  While you are there, you should also grab the NTP Time Server Monitor program.  This is very handy for checking on the operation of NTP.

Once you have the software downloaded, go ahead and run the installer. The installer needs to be run with Administrator rights; I find it easiest to Right-click and use ‘Run as Administrator’. The defaults are fine for most people; make sure to select the correct country for the Pool Server. This will give NTP a good set of internet servers to synchronize with. Once NTP is installed, you can go ahead and install the NTP Monitor Software as well.zzz

Using pool servers

In later versions of the NTP software (after 4.2.6p5), you can simplify the pool server setup by replacing e.g.

server 0.us.pool.ntp.org iburst
server 1.us.pool.ntp.org iburst
server 2.us.pool.ntp.org iburst
server 3.us.pool.ntp.org iburst

with a single line:

pool us.pool.ntp.org iburst

and it will choose a number of working servers from county pool (the US in this case) and add them in.

Adding statistics output

Using either the NTP Time Server Monitor or by editing the config file directly, add the following lines into the ntp.conf:

enable stats
statsdir "C:\Program Files (x86)\NTP\etc\"
statistics loopstats

(There is also a peerstats which records the statistics on each remote clock (‘peer’) but I don’t find it very useful, and a clockstats which can be handy to find the GPS sentence offset (see later).  Certainly the loopstats is more generally useful for most people).

The format of the loopstats file is buried in the NTP documentation (http://doc.ntp.org/4.2.4/monopt.html and look about half way down the page) but it looks like this:

#MJD Seconds of the day Offset(s) Frequency (PPM) Jitter(s) Allan Deviation (PPM)
58263  55.919  0.000011875 -10.419 0.000008037 0.011183 4
58263 167.918 -0.000003361 -10.425 0.000009249 0.010655 4
58263 295.919  0.000005443 -10.414 0.000009195 0.010651 4
58263 343.918  0.000003266 -10.412 0.000008635 0.009999 4

MJD is Modified Julian Date, which was something astronomers invented for keeping continuous count of days and to confuse people (sorry about that…). You can combine the MJD with the seconds of the day (from UTC midnight) to get a fractional day. I then like to plot the offset and frequency in gnuplot as described in <link>; an example is shown below.

Plot of the NTP statistics files for about 1.8 days. We are plotting the offset in microseconds (left vertical axis) and frequency in PPM (right hand side vertical axis).
Plot of the NTP statistics files for about 1.8 days. We are plotting the offset in microseconds (purple line, values on the left vertical axis) and frequency in PPM (light blue line, values on the right hand side vertical axis). These results are from a Raspberry Pi with a local GPS module and using the PPS output.

Adding a local GPS

Assuming a regular GPS producing NMEA sentences (which is the most common kind), you want to add the following lines to the ntp.conf and restart NTP:

# Add GPS clock
server 127.127.20.1 minpoll 4 mode 16
fudge 127.127.20.1 refid MyGPS time2 0.0

The format is similar to adding an external server on the Internet. The 127.127 says that this a local server, the 20 refers to the specific clock driver for NMEA (from the list of reference clocks) and the 1 is the GPS device number (starting at 1). The minpoll 4 specifies how often to poll the clock; it’s 2^<number>, so minpoll 4 is 2^4=16 seconds. (The default is minpoll 6, meaning 2^6=64 seconds. You shouldn’t poll external servers faster than this as it puts extra load and could result in you being blocked).

The mode 16 tells NTP to listen at 9600 baud, which is the most common rate. The mode value is a bit mask in integer format; you can add additional options to make it listen to a specific NMEA sentence other than whichever comes first or write the sub-second sentence into clockstats which can help determine a good value for time2. The various options for mode are documented at http://doc.ntp.org/current-stable/drivers/driver20.html).

The fudge line allows you to have a more friendly name for the GPS (using refid) and adjust the timing of the received GPS sentences (using time2). Depending on your GPS, this may be necessary if the chosen GPS sentence is not close to the second marker. One way to determine this value is to add clockstats to your statistics loopstats line you added earlier, add 128 to the mode value, and restart NTP. This will write a clockstats.YYYYMMDD file with a delay value for each sentence. Remember to turn this off, otherwise you will get very big log files quite quickly.

Adding Pulse Per Second (PPS)

After a while of running NTP with a GPS connected and examining the status in either the NTP Time Server Monitor or the statistics files, you may well be somewhat disappointed with the performance of your GPS; I know I was… ! You will probably see quite a high jitter value and perhaps a high offset if you haven’t managed to find a stable time2 value. The problem is not really with the GPS, it’s just that the NMEA sentences are not designed to be precisely timed. The solution is to add the Pulse Per Second (PPS) information to NTP. The PPS pulse doesn’t carry any time information by itself, but its start is usually good to <100 nanoseconds.

Telling NTP to use PPS is easy:

# Add PPS source
server 127.127.22.1 minpoll 4

You will also need to designate a clock as the preferred source for the date & time information. I normally use a good nearby local server, rather than the local GPS to avoid any problems with jitter or picking the wrong sentence. Simply add prefer to the end of a suitable server line.

Getting NTP and PPS on Windows actually talking to each other, is somewhat tricky but has got easier in the latest version of NTP. The advice depends on whether you have a real serial port with the PPS signal on or not.

Real serial port

Meinberg have signed the version of the serialpps.sys driver produced by Dave Hart so it works on modern Windows. This is available through this link: http://people.ntp.org/burnicki/windows/serialpps-20120321-signed.zip

Once downloaded and unpacked, run the install.bat script as the administrator. The script will suggest to add a PPSAPI_DLLS environment variable but the better and more secure way (supported by ntp 4.2.8p10 and later) is to create a registry entry. This can be done by using the regedit browser and editor or from a command prompt (as administrator):

reg add HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NTP /v PPSProviders /t REG_MULTI_SZ /d c:\serialpps\serialpps-ppsapi-provider\x86\serialpps-ppsapi-provider.dll /f

For the Registry Editor GUI, you will want to navigate down each part after the add (e.g. HKEY_LOCAL_MACHINE then SYSTEM etc) until you get down to NTP. The Right-click, choose New and Multi-String Value and then enter ‘PPSProviders’. You can then fill in your path to the serialpps-ppsapi-provider.dll file. This will be in a sub directory that were unpacked from the zipfile earlier.

No actual serial port

This procedure is very similar to the above but instead the DLL is called loopback-ppsapi-provider.dll. This is located in the bin\ directory of the NTP distribution (normally C:\Program Files (x86)\NTP\bin).

More info on these options is at the PPS on Windows section of the NTP support site

Allowing connection by other clients

To allow other clients on your local network to connect, you need to add the following lines:

# Allow local subnet to receive time service and query server stats
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

Otherwise the default nopeer and noquery parts further up (usually applied to all IPv4 connections via the restrict -4 default ... line). The nopeer part prevents other clients connecting (‘peering’) with your NTP server. The noquery part prevents the query tools such as ntpq -p <hostname> from connecting to your particular server <hostname> at which can be annoying when trying to see what is going on.

The TL,DR version for serial GPS with PPS

  1. Download stable NTP from Meinberg and install.
  2. Download NTP Monitor from Meinberg and install also.
  3. Get the serial PPS kernel driver, unpack and run install.bat as administrator.
  4. Add PPSProviders registry key as in Real serial port above.
  5. Download and modify the example ntp.conf file.
  6. Restart NTP service.