Introduction

The network technology is widely used in various industrial automation, and control domains with the rapid advancement of industrial automation1, robotics technology2, and the Internet of Things (IoT)3. Thus, there is an increasing necessary for network performance. Improving time synchronization performance is becoming an urgent priority, because time synchronization technology serves as the fundamental basis for ensuring reliable network operation4.

Currently, the dominated time synchronization technologies include GPS-based clock synchronization5, the Network Time Protocol (NTP)6, and IEEE 1588 (Precision Time Protocol, PTP)7. The study in Ref.5 indicates that GPS clock synchronization devices offer high precision but are unsuitable for indoor environments where GPS cannot be used. NTP, operating on a client/server model, achieves clock synchronization with millisecond precision8. PTP, widely used in distributed networks, operates on a master/slave mode and achieves synchronization between master and slave node clocks with sub-microsecond precision, surpassing that of NTP9. Therefore, this research focuses on the PTP time synchronization method.

Recent research shows that the precision of PTP clock synchronization can be significantly improved. In Refs.10,11,12,13, authors exchanged multiple data packets to acquire precise timestamps, mitigating the effects of link asymmetry. Giorgi et al. developed a software-based packet sampler that effectively filters out packets with delays exceeding a certain threshold, compensating for the impact of packet delay on time precision12. Karthik, Shrestha, Ju, Zheng et al. various models were proposed to address the drift and aging of crystal oscillators, as well as the estimated time offset and drift14,15,16,17,18,19,20. Karthik et al. introduced a clock drift autoregressive model using a Kalman filter to estimate the offset and drift of master–slave clocks, thereby reducing the impact of timestamps on time synchronization14. Shrestha et al. employed clock drift coefficients and estimated clock drift factors to enhance time synchronization performance over an estimation period15. Zuo, Y. et al. modeled clock and frequency offsets and employed a second-order Kalman filter algorithm to enhance the precision of master–slave clock synchronization17. Furthermore, Yuan, Exel, Yin, Pedretti, Eidson, et al. implemented the PTP algorithm on various FPGA hardware platforms13,21,22,23,24,25. Specifically, Yin, Pedretti, Aamir Sohail Nagra et al. successfully implemented the PTP algorithm through FPGA, achieving nanosecond-level time synchronization precision according to their research results22,23,24.

However, these works in Ref.10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25 have the disadvantage of requiring extra hardware overhead and message packet exchange. In this paper, an enhanced time synchronization algorithm is proposed by improving the structure and algorithm of synchronization message packets based on the underlying protocol level. The key differences between this algorithm and the PTP algorithm are as follows: First, the synchronization message has a fixed length of 10 bytes and is assigned the highest priority. This ensures that the synchronization message reaches the slave clock as quickly as possible, thereby reducing network queuing delays and minimizing noise interference from asymmetric links. Subsequently, a Kalman filter model is employed to eliminate noise interference, including clock drift, network delay jitter, and network asymmetry. Finally, the clock is adjusted using a clock drift compensation algorithm to achieve higher time synchronization precision and stability. This study utilizes the OMNET ++ simulator26 to construct a simulation model for assessing the time synchronization precision of various algorithms.

IEEE 1588 overview

IEEE 1588(PTP)27,28 is a network communication protocol which is mainly utilized for achieving precise clock synchronization to ensure temporal consistency among various devices in computer networks25. The synchronization process is shown in Fig. 1. When the master/slave hierarchy is established, a clock synchronization between the master and slave clocks is achieved by transmitting four different types of synchronization messages: Sync, Follow_Up, Delay_Req and Delay_Resp28. From Fig. 1, when the slave clock receives the Delay_Resp message, it will have four timestamps. Thus,

$$T_{s1} { - }T_{m1} \, = \theta_{offset} { + }d_{ms} ,$$
(1)
$$T_{m2} { - }T_{s2} = d_{sm} { - }\theta_{offset} ,$$
(2)

where θoffset is the time offset between the master and slave clocks, dms is the propagation delay of the master clocks-to-slave clocks link, and dsm is the propagation delay of the slave clocks-to-master clocks link. In the PTP protocol, it is assumed that the communication links are symmetric29. Therefore,

$$d_{ms} = d_{sm} .$$
(3)
Fig. 1
figure 1

Timing diagram of PTP synchronization messages.

As a result, the time offset θoffset and the average transmission delay ddelay between the master and slave clock can be computed10:

$$d_{delay} = \frac{{d_{ms} + d_{sm} }}{2} = \frac{{T_{s1} - T_{m1} { + }T_{s2} - T_{m2} }}{2},$$
(4)
$$\theta_{offset} = \frac{{T_{s1} - T_{m1} + T_{{{\text{s}}2}} - T_{m2} }}{2}.$$
(5)

Finally, the slave clock can adjust the local clock based on θoffset so that it can synchronize the master clock30.

However, a major problem is that PTP assumes that the communication links are symmetric. This is not applicable in practical environments, because the synchronized message will inevitably experience various delays when it reaches the destination. Moreover, the precision of time synchronization can be also influenced by the precision of timestamps, the instability of crystal oscillators and the asymmetry in links31. Therefore, in recent years, many researches focus on the improvement of the precision of clock synchronization between master and slave devices.

An enhanced time synchronization algorithm

IEEE 1588 is a standardized protocol which is used in measurement and control systems to achieve precise synchronization between master and slave clocks. This protocol relies on the accurate master clocks to correct periodically the time of slave clocks along with the network. This paper proposes a high-performance, high reliability and auto-reconstructed network for the aerospace and industrial applications—SharkNet. Unlike traditional networks, SharkNet utilizes an independent underlying protocol. To resolve the issue of time synchronization between master and slave clocks, a novel time synchronization packet structure and an enhanced synchronization method are also proposed in this paper.

The SharkNet system has the following features:

  1. 1.

    The system has auto-reconstructed function: the system is completely transparent to users, and no configuration of network devices is required. The switch will automatically detect the port status regularly, ensuring timely identification of network failures. The system will be quickly reconstructed within 30 μs to achieve self-repair and ensure the effectiveness of the transmission path;

  2. 2.

    The system has autonomous path-finding function: the system can always find the optimal path among many redundant paths to implement information transmission. Furthermore, the system autonomously maintains its consistency and completeness, thereby completely eliminating coordination costs among users and reducing the threshold for user utilization;

  3. 3.

    The system has multiple redundant links to ensure system reliability: depending on specific applications, some or all ports can be connected as redundant links without the need for user configuration. When a switch or cable fails, the system can quickly detect the port state change and reselect the best path for data transmission;

  4. 4.

    The system is insensitive to the transmission medium, which can adapt to the local transformation of old systems. At present, the network is compatible with RS422, RS485, LVDS, Ethernet interfaces, and other mainstream networks available in the market;

  5. 5.

    The system has a high-precision time synchronization algorithm that can improve the synchronization precision and stability of node clocks in the network32.

Clock model

Assuming C(t) represents the time of a slave clock node at the reference time t (where t denotes the time of the master clock node), the time offset θ(t) of the slave clock can be expressed as:

$$\theta (t) = C(t) - t.$$
(6)

The rate of change of time offset is defined as clock drift s(t), expressed as:

$$s(t) = \frac{d\theta }{{dt}} \approx \frac{{\theta (t + T_{{{\text{cycle}}}} ) - \theta (t)}}{{T_{{{\text{cycle}}}} }}.$$
(7)

γ(t) is the rate of change of clock drift (also called the clock aging rate), and its relationship with s(t) is given by:

$$\gamma (t) = \frac{ds(t)}{{dt}} \approx \frac{{s(t + T_{{{\text{cycle}}}} ) - s(t)}}{{T_{{{\text{cycle}}}} }}.$$
(8)

From the above formula, the fundamental model of the clock can be derived:

$$\left\{ {\begin{array}{*{20}l} {\theta (k + 1) = \theta (k) + s(k)T_{{{\text{cycle}}}} + \gamma (k)T_{cycle}^{2} + \omega_{\theta (k)} } \\ {s(k + 1) = s(k) + \gamma (k)T_{{{\text{cycle}}}} + \omega_{s(k)} } \\ {\gamma (k + 1) = \gamma (k) + \omega_{\gamma (k)} } \\ \end{array} } \right..$$
(9)

In Eq. (9), Tcycle represents the time synchronization message sending interval, \(\omega_{\theta (k)}\),\(\omega_{s(k)}\),\(\omega_{\gamma (k)}\) are Gaussian white noise representing time offset, clock drift and the change rate of clock drift, respectively. Their variances are denoted by: \(\delta_{\theta }^{2} \cdot T_{cycle}\),\(\delta_{s}^{2} \cdot T_{cycle}\),\(\delta_{\gamma }^{2} \cdot T_{cycle}\).

In the IEEE 1588 synchronization process, the clock is adjusted based on the estimated values of the time offset and clock drift. In the kth synchronization iteration, the time offset, clock drift, and the change rate of clock drift are adjusted using the input parameters \(u_{\theta } (k)\),\(u_{s} (k)\) and \(u_{\gamma } (k)\). Assuming real-time and valid correction input during the synchronization period Tcycle, the IEEE 1588 three-state clock model can be formulated as follows:

$$\left\{ {\begin{array}{*{20}l} {\theta (k + 1) = (\theta (k) - u_{\theta } (k)) + (s(k) - u_{s} (k))T_{sync} + (\gamma (k) - u_{\gamma } (k))T_{sync}^{2} + \omega_{\theta (k)} } \\ {s(k + 1) = (s(k) - u_{s} (k)) + (\gamma (k) - u_{\gamma } (k))T_{sync} + \omega_{s(k)} } \\ {\gamma (k + 1) = \gamma (k) - u_{\gamma } (k) + \omega_{\gamma (k)} } \\ \end{array} } \right.,$$
(10)

where \(u_{\theta } (k)\),\(u_{s} (k)\) and \(u_{\gamma } (k)\) denote the corrected values of time offset, clock drift, and rate of change of clock drift, respectively, and they are considered as the estimated values at time k.

Proposed protocol architecture

The SharkNet system topology includes point-to-point direct connection, ring topology, tree topology, mesh hybrid topology. Among them, the mesh hybrid topological structure has the highest fault reliability among all topological structures.

The SharkNet system components consist of two parts: switches and end system33:

  1. 1.

    The switch is responsible for system maintenance and data packet forwarding. Its core is the data exchange center, which stores routing tables and is responsible for polling data in all interface data cache units to establish pipelines and forward data. Each switch can have 32 ports, each port contains two physical interfaces, one for receiving and one for sending, and has full-duplex communication capabilities;

  2. 2.

    The end system provide users with a connectivity interface to the SharkNet system and are responsible for automatically maintaining the availability of and access to network resources. The control interface and status interface are used to ensure smooth communication between the local controller and the end system interface module, and three data transmission methods: Parallel Interface, UART and SPI, are provided to meet actual application requirements. The end system module is connected to the switch via its uplink ports U0 and U1 and joins the network.

During data transmission, the communication link's transmission delay fluctuates due to the continuous variation in the length of the transmitted data frame. This fluctuation causes the PTP algorithm to introduce substantial noise when calculating the time offset and average transmission delay. Ethernet's PTP messages use frame lengths in the range of 64 to 1518 bytes34, so the transmission time of each message packet is uncertain, which introduces a significant amount of noise interference into subsequent time offset and average transmission delay calculations. To address this issue, this paper proposes a new protocol structure designed to mitigate the time offsets caused by frame length variations.

In SharkNet system, the length of each packet frame is 10 bytes, referred to as the base packet. There are two types of data packets in system: message packets and data packets.

Message packets are used to transmit command, status and response information in the network, which can be realized by using a single base packet. Message packets are divided into three types: internal, external and user-defined. Internal message packets are used for information exchange between devices to maintain network consistency and implement various built-in functions, such as port detection, automatic reconstruction, and time synchronization. These packets are restricted from user access. External message packets provide common network functions to users, such as reading the local address, sending bulk commands, and reading the routing table, etc. User-defined message packets are customized by users according to specific application projects.

The SharkNet system supports high priority of message packets at the physical layer. By employing preemptive transmission, message packets are embedded into data packets and transmitted first. This approach markedly reduces queuing time, ensuring high real-time performance for message packets throughout the transmission process. The SharkNet system utilizes an 80-bit parallel processing kernel that matches the width of the message packet. This allows data packets to be forwarded quickly in a single clock cycle, resulting in short processing times and maximizing the real-time performance of message transmission.

Compared to the Ethernet, the frame structure proposed in this paper increases the proportion of valid data in a message packet, particularly for time synchronization-related data packets. Additionally, the network features autonomous path-finding, port detection, and port health check functions to ensure that message packets are transmitted promptly via the shortest path. The frame format of the message packet is shown in Table 1.

Table 1 Message frame structure of the proposed network message packet.

The structure of the data frame in a message packet includes the following fields:

  1. 1.

    The 1-byte Mode Domain which is used to indicate the characteristic of the packet in terms of its type, function as well as priority;

  2. 2.

    The 2-byte Source Address Domain represents the address of a source device;

  3. 3.

    The 2-byte Destination Address Domain represents the address of a target device. Each device that connects to the network has a unique address;

  4. 4.

    The 1-byte Parameter Domain 1 and the 2-byte Parameter Domain 2 are used to set the attribute of the packet;

  5. 5.

    The 1-byte Control Domain is used to select the transmission path of data;

  6. 6.

    The 1-byte Chek Domain is used to ensure the integrity of a message packet in which a CRC check is employed.

The frame format of the data packet is shown in Table 2, and its priority is lower than that of the message packet. The mode domain of the data start packet is 0X09. The mode domain of the data continuation packet is 0X1E. The mode domain of the data end packet is 0X1A. During bulk data transfer, multiple base packets are combined to form one composite packet. Only the data start packet and the data end packet need to transmit domain overheads such as the source address and the destination address. The data continuation packet only needs to transmit the data that needs to be transmitted, and does not need to transmit these additional overheads.

Table 2 Data frame structure of the proposed network data packet.

Proposed time synchronization algorithm

For the network protocol message packet, based on the structure of its data frame, a synchronization method is proposed which is similar to the PTP clock synchronization message mechanism. The time offset and average transmission delay are obtained when the master–slave clocks exchange the timestamps. Its synchronization process involves the following three steps: 1. average transmission delay calculation; 2. filtering implementation; 3. time offset calculation. It uses three types of handshake communication messages: 1. A1 message; 2. 51 message; 3. A2 message. These synchronization messages are 10 bytes. Their message types are determined by the Mode Domain of the data frame. In other words, the Mode Domain of the A1 message is 0XA1, the Mode Domain of the 51 message is 0X51, and the Mode Domain of the A2 message is 0XA2.

The proposed message exchange timing diagram for the enhanced time synchronization method is shown in Fig. 2:

Fig. 2
figure 2

Timing diagram of the enhanced synchronization messages.

Step 1: Firstly, after the system uses the Best Master Clock Algorithm (BMCA, The Best Master Clock Algorithm operates independently on each clock within the system, identifying and selecting the clock with the best performance, whether it is a local or another system clock, to serve as the master clock.) to select master clock and slave clock, this master clock sends periodically A1 messages to slave clocks. The A1 message contains the time count Cm1 when it leaves the port. Next, a slave clock receives an A1 message, and this message records the time count Cs1 when it enters its port. Subsequently, the slave clock sends a 51 message to the master clock and records another time count Cs2 when it leaves its port. Once receiving the 51 message, the master clock records another time count Cm2 when it enters its own port. Finally, after receiving the A2 message, the slave clock has four timestamps: Cm1, Cs1, Cs2 and Cm2. Assuming that the path delay is symmetric, i.e. \(d_{ms} = d_{sm}\). Based on Eq. (5) in Sect. 2.1, the time offset θoffset can be calculated.

Step 2: Due to the presence of noise in the θoffset calculated in step 1, the second-order Kalman filter algorithm is employed in this study to accurately estimate the time offset, clock drift, and clock drift change rate, thereby accurately correcting the delay between the master and slave clocks35. The Kalman filtering algorithm36,37,38 are explained as follows:

prediction equation:

$$\hat{x}\left( {k|k - 1} \right) = A\hat{x}\left( {k - 1| k - 1} \right){ + }Bu\left( k \right),$$
(11)
$$P\left( {k|k - 1} \right) = AP\left( {k - 1|k - 1} \right)A^{T} { + }Q,$$
(12)

Update equation:

$$K\left( k \right) = P\left( {k|k - 1} \right)H^{T} \left[ {HP\left( {k|k - 1} \right)H^{T} { + }R} \right]^{ - 1} ,$$
(13)
$$\hat{x}\left( {k | \, k} \right) = \hat{x}\left( {k|k - 1} \right) + K\left( k \right)\left( {z\left( k \right) - H\hat{x}\left( {k|k - 1} \right)} \right),$$
(14)
$$P\left( {k|k} \right) = \left( {I - K\left( k \right)H} \right)P\left( {k|k - 1} \right).$$
(15)

where the state transition matrix A is:

$$A = \left[ {\begin{array}{*{20}c} 1 & {T_{sync} } & {T_{sync}^{2} } \\ 0 & 1 & {T_{sync} } \\ 0 & 0 & 1 \\ \end{array} } \right],$$

The control input matrix B is:

$$B = \left[ {\begin{array}{*{20}c} { - 1} & { - T_{sync} } & { - T_{sync}^{2} } \\ 0 & { - 1} & { - T_{sync} } \\ 0 & 0 & { - 1} \\ \end{array} } \right],$$

The posterior state estimate \(\hat{x}\left( {k|k} \right)\) is:

$$\hat{x}\left( {k| k} \right) = \left[ {\theta \left( k \right) s\left( k \right) \gamma \left( k \right)} \right]^{T} ,$$
(16)

The clock state equation input vector u(k) is:

$$u\left( k \right) = \left[ {u_{\theta } \left( k \right) u_{s} \left( k \right) u_{\gamma } \left( k \right)} \right]^{T} ,$$

The observation vector z(k) at time k is:

$$z\left( k \right) = \left[ {\theta_{M} \left( k \right) s_{M} \left( k \right)} \right]^{T} ,$$

where \(\theta_{M} \left( k \right)\) is the time offset calculated by the PTP algorithm at time k, and \(s_{M} \left( k \right)\) is the clock drift at time k, i.e.

$$\theta_{M} \left( k \right) = \theta_{offset} ,$$
(17)
$$s_{M} \left( k \right) = \frac{{\theta_{M} \left( k \right) - \theta_{M} \left( {k - 1} \right)}}{{T_{k} - T_{k - 1} }}.$$
(18)

The observation matrix H is:

$$H = \left[ \begin{gathered} \begin{array}{*{20}c} 1 & 0 & 0 \\ \end{array} \hfill \\ \begin{array}{*{20}c} 0 & 1 & 0 \\ \end{array} \hfill \\ \end{gathered} \right],$$

The covariance matrix of process noise Q is:

$$Q = \left[ {\begin{array}{*{20}c} {\delta_{\theta }^{2} T_{sync} } & 0 & 0 \\ 0 & {\delta_{s}^{2} T_{sync} } & 0 \\ 0 & 0 & {\delta_{\gamma }^{2} T_{sync} } \\ \end{array} } \right],$$

The matrix P(k|k−1) can be initialized to Q that is:

$$P\left( {\user2{1|0}} \right) = Q,$$

The observation noise covariance matrix R is:

$$R = \left[ {\begin{array}{*{20}c} {\sigma_{{\theta_{M} }}^{2} } & {\sigma_{{\theta_{s} }}^{2} } \\ {\sigma_{{s_{\theta } }}^{2} } & {\sigma_{{s_{M} }}^{2} } \\ \end{array} } \right] = \left[ {\begin{array}{*{20}c} {\sigma_{{\theta_{M} }}^{2} } & {\frac{{\sigma_{{\theta_{M} }}^{2} }}{{T_{sync} }}} \\ {\frac{{\sigma_{{\theta_{M} }}^{2} }}{{T_{sync} }}} & {2 \cdot \frac{{\sigma_{{\theta_{M} }}^{2} }}{{T_{sync} }}} \\ \end{array} } \right].$$

The above content uses the Kalman filter algorithm to estimate the time offset, clock drift, and the rate of change in clock drift. The state vector \(\hat{x}\left( {k|k} \right)\) in Eq. (14) represents the optimal solution calculated by the Kalman filter (the specific value of the state vector \(\hat{x}\left( {k|k} \right)\) is given in Eq. (16)). We denote the first component θ(k) of the state vector \(\hat{x}\left( {k|k} \right)\) obtained by the Kalman filter as θkoffset.

$$\theta_{koffset} = \theta \left( k \right).$$
(19)

The meaning of the Kalman filter algorithm parameters is shown in Table 335. First, use Eq. (5) and Eq. (18) to obtain the current time offset and clock drift. Subsequently, the time offset and clock drift are used as observation values of the Kalman filter algorithm so that the optimal time offset value θkoffset (Eq. (19)) can be obtained from the clock using the filter algorithm. Finally, the time offset (θkoffset) is added to the local clock of the slave clock in order to achieve time synchronization between the master clock and slave clock. Compared with PTP algorithm, the proposed algorithm requires to store the timestamp Cs1 of the slave clock (it will be used in the subsequent clock drift compensation algorithm).

Table 3 Parameters meaning for the Kalman Filtering algorithm.

Step 3: When the interval of the synchronized message set by the system ends, the second round of clock synchronization is initiated. During this round, Step 1 and Step 2 are repeated to obtain four timestamps, i.e., Cm3, Cs3, Cs4 and Cm4. At a result, the slave clock has five timestamps, i.e., Cm3, Cs3, Cm4, Cs4, and Cs1, Meanwhile, a new time count offset θkoffset is obtained. When the slave clock is operating at a slightly faster or slower frequency in the interval of the synchronized message, the time offset is accumulated. In order to resolve this issue, a clock drift compensation algorithm is used to correct this clock drift, as follows:

After obtaining the second time offset θkoffset, the cnt value of Eq. (20) is used to compensate for slave clock (see Fig. 2), in which θkoffset is the time offset between Cs1 and Cs3 (assuming that there is no clock drift for the master clock). This means that the slave clock in each cnt cycle is increased or decreased by one clock cycle.

$$cnt = \frac{{C_{s3} - C_{s1} }}{{\theta_{koffset} }} = \frac{{T_{cycle} }}{{\theta_{koffset} }}.$$
(20)

Step 4: When the sending interval of the synchronized message is completed again, the master clock sends an A1 message to initiate the third round of time synchronization, then repeating Step 3. The difference is that the θkoffset is a new value in the latest round.

The proposed method significantly reduces the impact of the asymmetric links, packet delay variation (PDV) and frequency drift of clock synchronization, thus effectively improving the time synchronization precision.

Simulation results

The OMNET ++ simulator software is used to simulate the time synchronization algorithm of the proposed algorithm in which the LibPLN library is employed as the noise generator39, so that the requirement of discrete event simulation is achieved40,41. The noise model is generated using the method proposed in Ref.42,43 to generate the oscillator noise. The model download can be found in Ref.44. The proposed simulation model is shown in Fig. 3. The master clock operates at the nominal frequency, thus the time offset is not generated. The slave clock adopts a standard clock noise model of the LibPLN library35. The Time Offset Observer module is a monitoring module that regularly checks the time offset between the master clock and the slave clock. The simulation results are shown in the following sections.

Fig. 3
figure 3

Simulation model by using OMNET ++  simulator.

Performance comparison in symmetric links

For a fair comparison, the same simulation configurations are used except for the length of the data frame. The detailed simulation parameters are presented in Table 4. The synchronization message sending interval, referred to as Tcycle, is set to 15.625 ms. This interval was chosen for specific reasons outlined in Sec. "Impact of sending interval". The following results are based on simulations using this sending interval.

Table 4 Simulation parameters*

In Fig. 4, the red line indicates the situation within one sending interval (15.625 ms). Since the monitoring interval is 1 ms, 15 or 16 number of time offset values between the master and slave clocks (from point A to point B) can be obtained using the Time Offset Observer module within one sending interval. It demonstrating that relying on the PTP algorithm alone leads to an accumulation of time errors. The slave clock at point B adjusts its local time based on the calculated time offset by the PTP algorithm to maintain synchronization with the master clock, thus confirming the effectiveness of the PTP algorithm.

Fig. 4
figure 4

Time offset of the PTP algorithm.

In Fig. 5, the X-axis represents the master–slave clock time offset values obtained from the simulation experiment, while the Y-axis represents the proportion of time offset in whole simulations. The red bar graph indicates the proportion of offsets greater than 1000 ns (1 μs), with the maximum value of 1375 ns to 1385 ns accounting for 0.4% of the total. This deviation may result from the accumulation of clock drift during the transmission interval. As the requirements for time synchronization accuracy and stability in measurement and control systems continue to increase, networks with microsecond-level time synchronization accuracy will be unable to meet this demand. Therefore, this paper employs an enhanced algorithm to improve time synchronization precision.

Fig. 5
figure 5

Distribution histogram of the PTP algorithm.

Figure 6 shows the time offset values of the proposed algorithm. From this figure, it can be seen that, the time offset values of the proposed algorithm are always within ± 12.5 ns and 0 ns when the master–slave clock is 80 MHz, i.e., the maximum time offset is less than ± 1 clock cycle due to the reduced propagation noise and the compensated frequency. As a result, for the symmetrical links, the proposed algorithm can improve the precision of the time synchronization to the nanosecond level.

Fig. 6
figure 6

Time offset of the proposed algorithm.

Figure 7 shows the comparison results of the time offset of various algorithm in symmetric links in panel (a) and asymmetric links in panel (b). It can be observed that the change of a frame length has a large impact on the time synchronization precision. The variable frame length of PTP results (Fig. 4.) in a synchronization precision of microseconds. However, when the packet length is set to a fixed length of 10 bytes, the time synchronization precision improves to nanoseconds (Case 1). The Kalman filter can slightly reduce the time offset due to the propagation noise, compared with the frame length adjustment method (Case 2). The used clock drift compensation algorithm significantly reduces the accumulation time offset (Case 3), but the proposed algorithm generates a minimum time offset (Case 4).

Fig. 7
figure 7

(a) Time offset in symmetric links. (b) Time offset in asymmetric links.

Impact of crystal oscillator frequency

Here, the impact of crystal oscillator frequency is investigated. The simulation parameters are shown in Table 5, and the maximum time offset of PTP (Red line) and the proposed algorithm (Blue line) is shown in Fig. 8. It can be seen that the time synchronization precision is improved when the crystal oscillator frequency increases. However, the time offset of the PTP algorithm always is larger than that of the proposed algorithm, even at a low frequency.

Table 5 Time offset of the proposed algorithm for various crystal oscillator frequencies.
Fig. 8
figure 8

The maximum time offset of various crystal oscillator frequencies.

The maximum time offset of the proposed algorithm for various crystal oscillator frequencies is summarized in Table 5. It can be seen that when the crystal oscillator frequency is 20 MHz, 40 MHz, 80 MHz, 100 MHz and 200 MHz respectively, the proposed algorithm has a good time synchronization precision. However, when the crystal oscillator frequency is 500 MHz and 800 MHz respectively, the time synchronization precision is increased to ± 2 clock cycles form ± 1 clock cycle due to shorter clock cycle. This amplifies the impact of errors caused by the crystal oscillator on each individual clock cycle, making it unattainable to achieve clock synchronization precision within ± 1 clock cycle.

Impact of sending interval

Keeping all other simulation environment parameters unchanged as indicated in Table 4, we change the sending interval in a symmetric link. We conducted simulations with eight different sending intervals, including 2 s, 1 s, 0.5 s, 0.25 s, 0125 s, 62.5 ms, 31.25 ms and 15.625 ms.

Figure 9 shows the maximum values of the obtained time offset when the sending interval is 2 s, 1 s, 0.5 s, 0.25 s, 0.125 s, 62.5 ms, 31.25 ms and 15.625 ms respectively. It can be seen from this figure that the PTP algorithm has the maximum time offset for all the sending intervals compared with the proposed algorithm, in which the proposed algorithm only has the time synchronization precision at the nanosecond level. At the same time, this figure also demonstrates that the time synchronization precision of the proposed algorithm is improved when the sending interval is reduced.

Fig. 9
figure 9

The maximum value of the time offset for various sending intervals.

Impact of asymmetric links

The delay between the master and slave clocks consists of sending delay, propagation delay, and receiving delay. When the sending delay is inconsistent with the receiving delay, the asymmetric delay is generated. Table 6 gives the delay of the proposed algorithm in an asymmetric link. This figure shows that the minimum sending and receiving delays of the proposed algorithm are 80 ns. Several jitters are added to these delays, and the Time Offset Observer module is used to monitor the time offset every 0.1 ms.

Table 6 The time offset in an asymmetric link*.

As shown in Table 6, we conducted 15 simulation experiments to examine the delay between the sending and receiving nodes, with a maximum offset of up to 100 ns. The results indicate that as the delay between the receiving and sending nodes increases, the time offset of the master–slave clock gradually increases as well. But our method effectively maintains time synchronization precision within three clock cycles.

Figure 10 shows the statistics of the time offset of the proposed algorithm. The pie chart illustrates the proportion of time offset obtained from simulations under various sending delays and receiving delays. To ensure the robustness of the experimental results, we conducted multiple sets of experiments. The red box in Fig. 10. indicates that when the delay of the sending and receiving nodes increase, the proportion of ≤  ± 1 clock cycle gradually decreases while the proportion of > 1 clock cycle gradually increases, so that the delay uncertainty is increased and the time offset is extended. The green box in Fig. 10 represents the result of two simulation experiment, in which the sending delay is exactly opposite to the receiving delay. The results show that in terms of amplifying the master–slave clock time offset, the sending node delay plays a key role in the time synchronization precision compared with the receiving node delay. Therefore, the time synchronization of the proposed algorithm can be achieved in the range of ± 37.5 ns.

Fig. 10
figure 10

Master–slave clock time offset proportion distribution diagram of the algorithm proposed in this paper under asymmetric conditions. (In the Fig. 10, take (b, c) as an example, where 'b' means that the processing delay of the sending node is increased by 'b' clock cycles on the basis of 80 ns, and 'c' means the processing delay of the receiving node is increased by "c" clock cycles on the basis of 80 ns. Each clock cycle is 12.5 ns.)

The comparison results of the time synchronization precision of various algorithm are given in Table 7. The time synchronization precision of the PTP algorithm is about 1 μs, the time synchronization precision described in Ref.19,20,21 basically reaches the microsecond level, and the time synchronization precision of the algorithms proposed in Ref.24 (i.e., the Kalman filter (KF), Sage-Husa adaptive Kalman filter (AKF), strong tracking Sage-Husa adaptive Kalman filter (STAKF) and the modified Strong Tracking Adaptive Kalman Filter (MSTAKF) algorithms) is microsecond level. For the proposed algorithm, its time synchronization precision is much smaller than that of other algorithms, thus efficiently improving its performance.

Table 7 Comparison results of the time synchronization precision of various algorithm.

Figure 11 gives the comparison results of the required time of the stable state of various algorithms. It can be seen that the PTP and PI control algorithms require about 155 ms (indicated by the red circle) to achieve the stable state while the proposed algorithm requires 883 ms (indicated by the green circle) due to the inclusion of the Kalman filtering algorithm. Therefore, future work will focus on reducing the time it takes for the proposed algorithm to reach a stable state.

Fig. 11
figure 11

Comparison results of the stable state of various algorithms.

This paper first conducts simulation experiments on the original PTP algorithm and the algorithm proposed in this paper based on symmetric links and asymmetric links. The results show that when the crystal frequency is 80 MHz, the proposed method successfully reduces the time offset from several microseconds to less than 40 ns. Then, we conducted a detailed analysis of the algorithm proposed in this paper from the aspects of crystal oscillator frequency, sending interval, sending delay, receiving delay and the time required to reach a stable state. The study found that when the crystal frequency is 80 MHz and the sending interval is 15.625 ms, the time synchronization accuracy achieved by the network has far exceeded the time synchronization precision requirements of current market demand. If higher precision is required, you can consider increasing the crystal oscillator frequency and stability to further improve the network's time synchronization precision.

Conclusion

This paper proposes a novel underlying protocol and an enhanced time synchronization algorithm to meet the time-sensitive requirements of the measurement and control system, in which the data frame structure is redesigned, the Kalman filtering model is used to eliminate noise interference, and the clock drift compensation algorithm is used to prevent the accumulated errors. The time synchronization algorithm proposed in this paper offers simplicity in implementation. The integration of the Kalman filter algorithm with the clock drift compensation algorithm renders it universally applicable across all network topology, promising significant efficacy. The simulation results have proved that the proposed algorithm has a better time synchronization precision, compared with the PTP and the improved PTP (based on the Kalman filtering) algorithms. Therefore, this algorithm provides a good choice for improving the time synchronization accuracy in measurement and control systems.