Clock synchronization method and device based on SNTP and PPS

By combining the clock synchronization method of SNTP and PPS protocols in the power equipment of the distribution network, the problem of insufficient time synchronization accuracy of the power equipment of the distribution network is solved, and high-precision time calibration within a time slice is achieved, with an error of less than 1ms.

CN114614935BActive Publication Date: 2024-10-15NANJING HEXING GRID TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210337419.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-04-01
Publication Date
2024-10-15
Estimated Expiration
2042-04-01

AI Technical Summary

Technical Problem

The existing SNTP protocol is difficult to meet the time synchronization error requirement within 5ms in distribution network power equipment, especially when the equipment is dispersed and far away from the main station, it is difficult to meet the power system's accuracy requirements for time synchronization.

Method used

Combined with the SNTP protocol and second pulse PPS, the client obtains the current first second of the system after receiving the PPS second pulse, sends an SNTP time synchronization request to the server, and reads the SNTP time of the server when the interrupt time synchronization flag is valid. Calculate the actual time, proofread and update the client system time, initialize the synchronization timer, synchronize the RTC clock, and achieve time synchronization.

Benefits of technology

The timing operation is completed within a time slice, which significantly improves the timing accuracy. The time calibration error is less than 1ms, far exceeding the 20ms error of the existing technology.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114614935B_ABST
    Figure CN114614935B_ABST
Patent Text Reader

Abstract

The present invention discloses a clock synchronization method and device based on SNTP and PPS, the method comprising: after receiving the PPS second pulse, the client obtains the current first second of the system and sends an SNTP time synchronization request to the server; when the interrupt time synchronization flag of the client is valid, the client reads the SNTP time sent by the server, obtains the current second second of the system, and sets the synchronization time synchronization flag; when the synchronization time synchronization flag is valid, calculates the actual time according to the first second, the second second and the SNTP time; checks and updates the system time of the client; initializes the synchronization timer and synchronizes the RTC clock. With the above technical solution, the time synchronization can be completed within a time slice of the client system, greatly improving the time synchronization accuracy.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of power distribution network power equipment communication, and in particular to a clock synchronization method and device based on SNTP and PPS. Background Art

[0002] The power equipment of the distribution network is mainly installed on the line. When a line fails, the fault is removed actively and the fault information is uploaded to the master station. Since the power equipment of the distribution network is scattered and numerous, and is far away from the master station, it is generally connected by communication. Therefore, the time synchronization of the power equipment is very important.

[0003] At present, the engineering communication of power system usually adopts SNTP (Simple Network Time protocol, SNTP) simple network time protocol, which simplifies the original NTP (Network Time Protocol, NTP) protocol. When simplifying the algorithm, it can ensure the time accuracy, and the time error is within 20ms. However, the current power system requires that the power equipment of the distribution network needs to have Bluetooth function, Beidou function and GPS function, and the GPS function requires the time error to be within 5ms, but it is difficult to achieve the actual engineering requirement of the time error within 5ms if only relying on the SNTP protocol. Summary of the invention

[0004] Purpose of the invention: The present invention provides a clock synchronization method and device based on SNTP and PPS, which aims to combine the SNTP protocol with the pulse per second (PPS) to enable a non-real-time system to synchronize time with a real-time system, thereby greatly improving the timing accuracy; further, the time slice beat of the client system is very short, the timing can be completed within one time slice, and the time calibration error is less than 1ms.

[0005] Technical solution: The present invention provides a clock synchronization method based on SNTP and PPS, including: after the client receives the PPS second pulse, it obtains the current first second moment of the system and sends an SNTP time synchronization request to the server; the client is a real-time operating system, and the server is a real-time operating system or a non-real-time operating system; when the interrupt time synchronization flag of the client is valid, the client reads the SNTP time sent by the server, obtains the current second second moment of the system, and sets the synchronization time synchronization flag; when the synchronization time synchronization flag is valid, calculates the actual time according to the first second moment, the second second moment and the SNTP time; verifies and updates the system time of the client; initializes the synchronization timer and synchronizes the RTC clock.

[0006] Specifically, when the client receives the PPS second pulse, it also includes: after the GPS generates the second pulse, synchronizing time with the server.

[0007] Specifically, the time slice beat of the client system is 1 ms.

[0008] Specifically, the interrupt time synchronization flag of the client is set by the PPS second pulse.

[0009] Specifically, the client obtains the current first second of the system within 300 to 500 ms after receiving the PPS second pulse, and sends an SNTP time synchronization request to the server.

[0010] Specifically, the SNTP time is converted to a UNIX timestamp; the UNIX timestamp refers to the number of seconds since January 1, 1970. ms , excluding leap seconds.

[0011] Specifically, sntp ms The current UNIX timestamp of the system is calculated by subtracting the first second from the sum of the second second; the UNIX timestamp is converted into the actual time.

[0012] Specifically, the time format of the system clock is determined, and when the standard requirements are met, the system time of the client is checked and updated.

[0013] The present invention also provides a clock synchronization device based on SNTP and PPS, comprising: a time synchronization request unit, a time reading unit, a time calculation unit and a clock synchronization unit, wherein: the time synchronization request unit is used for obtaining the current first second moment of the system after the client receives the PPS second pulse, and sending an SNTP time synchronization request to the server; the client is a real-time operating system, and the server is a real-time operating system or a non-real-time operating system; the time reading unit is used for the client to read the SNTP time sent by the server when the interrupt time synchronization flag of the client is valid, and obtain the current second second moment of the system, and set the synchronization time synchronization flag to the position; the time calculation unit is used to calculate the actual time according to the first second moment, the second second moment and the SNTP time when the synchronization time synchronization flag is valid; the clock synchronization unit is used to calibrate and update the system time of the client; initialize the synchronization timer, and synchronize the RTC clock.

[0014] Specifically, the time synchronization request unit is used for the client to obtain the current first second time of the system within 300 to 500 ms after receiving the PPS second pulse, and send an SNTP time synchronization request to the server.

[0015] Beneficial effects: Compared with the prior art, the present invention has the following significant advantages: timing can be completed within one time slice of the client system, greatly improving the timing accuracy. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] Figure 1 A schematic diagram of the steps of the clock synchronization method based on SNTP and PPS provided by the present invention. DETAILED DESCRIPTION

[0017] The technical solution of the present invention is further described below in conjunction with the accompanying drawings.

[0018] See also Figure 1 , which is a schematic diagram of the steps of the clock synchronization method based on SNTP and PPS provided by the present invention.

[0019] Step 1: After receiving the PPS second pulse, the client obtains the current first second of the system and sends an SNTP time synchronization request to the server.

[0020] In the embodiment of the present invention, the client is a real-time operating system, and the server is a real-time operating system or a non-real-time operating system.

[0021] In the embodiment of the present invention, after the GPS generates the second pulse, it synchronizes time with the server.

[0022] In specific implementation, the GPS module usually sends out the time through the communication serial port after 100ms, that is, 100ms after the GPS module generates a second pulse, the time is synchronized with the server through the communication serial port to ensure the time accuracy of the server.

[0023] In a specific implementation, the client device can adopt the Ucos_III real-time operating system, and the system time slice beat is 1ms. The method provided by the present invention can complete the timing operation within one time slice beat. Therefore, the time calibration error is less than 1ms. Compared with the prior art solution, the error is within 20ms, and the accuracy is significantly improved.

[0024] In specific implementation, a time slice is a microscopic period of CPU time allocated by the real-time operating system to each running process. When the client receives the time synchronization reply and performs reading and synchronization calibration, there is no need for additional waiting or other operations. The timing can be completed within one time slice, and the error of time calibration is less than 1ms.

[0025] In the embodiment of the present invention, the client obtains the current first second of the system within 300 to 500 ms after receiving the PPS second pulse, and sends an SNTP time synchronization request to the server.

[0026] In the specific implementation, since there is a certain time interval between the client's request for SNTP synchronization and the server's reply, the client is required to send an SNTP synchronization request within 500ms after the second pulse is triggered. In this case, the server can reply with synchronization within the current second, that is, reply with synchronization within the same second when the second pulse is triggered, to ensure that the SNTP synchronization time obtained from the server does not span seconds, thereby avoiding the generation of errors and completing the timing within the current second.

[0027] Step 2: When the interrupt time synchronization flag of the client is valid, the client reads the SNTP time sent by the server, obtains the current second moment of the system, and sets the synchronization time synchronization flag.

[0028] In the embodiment of the present invention, the client's interrupt time synchronization flag is set by the PPS second pulse

[0029] In a specific implementation, under the triggering of the PPS second pulse, the client's interrupt time synchronization flag can be set, and the value is usually 1. In this case, the client's reading and time calibration operations are triggered and completed within a time slice of the client system.

[0030] In the embodiment of the present invention, the client reads the SNTP time sent by the server, specifically including converting the SNTP time into a UNIX timestamp; the UNIX timestamp refers to the number of seconds since January 1, 1970 (00:00:00 GMT). ms , excluding leap seconds.

[0031] In a specific implementation, the client may set a synchronization flag, which is usually 1. In this case, the client may start a time calibration operation.

[0032] Step 3: When the synchronization flag is valid, the actual time is calculated based on the first second, the second second and the SNTP time.

[0033] In the embodiment of the present invention, sntp ms The current UNIX timestamp of the system is calculated by subtracting the first second from the sum of the second second; the UNIX timestamp is converted into the actual time.

[0034] In the specific implementation, the following formula is used to calculate the current UNIX timestamp:

[0035] T=sntp ms +t2-t1, where T represents the current UNIX timestamp, t2 represents the second second, and t1 represents the first second.

[0036] Step 4: Check and update the client's system time.

[0037] In the embodiment of the present invention, the time format of the system clock is determined, and when the standard requirements are met, the system time of the client is checked and updated.

[0038] Step 5, initialize the synchronization timer and synchronize the RTC clock.

[0039] In the specific implementation, the RTC clock refers to the clock of the client's hardware chip. After synchronizing the RTC clock, the timing operation is completed within a time slice of the client system, and the error can be controlled within 1ms, significantly improving the accuracy of time calibration.

[0040] The present invention also provides a clock synchronization device based on SNTP and PPS, comprising: a time synchronization request unit, a time reading unit, a time calculation unit and a clock synchronization unit, wherein: the time synchronization request unit is used for obtaining the current first second moment of the system after the client receives the PPS second pulse, and sending an SNTP time synchronization request to the server; the client is a real-time operating system, and the server is a real-time operating system or a non-real-time operating system; the time reading unit is used for the client to read the SNTP time sent by the server when the interrupt time synchronization flag of the client is valid, and obtain the current second second moment of the system, and set the synchronization time synchronization flag to the position; the time calculation unit is used to calculate the actual time according to the first second moment, the second second moment and the SNTP time when the synchronization time synchronization flag is valid; the clock synchronization unit is used to calibrate and update the system time of the client; initialize the synchronization timer, and synchronize the RTC clock.

[0041] In the embodiment of the present invention, the time synchronization request unit is used to synchronize time with the server after the GPS generates a second pulse.

[0042] In the embodiment of the present invention, the time slice rhythm of the client system is 1 ms.

[0043] In the embodiment of the present invention, the interrupt time synchronization flag of the client is set by the PPS second pulse.

[0044] In the embodiment of the present invention, the time synchronization request unit is used for the client to obtain the current first second time of the system within 300 to 500 ms after receiving the PPS second pulse, and send an SNTP time synchronization request to the server.

[0045] In the embodiment of the present invention, the time reading unit is used to convert the SNTP time into a UNIX timestamp; the UNIX timestamp refers to the number of seconds since January 1, 1970. ms , excluding leap seconds.

[0046] In the embodiment of the present invention, the time calculation unit is used for sntp msThe current UNIX timestamp of the system is calculated by subtracting the first second from the sum of the second second; the UNIX timestamp is converted into the actual time.

[0047] In the embodiment of the present invention, the clock synchronization unit is used to determine the time format of the system clock, and when the standard requirements are met, calibrate and update the system time of the client.

Claims

1. A clock synchronization method based on SNTP and PPS, characterized in that: include: Within 300 to 500 ms after receiving the PPS second pulse, the client obtains the current first second of the system and sends an SNTP time synchronization request to the server. The client is a real-time operating system, and the server is a real-time operating system or a non-real-time operating system; When the client's interrupt time synchronization flag is valid, the client reads the SNTP time sent by the server, obtains the current second moment of the system, and sets the synchronization time synchronization flag. When the synchronization flag is valid, the actual time is calculated based on the first second, the second second and the SNTP time; Check and update the client's system time; Initialize the synchronization timer and synchronize the RTC clock.

2. The clock synchronization method based on SNTP and PPS according to claim 1, characterized in that: When the client receives the PPS second pulse, the method also includes: After the GPS generates a second pulse, it synchronizes time with the server.

3. The clock synchronization method based on SNTP and PPS according to claim 1, characterized in that: The client system's time slice beat is 1 ms.

4. The clock synchronization method based on SNTP and PPS according to claim 3, characterized in that: The interrupt time synchronization flag of the client is set by the PPS second pulse.

5. The clock synchronization method based on SNTP and PPS according to claim 4, characterized in that: The client reads the SNTP time sent by the server, including: Convert SNTP time to UNIX timestamp; the UNIX timestamp refers to the number of seconds since January 1, 1970 ms , excluding leap seconds.

6. The clock synchronization method based on SNTP and PPS according to claim 5, characterized in that: The actual time is calculated according to the first second, the second second and the SNTP time, including: sntp ms The current UNIX timestamp of the system is calculated by subtracting the first second from the sum of the second second. Convert a UNIX timestamp to real time.

7. The clock synchronization method based on SNTP and PPS according to claim 6, characterized in that: The system time of the client is updated by checking and updating, including: Determine the time format of the system clock and, if it meets the standard requirements, calibrate and update the client's system time.

8. A clock synchronization device based on SNTP and PPS, characterized in that: include: Request time synchronization unit, time reading unit, time calculation unit and clock synchronization unit, where: The request time synchronization unit is used for the client to obtain the current first second of the system within 300 to 500 ms after receiving the PPS second pulse, and send an SNTP time synchronization request to the server; the client is a real-time operating system, and the server is a real-time operating system or a non-real-time operating system; The time reading unit is used for the client to read the SNTP time sent by the server when the interrupt time synchronization flag of the client is valid, and obtain the current second second of the system, and set the synchronization time synchronization flag to the position; The time calculation unit is used to calculate the actual time according to the first second moment, the second second moment and the SNTP time when the synchronization time flag is valid; The clock synchronization unit is used to check and update the system time of the client; initialize the synchronization timer and synchronize the RTC clock.