CN117675072A - Synchronization time determining method, time synchronization device, time synchronization system and medium - Google Patents

Synchronization time determining method, time synchronization device, time synchronization system and medium Download PDF

Info

Publication number
CN117675072A
CN117675072A CN202311556766.3A CN202311556766A CN117675072A CN 117675072 A CN117675072 A CN 117675072A CN 202311556766 A CN202311556766 A CN 202311556766A CN 117675072 A CN117675072 A CN 117675072A
Authority
CN
China
Prior art keywords
time
clock source
current
timer
synchronization
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
CN202311556766.3A
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.)
Shenzhen Mos Information Co ltd
Original Assignee
Shenzhen Mos Information 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 Shenzhen Mos Information Co ltd filed Critical Shenzhen Mos Information Co ltd
Priority to CN202311556766.3A priority Critical patent/CN117675072A/en
Publication of CN117675072A publication Critical patent/CN117675072A/en
Pending legal-status Critical Current

Links

Landscapes

  • Synchronisation In Digital Transmission Systems (AREA)

Abstract

The application relates to a synchronous time determining method, a time synchronizing device, a time synchronizing system and a storage medium of an adaptive external clock source, comprising the following steps: configuring reference counting frequency and overflow value of a timer of a local clock source, and setting the timer to reset and count when determining that a synchronous pulse signal of an external clock source is received or when counting overflows; receiving a current synchronous pulse signal of an external clock source; when the current synchronous pulse signal is invalid, the last counting frequency and the last time error of a timer of a local clock source are obtained; acquiring the local time and the current count value of the current reset record of the timer of the local clock source; and determining the synchronous time according to the last counting frequency of the timer, the last time error, the local time of the current reset record and the current counting value. The method can calibrate the synchronous time when the external clock source has abnormal conditions such as time jitter and the like, so as to avoid the phenomena such as time jitter, time rollback and the like of the clock source of the system.

Description

Synchronization time determining method, time synchronization device, time synchronization system and medium
Technical Field
The present invention relates to the field of time synchronization processing technologies, and in particular, to a method for determining synchronization time of an adaptive external clock source, a time synchronization device, a time synchronization system, and a storage medium.
Background
Global satellite navigation systems (GNSS) are currently generally used internationally as external clock sources to provide a unified time reference for each system. The GNSS time synchronization technology is a technology for realizing time synchronization among systems by respectively receiving satellite signals, and the systems rely on second pulse signals and corresponding time stamps to obtain uniform time with nanosecond precision. However, GNSS signals are greatly affected by the environment, and in the situations of shielding, electromagnetic interference, indoor satellite signals and the like, the quality of the satellite signals is reduced or interrupted to cause the phenomena of time jitter, time rollback and the like of a clock source of the system, so that the data of each device in the system are caused to have the conditions of corresponding time stamp discontinuity, time rollback and the like.
Disclosure of Invention
In view of the foregoing, it is desirable to provide a method, a time synchronization device, a time synchronization system, and a storage medium for determining synchronization time of an adaptive external clock source, which can calibrate synchronization time when an abnormal situation such as time jitter occurs in the external clock source, so as to avoid phenomena such as time jitter and time rollback occurring in the clock source of the system.
A method for determining synchronization time of an adaptive external clock source, comprising: configuring reference counting frequency and overflow value of a timer of a local clock source, and setting the timer to reset and count when determining that a synchronous pulse signal of an external clock source is received or when counting overflows; receiving a current synchronous pulse signal of an external clock source; when the current synchronous pulse signal is invalid, acquiring the last counting frequency of a timer of the local clock source, wherein the last counting frequency is determined based on the count value of the timer when the valid synchronous pulse signal is received last time and the synchronous pulse period of the external clock source; acquiring a last time error of a local clock source, wherein the last time error is determined based on a difference value between the external time of the external clock source and the local time of the local clock source when a valid synchronous pulse signal is received last time; acquiring the local time and the current count value of the current reset record of the timer of the local clock source; and determining the synchronous time according to the last counting frequency of the timer, the last time error, the local time of the current reset record and the current counting value.
In one embodiment, a method for determining synchronization time of an adaptive external clock source further includes: acquiring a current count value of a current reset record of the timer and a last count value of the timer; if the difference value between the current count value and the last count value is larger than the set value, determining that the current synchronous pulse signal is invalid; and if the difference value between the current count value and the last count value is smaller than or equal to the set value, determining that the current synchronous pulse signal is valid.
In one embodiment, a method for determining synchronization time of an adaptive external clock source further includes: and when the current synchronous pulse signal is valid, determining the current counting frequency according to the current counting value and the synchronous pulse period of the external clock source.
In one embodiment, determining the current count frequency from the current count value and the synchronization pulse period of the external clock source includes: and determining the current counting frequency according to the ratio of the current counting value to the synchronous pulse period of the external clock source.
In one embodiment, a method for determining synchronization time of an adaptive external clock source further includes: when the current synchronous pulse signal is valid, acquiring the external time of an external clock source and the local time of a local clock source; and determining the current time error according to the acquired difference value between the external time of the external clock source and the local time of the local clock source.
In one embodiment, determining the synchronization time according to the last count frequency of the timer, the last time error, the local time of the current reset record, and the current count value of the timer includes: acquiring the ratio of the current count value of the timer to the last count frequency of the timer; obtaining the product value of the ratio and the last time error; and determining the synchronous time according to the local time, the ratio and the product value of the current reset record.
In one embodiment, determining the synchronization time based on the local time, the ratio, and the product value of the current reset record includes: and determining the synchronous time according to the local time, the sum of the ratio and the product value of the current reset record.
In one embodiment, a method for determining synchronization time of an adaptive external clock source further includes: when the current synchronous pulse signal is valid, acquiring the external time of an external clock source; the external time of the external clock source is taken as the synchronization time.
In one embodiment, the overflow value of the timer is greater than an integer number of seconds of the synchronization pulse signal interval of the external clock source.
In one embodiment, the external clock source is a global satellite navigation system, the synchronization pulse signal of the external clock source is a second pulse signal output by the global satellite navigation system, and the external time of the external clock source is the whole second time output by the global satellite navigation system.
In one embodiment, after the step of determining the synchronization time according to the last count frequency of the timer, the last time error, the local time of the current reset record, and the current count value, the method further includes: if the received synchronous pulse signals are invalid, acquiring the average value of a plurality of historical counting frequencies, wherein each historical counting frequency is determined based on the count value of a timer and the synchronous pulse period of an external clock source when each valid synchronous pulse signal is received in a historical manner, and updating the reference counting frequency of the timer based on the average value of the plurality of historical counting frequencies; and determining the synchronous time according to the updated reference counting frequency of the timer, the local time recorded by resetting the timer again and the counted value of the timer again until receiving a valid synchronous pulse signal.
In one embodiment, a method for determining synchronization time of an adaptive external clock source further includes: receiving a first pulse signal output by an incremental encoder; if the first pulse signal is the first pulse signal, carrying out accumulated count on a plurality of first pulse signals output by an incremental encoder, determining current absolute time based on synchronous time when reading the counted value of the accumulated count, and carrying out timestamp marking on the read counted value by using the current absolute time; if the first pulse signal is the second pulse signal, accumulating and counting a plurality of second pulse signals output by the incremental encoder, determining the current absolute time based on the synchronous time when the counted value of the accumulated and counted number is read, and performing time stamping on the read counted value by using the current absolute time; wherein, the phase difference of the first pulse signal and the second pulse signal is 90 degrees.
In one embodiment, a method for determining synchronization time of an adaptive external clock source further includes: determining a third current absolute time based on the synchronization time when the sampling pulse of the pulse sensor is captured through the input capture channel; if the sampling data of the pulse sensor are received, after the completion of the reception of the sampling data is confirmed, adding a third current absolute time into a data packet of the sampling data; and if the sampling data of the pulse sensor are not received, the third current absolute time is associated with the pulse sensor and then output.
In one embodiment, a method for determining synchronization time of an adaptive external clock source further includes: when the current synchronous pulse signal is valid, sending the external time of an external clock source to the second pulse self-synchronous sensor; when the current synchronous pulse signal is invalid, sending synchronous time to the second pulse self-synchronous sensor; the external clock source is a global satellite navigation system, the synchronous pulse signal of the external clock source is a second pulse signal output by the global satellite navigation system, and the external time of the external clock source is the whole second time output by the global satellite navigation system.
In one embodiment, a method for determining synchronization time of an adaptive external clock source further includes: the time synchronization protocol based sensor sends a synchronization time to the time synchronization protocol enabled sensor such that the time synchronization protocol enabled sensor performs time stamp synchronization of the data packet based on the synchronization time.
The time synchronization device comprises a local clock source, wherein the local clock source is an MCU clock, the MCU clock is provided with a timer and a temperature compensation crystal oscillator, and the clock frequency of the peripheral of the timer is provided by the temperature compensation crystal oscillator; the MCU clock is further configured with a processor, a memory and an embedded program stored on the memory and executable on the processor, the processor implementing the steps of any of the methods of the above embodiments when executing the embedded program.
A readable storage medium having stored thereon an embedded program which, when executed by a processor, performs the steps of the method of any of the above embodiments.
The time synchronization system of the self-adaptive external clock source comprises the time synchronization device of the embodiment, further comprises one or more sensors, and the time synchronization device sends synchronization time to the one or more sensors; wherein the one or more sensors include one or more of an incremental encoder, a pulse sensor, a self-synchronizing pulse-second sensor, and a sensor supporting a time synchronization protocol.
The self-adaptive external clock source synchronous time determining method, the time synchronizing device, the time synchronizing system and the storage medium are used for configuring the reference counting frequency and the overflow value of the timer of the local clock source, and setting the timer to reset and count when the timer determines that the synchronous pulse signal of the external clock source is received or when the count overflows; receiving a current synchronous pulse signal of an external clock source; when the current synchronous pulse signal is invalid, acquiring the last counting frequency of a timer of the local clock source, wherein the last counting frequency is determined based on the count value of the timer when the valid synchronous pulse signal is received last time and the synchronous pulse period of the external clock source; acquiring a last time error of a local clock source, wherein the last time error is determined based on a difference value between the external time of the external clock source and the local time of the local clock source when a valid synchronous pulse signal is received last time; acquiring the local time and the current count value of the current reset record of the timer of the local clock source; and determining the synchronous time according to the last counting frequency of the timer, the last time error, the local time of the current reset record and the current counting value.
Therefore, the time stability of the external clock source is judged by detecting the validity of the synchronous pulse of the external clock source received at each moment, when the invalidation of the current synchronous pulse signal, namely the time abnormality of the external clock source is detected, the synchronous time is determined based on the last counting frequency of the timer of the local clock source, the last time error, the local time recorded by the current reset and the current counting value, so that the synchronous time of the self-adaptive external clock source is realized, the accuracy of the synchronous time of the system is ensured, and the situations that the corresponding time stamp is discontinuous, the time rollback is generated due to the instability of the external clock source in the data of each device in the system are avoided.
Drawings
FIG. 1 is a block diagram of a time synchronization system of an adaptive external clock source in one embodiment;
FIG. 2 is a block diagram of an adaptive external clock source time synchronization device in one embodiment;
FIG. 3 is a schematic diagram of an application environment of a time synchronization device of an adaptive external clock source in one embodiment;
FIG. 4 is a flow chart of a method for determining synchronization time of an adaptive external clock source according to one embodiment;
FIG. 5 is a timing diagram of PPS pulse signals and full second time output by a GNSS clock source in one embodiment;
FIG. 6 is a diagram illustrating the relationship between the count of the timer and the PPS signal of the GNSS clock source in one embodiment;
FIG. 7 is a schematic diagram of synchronous time stamping of pulse signals output by an incremental encoder in one embodiment;
FIG. 8 is a schematic diagram of synchronous time stamping of sampled data output by a pulse sensor in one 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 application provides a time synchronization system of an adaptive external clock source. In one embodiment, as shown in fig. 1, a time synchronization system of an adaptive external clock source includes a time synchronization device of the adaptive external clock source, and further includes one or more sensors, and the time synchronization device transmits a synchronization time to the one or more sensors; wherein the one or more sensors include one or more of an incremental encoder, a pulse sensor, a self-synchronizing pulse-second sensor, and a sensor supporting a time synchronization protocol.
In an example, the time synchronization device of the adaptive external clock source includes a local clock source, where the local clock source is an MCU clock. MCU: microcontroller Unit, a micro control unit, also called a single chip microcomputer or a single chip microcomputer. As shown in fig. 2, the MCU clock is configured with a timer and a temperature compensation crystal oscillator, and the clock frequency of the timer is provided by the temperature compensation crystal oscillator; the MCU clock is also provided with a processor, a memory and an embedded program which is stored in the memory and can run on the processor, and the processor realizes the synchronous time determining method of the self-adaptive external clock source when executing the embedded program. The temperature compensated crystal oscillator provides a unified clock source for the synchronous clock device through the processor as shown in fig. 2.
Specifically, the time synchronization device is shown in fig. 3. The external clock source is a GNSS (global satellite navigation system) clock source. The accurate time source is provided for the time synchronization device by using the time information of a second pulse signal (PPS, the time interval between every two PPS is theoretically 1 second) output by the GNSS clock source, a hardware timer inside the MCU is adopted in the time synchronization device to maintain the local time, and the clock frequency of the timer peripheral is provided by a high-precision temperature compensation crystal oscillator of the MCU for realizing high-precision timing. Meanwhile, the GNSS time is measured continuously, and the effectiveness of the GNSS time is judged. When the GNSS time is effective, the local time is corrected by taking the GNSS time as a reference, and when the GNSS time has fluctuation or is ineffective, the corrected local time at the last moment of the system is used for maintaining. The corrected time is a synchronization time for maintaining 1588 synchronized master clocks and providing a stable synchronization clock source for external sensors.
The clock source adaptive switching of the time synchronization device is specifically: the clock source adaptive switching is to use the GNSS time as the clock source of the time synchronization device when the PPS signal of the GNSS is stable, and to provide an accurate time source for the system and the external sensor, and to switch to use the MCU internal clock to provide an accurate time source when the PPS signal is unstable, the MCU internal clock is operated at the counting frequency of the previous PPS signal stable time until the PPS signal is switched back to the GNSS clock source after the PPS signal is recovered to be normal, which can be specifically referred to as the following specific description of the synchronization time determination method of the adaptive external clock source.
The time synchronization device of the self-adaptive external clock source and the time synchronization system thereof can be applied to automatic driving, mobile mapping and other application scenes needing multi-sensor or multi-system cooperative work. Because the clock systems of the sensors or devices of different types and models are independent, and the data output delay, the data frame rate, the data length and the like are quite different, the organization, the processing and the coordination of various data are required to depend on a unified synchronization time. And the unified synchronization time is used as a reference to synchronize the sensors or the devices, and the data with the time stamp is output according to the synchronized time sequence, so that the complexity of subsequent matching, cooperation and other works is greatly reduced. The time synchronization device of the self-adaptive external clock source and the time synchronization system thereof can improve the precision of the synchronization time as much as possible, and are beneficial to improving the data precision of each sensor or equipment or the coordination degree of the system operation.
In one embodiment, as shown in fig. 4, a method for determining synchronization time of an adaptive external clock source is provided, and the method is applied to the MCU clock in fig. 2 for illustration, and includes the following steps:
s402, configuring the reference counting frequency and the overflow value of a timer of the local clock source, and setting the timer to perform reset counting when the synchronous pulse signal of the external clock source is received or when the count overflows.
In this embodiment, the reference count frequency of the timer of the local clock source refers to the count value of the timer in the period, and is used to generate the local time of the local clock source. When the count value of the overflow designating timer reaches a set specific value, an interrupt processing program of the microcontroller is triggered, and the count is restarted from zero. The overflow value of the timer of the local clock source is the count threshold of the timer. I.e. the timer counts up to the overflow value. Further, a timer is configured to perform reset counting upon determining that a synchronization pulse signal of an external clock source is received or upon count overflow. That is, upon receiving the synchronization pulse signal of the external clock source, the timer performs a reset operation, and recounts. Or when the count of the timer reaches the overflow value, counting overflow is carried out, reset operation is carried out, and counting is carried out again. In one example, the overflow value of the timer is greater than an integer number of seconds of the synchronization pulse signal interval of the external clock source.
Specifically, the external clock source is a GNSS clock source, and the synchronization pulse signal is a PPS pulse signal. The counting frequency of the 32-bit timer of the MCU clock in the time synchronization device of the self-adaptive external clock source is set to be 90M, and then the reference counting frequency of the timer is also set to be 90M by default, namely the resolution of the counting is 1/90M per second, which means that each counting represents 11.1 nanoseconds. Setting the overflow value to 180M, the theoretical timer overflow time is 2 seconds, namely 180M counts are counted. The timer is set to reset the count value after the arrival or the overflow of the synchronous pulse signal of the external clock source is effectively received, so that the count value before the count reset of the timer should be 90M in theory each time when the synchronous pulse signal of the external clock source is received, but in practice, the actual count of the timer may exceed or be less than 90M when the synchronous pulse signal of the external clock source is received due to errors of a system crystal oscillator and the like, and the count error is the clock error of the device.
S404, receiving the current synchronous pulse signal of the external clock source.
In this embodiment, after the timer of the local clock source is configured, the system configured with the MCU clock starts to receive the synchronization pulse signal of the external clock source. In general, the synchronization pulse signal of the external clock source is an active signal, but in case of interference, the synchronization pulse signal of the external clock source is an inactive signal. And taking the synchronous pulse signal received at the current moment as the current synchronous pulse signal of the external clock source.
S406, when the current synchronous pulse signal is invalid, the last counting frequency of the timer of the local clock source is acquired, and the last counting frequency is determined based on the count value of the timer when the valid synchronous pulse signal is received last time and the synchronous pulse period of the external clock source.
In this embodiment, validity judgment is performed on the current synchronization pulse signal. When the current synchronization pulse signal is invalid, the self-adaptive external clock source is required to adjust the synchronization time. Specifically, the last count frequency of the timer of the local clock source is acquired. The last count frequency refers to a count frequency calculated based on the count value of the timer and the synchronization pulse period of the external clock source when the valid synchronization pulse signal is received last time.
In one example, before or after the step S406, the method further includes: when the current synchronous pulse signal is valid, acquiring the external time of an external clock source; the external time of the external clock source is taken as the synchronization time.
In this example, when the current synchronization pulse signal is valid, the time signal of the external clock source is explained to be stable. Thus, the external time of the external clock source can be used as the synchronization time. The external clock source is a global satellite navigation system, the synchronous pulse signal of the external clock source is a second pulse signal output by the global satellite navigation system, and the external time of the external clock source is the whole second time output by the global satellite navigation system.
Specifically, the external time of the external clock source is the whole second time information output by the GNSS clock source. The PPS pulse signal and whole second time information output by the GNSS clock source are respectively introduced into an external input interrupt and a UART interface of the time synchronization device. The input interrupt detects the front edge of the PPS pulse signal, representing the whole second time of the GNSS clock source, and a time packet is sent after each PPS pulse, including the actual time corresponding to the previous PPS, where the time format of the packet may be UTC, unix, or seconds in the week, and the timing is shown in fig. 5.
S408, the last time error of the local clock source is obtained, and the last time error is determined based on the difference value between the external time of the external clock source and the local time of the local clock source when the valid synchronous pulse signal is received last time.
In this embodiment, the last time error of the local clock source is based on the difference between the external time of the external clock source and the local time of the local clock source when the valid synchronization pulse signal is received last time. For example, when a global satellite navigation system is used as an external clock source to provide a uniform time reference for each sensor or system, the external time of the external clock source refers to the entire second of time output by the GNSS clock source. The local time of the local clock source refers to the time determined by the timer of the local clock source.
S410, acquiring the local time and the current count value of the current reset record of the timer of the local clock source.
In this embodiment, when the current synchronization pulse signal is invalid, an overflow interrupt occurs when the timer count reaches an overflow value, and the count is reset. The timer outputs the local time of the current reset record and the current count value. For example, a global satellite navigation system is adopted as an external clock source, and a synchronous pulse signal of the external clock source is a second pulse signal output by the GNSS clock source. The relationship of the count of the timer to the PPS signal of the GNSS clock source is shown in fig. 6.
As shown in fig. 6, cnt_t (overflow) represents the count of the timer at the time of timer overflow interrupt. cnt_t (0) represents the count of the timer at time 0. cnt_t (1) represents the count of the timer at time 1. cnt_t (n) represents the count of the timer at time n, n being a positive integer. cnt_t (n+1) represents the count of the timer at time n+1. t (0) represents time 0. t (1) represents time 1. t (n) represents time n. t (n+1) represents time n+1. The GNSS pulse signal is PPS pulse signal. As shown in fig. 6, when the GNSS pulse signal is not valid, the timer overflows and outputs a count value and a local time.
S412, determining the synchronous time according to the last counting frequency of the timer, the last time error, the local time of the current reset record and the current counting value.
In this embodiment, since the current synchronization pulse signal is invalid, time synchronization cannot be performed using an external clock source. In this case, the synchronization time is determined by using the frequency of the last count of the timer and the last time error, in combination with the local time recorded by the current reset of the timer and the current count value.
In one example, determining the synchronization time based on the last count frequency of the timer, the last time error, the local time of the current reset record, and the current count value of the timer includes: acquiring the ratio of the current count value of the timer to the last count frequency of the timer; obtaining the product value of the ratio and the last time error; and determining the synchronous time according to the local time, the ratio and the product value of the current reset record.
The method for determining the synchronous time according to the local time, the ratio and the product value of the current reset record comprises the following steps: and determining the synchronous time according to the local time, the sum of the ratio and the product value of the current reset record.
Specifically, the synchronization time is calculated according to the following formula:
wherein t is n(modify) Representing the locally calibrated synchronization time referenced to an external clock source; t (T) (frequency) Representing the count frequency of the timer; t is t (timerstart) The local time recorded at each reset time of the timer is represented; cnt represents the count value of the timer; time of (err) Representing the time error. When the synchronous time is calculated by using the formula, T (frequency) Using the frequency, time of last count (err) Adopting the last time error, cnt adopts the count value when the current timer is reset, t (timerstart) The time recorded when the current timer was reset is used. Therefore, the local synchronous time can be determined at each moment through the counting frequency and the time error of the last moment and the local time and the counting value recorded by the timer at the current moment, so that the problem that the local synchronous time is abnormal due to the time abnormality of the external clock source at any moment is solved.
According to the self-adaptive external clock source synchronization time determining method, the time stability of the external clock source is judged by detecting the validity of the synchronization pulse of the external clock source received at each moment, when the fact that the current synchronization pulse signal is invalid is detected, namely the time of the external clock source is abnormal, the synchronization time is determined based on the last counting frequency of the timer of the local clock source, the last time error, the current reset recorded local time and the current counting value, so that the self-adaptive external clock source synchronization time is realized, the accuracy of the synchronization time of a system is ensured, and the situations that corresponding time stamp discontinuity, time rollback and the like occur in data of all equipment in the system due to instability of the external clock source are avoided.
In one embodiment, before the step S406, the method further includes: acquiring a current count value of a current reset record of the timer and a last count value of the timer; if the difference value between the current count value and the last count value is larger than the set value, determining that the current synchronous pulse signal is invalid; and if the difference value between the current count value and the last count value is smaller than or equal to the set value, determining that the current synchronous pulse signal is valid.
In this embodiment, the validity of the synchronization pulse is determined by the count value of the timer between adjacent synchronization pulses. Specifically, if the difference value between the current count value and the last count value is greater than a set value, determining that the current synchronous pulse signal is invalid; and if the difference value between the current count value and the last count value is smaller than or equal to the set value, determining that the current synchronous pulse signal is valid. For example, the synchronous pulse is a PPS pulse, the actual count value of a timer between the PPS pulses is obtained, if the difference value between the current count value and the last count value is less than or equal to 2 count values, the current PPS pulse is effective, and the GNSS signal is stable; if the difference between the current count value and the last count value exceeds 3 count values, the current PPS pulse is considered to be invalid, the GNSS signal shakes, and the instability of the PPS signal is indicated. Thus, the stability of the external clock source can be recognized by the count value of the timer.
In one example, the current count frequency is determined from the current count value and a synchronization pulse period of the external clock source when the current synchronization pulse signal is active. Wherein determining the current count frequency according to the current count value and the synchronization pulse period of the external clock source comprises: and determining the current counting frequency according to the ratio of the current counting value to the synchronous pulse period of the external clock source.
Specifically, when the current synchronization pulse signal is valid, the current count frequency is calculated by the following formula:
T1 (frequency) =cnt_t (n)/sync pulse period;
wherein T1 (frequency) Indicating the current count frequency, cnt_t is the current count value at the time of timer reset.
Therefore, when the current synchronization pulse signal is valid, the current count frequency is determined so that when the synchronization pulse signal is received next time, if the received synchronization pulse signal is invalid, the synchronization time when the next synchronization pulse signal is invalid can be calculated using the current count frequency.
In one example, when the current synchronization pulse signal is valid, an external time of the external clock source and a local time of the local clock source are acquired; and determining the current time error according to the acquired difference value between the external time of the external clock source and the local time of the local clock source.
For example, the local time may be grasped by the following calculation:
wherein t is (raw) Designating a local time corresponding to the timer count cnt, t (timerstart) Specifying the local time recorded at each reset time of the timer, T (frequency) The counting frequency of the timer is shown, namely, the number of timer counting in one second in practice is shown, and cnt designates the counting of the timer.
For example, the external clock source is a GNSS, the external time is a whole second time corresponding to the GNSS, and the synchronization pulse is a PPS pulse. After the PPS pulse signal is detected by external input interruption, the following operations are carried out:
(1) Obtaining PPS pulses to temporarily nick the local time: t is t (raw)
(2) Acquiring timer counts among PPS pulses, and if the PPS is stable, namely the deviation between the current count value and the last count value is less than or equal to 2 count values, setting the timerCounting frequency T (frequency) Updating to the actual measured count frequency;
(3) Resetting the count of the timer and updating the local time t timed by the timer (timerstart) =t (raw)
(4) Recording the whole second time t corresponding to the PPS pulse (n)
(5) Calculating the deviation between the local time and the GNSS time:
time (err) =t (n) -t (raw)
i.e. by the formula time (err) =t (n) -t (raw) And determining the time error of each moment, and determining the current time error. Therefore, when the time signal of the external clock source is stable, the time error between the local time and the external time can be calculated, and the synchronization time can be calculated using the time error calculated this time when the time signal of the external clock source is unstable next time.
In one embodiment, after the step of determining the synchronization time according to the last count frequency of the timer, the last time error, the local time of the current reset record, and the current count value, the method further includes: if the received synchronous pulse signals are invalid, acquiring the average value of a plurality of historical counting frequencies, wherein each historical counting frequency is determined based on the count value of a timer and the synchronous pulse period of an external clock source when each valid synchronous pulse signal is received in a historical manner, and updating the reference counting frequency of the timer based on the average value of the plurality of historical counting frequencies; and determining the synchronous time according to the updated reference counting frequency of the timer, the local time recorded by resetting the timer again and the counted value of the timer again until receiving a valid synchronous pulse signal.
In this embodiment, if the synchronization pulse signal received again later is also an invalid signal, the reference counting frequency of the timer is updated to be the average value of a plurality of historical counting frequencies, and the synchronization time is calculated according to the updated reference counting frequency, so as to avoid unstable local synchronization time in the system when the time signal of the external clock source is unstable for a long time.
For example, the external clock source is a GNSS clock source, and the synchronization pulse signal is a PPS pulse signal. The timer enters an overflow interrupt mode when the PPS pulse signal is unstable, and the following operations are performed:
(1) Recording time t recorded by timer when local timer overflows (raw)
(2) Resetting a timer;
(3) Updating the starting time t of timer counting in timer overflow interrupt (timerstart) =t (raw)
(4) Ignoring the bias between the local time and the GNSS time, updating the time (err) =0;
(5) Setting the counting frequency T of a timer (frequency) The average value of 3 seconds before the PPS pulse signal is abnormal, namely, the average value of 3 seconds before the PPS pulse signal is invalid, and the average value is kept unchanged until the synchronous pulse signal is judged to be normal.
In one embodiment, the step S312, that is, after determining the synchronization time according to the last count frequency of the timer, the last time error, the local time of the current reset record, and the current count value, further includes: receiving a first pulse signal output by an incremental encoder; if the first pulse signal is the first pulse signal, carrying out accumulated count on a plurality of first pulse signals output by an incremental encoder, determining current absolute time based on synchronous time when reading the counted value of the accumulated count, and carrying out timestamp marking on the read counted value by using the current absolute time; if the first pulse signal is the second pulse signal, accumulating and counting a plurality of second pulse signals output by the incremental encoder, determining the current absolute time based on the synchronous time when the counted value of the accumulated and counted number is read, and performing time stamping on the read counted value by using the current absolute time; wherein, the phase difference of the first pulse signal and the second pulse signal is 90 degrees.
In this embodiment, for the incremental encoder, after determining the synchronization time, time synchronization operations are performed for different types of sensors that are connected to the time synchronization device. For the incremental encoder, as shown in fig. 7, two paths of pulse signals with different phases are output, and the rotation direction can be indicated, the two paths of pulse signals are simultaneously connected to a timer interface which is additionally configured into an encoder mode in the time synchronization device, the pulses of the incremental encoder are counted in an accumulated manner, the initial value of the count is 0, and then the accumulated value is increased or decreased one by one according to the actual rotation direction of the incremental encoder. As shown in fig. 7, the first pulse signal is a phase a pulse, and the second pulse signal is a phase B pulse. If the phase of the A phase pulse advances, the count accumulation increases, if the phase of the B phase pulse advances, the count accumulation decreases, and the absolute time when the count value is read out is recorded to complete the time stamp synchronization of the incremental encoder when the count is cut off, namely, the shorter the output time interval is, namely, the shorter the interval of the count value is read out, and the higher the resolution is.
In one embodiment, the step S312, that is, after determining the synchronization time according to the last count frequency of the timer, the last time error, the local time of the current reset record, and the current count value, further includes: determining a third current absolute time based on the synchronization time when the sampling pulse of the pulse sensor is captured through the input capture channel; if the sampling data of the pulse sensor are received, after the completion of the reception of the sampling data is confirmed, adding a third current absolute time into a data packet of the sampling data; and if the sampling data of the pulse sensor are not received, the third current absolute time is associated with the pulse sensor and then output.
In this embodiment, after determining the synchronization time, time synchronization operations are performed for different types of sensors that are connected to the time synchronization device. Among them, for a pulse sensor, i.e., a sampling pulse+sampling data type sensor, this type sensor transmits/receives a sampling pulse while outputting sampling data at the sampling pulse timing. As shown in fig. 8, in order to calculate the pulse time more precisely, it is necessary to connect the pulse sensor sampling pulse to the input capturing channel of the time synchronizer, and the synchronizer will automatically capture the count value of the current time timer in the internal register of the time synchronizer when the sampling pulse arrives. After the sampling data is received, calculating the synchronous time corresponding to the sampling pulse through the captured timer data and adding the synchronous time into a data packet of the sampling data; for the sensor with only sampling pulse and no sampling data, the time synchronizing device directly outputs the time stamp of the sampling moment to complete the time stamp synchronization of the sampling pulse.
In one embodiment, the step S312, that is, after determining the synchronization time according to the last count frequency of the timer, the last time error, the local time of the current reset record, and the current count value, further includes: when the current synchronous pulse signal is valid, sending the external time of an external clock source to the second pulse self-synchronous sensor; when the current synchronous pulse signal is invalid, sending synchronous time to the second pulse self-synchronous sensor; the external clock source is a global satellite navigation system, the synchronous pulse signal of the external clock source is a second pulse signal output by the global satellite navigation system, and the external time of the external clock source is the whole second time output by the global satellite navigation system.
In this embodiment, after determining the synchronization time, time synchronization operations are performed for different types of sensors that are connected to the time synchronization device. For the self-synchronization sensor of the pulse per second type, the sensor of the type can be directly connected with the PPS signal and the receiving synchronization time of the GNSS for self time synchronization, but is influenced by possible signal instability and the like of the GNSS, and larger deviation exists between a clock system of the self-synchronization sensor of the pulse per second type and other sensors when the GNSS signal is lost. When the current synchronous pulse signal is valid, sending the external time of an external clock source to the second pulse self-synchronous sensor; when the current synchronization pulse signal is invalid, the synchronization time is sent to the second pulse self-synchronization sensor. Therefore, for abnormal conditions of GNSS signals, particularly for among multiple sensors under the condition of no GNSS, continuous, reliable and stable synchronization signals of the self-synchronization type sensor of the pulse per second are ensured.
In one embodiment, the step S312, that is, after determining the synchronization time according to the last count frequency of the timer, the last time error, the local time of the current reset record, and the current count value, further includes: the time synchronization protocol based sensor sends a synchronization time to the time synchronization protocol enabled sensor such that the time synchronization protocol enabled sensor performs time stamp synchronization of the data packet based on the synchronization time.
In this embodiment, after determining the synchronization time, time synchronization operations are performed for different types of sensors that are connected to the time synchronization device. For a sensor supporting a time synchronization protocol, such as a sensor supporting a network port PTP synchronization protocol, a stable PTP master clock is maintained depending on GNSS or internal synchronization time. In this embodiment, the synchronization time is sent to the sensor supporting the time synchronization protocol based on the time synchronization protocol, so that the sensor supporting the time synchronization protocol performs time stamp synchronization of the data packet based on the synchronization time, and the time synchronization protocol of PTP (Precision Time Protocol, IEEE 1588 precision time protocol) is implemented, so that the time stamp synchronization of the data packet can be implemented for the sensor supporting the PTP protocol, and it is ensured that the sensor supporting the time synchronization protocol and other sensors are located under the same clock system.
In summary, the method for determining the synchronization time of the adaptive external clock source, the time synchronization device, the time synchronization system and the storage medium have the following beneficial effects:
1. the overflow value of the timer is set to be larger than the integral seconds of the interval of the synchronous pulse signals of the external clock source, such as the integral seconds of the PPS pulse signals, so that the overflow interrupt of the timer can not be triggered when the GNSS signals are normal, the interrupt overhead is saved, the interrupt nesting problem of the PPS pulse signals and the timer is avoided, and the synchronization precision of the local clock and the GNSS clock is improved.
2. And judging whether the GNSS clock source is healthy and stable or not through PPS pulse period change, and adaptively switching a time system maintained by a clock circuit based on an internal high-precision temperature compensation crystal oscillator when the GNSS clock source is unstable, namely using the synchronization time obtained by local calculation. Under the condition of no GNSS signals in a room, a tunnel and the like, higher time precision can be continuously maintained, the condition that time jitter exists when GNSS calibration time is directly used is avoided, and the problem of GNSS signal interference or failure is solved to a certain extent.
3. A uniform fit is used for the existing bias of the local time to the full second time of the GNSS. Namely, the actual frequency and the theoretical frequency of the timer are subjected to proportional mapping processing, so that the problem of errors of the local clock frequency and the theoretical frequency is solved, and the continuity and the stability of a local time system and the synchronization precision of GNSS time are ensured. Through verification, the synchronization precision of the local time and the GNSS time can reach +/-200 ns.
4. The time synchronization device can add time stamps for the multipath sensors, and because the input capturing technology is adopted, each path of pulse trigger is independent and mutually noninterfere, compared with the common mode of adding time stamps in interruption, the precision is greatly improved. And, higher performance is achieved at lower cost.
5. The time synchronization device has various time synchronization modes such as adding time stamp, PTP network timing, PPS and UTC time timing, and the like, has high synchronization precision, can reach ns level through the synchronization precision of the test time synchronization device, and can meet the use scene of most of time synchronization precision requirement teaching high.
It should be understood that, although the steps in the flowchart 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 the figures may include multiple sub-steps or stages that are not necessarily performed at the same time, but may be performed at different times, nor does 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 other steps.
In one embodiment, a readable storage medium is provided, on which an embedded program is stored, which when executed by a processor, implements a method for determining synchronization time of an adaptive external clock source as described in any one of the above embodiments.
Those skilled in the art will appreciate that the implementation of all or part of the above-described methods may be implemented by means of embedded program instructions, which may be stored in a non-volatile computer-readable storage medium, and which when executed may comprise the steps of the above-described embodiments of the methods. Any reference to memory, storage, database, or other medium used in the various embodiments provided herein may include non-volatile and/or volatile memory. The nonvolatile memory can include Read Only Memory (ROM), programmable ROM (PROM), electrically Programmable ROM (EPROM), electrically Erasable Programmable ROM (EEPROM), or flash memory. Volatile memory can include Random Access Memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms such as Static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double Data Rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous Link DRAM (SLDRAM), memory bus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), among others.
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 is to be determined by the claims appended hereto.

Claims (18)

1. A method for determining synchronization time of an adaptive external clock source, the method comprising:
configuring reference counting frequency and overflow value of a timer of a local clock source, and setting the timer to reset and count when determining that a synchronous pulse signal of an external clock source is received or when counting overflows;
receiving a current synchronous pulse signal of the external clock source;
When the current synchronous pulse signal is invalid, acquiring the last counting frequency of a timer of the local clock source, wherein the last counting frequency is determined based on the count value of the timer when the valid synchronous pulse signal is received last time and the synchronous pulse period of the external clock source;
acquiring a last time error of a local clock source, wherein the last time error is determined based on a difference value between the external time of the external clock source and the local time of the local clock source when a valid synchronous pulse signal is received last time;
acquiring the local time and the current count value of the current reset record of the timer of the local clock source;
and determining the synchronous time according to the last counting frequency of the timer, the last time error, the local time of the current reset record and the current counting value.
2. The method according to claim 1, wherein the method further comprises:
acquiring a current count value of a current reset record of the timer and a last count value of the timer;
if the difference value between the current count value and the last count value is larger than a set value, determining that the current synchronous pulse signal is invalid;
And if the difference value between the current count value and the last count value is smaller than or equal to a set value, determining that the current synchronous pulse signal is valid.
3. The method according to claim 2, wherein the method further comprises:
and when the current synchronous pulse signal is valid, determining the current counting frequency according to the current counting value and the synchronous pulse period of the external clock source.
4. A method according to claim 3, wherein said determining a current count frequency from said current count value and a synchronization pulse period of said external clock source comprises:
and determining the current counting frequency according to the ratio of the current counting value to the synchronous pulse period of the external clock source.
5. The method according to claim 2, wherein the method further comprises:
when the current synchronous pulse signal is valid, acquiring the external time of the external clock source and the local time of the local clock source;
and determining the current time error according to the acquired difference value between the external time of the external clock source and the local time of the local clock source.
6. The method of claim 1, wherein the determining the synchronization time based on the last count frequency of the timer, the last time error, the current reset recorded local time, and the current count value of the timer comprises:
Acquiring the ratio of the current count value of the timer to the last count frequency of the timer;
obtaining a product value of the ratio and the last time error;
and determining the synchronous time according to the local time of the current reset record, the ratio and the product value.
7. The method of claim 6, wherein said determining a synchronization time based on said local time of said current reset record, said ratio, and said product value comprises:
and determining the synchronous time according to the local time of the current reset record, the sum of the ratio and the product value.
8. The method according to claim 1, wherein the method further comprises:
when the current synchronous pulse signal is valid, acquiring the external time of the external clock source;
and taking the external time of the external clock source as the synchronous time.
9. The method of claim 1, wherein the timer has an overflow value greater than an integer number of seconds of a synchronization pulse signal interval of the external clock source.
10. The method of any one of claims 1-9, wherein the external clock source is a global satellite navigation system, the synchronization pulse signal of the external clock source is a second pulse signal output by the global satellite navigation system, and the external time of the external clock source is a whole second time output by the global satellite navigation system.
11. The method of claim 1, wherein after the step of determining the synchronization time based on the last count frequency of the timer, the last time error, the current reset recorded local time, and the current count value, further comprising:
if the received synchronous pulse signals are invalid, acquiring an average value of a plurality of historical counting frequencies, wherein each historical counting frequency is determined based on the count value of a timer and the synchronous pulse period of the external clock source when each valid synchronous pulse signal is received in a historical manner, and updating the reference counting frequency of the timer based on the average value of the plurality of historical counting frequencies;
and determining the synchronous time according to the updated reference counting frequency of the timer, the local time recorded by resetting the timer again and the counted value of the timer again until receiving an effective synchronous pulse signal.
12. The method according to claim 1, wherein the method further comprises:
receiving a first pulse signal output by an incremental encoder;
if the first pulse signal is a first pulse signal, performing accumulated count on a plurality of first pulse signals output by the incremental encoder, determining current absolute time based on the synchronous time when reading the counted value of the accumulated count, and performing timestamp marking on the read counted value by using the current absolute time;
If the first pulse signal is a second pulse signal, performing accumulated count on a plurality of second pulse signals output by the incremental encoder, determining current absolute time based on the synchronous time when reading the counted value of the accumulated count, and performing timestamp marking on the read counted value by using the current absolute time;
wherein the phase difference between the first pulse signal and the second pulse signal is 90 °.
13. The method according to claim 1, wherein the method further comprises:
determining a third current absolute time based on the synchronization time when capturing a sampling pulse of the pulse sensor through an input capture channel;
if the sampling data of the pulse sensor are received, after the completion of the reception of the sampling data is confirmed, adding the third current absolute time into a data packet of the sampling data;
and if the sampling data of the pulse sensor are not received, the third current absolute time is associated with the pulse sensor and then output.
14. The method according to claim 1, wherein the method further comprises:
when the current synchronous pulse signal is valid, sending the external time of the external clock source to a second pulse self-synchronous sensor;
When the current synchronous pulse signal is invalid, the synchronous time is sent to a second pulse self-synchronous sensor;
the external clock source is a global satellite navigation system, the synchronous pulse signal of the external clock source is a second pulse signal output by the global satellite navigation system, and the external time of the external clock source is the whole second time output by the global satellite navigation system.
15. The method according to claim 1, wherein the method further comprises:
and transmitting the synchronization time to a sensor supporting the time synchronization protocol based on the time synchronization protocol, so that the sensor supporting the time synchronization protocol performs time stamp synchronization of the data packet based on the synchronization time.
16. The time synchronization device of the self-adaptive external clock source is characterized by comprising a local clock source, wherein the local clock source is an MCU clock, the MCU clock is provided with a timer and a temperature compensation crystal oscillator, and the clock frequency of the timer is provided by the temperature compensation crystal oscillator; the MCU clock is further configured with a processor, a memory and an embedded program stored on the memory and executable on the processor, which processor, when executing the embedded program, implements the steps of the method of any of claims 1 to 15.
17. A readable storage medium having stored thereon an embedded program, wherein the embedded program, when executed by a processor, realizes the steps of the method of any of claims 1 to 15.
18. A time synchronization system of an adaptive external clock source, comprising the time synchronization device of claim 16, further comprising one or more sensors, the time synchronization device sending synchronization time to the one or more sensors;
wherein the one or more sensors include one or more of an incremental encoder, a pulse sensor, a self-synchronizing pulse-second sensor, and a sensor supporting a time synchronization protocol.
CN202311556766.3A 2023-11-21 2023-11-21 Synchronization time determining method, time synchronization device, time synchronization system and medium Pending CN117675072A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311556766.3A CN117675072A (en) 2023-11-21 2023-11-21 Synchronization time determining method, time synchronization device, time synchronization system and medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311556766.3A CN117675072A (en) 2023-11-21 2023-11-21 Synchronization time determining method, time synchronization device, time synchronization system and medium

Publications (1)

Publication Number Publication Date
CN117675072A true CN117675072A (en) 2024-03-08

Family

ID=90083673

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311556766.3A Pending CN117675072A (en) 2023-11-21 2023-11-21 Synchronization time determining method, time synchronization device, time synchronization system and medium

Country Status (1)

Country Link
CN (1) CN117675072A (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
US9671761B2 (en) Method, time consumer system, and computer program product for maintaining accurate time on an ideal clock
US6535926B1 (en) Time synchronization system for industrial control network using global reference pulses
CN108923876B (en) Time synchronization method, device and system
US11994896B2 (en) Maintaining the correct time when counter values are transferred between clock domains
US7379480B2 (en) Fast frequency adjustment method for synchronizing network clocks
US8391270B2 (en) Network synchronization with reduced energy consumption
US20090086764A1 (en) System and method for time synchronization on network
US9763207B2 (en) Timing synchronization device and timing synchronization control method
CN117675072A (en) Synchronization time determining method, time synchronization device, time synchronization system and medium
EP2811672A1 (en) Communication apparatus, communication system, and communication method for time synchronization
WO2017063450A1 (en) Timestamp filtering method and apparatus
KR20160078893A (en) Semiconductor device, electronic device module and network system
CN114586297B (en) Synchronization method and equipment
JP2011185731A (en) Time synchronization device and time synchronization correction method therefor
JP4827866B2 (en) Packet monitoring device
JP2011122983A (en) Time synchronization device and method for time synchronization correction
US10853288B2 (en) Bus system
US10222786B2 (en) Numerical control system having synchronous control function between units
TWI618432B (en) Frequency calibration apparatus and method
US11664969B2 (en) Communication apparatus, method of controlling communication apparatus, and storage medium
CN112286034B (en) Whole vehicle data time synchronization method and device, electronic equipment and storage medium
KR20170058629A (en) Method, apparatus, system and computer program for enhancing the accuracy of Time Synchronization between devices
EP2398173A1 (en) Remote I/O system and synchronization method in the same
US20240171295A1 (en) Communication apparatus, control method for communication apparatus, and storage medium
JP6208712B2 (en) Time synchronization method and time synchronization 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