Microcontroller-based crystal frequency automatic testing and closed-loop compensation method and system

CN122525212APending Publication Date: 2026-08-07GUANGDONG FAILONG CRYSTAL TECH
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
GUANGDONG FAILONG CRYSTAL TECH
Filing Date
2026-05-14
Publication Date
2026-08-07

AI Technical Summary

Technical Problem

[0007]综上所述,现有TCXO测试技术在信号整形精度、硬件柔性适配及流程闭环协同等方面存在明显不足,亟需一种能够实现高精度频率采集、动态电压适配及测量-烧录-验证全自动闭环的新型测试方法与系统

Benefits of technology

[0011] Unlike existing technologies, this application uses a microcontroller to dynamically adjust the power supply module, ensuring a strict match between the operating voltage and communication level and the physical layer of the crystal oscillator IC under test. This automatically adapts to the power supply and communication requirements of different temperature-compensated crystal oscillator IC models, eliminating the need for frequent hardware tooling changes for different product specifications and effectively mitigating the risk of damage to the communication interface of the crystal oscillator IC due to level mismatch. Furthermore, this application utilizes a high-frequency timer within the microcontroller combined with equal-precision measurement methods to accurately calculate the current actual oscillation frequency of the crystal oscillator IC, effectively improving the accuracy and stability of frequency acquisition.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122525212A_ABST
    Figure CN122525212A_ABST
Patent Text Reader

Abstract

The application discloses a microcontroller-based crystal frequency automatic testing and closed-loop compensation method and system, which comprises the following steps: S1, an upper computer acquires crystal IC model parameters and issues instructions to control a microcontroller to dynamically adjust the working voltage and communication level output by a power supply module; S2, a two-stage logic shaping circuit converts the peak-clipped sinusoidal wave signal output by the crystal IC into a standard digital square wave signal through a high-speed comparator and a Schmitt trigger; S3, the microcontroller calculates an actual oscillation frequency by using an equal-precision measurement method; S4, the upper computer calculates frequency correction parameters by using a temperature compensation algorithm, and the microcontroller switches the test channel mode to burn the frequency correction parameters into a volatile register; and S5, after the burning is completed, the system is reset for secondary measurement, and it is verified whether the frequency deviation after compensation reaches a preset precision threshold, and when the verification is qualified, the frequency correction parameters are written into a non-volatile register. The application realizes high-precision frequency acquisition, dynamic voltage adaptation and full-automatic closed-loop measurement-burning-verification.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of automated testing and production technology of crystal oscillators, and in particular to a method and system for automatic testing and closed-loop compensation of crystal oscillator frequency based on a microcontroller. Background Technology

[0002] Temperature-compensated crystal oscillators (TCXOs), as core frequency references in modern electronic devices, are widely used in fields such as communication, navigation, and measurement and control where frequency stability is extremely critical. Their frequency accuracy directly determines the system's communication quality and synchronization performance. With the rapid development of 5G communication, satellite navigation, and high-precision measurement technologies, the market has placed stringent requirements on TCXO frequency accuracy at the ppb (parts per billion) level, posing significant challenges to mass production testing and compensation processes. However, existing TCXO mass production testing technologies still have many significant shortcomings, hindering improvements in product yield and production efficiency.

[0003] Firstly, regarding signal acquisition accuracy, high-performance TCXOs typically output clipped sine wave signals with weak amplitudes (usually below 1.3V) and significant DC component offset. Existing test equipment often uses direct sampling or simple shaping methods to process this signal, which easily leads to counting jitter due to the non-steep waveform edges and low signal-to-noise ratio, making it difficult to achieve frequency acquisition resolution at the ppb level. This phase jitter and edge mis-triggered issues introduce significant measurement errors, severely affecting the accuracy of subsequent temperature compensation parameters and becoming a key bottleneck restricting frequency calibration accuracy.

[0004] Secondly, regarding hardware compatibility flexibility, the market offers a wide variety of TCXO product specifications, with different IC models operating at voltages ranging from 1.8V to 5V, and communication clock and data transmission line voltages varying from 3.3V to 6.5V. Existing testing technologies typically employ fixed-voltage test fixtures, requiring frequent replacement of hardware adapter boards for different product models. This not only hinders flexible production but also carries the risk of damaging the communication interface of the IC under test due to voltage level mismatches. This rigid "one board per model" architecture significantly increases equipment investment costs and production line changeover time, making it difficult to adapt to the modern manufacturing model of multi-variety, small-batch production.

[0005] Secondly, regarding the collaboration of the testing process, traditional production models typically separate "frequency measurement" and "parameter programming" into two independent stages. Measurement data needs to be manually transferred between different devices, which not only increases labor costs and management complexity, but more importantly, due to slight differences between the measurement and programming environments, the calculated compensation values ​​will have secondary deviations after actual programming. This discrete process, lacking real-time closed-loop verification, cannot immediately confirm and iteratively correct the compensation effect, making it difficult to guarantee the consistency of the frequency accuracy of the final product.

[0006] Furthermore, existing technologies typically require separate physical channels and probes for frequency measurement and parameter programming, further increasing hardware complexity and contact reliability risks. How to achieve high-fidelity digitization of weak analog signals, voltage adaptive adaptation for multiple IC specifications, and integrated closed-loop control of measurement and programming on the same hardware platform has become a pressing technical challenge in the field of TCXO automated testing.

[0007] In summary, existing TCXO testing technologies have significant shortcomings in terms of signal shaping accuracy, hardware flexibility, and closed-loop process coordination. There is an urgent need for a new testing method and system that can achieve high-precision frequency acquisition, dynamic voltage adaptation, and a fully automated closed-loop measurement-programming-verification process. Summary of the Invention

[0008] The purpose of this application is to provide a microcontroller-based automatic crystal oscillator frequency testing and closed-loop compensation method and system, which can realize high-precision frequency acquisition, dynamic voltage adaptation, and fully automatic closed-loop measurement-programming-verification.

[0009] The first aspect of this application provides a method for automatic crystal oscillator frequency testing and closed-loop compensation based on a microcontroller, the method comprising: S1. The host computer obtains the model parameters of the crystal oscillator IC under test and sends control commands to the microcontroller. The microcontroller dynamically adjusts the power supply module based on the control commands and outputs the working voltage and communication level that match the physical layer of the crystal oscillator IC under test. S2. The two-stage logic shaping circuit obtains the weak peak-clipping sine wave signal output by the crystal oscillator IC under test. The signal zero-crossing point is captured by the high-speed comparator and the primary pulse is flipped. The glitches and noise at the moment of level transition are eliminated by the Schmitt trigger, and the standard digital square wave signal with steep edges is output. S3. The microcontroller captures the standard digital square wave signal through its internal timer and calculates the current actual oscillation frequency using the equal precision measurement method, and then uploads the actual oscillation frequency to the host computer. S4. The host computer obtains the actual oscillation frequency and the theoretical standard frequency, calculates the frequency correction parameters based on the temperature compensation algorithm, and sends a programming instruction to the microcontroller. The microcontroller switches the test channel to communication mode based on the programming instruction and programs the frequency correction parameters into the volatile register inside the crystal oscillator IC under test, so as to adjust the frequency of the crystal oscillator IC under test in real time. S5. After the programming is completed, the microcontroller switches the test channel back to the measurement mode. The host computer performs a second acquisition of the adjusted frequency of the crystal oscillator IC under test, and verifies whether the frequency deviation after compensation reaches the preset accuracy threshold. If it is qualified, the process ends and the frequency correction parameters are written into the non-volatile register inside the crystal oscillator IC under test, forming a fully automatic closed loop of "measurement-programming-verification".

[0010] A second aspect of this application provides a microcontroller-based automatic frequency testing and closed-loop compensation system for crystal oscillator ICs, used for automated testing of the IV characteristics of multi-pin devices. The system includes: The host computer is used to receive the model parameters and theoretical standard frequency of the crystal oscillator IC under test from the user. The microcontroller transmits data to the host computer via a serial communication protocol, receives control commands from the host computer, and performs parameter measurement, programming, and verification of the crystal oscillator IC under test based on the control commands. The power supply module provides dynamically adjustable operating voltage and communication level. The microcontroller dynamically adjusts the power supply module based on control commands. The bipolar logic shaping circuit is used to convert the peak-clipping sine wave output by the crystal oscillator IC under test into a standard digital square wave that meets the input conditions of the microcontroller. The bipolar logic shaping circuit includes a high-speed comparator and a Schmitt trigger. The high-speed comparator is used to capture the zero-crossing point of the signal and perform primary pulse flipping, while the Schmitt trigger is used to eliminate glitches and noise at the moment of level transition.

[0011] Unlike existing technologies, this application uses a microcontroller to dynamically adjust the power supply module, ensuring a strict match between the operating voltage and communication level and the physical layer of the crystal oscillator IC under test. This automatically adapts to the power supply and communication requirements of different temperature-compensated crystal oscillator IC models, eliminating the need for frequent hardware tooling changes for different product specifications and effectively mitigating the risk of damage to the communication interface of the crystal oscillator IC due to level mismatch. Furthermore, this application utilizes a high-frequency timer within the microcontroller combined with equal-precision measurement methods to accurately calculate the current actual oscillation frequency of the crystal oscillator IC, effectively improving the accuracy and stability of frequency acquisition.

[0012] The bipolar logic shaping circuit of this application consists of a high-speed comparator and a Schmitt trigger. Utilizing the inherent characteristics of the high-speed comparator and Schmitt trigger, the high-speed comparator captures the zero-crossing point of a weak clipped sine wave and performs primary pulse flipping. Then, the Schmitt trigger eliminates glitches and noise at the moment of level transition. This can convert a weak, gently edged analog signal into a standard digital square wave with steep edges, significantly reducing signal jitter and false trigger probability, and providing high-quality digital pulse input for subsequent accurate frequency measurement.

[0013] The host computer in this application automatically calculates frequency correction parameters based on the deviation between the actual oscillation frequency and the theoretical standard frequency by running a temperature compensation algorithm. The microcontroller switches the test channel to communication mode to complete parameter programming. After programming, the system automatically resets and repeats the frequency measurement to verify whether the compensation result reaches the set accuracy threshold, forming a fully automatic closed loop of "measurement-algorithm-programming-verification". This ensures that the frequency accuracy after compensation meets the requirements, reduces manual intervention, and improves production efficiency and calibration consistency.

[0014] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and are not intended to limit this application. 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 This is a schematic diagram of the overall structure of an embodiment of the microcontroller-based automatic frequency testing and closed-loop compensation system for crystal oscillator ICs according to this application; Figure 2 This is a flowchart illustrating an embodiment of the microcontroller-based automatic frequency testing and closed-loop compensation method for crystal oscillator ICs according to this application. Figure 3 This is a schematic diagram of the specific process for calculating the true frequency value of the microcontroller-based crystal IC frequency automatic testing and closed-loop compensation system of this application. Figure 4 This is a schematic diagram illustrating the specific process of parameter programming and closed-loop verification for the microcontroller-based automatic frequency testing and closed-loop compensation system for crystal oscillator ICs in this application. Detailed Implementation

[0017] To enable those skilled in the art to better understand the technical solutions of this application, the automatic frequency testing and closed-loop compensation method and system for microcontroller-based crystal oscillator ICs provided in this application will be further described in detail below with reference to the accompanying drawings and specific embodiments. It is understood that the described embodiments are merely some embodiments of this application, and not all embodiments. All other embodiments obtained by those skilled in the art based on the embodiments of this application without creative effort are within the scope of protection of this application.

[0018] The terms "first," "second," etc., used in this application are used to distinguish different objects, not to describe a specific order. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or apparatus that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to these processes, methods, products, or apparatuses.

[0019] Please see Figure 1The microcontroller-based automatic frequency testing and closed-loop compensation system for crystal oscillator ICs provided in this application mainly consists of a host computer 10, a microcontroller 20, a power supply module 21, and a two-stage logic shaping circuit 30. Specifically, the host computer runs automated testing software developed based on Python, interacts with the microcontroller 20 via the USB CDC virtual serial port protocol, and communicates with the crystal oscillator IC 40 under test through specific timing.

[0020] The two-stage logic shaping circuit 30 is used by the microcontroller 20 to measure the output signal of the crystal oscillator IC 40 under test. Specifically, it converts the peak-clipping sine wave output by the crystal oscillator IC 40 under test into a standard digital square wave that meets the input conditions of the microcontroller 20. The two-stage logic shaping circuit 30 includes a high-speed comparator 32 and a Schmitt trigger 31. The high-speed comparator 32 is used to capture the zero-crossing point of the signal and perform primary pulse flipping, while the Schmitt trigger 31 is used to eliminate glitches and noise at the moment of level transition.

[0021] The microcontroller 20 in this application can be an STM32H743 microprocessor, and the power supply module 21 can be a low dropout regulator (LDO). Optionally, the power supply module 21 can be any type of adjustable LDO. To meet the different voltage conditions for the operation and programming of the crystal oscillator IC 40 under test, the microcontroller 20 switches the feedback resistor of the LDO via an analog switch to achieve different voltage outputs, thus meeting the voltage requirements for communication.

[0022] Please see Figure 2 The microcontroller-based automatic frequency testing and closed-loop compensation method for crystal oscillator ICs provided in this application is used to complete fully automated closed-loop testing of the parameters of the crystal oscillator IC 40 under test, including parameter measurement, programming, and verification. The execution entity of this microcontroller-based automatic frequency testing and closed-loop compensation method can be the microcontroller-based automatic frequency testing and closed-loop compensation system described in the above embodiments. In some possible implementations, this microcontroller-based automatic frequency testing and closed-loop compensation method can also be implemented by a processor calling computer-readable instructions stored in memory.

[0023] like Figure 2 As shown, specifically, the microcontroller-based automatic crystal oscillator frequency testing and closed-loop compensation method of this embodiment may include the following steps: Step S1: The host computer obtains the model parameters of the crystal oscillator IC under test and sends control commands to the microcontroller. The microcontroller dynamically adjusts the power supply module based on the control commands and outputs the working voltage and communication level that match the physical layer of the crystal oscillator IC under test.

[0024] The host computer 10 can be equipped with a human-machine interaction module or a human-machine interaction interface. Users can input the model of the crystal oscillator IC40 under test and the theoretical standard frequency through the human-machine interaction module or human-machine interaction interface. The theoretical standard frequency is the nominal frequency (also called the rated frequency or center frequency) of the crystal oscillator IC40 under test.

[0025] The microcontroller 20 obtains the model parameters of the crystal oscillator IC40 under test from the host computer 10, and adjusts the feedback resistor value of the LDO to adjust the working voltage and communication level of the LDO output to the crystal oscillator IC40 under test, so that the output voltage of the LDO is strictly matched with the physical layer of the crystal oscillator IC40 under test.

[0026] This application uses a microcontroller 20 to dynamically adjust the feedback resistor value of the LDO, achieving dynamic output of a working voltage of 1.8V to 5V and a communication level of 3.3V to 6.5V. This ensures that the power supply level and communication level are strictly aligned at the physical level. For different models of temperature-compensated crystal oscillator ICs, seamless compatibility can be achieved without replacing any hardware adapter boards. This effectively avoids the risk of damage to the communication interface of the crystal oscillator IC under test due to level mismatch, significantly reduces equipment investment costs and production line changeover time, and meets the flexible production needs of multiple varieties and small batches.

[0027] Step S2: The two-stage logic shaping circuit acquires the weak clipped sine wave signal output by the crystal oscillator IC under test, and sequentially captures the zero-crossing point of the signal through a high-speed comparator and performs primary pulse flipping, and eliminates the glitches and noise at the moment of level transition through a Schmitt trigger, outputting a standard digital square wave signal with steep edges.

[0028] The two-stage logic shaping circuit 30 is used to convert the weak clipped sine wave signal output by the crystal oscillator IC 40 under test into a standard digital square wave that meets the input conditions of the microcontroller 20.

[0029] Specifically, step S2 includes the following steps: Step S21: The high-speed comparator captures the zero-crossing point of the signal and performs primary pulse flipping in combination with the preset reference voltage. The preset reference voltage is the reference bias voltage provided by the voltage follower constructed by the operational amplifier and input through the resistor voltage divider network.

[0030] In this embodiment, the high-speed comparator 32 can be an ultra-high-speed comparator. The ultra-high-speed comparator compares the signal with a set precise reference threshold (e.g., 0.5V) to instantly amplify and flip a weak signal of up to 1.3V into a rail-to-rail digital level. Compared to the GPIO of a regular MCU, the dedicated high-speed comparator has extremely low propagation delay and extremely low offset voltage, and can accurately lock the fixed phase point (e.g., zero crossing) of the input sine wave, ensuring that the phase of the frequency measurement is jitter-free from the source.

[0031] Step S22: The Schmitt trigger uses its own double threshold hysteresis characteristic to shield high-frequency environmental noise, thereby eliminating glitches and noise at the moment of level transition, and achieves edge sharpening by compressing the rise and fall time of the signal, outputting a standard digital square wave signal with steep edges.

[0032] Because the high-speed comparator 32 is extremely sensitive, when a slowly changing analog signal crosses the comparison threshold, if superimposed with microvolt-level high-frequency environmental noise, it is prone to multiple consecutive false flips (oscillations / glitches) at the edge. The Schmitt trigger 31 utilizes its unique double-threshold hysteresis characteristic to physically shield this noise, ensuring that the output signal flips "one and only once." Furthermore, it further compresses the rise and fall times of the signal, outputting an extremely steep and perfect 0~3.3V standard square wave, meeting the stringent setup / hold time requirements of the downstream high-speed digital circuitry. Simultaneously, the Schmitt trigger 31 acts as an isolation buffer, effectively preventing high-frequency digital flip noise from the downstream microcontroller 20 from being reverse-coupled to the fragile analog crystal oscillator network in the upstream stage.

[0033] The microcontroller 20 receives a perfectly conditioned 0~3.3V standard square wave. At this point, there is no risk of signal level mismatch or edge mis-triggered signal. The internal timer of the microcontroller 20 only needs to perform pulse edge capture or frequency metering with equal precision in a stable and reliable manner.

[0034] This application employs a two-stage logic shaping circuit 30 to physically decouple the "amplitude decision" from the "logic noise immunity." The front end uses a high-speed comparator 32 to capture the zero-crossing point of a weak, clipped sine wave and instantly flip it to a rail-to-rail digital level. The back end uses a Schmitt trigger 31 to physically shield high-frequency environmental noise using dual-threshold hysteresis, reshaping the chaotic analog signal into a standard digital square wave with extremely steep edges at zero bit error rate. Combined with the nanosecond-level timestamp recording of the high-frequency timer inside the microcontroller 20, this fundamentally eliminates the counting jitter problem caused by the non-sharp waveform edges and low signal-to-noise ratio in traditional direct sampling methods. This enables frequency acquisition resolution to reach the ppb level, providing a high-precision data foundation for subsequent temperature compensation.

[0035] Step S3: The microcontroller captures the standard digital square wave signal through its internal timer, calculates the current actual oscillation frequency using the equal precision measurement method, and uploads the actual oscillation frequency to the host computer.

[0036] Specifically, step S3 includes the following steps: Step S31: The host computer obtains the preset single frequency acquisition duration and the theoretical standard frequency of the crystal oscillator IC under test, and configures the microcontroller's internal timer as an internal counter to record the number of standard clock pulses, and configures the external timer as an external counter to record the number of pulses of the signal under test.

[0037] Step S32: Obtain the count values ​​of the internal timer and the external timer during the duration of a single frequency acquisition. Simultaneously, calculate the actual oscillation frequency of the crystal oscillator IC under test based on the standard high-frequency clock frequency of the internal timer.

[0038] The duration of a single frequency acquisition is The theoretical standard frequency of the crystal oscillator IC40 under test is .

[0039] Microcontroller 20 uses its internal high-frequency timer and extremely high clock frequency to record nanosecond-level timestamps. The internal timer of microcontroller 20 is TIM2, and the external timer is TIM5. TIM2 is used for internal counting, recording the number of internal high-frequency standard clock pulses. TIM5 is used for external counting, mainly recording the number of pulses of the measured signal. ) Specifically, when the host computer 10 starts the software for testing, the software is first pre-started, and the number of pulses of the signal being tested is set in the software. Simultaneously, the hardware starts synchronously. Upon the arrival of the first rising edge of the measured signal, the hardware is triggered, and TIM2 instantly latches the current count value (referred to as the initial value). At the same time, TIM5 starts counting; when the software gate ends, that is, when the number of pulses recorded by TIM5 reaches the set number of pulses of the measured signal ( TIM5 triggers an interrupt, and TIM2 simultaneously latches the final count value (referred to as the final value). At this point, a measurement is complete.

[0040] The actual count of the internal timer TIM2 can be calculated by determining the difference between the final value and the initial value. The final formula for calculating the actual oscillation frequency of the crystal oscillator IC40 under test is as follows: ,in This is the standard high-frequency clock frequency inside the system, i.e., the clock frequency of TIM2.

[0041] Step S4: The host computer obtains the actual oscillation frequency and the theoretical standard frequency, calculates the frequency correction parameters based on the temperature compensation algorithm, and sends a programming instruction to the microcontroller. The microcontroller switches the test channel to communication mode based on the programming instruction and programs the frequency correction parameters into the volatile register inside the crystal oscillator IC under test, so as to adjust the frequency of the crystal oscillator IC under test in real time.

[0042] In the process of calculating the frequency correction parameters, the host computer 10 needs to calculate the true frequency value of the crystal oscillator IC40 under test. The true frequency value is the actual oscillation frequency of the crystal oscillator IC40 under test. Then, based on the true frequency value, the theoretical standard frequency, and the temperature compensation algorithm, the frequency correction parameters are generated.

[0043] Specifically, a flowchart illustrating the process of calculating the true frequency value is shown below. Figure 3 As shown: Step S41: The host computer acquires the actual oscillation frequency of the crystal oscillator IC under test, the theoretical standard frequency of the crystal oscillator IC under test, the system crystal oscillator IC error of the microcontroller, and the fixed time deviation between the internal timer and the external timer of the microcontroller. The system crystal oscillator error of the microcontroller 20 itself is used for static correction of the hardware reference source deviation. Specifically, this can be achieved by obtaining the actual frequency of the external high-speed clock of the microcontroller 20. Its theoretical standard value The ratio is used to calculate the inherent system crystal IC error of the system. The calculation formula is as follows: The fixed time deviation K between the microcontroller's internal timer TIM2 and external timer TIM5 represents a fixed time error (sampling time difference) between the two channels TIM2 and TIM5. Taking 1 second "reading time" as a reference, the sampling time difference will result in a deviation of nearly 0.7 ppm. The shorter the time, the more the error will be magnified, and the longer the time, the smaller the error will be.

[0044] Step S42: Calculate the deviation amplification factor.

[0045] Among them, deviation amplification factor The formula for correcting time-dependent dynamic errors is as follows: ;in The duration of a single frequency sampling.

[0046] Step S43: Calculate the system dynamic error.

[0047] The specific calculation formula is as follows: ;in, For a fixed time deviation, optionally using a 1-second "reading time" as a reference, the acquisition time difference will result in a deviation of approximately 0.7 ppm, which is the system dynamic error. .

[0048] Step S44: Calculate the total deviation.

[0049] The total deviation is composed of the sum of the system dynamic error and the system crystal oscillator static error, and the specific calculation formula is as follows: ;in, This refers to the system crystal oscillator IC error of the microcontroller 20. Step S45: Calculate the true frequency value The final true frequency is obtained by adding the original frequency of the crystal oscillator IC40 actually read by the microcontroller 20 to the compensation amount calculated based on the total deviation. The specific calculation formula is as follows: ;in, The actual oscillation frequency of the crystal oscillator IC40 under test. The theoretical standard frequency of the crystal oscillator IC under test is given.

[0050] This application precisely isolates systematic errors from the original readings to obtain the true frequency value that reflects the real characteristics of the crystal oscillator. This provides a high-precision data foundation for subsequent calibration.

[0051] After step S45, the host computer 10 calculates the true frequency value. With theoretical standard frequency The absolute frequency deviation between the two values ​​is used to generate frequency correction parameters using a temperature compensation algorithm. Specifically, this system employs digital control linear frequency modulation technology, which involves writing data to specific registers of the IC. For each discrete value, the corresponding value can be obtained. The system calculates an output frequency. Furthermore, based on known "write value-frequency" data pairs, an approximation model is established using Newton's interpolation method. When a target frequency is needed, the interpolation algorithm is used to solve the problem in reverse, thus obtaining the accurate register write value.

[0052] This application proposes a dynamic amplification factor based on the reciprocal of the frequency measurement duration to map the system's fixed synchronization deviation to the current measurement window. Combined with the static error of the microcontroller 20's own system crystal oscillator IC, parasitic system errors are accurately eliminated, restoring the true frequency of the crystal oscillator IC 40 under test. Regarding parameter solving, based on known "write value-frequency" data pairs, an approximation model is established using Newton's interpolation method and solved in reverse, yielding accurate register write values. This algorithm achieves accurate frequency reading and compensation with low-cost hardware and a high-precision algorithm, demonstrating good engineering economics.

[0053] Step S5: After programming is completed, the microcontroller switches the test channel back to measurement mode. The host computer performs a second acquisition of the adjusted frequency of the crystal oscillator IC under test, and verifies whether the frequency deviation after compensation reaches the preset accuracy threshold. If it is qualified, the process ends and the frequency correction parameters are written into the non-volatile register inside the crystal oscillator IC under test, forming a fully automatic closed loop of "measurement-programming-verification".

[0054] If the compensated frequency deviation fails to reach the preset accuracy threshold, the host computer 10 records the residual deviation and returns to step S43 to enter the next round of closed-loop fine-tuning until the result converges; the preset accuracy threshold is ±1ppm; if the frequency tuning exceeds a certain number of times, the frequency tuning fails and the original value is written back.

[0055] In this design, the pins connecting the microcontroller 20 to the crystal oscillator IC 40 under test serve as test channels. Time-division multiplexing is achieved by switching the test channel modes: in measurement mode, the pins receive a standard digital square wave signal processed by the two-stage logic shaping circuit 30 and transmit it to the internal timer of the microcontroller 20; in communication mode, the pins send frequency correction parameters to the internal register of the crystal oscillator IC 40 under test according to the specific communication protocol of the crystal oscillator IC. Through the above design, this application achieves a perfect integration of high-speed frequency measurement and online calibration without increasing the number of probes, significantly improving calibration efficiency and reliability.

[0056] Meanwhile, this application adopts a "volatile first, then solidify" strategy. The frequency correction parameters are first written to the volatile register and then verified a second time. Only when the compensated frequency reaches a preset accuracy threshold (e.g., ±1ppm) are the parameters solidified to the non-volatile memory. If the verification fails, the system automatically records the residual deviation and returns to recalculate and reprogram, forming a closed-loop fine-tuning until the result converges. The "volatile first, then solidify" strategy effectively avoids the non-volatile register being unused due to the limited number of programming cycles, ensuring that the product can still be programmed with optimal parameters in the future, thus improving the reliability of testing and the maintainability of the product.

[0057] Specifically, this application achieves parameter programming and closed-loop verification through steps S4 and S5, and a detailed flowchart can be found as follows. Figure 4 As shown: Step S61: Sample frequency.

[0058] The frequency acquired in step S61 is the actual frequency of the crystal oscillator IC40 under test after system error compensation, acquired in step S45.

[0059] Step S62: Calculate the absolute frequency deviation value and generate frequency correction parameters.

[0060] Step S62 is the same as the operation performed by the host computer 10 after step S45, and will not be described again here.

[0061] Step S63: Switch to communication mode and burn parameters.

[0062] The microcontroller 20 switches the pins of the crystal oscillator IC 40 under test, which is in measurement mode, to communication mode, and writes the generated frequency correction parameters into the volatile register.

[0063] Step S64: Switch to measurement mode and measure the frequency a second time.

[0064] After the microcontroller 20 completes the data programming, it immediately switches the pins of the crystal oscillator IC 40 under test, which is in communication mode, to measurement mode to perform a second frequency measurement.

[0065] Step S65: Verify whether the frequency deviation after compensation reaches the preset accuracy threshold.

[0066] Step S66: Burn the data to a non-volatile register and solidify the data.

[0067] Step S67: Has the maximum number of steps for frequency modulation been exceeded?

[0068] The specific verification methods for steps S65-S67 are the same as those for step S5, and will not be repeated here.

[0069] This application's system architecture breaks through the traditional discrete process where "measurement" and "programming" are disconnected, constructing an integrated closed-loop system from precise frequency measurement and temperature compensation algorithm calculation to parameter programming and secondary verification. Through time-division multiplexing technology on the same physical pin, it receives shaped square wave signals in measurement mode and sends frequency correction parameters according to a specific protocol in communication mode, achieving high-speed frequency measurement and online calibration without increasing the number of probes. The entire process is automatically scheduled by the host computer, completing frequency measurement, parameter calculation, online programming, and accuracy verification with a single click, eliminating secondary deviations caused by manual data processing and significantly improving production efficiency and product consistency.

[0070] Optionally, the host computer 10 of this application can also display in real time the true frequency value of the crystal oscillator IC40 under test after frequency error compensation, as well as the distribution diagram of multiple measured frequency values. Specifically, it saves the frequency values ​​and internal register values ​​of different crystal oscillator IC40 under test in sequence and outputs a report document.

[0071] The system of this application is compatible with the specific communication timing and voltage requirements of multiple crystal oscillator IC products. The host computer 10 displays the real frequency value after frequency error compensation and the frequency distribution diagram of multiple measurements in real time, and automatically saves the frequency value, internal register value and pass rate of different products in sequence, and outputs a report document, providing complete data support for production quality control.

[0072] The above are merely embodiments of this application and do not limit the patent scope of this application. Any equivalent structural or procedural transformations made using the content of this application's specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the patent protection scope of this application.

Claims

1. A method for automatic testing and closed-loop compensation of crystal oscillator frequency based on a microcontroller, characterized in that, The method includes: S1. The host computer obtains the model parameters of the crystal oscillator IC under test and sends control commands to the microcontroller. The microcontroller dynamically adjusts the power supply module based on the control commands and outputs the working voltage and communication level that match the physical layer of the crystal oscillator IC under test. S2. The two-stage logic shaping circuit obtains the weak peak-clipping sine wave signal output by the crystal oscillator IC under test, and sequentially captures the zero-crossing point of the signal through a high-speed comparator and performs primary pulse flipping, and eliminates the glitches and noise at the moment of level transition through a Schmitt trigger, outputting a standard digital square wave signal with steep edges. S3. The microcontroller captures the standard digital square wave signal through an internal timer, calculates the current actual oscillation frequency using an equal-precision measurement method, and uploads the actual oscillation frequency to the host computer. S4. The host computer obtains the actual oscillation frequency and the theoretical standard frequency, calculates the frequency correction parameters based on the temperature compensation algorithm, and sends a programming instruction to the microcontroller. The microcontroller switches the test channel to communication mode based on the programming instruction and programs the frequency correction parameters into the volatile register inside the crystal oscillator IC under test to adjust the frequency of the crystal oscillator IC under test in real time. S5. After the programming is completed, the microcontroller switches the test channel back to the measurement mode. The host computer performs a second acquisition on the adjusted frequency of the crystal oscillator IC under test, verifies whether the compensated frequency deviation reaches the preset accuracy threshold. If it is qualified, the process ends, and the frequency correction parameter is written into the non-volatile register inside the crystal oscillator IC under test, forming a fully automatic closed loop of "measurement-programming-verification".

2. The method according to claim 1, characterized in that, The power supply module is a low-dropout linear regulator, and the specific steps of step S1 include: Based on the model parameters, the microcontroller adjusts the feedback resistor value of the low dropout linear stabilizer to adjust the operating voltage and communication level of the low dropout stabilizer output to the crystal oscillator IC under test.

3. The method according to claim 1, characterized in that, The specific steps of step S2 include: S21. The high-speed comparator captures the zero-crossing point of the signal in conjunction with a preset reference voltage and performs primary pulse flipping. The preset reference voltage is a reference bias voltage provided by a voltage follower constructed from an operational amplifier and input through a resistor divider network. S22. The Schmitt trigger utilizes its own double threshold hysteresis characteristic to shield high-frequency environmental noise, thereby eliminating glitches and noise at the moment of level transition, and achieves edge sharpening by compressing the rise and fall times of the signal, outputting a standard digital square wave signal with steep edges.

4. The method according to claim 1, characterized in that, The specific steps of step S3 include: S31. The host computer acquires the preset single frequency acquisition duration and the theoretical standard frequency of the crystal oscillator IC under test, and configures the internal timer of the microcontroller as an internal counter to record the number of standard clock pulses, and configures the external timer as an external counter to record the number of pulses of the signal under test. S32. Obtain the count value of the internal timer and the count value of the external timer during the duration of a single frequency acquisition, and calculate the actual oscillation frequency of the crystal oscillator IC under test based on the standard high-frequency clock frequency of the internal timer.

5. The method according to claim 4, characterized in that, The specific steps of step S4 include: S41, the host computer acquires the actual oscillation frequency of the crystal oscillator IC under test, the theoretical standard frequency of the crystal oscillator IC under test, the system crystal oscillator IC error of the microcontroller, and the fixed time deviation between the internal timer of the microcontroller and the external timer; S42. Calculate the deviation amplification factor: ;in The duration of a single frequency sampling; S43. Calculate the system dynamic error: ;in, For fixed time deviation; S44. Calculate the total deviation: ;in, The error is the system crystal IC error of the microcontroller; S45. Calculate the true value of the frequency: ;in, The actual oscillation frequency of the crystal oscillator IC under test. The theoretical standard frequency of the crystal oscillator IC under test; S46, The host computer calculates the true value of the frequency. With the theoretical standard frequency The absolute frequency deviation between the two values ​​is used to generate the frequency correction parameters by running a temperature compensation algorithm.

6. The method according to claim 5, characterized in that, Step S5 also includes: If the compensated frequency deviation fails to reach the preset accuracy threshold, the host computer records the residual deviation and returns to step S4 to enter the next round of closed-loop fine-tuning until the result converges; wherein, the preset accuracy threshold is ±1ppm; If the frequency is adjusted more than a certain number of times, the adjustment will fail and the original value will be written back.

7. The method according to claim 5, characterized in that, The method further includes: The host computer displays in real time the true frequency value of the crystal oscillator IC under test after frequency error compensation, as well as a distribution graph of multiple measured frequency values.

8. A microcontroller-based automatic frequency testing and closed-loop compensation system for crystal oscillator ICs, characterized in that, include: The host computer is used to receive the model parameters and theoretical standard frequency of the crystal oscillator IC under test from the user. The microcontroller transmits data with the host computer via a serial communication protocol, receives control commands from the host computer, and performs parameter measurement, programming, and verification of the crystal oscillator IC under test based on the control commands. A power supply module is used to provide dynamically adjustable operating voltage and communication level, and the microcontroller dynamically adjusts the power supply module based on control commands; A two-stage logic shaping circuit is used to convert the peak-clipping sine wave output by the crystal oscillator IC under test into a standard digital square wave that meets the input conditions of the microcontroller. The two-stage logic shaping circuit includes a high-speed comparator and a Schmitt trigger. The high-speed comparator is used to capture the zero-crossing point of the signal and perform primary pulse flipping. The Schmitt trigger is used to eliminate glitches and noise at the moment of level transition.

9. The system according to claim 8, characterized in that, The microcontroller uses its internal high-frequency timer and extremely high clock frequency to record nanosecond-level timestamps. The pins connecting the microcontroller to the crystal oscillator IC under test serve as test channels. Time-division multiplexing is achieved by switching the modes of the test channels: in measurement mode, the pins receive standard digital square wave signals processed by the two-level logic shaping circuit and transmit them to the internal timer of the microcontroller; in communication mode, the pins send frequency correction parameters to the internal register of the crystal oscillator IC under test according to the specific communication protocol of the crystal oscillator IC.

10. The system according to claim 8, characterized in that, The host computer is also used to sequentially save the frequency values ​​and internal register values ​​of different crystal oscillator ICs under test, and output report documents.