Vehicle-mounted time synchronization method
By setting up master nodes and slave nodes on the CAN bus and using timestamp data packets for time calibration, the problems of high cost and poor reliability in vehicle time synchronization are solved, sub-second accuracy and stability are achieved, and it is suitable for low-performance devices. , improving synchronization accuracy and reliability.
Patent Information
- Application Number
- CN202410904345.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-08
- Publication Date
- 2024-10-15
AI Technical Summary
Existing on-vehicle time synchronization methods have shortcomings such as high cost, poor reliability, and large time deviation. In particular, it is difficult to achieve high-precision and stable time synchronization in mobile devices and high-load computing conditions.
Set the master node and slave node on the CAN bus, connect to the timing system through the master node, send data packets containing timestamps, record and adjust the time difference to calculate and calibrate the time of the slave node, reduce hardware resource requirements and reduce time jumps .
It achieves sub-second time synchronization, reduces hardware cost and complexity, eliminates time jump problems, is suitable for low-performance devices, improves synchronization accuracy and reliability, and is suitable for high-load computing states.
Smart Images

Figure HDA0004931533770000011
Abstract
Description
Technical Field
[0001] The present invention relates to the field of communication technology, and in particular to a vehicle-mounted time synchronization method. Background Art
[0002] Category 1: Time synchronization through network protocols, such as NTP / PTP
[0003] NTP is a device that obtains the current time from the same time server through the network and uses an algorithm to minimize the time difference between the device and the standard clock source. Advantages: 1) Devices distributed in different areas can obtain time information with little difference through the same timing server, which can effectively reduce the time deviation between devices; 2) It can provide time calibration services for a large number of devices. Disadvantages: 1) All devices need to be connected to Ethernet or LAN, because timing devices usually need to be placed in a fixed place; 2) Devices receiving timing must have more than one means of networking, which increases hardware costs; 3) Due to communication needs, for mobile devices such as car-mounted devices, once they are in a basement or other place with no signal, the reliability of the equipment is extremely poor; 4) The time deviation between devices is large, and the request sent by the device to the server needs to be forwarded through a large number of gateways, which will inevitably lead to the timing accuracy being subject to the performance of network equipment and network congestion.
[0004] PTP can provide more accurate time synchronization. It can achieve sub-microsecond clock synchronization through hardware timestamp and network synchronization mechanism. It mainly relies on PTP synchronization protocol to ensure that multiple local time-served devices keep the same time as the time-serving device.
[0005] Advantages: 1) The PTP synchronization protocol is relatively mature, with high timing accuracy, and is widely used in industrial, automotive and other scenarios
[0006] Disadvantages: 1) High hardware cost. The premise of using PTP synchronization protocol is that the device must have Ethernet interface and supporting hardware interface. 2) High requirements on device performance. PTP needs to run network communication protocol, which requires the running device to have higher performance and resources, otherwise it cannot run stably.
[0007] Category 2: Time synchronization through satellite communications such as GPS / Beidou (GPS is used to refer to satellite communications below)
[0008] GPS module, which communicates with communication satellites through antennas and combines internal algorithms to obtain high-precision timing services from satellites
[0009] Advantages: 1) The time error between devices is small, relying on the high-precision clock source on the communication satellite. In theory, the time error of the device receiving GPS timing is only related to the transmission distance;
[0010] Disadvantages: 1) High cost, the device needs to have at least one antenna + one GPS chip; 2) Poor signal reliability, GPS signal is very poor in indoor, high-rise closed, underground and other places, basically unable to make the device work properly
[0011] Category 3: Time synchronization protocol through CAN network, such as AUTOSAR
[0012] The communication between the devices in the vehicle environment is mainly realized through the CAN network. The clock source device sends time information to the CAN network at a fixed frequency. The device receiving the time calculates the time error based on its own timer and then corrects it.
[0013] Advantages: 1) Low cost. As long as the device can be connected to the CAN network, high-precision time synchronization can be achieved based on the existing communication network. 2) Low performance requirements. Some low-performance devices can also operate normally without affecting their own performance.
[0014] Disadvantages: 1) Poor compatibility. Usually, the main control unit in the vehicle usually runs non-real-time operating systems such as Linux. Its own code structure determines that the process from the CAN module receiving data to the application end processing data will be easily disturbed by the system's own state, resulting in the error cannot be reduced, or even increased.
[0015] The existing vehicle environment uses a variety of time synchronization methods. The master end obtains time from the remote server through NTP, and other sub-devices complete it through GPRMC [recommended minimum positioning information, which is a message format of GPS], PTP, etc. In addition, considering that the system needs to run models, algorithms and other tasks that occupy a large performance, common devices will run SOC+MCU solutions. The SOC chip sends time to the MCU chip through the serial port, and the MCU sends time data to the slave device through the serial port+PPS or CAN.
[0016] shortcoming:
[0017] 1) Poor reliability. The SOC chip communicates with the MCU chip at a fixed frequency. As the running time increases, the time deviation between the two will become larger and larger and cannot be reduced. Increasing the synchronization frequency will affect the SOC resources, and reducing the synchronization frequency will cause the error to be unable to be reduced.
[0018] 2) Time mutation. During the data processing process, the time must be continuous and stable. As the time deviation between the SOC chip and the MCU increases, the two times will suddenly synchronize at a certain time period, causing the MCU time to jump, which will cause the entire system to operate abnormally or even cause accidents. Summary of the invention
[0019] The purpose of the present invention is to provide a vehicle-mounted time synchronization method to solve the problems raised in the above background technology.
[0020] To achieve the above object, the present invention provides the following technical solution: a vehicle-mounted time synchronization method, comprising the following steps:
[0021] Set up a master node and several slave nodes on the CAN bus;
[0022] Connecting the master node to a timing system, and timing the master node through the timing system;
[0023] Sending a data packet A containing a first timestamp to the slave node through the master node, and the slave node starts a timer after receiving the data packet A and starts recording time;
[0024] The master node sends a data packet B containing a second timestamp to the slave node, and after the slave node receives the data packet B, it turns off the timer and stops recording time;
[0025] The slave node reports the time record data to the master node, the master node calculates the time difference based on the data reported, and adjusts the value of data packet A and data packet B in the next round based on the time difference.
[0026] Preferably, the slave node reports the time record data to the master node, the master node calculates the time difference from the data reported, and adjusts the value of the data packet A and the data packet B of the next round by the time difference, including:
[0027] The master node obtains the UTC timestamp and records the time node T1;
[0028] Send the total number of seconds from 00:00:00 on January 1, 1970 to the present, obtained by the first timestamp.
[0029] Preferably, the master node obtains the UTC timestamp, records the time node T1 and starts the timer to calculate the transmission error between the time node T1 and the first timestamp.
[0030] Preferably, the sending of a data packet B including a second timestamp to the slave node through the master node, and after the slave node receives the data packet B, turning off the timer and stopping recording time, comprises:
[0031] The value of the transmission error between the calculation time node T1 and the first timestamp is introduced into the second timestamp, and the value of the second timestamp is adjusted;
[0032] Generate a data packet B using the adjusted second timestamp and transmit it to the slave node;
[0033] Combine data packet A and data packet B, compare the timer time and the self-time, and calculate the time deviation between the CAN bus and the timing device.
[0034] Preferably, the calculation process of the time deviation is:
[0035] Time T1: the current system time or the time of a specific time source, sent as a timestamp in UTC format;
[0036] Time T2: refers to the difference between the arrival time of data packet B and the arrival time of data packet A recorded by the present invention with a 1us time resolution;
[0037] Time T4: T4 = current Linux system time (us) - data time reported by the present invention (us). When T4 meets a certain range, it is considered valid and included in T3 calculation. Otherwise, it does not participate in T3 calculation.
[0038] Time T3: T3 = (time to send data packet B - time to send data packet A + correction time) (us) + T4 / proportional coefficient;
[0039] (us) indicates the time unit is microseconds, and (s) indicates the time unit is seconds.
[0040] Preferably, the self time is calculated as follows:
[0041] Time T5: the time involved in the time calibration of the present invention itself, T5=T1(data packet A) (s)+T3(data packet B) (us)+T2(data packet B arrival time-data packet A arrival time) (us)-the timestamp of the present invention itself (us).
[0042] Compared with the prior art, the present invention has the following beneficial effects:
[0043] 1. Advantage 1 of the present invention: The hardware resource requirements of peripheral devices are extremely low. As long as there is an RS232 or CAN module, time synchronization can be completed with sub-second accuracy. The performance requirements are low, which can greatly reduce the hardware cost and hardware complexity;
[0044] 2. Advantage 2 of the present invention: It eliminates the time jump problem caused by NTP and other methods. Timing devices usually need to communicate with peripheral servers. As the running time becomes longer, the deviation between the timing device itself and the peripheral server will become larger. At this time, the time of the timing device itself will jump [normal 1s 2s 3s, jump 1s 4s, and the middle 2s 3s disappear]. This will cause the timestamp on the data collected by the peripheral device to be discontinuous, which will cause unpredictable abnormal conditions for the algorithms and models that process the data. The present invention controls the length of each operating cycle and eliminates the risks caused by time jumps by using extremely small variables;
[0045] 3. Advantage 3 of the present invention: wide practical scope. Similar to the present invention, the protocol for time synchronization based on the CAN network requires that the loss caused by the transmission process between the timing device and the timing device should be reduced as much as possible. Therefore, it is not suitable for platforms such as Linux or computing platforms that are in a high-load computing state for a long time, which will greatly affect the transmission loss. The present invention can be applied to the working conditions of low transmission loss such as MCU to MCU, and is also applicable to the above situation. Through the supporting drive of the present invention, it can be adjusted in advance according to the transmission loss calculated in each calibration cycle so that the time accuracy can be controlled within milliseconds;
[0046] 4. Advantage 4 of the present invention: strong reliability. The timing equipment on the market is usually used as a master control device, computing unit and other high computing task states. In this state, it is possible that the timing equipment cannot work normally due to interference. The internal circuit of the present invention adds various protection measures, so that when the timing equipment is in an abnormal state, it can provide normal time to peripheral devices to ensure that they are in normal working state. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] Figure 1 is a flow chart of an embodiment of the present invention. DETAILED DESCRIPTION
[0048] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0049] See also Figure 1 The present invention provides a technical solution: a vehicle-mounted time synchronization method, comprising the following steps:
[0050] S100: Setting a master node and several slave nodes on the CAN bus;
[0051] S200: Connecting the master node to a timing system, and timing the master node through the timing system;
[0052] S300: sending a data packet A including a first timestamp to the slave node through the master node, and the slave node starts a timer after receiving the data packet A and starts recording time;
[0053] S400: sending a data packet B including a second timestamp to the slave node through the master node, and after receiving the data packet B, the slave node turns off the timer and stops recording time;
[0054] S500: The slave node reports the time record data to the master node, the master node calculates the time difference based on the data reported, and adjusts the values of data packets A and B in the next round based on the time difference.
[0055] In one embodiment of the present invention, S300 includes:
[0056] S301: The master node obtains the UTC timestamp and records the time node T1;
[0057] S302: Send the total number of seconds from 00:00:00 on January 1, 1970 to the present obtained by the first timestamp.
[0058] In one embodiment of the present invention, the master node obtains the UTC timestamp, records the time node T1 and starts the timer to calculate the transmission error between the time node T1 and the first timestamp.
[0059] In one embodiment of the present invention, S400 includes:
[0060] S401: introducing the value of the transmission error between the calculation time node T1 and the first timestamp into the second timestamp, and adjusting the value of the second timestamp;
[0061] S402: Generate a data packet B using the adjusted second timestamp, and transmit the data packet to the slave node;
[0062] S403: Combine data packet A and data packet B, compare the timer time and the own time, and calculate the time deviation between the CAN bus and the timing device.
[0063] In one embodiment of the present invention, the calculation process of the time deviation is:
[0064] Time T1: the current system time or the time of a specific time source, sent as a timestamp in UTC format;
[0065] Time T2: refers to the difference between the arrival time of data packet B and the arrival time of data packet A recorded by the present invention with a 1us time resolution;
[0066] Time T4: T4 = current Linux system time (us) - data time reported by the present invention (us). When T4 meets a certain range, it is considered valid and included in T3 calculation. Otherwise, it does not participate in T3 calculation.
[0067] Time T3: T3 = (time to send data packet B - time to send data packet A + correction time) (us) + T4 / proportional coefficient;
[0068] (us) indicates the time unit is microseconds, and (s) indicates the time unit is seconds.
[0069] In one embodiment of the present invention, the self time is calculated as follows:
[0070] Time T5: the time involved in the time calibration of the present invention itself, T5=T1(data packet A) (s)+T3(data packet B) (us)+T2(data packet B arrival time-data packet A arrival time) (us)-the timestamp of the present invention itself (us).
[0071] Although embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the appended claims and their equivalents.
Claims
1. A vehicle-mounted time synchronization method, characterized in that: The steps include: Set up a master node and several slave nodes on the CAN bus; Connecting the master node to a timing system, and timing the master node through the timing system; Sending a data packet A containing a first timestamp to the slave node through the master node, and the slave node starts a timer after receiving the data packet A and starts recording time; The master node sends a data packet B containing a second timestamp to the slave node, and after the slave node receives the data packet B, it turns off the timer and stops recording time; The slave node reports the time record data to the master node, the master node calculates the time difference based on the data reported, and adjusts the value of data packet A and data packet B in the next round based on the time difference.
2. A vehicle-mounted time synchronization method according to claim 1, characterized in that: The slave node reports the time record data to the master node, the master node calculates the time difference based on the data reported, and adjusts the values of the data packets A and B of the next round based on the time difference, including: The master node obtains the UTC timestamp and records the time node T1; Send the total number of seconds from 00:00:00 on January 1, 1970 to the present, obtained by the first timestamp.
3. A vehicle-mounted time synchronization method according to claim 2, characterized in that: The master node obtains the UTC timestamp, records the time node T1 and starts the timer to calculate the transmission error between the time node T1 and the first timestamp.
4. The vehicle-mounted time synchronization method according to claim 3, characterized in that: The method of sending a data packet B including a second timestamp to the slave node through the master node, and the slave node closing a timer and stopping recording time after receiving the data packet B, includes: The value of the transmission error between the calculation time node T1 and the first timestamp is introduced into the second timestamp, and the value of the second timestamp is adjusted; Generate a data packet B using the adjusted second timestamp and transmit it to the slave node; Combine data packet A and data packet B, compare the timer time and the self-time, and calculate the time deviation between the CAN bus and the timing device.
5. A vehicle-mounted time synchronization method according to claim 4, characterized in that: The calculation process of the time deviation is: Time T1: the current system time or the time of a specific time source, sent as a timestamp in UTC format; Time T2: refers to the difference between the arrival time of data packet B and the arrival time of data packet A recorded by the present invention with a 1us time resolution; Time T4: T4 = current Linux system time (us) - data time reported by the present invention (us). When T4 meets a certain range, it is considered valid and included in T3 calculation. Otherwise, it does not participate in T3 calculation. Time T3: T3 = (time to send data packet B - time to send data packet A + correction time) (us) + T4 / proportional coefficient; (us) indicates the time unit is microseconds, and (s) indicates the time unit is seconds.
6. The vehicle-mounted time synchronization method according to claim 6, characterized in that: The self time is calculated as follows: Time T5: the time involved in the time calibration of the present invention itself, T5=T1(data packet A) (s)+T3(data packet B) (us)+T2(data packet B arrival time-data packet A arrival time) (us)-the timestamp of the present invention itself (us).
Citation Information
Cited By
Anti-interference random sequence frequency hopping and frequency synchronization method and system and storage medium
CN119892149A
Device and method for automatically correcting transmission time of vehicle positioning data, computer system and program product, and storage medium
CN120567605A
Apparatus and method for automatically correcting transmission time of vehicle positioning data, computer system and program product, storage medium
CN120567605B
