Time keeping method, terminal equipment and computer readable storage medium

By training a prediction model in a time synchronization device and using the latest acquired data to predict frequency deviation, the problem of low timekeeping accuracy of crystal oscillators in dynamic environments is solved, achieving higher timekeeping accuracy and system reliability.

CN121978879APending Publication Date: 2026-05-05CYG SUNRI CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
CYG SUNRI CO LTD
Filing Date
2025-12-24
Publication Date
2026-05-05

AI Technical Summary

Technical Problem

In complex station environments, satellite signals are susceptible to electromagnetic interference, weather changes, building obstruction, or deceptive signals, leading to time synchronization interruptions. Existing timekeeping methods based on crystal oscillators cannot adapt to dynamic environmental changes, especially when out of sync for extended periods, resulting in low timekeeping accuracy.

Method used

By acquiring the latest data before the time synchronization device switches to the crystal oscillator's timekeeping state, a prediction model is trained. The prediction model is then used to predict frequency deviation. By combining data from different sampling frequencies, the model is trained to capture instantaneous details and long-term trends. This results in a prediction model that adapts to environmental changes and improves timekeeping accuracy.

Benefits of technology

It improves the timekeeping accuracy and reliability of the time synchronization device in dynamic environments, reduces failures caused by model prediction errors, and enhances the stability of the system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121978879A_ABST
    Figure CN121978879A_ABST
Patent Text Reader

Abstract

The invention is applicable to the technical field of clock synchronization, and provides a time keeping method, terminal equipment and a computer readable storage medium, which are applied to a time synchronization device, and the time synchronization device comprises a crystal oscillator. The time keeping method comprises the following steps: when the time synchronization device is switched from a first state to a second state, obtaining a prediction model obtained by training first collected data when the time synchronization device is in the first state; according to the prediction model, prediction frequency deviation corresponding to each control moment in the second state is obtained in sequence; and controlling the time synchronization device to carry out time keeping according to the predicted frequency deviation corresponding to each control moment in the second state. Wherein the time synchronization device carries out time keeping based on an external reference time source in the first state, and the time synchronization device carries out time keeping based on a crystal oscillator in the second state. Through the mode, the time keeping precision can be effectively improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application belongs to the field of clock synchronization technology, and in particular relates to a timekeeping method, terminal equipment and computer-readable storage medium. Background Technology

[0002] In digital substations and smart grids, the coordinated operation of relay protection, fault recording, measurement and control, monitoring, and communication equipment all rely on a unified, high-precision time reference, with time synchronization accuracy reaching the microsecond level. Currently, time synchronization devices typically utilize the BeiDou satellite system as their time reference source.

[0003] In complex station environments, satellite signals are susceptible to electromagnetic interference, weather changes, building obstructions, or deceptive signals, leading to receiver loss and time synchronization interruptions. When an external reference time source fails, the time synchronization device relies on its own crystal oscillator for timekeeping. However, existing crystal oscillator-based timekeeping methods cannot adapt to dynamic environmental changes, especially in cases of prolonged time synchronization loss, resulting in low timekeeping accuracy. Summary of the Invention

[0004] This application provides a timekeeping method, a terminal device, and a computer-readable storage medium, which can effectively improve timekeeping accuracy.

[0005] In a first aspect, embodiments of this application provide a timekeeping method applied to a time synchronization device, the time synchronization device including a crystal oscillator; the timekeeping method includes: When the time synchronization device switches from a first state to a second state, it acquires a prediction model trained based on the first acquisition data when the time synchronization device is in the first state. In the first state, the time synchronization device maintains time based on an external reference time source, while in the second state, it maintains time based on the crystal oscillator. The first acquisition data includes multiple first data packets corresponding to different first acquisition times. Each first data packet corresponding to a first acquisition time includes a target reference time, environmental data, and a historical frequency deviation sequence between the crystal oscillator's frequency and the external reference time source. The prediction model is used to predict the frequency deviation between the crystal oscillator and the external reference time source based on the target reference time, the environmental data, and the historical frequency deviation sequence. Acquire target data; wherein, the target data is the latest set of first data packets acquired by the time synchronization device before entering the second state; Based on the target data and the prediction model, the prediction frequency deviation corresponding to each control moment in the second state is obtained sequentially. In the second state, the time synchronization device is controlled to keep time according to the predicted frequency deviation corresponding to each control moment.

[0006] In this embodiment, when the time synchronization device switches to the state of timekeeping based on its own crystal oscillator (i.e., the second state), the frequency deviation is predicted based on the latest acquired data before the time synchronization device enters the second state. Since the data acquired before entering the second state is actual data, using this data as a benchmark for frequency prediction is equivalent to determining a relatively accurate benchmark data for prediction, providing a reliable data basis for subsequent timekeeping. In addition, after entering the second state, the frequency deviation is predicted based on a trained prediction model. The prediction model is trained based on historical target benchmark time, historical environmental data, and historical frequency deviation sequences. Therefore, the frequency deviation predicted by the prediction model can adapt to dynamic environmental changes and is closer to the historical frequency deviation pattern, thereby effectively improving the timekeeping accuracy of the crystal oscillator.

[0007] In one possible implementation of the first aspect, the method further includes: When the time synchronization device switches from the second state to the first state, it acquires the second acquisition data of the time synchronization device; wherein, the second acquisition data includes a second data packet corresponding to a plurality of second acquisition times, and each second data packet corresponding to the second acquisition time includes the target reference time, environmental data, and the historical frequency deviation sequence between the crystal oscillator frequency and the external reference time source corresponding to the second acquisition time; The prediction model is updated based on the second collected data to obtain the updated prediction model.

[0008] In the above method, after the signal of the external reference time source is recovered, the prediction model continues to be updated based on the data collected by the time synchronization device in the first state. Through this continuous update method, the prediction model can continuously adapt to changes in the external environment, making the predicted frequency deviation more accurate, thereby improving the timekeeping accuracy.

[0009] In one possible implementation of the first aspect, obtaining the prediction model trained based on the first collected data when the time synchronization device is in the first state includes: Obtain the first collected data; The first collected data is sampled to obtain the third collected data; wherein the sampling frequency of the third collected data is lower than the sampling frequency of the first collected data. The initial model is trained based on the first collected data to obtain the first model; The initial model is trained based on the third collected data to obtain the second model; The prediction model is constructed based on the first model and the second model.

[0010] In the above method, it is equivalent to training two models based on data with different sampling frequencies. The model trained on high-frequency data is good at capturing instantaneous details and high-frequency changes, while the model trained on low-frequency data is good at capturing long-term trends and overall patterns. Therefore, the prediction model built based on the two models can detect both the key features at the level of data details and the overall trend of data, which effectively improves the generalization ability of the prediction model and helps to improve the prediction accuracy of the prediction model.

[0011] In one possible implementation of the first aspect, obtaining the prediction frequency deviation corresponding to each control moment in the second state based on the target data and the prediction model includes: For the first moment, the target data is input into the first model to obtain the first output; wherein, the first moment is the first control moment after the time synchronization device switches from the first state to the second state; The target data is input into the second model to obtain the second output; The predicted frequency deviation corresponding to the first time moment is calculated based on the first output and the second output.

[0012] In the above approach, the first model is a model trained on high-frequency data and is good at capturing instantaneous details and high-frequency changes, while the second model is a model trained on low-frequency data and is good at capturing long-term trends and overall patterns. The predicted frequency deviation calculated based on the output data of the first and second models not only conforms to the key features at the level of data details but also combines the overall trend of the data. Therefore, the predicted frequency deviation is more accurate, which helps to improve the timekeeping accuracy.

[0013] In one possible implementation of the first aspect, after calculating the prediction frequency deviation corresponding to the first time moment based on the first output and the second output, the method further includes: The confidence level of the prediction model is calculated based on the prediction frequency deviation corresponding to the first time point; If the confidence level is lower than a preset threshold, then exit the second state.

[0014] In the above method, exiting crystal oscillator timekeeping when the confidence level of the prediction model is low can reduce timekeeping failures caused by large errors in the model prediction results, thus improving the reliability of the system.

[0015] In one possible implementation of the first aspect, the time synchronization device includes two receiving modules, which are used to receive time information from different external reference time sources respectively; The acquisition of the first collected data includes: For each of the first acquisition moments, obtain the time information received by each of the receiving modules; Calculate the signal quality for each of the receiving modules; Calculate the target reference time corresponding to the first acquisition moment based on the signal quality and time information corresponding to each of the receiving modules; Obtain the environmental data and historical frequency deviation sequence corresponding to the first acquisition time; The first data packet corresponding to the first acquisition time is generated based on the target reference time, the environmental data, and the historical frequency deviation sequence corresponding to the first acquisition time.

[0016] In the above method, the target reference time is determined by fusing the time information from different external reference time sources. This effectively reduces the time deviation caused by occasional failures of a single external reference time source, which helps to improve the timekeeping accuracy and reliability of the system.

[0017] In one possible implementation of the first aspect, controlling the time synchronization device to maintain time according to the predicted frequency deviation corresponding to each control moment in the second state includes: For each control moment, the average frequency of the crystal oscillator is obtained; wherein, the average frequency is the average value of the output frequency of the crystal oscillator corresponding to each of the first acquisition moments when the time synchronization device is in the first state; Calculate the target output frequency corresponding to the control time based on the average frequency and the predicted frequency deviation corresponding to the control time; The output compensation voltage corresponding to the control moment is calculated based on the target output frequency corresponding to the control moment and the preset sensitivity coefficient. The crystal oscillator is controlled to perform timekeeping based on the output compensation voltage corresponding to the control time.

[0018] In one possible implementation of the first aspect, after obtaining the target reference time corresponding to the first acquisition time, the method further includes: The crystal oscillator is time-controlled according to the target reference time corresponding to the first acquisition time.

[0019] Secondly, embodiments of this application provide a time synchronization device, including: The model acquisition unit is used to acquire a prediction model trained based on the first acquisition data of the time synchronization device when it switches from a first state to a second state. In the first state, the time synchronization device maintains time based on an external reference time source, and in the second state, it maintains time based on the crystal oscillator. The first acquisition data includes multiple first data packets corresponding to different first acquisition times. Each first data packet corresponding to a first acquisition time includes a target reference time, environmental data, and a historical frequency deviation sequence between the crystal oscillator's crystal frequency and the external reference time source. The prediction model is used to predict the frequency deviation between the crystal oscillator and the external reference time source based on the target reference time, the environmental data, and the historical frequency deviation sequence. A data acquisition unit is used to acquire target data; wherein the target data is the latest set of first data packets acquired by the time synchronization device before entering the second state; The frequency prediction unit is used to obtain the predicted frequency deviation corresponding to each control moment in the second state in sequence according to the target data and the prediction model. A timekeeping control unit is used to control the time synchronization device to keep time in the second state according to the predicted frequency deviation corresponding to each control moment.

[0020] Thirdly, embodiments of this application provide a terminal device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the timekeeping method as described in any one of the first aspects above.

[0021] Fourthly, embodiments of this application provide a computer-readable storage medium storing a computer program that, when executed by a processor, implements the timekeeping method as described in any one of the first aspects above.

[0022] Fifthly, embodiments of this application provide a computer program product that, when run on a terminal device, causes the terminal device to execute the timekeeping method described in any one of the first aspects.

[0023] It is understood that the beneficial effects of the second to fifth aspects mentioned above can be found in the relevant descriptions in the first aspect mentioned above, and will not be repeated here. Attached Figure Description

[0024] To more clearly illustrate the technical solutions in the embodiments of this application, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0025] Figure 1 This is a flowchart illustrating the timekeeping method provided in an embodiment of this application; Figure 2 This is a schematic diagram of the model training process provided in the embodiments of this application; Figure 3 This is a schematic diagram of the overall workflow of the time synchronization device provided in the embodiments of this application; Figure 4 This is a structural block diagram of the timekeeping device provided in the embodiments of this application; Figure 5 This is a schematic diagram of the structure of the terminal device provided in the embodiments of this application. Detailed Implementation

[0026] In the following description, specific details such as particular system architectures and techniques are set forth for illustrative purposes and not for limitation, in order to provide a thorough understanding of the embodiments of this application. However, those skilled in the art will understand that this application may also be implemented in other embodiments without these specific details. In other instances, detailed descriptions of well-known systems, apparatuses, circuits, and methods have been omitted so as not to obscure the description of this application with unnecessary detail.

[0027] It should be understood that, when used in this application specification and the appended claims, the term "comprising" indicates the presence of the described features, integrals, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components and / or a collection thereof.

[0028] It should also be understood that the term “and / or” as used in this application specification and the appended claims means any combination of one or more of the associated listed items and all possible combinations, and includes such combinations.

[0029] As used in this application specification and the appended claims, the term "if" may be interpreted, depending on the context, as "when," "once," "in response to determination," or "in response to detection." Similarly, the phrase "if determined" or "if detected [the described condition or event]" may be interpreted, depending on the context, as meaning "once determined," "in response to determination," "once detected [the described condition or event]," or "in response to detection [the described condition or event]."

[0030] Furthermore, in the description of this application and the appended claims, the terms "first," "second," "third," etc., are used only to distinguish descriptions and should not be construed as indicating or implying relative importance.

[0031] References to "one embodiment" or "some embodiments" in this specification mean that one or more embodiments of this application include a specific feature, structure, or characteristic described in connection with that embodiment. Therefore, the phrases "in one embodiment," "in some embodiments," "in other embodiments," "in still other embodiments," etc., appearing in different parts of this specification do not necessarily refer to the same embodiment, but rather mean "one or more, but not all, embodiments," unless otherwise specifically emphasized.

[0032] In digital substations and smart grids, the coordinated operation of relay protection, fault recording, measurement and control, monitoring, and communication equipment all rely on a unified, high-precision time reference, with time synchronization accuracy reaching the microsecond level. Currently, time synchronization devices typically utilize the BeiDou satellite system as their time reference source.

[0033] In complex station environments, satellite signals are susceptible to electromagnetic interference, weather changes, building obstructions, or deceptive signals, leading to receiver loss and time synchronization interruptions. When an external reference time source fails, the time synchronization device relies on its own crystal oscillator for timekeeping. However, existing crystal oscillator-based timekeeping methods cannot adapt to dynamic environmental changes, especially in cases of prolonged time synchronization loss, resulting in low timekeeping accuracy.

[0034] Based on this, this application provides a timekeeping method. In this application embodiment, when the time synchronization device switches to a state of timekeeping based on its own crystal oscillator (i.e., the second state), the frequency deviation is predicted based on the latest acquired data before the time synchronization device enters the second state. Since the data acquired before entering the second state is actual data, using this data as a benchmark for frequency prediction is equivalent to determining a relatively accurate benchmark data for prediction, providing a reliable data basis for subsequent timekeeping. In addition, after entering the second state, the frequency deviation is predicted based on a trained prediction model. The prediction model is trained based on historical target benchmark time, historical environmental data, and historical frequency deviation sequences. Therefore, the frequency deviation predicted by the prediction model can adapt to dynamic environmental changes and is closer to the historical frequency deviation pattern, thereby effectively improving the timekeeping accuracy of the crystal oscillator.

[0035] See Figure 1This is a flowchart illustrating the timekeeping method provided in an embodiment of this application. The timekeeping method of this application is applied to a time synchronization device, which includes a crystal oscillator. As an example and not a limitation, the method may include the following steps: S101, when the time synchronization device switches from the first state to the second state, the prediction model trained based on the first collection data when the time synchronization device is in the first state is obtained.

[0036] In the first state, the time synchronization device keeps time based on an external reference time source, while in the second state, the time synchronization device keeps time based on a crystal oscillator.

[0037] In this embodiment, the first acquired data includes multiple first data packets corresponding to different first acquisition times. Each first data packet corresponding to a first acquisition time includes a target reference time, environmental data, and a historical frequency deviation sequence between the crystal oscillator frequency and an external reference time source. Accordingly, the prediction model is used to predict the frequency deviation between the crystal oscillator and the external reference time source based on the target reference time, environmental data, and the historical frequency deviation sequence. The target reference time refers to the reference time determined based on the external reference time source.

[0038] In one embodiment, the step of obtaining the prediction model may include: Obtain the first set of collected data; The first collected data is sampled to obtain the third collected data; wherein the sampling frequency of the third collected data is lower than the sampling frequency of the first collected data. The initial model is trained based on the first collected data to obtain the first model; The initial model was trained based on the third set of collected data to obtain the second model; A prediction model is constructed based on the first and second models.

[0039] It is understandable that when the time synchronization device is in the first state, that is, when the external reference time source is valid, it continuously collects the first data packet to obtain the first collected data.

[0040] Optionally, the first and second models can be neural network models. For example, the first and second models can use Long Short-Term Memory (LSTM) networks, which can effectively reduce the gradient vanishing or gradient explosion problems when processing long sequences, have strong generalization ability, and are especially beneficial for improving the accuracy of long-term timekeeping.

[0041] Optionally, the prediction model may include a first model, a second model, and a fusion module. The inputs of both the first and second models are inputs to the prediction model, and the outputs of both models are connected to the fusion module, whose output is the output of the prediction model. The fusion module is used to fuse the output data of the first and second models.

[0042] For example, see Figure 2 This is a schematic diagram illustrating the model training process provided in an embodiment of this application. It is intended as an example and not a limitation. Figure 2 As shown, the model training process includes the following steps: S201, determine whether the external reference time source is valid.

[0043] If the external reference time source is valid, execute S202; if the external reference time source is invalid, execute S212.

[0044] S202, if the external reference time source is valid, then acquire the first collected data.

[0045] S203, Obtain the third data based on the first data.

[0046] S204, determine whether it is the first time the model is trained.

[0047] S205: If it is the first time training the model, initialize the model structure.

[0048] S206 If this is not the first time the model is trained, then read the saved model parameters (i.e. the model parameters of the prediction model obtained in the last training).

[0049] S207, Train the first model based on the first collected data.

[0050] S208, train the second model based on the third collected data.

[0051] Optionally, model training can be performed once for each first data packet acquired. Alternatively, model training can be performed once a certain number of first data packets are acquired.

[0052] S209, Construct a prediction model based on the first model and the second model.

[0053] For example, the loss function used to train the prediction model can be mean squared error, etc. The optimization algorithm used can be Adam or RMSPorop, etc.

[0054] Optionally, the first and second models can be trained separately, and then a prediction model can be built based on the trained first and second models. Alternatively, the structure of the prediction model can be built first, and then the prediction model can be trained as a whole.

[0055] In the above method, it is equivalent to training two models based on data with different sampling frequencies. The model trained on high-frequency data is good at capturing instantaneous details and high-frequency changes, while the model trained on low-frequency data is good at capturing long-term trends and overall patterns. Therefore, the prediction model built based on the two models can detect both the key features at the level of data details and the overall trend of data, which effectively improves the generalization ability of the prediction model and helps to improve the prediction accuracy of the prediction model.

[0056] S210, Save / update the model parameters of the prediction model.

[0057] S211, determine whether the external reference time source is valid.

[0058] S212, If the external reference time source is invalid, freeze the current model parameters and enter the second state.

[0059] If the external reference time source is still valid, continue to acquire the first collection data and continue training the model.

[0060] In one embodiment, the time synchronization device includes two receiving modules, which are used to receive time information from different external reference time sources, respectively.

[0061] Accordingly, the steps for obtaining the first set of collected data include: For each first acquisition moment, obtain the time information received by each receiving module; Calculate the signal quality for each receiving module separately; Calculate the target reference time corresponding to the first acquisition moment based on the signal quality and time information of each receiving module; Acquire the environmental data and historical frequency deviation sequence corresponding to the first acquisition time; The first data packet corresponding to the first acquisition time is generated based on the target reference time, environmental data, and historical frequency deviation sequence corresponding to the first acquisition time.

[0062] In one implementation, the target reference time is calculated according to the formula Tmaster = w1 * T1 + w2 * T2. Here, Tmaster is the target reference time, T1 and T2 are the time information from different external reference time sources, and w1 and w2 are the weights.

[0063] Optionally, w1 = a1 / (a1+a2), w2 = a2 / (a1+a2). Here, a1 and a2 are the health parameters corresponding to different external reference time sources. For example, the health parameters can be obtained by weighted summation based on parameters such as the carrier-to-noise ratio and lock-in status of the external reference time sources.

[0064] In the above method, the target reference time is determined by fusing the time information from different external reference time sources. This effectively reduces the time deviation caused by occasional failures of a single external reference time source, which helps to improve the timekeeping accuracy and reliability of the system.

[0065] In one embodiment, the method further includes: After obtaining the target reference time corresponding to the first acquisition time, the crystal oscillator is timed and disciplined according to the target reference time corresponding to the first acquisition time.

[0066] Optionally, the timekeeping discipline process may include: using the target reference time as a reference, counting the number of pulses of the crystal oscillator output signal within a measurement cycle; calculating the actual output frequency of the crystal oscillator within that measurement cycle based on the number of pulses; calculating the frequency deviation between the actual input frequency of the crystal oscillator and the target frequency; and performing frequency compensation based on the frequency deviation.

[0067] Optionally, the timekeeping discipline process may include: calculating the phase difference between the 1PPS signal corresponding to the target reference time and the 1PPS signal output by the crystal oscillator; calculating the frequency deviation between the crystal oscillator and the external reference time source based on the phase difference; and performing frequency compensation based on the frequency deviation.

[0068] S102, acquire target data; wherein, the target data is the latest set of first data packets acquired before the time synchronization device enters the second state.

[0069] S103, based on the target data and the prediction model, sequentially obtain the prediction frequency deviation corresponding to each control moment in the second state.

[0070] In one embodiment, S103 may include: For the first moment, the target data is input into the first model to obtain the first output; wherein, the first moment is the first control moment after the time synchronization device switches from the first state to the second state; Input the target data into the second model to obtain the second output; The predicted frequency deviation at the first moment is calculated based on the first and second outputs.

[0071] Understandably, for the second moment (the second control moment after the time synchronization device switches from the first state to the second state), the corresponding target reference time is the calibration time calculated based on the predicted frequency deviation of the first moment, and its corresponding historical frequency deviation sequence includes the frequency deviations of multiple moments prior to the second moment. By inputting the environmental data, target reference time, and historical frequency deviation sequence corresponding to the second moment into the prediction model, the predicted frequency deviation corresponding to the second moment is output. Similarly, the predicted frequency deviation for each control moment in the first state can be calculated.

[0072] In the above approach, the first model is a model trained on high-frequency data and is good at capturing instantaneous details and high-frequency changes, while the second model is a model trained on low-frequency data and is good at capturing long-term trends and overall patterns. The predicted frequency deviation calculated based on the output data of the first and second models not only conforms to the key features at the level of data details but also combines the overall trend of the data. Therefore, the predicted frequency deviation is more accurate, which helps to improve the timekeeping accuracy.

[0073] In one embodiment, the method further includes: After calculating the prediction frequency deviation corresponding to the first time step based on the first output and the second output, the confidence level of the prediction model is calculated based on the prediction frequency deviation corresponding to the first time step. If the confidence level is lower than the preset threshold, exit the second state.

[0074] Optionally, the confidence level is calculated as follows: The calibration time is calculated based on the prediction frequency deviation corresponding to the first moment, and the time difference between the calibration time and the target reference time in the target data is calculated. If the time difference is greater than a preset value, the confidence level is determined to be lower than a preset threshold. The preset value for the time difference can be determined based on the difference between the target reference times corresponding to each of every two adjacent acquisition moments in the first acquisition data. In other words, if the time difference is greater than the preset value, it indicates a higher probability that the current prediction does not conform to historical timekeeping patterns, meaning the model's confidence level is low.

[0075] In the above method, exiting crystal oscillator timekeeping when the confidence level of the prediction model is low can reduce timekeeping failures caused by large errors in the model prediction results, thus improving the reliability of the system.

[0076] S104, in the second state, the time synchronization device is controlled to keep time according to the predicted frequency deviation corresponding to each control moment.

[0077] In one implementation, S104 includes: For each control moment, the average frequency of the crystal oscillator is obtained; wherein, the average frequency is the average value of the output frequency of the crystal oscillator corresponding to each first acquisition moment when the time synchronization device is in the first state; Calculate the target output frequency at the control time based on the average frequency and the predicted frequency deviation at the control time. The output compensation voltage corresponding to the control moment is calculated based on the target output frequency and the preset sensitivity coefficient. The crystal oscillator is controlled to keep time based on the output compensation voltage corresponding to the control moment.

[0078] For example, according to formula ƒ target(t+1)=ƒ0*(1+Δƒ predict (t+1)) Calculate the target output frequency according to the formula = + Calculate the output compensation voltage. Where, ƒ target (t+1) represents the target output frequency at the (t+1)th control time, Δƒ predict (t+1) represents the predicted frequency deviation at the (t+1)th control time, and ƒ0 represents the average frequency of the crystal oscillator. This is the compensation voltage corresponding to the (t+1)th control time. The current voltage, This is the sensitivity coefficient.

[0079] In one embodiment, the method further includes: When the time synchronization device switches from the second state to the first state, it acquires the second acquisition data of the time synchronization device; wherein, the second acquisition data includes a second data packet corresponding to a plurality of second acquisition times, and the second data packet corresponding to each second acquisition time includes the target reference time, environmental data, and the historical frequency deviation sequence between the crystal oscillator frequency and the external reference time source corresponding to the second acquisition time; the prediction model is updated according to the second acquisition data to obtain the updated prediction model.

[0080] In the above method, after the signal of the external reference time source is recovered, the prediction model continues to be updated based on the data collected by the time synchronization device in the first state. Through this continuous update method, the prediction model can continuously adapt to changes in the external environment, making the predicted frequency deviation more accurate, thereby improving the timekeeping accuracy.

[0081] For example, see Figure 3 This is a schematic diagram illustrating the overall workflow of the time synchronization device provided in this application embodiment. As an example and not a limitation, the overall workflow of the time synchronization device may include the following steps: S301 determines whether the external reference time source is valid.

[0082] If a single external reference time source is valid or both external reference time sources are valid, the external reference time source is determined to be valid; if both external reference time sources are invalid, the external reference time source is determined to be invalid.

[0083] If the external reference time source is valid, execute S302; if the external reference time source is invalid, execute S305.

[0084] S302, if the external reference time source is valid, calculate the target reference time.

[0085] S303, acquire the first data.

[0086] S304, tames the crystal oscillator based on the first acquired data and trains the prediction model.

[0087] The implementation of steps S302-S304 is the same as that of training the prediction model in S101. For details, please refer to the description in the embodiment of S101, which will not be repeated here.

[0088] S305, if the external reference time source is invalid, switch to the second state to acquire the target data.

[0089] S306, Obtain the prediction frequency deviation based on the target data and the prediction model.

[0090] S307 performs timekeeping control based on predicted frequency deviation.

[0091] Steps S305-S307 are implemented in the same way as S102-S104. For details, please refer to the description in the embodiments of S102-S104, which will not be repeated here.

[0092] It is understandable that S305-S307 constitutes the flow corresponding to one control moment, and execution restarts from S301 at the next control moment. For example, at the first control moment, S301 is executed; if the external reference time source is invalid, S305-S307 are executed. At the second control moment, S301 is executed; if the external reference time source is still invalid, S305-S307 are executed again; if the external reference time source is valid, the process switches to the first state and S302-S304 are executed.

[0093] It should be noted that the execution frequencies of S302-S304 and S305-S307 can be different. For example, S305-S307 can be executed once per control moment, while S302-S304 can be executed once across multiple control moments.

[0094] In this embodiment, when the time synchronization device switches to the state of timekeeping based on its own crystal oscillator (i.e., the second state), the frequency deviation is predicted based on the latest acquired data before the time synchronization device enters the second state. Since the data acquired before entering the second state is actual data, using this data as a benchmark for frequency prediction is equivalent to determining a relatively accurate benchmark data for prediction, providing a reliable data basis for subsequent timekeeping. In addition, after entering the second state, the frequency deviation is predicted based on a trained prediction model. The prediction model is trained based on historical target benchmark time, historical environmental data, and historical frequency deviation sequences. Therefore, the frequency deviation predicted by the prediction model can adapt to dynamic environmental changes and is closer to the historical frequency deviation pattern, thereby effectively improving the timekeeping accuracy of the crystal oscillator.

[0095] It should be understood that the sequence number of each step in the above embodiments does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.

[0096] Corresponding to the timekeeping method described in the above embodiments, Figure 4 This is a structural block diagram of the timekeeping device provided in the embodiments of this application. For ease of explanation, only the parts related to the embodiments of this application are shown.

[0097] Reference Figure 4 The device 4 includes: The model acquisition unit 41 is used to acquire a prediction model trained based on the first acquisition data when the time synchronization device switches from a first state to a second state; wherein, in the first state, the time synchronization device maintains time based on an external reference time source, and in the second state, the time synchronization device maintains time based on the crystal oscillator; the first acquisition data includes a first data packet corresponding to a plurality of first acquisition times, and each first data packet corresponding to the first acquisition time includes a target reference time corresponding to the first acquisition time, environmental data, and a historical frequency deviation sequence between the crystal oscillator frequency and the external reference time source; the prediction model is used to predict the frequency deviation between the crystal oscillator and the external reference time source based on the target reference time, the environmental data, and the historical frequency deviation sequence.

[0098] The data acquisition unit 42 is used to acquire target data; wherein the target data is the latest set of first data packets acquired by the time synchronization device before entering the second state.

[0099] The frequency prediction unit 43 is used to obtain the predicted frequency deviation corresponding to each control moment in the second state according to the target data and the prediction model.

[0100] The timekeeping control unit 44 is used to control the time synchronization device to keep time according to the predicted frequency deviation corresponding to each control moment in the second state.

[0101] Optionally, the model acquisition unit 41 is also used for: When the time synchronization device switches from the second state to the first state, it acquires the second acquisition data of the time synchronization device; wherein, the second acquisition data includes a second data packet corresponding to a plurality of second acquisition times, and each second data packet corresponding to the second acquisition time includes the target reference time, environmental data, and the historical frequency deviation sequence between the crystal oscillator frequency and the external reference time source corresponding to the second acquisition time; The prediction model is updated based on the second collected data to obtain the updated prediction model.

[0102] Optionally, the model acquisition unit 41 is also used for: Obtain the first collected data; The first collected data is sampled to obtain the third collected data; wherein the sampling frequency of the third collected data is lower than the sampling frequency of the first collected data. The initial model is trained based on the first collected data to obtain the first model; The initial model is trained based on the third collected data to obtain the second model; The prediction model is constructed based on the first model and the second model.

[0103] Optionally, the frequency prediction unit 43 is also used for: For the first moment, the target data is input into the first model to obtain the first output; wherein, the first moment is the first control moment after the time synchronization device switches from the first state to the second state; The target data is input into the second model to obtain the second output; The predicted frequency deviation corresponding to the first time moment is calculated based on the first output and the second output.

[0104] Optionally, the timekeeping control unit 44 is also used for: After calculating the prediction frequency deviation corresponding to the first time step based on the first output and the second output, the confidence level of the prediction model is calculated based on the prediction frequency deviation corresponding to the first time step. If the confidence level is lower than a preset threshold, then exit the second state.

[0105] Optionally, the time synchronization device includes two receiving modules, which are used to receive time information from different external reference time sources respectively.

[0106] Accordingly, the model acquisition unit 41 is also used for: For each of the first acquisition moments, obtain the time information received by each of the receiving modules; Calculate the signal quality for each of the receiving modules; Calculate the target reference time corresponding to the first acquisition moment based on the signal quality and time information corresponding to each of the receiving modules; Obtain the environmental data and historical frequency deviation sequence corresponding to the first acquisition time; The first data packet corresponding to the first acquisition time is generated based on the target reference time, the environmental data, and the historical frequency deviation sequence corresponding to the first acquisition time.

[0107] Optionally, the timekeeping control unit 44 is also used for: For each control moment, the average frequency of the crystal oscillator is obtained; wherein, the average frequency is the average value of the output frequency of the crystal oscillator corresponding to each of the first acquisition moments when the time synchronization device is in the first state; Calculate the target output frequency corresponding to the control time based on the average frequency and the predicted frequency deviation corresponding to the control time; The output compensation voltage corresponding to the control moment is calculated based on the target output frequency corresponding to the control moment and the preset sensitivity coefficient. The crystal oscillator is controlled to perform timekeeping based on the output compensation voltage corresponding to the control time.

[0108] Optionally, the timekeeping control unit 44 is also used for: After obtaining the target reference time corresponding to the first acquisition time, the crystal oscillator is timed and disciplined according to the target reference time corresponding to the first acquisition time.

[0109] It should be noted that the information interaction and execution process between the above-mentioned devices / units are based on the same concept as the method embodiments of this application. For details on their specific functions and technical effects, please refer to the method embodiments section, and they will not be repeated here.

[0110] in addition, Figure 4 The time synchronization device shown can be a software unit, a hardware unit, or a combination of software and hardware built into an existing terminal device. It can also be integrated into the terminal device as an independent component, or it can exist as an independent terminal device.

[0111] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the above-described division of functional units and modules is merely an example. In practical applications, the above functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiments can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit. Furthermore, the specific names of the functional units and modules are only for easy differentiation and are not intended to limit the scope of protection of this application. The specific working process of the units and modules in the above system can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.

[0112] Figure 5 This is a schematic diagram of the structure of the terminal device provided in the embodiments of this application. For example... Figure 5 As shown, the terminal device 5 in this embodiment includes: at least one processor 50 ( Figure 5 (Only one is shown in the diagram) a processor, a memory 51, and a computer program 52 stored in the memory 51 and executable on the at least one processor 50, wherein the processor 50 executes the computer program 52 to implement the steps in any of the above-described timekeeping method embodiments.

[0113] The terminal device may be a desktop computer, laptop, handheld computer, or cloud server, etc. This terminal device may include, but is not limited to, a processor and memory. Those skilled in the art will understand that... Figure 5 This is merely an example of terminal device 5 and does not constitute a limitation on terminal device 5. It may include more or fewer components than shown in the figure, or combine certain components, or different components, such as input / output devices, network access devices, etc.

[0114] The processor 50 can be a Central Processing Unit (CPU), or it can be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or any conventional processor.

[0115] In some embodiments, the memory 51 may be an internal storage unit of the terminal device 5, such as a hard disk or memory of the terminal device 5. In other embodiments, the memory 51 may be an external storage device of the terminal device 5, such as a plug-in hard disk, smart media card (SMC), secure digital (SD) card, flash card, etc., equipped on the terminal device 5. Furthermore, the memory 51 may include both internal and external storage units of the terminal device 5. The memory 51 is used to store the operating system, applications, boot loader, data, and other programs, such as the program code of the computer program. The memory 51 can also be used to temporarily store data that has been output or will be output.

[0116] This application also provides a computer-readable storage medium storing a computer program that, when executed by a processor, can implement the steps in the above-described method embodiments.

[0117] This application provides a computer program product that, when run on a terminal device, enables the terminal device to implement the steps described in the various method embodiments.

[0118] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the methods of the above embodiments of this application can be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. The computer-readable medium can include at least: any entity or device capable of carrying computer program code to a device / terminal equipment, a recording medium, a computer memory, a read-only memory (ROM), a random access memory (RAM), an electrical carrier signal, a telecommunication signal, and a software distribution medium. Examples include USB flash drives, portable hard drives, magnetic disks, or optical disks. In some jurisdictions, according to legislation and patent practice, computer-readable media cannot be electrical carrier signals or telecommunication signals.

[0119] In the above embodiments, the descriptions of each embodiment have different focuses. For parts that are not described in detail or recorded in a certain embodiment, please refer to the relevant descriptions of other embodiments.

[0120] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0121] In the embodiments provided in this application, it should be understood that the disclosed devices / terminal equipment and methods can be implemented in other ways. For example, the device / terminal equipment embodiments described above are merely illustrative. For instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms.

[0122] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0123] The above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application, and should all be included within the protection scope of this application.

Claims

1. A method for keeping time, characterized in that, The time synchronization method is applied to a time synchronization device, which includes a crystal oscillator; the time synchronization method includes: When the time synchronization device switches from a first state to a second state, it acquires a prediction model trained based on the first acquisition data when the time synchronization device is in the first state. In the first state, the time synchronization device maintains time based on an external reference time source, while in the second state, it maintains time based on the crystal oscillator. The first acquisition data includes multiple first data packets corresponding to different first acquisition times. Each first data packet corresponding to a first acquisition time includes a target reference time, environmental data, and a historical frequency deviation sequence between the crystal oscillator's frequency and the external reference time source. The prediction model is used to predict the frequency deviation between the crystal oscillator and the external reference time source based on the target reference time, the environmental data, and the historical frequency deviation sequence. Acquire target data; wherein, the target data is the latest set of first data packets acquired by the time synchronization device before entering the second state; Based on the target data and the prediction model, the prediction frequency deviation corresponding to each control moment in the second state is obtained sequentially. In the second state, the time synchronization device is controlled to keep time according to the predicted frequency deviation corresponding to each control moment.

2. The timekeeping method as described in claim 1, characterized in that, The method further includes: When the time synchronization device switches from the second state to the first state, it acquires the second acquisition data of the time synchronization device; wherein, the second acquisition data includes a second data packet corresponding to a plurality of second acquisition times, and each second data packet corresponding to the second acquisition time includes the target reference time, environmental data, and the historical frequency deviation sequence between the crystal oscillator frequency and the external reference time source corresponding to the second acquisition time; The prediction model is updated based on the second collected data to obtain the updated prediction model.

3. The timekeeping method as described in claim 1, characterized in that, The step of acquiring the prediction model trained based on the first collected data when the time synchronization device is in the first state includes: Obtain the first collected data; The first collected data is sampled to obtain the third collected data; wherein the sampling frequency of the third collected data is lower than the sampling frequency of the first collected data. The initial model is trained based on the first collected data to obtain the first model; The initial model is trained based on the third collected data to obtain the second model; The prediction model is constructed based on the first model and the second model.

4. The timekeeping method as described in claim 3, characterized in that, The step of obtaining the prediction frequency deviation corresponding to each control moment in the second state based on the target data and the prediction model includes: For the first moment, the target data is input into the first model to obtain the first output; wherein, the first moment is the first control moment after the time synchronization device switches from the first state to the second state; The target data is input into the second model to obtain the second output; The predicted frequency deviation corresponding to the first time moment is calculated based on the first output and the second output.

5. The timekeeping method as described in claim 4, characterized in that, After calculating the prediction frequency deviation corresponding to the first time moment based on the first output and the second output, the method further includes: The confidence level of the prediction model is calculated based on the prediction frequency deviation corresponding to the first time point; If the confidence level is lower than a preset threshold, then exit the second state.

6. The timekeeping method as described in claim 3, characterized in that, The time synchronization device includes two receiving modules, which are used to receive time information from different external reference time sources respectively. The acquisition of the first collected data includes: For each of the first acquisition moments, obtain the time information received by each of the receiving modules; Calculate the signal quality for each of the receiving modules; Calculate the target reference time corresponding to the first acquisition moment based on the signal quality and time information corresponding to each of the receiving modules; Obtain the environmental data and historical frequency deviation sequence corresponding to the first acquisition time; The first data packet corresponding to the first acquisition time is generated based on the target reference time, the environmental data, and the historical frequency deviation sequence corresponding to the first acquisition time.

7. The timekeeping method as described in claim 1, characterized in that, In the second state, the time synchronization device is controlled to maintain time based on the predicted frequency deviation corresponding to each control moment, including: For each control moment, the average frequency of the crystal oscillator is obtained; wherein, the average frequency is the average value of the output frequency of the crystal oscillator corresponding to each of the first acquisition moments when the time synchronization device is in the first state; Calculate the target output frequency corresponding to the control time based on the average frequency and the predicted frequency deviation corresponding to the control time; The output compensation voltage corresponding to the control moment is calculated based on the target output frequency corresponding to the control moment and the preset sensitivity coefficient. The crystal oscillator is controlled to perform timekeeping based on the output compensation voltage corresponding to the control time.

8. The timekeeping method as described in claim 6, characterized in that, After obtaining the target reference time corresponding to the first acquisition time, the method further includes: The crystal oscillator is time-controlled according to the target reference time corresponding to the first acquisition time.

9. A terminal device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the method as described in any one of claims 1 to 8.

10. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the method as described in any one of claims 1 to 8.