PPS signal and TOD combined high-precision time synchronization implementation method and system

By combining PPS signal and TOD interface, the real-time operating system and microsecond counting unit are used to dynamically correct the time system time, solving the problem of insufficient time synchronization accuracy in the existing technology, and realizing time synchronization with high precision and low CPU occupancy Effect.

CN119109546APending Publication Date: 2024-12-10JIANGLING MOTORS
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202411210821.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-30
Publication Date
2024-12-10

AI Technical Summary

Technical Problem

In the automotive time synchronization, the prior art, due to the randomness of scheduling and data processing delays, the time synchronization accuracy cannot reach the microsecond level, and the compensation mechanism is static and cannot be adjusted dynamically, which limits the system's time synchronization accuracy and reliability.

Method used

Combining PPS signal and TOD interface, through the real-time operating system, microsecond counting unit, real-time clock module and GPIO interrupt functions, PPS signal is captured and the microsecond time difference is calculated, and the system time is dynamically corrected to achieve high-precision time synchronization.

Benefits of technology

It realizes microsecond accuracy of time synchronization, reduces CPU usage, and does not increase hardware design cost. The software is simple to implement and has strong portability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119109546A_ABST
    Figure CN119109546A_ABST
Patent Text Reader

Abstract

The invention provides a PPS signal and TOD combined high-precision time synchronization realization method and system, main task processing and interrupt task processing are combined, an interrupt task processes a PPS rising edge signal, accurately captures a whole second signal, establishes a whole second identifier, and reads a count value of a microsecond timer, and after the main task obtains the whole second identifier, the PPS rising edge signal and the count value of the microsecond timer are calculated. According to the method, the latest TOD data is analyzed, after the effective TOD data is analyzed, the counting value of the microsecond-level timer is read again, the counter difference value of the microsecond-level timer is calculated twice, the counting value is converted into the accurate microsecond-level time, the local time is calibrated, the microsecond-level time is stored, and under the same task condition, the CPU occupancy rate can be greatly reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of automobile time synchronization, and in particular to a high-precision time synchronization implementation method and system combining a PPS signal and a TOD. Background Art

[0002] In modern automobiles and complex embedded systems, multiple electronic control units (ECUs), sensors, and communication modules need to work together, and these components must maintain precise time synchronization to ensure system performance and reliability. The accuracy of time synchronization is particularly important in autonomous driving, V2X communication, vehicle network communication, and data logging and diagnosis, because time errors may lead to system decision errors or inconsistent data processing, thus affecting the safety and operating efficiency of the vehicle.

[0003] The PPS (Pulse Per Second) signal is a precise time pulse signal provided by a GPS receiver or RTK device. It is sent out once per second and is used to synchronize the system time. Currently, the system usually combines the PPS signal and the timing data output interface to synchronize the time. The timing data provides the current time information (usually accurate to the second), while the PPS signal provides a time pulse per second. In this method, due to the task scheduling mechanism of the operating system and the possible delays in the data processing process, the system needs to perform time compensation to correct the errors caused by these delays. The calculation of the compensation time is usually based on the system scheduling cycle. The time compensation value is usually a fixed value, and the accuracy of time synchronization can only reach the millisecond (ms) level.

[0004] However, due to the randomness of scheduling and data processing delays, the fixed compensation value calculated by statistics cannot accurately correct all time errors and cannot capture delay changes in real time. In addition, the existing compensation mechanism is often static. Once the compensation value is set, it will not be adjusted according to actual operating conditions and environmental changes. This results in the system being unable to dynamically adjust the compensation value, limiting the accuracy and reliability of time synchronization. Summary of the invention

[0005] In view of the defects in the prior art, the purpose of the present invention is to provide a high-precision time synchronization implementation method and system combining PPS signals and TOD, combining the main task processing flow and the interrupt task processing flow, thereby achieving high-precision time synchronization while significantly reducing the CPU occupancy rate.

[0006] In order to achieve the above technical effects, the present invention adopts the following technical solutions:

[0007] According to a first aspect of the present invention, a method for realizing high-precision time synchronization combining a PPS signal and a TOD is provided, comprising the following steps:

[0008] Step S1. Start and initialize the real-time operating system, initialize the microsecond counting unit, the real-time clock (RTC) module, the CAN interface, and enable the interrupt function of the general input and output (GPIO) pin in the microcontroller, configure the general input and output (GPIO) port to the edge trigger mode and clear the previous interrupt flag;

[0009] Step S2. The GPIO port detects the edge of the PPS signal and triggers an interrupt, and sets an interrupt flag to indicate that an interrupt occurs, records the count value of the current microsecond counter unit and converts the count value into an actual number of microseconds to obtain the first microsecond counter value;

[0010] Step S3. The system is connected to the timing data output interface (TOD interface) to receive the timing time in the TOD data, parse the received TOD data, and convert it into a TOD time format readable by the system;

[0011] Step S4. After parsing to obtain a readable TOD time format, the system reads the current count value of the microsecond counter again and converts the counter value into a microsecond value, then subtracts the first microsecond counter value, calculates the actual microsecond time difference between the two readings, adds the calculated microsecond time difference to the parsed TOD time, obtains the complete corrected time value, and uses this corrected time value to set the time of the RTC module;

[0012] Step S5: Before the next PPS signal arrives, the system updates the system time using the time of the RTC module and the latest microsecond time difference.

[0013] Preferably, the accuracy of the TOD data received in step S3 is at the second level.

[0014] Preferably, the method needs to meet the following prerequisites: having an effective underlying embedded system scheduling mechanism, the microcontroller unit (MCU) needs to support the interrupt function of the general purpose input and output (GPIO) port, and the MCU can access the data of the system timer.

[0015] According to a second aspect of the present invention, a high-precision time synchronization implementation system combining a PPS signal and a TOD is provided, which is used to implement the high-precision time synchronization implementation method combining a PPS signal and a TOD, and specifically includes the following modules:

[0016] Initialization module: This module is used to start and initialize the real-time operating system, initialize the microsecond counting unit, the real-time clock (RTC) module, the CAN interface, and enable the interrupt function of the general-purpose input and output (GPIO) pins in the microcontroller, configure the general-purpose input and output (GPIO) port to edge-triggered mode and clear the previous interrupt flag;

[0017] GPIO interrupt trigger module: This module is used to trigger the GPIO interrupt after detecting the edge of the PPS signal, set the interrupt flag to indicate the interrupt occurs, and record the current value of the microsecond counting unit;

[0018] Timer value conversion module: This module is used to convert the count value read from the microsecond counting unit into the actual number of microseconds;

[0019] TOD data parsing module: This module is used to receive and parse the received TOD data and convert it into a TOD time format readable by the system;

[0020] Compensation time calculation module: This module is used to subtract the microsecond value of the second microsecond counter from the microsecond value of the first microsecond counter to calculate the actual time difference between the two times, add the calculated microsecond time difference to the parsed TOD time, and obtain the complete corrected precise time, and use this corrected time value to set the time of the real-time clock module.

[0021] Compared with the prior art, the present invention has the following beneficial effects:

[0022] The high-precision time synchronization implementation method combining the PPS signal and the TOD interface provided by the present invention uses the combination of the main task and the interrupt. The interrupt task accurately captures the whole second signal by processing the PPS rising edge signal, establishes the whole second mark, and reads the count value of the microsecond timer at the same time. After obtaining the whole second mark, the main task parses the most recent TOD data. When valid TOD data is parsed, the microsecond timer count value is read again, the difference between the two microsecond timer counters is calculated, and converted into accurate microsecond time, the local time is calibrated and the us time is saved. Under the same task conditions, the CPU occupancy rate is greatly reduced, and the hardware design cost of the system is not increased. The software implementation is simple and the portability is strong. BRIEF DESCRIPTION OF THE DRAWINGS

[0023] Other features, objects and advantages of the present invention will become more apparent from the detailed description of non-limiting embodiments made with reference to the following drawings:

[0024] Figure 1 It is a flowchart of the steps of the method for realizing high-precision time synchronization combining the PPS signal and TOD described in the first embodiment;

[0025] Figure 2 It is a flow chart of interrupt processing in the high-precision time synchronization implementation method combining the PPS signal and TOD described in the first embodiment;

[0026] Figure 3This is a main task processing flow chart of the high-precision time synchronization implementation method combining the PPS signal and TOD described in the first embodiment;

[0027] Figure 4 A schematic diagram of a high-precision time synchronization implementation system combining a PPS signal and a TOD as described in the second embodiment; DETAILED DESCRIPTION

[0028] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. The components of the embodiments of the present application described and shown in the drawings here can be arranged and designed in various different configurations.

[0029] Therefore, the following detailed description of the embodiments of the present application provided in the accompanying drawings is not intended to limit the scope of the present application for which protection is sought, but merely represents selected embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without creative work are within the scope of protection of the present application.

[0030] like Figure 1 , 2As shown, this embodiment provides a high-precision time synchronization implementation method combining PPS signal and TOD. The method uses the PPS signal on the real-time dynamic measurement (RTK) device to combine with the TOD interface to achieve high-precision time synchronization, which can compensate for the data processing delay at the microsecond level. The method does not increase the hardware design cost of the system, the software implementation is simple, and the portability is strong. The implementation of this method needs to first meet the following prerequisites: 1. Have an effective underlying embedded system scheduling mechanism; embedded systems usually run real-time operating systems (RTOS) or similar software, which can schedule tasks and interrupts according to priority. The underlying system scheduling needs to have efficient task and interrupt management functions to ensure that the time synchronization method can run as expected. An effective scheduling mechanism can ensure that the time synchronization task is executed at the appropriate time point, so that the data collection and processing during the time synchronization process are accurate. 2. MCU (microcontroller unit) needs to support the interrupt function of the GPIO (general input and output) port. GPIO interrupts allow the MCU to respond immediately when a specific signal (such as a PPS signal) arrives without continuous polling. This interrupt mechanism is an important part of achieving high-precision time synchronization because it can capture the time pulse signal every second. 3. The MCU can access the data of the system timer, which is usually a high-precision timer that can record the time interval from the PPS signal trigger to the system response with microsecond or higher accuracy, thereby helping to calculate the time error and compensation value.

[0031] After the above preconditions are met, the high-precision time synchronization implementation method combining the PPS signal and the TOD interface provided in this embodiment is used as follows: Figure 2 , 3 The interrupt task processing is combined with the main task processing shown in the figure. The interrupt task accurately captures the whole second signal by processing the PPS rising edge signal, establishes the whole second mark, and reads the count value of the microsecond timer at the same time. After obtaining the whole second mark, the main task parses the most recent TOD data, which specifically includes the following steps:

[0032] Step S1. System initialization;

[0033] Initialize the real-time operating system (RTOS system): Start the real-time operating system to ensure the real-time nature of task scheduling and system response. Initialize the microsecond counting unit and set a counting unit that can be accurate to microseconds to record the exact time when the PPS signal arrives. Initialize the RTC module and configure the real-time clock (RTC), which can provide current time information and keep the system time synchronized. Initialize the CAN interface and configure the controller area network (CAN) interface for communication within the system or between external devices (if necessary). Initialize the GPIO interrupt, configure and enable the interrupt function of the GPIO pin in the microcontroller (MCU), and configure the GPIO port (general input and output port) to edge trigger mode so that an interrupt is triggered when the PPS signal is received, and clear the previous interrupt flag to ensure that the system starts working in a clean state.

[0034] Step S2. Wait for GPIO to trigger an interrupt; in this step, the PPS signal is used as follows Figure 2 The interrupt processing method shown uses a rising edge interrupt based on the signal characteristics of the PPS, which can accurately capture the whole second time. When the PPS signal arrives, the GPIO port detects the signal edge and triggers an interrupt. In the interrupt service routine (ISR), the interrupt flag is set to indicate that the interrupt has occurred, and the current value of the microsecond counting unit is recorded for subsequent calculations. At the same time, the count value read from the microsecond counting unit is converted into the actual number of microseconds.

[0035] Step S3. Parse TOD timestamp;

[0036] While waiting for TOD data, the system receives the timestamp of the current time by communicating with the timing data output interface (TOD interface). This timestamp usually comes from an external time source, such as a network time protocol (NTP) server or a GPS system. At this stage, the system will enter a waiting state until the complete TOD data is received. TOD data usually refers to "Time of Day" data, which represents the precise time information at a specific moment. This type of data is very important in systems that require precise time synchronization. It is usually recorded in the form of a timestamp to mark the exact time when an event or operation occurs. In this step, there is no particularly strict data processing requirement for the data interface sent by the peer TOD. It can be automatically adapted and calculated according to the current resources. The TOD interface can be a serial port, CAN interface, Ethernet interface, etc.

[0037] Parse the received TOD data and convert it into a system-readable time format. Usually, TOD data provides the current date and time information, such as "August 26, 2024 14:30:00", accurate to seconds. The parsing process involves extracting the raw data into fields such as year, month, day, hour, minute, and second, and formatting them into a standard time representation. The accuracy of TOD data is usually at the second level, and accuracy must be ensured during parsing. In addition, the parsed time information will be used as a benchmark for subsequent time compensation calculations.

[0038] After acquiring and parsing the TOD timestamp, the system reads the current value of the microsecond counter again. The read microsecond counter value represents the time interval from the last counter reading to the current time point. The purpose of re-reading the microsecond counter is to calculate the time delay between the trigger time of the PPS signal and the TOD data parsing.

[0039] Step S4. After parsing the TOD data, the system reads the microsecond counter value again to obtain the current microsecond time, converts the second microsecond counter value into a microsecond value, and then subtracts the first microsecond counter value to calculate the actual time difference between the two readings. This difference represents the time delay from the PPS signal trigger to the TOD data parsing, accurate to the microsecond level, and the calculated time difference is used to compensate for the time error caused by processing delays. Then the calculated microsecond time difference is combined with the time parsed by the TOD interface, and the calculated precise microsecond time difference is added to the parsed TOD timestamp to obtain the complete corrected precise time, and this corrected time value is used to set the time of the RTC (real time clock) module.

[0040] Step S5: Before the next PPS signal arrives, the system updates the system time using the RTC time and the latest microsecond time difference to ensure that the accuracy of time synchronization remains stable between the two PPS signals.

[0041] Second Embodiment

[0042] like Figure 4 As shown, this embodiment provides a high-precision time synchronization implementation system combining a PPS signal and a TOD, which is used for the high-precision time synchronization implementation method combining a PPS signal and a TOD described in the first embodiment in real time, and specifically includes the following modules:

[0043] Initialization module: This module is used to start and initialize the real-time operating system, initialize the microsecond counting unit, the real-time clock (RTC) module, the CAN interface, and enable the interrupt function of the general-purpose input and output (GPIO) pins in the microcontroller, configure the general-purpose input and output (GPIO) port to edge-triggered mode and clear the previous interrupt flag;

[0044] GPIO interrupt trigger module: This module is used to trigger the GPIO interrupt after detecting the edge of the PPS signal, set the interrupt flag to indicate the interrupt occurs, and record the current value of the microsecond counting unit;

[0045] Timer value conversion module: This module is used to convert the count value read from the microsecond counting unit into the actual number of microseconds;

[0046] TOD data parsing module: This module is used to receive and parse the received TOD data and convert it into a TOD time format readable by the system;

[0047] Compensation time calculation module: This module is used to subtract the microsecond value of the second microsecond counter from the microsecond value of the first microsecond counter to calculate the actual time difference between the two times, add the calculated microsecond time difference to the parsed TOD time, and obtain the complete corrected precise time, and use this corrected time value to set the time of the real-time clock module.

[0048] The above describes the specific embodiments of the present invention. Based on the above description, relevant personnel can make various changes and modifications without departing from the technical concept of the present invention.

Claims

1. A high-precision time synchronization implementation method combining PPS signal and TOD, characterized in that: The following steps are involved: Step S1. Start and initialize the real-time operating system, initialize the microsecond counting unit, the real-time clock (RTC) module, the CAN interface, and enable the interrupt function of the general input and output (GPIO) pin in the microcontroller, configure the general input and output (GPIO) port to the edge trigger mode and clear the previous interrupt flag; Step S2. The GPIO port detects the edge of the PPS signal and triggers an interrupt, and sets an interrupt flag to indicate that an interrupt occurs, records the count value of the current microsecond counter unit and converts the count value into an actual number of microseconds to obtain the first microsecond counter value; Step S3. The system is connected to the timing data output interface (TOD interface) to receive the timing time in the TOD data, parse the received TOD data, and convert it into a TOD time format readable by the system; Step S4. After parsing to obtain a readable TOD time format, the system reads the current count value of the microsecond counter again and converts the counter value into a microsecond value, then subtracts the first microsecond counter value, calculates the actual microsecond time difference between the two readings, adds the calculated microsecond time difference to the parsed TOD time, obtains the complete corrected time value, and uses this corrected time value to set the time of the RTC module; Step S5: Before the next PPS signal arrives, the system updates the system time using the time of the RTC module and the latest microsecond time difference.

2. The high-precision time synchronization implementation method combining PPS signal and TOD according to claim 1 is characterized in that: The accuracy of the TOD data received in step S3 is at the second level.

3. The high-precision time synchronization implementation method combining PPS signal and TOD according to claim 1 is characterized in that: The method needs to meet the following prerequisites: an effective underlying embedded system scheduling mechanism, a microcontroller unit (MCU) needs to support the interrupt function of a general purpose input and output (GPIO) port, and the MCU can access the data of a system timer.

4. A high-precision time synchronization implementation system combining a PPS signal and a TOD, used to implement the high-precision time synchronization implementation method combining a PPS signal and a TOD as described in any one of claims 1 to 3, characterized in that: Specifically includes the following modules: Initialization module: This module is used to start and initialize the real-time operating system, initialize the microsecond counting unit, the real-time clock (RTC) module, the CAN interface, and enable the interrupt function of the general-purpose input and output (GPIO) pins in the microcontroller, configure the general-purpose input and output (GPIO) port to edge-triggered mode and clear the previous interrupt flag; GPIO interrupt trigger module: This module is used to trigger the GPIO interrupt after detecting the edge of the PPS signal, set the interrupt flag to indicate the interrupt occurs, and record the current value of the microsecond counting unit; Timer value conversion module: This module is used to convert the count value read from the microsecond counting unit into the actual number of microseconds; TOD data parsing module: This module is used to receive and parse the received TOD data and convert it into a TOD time format readable by the system; Compensation time calculation module: This module is used to subtract the microsecond value of the second microsecond counter from the microsecond value of the first microsecond counter to calculate the actual time difference between the two times, add the calculated microsecond time difference to the parsed TOD time, and obtain the complete corrected precise time, and use this corrected time value to set the time of the real-time clock module.

Citation Information

Cited By

  • Time synchronization method and device and time synchronization system of intelligent driving system

    CN120658338A

  • Time synchronization method, apparatus and time synchronization system for intelligent driving system

    EP4668048A3