Implementation of a High Performance
Low Cost PTP Clock

ptp slave clock


The transition from a circuit switched to a packet based network data sometimes requires mechanisms for the transmission of precise time for synchronization of embedded systems as this information is not available any more. The femtocell, a thin 3G or 4G base station for indoor use and with a target price of less than $100, is an example of a device where this needs to be done at low cost.

This article is an introduction to the IEEE 1588 Precision Time Protocol, PTP. The article gives an overview of PTP basic principles and details of how hardware accuracy enhancements can improve accuracy by orders of magnitude. The use of a position integral (PI) servo loop (with some non-linear modification) in the PTP Protocol Engine software will allow for a nanosecond time resolution in spite of the jitter caused by packet switching.

About PTP

PTP is independent of network technology, but assumes that the average path delay between nodes is equal in both directions. The Protocol Engine will automatically adjust for this delay and will tolerate changes of the delay caused by network reconfiguration. We assume that TCP/IP over Ethernet used.

Grandmaster and Best Master Clock Algorithm

In a PTP network a Grandmaster (GM) is the node that defines what is the correct time. A GM normally has a highly stable oscillator and can have its clock locked to a built in GPS receiver or other time source reference. Thereby all clocks in the network can synchronize to a common reference such as TAI or UTC, which may be of value for legal and other reasons. In some applications a local time reference may be sufficient, eg. in a group of machines without any critical coupling outside the group. There may be several potential GMs in a PTP system, and the Protocol Engine software contains a mechanism, the Best Master Clock algorithm, that enables the clocks in the network to agree on the selection of the GM.

Frequency Synchronization

Sometimes the speed of the clock, i.e. the frequency, is more important than time. PTP can here be used to accurately and at low cost keep a frequency at a nominal and stable value for synthesis of the correct radio frequencies in a radio base station.

PTP Algorithms

The standard describes how synchronization is done by the exchange of different messages between master and slave. The messages are described below (see fact box) with a diagram showing the interdependencies between the messages. Each message is a UDP packet, encapsulated in an Ethernet frame. Time stamping is done for some messages. Software in the slave performs the necessary computations, filters the phase and frequency error signals and adjusts the slave clock so the errors are kept within narrow tolerances. The algorithms must be such that the time to lock is short enough (usually less than a minute), but when steady state has been reached, the servo can utilize the fact that the source is very stable and the only source of error to neutralize (when the jitter has been averaged out) is the relatively slow inherent drift of the local clock.

Different PTP clocks

Until now we have only talked about when a slave or a master running the PTP stacks. The standard refers to these end node applications as Ordinary clocks. However, in a networked topology the there are also intermediate units. A PTP slave can also be a master for another slave and such clock is called a Boundary Clock (BC). A BC has a network port with slave functionality that controls a local clock and has one or more ports with master functionality that distributes the local clock’s time instead of forwarding PTP messages between its slave and master ports.The BC clocks are usually combined with normal switching functions.

With the version 2 of PTP yet another type of clock called Transparent Clock (TC) was introduced. A TC can replace a BC in network elements. A TC does not have its own clock, and it does not block PTP messages between the master and the slaves. However, it inserts data on its delay (residence time), and slaves “downstream” can take that into account in their computations. The residence time can be accumulated over several nodes, so a slave can adjust for the aggregated time delay in a chain of TCs.

Timestamped Messages Synchronize the Clocks

Master - Slave Protocol

The synchronization is done by the exchange of four different PTP message types between master and slave as shown in the figure.

A fifth type of message is the management messages used for other communication needed between PTP nodes.

Qulsar's Ordniary Clock implementation

Ordniary Clock implementation

The block diagram illustrates roughly the organization of the system and how it is implemented. Green color is used for software, yellow for microcode, and blue for hardware. The customer application program can be developed in ANSI C, using the Conemtech Developer IDE. The platform has a POSIX compliant RTOS, a flash file system, and several I/O interfaces in addition to Ethernet channels.

The Conemtech processor architecture is built on extensive use of microcode – internal very low level, high speed, control code with wide microinstructions controlling the operations of every cycle with extreme flexibility in the combination of operations. Part of the microcode is writable, i.e. “soft” as software, which is unusual.

For accessing the network, the Conemtech processor chip contains an Ethernet MAC, implemented partly in microcode and partly in on-chip logic.

A clock should basically have a high frequency oscillator and a counter, with adjustable frequency and phase (i.e. time). In the Conemtech system system the local PTP clock can be adjusted without actually changing the oscillator frequency or the high-frequency counter. This will be described below.


Timestamping Packet Network Master Slave Ordinary Clock

High precision can only be achieved if timestamping is performed in hardware, close to the physical layer, so that the jitter caused by software is eliminated. A pulse is generated in the MAC logic at a specified point in the Ethernet frame passing to/from the physical layer, and this event triggers the copying of a counter value to a register.

Further timestamp processing is performed by interrupt-driven dedicated microcode – by the same processor core that also executes the TCP/IP stack, the RTOS, the PTP Protocol Engine, and typically some customer application – and thus requires no additional dedicated hardware.

On-chip timers

An on-chip configurable 8-channel timer system is used for the high-frequency timer and timestamp register, as well as for producing, under microprogram control, precise time signal output for use by embedded system hardware external to the chip.

Adjusting speed and phase of the local clock

A high-frequency oscillator drives a counter, but neither the oscillator nor the counter is adjustable. This counter measures “raw time” at the slave.

In the Ethernet MAC logic, the passage of the SFD byte to or from the PHY is detected. This event triggers the copying (capture) of the raw time counter contents to a register, and a microprogram IRQ is generated. The microprogram reads the register, as well as a continuation (more significant part) of the raw time counter that it keeps in its scratchpad, and stores this raw timestamp in a queue. However, it first checks that it is a PTP frame, or the timestamp is discarded.

When the raw time counter passes zero, it generates a microprogram IRQ, which triggers the microprogram to increment the continuation in the scratchpad.

Before the timestamps are delivered from the queue to the PTP software, they are converted to precise time according to the slave clock – which is virtual. The conversion is done by multiplication with a parameter A and addition of another parameter B.

The same conversion is done every time the software needs to read the current value of the precise time.

As mentioned above, the servo loop does not control the frequency or phase of the hardware counter. Instead it controls the parameters A and B. The actual slave precise time is not visible anywhere unless when it is calculated, which is only when needed. This saves energy.

Application example: Precise output signals

Precise output signals

In typical applications external hardware needs precisely timed signals, e.g. a pulse train, from the slave clock. The configurable counter system is used also for this purpose. As an example, a transition on an output port pin at a given precise time is generated as follows:

Copyright © 2024 Qulsar Inc. All rights reserved. Privacy Policy