Fixed point number method based on real-time clock module compensation crystal precision and related device

The method of replacing floating-point number operation by fixed-point number method and calculating and writing RTC compensation registers has solved the problem of increasing code volume and decreasing execution speed caused by floating-point number calculation in the prior art, and achieved high-precision compensation and fast response.

CN119717472APending Publication Date: 2025-03-28小华半导体有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411770791.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-04
Publication Date
2025-03-28

AI Technical Summary

Technical Problem

When the prior art realizes high-precision compensation of quartz crystals, floating point calculations are required, resulting in an increase in the number of codes and a decrease in execution speed.

Method used

The fixed-point number method is used instead of floating-point number operation, and the compensation accuracy based on the real-time clock module is obtained through the shift algorithm, and it is written to the RTC compensation register.

Benefits of technology

It realizes fast response of real-time clock high-precision compensation processing in a wide temperature domain and occupies a small code space.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119717472A_ABST
    Figure CN119717472A_ABST
Patent Text Reader

Abstract

The invention relates to a fixed point number method for compensating crystal precision based on a real-time clock module and a related device. The method comprises the following steps: acquiring actual temperature data of a crystal, and converting the actual temperature data into a signed number Temp, so that the positive and negative properties of the Temp data type represent the positive and negative properties of the temperature; defining integer data according to the parabola coefficient, the inflection point temperature and the vertex ppm deviation; calculating to obtain compensation precision based on a real-time clock module according to the integer data; and superposing the compensation precision with a 0ppm value of a real-time clock module, and writing into an RTC compensation register. According to the fixed-point number method for compensating the crystal precision based on the real-time clock module, the fixed-point number is used for replacing floating-point number operation, a shifting algorithm is adopted in the calculation process, and the calculation result is directly converted into a value based on RTC compensation precision, so that quick response of real-time clock high-precision compensation processing in a wide temperature domain can be realized; and a small code space is occupied.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of real-time clocks, and in particular to a fixed-point number method and a related device based on a real-time clock module to compensate for crystal precision. Background Art

[0002] Real Time Clock (RTC) is an important electronic device that provides real-time time information and time reference in various electronic products, and plays an important role in the stability and reliability of the system. The most important function of RTC is to provide calendar function. RTC is usually used in the system to provide reliable system time, including hours, minutes, seconds, years, months, days, etc. Devices with RTC usually have an external 32768Hz high-precision ppm quartz crystal on the hardware board. Since the oscillation frequency of the quartz crystal will drift with the temperature, that is, the temperature characteristic curve of the quartz crystal within a certain temperature range is approximately parabolic, such as Figure 1 The device needs to calculate the ppm (Parts Per Million) deviation of the quartz crystal according to the current temperature, and realize the correction of the actual output ppm through the RTC compensation module inside the microprocessor.

[0003] like Figure 1 As shown, the horizontal axis is the temperature of the quartz crystal, and the vertical axis is Δf / f. The temperature characteristic curve of the crystal can be expressed by the formula:

[0004] Δf / f=α*(T–Ti) 2 +ppm_t

[0005] Where * indicates multiplication, α is the parabola coefficient; T is the actual temperature, in °C; Ti is the inflection point temperature, in °C; ppm_t is the vertex ppm deviation; Δf / f = (actual frequency - target frequency) / target frequency * 10 -6 .

[0006] It should be noted that α is a floating point number with an absolute value less than 1; when high-precision ppm control is required, the temperature-related quantity will be a floating point number with an accuracy less than 1°C; when the accuracy of the RTC module compensation is less than 1ppm, the ppm directly calculated by the formula needs to be converted by floating point calculation before it can be written into the actual RTC register. The calculation of floating point numbers increases the amount of code and reduces the execution speed. Summary of the invention

[0007] In view of some or all of the problems in the prior art, the present invention provides a fixed-point number method based on a real-time clock module to compensate for crystal precision, the method comprising:

[0008] Acquire actual temperature data of the crystal, and convert the actual temperature data into a signed number Temp, so that the positive and negative values ​​of the Temp data type represent the positive and negative values ​​of the temperature;

[0009] Define integer data based on parabola coefficient, inflection point temperature and vertex ppm deviation;

[0010] Calculating compensation accuracy based on a real-time clock module according to the integer data; and

[0011] The compensation accuracy is superimposed on the 0ppm value of the real-time clock module and written into the RTC compensation register.

[0012] Further, actual temperature data of the crystal is obtained, and the actual temperature data is converted into a signed number Temp, so that the positive and negative of the Temp data type represents the positive and negative of the temperature, including:

[0013] Use a temperature sensor to obtain actual temperature data of the crystal, wherein the actual temperature data length is 16 bits, data 0 to 0x7FFF represents positive temperature, and data 0x8000 to 0xFFFF represents negative temperature;

[0014] The signed number Temp is defined as follows,

[0015] Temp=T*2 TEMP_SHIFT

[0016] Where T is the actual temperature of the crystal and TEMP_SHIFT is defined by,

[0017] 1 / 2 TEMP_SHIFT =The actual temperature of the integer data of the temperature value.

[0018] Further, the integer data includes MACRO_ALPHA, MACRO_TI and MACRO_PPM_T;

[0019] MACRO_ALPHA is defined as follows,

[0020] MACRO_ALPHA=α*2 ALPHA_SHIFT *MACRO_RTC

[0021] Among them, * represents multiplication, and α is the parabola coefficient;

[0022] According to α*2 ALPHA_SHIFT The integer data value retains the precision of α and determines the value of ALPHA_SHIFT;

[0023] Among them, MACRO_RTC is defined by the following formula:

[0024] MACRO_RTC = 32768*32 / 1000000

[0025] MACRO_TI is defined by the following formula,

[0026] MACRO_TI=Ti*2 TEMP_SHIFT

[0027] Where Ti is the inflection point temperature;

[0028] TEMP_SHIFT is defined as follows,

[0029] 1 / 2 TEMP_SHIFT =The actual temperature of the integer data of the temperature value.

[0030] MACRO_PPM_T is defined by the following formula,

[0031] MACRO_PPM_T=ppm_t*2 ALPHA_SHIFT MACRO_RTC*2 TEMP_SHIFT *2 TEMP_SHIFT

[0032] Where ppm_t is the vertex ppm deviation.

[0033] Furthermore, the definition items are all processed by a precompiler during program implementation, and the calculation process does not occupy the execution time of the program.

[0034] Further, according to the integer data, the compensation accuracy based on the real-time clock module is calculated including:

[0035] The compensation accuracy RTC_ca based on the real-time clock module is given by the following formula:

[0036] RTC_ca=MACRO_F / 2 (ALPHA_SHIFT+TEMP_SHIFT+TEMP_SHIFT)

[0037] Where MACRO_F is defined as follows:

[0038] MACRO_F=MACRO_ALPHA*(Temp–MACRO_TI) 2 +MACRO_PPM_T

[0039] Among them, MACRO_ALPHA, MACRO_TI and MACRO_PPM_T are integer data of parabola coefficient, inflection point temperature and vertex ppm deviation, and Temp is the signed number converted from the actual temperature data of the crystal.

[0040] Further, the compensation accuracy is superimposed on the 0ppm value of the real-time clock module and written into the RTC compensation register, including:

[0041] The 0ppm compensation value of the real-time clock module is 0x20, and the compensation accuracy is superimposed with 0x20 for setting the compensation accuracy register of the RTC compensation module.

[0042] The present invention also provides a device for compensating crystal accuracy based on a real-time clock module, which is characterized by comprising:

[0043] Compensation control module, setting and starting the RTC compensation function;

[0044] 15-bit asynchronous frequency divider module, outputs compensated high-precision 1Hz.

[0045] The present invention also provides a computer-readable storage medium, characterized in that machine-readable instructions are stored thereon, and when the machine-readable instructions are executed by a processor, the steps of the fixed-point number method based on real-time clock module compensation of crystal precision are executed.

[0046] Compared with the prior art, the beneficial effects of the present invention are as follows: the fixed-point number method based on the real-time clock module to compensate for the crystal precision provided by the present invention uses fixed-point numbers instead of floating-point operations, the calculation process adopts a shift algorithm, and the calculation result is directly converted into a value based on the RTC compensation precision, which can achieve fast response of high-precision compensation processing of the real-time clock in a wide temperature range and occupy a smaller code space. BRIEF DESCRIPTION OF THE DRAWINGS

[0047] To further illustrate the above and other advantages and features of various embodiments of the present invention, a more specific description of various embodiments of the present invention will be presented with reference to the accompanying drawings. It will be understood that these drawings only depict typical embodiments of the present invention and are therefore not to be considered as limiting the scope thereof. In the accompanying drawings, for clarity, identical or corresponding parts will be represented by identical or similar reference numerals.

[0048] Figure 1 It is a schematic diagram of the measured frequency-temperature characteristic curve of a quartz crystal;

[0049] Figure 2 A flow chart of a fixed-point number method for compensating crystal precision based on a real-time clock module according to an embodiment of the present invention; and

[0050] Figure 3 The present invention is a structural block diagram of a device for compensating crystal accuracy based on a real-time clock module according to another embodiment of the present invention. DETAILED DESCRIPTION

[0051] In the following description, the present invention is described with reference to various embodiments. However, those skilled in the art will recognize that various embodiments may be implemented without one or more specific details or with other replacement and / or additional methods or components. In other cases, well-known structures or operations are not shown or described in detail to avoid obscuring the inventive point of the present invention. Similarly, for the purpose of explanation, specific numbers and configurations are set forth to provide a comprehensive understanding of embodiments of the present invention. However, the present invention is not limited to these specific details.

[0052] In this specification, reference to "one embodiment" or "the embodiment" means that a particular feature, structure, or characteristic described in conjunction with the embodiment is included in at least one embodiment of the present invention. The phrase "in one embodiment" appearing in various places in this specification does not necessarily all refer to the same embodiment.

[0053] It should be noted that the embodiments of the present invention describe the method steps in a specific order, but this is only for the purpose of illustrating the specific embodiment, rather than limiting the order of the steps. On the contrary, in different embodiments of the present invention, the order of the steps can be adjusted according to actual needs.

[0054] The fixed-point number method for compensating crystal precision based on a real-time clock module provided by the present invention improves the execution speed while reducing the amount of code, directly converts the calculation result into a compensation value of the RTC module based on a microprocessor, and realizes the correction of crystal ppm under a wide temperature range.

[0055] The technical solutions in the embodiments of the present invention are described clearly and completely below in conjunction with the accompanying drawings in the embodiments of the present invention.

[0056] Figure 2 The following is a flow chart of a fixed-point number method based on a real-time clock module to compensate for crystal precision according to an embodiment of the present invention. Figure 2 , explaining the fixed-point number method based on the real-time clock module to compensate for the crystal accuracy.

[0057] First, actual temperature data of the crystal is obtained, and the actual temperature data is converted into a signed number Temp, so that the positive and negative values ​​of the Temp data type represent the positive and negative values ​​of the temperature.

[0058] Use the temperature sensor to obtain the actual temperature data of the crystal, and the program needs to convert the temperature data into a signed number Temp. The actual temperature data length is 16 bits, data 0 to 0x7FFF represents positive temperature, and data 0x8000 to 0xFFFF represents negative temperature.

[0059] The signed number Temp is defined as follows,

[0060] Temp=T*2TEMP_SHIFT

[0061] Where T is the actual temperature of the crystal and TEMP_SHIFT is defined by,

[0062] 1 / 2 TEMP_SHIFT =The actual temperature of the integer data of the temperature value.

[0063] Next, define integer data based on the parabola coefficient, inflection point temperature, and vertex ppm deviation.

[0064] The integer data includes MACRO_ALPHA, MACRO_TI and MACRO_PPM_T;

[0065] MACRO_ALPHA is defined as follows,

[0066] MACRO_ALPHA=α*2 ALPHA_SHIFT *MACRO_RTC

[0067] Where * represents multiplication and α is the parabola coefficient.

[0068] According to α*2 ALPHA_SHIFT The integer data value retains the precision of α and determines the value of ALPHA_SHIFT. For example, when α = 0.0351, the precision is 10 -4 , you can set ALPHA_SHIFT = 14, 2 ALPHA_SHIFT =2 14 =16384, then α*2 ALPHA _SHIFT After the operation, the accuracy of α can be retained.

[0069] Among them, MACRO_RTC is defined by the following formula:

[0070] MACRO_RTC = 32768*32 / 1000000

[0071] Referring to the compensation principle of the RTC module, in the RTC compensation register used in the present invention, each change of 1 represents a change of 0.95ppm. The purpose of the MACRO_RTC definition is to convert each unit of 1ppm to each unit of 0.95ppm.

[0072] MACRO_TI is defined by the following formula,

[0073] MACRO_TI=Ti*2 TEMP_SHIFT

[0074] Wherein, Ti is the inflection point temperature.

[0075] Define TEMP_SHIFT according to the precision of the integer data of the temperature value.

[0076] 1 / 2 TEMP_SHIFT =The actual temperature of the integer data of the temperature value.

[0077] According to the crystal circuit and test results, define MACRO_PPM_T,

[0078] MACRO_PPM_T=ppm_t*2 ALPHA_SHIFT MACRO_RTC*2 TEMP_SHIFT *2 TEMP_SHIFT

[0079] Where ppm_t is the vertex ppm deviation.

[0080] The above definition items are processed by the precompiler during program implementation, and the calculation process does not take up the program's execution time.

[0081] Next, the compensation accuracy based on the real-time clock module is calculated according to the integer data.

[0082] The compensation accuracy RTC_ca based on the real-time clock module is given by the following formula:

[0083] RTC_ca=MACRO_F / 2 (ALPHA_SHIFT+TEMP_SHIFT+TEMP_SHIFT)

[0084] Where MACRO_F is defined as follows:

[0085] MACRO_F=MACRO_ALPHA*(Temp–MACRO_TI) 2 +MACRO_PPM_T

[0086] Among them, MACRO_ALPHA, MACRO_TI and MACRO_PPM_T are integer data of parabola coefficient, inflection point temperature and vertex ppm deviation, and Temp is the signed number converted from the actual temperature data of the crystal.

[0087] Finally, the compensation accuracy is superimposed on the 0ppm value of the real-time clock module and written into the RTC compensation register. According to the 0ppm compensation value of the RTC module, the 0ppm compensation value of the RTC module used in the present invention is 0x20, and the compensation accuracy is superimposed on 0x20 for the compensation accuracy register setting of the RTC compensation module.

[0088] The fixed-point number method based on real-time clock module compensation crystal precision provided by the present invention uses fixed-point numbers to replace floating-point operations, the calculation process adopts a shift algorithm, and the calculation result is directly converted into a value based on the RTC compensation precision, which can achieve fast response of high-precision compensation processing of the real-time clock in a wide temperature range and occupy a small code space.

[0089] Figure 3 FIG. 1 is a structural block diagram of a device for compensating crystal accuracy based on a real-time clock module according to another embodiment of the present invention. Figure 3 As shown, based on the device for compensating the crystal precision of the real-time clock module, the hardware unit related to compensation in the RTC module used in the present invention includes a 15-bit asynchronous frequency divider module and a compensation control module. The compensation control module distributes the compensation value to each second and finally adjusts the input clock once every 32 seconds. When there is a ppm deviation in the RTCCLK, the data calculated by the present invention is directly written into the compensation register. After the compensation control module sets and starts the RTC compensation function, the 15-bit asynchronous frequency divider module outputs the compensated high-precision 1Hz.

[0090] Table 1 is a description table of compensation value settings for a device based on a real-time clock module to compensate for crystal accuracy. The compensation register of the RTC module used in the present invention can achieve compensation with a minimum step length of 0.95ppm. When the written data is 0x20, the compensation value is 0ppm.

[0091] Table 1 Description of compensation value settings for a device based on real-time clock module compensation crystal accuracy

[0092]

[0093] In one embodiment of the present invention, the present invention also provides a computer-readable storage medium having machine-readable instructions stored thereon, and the machine-readable instructions implement the following processing steps when executed by a processor: obtaining actual temperature data of the crystal, converting the actual temperature data into a signed number Temp, so that the positive and negative properties of the Temp data type represent the positive and negative properties of the temperature; defining integer data according to the parabola coefficient, the inflection point temperature, and the vertex ppm deviation; calculating the compensation accuracy based on the real-time clock module according to the integer data; and superimposing the compensation accuracy on the 0ppm value of the real-time clock module and writing it into the RTC compensation register.

[0094] The readable storage medium includes: a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk, and other media that can store machine-readable instructions.

[0095] Although various embodiments of the present invention are described above, it should be understood that they are presented as examples only and not as limitations. It is obvious to those skilled in the relevant art that various combinations, modifications and changes can be made thereto without departing from the spirit and scope of the present invention. Therefore, the breadth and scope of the present invention disclosed herein should not be limited by the exemplary embodiments disclosed above, but should only be defined according to the attached claims and their equivalents.

Claims

1. A fixed-point number method based on real-time clock module to compensate for crystal accuracy, characterized in that: include: Acquire actual temperature data of the crystal, and convert the actual temperature data into a signed number Temp, so that the positive and negative values ​​of the Temp data type represent the positive and negative values ​​of the temperature; Define integer data based on parabola coefficient, inflection point temperature and vertex ppm deviation; According to the integer data, a compensation accuracy based on a real-time clock module is calculated; as well as The compensation accuracy is superimposed on the 0ppm value of the real-time clock module and written into the RTC compensation register.

2. The fixed-point number method based on real-time clock module compensation crystal precision according to claim 1, characterized in that: Acquire the actual temperature data of the crystal, and convert the actual temperature data into a signed number Temp, so that the positive and negative of the Temp data type represents the positive and negative of the temperature, including: Use a temperature sensor to obtain actual temperature data of the crystal, wherein the actual temperature data length is 16 bits, data 0 to 0x7FFF represents positive temperature, and data 0x8000 to 0xFFFF represents negative temperature; The signed number Temp is defined as follows, Temp=T*2 TEMP_SHIFT Where T is the actual temperature of the crystal and TEMP_SHIFT is defined by, 1 / 2 TEMP_SHIFT =The actual temperature of the integer data of the temperature value.

3. The fixed-point number method based on real-time clock module compensation crystal precision according to claim 1 or 2, characterized in that: The integer data includes MACRO_ALPHA, MACRO_TI and MACRO_PPM_T; MACRO_ALPHA is defined as follows, MACRO_ALPHA=α*2 ALPHA_SHIFT *MACRO_RTC Among them, * represents multiplication, and α is the parabola coefficient; According to α*2 ALPHA_SHIFT The integer data value retains the precision of α and determines the value of ALPHA_SHIFT; Among them, MACRO_RTC is defined by the following formula: MACRO_RTC = 32768*32 / 1000000 MACRO_TI is defined by the following formula, MACRO_TI=Ti*2 TEMP_SHIFT Where Ti is the inflection point temperature; TEMP_SHIFT is defined as follows, 1 / 2 TEMP_SHIFT =The actual temperature of the integer data of the temperature value. MACRO_PPM_T is defined by the following formula, MACRO_PPM_T=ppm_t*2 ALPHA_SHIFT *MACRO_RTC*2 TEMP_SHIFT *2 TEMP_SHIFT Where ppm_t is the vertex ppm deviation.

4. The fixed-point number method based on real-time clock module compensation crystal precision according to claim 3, characterized in that: The definition items are processed by the precompiler during program implementation, and the calculation process does not occupy the execution time of the program.

5. The fixed-point number method based on real-time clock module compensation crystal precision according to any one of claims 1 to 3, characterized in that: According to the integer data, the compensation accuracy based on the real-time clock module is calculated to include: The compensation accuracy RTC_ca based on the real-time clock module is given by the following formula: RTC_ca=MACRO_F / 2 (ALPHA_SHIFT +TEMP_SHIFT +TEMP_SHIFT) Where MACRO_F is defined as follows: MACRO_F=MACRO_ALPHA*(Temp–MACRO_TI) 2 +MACRO_PPM_T Among them, MACRO_ALPHA, MACRO_TI and MACRO_PPM_T are integer data of parabola coefficient, inflection point temperature and vertex ppm deviation, and Temp is the signed number converted from the actual temperature data of the crystal.

6. The fixed-point number method based on real-time clock module compensation crystal precision according to claim 1, characterized in that: Adding the compensation accuracy to the 0ppm value of the real-time clock module and writing it into the RTC compensation register includes: The 0ppm compensation value of the real-time clock module is 0x20, and the compensation accuracy is superimposed with 0x20 for setting the compensation accuracy register of the RTC compensation module.

7. A device for compensating crystal accuracy based on a real-time clock module, characterized in that: include: Compensation control module, setting and starting the RTC compensation function; 15-bit asynchronous frequency divider module, outputs compensated high-precision 1Hz.

8. A computer-readable storage medium, characterized in that: Machine-readable instructions are stored thereon, and when the machine-readable instructions are executed by a processor, the steps of the method according to any one of claims 1 to 6 are performed.