CN117320144A - Primary and secondary clock time synchronization method and system based on wireless communication - Google Patents

Primary and secondary clock time synchronization method and system based on wireless communication Download PDF

Info

Publication number
CN117320144A
CN117320144A CN202311520703.2A CN202311520703A CN117320144A CN 117320144 A CN117320144 A CN 117320144A CN 202311520703 A CN202311520703 A CN 202311520703A CN 117320144 A CN117320144 A CN 117320144A
Authority
CN
China
Prior art keywords
time
time service
message
slave
local
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202311520703.2A
Other languages
Chinese (zh)
Inventor
熊跃军
刘阳琦
邓黠
李大志
岳冬梅
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Xinghan Spacetime Technology Beijing Co ltd
Xinghan Spacetime Technology Changsha Co ltd
Original Assignee
Xinghan Spacetime Technology Beijing Co ltd
Xinghan Spacetime Technology Changsha Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Xinghan Spacetime Technology Beijing Co ltd, Xinghan Spacetime Technology Changsha Co ltd filed Critical Xinghan Spacetime Technology Beijing Co ltd
Priority to CN202311520703.2A priority Critical patent/CN117320144A/en
Publication of CN117320144A publication Critical patent/CN117320144A/en
Pending legal-status Critical Current

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04WWIRELESS COMMUNICATION NETWORKS
    • H04W56/00Synchronisation arrangements
    • H04W56/001Synchronization between nodes
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04BTRANSMISSION
    • H04B7/00Radio transmission systems, i.e. using radiation field
    • H04B7/14Relay systems
    • H04B7/15Active relay systems
    • H04B7/185Space-based or airborne stations; Stations for satellite systems
    • H04B7/1851Systems using a satellite or space-based relay
    • H04B7/18513Transmission in a satellite or space-based system
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04JMULTIPLEX COMMUNICATION
    • H04J3/00Time-division multiplex systems
    • H04J3/02Details
    • H04J3/06Synchronising arrangements
    • H04J3/0635Clock or time synchronisation in a network
    • H04J3/0638Clock or time synchronisation among nodes; Internode synchronisation
    • H04J3/0658Clock or time synchronisation among packet nodes
    • H04J3/0661Clock or time synchronisation among packet nodes using timestamps
    • H04J3/0667Bidirectional timestamps, e.g. NTP or PTP for compensation of clock drift and for compensation of propagation delays

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Physics & Mathematics (AREA)
  • Astronomy & Astrophysics (AREA)
  • Aviation & Aerospace Engineering (AREA)
  • General Physics & Mathematics (AREA)
  • Electric Clocks (AREA)
  • Synchronisation In Digital Transmission Systems (AREA)

Abstract

The application relates to a primary and secondary clock time synchronization method and system based on wireless communication, wherein the method comprises the following steps: the time service host receives satellite system messages and standard second pulse signals through a BD/GPS satellite signal receiving module and calibrates local time and a local clock; and the time synchronization of the primary clock and the secondary clock is realized through LORA wireless communication mode between the time service host and the time service slave after satellite time service. The method adopts the BD/GPS satellite time service and LORA microwave time synchronization mode, combines the satellite time service technology with a pure software mode to realize the time synchronization algorithm in the PTP protocol, fills the defect of application to a radio communication system, and realizes the purposes of satellite time service and high-precision clock synchronization.

Description

Primary and secondary clock time synchronization method and system based on wireless communication
Technical Field
The present disclosure relates to the field of communications technologies, and in particular, to a method and a system for synchronizing a primary clock and a secondary clock based on wireless communications.
Background
With rapid development of radio communication technology and big data in recent years, more and more distributed wireless sensor networks are applied to aspects of life, such as: smart home, smart measurement, etc., and each node of these distributed wireless sensor networks is a radio communication system. For most distributed sensor networks, data collected by all sub-nodes are finally transmitted to a unified data processing platform, and the data are processed, analyzed and researched, so that future data development trend is predicted. The uniform time reference is a critical influencing factor for the whole distributed wireless sensor network. Just as for a single sensor device, an accurate system clock is a critical factor that affects whether it can provide accurate services. For the whole distributed wireless sensor network, the accuracy of clock synchronization of the whole network is a key factor for affecting whether the whole network can provide accurate service. When the clock synchronization performance of the whole network is poor, for some measurement works with higher time precision requirements, and the like, larger data errors are likely to occur, and the whole network is more seriously likely to be jammed, so that the network is paralyzed. Therefore, the time reference of the whole distributed wireless sensor network can be unified, the performance of the whole network can be greatly improved, and important references are provided for post-processing and analyzing the data of each child node, so that the research on the time synchronization problem of the distributed wireless sensor network is also a hot research topic.
Because of the limitation of space region, each node in the distributed wireless sensor network is not time-shared at the same time, and the situation of non-uniform time reference in the network is caused. When the distributed wireless sensor network performs time synchronization, the time of each piece of sub-equipment must be synchronized on the same time line, and the time line is generally UTC time, i.e. international standard time, or the time line is converted from standard time to unified time used by the country or time zone standard time according to the region where the distributed wireless sensor network works, and the process of synchronizing the unified time of the distributed wireless sensor network to the international standard time is called time service.
Some results have been achieved in research on a satellite timing technology and a clock synchronization algorithm of a high-precision time synchronization protocol, but few application examples of combining the satellite timing technology with the clock synchronization algorithm of the high-precision time synchronization protocol and the LORA wireless communication technology are available.
Disclosure of Invention
Based on the foregoing, it is necessary to provide a primary and secondary clock time synchronization method and system based on wireless communication.
A primary and secondary clock time synchronization method based on wireless communication comprises the following steps:
the time service host receives satellite system messages and standard second pulse signals through the self-contained BD/GPS satellite signal receiving module and calibrates the local time and the local clock.
And the time synchronization of the primary clock and the secondary clock is realized through LORA wireless communication mode between the time service host and the time service slave after satellite time service.
In one embodiment, the method further comprises: and comparing the standard second pulse signal output by the calibrated time service host with the standard second pulse signal received by the BD/GPS satellite signal receiving module to obtain the time service clock error of the calibrated time service host and the BD/GPS satellite signal receiving module.
In one embodiment, the time synchronization of the primary clock and the secondary clock is realized through a LORA wireless communication mode between the time service host and the time service slave after satellite time service, and the method comprises the following steps:
and the time service host computer and the time service slave computer after satellite time service carry out message interaction by adopting a PTP protocol in a LORA wireless communication mode, and the time service slave computer acquires parameters of a time synchronization algorithm in the PTP protocol.
And calculating the time error value and the clock error value between the time service host and the time service slave by adopting a time synchronization algorithm in the time service slave according to the parameters.
And calibrating the local time and the local clock of the time service slave according to the time error value and the clock error value corresponding to the time service slave, and completing the time synchronization of the master clock and the slave clock.
In one embodiment, a time service host computer and a time service slave computer after satellite time service perform message interaction by adopting a PTP protocol in a LORA wireless communication mode, and the time service slave computer acquires parameters of a time synchronization algorithm in the PTP protocol, including:
time service host computer:
when receiving the date request message sent by the time service slave machine, the local date information of the local machine is obtained and the host date message is sent to the time service slave machine,
after receiving the request time message of the time service slave, recording the time T2 of receiving the message, acquiring the local time of the local machine, transmitting the time message to the time service slave, and recording the time T3 of transmitting the completion time message.
And after receiving the request time message of the time service slave machine and the sending completion time message, sending the time T2 timestamp of the local record to the time service slave machine.
And after receiving the request T3 message of the time service slave machine, sending the T3 timestamp of the local record to the time service slave machine.
Time service slave machine:
and sending a host date request message to the time service host to acquire the current date data of the time service host.
When receiving the host date message sent by the time service host, the time service host acquires the date information of the time service host from the host date message, and directly updates the local date of the time service slave.
And sending a request time message to the time service host, and recording the time T1 when the message is sent.
After receiving the time message sent by the time service host, recording the time T4 of receiving the time message, directly acquiring the time information of the time service host in the time message, and updating the local time of the time service slave by adopting the acquired time information of the time service host.
And sending a request time message and a sending completion time message to the time service host.
After receiving the T2 timestamp message, reading the T2 timestamp and storing the T2 timestamp to the local.
And sending a request T3 message to the time service host.
After receiving the T3 time stamp message, reading the T3 time stamp and storing the T3 time stamp to the local.
In one embodiment, the parameters include: the time service host sends the accurate time stamp of the request time message, the time service slave receives the accurate time stamp of the request time message, the time service slave sends the accurate time stamp of the Delay Req message, and the time service host receives the accurate time stamp of the Delay Req message.
Calculating a time error value and a clock error value between the time service host computer and the time service slave computer by adopting a time synchronization algorithm according to parameters, wherein the method comprises the following steps:
The root time service host machine sends a request time message accurate time stamp, the time service slave machine receives the request time message accurate time stamp, the time service slave machine sends a Delay Req message accurate time stamp, and the time service host machine receives the Delay Req message accurate time stamp and calculates a time error value and a clock error value of the time service host machine and the time service slave machine by adopting a PTP time synchronization protocol algorithm.
A primary and secondary clock time synchronization system based on wireless communication, the system comprising: a time service host and a plurality of time service slaves; the master-slave clock time synchronization method based on wireless communication of claim 1 is adopted between each time service slave and the time service master.
In one embodiment, the time service host is configured to receive a satellite system packet and a standard second pulse signal through the BD/GPS satellite signal receiving module, calibrate a local time and a local clock, and then perform packet interaction with each time service slave through the LORA radio communication module by using PTP protocol.
The time service slave is used for carrying out message interaction with the time service host by adopting a PTP protocol through the LORA radio communication module, and acquiring parameters of a time synchronization algorithm in the PTP protocol; calculating a time error value and a clock error value between the time service host computer and the time service slave computer by adopting a time synchronization algorithm according to the parameters; and calibrating the local time and the local clock according to the time error value and the clock error value, so as to realize the time synchronization of the master clock and the slave clock.
In one embodiment, the timing host includes: the system comprises a main control module, a BD/GPS satellite signal receiving module, a LORA radio communication module and an OLED real-time display module; the hardware structure of the time service slave is the same as that of the time service host.
The main control module comprises an ARM microcontroller, the ARM microcontroller is communicated with the BD/GPS satellite signal receiving module through a second serial port, and the ARM microcontroller is communicated with the LORA radio communication module through a third serial port; the ARM microcontroller is connected with the OLED real-time display module through an IIC2 interface; the timer TIM2 of the ARM microcontroller outputs a local standard second pulse signal serving as an updating time reference in a PWM mode, and a mechanism for updating second parameters and other time parameters by interrupting and updating tasks is adopted to update the local time.
And the BD/GPS satellite signal receiving module is used for receiving and processing the positioning time-giving message and the standard second pulse signal of the BD/GPS satellite system under the control of the main control module, and feeding back the received message and the standard second pulse signal to the ARM microcontroller.
And the LORA radio communication module is used for carrying out message interaction with the time service slave machine by adopting a PTP protocol under the control of the main control module and feeding back the interaction communication message data to the main control module.
The main control module is used for analyzing, checking and extracting the standard universal time UTC time contained in the received positioning time-giving message of the BD/GPS satellite system, calibrating the local time and the local clock to realize satellite time-giving, and transmitting the local time to the OLED real-time display module; and the method is also used for analyzing the message data fed back by the LORA radio communication module and acquiring parameters required by a time synchronization algorithm in the PTP protocol.
And the OLED real-time display module is used for refreshing and displaying the local time in real time.
In one embodiment, the ARM microcontroller is an STM32F407ZGT6 microcontroller unit.
The mechanism for updating the second parameter and other time parameters of the task by adopting the interrupt is adopted to update the local time, which comprises the following steps:
initializing an ARM microcontroller, enabling a related interrupt, loading an initialization time in a local time, setting a second overflow flag to be in a false state, enabling a PWM channel of the timer TIM2 to output a 1PPS signal of a first period according to a count value of the timer TIM2, enabling a microprocessor to automatically enter the timer TIM2 interrupt when the timer TIM2 is timed to 1s each time when the system formally operates, automatically increasing a second parameter in the interrupt, setting the second overflow flag bit to be in a true state if the second parameter overflows, enabling the PWM channel of the timer TIM2 to update and output the 1PPS signal of a next period, calculating and refreshing other time parameters when the PWM channel of the timer TIM2 detects that the second overflow flag bit is in a true state when the foreground task operates, resetting the second overflow flag bit to be in false state, and waiting for next second overflow update.
In one embodiment, the time synchronization of the primary clock and the secondary clock of the system is realized based on LORA radio communication modules carried on the time service host and the time service slave; the process of the time synchronization of the primary clock and the secondary clock comprises the following steps:
when the timing host starts a PTP period, the timing host sends a Sync message to the LORA radio communication module of the timing slave through the LORA radio communication module; after the Sync message is sent, a Follow Up message is sent to a LORA radio communication module of the time service slave; the Follow Up message contains accurate timestamp information of the moment when the Sync message leaves the time service host.
And the LORA radio communication module of the time service slave receives the Sync message and records the accurate time stamp information of the receiving time, and then reads and stores the accurate time stamp information of the sending time of the Sync message from the received Follow Up message.
The time service slave machine sends a Delay Req message to the time service host machine through the LORA radio communication module of the time service slave machine.
The time service host receives the Delay Req message sent by the time service slave and records the accurate time stamp information of the received Delay Req message.
The time service host loads the accurate receiving time stamp information of the Delay Req message into the Delay Resp message and sends the Delay Resp message to the time service slave.
The time service slave receives the Delay Resp message and acquires the accurate receiving time stamp information of the Delay Resp message from the Delay Resp message;
the time service slave machine calculates by adopting a time synchronization algorithm in a PTP protocol according to the accurate time stamp information of the Sync message at the moment when the Sync message leaves the time service host machine, the accurate time stamp information of the Sync message at the moment when the Sync message is sent, the accurate time stamp information of the Delay Req message and the accurate time stamp information of the Delay Resp message, so as to obtain a time error value and a clock error value of the time service host machine and the time service slave machine, and then updates the local time and the local clock of the calibration time service slave machine according to the time error value and the clock error value, thereby realizing the time synchronization of the master clock and the slave clock.
The method and the system for synchronizing the time of the primary clock and the secondary clock based on wireless communication, wherein the method comprises the following steps: the time service host receives satellite system messages and standard second pulse signals through a BD/GPS satellite signal receiving module and calibrates local time and a local clock; and the time synchronization of the primary clock and the secondary clock is realized through LORA wireless communication mode between the time service host and the time service slave after satellite time service. The method adopts the BD/GPS satellite time service and LORA microwave time synchronization mode, combines the satellite time service technology with a pure software mode to realize the time synchronization algorithm in the PTP protocol, fills the defect of application to a radio communication system, and realizes the purposes of satellite time service and high-precision clock synchronization.
Drawings
FIG. 1 is a flow chart of a primary and secondary clock time synchronization method based on wireless communication in one embodiment;
FIG. 2 is a schematic diagram of a transfer satellite timing scheme in one embodiment;
FIG. 3 is a schematic diagram of a satellite clock checking calculation in one embodiment;
FIG. 4 is a timing flow between a timing master and a timing slave according to another embodiment;
FIG. 5 is a primary and secondary clock time synchronization block diagram based on wireless communications in one embodiment;
FIG. 6 is a timing host workflow in another embodiment;
fig. 7 is a working flow of a time service slave in another embodiment.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the present application will be further described in detail with reference to the accompanying drawings and examples. It should be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the present application.
The method adopts the time service host computer after satellite time service to realize the time synchronization of the primary clock and the secondary clock through the wireless communication between the time service host computer and the time service slave computer. The method specifically comprises the following steps: the time service host machine adopts a satellite signal receiver to receive satellite system messages and second pulse signals and calibrate local time and local clocks so as to realize a satellite time service function; meanwhile, the time service host computer and the time service slave computer interact messages through the LORA radio communication module; the time service slave machine acquires and records calculation parameters required by a high-precision time service algorithm through message interaction with the time service host machine, then calculates and obtains a time error value and a clock error value between the time service host machine and the time service slave machine through the high-precision time service algorithm, and then calibrates the local time and the local clock according to the calculated error value, thereby realizing time synchronization of the master clock and the slave clock.
In one embodiment, as shown in fig. 1, there is provided a primary and secondary clock time synchronization method based on wireless communication, the method comprising the steps of:
step 100: the time service host receives satellite system messages and standard second pulse signals through the self-contained BD/GPS satellite signal receiving module and calibrates the local time and the local clock.
Specifically, the satellite system time service function is realized based on a Beidou/GPS signal receiving module carried by a time service host, the module receives a positioning time service message and a second pulse signal of a Beidou/GPS satellite system in real time, feeds back the received message and the second pulse signal to a microprocessor, and the microprocessor analyzes, checks and extracts the standard universal time UTC time contained in the positioning time service message of the Beidou/GPS satellite system.
The key point of the satellite system capable of realizing accurate positioning and time service is that a high-precision clock source carried by the satellite system itself directly influences the positioning precision and time service precision of the whole satellite navigation system. Normally, the satellite system carries a high-precision atomic clock which is strictly time-synchronized with the standard world coordination time (UTC) as a local clock source of the satellite navigation system. After the satellite navigation system automatically sends, organizes and starts to work normally, a navigation time-giving message is sent to a ground satellite navigation system receiver, and after the satellite navigation time-giving message is received by a satellite signal receiver on the ground, the satellite navigation time-giving message is analyzed and a corresponding standard second pulse signal, namely a 1PPS signal, is output, and the period of the signal is 1 second. The ground equipment with the satellite navigation system receiver can calibrate the clock source signal of the crystal oscillator of the equipment through the second pulse signal, so that the local clock signal is synchronous with the satellite clock signal, the whole project is satellite time service, and the schematic diagram of the forwarding type satellite time service is shown in fig. 2.
The device at a certain position on the earth surface needs to acquire the position information of the device or needs to calibrate the clock signal of the device, and then the satellite navigation time service receiver carried on the device can calculate the position information of the device only by receiving satellite navigation time service message information of more than four satellites. However, on the basis that the local equipment knows the self position coordinate information, the clock synchronization with the satellite system can be realized only by receiving the positioning time-giving message sent by 1 satellite. Assuming that the clock error value between the local device and UTC in standard world coordination is t, the calculation principle of calculating the clock error t between the local device and UTC in standard world coordination is shown in fig. 3. In fig. 3, T (u) represents the local time of the device, T (UTC) represents the UTC time of the standard world coordination time, and T (sv) represents the satellite system time.
t=T(utc)-T(u) (1)
In fig. 3, RC is the time difference between the time when the satellite system transmits the positioning grant message and the time when the local device receives the positioning grant message, and the time difference can be calculated by equation (2) and equation (3).
RC=t+T(sv)+T() (2)
T()=t R +t i +t j +t r (3)
Wherein T (sv) represents an error value between the atomic clock time of the satellite system and UTC (universal coordinated time) of the standard world, T R Time delay value t representing transmission path of satellite positioning time-giving message i 、t j Representing additional delay values, t, generated by satellite system positioning time-lapse message transmission due to atmospheric effects r Represented as an additional delay value due to untimely reception or other problems by the local device.
Step 102: and the time synchronization of the primary clock and the secondary clock is realized through LORA wireless communication mode between the time service host and the time service slave after satellite time service.
Specifically, the LORA technology is a wireless communication technology widely applied to a wide area network, is developed from a spread spectrum modulation technology, generally works in an unlicensed frequency band, and is widely used in a large-scale communication scenario with long distance and low power consumption. The LORA technology adopts a spread spectrum modulation communication technology, which shows that the technology can obtain a longer wireless communication distance in principle, and improves the wireless transmission capability.
The PTP (Precise Time Protocol) protocol, namely the high-precision time service protocol, is a time service protocol proposed in the IEEE1588v2 standard, solves the problem of inaccurate time synchronization by utilizing link symmetry in a communication network, and can theoretically realize time service precision of 10 nanosecond magnitude by using the protocol algorithm. The PTP protocol utilizes an optimal master clock (Best Master Clock, BMC) algorithm, first, a device clock with an accurate clock source needs to be selected as a master clock, the device is then a time service host, then other device clocks in the network are then slave clocks, and then the other devices are time service slaves. The time service slave can calculate the clock error between the time service slave and the time service master by carrying out a series of message interactions with the time service master and then using a local clock synchronization (Local Clock Synchronization, LCS) algorithm, and then the time service slave calibrates the local clock of the time service slave according to the calculated clock error so as to realize the purpose of clock synchronization.
And the time service slave machine uses the calculated clock deviation to calibrate the clock source of the slave machine and correct the self time of the slave machine system along with the execution of the time synchronization algorithm, and then gradually reduces the clock error with the host machine clock after the next time of the time synchronization algorithm passes through the time synchronization algorithm for a plurality of times, thereby achieving the purpose of improving the time synchronization precision.
In the above method for synchronizing the time of the primary and secondary clocks based on wireless communication, the method comprises: the time service host receives satellite system messages and standard second pulse signals through a BD/GPS satellite signal receiving module and calibrates local time and a local clock; and the time synchronization of the primary clock and the secondary clock is realized through LORA wireless communication mode between the time service host and the time service slave after satellite time service. The method adopts the BD/GPS satellite time service and LORA microwave time synchronization mode, combines the satellite time service technology with a pure software mode to realize the time synchronization algorithm in the PTP protocol, fills the defect of application to a radio communication system, and realizes the purposes of satellite time service and high-precision clock synchronization.
In one embodiment, the method further comprises: and comparing the standard second pulse signal output by the calibrated time service host with the standard second pulse signal received by the BD/GPS satellite signal receiving module to obtain the time service clock error of the calibrated time service host and the BD/GPS satellite signal receiving module.
In one embodiment, step 102 includes the steps of:
step 200: and the time service host computer and the time service slave computer after satellite time service carry out message interaction by adopting a PTP protocol in a LORA wireless communication mode, and the time service slave computer acquires parameters of a time synchronization algorithm in the PTP protocol.
Step 202: and calculating the time error value and the clock error value between the time service host and the time service slave by adopting a time synchronization algorithm in the time service slave according to the parameters.
Step 204: and calibrating the local time and the local clock of the time service slave according to the time error value and the clock error value corresponding to the time service slave, and completing the time synchronization of the master clock and the slave clock.
In one embodiment, step 200 includes:
time service host computer:
and after receiving the date request message sent by the time service slave machine, acquiring local date information of the local machine and sending the host date message to the time service slave machine.
After receiving the request time message of the time service slave, recording the time T2 of receiving the message, acquiring the local time of the local machine, transmitting the time message to the time service slave, and recording the time T3 of transmitting the completion time message.
And after receiving the request time message of the time service slave machine and the sending completion time message, sending the time T2 timestamp of the local record to the time service slave machine.
And after receiving the request T3 message of the time service slave machine, sending the T3 timestamp of the local record to the time service slave machine.
Time service slave machine:
and sending a host date request message to the time service host to acquire the current date data of the time service host.
When receiving the host date message sent by the time service host, the time service host acquires the date information of the time service host from the host date message, and directly updates the local date of the time service slave.
And sending a request time message to the time service host, and recording the time T1 when the message is sent.
After receiving the time message sent by the time service host, recording the time T4 of receiving the time message, directly acquiring the time information of the time service host in the time message, and updating the local time of the time service slave by adopting the acquired time information of the time service host.
And sending a request time message and a sending completion time message to the time service host.
After receiving the T2 timestamp message, reading the T2 timestamp and storing the T2 timestamp to the local. The T2 timestamp message refers to a Sync message sent by a time service host and received by the time service slave.
And sending a request T3 message to the time service host. Wherein the request T3 message refers to a Delay Req message.
After receiving the T3 time stamp message, reading the T3 time stamp and storing the T3 time stamp to the local.
In one embodiment, the parameters include: the time service host sends a request time message accurate time stamp, the time service slave receives the request time message accurate time stamp, the time service slave sends a Delay Req message accurate time stamp, and the time service host receives the Delay Req message accurate time stamp; step 202 comprises: the time service host sends a request time message accurate time stamp, the time service slave receives the request time message accurate time stamp, the time service slave sends a Delay Req message accurate time stamp, and the time service host receives the Delay Req message accurate time stamp and calculates a time error value and a clock error value of the time service host and the time service slave by adopting a PTP time synchronization protocol algorithm.
Specifically, the clock error and link delay time of the time service host and the time service slave:
t offset =((T2-T1)-(T4-T3))/2 (4)
t delay =((T2-T2)+(T4-T3))/2 (5)
wherein T1 represents an accurate time stamp of a Sync message sent by a time service host, and T offset The clock error of the time service host computer and the time service slave computer is represented, T2 represents the accurate time stamp of the Sync message received by the time service slave computer, T3 represents the accurate time stamp of the Delay Req message sent by the time service slave computer, T4 represents the accurate time stamp of the Delay Req message received by the time service host computer, and T delay Is the link delay time.
The principle of PTP network timing is used here, but only by means of this technique, above the LORA wireless timing. T1 is in the Follow Up message, the time stamp of Sync packet is sent for the time service host (because the sending time is not the time of sending the current data packet of the time service host, the time stamp is sent by the Follow Up message), T2 is the time stamp of the Sync packet of the time service host received by the time service slave, T3 is the time stamp of the Delay Req sent by the time service slave, T4 is the time stamp of the Delay Req message received by the time service host, the T4 time stamp received by the time service host is embedded into the slave by the Delay Req message, T2 and T3 are the time stamp of the time service slave for receiving the Sync message and the time stamp of the Delay Req sent, the time service slave knows the two time stamps, the two time stamps do not need to be transmitted, and only the time service host needs to transmit the two time stamps T1 and T4 to the time service slave.
In a specific embodiment, the time synchronization flow between the time service host and the time service slave is shown in fig. 4, after the time service host calibrates the local time, a time synchronization ready message is sent to the time service slave, and after the slave receives the time synchronization ready message sent by the time service host, the slave is ready to pair with the host. Firstly, the time service slave machine sends a host date request message to the time service host machine to acquire current date data of the host machine, after the time service host machine receives the date request message sent by the time service slave machine, local date information of the time service slave machine is acquired, and after the time service slave machine receives the host date message sent by the time service host machine, the time service slave machine can only directly update the local date after acquiring the date information of the time service host machine because of long period of date transmission change. And then the time service host computer sends a time request message to the time service host computer, records the time T1 when the time transmission is completed, records the time T2 when the time service host computer receives the time request message sent by the time service slave computer, acquires the local time transmission time message of the local machine to the slave computer, simultaneously records the time T3 when the time transmission is completed, and records the time T4 when the time service slave computer receives the time message sent by the time service host computer, and directly acquires the time information of the time service host computer in the time message. The acquired time information of the time-service host is used for updating the local time of the time-service slave, and the time of the time-service slave is delayed than that of the time-service host because the time delay of the wireless communication link exists. Then, the time service slave machine sends a request T2 message to the time service host machine, the time service host machine receives the request T2 message of the time service slave machine and then sends a local recorded T2 timestamp to the time service slave machine, the time service slave machine reads the T2 timestamp and stores the T2 timestamp to the local after receiving the timestamp message, then the time service slave machine sends a request T3 message to the time service host machine, the time service host machine receives the request T3 message and then sends the local recorded T3 timestamp to the time service slave machine, and the time service slave machine reads the T3 timestamp and stores the T3 timestamp to the local after receiving the T3 timestamp message. And finally, the time-service slave calculates the time difference between the master and the slave through the four time stamps of T1, T2, T3 and T4 and the PTP time synchronization protocol algorithm, calibrates the local clock, and can obtain the time-service error through comparing and calculating by measuring the 1PPS signals on the time-service slave and the time-service host.
It should be understood that, although the steps in the flowchart of fig. 1 are shown in sequence as indicated by the arrows, the steps are not necessarily performed in sequence as indicated by the arrows. The steps are not strictly limited to the order of execution unless explicitly recited herein, and the steps may be executed in other orders. Moreover, at least some of the steps in fig. 1 may include multiple sub-steps or stages that are not necessarily performed at the same time, but may be performed at different times, nor do the order in which the sub-steps or stages are performed necessarily performed in sequence, but may be performed alternately or alternately with at least a portion of other steps or sub-steps of other steps.
In one embodiment, as shown in fig. 5, there is provided a primary and secondary clock time synchronization system based on wireless communication, the system comprising: a time service host 1 and a plurality of time service slaves 2; the master-slave clock time synchronization method based on wireless communication is adopted between each time service slave machine 2 and the time service master machine 1 to carry out master-slave clock time synchronization.
Noteworthy are: before satellite time service, the second pulse signal generated by the local clock signal running in the local time of the time service host 1 and the second pulse signal generated by the satellite signal receiving module need to be paid attention to and recorded correspondingly.
In one embodiment, the time service host is configured to receive a satellite system packet and a standard second pulse signal through the BD/GPS satellite signal receiving module, calibrate a local time and a local clock, and then perform packet interaction with each time service slave through the LORA radio communication module by using PTP protocol.
The time service slave is used for carrying out message interaction with the time service host by adopting a PTP protocol through the LORA radio communication module, and acquiring parameters of a time synchronization algorithm in the PTP protocol; calculating a time error value and a clock error value between the time service host computer and the time service slave computer by adopting a time synchronization algorithm according to the parameters; and calibrating the local time and the local clock according to the time error value and the clock error value, so as to realize the time synchronization of the master clock and the slave clock between each time service slave and the time service master.
In one embodiment, the timing host 1 includes: the device comprises a main control module 10, a BD/GPS satellite signal receiving module 11, a LORA radio communication module 12 and an OLED real-time display module 13; the hardware structure of the timing slave 2 is the same as that of the timing master 1.
The main control module 10 comprises an ARM microcontroller 101, the ARM microcontroller 101 communicates with the BD/GPS satellite signal receiving module 11 through a second serial port, and the ARM microcontroller communicates with the LORA radio communication module 12 through a third serial port; ARM microcontroller 101 is connected with OLED real-time display module 13 through IIC2 interface; the timer TIM2 of the ARM microcontroller 101 outputs a local standard second pulse signal serving as an update time reference in a PWM manner, and updates the local time by adopting a mechanism of interrupting update second parameters and task update other time parameters.
The BD/GPS satellite signal receiving module 11 is configured to receive and process the positioning time-giving message and the standard second pulse signal of the BD/GPS satellite system under the control of the main control module 10, and feed back the received message and the standard second pulse signal to the ARM microcontroller 101.
And the LORA radio communication module 12 is used for carrying out message interaction with the time service slave 2 by adopting a PTP protocol under the control of the main control module 10 and feeding back interaction communication message data to the main control module 10.
The main control module 10 is configured to parse, check and extract a standard universal time UTC time contained in a received positioning time-giving message of the BD/GPS satellite system, calibrate a local time and a local clock to realize satellite time-giving, and transmit the local time to the OLED real-time display module 13; and is further configured to parse the message data fed back by the LORA radio communication module 12, and obtain parameters required by a time synchronization algorithm in the PTP protocol.
The OLED real-time display module 13 is configured to refresh the display local time in real time.
Specifically, the time service host is provided with a BD/GPS satellite signal receiving module for receiving satellite signals and acquiring time information and satellite 1PPS signals therefrom to calibrate the local clock of the time service host, so that the local clock of the time service host is synchronous with the satellite clock, after the local clock is calibrated, the local time information can be displayed through an OLED display module provided with the time service host, and meanwhile, signal error comparison can be performed between the 1PPS signals output by the calibrated time service host and the 1PPS signals output by the BD/GPS satellite signal receiving module through an oscilloscope or other devices, so that the time service clock error of the time service host and the BD/GPS satellite signal receiving module can be measured.
In one embodiment, the ARM microcontroller is an STM32F407ZGT6 microcontroller unit; the mechanism for updating the second parameter and other time parameters of the task by adopting the interrupt is adopted to update the local time, which comprises the following steps: initializing an ARM microcontroller, enabling a related interrupt, loading an initialization time in a local time, setting a second overflow flag to be in a false state, enabling a PWM channel of the timer TIM2 to output a 1PPS signal of a first period according to a count value of the timer TIM2, enabling a microprocessor to automatically enter the timer TIM2 interrupt when the timer TIM2 is timed to 1s each time when the system formally operates, automatically increasing a second parameter in the interrupt, setting the second overflow flag bit to be in a true state if the second parameter overflows, enabling the PWM channel of the timer TIM2 to update and output the 1PPS signal of a next period, calculating and refreshing other time parameters when the PWM channel of the timer TIM2 detects that the second overflow flag bit is in a true state when the foreground task operates, resetting the second overflow flag bit to be in false state, and waiting for next second overflow update.
Specifically, the timing master and the timing slave both adopt STM32F407ZGT6 microcontroller units as main control modules, and carry a FreeRTOS operating system as an application software operation platform.
In one embodiment, the time synchronization of the primary clock and the secondary clock of the system is realized based on LORA radio communication modules carried on the time service host and the time service slave; the process of the time synchronization of the primary clock and the secondary clock comprises the following steps:
when the timing host starts a PTP period, the timing host sends a Sync message to the LORA radio communication module of the timing slave through the LORA radio communication module; after the Sync message is sent, a Follow Up message is sent to a LORA radio communication module of the time service slave; the Follow Up message contains accurate timestamp information of the moment when the Sync message leaves the time service host.
And the LORA radio communication module of the time service slave receives the Sync message and records the accurate time stamp information of the receiving time, and then reads and stores the accurate time stamp information of the sending time of the Sync message from the received Follow Up message.
The time service slave machine sends a Delay Req message to the time service host machine through the LORA radio communication module of the time service slave machine.
The time service host receives the Delay Req message sent by the time service slave and records the accurate time stamp information of the received Delay Req message.
The time service host loads the accurate receiving time stamp information of the Delay Req message into the Delay Resp message and sends the Delay Resp message to the time service slave.
The time service slave receives the Delay Resp message and acquires the accurate receiving time stamp information of the Delay Resp message from the Delay Resp message;
the time service slave machine calculates by adopting a time synchronization algorithm in a PTP protocol according to the accurate time stamp information of the Sync message at the moment when the Sync message leaves the time service host machine, the accurate time stamp information of the Sync message at the moment when the Sync message is sent, the accurate time stamp information of the Delay Req message and the accurate time stamp information of the Delay Resp message, so as to obtain a time error value and a clock error value of the time service host machine and the time service slave machine, and then updates the local time and the local clock of the calibration time service slave machine according to the time error value and the clock error value, thereby realizing the time synchronization of the master clock and the slave clock.
In a specific embodiment, the master-slave clock time synchronization system based on wireless communication totally uses STM32F407 series microprocessors as a master control chip, and on a FreeRTOS platform, the local time and local clock synchronization operation of the time service host and the satellite positioning time service system are completed based on a satellite time service technology, and the local time and local clock synchronization operation of the time service host and the time service slave are realized based on a time synchronization algorithm of a high-precision clock synchronization protocol and a LORA radio communication technology. Finally, a radio time synchronization system based on satellite time service is completely realized.
The system adopts a Beidou/GPS satellite signal receiver module to realize satellite time service positioning message receiving and second pulse signal receiving, realizes time synchronization of a time service host and a satellite positioning time service system, adopts a LORA radio communication module to realize message interaction of the time service host and a time service slave, transmits parameters for calculating time errors and clock errors to the time service slave to be synchronized, and finally corrects and calibrates local time and local clock by adopting an error value calculated by a pure software method of the time service slave to be synchronized, thereby realizing synchronization of the time service host and the time service slave. Finally, the satellite time service precision of the radio clock synchronization system based on the satellite time service reaches microsecond magnitude and the time synchronization precision of LORA time synchronization also reaches microsecond magnitude.
(1) Time service host
The time service host is mainly composed of four functional parts, namely a local clock updating function, a BD/GPS satellite signal message receiving and processing function, a LORA radio communication message receiving and processing function and an OLED real-time display refreshing local clock function. The local clock updating function accurately updates the local time data in a timing mode through the counting and timing function of the timer, and when the time service host is in an offline state due to unexpected situations and can not receive satellite signals, accurate local time information can be provided for users. The BD/GPS satellite signal message receiving and processing function is used for receiving and processing the data message of the BD/GPS satellite, acquiring accurate UTC time information and date information from the message, and simultaneously calibrating and updating the 1PPS signal of the local clock through the acquired 1PPS signal to realize the clock synchronization of microsecond magnitude of the counter. The LORA radio communication message receiving and transmitting processing function is responsible for sending, receiving and processing relevant communication message data; the OLED display module is used for refreshing local time display in real time, and a user can intuitively acquire relative time information through the module. Corresponding to the functions of the four modules described above, the present embodiment creates a plurality of functional tasks corresponding thereto, and is supplemented with corresponding interrupt service functions to ensure efficient, quick and accurate implementation of the corresponding functions. The specific workflow of the timing host is shown in fig. 6.
Firstly, aiming at realizing the local time updating function of a time service host, the TIM2 of STM32F407ZGT6 is used as a time reference for local time operation updating in design, and meanwhile, in order to ensure the accuracy of local time information in an offline state, a mechanism for interrupting updating second parameters and updating other time parameters by tasks is adopted in design, so that local time data is updated. In order to reduce the complexity of time setting calculation and increase the accuracy of time setting function realization, the design sets the counting period of the timer counter to 0.25us and sets the timing time of the timer to 1s, so that the steps of executing a time setting algorithm and updating the local time of a microprocessor can be reduced, the processing time is shortened to a certain extent, and the processing efficiency is improved. The design uses the PWM output function of Channel2 of TIM2 as 1PPS output of local time signal, and can make the 1PPS signal updated in time more accurate in combination with the configuration of the above. It should be noted that, in code implementation, restrictions need to be applied to all data according to the theoretical scope of data, so as to prevent system breakdown caused by using erroneous data. When the local time updating function is realized, firstly, at the initialization, the TIM2 is started, the related interrupt is enabled, the local time is loaded with an initialization time, the second overflow flag is set to be in a false state, meanwhile, the PWM channel of the TIM2 starts to output a 1PPS signal of a first period according to the count value of a timer, when the system formally operates, because the microprocessor automatically enters the TIM2 interrupt when the timer reaches 1s every time, the second parameter is automatically increased in the interrupt, if the second parameter overflows, the second overflow flag bit is set to be in a true state, meanwhile, the PWM channel of the TIM2 updates and outputs the 1PPS signal of the next period, when the second overflow flag bit is detected to be in a true state during the operation of a foreground task, other time parameters are calculated and refreshed, and the second overflow flag bit is set to be in false again, and the next second overflow updating is waited. The update of the local time and the output of the local time 1PPS signal are realized through the workflow.
Secondly, aiming at the realization of the BD/GPS satellite signal message receiving and processing function, the USART2 of STM32F407ZGT6 is used as a BD/GPS satellite signal message receiving interface in design, the PD8 of STM32F407ZGT6 is used as a 1PPS signal acquisition interface of a BD/GPS module, the communication baud rate of the USART2 is configured to be 9600,8 data bits according to the related parameters of the USART interface of the BD/GPS module, no verification exists, and the 1 end bit is communicated with the USART interface of the BD/GPS module. When the BD/GPS satellite signal message receiving and processing function is realized, initializing and starting USART2, enabling related interruption, configuring the communication baud rate and related communication setting of the USART2, emptying a data receiving buffer area of the USART2, setting the receiving length of the USART2 to 0, setting the receiving completion state of the BD/GPS message to be false, entering a receiving monitoring state, marking the moment as new second starting moment and message starting sending moment when rising edge jump occurs on a 1PPS signal of the BD/GPS module, resetting a timer counter at the moment, realizing the function of synchronizing with a BD/GPS clock, entering the message receiving starting state, receiving the message transmitted by the BD/GPS module by the USART2, setting a BD/GPS message receiving completion flag bit to be true in the interruption, entering the receiving completion state when the front task is running, detecting that the BD/GPS message receiving completion flag bit is true, analyzing the BD/GPS message, converting the time from the current time to UTC, and finally realizing the function of synchronizing with the UTC time. Through the flow, the receiving processing of BD/GPS satellite signals and the receiving processing of BD/GPS 1PPS signals are finally realized, and satellite time service is realized.
Thirdly, aiming at the realization of the LORA radio receiving and transmitting processing function, the design uses the USART3 of STM32F407ZGT6 as a data receiving and transmitting interface of the LORA radio communication module, adopts the PA15 of STM32F407ZGT6 as an AUX signal receiving and processing interface of the LORA radio communication module, configures baud rate 9600bps according to the LORA radio communication module, 8 data bits, has no check bit, configures relevant parameters of the USART3 in 1 end bit, starts the USART3 during initialization, starts relevant interruption, sets the state of the LORA radio communication module to be busy, waits for the AUX signal of the LORA radio communication module to be in a rising edge, namely, the module returns to an idle state, then sends a configuration message of the LORA radio communication module to configure the LORA radio communication module, at the moment, the AUX signal of the LORA radio communication module is in a falling edge, the AUX of the LORA radio communication module is in a busy state, the AUX of the LORA radio communication module is waited to be in a rising edge again, the idle state, the AUX of the LORA radio communication module is represented, the LORA radio communication module is configured, and the data can be completely received by sending the AUX to the LORA radio communication module through the ART 3. When the LORA radio communication module transmits data, the LORA radio communication module needs to wait for idle, and the last USART3 transmission is completed and is currently in an idle state, and then the data to be transmitted is transmitted to the LORA radio communication module through the USART3, i.e. the data transmission can be performed through the LORA radio communication module. When the LORA radio communication module receives, the AUX signal of the LORA radio communication module will have a falling edge, which marks that the module is receiving transmission, then waits for the AUX signal of the LORA radio communication module to have a rising edge, marks that the module is idle, but there may still be last frame data being transmitted at this time, so that it is necessary to wait for the USART3 idle interrupt to trigger and place a USART3 data receiving completion mark, marks that the LORA radio module finishes receiving data, stores the received data in the USART3 data receiving buffer, and finally reads the received data when the foreground task is running. After the initialization of the time service host is completed, a time service ready message is sent to the time service slave, then the time service host enters a time service waiting state, and the time service host waits for receiving a relevant time service request message sent by the time service slave and carries out corresponding processing. And the data receiving and transmitting processing function of the LORA radio module is realized.
And fourthly, aiming at the realization of the real-time refreshing and displaying local time function of the OLED, the design adopts IIC2 of STM32F407ZGT6 as a communication interface of the OLED display module, and performs initialization configuration on the OLED module according to an OLED data configuration manual issued by an OLED manufacturer, so that the OLED module has a better display effect, when in initialization, the hardware IIC function of the STM32F407ZGT6 is started, the local time information of the local time module is obtained, the relevant display information is displayed on the OLED display module through the IIC2 interface by adopting the 1608 font, and when the time display needs to be updated, the time information needing to be refreshed is sent to the OLED display module again through the IIC interface in a foreground task displayed in the local time, so that the real-time refreshing and displaying of the local time function of the OLED module is realized.
(2) Time service slave machine
The time service host is mainly composed of four functional parts, namely a local clock updating function, a BD/GPS satellite signal message receiving and processing function, a LORA radio communication message receiving and processing function and an OLED real-time display refreshing local clock function. The local clock updating function updates the local time data through the counting function of the timer, and can still provide accurate local time information for a user when the time service slave is in an offline state due to unexpected situations, namely can not receive a time service signal of the time service host. The LORA radio communication message receiving and transmitting processing function is responsible for sending, receiving and processing relevant communication message data; the OLED display module is used for refreshing local time display in real time, and a user can intuitively acquire relative time information through the OLED display module. Corresponding to the functions of the three modules described above, the present embodiment creates a plurality of functional tasks corresponding thereto, and is supplemented with corresponding interrupt service functions to ensure efficient, quick and accurate implementation of the corresponding functions. The working flow of the time service slave is shown in fig. 7.
Firstly, aiming at realizing the local time updating function of a time service host, the TIM2 of STM32F407ZGT6 is used as a time reference for local time operation updating in design, and meanwhile, in order to ensure the accuracy of local time information in an offline state, a mechanism for interrupting updating second parameters and updating other time parameters by tasks is adopted in design, so that local time data is updated. In order to reduce the complexity of time setting calculation and increase the accuracy of time setting function realization, the design sets the counting period of the timer counter to 0.25us and sets the timing time of the timer to 1s, so that the steps of executing a time setting algorithm and updating the local time of a microprocessor can be reduced, the processing time is shortened to a certain extent, and the processing efficiency is improved. The design uses the PWM output function of Channel2 of TIM2 as 1PPS output of local time signal, and can make the 1PPS signal updated in time more accurate in combination with the configuration of the above. It should be noted that, in code implementation, restrictions need to be applied to all data according to the theoretical scope of data, so as to prevent system breakdown caused by using erroneous data. When the local time updating function is realized, firstly, at the initialization, the TIM2 is started, the related interrupt is enabled, the local time is loaded with an initialization time, the second overflow flag is set to be in a false state, meanwhile, the PWM channel of the TIM2 starts to output a 1PPS signal of a first period according to the count value of a timer, when the system formally operates, because the microprocessor automatically enters the TIM2 interrupt when the timer reaches 1s every time, the second parameter is automatically increased in the interrupt, if the second parameter overflows, the second overflow flag bit is set to be in a true state, meanwhile, the PWM channel of the TIM2 updates and outputs the 1PPS signal of the next period, when the second overflow flag bit is detected to be in a true state during the operation of a foreground task, other time parameters are calculated and refreshed, and the second overflow flag bit is set to be in false again, and the next second overflow updating is waited. The update of the local time and the output of the local time 1PPS signal are realized through the workflow.
Secondly, aiming at the realization of the LORA radio receiving and transmitting processing function, the design uses the USART3 of STM32F407ZGT6 as a data receiving and transmitting interface of the LORA radio communication module, adopts the PA15 of STM32F407ZGT6 as an AUX signal receiving and processing interface of the LORA radio communication module, configures baud rate 9600bps according to the LORA radio communication module, 8 data bits, has no check bit, configures relevant parameters of the USART3 in 1 end bit, starts the USART3 during initialization, starts relevant interruption, sets the state of the LORA radio communication module to be busy, waits for the AUX signal of the LORA radio communication module to be in a rising edge, namely, the module returns to an idle state, then sends a configuration message of the LORA radio communication module to configure the LORA radio communication module, at the moment, the AUX signal of the LORA radio communication module is in a falling edge, the AUX of the LORA radio communication module is in a busy state, the AUX of the LORA radio communication module is waited to be in a rising edge again, the idle state, the AUX of the LORA radio communication module is represented, the LORA radio communication module is configured, and the data can be completely received by sending the AUX to the LORA radio communication module through the ART 3. When the LORA radio communication module transmits data, the LORA radio communication module needs to wait for idle, and the last USART3 transmission is completed and is currently in an idle state, and then the data to be transmitted is transmitted to the LORA radio communication module through the USART3, i.e. the data transmission can be performed through the LORA radio communication module. When the LORA radio communication module receives, the AUX signal of the LORA radio communication module will have a falling edge, which marks that the module is receiving transmission, then waits for the AUX signal of the LORA radio communication module to have a rising edge, marks that the module is idle, but there may still be last frame data being transmitted at this time, so that it is necessary to wait for the USART3 idle interrupt to trigger and place a USART3 data receiving completion mark, marks that the LORA radio module finishes receiving data, stores the received data in the USART3 data receiving buffer, and finally reads the received data when the foreground task is running. After the initialization of the time service host is completed, a time service ready message is sent to the time service slave, then the time service host enters a time service waiting state, and the time service host waits for receiving a relevant time service request message sent by the time service slave and carries out corresponding processing. And the data receiving and transmitting processing function of the LORA radio module is realized.
And fourthly, aiming at the realization of the real-time refreshing and displaying local time function of the OLED, the design adopts IIC2 of STM32F407ZGT6 as a communication interface of the OLED display module, and performs initialization configuration on the OLED module according to an OLED data configuration manual issued by an OLED manufacturer, so that the OLED module has a better display effect, when in initialization, the hardware IIC function of the STM32F407ZGT6 is started, the local time information of the local time module is obtained, the relevant display information is displayed on the OLED display module through the IIC2 interface by adopting the 1608 font, and when the time display needs to be updated, the time information needing to be refreshed is sent to the OLED display module again through the IIC interface in a foreground task displayed in the local time, so that the real-time refreshing and displaying of the local time function of the OLED module is realized.
(3) Time synchronization
The local time and local date are synchronized with the local time and local date of the satellite positioning navigation system. Meanwhile, the microprocessor directly uses the received second pulse signal to update the count value of the local timer of the time service host in the service function of the external interrupt processing of the software operation platform, the second pulse signal of the local clock operation is automatically generated by the pulse signal modulation channel of the local timer, and when the count value of the local timer is updated, the phase of the updated local second pulse signal is synchronous with the second pulse signal of the satellite, thereby realizing the satellite time service function of the host equipment.
The synchronous error value of the second pulse signal generated by the local clock signal running at the local time of the time service host and the second pulse signal of the satellite signal receiving module is less than 400 microseconds, so that the satellite time service function of microsecond magnitude is realized, and the design requirement is completely met.
The high-precision time synchronization function is realized based on LORA radio communication modules mounted on the time service host computer and the time service slave computer, and the modules are used for carrying out wireless communication on the time service host computer and the time service slave computer.
When the time service slave operates the initialized local time, the time service host operates the local time after satellite time service, and errors exist between the two local times and the local date. When the timing host starts a PTP period, the timing host needs to send a Sync message to the LORA radio communication module of the timing slave through the LORA radio communication module in the first step. And sending a Follow Up message to the LORA radio communication module of the time service slave immediately after the message is sent, wherein the message contains accurate time stamp information of the moment when the Sync message leaves the time service host.
And secondly, the LORA radio communication module of the time service slave receives the Sync message and records the accurate time stamp information of the receiving time, and then reads and stores the accurate time stamp information of the sending time of the Sync message from the immediately received Follow Up message.
And thirdly, the time service slave machine sends a Delay Req message to the time service host machine through the LORA radio communication module. And step four, the time service host receives the Delay Req message sent by the time service slave and records the accurate time stamp information of the received message.
And fifthly, the time service host loads the accurate receiving time stamp information of the Delay Req message into the Delay Resp message and sends the information to the slave.
And sixthly, the slave receives the Delay Resp message and acquires the accurate receiving time stamp information of the Delay Resp message.
And seventhly, calculating through a high-precision time service protocol algorithm through all received time stamp information, obtaining a time difference, and updating and calibrating the local time and the local clock according to the time difference to realize the time synchronization function of the time service host computer and the time service slave computer. After time synchronization of the second pulse signals of the time service host and the time service slave, the signal error value is extremely fine, so that it can be deduced that the high-precision time synchronization algorithm realized in the embodiment can realize that the clock synchronization error between the distributed wireless communication systems is at least in microsecond level, and the design requirement is completely met.
In the system, STM32F407ZGT6 is used as a main control chip, a FreeRTOS operating system is carried as an application software operation platform, TIM2 is used as a local clock reference for a time service host and a time service slave, IIC2 communication of an OLED module and USART3 communication of a LORA radio communication module are simultaneously adopted, and the time service host is additionally carried with BD/GPS module to carry out communication by adopting USART 2. After the time service host receives satellite signals and completes local clock calibration, namely the satellite time service function is completed, then the time service slave and the time service host carry out multiple handshake communication, relevant parameters of a time synchronization algorithm in a PTP protocol are obtained, corresponding algorithm calculation is carried out, and after filtering operation is carried out on a calculation result, the calculation result is used for calibrating local time and a local clock. By refreshing the display with local time on the fly during the completion of all of the above functions. The whole radio time synchronization system based on satellite time service is realized through the above flow.
Then, the radio time synchronization system based on satellite time service realizes the satellite time service function, and the measurement can be obtained after the system is realized, and the satellite time service precision of a time service host of the radio time service system based on satellite time service is better than 400 microseconds; meanwhile, the time synchronization function of the time service host and the time service slave is realized, the time service host and the time service slave can be obtained through measurement after the system is realized, and the clock synchronization precision of the time service host and the time service slave is also better than 50 microseconds; finally, the display accuracy of the radio time synchronization system based on satellite time service is within 400 microseconds after the system is realized and is obtained through software measurement.
The distributed sensor network is time-stamped based on a satellite time stamping technology, namely a radio communication system based on satellite time stamping is realized, the local time of a UTC time and date information updating receiver is received, analyzed and extracted through a satellite signal receiver, and then the local time and date information of the satellite signal receiver is synchronized to other node equipment through a LORA radio communication module, so that the time synchronization of the wireless communication network is realized.
The technical features of the above embodiments may be arbitrarily combined, and all possible combinations of the technical features in the above embodiments are not described for brevity of description, however, as long as there is no contradiction between the combinations of the technical features, they should be considered as the scope of the description.
The above examples merely represent a few embodiments of the present application, which are described in more detail and are not to be construed as limiting the scope of the invention. It should be noted that it would be apparent to those skilled in the art that various modifications and improvements could be made without departing from the spirit of the present application, which would be within the scope of the present application. Accordingly, the scope of protection of the present application shall be subject to the appended claims.

Claims (10)

1. A method for synchronizing time of a master clock and a slave clock based on wireless communication, the method comprising:
the time service host receives satellite system messages and standard second pulse signals through a BD/GPS satellite signal receiving module and calibrates local time and a local clock;
and the time synchronization of the primary clock and the secondary clock is realized through LORA wireless communication mode between the time service host and the time service slave after satellite time service.
2. The method according to claim 1, wherein the method further comprises:
and comparing the standard second pulse signal output by the calibrated time service host with the standard second pulse signal received by the BD/GPS satellite signal receiving module to obtain the time service clock error of the calibrated time service host and the BD/GPS satellite signal receiving module.
3. The method of claim 1, wherein the master time synchronization and the slave time synchronization after satellite time service are realized by a LORA wireless communication mode, and the method comprises the following steps:
the time service host computer and the time service slave computer after satellite time service carry out message interaction by adopting a PTP protocol in a LORA wireless communication mode, and the time service slave computer acquires parameters of a time synchronization algorithm in the PTP protocol;
calculating a time error value and a clock error value between the time service host and the time service slave by adopting the time synchronization algorithm according to the parameters in the time service slave;
and calibrating the local time and the local clock of the time service slave according to the time error value and the clock error value corresponding to the time service slave, and completing the time synchronization of the master clock and the slave clock.
4. The method of claim 3, wherein the time service host computer and the time service slave computer after satellite time service perform message interaction by using a PTP protocol in a LORA wireless communication mode, and the time service slave computer acquires parameters of a time synchronization algorithm in the PTP protocol, including:
time service host computer:
when receiving the date request message sent by the time service slave machine, acquiring local date information of the local machine and sending a host date message to the time service slave machine,
After receiving a request time message of a time service slave, recording the time T2 when the message is received, acquiring the local time of the local machine, sending the time message to the time service slave, and recording the time T3 when the time message is finished to be sent;
after receiving a request time message transmission completion time message of the time service slave, transmitting a time T2 timestamp of the local record to the time service slave;
after receiving a request T3 message of the time service slave machine, sending a T3 timestamp of the local record to the time service slave machine;
time service slave machine:
sending a host date request message to the time service host to acquire current date data of the time service host;
when a host date message sent by a time service host is received, acquiring the date information of the time service host from the host date message, and directly updating the local date of the time service slave;
sending a time request message to a time service host, and recording the time T1 when the message is sent;
after receiving a time message sent by a time service host, recording the time T4 of the received time message, directly acquiring time information of the time service host in the time message, and updating the local time of the time service slave by adopting the acquired time information of the time service host;
Sending the request time message and the sending completion time message to a time service host;
after receiving the T2 timestamp message, reading the T2 timestamp and storing the T2 timestamp to a local place;
sending the request T3 message to a time service host;
after receiving the T3 time stamp message, reading the T3 time stamp and storing the T3 time stamp to the local.
5. The method of claim 1, wherein the parameters include: the time service host sends a request time message accurate time stamp, the time service slave receives the request time message accurate time stamp, the time service slave sends a Delay Req message accurate time stamp, and the time service host receives the Delay Req message accurate time stamp;
calculating a time error value and a clock error value between the time service host computer and the time service slave computer by adopting the time synchronization algorithm according to the parameters, wherein the method comprises the following steps:
according to the accurate time stamp of the request time message sent by the time service host, the accurate time stamp of the request time message received by the time service slave, the accurate time stamp of the Delay Req message sent by the time service slave, and the accurate time stamp of the Delay Req message received by the time service host, the time error value and the clock error value of the time service host and the time service slave are calculated by adopting a PTP time synchronization protocol algorithm.
6. A primary and secondary clock time synchronization system based on wireless communication, the system comprising: a time service host and a plurality of time service slaves; the master-slave clock time synchronization method based on wireless communication as claimed in claim 1 is adopted between each time service slave and the time service master.
7. The system of claim 6, wherein the timing host is configured to receive satellite system messages and standard second pulse signals through a BD/GPS satellite signal receiving module, calibrate local time and local clocks, and then perform message interaction with each timing slave through a LORA radio communication module by using PTP protocol;
the time service slave is used for carrying out message interaction with the time service host by adopting a PTP protocol through the LORA radio communication module to acquire parameters of a time synchronization algorithm in the PTP protocol; calculating a time error value and a clock error value between the time service host computer and the time service slave computer by adopting the time synchronization algorithm according to the parameters; and calibrating the local time and the local clock according to the time error value and the clock error value, so as to realize time synchronization of the primary clock and the secondary clock.
8. The system of claim 6, wherein the timing host comprises: the system comprises a main control module, a BD/GPS satellite signal receiving module, a LORA radio communication module and an OLED real-time display module; the hardware structure of the time service slave machine is the same as that of the time service host machine;
the main control module comprises an ARM microcontroller, the ARM microcontroller is communicated with the BD/GPS satellite signal receiving module through a second serial port, and the ARM microcontroller is communicated with the LORA radio communication module through a third serial port; the ARM microcontroller is connected with the OLED real-time display module through an IIC2 interface; the timer TIM2 of the ARM microcontroller outputs a local standard second pulse signal serving as an updating time reference in a PWM mode, and a mechanism for updating second parameters by interruption and other time parameters by tasks is adopted to update the local time;
the BD/GPS satellite signal receiving module is used for receiving and processing a positioning time-giving message and a standard second pulse signal of a BD/GPS satellite system under the control of the main control module, and feeding back the received message and the standard second pulse signal to the ARM microcontroller;
the LORA radio communication module is used for carrying out message interaction with the time service slave machine by adopting a PTP protocol under the control of the main control module and feeding back interaction communication message data to the main control module;
The main control module is used for analyzing, checking and extracting the standard universal time UTC time contained in the received positioning time-giving message of the BD/GPS satellite system, calibrating the local time and the local clock to realize satellite time-giving, and transmitting the local time to the OLED real-time display module; the method is also used for analyzing the message data fed back by the LORA radio communication module and acquiring parameters required by a time synchronization algorithm in the PTP protocol;
the OLED real-time display module is used for refreshing and displaying the local time in real time.
9. The system of claim 8 wherein said ARM microcontroller is an STM32F407ZGT6 microcontroller unit;
the mechanism for updating the second parameter and other time parameters of the task by adopting the interrupt is adopted to update the local time, which comprises the following steps:
initializing the ARM microcontroller, starting a timer TIM2, enabling related interruption, loading the local time for one initialization time, setting a second overflow flag to be in a false state, starting a PWM channel of the timer TIM2 to output a 1PPS signal of a first period according to the count value of the timer TIM2, automatically entering the timer TIM2 interruption by a microprocessor when the timer TIM2 is timed to 1s each time when the system formally operates, automatically increasing a second parameter in the interruption, setting a second overflow flag bit to be in a true state if the second parameter overflows, updating and outputting a 1 signal of the next period by the PWM channel of the timer TIM2, calculating and refreshing other time parameters when the second overflow flag bit is detected to be true when the foreground task operates, and resetting the second overflow flag bit to be in false state to wait for next second overflow update.
10. The system according to claim 8, wherein the master-slave clock time synchronization of the system is realized based on a LORA radio communication module carried on a time service master and a time service slave; the process of the time synchronization of the primary clock and the secondary clock comprises the following steps:
when the timing host starts a PTP period, the timing host sends a Sync message to the LORA radio communication module of the timing slave through the LORA radio communication module; after the Sync message is sent, a Follow Up message is sent to the LORA radio communication module of the time service slave; the Follow Up message contains accurate time stamp information of the moment when the Sync message leaves the time service host;
the LORA radio communication module of the time service slave receives the Sync message and records the accurate time stamp information of the receiving time, and then reads and stores the accurate time stamp information of the sending time of the Sync message from the received Follow Up message;
the time service slave machine sends a Delay Req message to the time service host machine through a LORA radio communication module of the time service slave machine;
the time service host receives the Delay Req message sent by the time service slave and records accurate time stamp information of the received Delay Req message;
The time service host loads the accurate receiving time stamp information of the Delay Req message into a Delay Resp message and sends the Delay Resp message to the time service slave;
the time service slave receives the Delay Resp message and acquires the accurate receiving time stamp information of the Delay Resp message from the Delay Resp message;
the time service slave machine calculates by adopting a time synchronization algorithm in a PTP protocol according to accurate time stamp information of the Sync message at the moment when the Sync message leaves the time service host machine, accurate time stamp information of the Sync message at the moment when the Sync message is sent, accurate time stamp information of the Delay Req message and accurate receiving time stamp information of the Delay Resp message, so as to obtain a time error value and a clock error value of the time service host machine and the time service slave machine, and then updates and calibrates the local time and the local clock of the time service slave machine according to the time error value and the clock error value, thereby realizing the time synchronization of the primary clock and the secondary clock.
CN202311520703.2A 2023-11-14 2023-11-14 Primary and secondary clock time synchronization method and system based on wireless communication Pending CN117320144A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311520703.2A CN117320144A (en) 2023-11-14 2023-11-14 Primary and secondary clock time synchronization method and system based on wireless communication

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311520703.2A CN117320144A (en) 2023-11-14 2023-11-14 Primary and secondary clock time synchronization method and system based on wireless communication

Publications (1)

Publication Number Publication Date
CN117320144A true CN117320144A (en) 2023-12-29

Family

ID=89255428

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311520703.2A Pending CN117320144A (en) 2023-11-14 2023-11-14 Primary and secondary clock time synchronization method and system based on wireless communication

Country Status (1)

Country Link
CN (1) CN117320144A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN118019099A (en) * 2024-04-08 2024-05-10 福州马尾区金桐科技有限公司 Wireless time synchronization method for improving precision

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN118019099A (en) * 2024-04-08 2024-05-10 福州马尾区金桐科技有限公司 Wireless time synchronization method for improving precision
CN118019099B (en) * 2024-04-08 2024-06-04 福州马尾区金桐科技有限公司 Wireless time synchronization method for improving precision

Similar Documents

Publication Publication Date Title
CN110493744B (en) Data synchronous acquisition method and system of master-slave wireless sensor
EP2469765B1 (en) Method and system for implementing time synchronization in local area network (lan)
CN102244572B (en) A kind of method and device for realizing that clock is synchronous
CN102546071B (en) Clock synchronization method and system
CN100581164C (en) Accurate time synchronization method and system facing measurement and control
CN108650051B (en) The clock synchronization apparatus and method of general devices at full hardware single step 1588
CN104836630B (en) IEEE1588 clock synchronization system and implementation method therefor
US11177896B2 (en) Time synchronization device and time synchronization method
EP1624361B1 (en) Device in a modularized system for effecting time-stamping of events/reference events
CN103563287B (en) Synchronization device and synchronization method
CN109996325B (en) Clock synchronization system and method of wireless sensor network
CN110100408B (en) Method for interacting time synchronization message and network device
CN117320144A (en) Primary and secondary clock time synchronization method and system based on wireless communication
JP2018534686A (en) Apparatus and method for synchronizing controllers and sensors
CN110740227B (en) Camera time synchronization device and method based on GNSS time service and image display information coding mode
CN101771487A (en) Equipment for network time service precision detection and detection method using the detection equipment
CN110928176B (en) Multifunctional time service equipment supporting multiple time service technologies
CN112821974B (en) High-precision time synchronization method and device for vehicle-mounted ECU
US20220006548A1 (en) Method and system for controlling network timing precision of a seismic collector, and terminal device
WO2021077289A1 (en) Synchronization method and device
CN108738127B (en) Radio remote unit, baseband processing unit, distributed base station and synchronization method thereof
US20220269223A1 (en) Wireless time servicing method, device, and system
Wobschall et al. Synchronization of wireless sensor networks using a modified IEEE 1588 protocol
CN110198198B (en) Road side unit synchronization method, device, processor and road side unit
US20220360350A1 (en) Method and apparatus for acquiring timestamp of data stream, storage medium, and electronic apparatus

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination