Time synchronization

From MuonPi-Wiki
Jump to navigation Jump to search

This tutorial describes, how to set up the time synchronization of the system clock by disciplining the kernel of the RPi with the Ublox's PPS (Pulse-Per-Second) signal using chronyd.

Install the pps kernel driver module

Edit the /boot/config.txt and add the following line:

dtoverlay=pps-gpio,gpiopin=18

This will activate the kernel pps driver module at startup listening to GPIO pin 18 to which the timepulse output of the uBlox is connected on the MuonPi HAT board. After a restart, one should see the activated driver in the kernel module list.

lsmod showing the loaded pps_gpio kernel module

To test the pps functionality, the command-line-tool ppstest may be used (install with sudo apt install pps-tools).

Checking the timepulse signal with ppstest.

In order to discipline the system clock, the pps signal has to be regarded and from the mean time difference a correction has to be applied to the clock speed. This can be realized with the chrony-daemon. Install chrony with sudo apt install chrony and edit the config file in /etc/chrony/chrony.conf. Modify or add lines as shown below.

# Welcome to the chrony configuration file. See chrony.conf(5) for more
# information about usuable directives.
# use a server from a public pool of ntp servers
pool 2.debian.pool.ntp.org iburst
# add another server within the local network to prevent synchronization loss in case of internet outages, not mandatory
server 192.168.2.1 iburst
# add the pps device as a trusted synchronization source
refclock PPS /dev/pps0 refid PPS trust
...

Finally, restart chronyd with sudo systemctl restart chrony.service and observe the activity e.g. with:

pi@raspberrypi:~ $ chronyc sources
210 Number of sources = 4
MS Name/IP address         Stratum Poll Reach LastRx Last sample               
===============================================================================
#* PPS                           0   4   377    17   +195ns[ +823ns] +/-  208ns
^? fb07-unbekannt2.physik.u>     0  10     0     -     +0ns[   +0ns] +/-    0ns
^- ns1.hrz.uni-giessen.de        2   9   377   184   -239us[ -238us] +/-   39ms
^- ns2.hrz.uni-giessen.de        2   9   377   240   -129us[ -127us] +/-   30ms