Crystal oscillator calibration method, device and computer equipment

By obtaining the period count value of the target crystal oscillator and using the binary search method for calibration, the problem of temperature affecting the internal crystal oscillator of the chip was solved, achieving frequency stability and cost reduction.

CN115603735BActive Publication Date: 2026-06-09GREE ELECTRIC APPLIANCE INC OF ZHUHAI +1

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
GREE ELECTRIC APPLIANCE INC OF ZHUHAI
Filing Date
2022-09-09
Publication Date
2026-06-09

Smart Images

  • Figure CN115603735B_ABST
    Figure CN115603735B_ABST
Patent Text Reader

Abstract

Embodiments of the present application provide a crystal calibration method, device and computer equipment, the method. The method comprises obtaining a cycle count value of a target crystal in a preset time interval, the cycle count value being the vibration frequency of a reference crystal in the time interval; if the cycle count value is not in a preset count value reference interval, calibrating the target crystal until a calibration stop condition is reached. The method provided by the present application can calibrate the frequency of the target crystal based on the reference crystal, improve the reliability of the target crystal, increase the application range of the internal low-speed crystal, thereby reducing the circuit board area and component cost.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of microelectronics technology, and in particular to a crystal oscillator calibration method, apparatus, and computer equipment. Background Technology

[0002] Traditionally, internal crystal oscillators in chips often use RC oscillators. Because RC oscillators are easily affected by ambient temperature, the oscillation frequency error of the internal crystal oscillator will vary with temperature. Specifically, both rising and falling temperatures will reduce the accuracy of the internal crystal oscillator, causing its oscillation frequency to vary within the range of 5% to 50% of the nominal output frequency.

[0003] When the operating environment cannot meet the constant temperature requirements and strict time accuracy is required, an external crystal oscillator with a stable oscillation frequency is usually needed. However, external crystal oscillators increase the circuit board area and component cost, making them impractical for real-world applications. Summary of the Invention

[0004] To address the problem of unstable frequency caused by the significant influence of ambient temperature on the internal crystal oscillators of existing chips, this application provides a crystal oscillator calibration method, apparatus, and computer equipment, which can improve the accuracy and reliability of the crystal oscillation frequency.

[0005] On the one hand, a crystal oscillator calibration method is provided, the method comprising:

[0006] Obtain the period count value of the target crystal oscillator within a preset time interval, wherein the period count value is the number of vibrations of the reference crystal oscillator within the time interval;

[0007] If the period count value is not within the preset count value reference range, the target crystal oscillator is calibrated until the calibration stop condition is met.

[0008] On the other hand, a crystal oscillator calibration device is provided, the device comprising:

[0009] The counting value acquisition module is used to acquire the period count value of the target crystal oscillator within a preset time interval, wherein the period count value is the number of vibrations of the reference crystal oscillator within the time interval;

[0010] The crystal oscillator frequency calibration module is used to calibrate the target crystal oscillator if the period count value is not within a preset count value reference range, until the calibration stop condition is met.

[0011] On the other hand, a computer device is provided, which includes a processor and a memory. The memory stores at least one instruction, at least one program, code set, or instruction set. The processor can load and execute at least one instruction, at least one program, code set, or instruction set to implement the crystal oscillator calibration method provided in the above-mentioned embodiments.

[0012] On the other hand, a computer-readable storage medium is provided, which stores at least one instruction, at least one program, code set, or instruction set. A processor can load and execute at least one instruction, at least one program, code set, or instruction set to implement the crystal oscillator calibration method provided in the embodiments of this application.

[0013] On the other hand, a computer program product or computer program is provided, which includes computer program instructions stored in a computer-readable storage medium. A processor reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform any of the crystal oscillator calibration methods described in the above embodiments.

[0014] The beneficial effects of the technical solution provided in this application include at least the following: Embodiments of the present invention provide a crystal oscillator calibration method, apparatus, and computer device. The method includes acquiring a period count value of a target crystal oscillator within a preset time interval, wherein the period count value is the number of vibrations of a reference crystal oscillator within the time interval; if the period count value is not within a preset count value reference range, the target crystal oscillator is calibrated until a calibration stop condition is met. The method provided by embodiments of the present invention can calibrate the frequency of a target crystal oscillator based on a reference crystal oscillator, improving the reliability of the target crystal oscillator, increasing the application range of internal low-speed crystal oscillators, thereby reducing circuit board area and component costs. Attached Figure Description

[0015] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying 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.

[0016] Figure 1 The illustration shows a schematic diagram of the implementation flow of a crystal oscillator calibration method provided in an exemplary embodiment of this application;

[0017] Figure 2 This illustration shows a module structure diagram of an application of a crystal oscillator calibration method provided in an exemplary embodiment of this application;

[0018] Figure 3 This illustration shows a schematic diagram illustrating the application effect of a crystal oscillator calibration method provided in an exemplary embodiment of this application;

[0019] Figure 4 This illustration shows another implementation flow diagram of a crystal oscillator calibration method provided in an exemplary embodiment of this application;

[0020] Figure 5 This illustration shows another implementation flow diagram of a crystal oscillator calibration method provided in an exemplary embodiment of this application;

[0021] Figure 6 This illustration shows another implementation flow diagram of a crystal oscillator calibration method provided in an exemplary embodiment of this application;

[0022] Figure 7 This illustration shows another implementation flow diagram of a crystal oscillator calibration method provided in an exemplary embodiment of this application;

[0023] Figure 8 A structural diagram of a crystal oscillator calibration device provided in an exemplary embodiment of this application is shown;

[0024] Figure 9 A schematic diagram of the structure of a computer device corresponding to a crystal oscillator calibration method provided in an exemplary embodiment of this application is shown. Detailed Implementation

[0025] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be described in further detail below with reference to the accompanying drawings.

[0026] The crystal oscillator calibration method provided in this application can correct crystal oscillators, especially internal low-speed crystal oscillators, and avoid errors caused by temperature changes.

[0027] Example 1

[0028] The method provided in this invention can be applied to a low-speed internal RC oscillator (LIRC) embedded in a chip.

[0029] Figure 1 The diagram illustrates the implementation flow of a crystal oscillator calibration method provided by an embodiment of the present invention.

[0030] See Figure 1 The crystal oscillator calibration method provided in this embodiment of the invention may include steps 101 and 102.

[0031] Step 101: Obtain the period count value of the target crystal oscillator within a preset time interval, wherein the period count value is the number of vibrations of the reference crystal oscillator within the time interval.

[0032] Specifically, the target crystal oscillator can be a LIRC, and the reference crystal oscillator can be an embedded high-speed internal RC oscillator (HIRC) or a high-speed oscillator (HOSC).

[0033] In some embodiments, LIRC serves as the clock source for the chip's real-time clock.

[0034] In some embodiments, the crystal oscillator calibration method provided in this invention may further include:

[0035] The preset time interval is calculated based on the time interval calculation formula.

[0036] The time interval calculation formula includes:

[0037]

[0038] Where F1 is the preset frequency, RTC is the ideal frequency of the target crystal oscillator, Pre is the pre-division number, W is the number of wake-up times, and T1 is the time interval.

[0039] Optionally, the ideal frequency of the target crystal oscillator is 32.768KHz, the prescaler is 7, and the number of wake-up times is 1. The above preset frequency is 1024Hz, and the accurate value of the time interval is 1 / 1024 seconds, which is 976.5625 microseconds, approximately equal to 1 millisecond.

[0040] In some embodiments, obtaining the period count value of the target crystal oscillator within a preset time interval includes:

[0041] The peripheral event system captures the rising or falling edge of the reference crystal oscillator to obtain the period count value.

[0042] In some embodiments, HIRC or HOSC is used as the clock source for the enhanced timer.

[0043] In some embodiments, the enhanced counter captures the cycle count value when triggered by the PES.

[0044] In some embodiments, the crystal oscillator calibration method further includes:

[0045] The ideal count value is obtained by multiplying the preset time interval and the reference frequency of the reference crystal oscillator.

[0046] In some embodiments, the reference frequency of the reference crystal oscillator is 7.9545MHz, the preset time interval is 976.5625 microseconds, and multiplying them together yields an ideal count value of 7768.

[0047] Based on the ideal count value and the preset accuracy value, the reference range of the count value is determined.

[0048] Specifically, based on the ideal count value and the precision value, the upper and lower limits of the count value reference interval are calculated;

[0049] The reference range for the count value is determined based on the upper and lower limits.

[0050] In a specific example, if the preset precision value is 0.314%, then the upper limit is (1 + 0.314%) × 7768, and the lower limit is (1 - 0.314%) × 7768.

[0051] Step 102: If the period count value is not within the preset count value reference range, then the target crystal oscillator is calibrated until the calibration stop condition is met.

[0052] In some embodiments, step 102 includes:

[0053] If the period count value is greater than the upper limit of the counting reference interval, the target crystal oscillator is frequency-reduced and calibrated based on the bisection approximation method until the period count value is within the counting reference interval or the number of calibrations reaches a preset threshold.

[0054] If the period count value is less than the lower limit of the counting reference interval, the target crystal oscillator is frequency-upgraded and calibrated based on the bisection approximation method until the period count value is within the counting reference interval or the number of calibrations reaches a preset threshold.

[0055] Specifically, during frequency downsampling or upsampling, the error range of the LIRC is determined by capturing the current cycle count value using an enhanced timer. The calibration value to be written, and whether coarse adjustment is needed, are then written to the LIRC's calibration register. These steps are repeated using a binary search method to achieve further calibration until the preset accuracy requirement is met, or the maximum number of calibrations is reached.

[0056] Figure 2 The diagram illustrates a module structure of an application of a method provided in an embodiment of the present invention.

[0057] See Figure 2 In some embodiments, the embedded low-speed RC oscillator is timed based on a real-time clock, with the embedded high-speed RC oscillator or high-speed oscillator as a reference. After being triggered by the peripheral event system, the result is finally captured by the ETM.

[0058] Figure 3 The diagram illustrates the application effect of a method provided by an embodiment of the present invention.

[0059] See Figure 3 The PTC timing triggers the PES to generate a stable pulse signal.

[0060] The method provided in this invention uses RTC timing, PES triggering, and ETM capture to calibrate a low-precision crystal oscillator with a high-precision crystal oscillator, which can effectively reduce frequency error and enable the crystal oscillator frequency to meet the required accuracy.

[0061] Example 2

[0062] Figure 4 This diagram illustrates another implementation flow of the method provided in this embodiment of the invention.

[0063] See Figure 4 In some embodiments, this method may include the following procedures.

[0064] First, switch the system clock to 8MHz HIRC or HOSC to perform ETM capture. Optionally, the number of capture attempts can be set to 5. After capture is complete, reset the capture status based on the feedwdog.

[0065] The current capture count is checked. If the capture count is not zero, it is further determined whether the error between the current period value and the 1ms standard value exceeds the error threshold. Optionally, the error threshold is ±0.314% of the 1ms standard value 7768.

[0066] If the current error value exceeds the error threshold, the calibration flag is set, the LIRC is calibrated, and the capture count is decremented by one.

[0067] If the current capture count is zero, or the current error value no longer exceeds the error threshold, then stop ETM capture and RTC counting, switch to a 1MHz HIRC / HOSC clock, clear the calibration count to zero, and enable the capture status.

[0068] In some embodiments, the frequency calculation formula for the time interval includes:

[0069] Interval frequency = Ideal frequency / (2(Prescaler + 1) × (Number of wake-ups + 1)).

[0070] Figure 5 This diagram illustrates another implementation flow of the method provided in an embodiment of the present invention.

[0071] See Figure 5 In some embodiments, the ETM capture process in this method may include the following steps.

[0072] First, call ETM to obtain the captured value.

[0073] If the calibration flag is not in the write-1 state at this time, the new capture value will overwrite the original capture value, and the total cycle value, capture cycle and calibration count will be cleared to zero.

[0074] If the calibration flag is set to 1 at this time, the new capture value will overwrite the original capture value, the capture period will be calculated, and the calibration count will be increased by 1.

[0075] When the number of calibrations is no more than 3, the total cycle value is incremented by the current capture cycle, and the capture cycle value is adjusted to 1 / 3 of the new total cycle value. The ETM capture flag is then set to 1.

[0076] When the number of calibrations exceeds 3, directly set the ETM capture flag to 1.

[0077] Figure 6 This diagram illustrates another implementation flow of the method provided in an embodiment of the present invention.

[0078] See Figure 6 In some embodiments, the LIRC down-frequency reduction process in this method may include the following steps.

[0079] First, determine if the capture period exceeds 10% of the standard value. If it does not exceed the standard value, continue monitoring.

[0080] If the capture period exceeds the standard value by more than 10%, a fine-tuning is performed.

[0081] If the fine-tuning time does not exceed 3µs, the fine-tuning will be increased by 1 level, and the corresponding register value will be updated.

[0082] If the frequency exceeds 3µs after one fine adjustment, increase the coarse adjustment by one level and the fine adjustment by one level. Decrease the coarse adjustment value and increase the fine adjustment value until the frequency increases to the ideal value. Finally, determine the new coarse and fine adjustment values ​​and update the register values ​​accordingly.

[0083] Figure 7 This diagram illustrates another implementation flow of the method provided in an embodiment of the present invention.

[0084] See Figure 7 In some embodiments, the LIRC upsampling process in this method may include the following steps.

[0085] First, determine if the capture period is more than 10% below the standard value. If it is not below, continue monitoring.

[0086] If the capture period is more than 10% below the standard value, a fine-tuning is performed.

[0087] If the fine-tuning time does not exceed 3µs, the fine-tuning will be reduced by one level, and the corresponding register will be updated.

[0088] If the fine-tuning exceeds 3µs, decrease the coarse adjustment value and increase the fine adjustment value until the frequency increases to the ideal value. Then, determine the new coarse and fine adjustment values ​​and update the registers accordingly.

[0089] In some embodiments, the method provided by the present invention can be applied to the calibration of low-speed crystal oscillators (LIRC) inside remote controls of various electrical appliances.

[0090] In summary, the crystal oscillator calibration method provided by the embodiments of the present invention can reduce the error caused by the frequency of the low-speed crystal oscillator inside the chip being affected by temperature. In many scenarios, it can replace the external low-speed crystal oscillator, thereby reducing the cost of peripheral components and the wiring space of the circuit board, improving wiring efficiency, and reducing product size.

[0091] Example 3

[0092] Figure 8 A schematic diagram of the crystal oscillator calibration device provided in an embodiment of the present invention is shown.

[0093] See Figure 8 The crystal oscillator calibration device provided in this embodiment of the invention may include:

[0094] The counting value acquisition module 201 is used to acquire the period count value of the target crystal oscillator within a preset time interval, wherein the period count value is the number of vibrations of the reference crystal oscillator within the time interval;

[0095] The crystal oscillator frequency calibration module 202 is used to calibrate the target crystal oscillator if the period count value is not within the preset count value reference range, until the calibration stop condition is met.

[0096] In some embodiments, the crystal oscillator calibration device may further include a time interval calculation module for calculating the preset time interval based on a time interval calculation formula;

[0097] The time interval calculation formula includes:

[0098]

[0099] Where F1 is the preset frequency, RTC is the ideal frequency of the target crystal oscillator, Pre is the pre-division number, W is the number of wake-up times, and T1 is the time interval.

[0100] In some embodiments, the count value acquisition module 201 is specifically used for:

[0101] The peripheral event system captures the rising or falling edge of the reference crystal oscillator to obtain the period count value.

[0102] In some embodiments, the crystal oscillator calibration device may further include an ideal count value calculation module, which is used to multiply the preset time interval and the reference frequency of the reference crystal oscillator to obtain the ideal count value;

[0103] Based on the ideal count value and the preset accuracy value, the reference range of the count value is determined.

[0104] In some embodiments, the ideal count value calculation module is specifically used for:

[0105] Based on the ideal count value and the precision value, calculate the upper and lower limits of the count value reference interval;

[0106] The reference range for the count value is determined based on the upper and lower limits.

[0107] In some embodiments, the crystal oscillator frequency calibration module 202 is specifically used for:

[0108] If the period count value is greater than the upper limit of the counting reference interval, the target crystal oscillator is frequency-reduced and calibrated based on the bisection approximation method until the period count value is within the counting reference interval or the number of calibrations reaches a preset threshold.

[0109] In some embodiments, the crystal oscillator frequency calibration module 202 is specifically used for:

[0110] If the period count value is less than the lower limit of the counting reference interval, the target crystal oscillator is frequency-upgraded and calibrated based on the bisection approximation method until the period count value is within the counting reference interval or the number of calibrations reaches a preset threshold.

[0111] In summary, the crystal oscillator calibration device provided by this invention can reduce the frequency error caused by temperature variations in the low-speed crystal oscillator inside the chip. In many scenarios, it can replace external low-speed crystal oscillators, thereby reducing the cost of peripheral components and the wiring space on the circuit board, improving wiring efficiency, and reducing product size.

[0112] Example 4

[0113] Figure 9 This application shows a schematic diagram of the structure of a computer device provided in an exemplary embodiment, the computer device comprising:

[0114] The processor 301 includes one or more processing cores. The processor 301 executes various functional applications and data processing by running software programs and modules.

[0115] The receiver 302 and transmitter 303 can be implemented as a communication component, which can be a communication chip. Optionally, this communication component can include signal transmission functionality. That is, the transmitter 303 can be used to transmit control signals to the image acquisition device and the scanning device, and the receiver 302 can be used to receive corresponding feedback commands.

[0116] The memory 304 is connected to the processor 301 via the bus 305.

[0117] The memory 304 can be used to store at least one instruction, and the processor 301 is used to execute the at least one instruction to implement steps 101 to 102 in the above crystal oscillator calibration method embodiment.

[0118] Example 5

[0119] This application also provides a computer-readable storage medium storing at least one instruction, at least one program, code set, or instruction set, which can be loaded and executed by a processor to implement the crystal oscillator calibration method described above.

[0120] Example 6

[0121] This application also provides a computer program product or computer program that includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform any of the mobile terminal application software interaction methods described in the above embodiments.

[0122] Optionally, the computer-readable storage medium may include: read-only memory (ROM), random access memory (RAM), solid-state drives (SSDs), or optical discs, etc. The random access memory may include resistive random access memory (ReRAM) and dynamic random access memory (DRAM). The sequence numbers of the embodiments described above are for descriptive purposes only and do not represent the superiority or inferiority of the implementation.

[0123] Those skilled in the art will understand that all or part of the steps of the above embodiments can be implemented by hardware or by a program instructing related hardware. The program can be stored in a computer-readable storage medium, such as a read-only memory, a disk, or an optical disk.

[0124] The above are merely optional embodiments of this application and are not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.

Claims

1. A crystal oscillator calibration method, characterized in that, The method includes: The process involves acquiring the period count value of a target crystal oscillator within a preset time interval, where the period count value is the number of oscillations of a reference crystal oscillator within the time interval. Acquiring the period count value of the target crystal oscillator within the preset time interval includes: capturing the rising or falling edge of the reference crystal oscillator based on a peripheral event system to obtain the period count value, wherein the value is ultimately captured by an enhanced timer after being triggered by the peripheral event system. The target crystal oscillator is an embedded low-speed RC oscillator of the chip; the embedded low-speed RC oscillator serves as the clock source for the chip's real-time clock. If the period count value is not within the preset count value reference range, the target crystal oscillator is calibrated until the calibration stop condition is met. The method further includes: The preset time interval is calculated based on the time interval calculation formula; The time interval calculation formula includes: ; in, For preset frequency, RTC The ideal frequency for the target crystal oscillator. Pre For pre-division frequency, W For the number of wake-ups, For time intervals.

2. The method according to claim 1, characterized in that, The method further includes: The ideal count value is obtained by multiplying the preset time interval and the reference frequency of the reference crystal oscillator. Based on the ideal count value and the preset accuracy value, the reference range of the count value is determined.

3. The method according to claim 2, characterized in that, Determining the reference range for the count value based on the ideal count value and the preset precision value includes: Based on the ideal count value and the preset precision value, calculate the upper and lower limits of the count value reference interval; The reference range for the count value is determined based on the upper and lower limits.

4. The method according to any one of claims 1 to 3, characterized in that, The calibration of the target crystal oscillator until the calibration stop condition is met includes: If the period count value is greater than the upper limit of the count value reference interval, the target crystal oscillator is frequency-reduced and calibrated based on the bisection approximation method until the period count value is within the count value reference interval or the number of calibrations reaches a preset threshold.

5. The method according to any one of claims 1 to 3, characterized in that, The calibration of the target crystal oscillator until the calibration stop condition is met includes: If the period count value is less than the lower limit of the count value reference interval, the target crystal oscillator is frequency-upgraded and calibrated based on the bisection approximation method until the period count value is within the count value reference interval or the number of calibrations reaches a preset threshold.

6. A crystal oscillator calibration device, characterized in that, The device includes: A counting value acquisition module is used to acquire the period count value of the target crystal oscillator within a preset time interval, wherein the period count value is the number of vibrations of the reference crystal oscillator within the time interval; the counting value acquisition module is specifically used to: capture the rising edge or falling edge of the reference crystal oscillator based on the peripheral event system to obtain the period count value, wherein, after being triggered by the peripheral event system, it is finally captured by an enhanced timer; the target crystal oscillator is an embedded low-speed RC oscillator of the chip; the embedded low-speed RC oscillator serves as the clock source of the chip's real-time clock; The crystal oscillator frequency calibration module is used to calibrate the target crystal oscillator if the period count value is not within the preset count value reference range, until the calibration stop condition is met. The crystal oscillator calibration device also includes a time interval calculation module, used to calculate the preset time interval based on the time interval calculation formula; The time interval calculation formula includes: ; in, For preset frequency, RTC The ideal frequency for the target crystal oscillator. Pre For pre-division frequency, W For the number of wake-ups, For time intervals.

7. A computer device, characterized in that, The computer device includes a processor and a memory, the memory storing at least one instruction, at least one program, code set, or instruction set, the at least one instruction, at least one program, code set, or instruction set being loaded and executed by the processor to implement the crystal oscillator calibration method as described in any one of claims 1 to 5.

8. A computer-readable storage medium, characterized in that, The readable storage medium stores at least one instruction, at least one program, code set, or instruction set, wherein the at least one instruction, at least one program, code set, or instruction set is loaded and executed by a processor to implement the crystal oscillator calibration method as described in any one of claims 1 to 5.