[go: up one dir, main page]

CN118381577B - MCU system time synchronization method and device - Google Patents

MCU system time synchronization method and device Download PDF

Info

Publication number
CN118381577B
CN118381577B CN202410825658.XA CN202410825658A CN118381577B CN 118381577 B CN118381577 B CN 118381577B CN 202410825658 A CN202410825658 A CN 202410825658A CN 118381577 B CN118381577 B CN 118381577B
Authority
CN
China
Prior art keywords
time
slave device
master device
data
slave
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.)
Active
Application number
CN202410825658.XA
Other languages
Chinese (zh)
Other versions
CN118381577A (en
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.)
Sichuan Qingneng Jikong Technology Co ltd
Original Assignee
Sichuan Qingneng Jikong Technology 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 Sichuan Qingneng Jikong Technology Co ltd filed Critical Sichuan Qingneng Jikong Technology Co ltd
Priority to CN202410825658.XA priority Critical patent/CN118381577B/en
Publication of CN118381577A publication Critical patent/CN118381577A/en
Application granted granted Critical
Publication of CN118381577B publication Critical patent/CN118381577B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04JMULTIPLEX COMMUNICATION
    • H04J3/00Time-division multiplex systems
    • H04J3/02Details
    • H04J3/06Synchronising arrangements
    • H04J3/0635Clock or time synchronisation in a network
    • H04J3/0638Clock or time synchronisation among nodes; Internode synchronisation

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Synchronisation In Digital Transmission Systems (AREA)
  • Electric Clocks (AREA)

Abstract

The application provides a method and a device for synchronizing MCU system time, wherein the method for synchronizing MCU system time comprises the following steps: setting a master device and at least one slave device in a target system, wherein the master device comprises a reference time; generating time stamp data according to the reference time, and sending the time stamp data to the at least one slave device through the master device according to the time granularity of the reference time; transmitting, by the master device, a corrective signal to the at least one slave device based on a preset interval time; and adjusting the time data in the at least one slave device to be synchronous with the time data of the master device through the received time stamp data and the correction signal. The high-precision time synchronization inside the MCU system is realized, and meanwhile, as other devices are not required to be externally connected, the MCU system has high reliability, low cost and wide application range.

Description

MCU system time synchronization method and device
Technical Field
The application relates to the technical field of time synchronization processing, in particular to a time synchronization method of an MCU system. The application also relates to a MCU system time synchronization device.
Background
With the development of electronic technology, more and more electronic products are designed to require a plurality of systems to work cooperatively, and in the process of multi-system cooperation, the plurality of systems are required to have the same time reference, and in the prior art, a real-time clock chip or a GPS real-time clock is often adopted for multi-system time synchronization.
However, in the method of line synchronization time by the real-time clock chip, since each system operates independently, the time accuracy depends on the quality of the real-time clock chip and the accuracy of the crystal oscillator element, and error accumulation is unavoidable, and along with the execution time of the multi-system cooperative task, errors above the second level are unavoidable.
The method for synchronizing time by adopting the GPS real-time clock is expensive on one hand, and on the other hand, ideal signal condition support is needed, besides, the time synchronization is carried out by adopting the GPS real-time clock, and the method is generally only in the millisecond level and is not applicable to occasions with high time precision requirements.
Disclosure of Invention
In view of this, the embodiment of the application provides a method for synchronizing time of an MCU system, so as to solve the technical defects existing in the prior art. The embodiment of the application also provides a MCU system time synchronization device, a computing device and a computer readable storage medium.
According to a first aspect of an embodiment of the present application, there is provided an MCU system time synchronization method, including:
Setting a master device and at least one slave device in a target system, wherein the master device comprises a reference time;
Generating time stamp data according to the reference time, and sending the time stamp data to the at least one slave device through the master device according to the time granularity of the reference time;
transmitting, by the master device, a corrective signal to the at least one slave device based on a preset interval time;
and adjusting the time data in the at least one slave device to be synchronous with the time data of the master device through the received time stamp data and the correction signal.
Optionally, the setting a master device and at least one slave device in the target system includes:
Determining a reference sub-module comprising a reference time module according to a use manual of the target system, and determining a device code of the reference sub-module;
according to the device code, one of the reference sub-modules is selected as the master device in response to a received master device selection instruction, and other sub-devices in the target system are set as slave devices.
Optionally, the setting a master device and at least one slave device in the target system includes:
inquiring sub-equipment parameters contained in the target system;
Determining a reference sub-module comprising a reference time module based on the sub-device parameters, and determining a device code of the reference sub-module;
according to the device code, one of the reference sub-modules is selected as the master device in response to a received master device selection instruction, and other sub-devices in the target system are set as slave devices.
Optionally, the sending, by the master device, the timestamp data to the at least one slave device according to the time granularity of the reference time includes:
And updating the time stamp data in real time according to the reference time, and sending the time stamp data to the at least one slave device through the master device by taking the time granularity as a period.
Optionally, the sending, by the master device, the timestamp data to the at least one slave device includes:
Generating a serial data stream based on the timestamp data;
Transmitting the serial data stream from the master device to the at least one slave device through a signal path disposed between the master device and the at least one slave device;
and the at least one slave device analyzes the received serial port data stream to obtain the timestamp data.
Optionally, the sending, by the master device, the correction signal to the at least one slave device based on the preset interval time includes:
And after the master device transmits the time stamp data, waiting for the interval time, and transmitting the correction signal to the at least one slave device through the master device.
Optionally, said adjusting the time data in the at least one slave device to synchronize with the time data of the master device by receiving the time stamp data and the correction signal includes:
Responsive to the received timestamp data, adjusting the at least one slave device to switch to a signal capture mode;
receiving the correction signal by the at least one slave device in the signal capture mode;
According to the signal duration of the correction signal, configuring a synchronous timer consistent with the timing frequency of the main equipment;
And adjusting the time data in the at least one slave device to be synchronous with the time data of the master device according to the time stamp data and the synchronous timer.
Optionally, the configuring the synchronization timer consistent with the master device timing frequency according to the signal duration of the correction signal includes:
Determining, by an internal timer of the at least one slave device, a timing duration of the corrective signal received by the at least one slave device;
and comparing the timing duration with the signal duration, and configuring a synchronous timer consistent with the timing frequency of the main equipment according to a comparison result.
Optionally, the determining, by the internal timer of the at least one slave device, a timing duration of the correction signal received by the at least one slave device includes:
Setting a signal path arranged between the master device and the at least one slave device to maintain a high level;
Starting the internal timer when the at least one slave device collects a level falling edge of the correction signal in a low level form;
closing the internal timer when the at least one slave device collects a level rising edge of the correction signal in a low level form;
and determining the timing duration according to the count value of the internal timer.
According to a second aspect of an embodiment of the present application, there is provided an MCU system time synchronization device, including:
a setting module configured to set a master device and at least one slave device in a target system, wherein the master device includes a reference time;
A generation module configured to generate time stamp data according to the reference time and to transmit the time stamp data to the at least one slave device through the master device according to a time granularity of the reference time;
a correction module configured to transmit a correction signal to the at least one slave device through the master device based on a preset interval time;
and the synchronization module is configured to adjust the time data in the at least one slave device to be synchronous with the time data of the master device through the received time stamp data and the correction signal.
The application provides a MCU system time synchronization method, which is characterized in that a master device and at least one slave device are arranged in a target system, wherein the master device comprises a reference time; generating time stamp data according to the reference time, and sending the time stamp data to the at least one slave device through the master device according to the time granularity of the reference time; transmitting, by the master device, a corrective signal to the at least one slave device based on a preset interval time; and adjusting the time data in the at least one slave device to be synchronous with the time data of the master device through the received time stamp data and the correction signal. The high-precision time synchronization inside the MCU system is realized, and meanwhile, as other devices are not required to be externally connected, the MCU system has high reliability, low cost and wide application range.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for the description of the embodiments will be briefly described below, and it is apparent that the drawings in the following description are only some embodiments of the present application, and other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
FIG. 1 is a flowchart of a method for synchronizing MCU system time according to an embodiment of the present application;
FIG. 2 is a connection diagram of a method for synchronizing MCU system time according to an embodiment of the present application;
FIG. 3 is a signal timing diagram of a method for time synchronization of an MCU system according to an embodiment of the present application;
FIG. 4 is a process flow diagram of an MCU system time synchronization method applied to an engineering mechanical arm according to an embodiment of the present application;
fig. 5 is a schematic structural diagram of an MCU system time synchronization device according to an embodiment of the present application.
Detailed Description
In the following description, numerous specific details are set forth in order to provide a thorough understanding of the present application. The present application may be embodied in many other forms than those herein described, and those skilled in the art will readily appreciate that the present application may be similarly embodied without departing from the spirit or essential characteristics thereof, and therefore the present application is not limited to the specific embodiments disclosed below.
The terminology used in the one or more embodiments of the application is for the purpose of describing particular embodiments only and is not intended to be limiting of the one or more embodiments of the application. As used in one or more embodiments of the application and the appended claims, the singular forms "a," "an," and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. It should also be understood that the term "and/or" as used in one or more embodiments of the present application refers to and encompasses any or all possible combinations of one or more of the associated listed items.
It should be understood that, although the terms first, second, etc. may be used in one or more embodiments of the application to describe various information, these information should not be limited by these terms. These terms are only used to distinguish one type of information from another. For example, a first may also be referred to as a second, and similarly, a second may also be referred to as a first, without departing from the scope of one or more embodiments of the application.
First, terms related to one or more embodiments of the present invention will be explained.
MCU: the micro control unit (Microcontroller Unit), also called a single chip Microcomputer (SINGLE CHIP Microcomputer) or a single chip Microcomputer, properly reduces the frequency and specification of a central processing unit (Central Process Unit; CPU), integrates peripheral interfaces such as a memory (memory), a counter (Timer), USB, A/D conversion, UART, PLC, DMA and the like, and even an LCD driving circuit on a single chip to form a chip-level computer, and performs different combination control for different application occasions.
Real-time clock chip: is one of the most widely used consumer electronic products in daily life. The real-time clock chip mainly adopts a crystal oscillator with higher precision as a clock source. Some clock chips can work when the main power supply is powered down, and additional batteries are needed for supplying power.
GPS real-time clock: basic time service application product developed based on latest GPS high-precision positioning time service module. The time information format conforming to the protocol can be output according to the requirements of users, so that synchronous time service is completed. The main principle is that the crystal oscillator is tamed through signals of a GPS or other satellite navigation systems, so that high-precision frequency and time signal output is realized, and the crystal oscillator is the most effective way for achieving nanosecond time service precision and stability in 1E12 order frequency output.
The application provides a MCU system time synchronization method. The application also relates to a time synchronization device of the MCU system, which is described in detail in the following embodiments.
Fig. 1 shows a flowchart of a method for synchronizing time of an MCU system according to an embodiment of the present application, which specifically includes the following steps:
step S101: setting a master device and at least one slave device in a target system, wherein the master device comprises a reference time;
Step S102: generating time stamp data according to the reference time, and sending the time stamp data to the at least one slave device through the master device according to the time granularity of the reference time;
Step S103: transmitting, by the master device, a corrective signal to the at least one slave device based on a preset interval time;
step S104: and adjusting the time data in the at least one slave device to be synchronous with the time data of the master device through the received time stamp data and the correction signal.
Specifically, the target system is an MCU system, and specific target systems, such as mobile phones, PC peripherals, remote controllers, automotive electronics, stepper motors, control of robotic arms, etc., are not unique, and the specific target system selection range is determined by actual user requirements, which is not limited in this embodiment.
As shown in the connection diagram of the MCU system time synchronization method provided in fig. 2, after a master device and a slave device are set in a target system, the master device has an output interface, any slave device has an input interface, and a communication time synchronization line is set between the master device and the slave device and is used as a signal path when the master device sends data to the slave device. The master device includes a module for generating the reference time, such as a real-time chip, a GPS real-time clock, a network time server, etc., and the mode of generating the reference time is not unique, the specific mode is determined by the actual use scenario, the embodiment is not limited, and the slave device is not limited as to whether the slave device has the module capable of generating the reference time.
In addition, the time granularity of the base time may be understood as the minimum time unit that can be displayed by the base time, for example, if the base time is "2024, 1 month, 1 day", then the time granularity is 1 day, and if the base time is "2024, 1 month, 1 day, 0 minute, 0 second", then the time granularity is 1 second.
Based on the above, after the master device and the slave device are set in the target system, the master device generates timestamp data through its own reference time, the timestamp data changes in real time along with the reference time, and with the time granularity as a time interval, the master device continuously transmits the current timestamp data to the slave device through communication time lines, if the time granularity is 1 second, and the current time is "0.0 minute 0 second", then the master device transmits the timestamp data corresponding to "0.0 minute 0 second" to the slave device, after the next second, the master device transmits the timestamp data corresponding to "0.0 minute 1 second" to the slave device, after the next second, the master device transmits the timestamp data corresponding to "0.0 minute 2 seconds" to the slave device, and so on.
Then, according to the preset interval time, the master device sends correction signals to the slave devices through the communication time pair line, and it is to be noted that the data of the interval time are not fixed, the specific interval time data are determined by the actual use situation, the embodiment is not limited, and finally, the slave device adjusts the time data in itself through the received time stamp data and the correction signal, so that the slave device aligns with the time data in the master device, and time synchronization is achieved.
In summary, in the actual use scene, each equipment in the target system carries out time synchronization, only need guarantee to exist a master device that possesses the reference time can, under this kind of circumstances, slave device need not to set up the module that is used for producing the reference time, such as real-time clock, GPS real-time clock, greatly reduced the cost, need not to set up extra module and components and parts in the target system in addition, the stability of target system is high, further need not to set up extra module and components and parts, just need not to set up extra power, the problem that the time can't be synchronous in the target system that the extra power electric quantity loss leads to has been avoided, in addition, the mode of physical connection also need not to receive the radio signal that sends with the help of equipment such as satellite signal, radio module, stability is high, can adapt to more service environment, and extensive applicability.
Further, in the process of time synchronization of each device included in the target system, the master device and the slave device need to be determined first, and in this embodiment, the specific implementation manner is as follows:
Determining a reference sub-module comprising a reference time module according to a use manual of the target system, and determining a device code of the reference sub-module; according to the device code, one of the reference sub-modules is selected as the master device in response to a received master device selection instruction, and other sub-devices in the target system are set as slave devices.
Or inquiring the parameters of the sub-equipment contained in the target system; determining a reference sub-module comprising a reference time module based on the sub-device parameters, and determining a device code of the reference sub-module; according to the device code, one of the reference sub-modules is selected as the master device in response to a received master device selection instruction, and other sub-devices in the target system are set as slave devices.
The process of inquiring the parameters of the sub-device may be determined by inquiring a usage manual of the target system, or may be determined by accessing the sub-device through related software, and the specific inquiring mode is determined by the actual usage scenario, which is not limited in this embodiment. The reference submodule may be understood as a component for generating a reference time, such as a real-time clock chip, a GPS real-time clock, etc., and the type of the specific reference submodule is determined by the actual use scenario, which is not limited in this embodiment.
Based on this, by querying the sub-device parameters of the sub-devices included in the target system, determining the sub-devices including the reference sub-module, and determining the device codes of these sub-devices, these device codes may be then presented to the user, and one of them may be selected by the user as the master device, or one of them may be automatically selected by a preset selection algorithm as the master device, and the specific adopted master device selection mode is determined by the actual use scenario, which is not limited in this embodiment.
And generating a main device selection instruction based on the selected sub device, and setting the selected sub device as the main device of the target system through the main device selection instruction, wherein other sub devices in the target system are used as the slave devices. The communication time synchronization line between the master device and the slave device may be constructed by adding a new physical connection line to the target system as the communication time synchronization line, or by calling an idle connection path between the original sub devices in the target system as the communication time synchronization line, where the specific communication time synchronization line construction is determined by the actual use scenario, and the embodiment is not limited.
In sum, by selecting one piece of sub-equipment in the target system as the main equipment, the time synchronization of the target system is guaranteed only through the reference time of the main equipment, the addition of the reference sub-modules of all the sub-equipment is avoided, and the cost is reduced.
Further, for the process of sending the timestamp data to the slave device, in this embodiment, the specific implementation manner is as follows:
And updating the time stamp data in real time according to the reference time, and sending the time stamp data to the at least one slave device through the master device by taking the time granularity as a period.
The master device updates the time stamp data in real time according to the reference time, and sends the current time stamp data to the slave device with the time granularity as a period, so that the slave device can continuously acquire the rough time of the master device from the time stamp data, and a basis is provided for the follow-up accurate time synchronization.
Further, in the process of sending the timestamp data from the master device to the slave device, the specific implementation manner in this embodiment is as follows:
Generating a serial data stream based on the timestamp data; transmitting the serial data stream from the master device to the at least one slave device through a signal path disposed between the master device and the at least one slave device; and the at least one slave device analyzes the received serial port data stream to obtain the timestamp data.
In the process of transmitting the time stamp data to the slave device, in order to avoid distortion of information transmission, the time stamp data needs to be compiled and transcoded. After receiving the serial data stream obtained by compiling and transcoding, the slave device needs to analyze the serial data stream to obtain timestamp data.
Based on the time stamp data, the serial port data stream is obtained by processing the time stamp data, the data is transmitted, the serial port data stream is used as a signal path of a signal transmission channel, the serial port data stream is sent to the slave device by the master device through the communication time line, and the slave device analyzes the received serial port data stream to obtain the time stamp data.
In addition, in the process of generating the serial port data stream, the time stamp data can be encrypted to obtain an encrypted serial port data stream, the encrypted serial port data stream is sent to the slave device, and the slave device decrypts the encrypted serial port data stream to obtain the time stamp data.
Further, in this embodiment, the specific implementation manner of the process that the master device sends the correction signal to the slave device is as follows:
And after the master device transmits the time stamp data, waiting for the interval time, and transmitting the correction signal to the at least one slave device through the master device.
The master device starts to count after sending the time stamp data until the count time is equal to a preset interval time, and the master device sends a correction signal to the slave device.
Based on the above, the slave device can determine the time data of the current master device at the moment of receiving the correction signal according to the known interval time, and specifically, the reference time and the interval time recorded in the time stamp data are the current time data of the master device. Note that, the selection of the interval time is determined by the actual use scenario, and the present embodiment is not limited.
However, in the actual use scenario, the interval time is often selected to be smaller than the time granularity of the reference time, which ensures that the time synchronization process is concentrated in a time granularity range after the current time stamp data and before the next time stamp data each time when the correction signal is sent each time, thereby increasing the timeliness of time synchronization of each piece of sub-equipment in the system, avoiding the problem of data signal confusion caused by dispersing the time synchronization process and reducing the time synchronization efficiency.
As shown in a signal timing diagram of an MCU system time synchronization method provided in fig. 3, each 0 ms is a starting time point when timestamp data is sent from a master device to a slave device, and if a time consumption of sending the timestamp data is 10 ms, a time point when the timestamp data is sent from the master device to the slave device is 10 ms, an interval time is set to be 100 ms, and then, a correction signal is sent when the 100 th ms.
Further, according to the timestamp data and the correction signal, a time synchronization process is performed on each piece of sub-equipment in the target system, and in this embodiment, the specific implementation manner is as follows:
Responsive to the received timestamp data, adjusting the at least one slave device to switch to a signal capture mode; receiving the correction signal by the at least one slave device in the signal capture mode; according to the signal duration of the correction signal, configuring a synchronous timer consistent with the timing frequency of the main equipment; and adjusting the time data in the at least one slave device to be synchronous with the time data of the master device according to the time stamp data and the synchronous timer.
The correction signal is used for synchronizing the timing frequency of the slave device to the timing frequency of the master device, and the timing frequency synchronization process needs to involve higher time precision, so that the slave device is switched to a signal capturing mode which is focused on collecting signals transmitted on a communication time synchronization line, and the duration of the signal capturing mode is not too long in order to ensure the completion efficiency of other tasks of the slave device in the operation process, so that the slave device in the signal capturing mode can be set to be started after receiving time stamp data, and the slave device is finished after receiving the correction signal.
Based on the method, the slave equipment in the signal capturing mode is started to collect the correction signal, the timing duration of the collected correction signal is determined, and the determined timing duration can be determined by recording the starting time and the ending time of the correction signal.
Further, by recording the start time and the end time of the correction signal, the timing duration is determined, and in this embodiment, the specific implementation manner is as follows:
Determining, by an internal timer of the at least one slave device, a timing duration of the corrective signal received by the at least one slave device; and comparing the timing duration with the signal duration, and configuring a synchronous timer consistent with the timing frequency of the main equipment according to a comparison result.
Because the target system is an MCU system, the internal sub-equipment comprises circuits such as a multivibrator, a monostable trigger, an RC oscillator and the like formed by elements, and a timer is constructed based on the circuits.
Based on the above, the internal timer of the slave device starts to count when receiving the correction signal, and stops counting after receiving the correction signal, so that the count duration of the slave device can be determined. In the process of transmitting the correction signal, the master device transmits the correction signal with preset signal duration through the timing of an internal timer, which means that the signal duration is related to the timing frequency of the master device, and the timing duration is related to the timing frequency of the slave device. And determining the ratio relation between the timing frequency of the slave device and the timing frequency of the master device through the ratio of the timing duration to the signal duration, and constructing a synchronous timer with the timing frequency of the master device by the slave device.
Further, by timing the start time and the end time of the correction signal, the timing duration is determined, and the content of the correction signal does not affect the confirmation of the signal duration, so that the correction signal can be represented by the level signal, and in this embodiment, the following specific embodiments are provided:
Setting a signal path arranged between the master device and the at least one slave device to maintain a high level; starting the internal timer when the at least one slave device collects a level falling edge of the correction signal in a low level form; closing the internal timer when the at least one slave device collects a level rising edge of the correction signal in a low level form; and determining the timing duration according to the count value of the internal timer.
Wherein a communication pair line between a master device and a slave device is set to maintain a constant level under a limited condition, and the level is changed when information is transmitted, in which case, a signal of a level opposite to the communication pair line is transmitted as a correction signal, however, in the conventional use again, in the case where a bottom level is maintained in the communication pair line, voltage noise is easily generated by external interference, and may cause incorrect time synchronization of a target system, in order to avoid this, a high level is maintained in a communication time line, and a low level signal is used as a correction signal, as shown in a signal timing diagram of an MCU system time synchronization method provided in fig. 3.
Based on the method, after the slave device receives the time stamp signal in the communication time line, the slave device switches to a signal capturing mode, waits for receiving the correction signal and timing the correction signal, when the slave device receives the falling edge of the level, the slave device starts a timer, collects the duration of the low-level signal, and when the slave device receives the rising edge of the level, the slave device closes the timer to realize the determination of the timing duration.
Specifically, the signal duration of the correction signal is generally set to be in the millisecond level, and the too short signal duration is unfavorable for the acquisition of the correction signal by the slave device, for example, the timing frequency of a timer in the slave device is 1 mhz, in this case, the minimum period of the timer is greater than the signal duration of the correction signal, the correction signal cannot be timed, in addition, the signal duration of the correction signal is not suitable for the correction signal with too long signal duration, so that the timing time length is slow, and the time synchronization efficiency of the target system is further affected.
The following is a description of the MCU system time synchronization method provided by the present application, taking the application of the MCU system time synchronization method to the engineering mechanical arm as an example, with reference to fig. 4. Fig. 4 shows a process flow chart of an MCU system time synchronization method applied to an engineering mechanical arm according to an embodiment of the present application, specifically including the following steps:
s401: inquiring the parameters of the sub-equipment contained in the target system.
Specifically, in the time synchronization processing of the sub-equipment 1-10 contained in the MCU system in the engineering mechanical arm, firstly, the equipment parameters of the sub-equipment 1-10 in the MCU system are queried through engineering software associated with the engineering mechanical arm.
S402: and determining a reference sub-module comprising a reference time module based on the sub-device parameters, and determining a device code of the reference sub-module.
Specifically, it is determined that the sub-device 1 includes a real-time clock chip, the sub-devices 2 to 10 do not have the real-time clock chip, the device code of the sub-device 1 is determined, and the device code of the sub-device 1 is displayed on a display interface of engineering software.
S403: according to the device code, one of the reference sub-modules is selected as the master device in response to a received master device selection instruction, and other sub-devices in the target system are set as slave devices.
Specifically, the user selects the sub-device 1 on the engineering software, the engineering software sets the sub-device 1 as the master device and the sub-devices 2 to 10 as the slave devices in response to the selection instruction, it is to be noted that the sub-devices 1 to 10 are previously provided with data transmission lines for communication, the data transmission lines are maintained at high levels after the master device and the slave devices are set, and the ports of the sub-devices 1 to which the data transmission lines are connected are set as output ports for data output, and the ports of the sub-devices 2 to 10 to which the data transmission lines are connected are set as input ports for data input.
S404: and updating the time stamp data in real time according to the reference time, and sending the time stamp data to the at least one slave device through the master device by taking the time granularity as a period.
Specifically, the slave device 1 records the reference time in the form of "/year/month/day/time second", generates the timestamp data in the form of a character string according to the reference time in the slave device, generates the serial data stream by compiling and transcoding operation, and transmits the serial data stream corresponding to the current reference time to the slave devices 2-10 through the data transmission line at the beginning of each second. After receiving the serial data stream, the sub-device 2-10 analyzes the serial data stream to obtain timestamp data carrying the reference time of the current sub-device 1.
S405: and after the master device transmits the time stamp data, waiting for the interval time, and transmitting the correction signal to the at least one slave device through the master device.
Specifically, the slave device 1 re-transmits a1 ms low level signal to the slave devices 2-10 every 100 ms after transmitting the serial data stream. The process of the slave device 1 sending the low level of 1 millisecond is that the slave device 1 controls the output port of the slave device 1 to output the low level signal, and simultaneously starts the internal timer of the slave device 1 until the internal timer timing time of the slave device 1 reaches 1 millisecond, and the slave device 1 stops outputting the low level signal.
S406: and adjusting the at least one slave device to switch to a signal capture mode in response to the received timestamp data.
Specifically, the slave devices 2-10 will adjust to the low level capture mode after receiving the serial data stream.
S407: and starting the internal timer when the at least one slave device collects the level falling edge of the correction signal in the low level form.
Specifically, when the slave device 2-10 collects the falling edge of the low level signal, the current time is determined, and the internal time of the slave device 1 is the reference time contained in the latest time stamp data, plus 100 milliseconds. The kid device 2-10 starts an internal timer at this point.
S408: and closing the internal timer when the at least one slave device collects a level rising edge of the correction signal in a low level form.
Specifically, when the slave device 2-10 collects the rising edge of the low level signal, the slave device 2-10 turns off its own internal timer.
S409: and determining the timing duration according to the count value of the internal timer.
Specifically, the sub-devices 2 to 10 determine the count duration based on the count value of their own internal timer.
S410: and comparing the timing duration with the signal duration, and configuring a synchronous timer consistent with the timing frequency of the main equipment according to a comparison result.
Specifically, the slave devices 2-10 determine the count duration acquired by the internal timer of the slave device, and adjust the timing frequency of the internal timer of the slave device 1 corresponding to the duration of the internal timer of the slave device 1 for 1 millisecond, so as to obtain the synchronous timer with the same timing frequency as the internal timer of the slave device 1.
S411: and adjusting the time data in the at least one slave device to be synchronous with the time data of the master device according to the time stamp data and the synchronous timer.
Specifically, the sub-equipment 2-10 obtains the same time data as the sub-equipment 1 by combining the reference time in the time stamp data and the synchronous timer with the same timing frequency as the sub-equipment 1, and completes the time synchronization of the MCU system in the engineering mechanical arm.
In summary, a master device and at least one slave device are set in a target system, wherein the master device comprises a reference time; generating time stamp data according to the reference time, and sending the time stamp data to the at least one slave device through the master device according to the time granularity of the reference time; transmitting, by the master device, a corrective signal to the at least one slave device based on a preset interval time; and adjusting the time data in the at least one slave device to be synchronous with the time data of the master device through the received time stamp data and the correction signal. The time synchronization of each device in the target system is realized, only the master device with the reference time is required to be ensured, under the condition, the slave device does not need to be provided with a module for generating the reference time, such as a real-time clock chip, a GPS real-time clock and the like, the cost is greatly reduced, in addition, the target system does not need to be provided with an additional module and components, the stability of the target system is high, the additional module and components are further not required to be provided, the additional power supply is not required, the problem that the time in the target system cannot be synchronized due to the loss of the electric quantity of the additional power supply is avoided, in addition, the wireless signal transmitted by the devices such as satellite signals and wireless modules is not required to be received by a physical connection mode, the stability is high, the method can adapt to more use environments and the applicability is wide.
Corresponding to the above method embodiment, the present application further provides an embodiment of an MCU system time synchronization device, and fig. 5 shows a schematic structural diagram of an MCU system time synchronization device according to an embodiment of the present application. As shown in fig. 5, the apparatus includes:
A setting module 502, configured to set a master device and at least one slave device in a target system, where the master device includes a reference time;
A generation module 504 configured to generate time stamp data according to the reference time and to send the time stamp data to the at least one slave device by the master device according to a time granularity of the reference time;
a correction module 506 configured to send a correction signal to the at least one slave device through the master device based on a preset interval time;
A synchronization module 508 configured to adjust the time data in the at least one slave device to be synchronized with the time data of the master device by the received time stamp data and the correction signal.
In an alternative embodiment, the setting module 502 is further configured to:
Determining a reference sub-module comprising a reference time module according to a use manual of the target system, and determining a device code of the reference sub-module;
according to the device code, one of the reference sub-modules is selected as the master device in response to a received master device selection instruction, and other sub-devices in the target system are set as slave devices.
In an alternative embodiment, the setting module 502 is further configured to:
Inquiring sub-equipment parameters contained in the target system; determining a reference sub-module comprising a reference time module based on the sub-device parameters, and determining a device code of the reference sub-module; according to the device code, one of the reference sub-modules is selected as the master device in response to a received master device selection instruction, and other sub-devices in the target system are set as slave devices.
In an alternative embodiment, the generating module 504 is further configured to:
And updating the time stamp data in real time according to the reference time, and sending the time stamp data to the at least one slave device through the master device by taking the time granularity as a period.
In an alternative embodiment, the generating module 504 is further configured to:
Generating a serial data stream based on the timestamp data; transmitting the serial data stream from the master device to the at least one slave device through a signal path disposed between the master device and the at least one slave device; and the at least one slave device analyzes the received serial port data stream to obtain the timestamp data.
In an alternative embodiment, the remediation module 506 is further configured to:
And after the master device transmits the time stamp data, waiting for the interval time, and transmitting the correction signal to the at least one slave device through the master device.
In an alternative embodiment, the synchronization module 508 is further configured to:
Responsive to the received timestamp data, adjusting the at least one slave device to switch to a signal capture mode; receiving the correction signal by the at least one slave device in the signal capture mode; according to the signal duration of the correction signal, configuring a synchronous timer consistent with the timing frequency of the main equipment; and adjusting the time data in the at least one slave device to be synchronous with the time data of the master device according to the time stamp data and the synchronous timer.
In an alternative embodiment, the synchronization module 508 is further configured to:
Determining, by an internal timer of the at least one slave device, a timing duration of the corrective signal received by the at least one slave device; and comparing the timing duration with the signal duration, and configuring a synchronous timer consistent with the timing frequency of the main equipment according to a comparison result.
In an alternative embodiment, the synchronization module 508 is further configured to:
Setting a signal path arranged between the master device and the at least one slave device to maintain a high level; starting the internal timer when the at least one slave device collects a level falling edge of the correction signal in a low level form; closing the internal timer when the at least one slave device collects a level rising edge of the correction signal in a low level form; and determining the timing duration according to the count value of the internal timer.
The application provides an MCU system time synchronization device, which is characterized in that a master device and at least one slave device are arranged in a target system, wherein the master device comprises a reference time; generating time stamp data according to the reference time, and sending the time stamp data to the at least one slave device through the master device according to the time granularity of the reference time; transmitting, by the master device, a corrective signal to the at least one slave device based on a preset interval time; and adjusting the time data in the at least one slave device to be synchronous with the time data of the master device through the received time stamp data and the correction signal. The time synchronization of each device in the target system is realized, only the master device with the reference time is required to be ensured, under the condition, the slave device does not need to be provided with a module for generating the reference time, such as a real-time clock chip, a GPS real-time clock and the like, the cost is greatly reduced, in addition, the target system does not need to be provided with an additional module and components, the stability of the target system is high, the additional module and components are further not required to be provided, the additional power supply is not required, the problem that the time in the target system cannot be synchronized due to the loss of the electric quantity of the additional power supply is avoided, in addition, the wireless signal transmitted by the devices such as satellite signals and wireless modules is not required to be received by a physical connection mode, the stability is high, the method can adapt to more use environments and the applicability is wide.
The above is a schematic scheme of the MCU system time synchronization device of this embodiment. It should be noted that, the technical solution of the MCU system time synchronization device and the technical solution of the MCU system time synchronization method described above belong to the same concept, and details of the technical solution of the MCU system time synchronization device not described in detail may be referred to the description of the technical solution of the MCU system time synchronization method described above. Furthermore, the components in the apparatus embodiments should be understood as functional blocks that must be established to implement the steps of the program flow or the steps of the method, and the functional blocks are not actually functional partitions or separate limitations. The device claims defined by such a set of functional modules should be understood as a functional module architecture for implementing the solution primarily by means of the computer program described in the specification, and not as a physical device for implementing the solution primarily by means of hardware.
It should be noted that, for the sake of simplicity of description, the foregoing method embodiments are all expressed as a series of combinations of actions, but it should be understood by those skilled in the art that the present application is not limited by the order of actions described, as some steps may be performed in other order or simultaneously in accordance with the present application. Further, those skilled in the art will appreciate that the embodiments described in the specification are all preferred embodiments, and that the acts and modules referred to are not necessarily all required for the present application.
In the foregoing embodiments, the descriptions of the embodiments are emphasized, and for parts of one embodiment that are not described in detail, reference may be made to the related descriptions of other embodiments.
The preferred embodiments of the application disclosed above are intended only to assist in the explanation of the application. Alternative embodiments are not intended to be exhaustive or to limit the application to the precise form disclosed. Obviously, many modifications and variations are possible in light of the above teaching. The embodiments were chosen and described in order to best explain the principles of the application and the practical application, to thereby enable others skilled in the art to best understand and utilize the application. The application is limited only by the claims and the full scope and equivalents thereof.

Claims (9)

1. An MCU system time synchronization method, comprising:
Setting a master device and at least one slave device in a target system, wherein the master device comprises a reference time;
Generating time stamp data according to the reference time, and sending the time stamp data to the at least one slave device through the master device according to the time granularity of the reference time;
Transmitting a correction signal to the at least one slave device through the master device based on a preset interval time, specifically, waiting for the interval time after the master device transmits the timestamp data, and transmitting the correction signal to the at least one slave device through the master device, wherein the interval time is selected to be smaller than the time granularity of the reference time;
and adjusting the time data in the at least one slave device to be synchronous with the time data of the master device through the received time stamp data and the correction signal.
2. The method of claim 1, wherein said providing a master device and at least one slave device in the target system comprises:
inquiring sub-equipment parameters contained in the target system;
Determining a reference sub-module comprising a reference time module based on the sub-device parameters, and determining a device code of the reference sub-module;
according to the device code, one of the reference sub-modules is selected as the master device in response to a received master device selection instruction, and other sub-devices in the target system are set as slave devices.
3. The method of claim 1, wherein said providing a master device and at least one slave device in the target system comprises:
Determining a reference sub-module comprising a reference time module according to a use manual of the target system, and determining a device code of the reference sub-module;
according to the device code, one of the reference sub-modules is selected as the master device in response to a received master device selection instruction, and other sub-devices in the target system are set as slave devices.
4. The method of claim 1, wherein the sending, by the master device, the timestamp data to the at least one slave device according to the time granularity of the reference time, comprises:
And updating the time stamp data in real time according to the reference time, and sending the time stamp data to the at least one slave device through the master device by taking the time granularity as a period.
5. The method of claim 1, wherein the sending, by the master device, the timestamp data to the at least one slave device comprises:
Generating a serial data stream based on the timestamp data;
Transmitting the serial data stream from the master device to the at least one slave device through a signal path disposed between the master device and the at least one slave device;
and the at least one slave device analyzes the received serial port data stream to obtain the timestamp data.
6. The method of claim 1, wherein said adjusting the time data in the at least one slave device to be synchronized with the time data of the master device by the received time stamp data and the correction signal comprises:
Responsive to the received timestamp data, adjusting the at least one slave device to switch to a signal capture mode;
receiving the correction signal by the at least one slave device in the signal capture mode;
According to the signal duration of the correction signal, configuring a synchronous timer consistent with the timing frequency of the main equipment;
And adjusting the time data in the at least one slave device to be synchronous with the time data of the master device according to the time stamp data and the synchronous timer.
7. The method of claim 6, wherein configuring a synchronization timer consistent with the master device timing frequency based on the signal duration of the correction signal comprises:
Determining, by an internal timer of the at least one slave device, a timing duration of the corrective signal received by the at least one slave device;
and comparing the timing duration with the signal duration, and configuring a synchronous timer consistent with the timing frequency of the main equipment according to a comparison result.
8. The method of claim 7, wherein said determining, by an internal timer of said at least one slave device, a timing duration of said corrective signal received by said at least one slave device comprises:
Setting a signal path arranged between the master device and the at least one slave device to maintain a high level;
Starting the internal timer when the at least one slave device collects a level falling edge of the correction signal in a low level form;
closing the internal timer when the at least one slave device collects a level rising edge of the correction signal in a low level form;
and determining the timing duration according to the count value of the internal timer.
9. An MCU system time synchronization device, comprising:
a setting module configured to set a master device and at least one slave device in a target system, wherein the master device includes a reference time;
A generation module configured to generate time stamp data according to the reference time and to transmit the time stamp data to the at least one slave device through the master device according to a time granularity of the reference time;
The correction module is configured to send a correction signal to the at least one slave device through the master device based on a preset interval time, specifically, after the master device sends the timestamp data, waiting for the interval time, and sending the correction signal to the at least one slave device through the master device, wherein the interval time is selected to be smaller than the time granularity of the reference time;
and the synchronization module is configured to adjust the time data in the at least one slave device to be synchronous with the time data of the master device through the received time stamp data and the correction signal.
CN202410825658.XA 2024-06-25 2024-06-25 MCU system time synchronization method and device Active CN118381577B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202410825658.XA CN118381577B (en) 2024-06-25 2024-06-25 MCU system time synchronization method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202410825658.XA CN118381577B (en) 2024-06-25 2024-06-25 MCU system time synchronization method and device

Publications (2)

Publication Number Publication Date
CN118381577A CN118381577A (en) 2024-07-23
CN118381577B true CN118381577B (en) 2024-08-30

Family

ID=91904248

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202410825658.XA Active CN118381577B (en) 2024-06-25 2024-06-25 MCU system time synchronization method and device

Country Status (1)

Country Link
CN (1) CN118381577B (en)

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101977104A (en) * 2010-11-13 2011-02-16 上海交通大学 IEEE1588 based accurate clock synchronization protocol system and synchronization method thereof

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9319054B2 (en) * 2011-09-27 2016-04-19 Anue Systems, Inc. Systems and methods utilizing randomized clock rates to reduce systematic time-stamp granularity errors in network packet communications
US9112631B2 (en) * 2013-09-11 2015-08-18 Khalifa University of Science, Technology, and Research Method and devices for frequency distribution
EP3420655B1 (en) * 2016-02-25 2020-05-20 Khalifa University of Science and Technology Methods and systems for estimating frequency synchronization accuracy
WO2021131583A1 (en) * 2019-12-25 2021-07-01 ソニーセミコンダクタソリューションズ株式会社 Synchronization device and synchronization method

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101977104A (en) * 2010-11-13 2011-02-16 上海交通大学 IEEE1588 based accurate clock synchronization protocol system and synchronization method thereof

Also Published As

Publication number Publication date
CN118381577A (en) 2024-07-23

Similar Documents

Publication Publication Date Title
CN102013967A (en) 1588 protocol-based beidou time synchronization device and application thereof
CN109074723B (en) Time synchronization method, sensor embedded terminal and sensor network system
CN112866098B (en) Gateway time service method, device, electronic equipment and computer readable medium
CN102830611B (en) Time source
CN109996325B (en) Clock synchronization system and method of wireless sensor network
CN105867109A (en) Self-timing pointer type intelligent clock and time service method thereof
CN114114344A (en) A portable satellite positioning and timing equipment
CN102158950A (en) Clock synchronization method, system, device and base station
CN111831056A (en) Real-time clock calibration module and method and real-time clock chip
CN117320144A (en) Primary and secondary clock time synchronization method and system based on wireless communication
CN118381577B (en) MCU system time synchronization method and device
CN111102689A (en) Method and device for adjusting clock synchronization
CN118963097A (en) A shared mobile timekeeping device and method
CN210776231U (en) Multi-time-scale source time system circuit board
CN209949115U (en) Multi-clock source integrated network time system card
CN107659369B (en) Clock synchronization device and synchronization method for positioning base station
CN112995938A (en) Synchronous acquisition method for sensors in field of power Internet of things
CN117270377A (en) Standard clock device based on Beidou common-view tame crystal oscillator
CN114567405A (en) Time synchronization method based on time deviation, terminal and storage medium
CN116157786A (en) Synchronous data processing method and equipment
CN110247724B (en) Portable parking lot time synchronization system and method
JP2004023350A (en) Base station, communication method, communication program, and computer-readable recording medium stored with the communication program
Terraneo et al. FLOPSYNC-QACS: quantization-aware clock synchronization for wireless sensor networks
CN221686845U (en) A pointer clock that synchronizes and manages time via a WIFI network
CN215601307U (en) A Multimodal Tamed Time Server System

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
GR01 Patent grant
GR01 Patent grant