Method for self-calibration of errors of built-in adc of mcu
By using a bandgap reference voltage for self-calibration in the MCU's built-in ADC and calculating the calibration coefficient K, the problem of ADC gain error is solved, achieving high-precision, low-cost online calibration, which is suitable for various MCUs and SoC chips.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- CHENGDU HUANYUXIN TECH
- Filing Date
- 2026-02-06
- Publication Date
- 2026-06-16
AI Technical Summary
Existing technologies cannot provide low-cost, easy-to-implement, and online calibration and compensation for ADC gain errors introduced by power supply voltage fluctuations, resulting in insufficient ADC measurement accuracy.
By connecting the VDD power supply to the ADC reference voltage terminal, sampling is performed using the MCU's built-in bandgap reference voltage, the calibration coefficient K is calculated, and stored in non-volatile memory to achieve real-time compensation for gain error.
Significantly improves ADC measurement accuracy to within ±1%, reduces cost and complexity, supports online adaptive calibration, and is suitable for a wide range of MCU and SoC chip scenarios.
Smart Images

Figure CN122226035A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to electronic technology, specifically to the field of microcontroller (MCU) and analog integrated circuit technology. Background Technology
[0002] In modern electronic systems, the ADC built into the MCU is the core module for realizing the digitization of analog signals. Its measurement accuracy directly determines the accuracy of data acquisition and control, and has a wide impact on various application scenarios that rely on precise signal conversion, such as industrial control, intelligent sensing, and medical electronics.
[0003] The full-scale reference voltage (VREF) of an ADC is typically taken directly or indirectly from the MCU's supply voltage (such as VDD), which is provided by power supply circuits such as DC-DC converters (DCDC) and low-dropout linear regulators (LDOs). Due to the inherent accuracy limitations of power supply devices, the output voltage of these power supply circuits often has a deviation of ±5% or more. This deviation directly causes a proportional change in the ADC's full-scale range, thereby introducing a systematic gain error. This results in a proportional measurement deviation at all sampling points, severely affecting the ADC's measurement accuracy.
[0004] To improve ADC accuracy, various calibration schemes exist in existing technologies. One common method is the "two-point calibration method," which involves inputting two known, precise voltages to the ADC, measuring the corresponding output code values, and fitting the actual conversion function (y = mx + b) to compensate for offset error (b) and gain error (m). However, this method requires a high-precision calibration signal from an external source during mass production, significantly increasing testing costs and production complexity. Another approach is to use an ADC with internal self-calibration capabilities. However, such ADCs typically only calibrate the offset and gain errors of their core, failing to specifically compensate for errors caused by power supply voltage fluctuations. Furthermore, they require specific hardware architecture support, limiting their applicability and increasing hardware costs.
[0005] In summary, existing technologies cannot simultaneously meet the requirements of "low cost, easy implementation, online calibration, and effective compensation for ADC gain errors introduced by power supply fluctuations." Therefore, there is an urgent need for a MCU self-calibration ADC error method that balances accuracy improvement and cost control. Summary of the Invention
[0006] The technical problem to be solved by the present invention is to overcome the shortcomings of existing ADC calibration schemes, such as high cost, high complexity, and inability to effectively compensate for gain errors introduced by power supply voltage fluctuations, and to provide a self-calibration method based on existing resources inside the MCU, so as to achieve low-cost, high-precision, and online adaptive ADC gain error calibration.
[0007] The technical solution adopted by the present invention to solve the aforementioned technical problem is a self-calibration method for ADC error built into an MCU, characterized by comprising the following steps:
[0008] (a) Connect the VDD power supply to the reference voltage terminal of the ADC;
[0009] (b) The input channel of the ADC is connected to the on-chip bandgap reference voltage. The ADC samples the bandgap reference voltage to obtain the reference measurement code value D.
[0010] (b) Calculate the actual voltage VDD_actual using equation (1):
[0011] VDD_actual = V0×R / D (1)
[0012] Where V0 is the on-chip bandgap reference voltage; R is the full scale of the ADC, that is, the maximum value of the ADC output code;
[0013] (d) Calculate and store the calibration coefficient K using equation (2):
[0014] K = VDD_actual / VDD_nominal (2)
[0015] VDD_nominal is the nominal supply voltage;
[0016] (e) The ADC input channel is connected to the target analog signal (e.g., an externally input analog signal) for sampling to obtain the raw code value D_raw, and then D_corrected is calculated using equation (3):
[0017] D_corrected = D_raw × K (3)
[0018] D_corrected is the accurate code value of the calibrated external input analog signal.
[0019] Furthermore, in step (b), the ADC samples the bandgap reference voltage a predetermined number of times, calculates the average value, and obtains the reference measurement code value D.
[0020] It also includes step (f): after waiting for a predetermined period of time, return to step (a).
[0021] Further, step (f) is: monitoring the fluctuation of VDD. If the fluctuation amplitude exceeds the preset value, or if the fluctuation amplitude does not exceed the preset value but the waiting time reaches the predetermined duration, then return to step (a).
[0022] Compared with the prior art, the present invention has the following significant advantages:
[0023] 1. Significantly improved measurement accuracy: It can specifically eliminate the systematic ADC gain error introduced by power supply voltage fluctuations, and improve the absolute measurement accuracy of the ADC from relying on the accuracy of external power supply (±5% and above) to a level close to the internal high-precision bandgap reference (typically within ±1%), greatly optimizing the accuracy of data acquisition;
[0024] 2. Significantly reduced cost and complexity: No additional configuration of external high-precision calibration voltage source or dedicated calibration hardware circuit is required. Calibration is achieved solely through software algorithms relying on the existing internal resources of the MCU (bandgap reference, ADC, CPU, non-volatile memory), significantly reducing mass production testing costs and hardware design costs.
[0025] 3. Supports online adaptive calibration: The calibration process can be automatically initiated and executed by the MCU software. A periodic calibration mechanism can be set according to actual needs, or calibration can be triggered when power fluctuations are detected. It can track and compensate for power characteristic drift caused by factors such as temperature changes and device aging in real time, ensuring long-term measurement accuracy stability.
[0026] 4. High versatility: The calibration principle of this invention does not depend on a specific ADC architecture or MCU model. As long as the chip integrates a built-in high-precision reference voltage source and ADC, it is applicable and can be widely promoted and applied to various MCU and SoC chip ADC accuracy optimization scenarios. Attached Figure Description
[0027] Figure 1 This is a hardware architecture diagram of the MCU self-calibration ADC error method of the present invention;
[0028] Figure 2 This is a schematic diagram comparing the ADC conversion characteristics before and after calibration; Detailed Implementation Plan
[0029] See Figure 1 and Figure 2 , Figure 1 The core hardware components of the method of this invention are shown, including a power supply (Vsupply), an internal high-precision reference voltage source (REF=1.25V), a 12-bit ADC, a calibration algorithm module, and an MCU core unit. The signal connection relationship of each module and the hardware support logic of the calibration process are clearly presented.
[0030] This invention is achieved through two core stages: "calibration mode" and "execution mode," with the specific steps as follows:
[0031] Phase 1: Entering Calibration Mode
[0032] The trigger conditions for calibration mode can be flexibly set, including but not limited to: automatic triggering when the MCU is initially powered on, timed triggering according to a preset period, triggering when the power supply voltage fluctuation exceeds a threshold, and triggering by external commands. After triggering, the MCU pauses normal measurement tasks and enters the calibration process.
[0033] Phase Two: Internal Reference Voltage Measurement
[0034] By using an internal analog switch in the MCU, the input channel of the ADC is switched to the internal high-precision bandgap reference voltage source (nominal voltage Vref_int, such as 1.25V); the ADC is controlled to sample the internal reference voltage multiple times, and the multiple raw code values obtained by sampling are denoised (such as taking the average value) to finally obtain a stable reference measurement code value D_ref.
[0035] Phase 3: Calibration Coefficient Calculation
[0036] Based on the ADC conversion principle, and combining known parameters and the measured D_ref, the gain calibration coefficient K is calculated in two steps:
[0037] (1) Calculate the actual supply voltage (VDD_actual):
[0038] According to the ADC conversion formula, the relationship between the internal reference voltage Vref_int, the supply voltage (which is used as the ADC reference voltage VREF), and the reference measurement code value D_ref satisfies:
[0039]
[0040] Where N is the resolution of the ADC (e.g., 12-bit, 16-bit, etc.).
[0041] The formula for calculating the actual value of the supply voltage can be obtained by deformation:
[0042]
[0043] (2) Calculate the gain calibration coefficient K:
[0044] Let the ideal supply voltage (nominal supply voltage) of the MCU be VDD_nominal (e.g., 5.0V), and the gain calibration coefficient K be the ratio of the actual supply voltage to the ideal supply voltage, that is:
[0045]
[0046] This coefficient directly characterizes the degree of deviation between the actual gain and the ideal gain of the ADC, providing a core basis for subsequent error compensation.
[0047] Phase Four: Calibration Coefficient Storage and Execution Mode Application
[0048] The calculated gain calibration coefficient K is stored in the MCU's non-volatile memory (such as Flash) to ensure that it is not lost after power failure; after the calibration process is completed, the MCU exits the calibration mode and enters the normal execution mode (measurement mode).
[0049] In execution mode, the MCU performs ADC sampling on the external input analog signal Vin to obtain the raw sampled code value D_raw; it then calls the stored calibration coefficient K using the formula:
[0050]
[0051] The calibrated accurate code value is calculated to achieve real-time compensation for gain error.
[0052] Example:
[0053] The following detailed implementation process of the present invention is illustrated with specific embodiments (using a 12-bit ADC, a 1.25V internal bandgap reference, and a 5.0V nominal supply voltage MCU as an example):
[0054] Implementation prerequisites: The MCU chip must integrate a 12-bit ADC, a 1.25V high-precision bandgap reference voltage source, an internal analog switch, and Flash memory, and the reference voltage terminal of the ADC must be connected to the actual power supply voltage VDD.
[0055] (a) Calibration mode implementation steps:
[0056] 1. Trigger calibration: After the MCU powers on and completes initialization, it automatically triggers calibration mode;
[0057] 2. Channel switching and sampling: The ADC input channel is switched to the 1.25V internal bandgap reference by configuring the internal analog switch through software; the ADC is controlled to sample the reference voltage 20 times at a preset sampling rate to obtain 20 raw code values D1~D20;
[0058] 3. Denoising: Calculate the average value of D1~D20 to obtain the reference measurement code value D_ref = (D1+D2+...+D20) / 20, thus eliminating the influence of random noise;
[0059] 4. Calculate VDD_actual: Given that the full-scale code value of the 12-bit ADC (corresponding to the ADC's reference voltage) is 2^12 - 1 = 4095, and the internal reference nominal value Vref_int = 1.25V, substitute into the formula:
[0060]
[0061] The actual value of the current supply voltage is calculated;
[0062] 5. Calculate the calibration coefficient K: Given the nominal supply voltage VDD_nominal = 5.0V, substitute into the formula:
[0063]
[0064] The calibration coefficient K is obtained (for example, if VDD_actual = 4.8V, then K = 4.8 / 5.0 = 0.96).
[0065] 6. Coefficient storage: Write the calibration coefficient K to the specified address in the MCU's Flash memory to complete the calibration process and exit calibration mode.
[0066] (II) Implementation steps of the execution mode:
[0067] 1. Normal sampling: The MCU performs ADC sampling on the external input analog signal Vin (such as the sensor output voltage) to obtain the raw code value D_raw;
[0068] 2. Error compensation: Read the calibration coefficient K from Flash and calculate the calibrated accurate code value using the formula D_corrected = D_raw × K;
[0069] 3. Data application: The calibrated D_corrected is used in subsequent data processing, control decision-making and other processes to achieve high-precision signal acquisition.
[0070] This invention allows for the use of a software-set timer to trigger a calibration mode every hour, recalculating and updating the calibration coefficient K. Simultaneously, a power supply voltage monitoring module is configured to immediately trigger calibration when VDD fluctuations exceed ±1%, ensuring that ADC measurement accuracy is maintained even under conditions of environmental temperature changes and device aging. See also... Figure 2 The horizontal axis represents the input analog voltage, and the vertical axis represents the ADC output digital code value; the curve For ideal conversion characteristics, the curve The actual conversion characteristics after gain shift caused by power supply voltage deviation are shown, intuitively demonstrating the gain error state before calibration and the effect of restoring to ideal conversion characteristics after calibration using the method of the present invention.
Claims
1. A self-calibration method for ADC error built into an MCU, characterized in that, Includes the following steps: (a) Connect the VDD power supply to the reference voltage terminal of the ADC; (b) The input channel of the ADC is connected to the on-chip bandgap reference voltage. The ADC samples the bandgap reference voltage to obtain the reference measurement code value D. (c) Calculate the actual voltage VDD_actual using equation (1): VDD_actual = V0×R / D (1) Where V0 is the on-chip bandgap reference voltage and R is the full scale of the ADC; (d) Calculate and store the calibration coefficient K using equation (2): K = VDD_actual / VDD_nominal (2) VDD_nominal is the nominal supply voltage; (e) The ADC input channel is connected to the target analog signal for sampling to obtain the raw code value D_raw, and then D_corrected is calculated by equation (3): D_corrected = D_raw × K (3) D_corrected represents the accurate code value of the calibrated target analog signal.
2. The MCU built-in ADC error self-calibration method as described in claim 1, characterized in that, In step (b), the ADC samples the bandgap reference voltage a predetermined number of times, calculates the average value, and obtains the reference measurement code value D.
3. The MCU built-in ADC error self-calibration method as described in claim 1, characterized in that, It also includes step (f): after waiting for a predetermined period of time, return to step (a).
4. The MCU built-in ADC error self-calibration method as described in claim 1, characterized in that, It also includes step (f): monitoring the fluctuation of VDD. If the fluctuation exceeds the preset value, or if the fluctuation does not exceed the preset value but the waiting time reaches the predetermined duration, then return to step (a).