Time synchronization in automation and DAQ systems is an important tool to ensure all moving parts in a system are synced together. Yet, setting up a time synchronized system is not always a trivial task. Depending on the network switch and its capabilities, different Precision Time Protocol (PTP) clock types are required to handle the demands on the hardware configuration.
PTP Nomenclature
Clock Priority
When networks negotiate which clock will be the grandmaster the priority numbers are the main differentiator. Priority numbers can be anything from 0 to 255. A device with a priority of 0 has the highest priority and a device with 255 has the lowest priority. For example, if device one has a priority of 25 and device two has a priority of 55, then device two will assume that device one is the grandmaster and has the “best clock” therefore syncing it’s time to device two.
UTC Offset/Leap Seconds
The UTC offset is the current number of leap seconds differentiating International Atomic Time (TAI) and Universal Coordinated Time (UTC). Read more about UTC Offset and leap seconds here.
Clock Types
There are two clock types on network switches that can handle most time synchronization requirements: Boundary Clocks and Transparent Clocks. Both clock types send PTP packets to devices, however choosing the correct clock type is a critical step in ensuring stable time synchronization.
Boundary Clock
A boundary clock requires the network switch to have a built-in PTP master clock. The switch's boundary clock will be a slave to the PTP grandmaster and the grandmaster for configured endpoint devices. Boundary clocks are useful in ensuring PTP grandmasters are not overloaded with messages.
Transparent Clock
A transparent clock configuration relays all PTP messages directly between the endpoint devices and the PTP grandmaster. There is no way to block the number of messages sent to the PTP grandmaster on the same network, which can overload the grandmaster. Transparent clocks generally adjust the PTP messages automatically to account for switch delay since the message is not coming directly from a clock (unlike the Boundary clock configuration).
PTP Uses
Many different fields that require precise time synchronization use PTP. While these are not all use cases, these are the most common places an engineer could find PTP time synchronization.
- Industrial Automation: PTP helps coordinate precise actions between any number of machines and devices in manufacturing and process control settings.
- Scientific Research: Similar to Industrial Automation, PTP synchronizes data across any number of data acquisition devices to sync up high speed data across many sensors.
- Aerospace and Defense: Satellite communications, navigation systems, and radar systems all use PTP to provide precise timing even across long distances.
- Power Grids: PTP allows grids to synchronize measurements and increase efficiency and stability over a wider area.
- Financial Services: Trading systems often require microsecond accuracy and PTP ensures fair trading.
Technical Details
PTP first must establish which clock is the "best" to ensure the most accurate timing source is being used. The Best Master Clock Algorithm (BCMA) automatically selects the most suitable clock based on the Clock Priority on each device.
PTP uses a set of specialized messages to exchange timing information between master and slave clocks. These messages work together to determine network delays and synchronize time across devices.
- Sync Message: The master clock initiates the synchronization process by sending a Sync message across the network. This message contains the master's timestamp of when it believes the message was sent based on processing time. However, this timestamp might not be perfectly accurate because processing times are not exact.
- Follow_Up Message: Immediately after the Sync message, the master clock sends a Follow_Up message. This message contains the precise timestamp of when the Sync message left the master's network interface. This two-step process allows for greater accuracy, especially when using hardware timestamping.
- Delay_Req (Delay Request) Message: After receiving the Sync and Follow_Up messages, the slave clock sends a Delay_Req message to the master. The slave records the exact time it sends this message but doesn't include this timestamp in the message itself.
- Delay_Resp (Delay Response) Message: Upon receiving the Delay_Req message, the master clock responds with a Delay_Resp message. This message contains the master's timestamp of when it received the Delay_Req message.
These messages work together to allow the slave clock to calculate two pieces of information:
- The offset between the master and slave clocks
- The network delay between the two devices
Here's how the slave uses these messages to perform its calculations:
- The slave notes the time it receives the Sync message (T2).
- From the Follow_Up message, it gets the precise time the Sync was sent (T1).
- The slave records the time it sends the Delay_Req message (T3).
- From the Delay_Resp message, it gets the time the master received the Delay_Req (T4).
Then, using these four timestamps, the slave can calculate:
- The offset between the clocks: ((T2 - T1) - (T4 - T3)) / 2
- The network delay: ((T2 - T1) + (T4 - T3)) / 2
The slave can adjust its local clock to match the master's time using these calculations to account for both the time difference and the network delay. This message exchange typically occurs periodically to maintain synchronization, with the frequency depending on the specific PTP implementation and the required level of accuracy.
In addition to these core messages, PTP also uses other types of messages for tasks such as announcing the presence of clocks, managing the master-slave hierarchy, and handling specific events or errors in the network.
This sophisticated messaging system, combined with precise timestamping (often at the hardware level), allows PTP to achieve remarkably accurate time synchronization, often down to sub-microsecond levels in well-designed networks.
While PTP is most often seen over Ethernet, it can operate over network layers like UDP/IP and wireless networks. The flexibility of PTP allows all kinds of devices to be synchronized without requiring direct connection to a PTP grandmaster.
Conclusion
While it often goes unnoticed, PTP is a highly sophisticated process applied in many areas. Yet, there are many different cases where UTC, TAI, and Leap Seconds can be a nuisance, or timing modules act differently on different devices. Ensure the clock types, network topology, and clock priority are all correctly defined for the best time synchronization possible.
Learn more about DMC's Test and Measurement Automation expertise and contact us for your next project.