Resistance value measuring method with automatic calibration function
The automatic calibration resistance measurement method based on the principle of capacitor charging and discharging solves the problems of complex resistance measurement circuits, high costs, and high resource consumption, achieving low cost, simplified circuits, improved measurement accuracy, and increased production efficiency.
Patent Information
- Application Number
- CN202511263236.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-05
- Publication Date
- 2025-10-31
AI Technical Summary
Existing resistance measurement methods are complex, costly, require high hardware resources, have low production efficiency, and are easily affected by the environment. In particular, they lack measurement accuracy in low-cost and resource-constrained embedded systems.
An automatic calibration resistance measurement method based on the principle of capacitor charging and discharging is adopted. The calibration resistor is controlled by a microcontroller to be connected in parallel with the resistor being measured. The resistance value is calculated by utilizing the difference in capacitor charging and discharging time, which simplifies the circuit structure and reduces the dependence on microcontroller resources.
It achieves low cost, simplified circuitry, reduced hardware resource requirements, improved measurement accuracy, adaptability to different environments, and eliminates the need for manual calibration, thereby improving production efficiency.
Smart Images

Figure CN120870675A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of electronic measurement technology, specifically relating to a resistance measurement method with automatic calibration function based on the principle of capacitor charging and discharging. It is suitable for low-cost, convenient and simplified measurement scenarios of resistance values of resistive elements, and is especially suitable for applications such as embedded systems and portable measuring devices that are sensitive to circuit complexity and cost and have good environmental adaptability. Background Technology
[0002] 1. In the field of electronic measurement, resistance measurement is a fundamental and commonly used technique. Traditional resistance measurement methods mainly include the following: Wheatstone bridge method: Measurement is achieved by adjusting the balance of the bridge arms. It has high accuracy, but requires precise adjustable resistors and complex balance adjustment mechanisms. The circuit structure is complex and not suitable for low-cost integration scenarios.
[0003] Constant current source method: A constant current is flowed through the resistor under test, and the voltage across the resistor (U=IR) is measured to calculate the resistance value. This method requires a high-precision constant current source circuit, and the stability of the constant current source directly affects the measurement accuracy, resulting in a relatively high circuit cost.
[0004] Direct ADC sampling: This method uses the microcontroller's ADC pins to sample the voltage across a resistor (in conjunction with a voltage divider circuit) and calculates the resistance value. This method relies on the microcontroller's ADC resources, which limits the circuit's applicability. Furthermore, some low-cost microcontrollers have a limited number of ADC pins, which may conflict with normal ADC requirements. 2. In the field of industrial control, some terminal devices need to be flexibly configured with communication addresses according to the application environment. Common methods are as follows: Changing configuration parameters via software requires additional debugging tools (such as computers, mobile phones, etc.) to communicate with the terminal device.
[0005] Encoding via DIP switches requires the use of multiple GPIO resources on the microcontroller, which can easily lead to a shortage of microcontroller resources.
[0006] By selecting resistors, the ADC direct sampling method can be used—similar to the ADC direct sampling method in the field of electronic measurement.
[0007] To address the aforementioned issues, existing technologies include configuration methods that utilize resistance measurement. However, these methods typically rely on manual pre-calibration during the production phase. This calibration method not only increases the complexity of the production process but also leads to a decrease in measurement accuracy in practical applications due to differences between the field environment (especially temperature conditions) and the production environment. Summary of the Invention
[0008] To address the problems of complex circuits, high costs, high hardware resource requirements, low production efficiency, and susceptibility to environmental influences in existing technologies, this invention proposes a resistance measurement scheme with automatic calibration function based on the charging and discharging characteristics of capacitors. This simplifies the circuit, reduces costs, decreases dependence on hardware resources, and improves production efficiency and measurement accuracy.
[0009] The technical solution adopted in this invention is as follows: A method for measuring resistance with automatic calibration function, including a measurement circuit and measurement steps; The measurement circuit includes at least a microcontroller, a capacitor, a selectively accessible calibration resistor, a measurement port for connecting the resistor under test, and a constant measurement voltage Vn for providing the measurement port. The microcontroller has GPIO functionality, voltage change detection functionality (for triggering interrupt IRQ1), and timing functionality. The measurement voltage does not exceed the voltage tolerance range of the microcontroller. The resistor under test and the capacitor form an RC charging and discharging parallel circuit or an RC charging and discharging series circuit. The capacitor, the resistor under test, and the calibration resistor have an intersection point, which is the capacitor charging / discharging terminal and has a direct or indirect connection to the microcontroller (such as being connected to the microcontroller's GPIO pin or voltage comparator input pin), used to trigger the corresponding interrupt IRQ1 of the microcontroller's voltage change detection function.
[0010] The measurement steps include: (1) Control the calibration resistor to be connected in parallel with the resistor being measured; (2) The capacitor is pre-discharged / pre-charged to the initial voltage Vs (high level or low level) by the microcontroller. "Pre-discharge / pre-charge the capacitor to the initial voltage Vs" specifically means: setting the pin with level control function of the microcontroller to output mode, and controlling the capacitor to pre-charge to close to the microcontroller supply voltage VDD or pre-discharge to close to the ground potential 0V; (3) Switch to charging / discharging mode to start capacitor charging / discharging; at the same time start the timing function, enable the voltage change detection function and preset the threshold voltage Vt in case of triggering interrupt; Among them, the microcontroller's interrupt IRQ1 is an external interrupt or a voltage comparator output interrupt; when interrupt IRQ1 is an external interrupt, the triggering mode is edge triggering (rising edge or falling edge) or level triggering (high level or low level), and it matches the voltage change direction of capacitor charging and discharging; The "timing function" of a microcontroller is implemented through hardware timers, software timing modules, or timer groups to adapt to different hardware and meet the measurement accuracy requirements in different scenarios. The threshold voltage Vt should be in the direction of change of the capacitor charging / discharging terminal voltage. It can be finely adjusted by the microcontroller register configuration or software parameters to adapt to different circuit forms such as RC charging / discharging parallel circuit and RC charging / discharging series circuit, as well as capacitors of different values and resistors under test of different ranges, to ensure the stability of interrupt IRQ1 triggering.
[0011] "Switching to charge / discharge mode" specifically means: setting the pins of the microcontroller with level control function to input mode, cutting off the pre-discharge / pre-charge circuit, and simultaneously driving the capacitor to charge / discharge from the initial voltage Vs to the reverse logic level direction through the measurement voltage Vn connected to the measurement port; (4) When the capacitor is charged or discharged to the preset threshold voltage Vt, the microcontroller interrupt IRQ1 is triggered, and the timing stops at this time; (5) Record the duration of the measurement as the time taken for the first measurement; (6) Control the calibration resistor to exit the measurement circuit, repeat steps (2) to (4), and record the timing duration at this time as the time for the second measurement; (7) Calculate the resistance value of the resistor being measured based on the difference in the time taken for the two measurements and the known resistance value of the calibration resistor; The resistance value of the resistor being measured is calculated using the formula Rx=(T1 / (T2-T1))・R1, where T1 is the measurement time for the first measurement, T2 is the measurement time for the second measurement, and R1 is the known resistance value of the calibration resistor. Furthermore, when the temperature drift characteristics of the calibration resistor R1 and the resistor being measured Rx are consistent, the influence of ambient temperature on the measurement results will be reduced.
[0012] To improve measurement accuracy, the resistance Rx under test can be measured repeatedly and the average value can be calculated. Beneficial effects of the present invention
[0013] Circuit simplification: No operational amplifiers or constant current sources are needed, only one capacitor is required, reducing complexity; Resource saving: It does not occupy the microcontroller's ADC pins, and only requires a minimum of 2 GPIOs, one of which has an external interrupt function, reducing the dependence on microcontroller hardware resources; Low cost: Fewer components, easy to integrate into various devices; Easy to use: No manual calibration is required, saving production time. When the temperature drift characteristics of the calibration resistor and the resistor being measured are consistent, it can also play a role in resisting temperature drift. The measurement method is flexible: by setting different measurement voltages and corresponding operating procedures, it can adapt to different measurement scenarios and has good practicality. Attached Figure Description
[0014] Figure 1The circuit diagram is shown for the resistance measurement method with automatic calibration function of the present invention. Figure 2 This is a circuit schematic diagram of Embodiment A of the resistance measurement method with automatic calibration function of the present invention; Figure 3 This is a circuit diagram of embodiment B of the resistance measurement method with automatic calibration function of the present invention. Detailed Implementation
[0015] like Figure 1 The resistance measurement circuit shown includes a microcontroller U1, a capacitor C1, a resistor R1, measurement port 1, and measurement port 2. Pin 2 of the microcontroller U1 is connected to measurement port 1, pin 9 is grounded, and pin 10 is connected to the power supply VDD. The capacitor C1 is connected in parallel between measurement port 1 and ground. The resistor R1 is connected between pins 2 and 6 of U1. Measurement port 2 is connected to the measurement voltage Vn. During actual measurement, the resistor to be measured, Rx, is connected between measurement port 1 and measurement port 2. The microcontroller U1 should control the connection method of R1, which should be in parallel with Rx.
[0016] The microcontroller U1 is an STM32L011D4P6; Pin 2 of the microcontroller U1 serves as both a control capacitor pre-charge / discharge function and a voltage change detection function.
[0017] The measured voltage Vn should meet the following conditions: 1. Constant pressure; 2. The voltage should not exceed the voltage tolerance range of pin 2 of the microcontroller U1; 3. Its size should be sufficient to trigger an external interrupt of the microcontroller U1 required for the measurement; The following two examples, based on the specific quantization value of Vn, will be explained in detail. Both examples will have the following settings: 1) The allowable range of the measured resistance Rx is 1kΩ~100kΩ; 2) C1=100nF, Rx=20kΩ, Ifmax=Icmax=4mA, VDD=3.3V, R1=10kΩ; Ifmax is the maximum allowable discharge current of the circuit, and Icmax is the maximum allowable charging current of the circuit. The specific implementation method is as follows: Example A
[0018] In this example, the measured voltage Vn = VDD. The equivalent schematic diagram for the actual measurement is as follows: Figure 2 As shown.
[0019] from Figure 2It can be seen that capacitor C1, the measured resistor Rx, and the calibration resistor R1 have an intersection point. This intersection point is connected to pin 2 of microcontroller U1, and the measured resistor Rx and capacitor C1 are in series. When microcontroller U1 discharges capacitor C1, the circuit is still charging capacitor C1 through the measured resistor Rx and the calibration resistor R1. Only when the discharge current is greater than the charging current can C1 be guaranteed to discharge normally. Therefore, the resistance value of the measured resistor Rx is limited by the maximum allowable discharge current Ifmax of the circuit, and its value should be greater than VDD / (Ifmax-VDD / R1). Since the circuit discharges and charges simultaneously during pre-discharge, the actual discharge current If is between Ifmax-VDD / Rxmin-VDD / R1 and Ifmax. Therefore, the delay value Ty should not be less than VDD·C1 / (Ifmax-VDD / Rxmin-VDD / R1), where Rxmin is the minimum allowable measured resistance value. The measurement steps are implemented by writing a program for the microcontroller and configuring the timer accuracy to 1µs. The specific steps are as follows: (1) When the calibration pin Pj outputs a high level, it controls the calibration resistor R1 to be connected to the measurement circuit and to be connected in parallel with the resistor being measured. (2) Set the measurement pin Pc to push-pull output mode and output a low level, delaying Ty to ensure that capacitor C1 is pre-discharged to the initial voltage Vs≈0V; Ty>892μs (calculated according to the formula: 3.3V×100nF / (4mA−3.3V / Rxmin-3.3V / 10kΩ), when Rxmin=1kΩ, Ty≈892μs); (3) Switch the measurement pin Pc to input mode, enable external interrupt and configure it as rising edge interrupt (at this time Vt=0.7VDD), start the timer, and VDD charges C1 through Rx and R1; (4) When C1 is charged to 0.7VDD, the external interrupt IRQ1 is triggered, and the timing stops at this time; (5) Record the timing duration to obtain the first measurement time T1; (6) Switch the calibration pin Pj of microcontroller U1 to input mode to control the calibration resistor to exit the measurement circuit. Repeat steps (2) to (4), record the timing duration, and obtain the second measurement time T2. (7) Calculate Rx=(T1 / (T2-T1))·R1. If T1=800 and T2=1200, then Rx=2·10kΩ=20kΩ; The resistance value Rx can then be measured correctly. Example B
[0020] In this example, the measured voltage Vn is grounded. The equivalent schematic diagram of the actual measurement is as follows: Figure 3 As shown.
[0021] from Figure 3 It can be seen that capacitor C1, the measured resistor Rx, and the calibration resistor R1 have an intersection point. This intersection point is connected to pin 2 of microcontroller U1, and the measured resistor Rx and capacitor C1 are connected in parallel. When microcontroller U1 charges capacitor C1, the circuit is still discharging capacitor C1 through the measured resistor Rx and the calibration resistor R1. Only when the charging current is greater than the discharging current can C1 be charged normally. Therefore, the resistance value of the measured resistor Rx is limited by the maximum allowable charging current Icmax of the circuit, and its value should be greater than VDD / (Icmax-VDD / R1). Since the circuit discharges and charges simultaneously during pre-charging, the actual charging current Ic is between Icmax-VDD / Rxmin-VDD / R1 and Icmax. Therefore, the delay value Ty should not be less than VDD·C1 / (Icmax-VDD / Rxmin-VDD / R1), where Rxmin is the minimum allowable measured resistance value. The measurement steps are implemented by writing a program for the microcontroller and configuring the timer accuracy to 1µs. The specific steps are as follows: (1) When the calibration pin Pj outputs a low level, it controls the calibration resistor R1 to be connected to the measurement circuit and to be connected in parallel with the resistor being measured. (2) Set the measurement pin Pc to push-pull output mode and output a high level, delaying Ty to ensure that capacitor C1 is pre-charged to the initial voltage Vs≈VDD, Ty>892μs (calculated according to the formula: 3.3V×100nF / (4mA−3.3V / Rxmin-3.3V / 10kΩ), when Rxmin=1kΩ, Ty≈892μs). (3) Switch the measurement pin Pc to input mode, enable external interrupt and configure it as falling edge interrupt (at this time Vt=0.3VDD), start the timer, and C1 will be discharged through Rx and R1; (4) When C1 discharges to 0.3VDD, the external interrupt IRQ1 is triggered, and the timing stops. (5) Record the timing duration to obtain the first measurement time T1; (6) Switch the calibration pin Pj of microcontroller U1 to input mode to control the calibration resistor to exit the measurement circuit. Repeat steps (2) to (4), record the timing duration, and obtain the second measurement time T2. (7) Calculate Rx=(T1 / (T2-T1))·R1. If T1=800 and T2=1200, then Rx=2·10kΩ=20kΩ; Working principle of the invention
[0022] In an RC charging and discharging circuit, when other hardware components are fixed, the charging and discharging time t of the capacitor is linearly related to the resistance R. Therefore, the resistance can be measured by measuring the charging and discharging time. However, due to manufacturing processes, the electrical characteristics of the electronic components in each set of hardware will have deviations. Therefore, to improve measurement accuracy, each set of hardware needs to be calibrated. Considering that the resistor Rx being measured may be inconvenient to install and remove, this invention uses a microcontroller to dynamically connect a known resistor R1 to the RC charging and discharging circuit, so that R1 is connected in parallel with the resistor being measured during use. The charging times T1 and T2 under R1 / / Rx and Rx are measured respectively, and the values are substituted into the formula Rx=k·T. X The value of the measured resistance Rx can be obtained by solving the two linear equations in two variables.
Claims
1. A method for measuring resistance with automatic calibration function, characterized in that, Includes measurement circuitry and measurement procedures; The measurement circuit includes at least a microcontroller, a capacitor, a selectively accessible calibration resistor, a measurement port for connecting the resistor under test, and a measurement voltage Vn that provides a constant voltage to the measurement port; the microcontroller has GPIO function, voltage change detection function (for triggering interrupt IRQ1) and timing function, and the measurement voltage does not exceed the voltage tolerance range of the microcontroller. The resistor and capacitor under test form an RC charging and discharging parallel circuit or an RC charging and discharging series circuit. The measurement steps include: (1) Control the calibration resistor to be connected in parallel with the resistor being measured; (2) The capacitor is pre-discharged / pre-charged to the initial voltage Vs (high level or low level) by the microcontroller. (3) Switch to charging / discharging mode to start capacitor charging / discharging; at the same time start the timing function, enable the voltage change detection function and preset the threshold voltage Vt in preparation for triggering interrupt IRQ1; (4) When the capacitor is charged or discharged to the preset threshold voltage Vt, the microcontroller interrupt IRQ1 is triggered, and the timing stops at this time; (5) Record the duration of the measurement as the time taken for the first measurement; (6) Control the calibration resistor to exit the measurement circuit, repeat steps (2) to (4), and record the timing duration at this time as the time for the second measurement; (7) Calculate the resistance value of the resistor being measured based on the difference in the time taken for the two measurements and the known resistance value of the calibration resistor.
2. The resistance measurement method with automatic calibration function according to claim 1, characterized in that, The resistance value of the resistor to be measured in step (7) is calculated by the formula Rx=(T1 / (T2-T1))・R1, where T1 is the time for the first measurement, T2 is the time for the second measurement, and R1 is the known resistance value of the calibration resistor.
3. The resistance measurement method with automatic calibration function according to claim 1, characterized in that, The capacitor, the resistor under test, and the calibration resistor have an intersection point, which is the capacitor charging / discharging terminal and has a direct or indirect connection to the microcontroller (such as being connected to the microcontroller's GPIO pin or voltage comparator input pin), used to trigger the corresponding interrupt IRQ1 of the microcontroller's detection function; the threshold voltage Vt should be in the direction of change of the capacitor charging / discharging terminal voltage.
4. A resistance measurement method with automatic calibration function according to claim 1, characterized in that, In step (2), "pre-discharge / pre-charge the capacitor to the initial voltage Vs" specifically means: setting the pin with level control function of the microcontroller to push-pull output mode, outputting a high level to pre-charge the capacitor to near the microcontroller supply voltage VDD, or outputting a low level to pre-discharge the capacitor to near the ground potential 0V; "switch to charge / discharge mode" specifically means: setting the pin with level control function of the microcontroller to input mode, cutting off the pre-discharge / pre-charge circuit, and simultaneously driving the capacitor to charge / discharge from the initial voltage Vs to the reverse logic level direction through the measurement voltage Vn connected to the measurement port.
5. A resistance measurement method with automatic calibration function according to claim 1, characterized in that, The microcontroller's interrupt IRQ1 is either an external interrupt or a voltage comparator output interrupt. When interrupt IRQ1 is an external interrupt, the triggering method is edge-triggered (rising edge or falling edge) or level-triggered (high level or low level), and it matches the direction of voltage change during capacitor charging and discharging.
6. A resistance measurement method with automatic calibration function according to claim 1, characterized in that, The "timing function" of a microcontroller is implemented through hardware timers, software timing modules, or timer groups to meet the measurement accuracy requirements in different scenarios.
7. A resistance measurement method with automatic calibration function according to claim 3, characterized in that, The threshold voltage Vt can be configured through the microcontroller's registers or finely adjusted through software parameters to adapt to different circuit configurations such as parallel RC charging and discharging circuits and series RC charging and discharging circuits, as well as capacitors of different capacitance values and resistors under test of different ranges, ensuring the stability of interrupt IRQ1 triggering.