Resistance value measuring method

By adopting a resistance measurement method based on the charge and discharge characteristics of capacitors and utilizing the GPIO and timer functions of the microcontroller, the circuit structure is simplified, the problems of complex circuits and high costs in resistance measurement are solved, and low-cost, resource-saving and high-precision resistance measurement is achieved.

CN120610065APending Publication Date: 2025-09-09赵明
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511103295.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-08-07
Publication Date
2025-09-09

AI Technical Summary

Technical Problem

Existing resistance measurement methods have complex circuits, high costs, and high hardware resource requirements, making them difficult to effectively apply in low-cost and resource-constrained embedded systems.

Method used

A resistance measurement method based on the charge and discharge characteristics of the capacitor is adopted. The GPIO and timer functions of the microcontroller are used to calculate the resistance value through the charge and discharge time of the capacitor, which simplifies the circuit structure and reduces the dependence on the ADC and constant current source.

Benefits of technology

The device realizes resistance measurement with low cost, simplified circuit and hardware resource saving, and is suitable for embedded systems and portable devices, with flexible measurement adaptability and high measurement accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120610065A_ABST
    Figure CN120610065A_ABST
Patent Text Reader

Abstract

The invention discloses a resistance value measuring method which comprises the following steps: controlling charging and discharging of a capacitor through a microcontroller GPIO (General Purpose Input / Output), measuring charging and discharging time by utilizing a timer, and calculating a resistance value by combining an RC formula or a calibration coefficient. According to the method, an ADC (Analog to Digital Converter), an operational amplifier or a constant current source is not needed, only one GPIO (General Purpose Input / Output) and one capacitor are needed, the circuit is simplified, the cost is reduced, and the method is suitable for low-cost scenes such as an embedded system.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of electronic measurement technology, and specifically relates to a resistance value measurement method, which is suitable for low-cost and simplified measurement scenarios of the resistance value of resistor elements, and is particularly suitable for applications such as embedded systems and portable measurement equipment that are sensitive to circuit complexity and cost. Background Art

[0002] In the field of electronic measurement, resistance measurement is a basic and commonly used technology. 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 a complex balance adjustment mechanism. The circuit structure is complex and is not suitable for low-cost integration scenarios.

[0003] The constant current source method calculates the resistance value by passing a constant current through the resistor under test and measuring the voltage across it (U = IR). This method requires a high-precision constant current source circuit, and its stability directly affects measurement accuracy, resulting in high circuit costs.

[0004] ADC direct sampling: This method uses the microcontroller's ADC pin to acquire the voltage across the resistor (using a voltage divider circuit) to calculate 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. In the field of industrial control, some terminal devices require flexible configuration of communication addresses based on the application environment. Common methods are as follows: Changing configuration parameters through software requires additional debugging tools (such as computers, mobile phones, etc.) to communicate with the terminal device.

[0005] Coding through dip switches requires occupying multiple GPIO resources of the microcontroller, which can easily cause a shortage of microcontroller resources.

[0006] By installing an optional resistor, the ADC direct sampling method is used - the same as the ADC direct sampling method in the field of electronic measurement. Summary of the Invention

[0007] In response to the problems of complex circuits, high costs and high hardware resource requirements in the existing technology, the present invention proposes a resistance measurement solution based on the charging and discharging characteristics of capacitors to simplify the circuit, reduce costs and reduce dependence on hardware resources.

[0008] The technical solution adopted in the present invention is as follows: A resistance value measuring method, which uses a measuring circuit including a microcontroller U1, a capacitor C1, a measuring port 1 and a measuring port 2; The microcontroller U1 has at least GPIO function, external interrupt function and timer timing function, and its measurement pin Pc is connected to the measurement port 1; The capacitor C1 is connected in parallel between the measurement port 1 and the ground; the measurement port 1 and the measurement port 2 are used to connect to the measured resistor Rx; The measuring port 2 is also connected to the measuring voltage Vc; The Vc is a constant voltage and does not exceed the voltage tolerance range of the measurement pin of the microcontroller U1, and can trigger an external interrupt of the microcontroller U1; The measurement steps are as follows: (1) Set the measurement pin PC of the microcontroller U1 to push-pull output mode, and the output high / low level represents the charge / discharge of capacitor C1; (2) Delay T1 to ensure that the capacitor C1 is fully charged / discharged; (3) Switch the measurement pin PC of the microcontroller U1 to input mode, enable the falling edge / low level interrupt or the rising edge / high level interrupt, and then start one or a group of timers to start timing; (4) Wait for the interrupt signal from the measuring pin PC to arrive; (5) Stop the timer and obtain the measurement time Tx; (6) Use Tx to calculate the value of Rx.

[0009] Regarding the specific calculation methods in step (6), two are provided below: Method 1: The value of Rx can be calculated based on the following RC charge and discharge time calculation formula: tx=−Rx·C1·ln((Vt−Ve) / (Vs−Ve)) Where tx is the time in seconds corresponding to the measurement time Tx; Ve is the final voltage that can be reached during the charge / discharge process, which is also the measured voltage Vc in the present invention; Vt is the interrupt threshold voltage of the measurement pin Pc of the microcontroller U1, which can be obtained from its data sheet; Vs is the starting voltage of charge / discharge during the measurement process, When Vc=VDD, the starting voltage Vs=0V; When Vc is grounded, the starting voltage Vs=VDD.

[0010] Method 2: You can use the following formula to calculate the value of Rx (to offset component deviation and achieve higher accuracy): Rx=k·Tx Where k is the linear coefficient. In the calibration process, we can use steps (1) to (5) to measure the known resistance R1 to obtain the measurement time T1, and then calculate k = R1 / T1.

[0011] Considering the influence of the input leakage current of the measured pin Pc, the actual measurement curve (the curve of the relationship between Rx and Tx) is not linear. It is only approximately linear when the current Ix flowing through the measured resistor Rx is much larger than the leakage current Ic of the measurement pin Pc. Therefore, this method requires that the measured resistor Rx satisfies the condition: Rxmin < Rx << VDD / Ic, where Rxmin is the minimum measurement resistor allowed by the circuit. Specific scenario adaptation

[0012] There are specific differences in the measurement method according to the different measurement voltages Vc. Charging timing method

[0013] When the measurement voltage Vc = VDD, when the microcontroller U1 discharges the capacitor C1, the circuit is still charging the capacitor C1 through the measured resistor Rx. Only when the discharge current is greater than the charging current can it be ensured that C1 can be discharged normally. Therefore, the resistance value of the measured resistor Rx is limited by the maximum discharge current Ifmax allowed by the circuit, and its value should be greater than VDD / Ifmax; because the circuit is discharging and charging simultaneously from step (1) to (2), the actual discharge current If is between Ifmax - VDD / Rxmin and Ifmax. Therefore, the delay value T1 should not be less than VDD·C1 / (Ifmax - VDD / Rxmin), where Rxmin is the minimum measurement resistance value allowed; the specific measurement method is as follows: (1) Set the measurement pin Pc of the microcontroller U1 to the push - pull output mode and output a low level to discharge the capacitor C1; (2) Delay for T1 to ensure that the capacitor is fully discharged; (3) Set the measurement pin of the microcontroller U1 to the input mode and enable the rising - edge / high - level interrupt. At this time, the circuit will charge through the measured resistor Rx, and then use one or a group of timers to start counting; The subsequent steps are the same as the above general steps.

[0014] Discharging timing method When the measurement voltage Vc is grounded, when the microcontroller U1 charges the capacitor C1, the circuit is still discharging the capacitor C1 through the measured resistor Rx. Only when the charging current is greater than the discharge current can it be ensured that C1 can be charged normally. Therefore, the resistance value of the measured resistor Rx is limited by the maximum charging current Icmax allowed by the circuit, and its value should be greater than VDD / Icmax; because the circuit is discharging and charging simultaneously from step (1) to (2), the actual charging current Ic is between Icmax - VDD / Rxmin and Icmax. Therefore, the delay value T1 should not be less than VDD·C1 / (Icmax - VDD / Rxmin), where Rxmin is the minimum measurement resistance value allowed; the specific measurement steps are as follows: (1) Set the measurement pin PC of the microcontroller U1 to push-pull output mode and output a high level to charge the capacitor C1; (2) Delay T1 to wait for the capacitor to be fully charged; (3) Set the measurement pin PC of the microcontroller U1 to input mode and enable the falling edge / low level interrupt. At this time, the circuit will discharge through the measured resistor Rx and then use one or a group of timers to start counting; The subsequent steps are consistent with the general steps above.

[0015] To improve the measurement accuracy, the measured resistance Rx can be measured repeatedly multiple times to obtain the average value.

[0016] Beneficial effects of the present invention Circuit simplification: no op amp or constant current source is required, only one capacitor is needed, reducing complexity; Resource saving: no ADC pin is required, only one GPIO pin with interrupt function is used, reducing dependence on the microcontroller; Low cost: Fewer components, easy to integrate into various devices; Flexible measurement method: Through different measurement voltage settings and corresponding operation steps, it can adapt to different measurement scenarios and has good practicality. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] Figure 1 A circuit diagram of the resistance value measurement method of the present invention; Figure 2 This is a circuit diagram of Embodiment A of the resistance value measurement method of the present invention; Figure 3 This is a circuit diagram of Example B of the resistance value measurement method of the present invention. DETAILED DESCRIPTION

[0018] refer to Figure 1 The schematic diagram shown includes a microcontroller U1, a capacitor C1, a measurement port 1, and a measurement port 2; pin 2 of the microcontroller U1 is connected to the measurement port 1 as the measurement pin PC, pin 9 is grounded, and pin 10 is connected to the power supply VDD; the capacitor C1 is connected in parallel between the measurement port 1 and the ground; and the measurement port 2 is connected to the measurement voltage Vc. During actual measurement, the resistor Rx to be measured is connected between measurement port 1 and measurement port 2.

[0019] The microcontroller U1 is STM32L011D4P6, which has GPIO push-pull output, external interrupt and timer functions, meeting the hardware requirements of the present invention; The measured voltage Vc should meet the following conditions: is constant pressure; The voltage tolerance of pin 2 of the microcontroller U1 should not be exceeded; Its size should be able to trigger an external interrupt of the microcontroller U1 required for the measurement; The following is a detailed description of two embodiments based on the specific quantized value of Vc. Both embodiments are set as follows: 1) The allowable value range of the measured resistance Rx is 1kΩ to 100kΩ; 2) C1=100nF, Rx=20kΩ, Ifmax=Icmax=4mA, VDD=3.3V; 3) The first time you execute the process, you must use a 10k resistor for calibration. The initial value of the calibration coefficient k is 0xFFFFFFFF (an invalid value for floating-point numbers). The specific embodiments are as follows: Example A

[0020] In this example, the measured voltage Vc=VDD, the equivalent schematic diagram of the actual measurement is as follows Figure 2 shown.

[0021] from Figure 2 It can be seen that the measured resistance Rx and capacitor C1 are in series. By programming the microcontroller, the measurement steps of the charging method and timing method are implemented, and the timer accuracy is configured to 1us. The specific steps are as follows: (1) The measuring pin PC outputs a low level and C1 discharges; (2) Delay T1, T1>472μs, calculated according to the formula: 3.3V×100nF / (4mA−3.3V / Rxmin), when Rxmin=1kΩ, T1≈472μs); (3) Switch to input mode, enable rising edge interrupt, and start timer timing; (4) VDD charges C1 through Rx and triggers an interrupt when it reaches 0.7VDD; (5) Stop timing and obtain the measured time Tx; (6) Determine whether the calibration coefficient k is 0XFFFFFFFF. If so, calculate k = 10000 / Tx (Tx is the measurement time corresponding to a 10 kΩ resistor). Assuming that Tx = 1200, then k = 8.333333, and then save the value of k. Otherwise, calculate Rx = k·Tx. If Tx = 2410, then Rx ≈ 20.033 kΩ.

[0022] The resistance value Rx is measured correctly. Example B

[0023] In this example, the measured voltage Vc is grounded. The equivalent schematic diagram of the actual measurement is as follows: Figure 3 shown.

[0024] from Figure 3 It can be seen that the measured resistance Rx and capacitor C1 are in parallel. By programming the microcontroller, the measurement steps of the discharge method and timing method are implemented, and the timer accuracy is configured to 1us. The specific steps are as follows: (1) The measuring pin PC outputs a high level and C1 charges; (2) Delay T1, T1>472μs, calculated according to the formula: 3.3V×100nF / (4mA−3.3V / Rxmin), when Rxmin=1kΩ, T1≈472μs); (3) Switch to input mode, enable falling edge interrupt, and start the timer; (4) C1 is discharged through Rx and triggers an interrupt when it reaches 0.3VDD; (5) Stop timing and obtain the measured time Tx; (6) Determine whether the calibration coefficient k is 0XFFFFFFFF. If so, calculate k = 10000 / Tx (Tx is the measurement time corresponding to a 10 kΩ resistor). Assuming that Tx = 1200, then k = 8.333333, and then save the value of k; otherwise, calculate Rx = k·Tx. If Tx = 2404, then Rx ≈ 20.033 kΩ.

[0025] The resistance value Rx is measured correctly.

[0026] Working principle of the present invention In the present invention, capacitor C1 is a constant, and each charge and discharge voltage of capacitor C1 is determined by the hardware characteristics of microcontroller U1. It can be considered that the charge and discharge start and end voltages of capacitor C are also a set of constants. Therefore, when the charge and discharge time of capacitor C1 is measured, the measured resistance Rx can be calculated using the charge and discharge time calculation formula of the capacitor. Due to manufacturing process reasons, the actual value of the electronic component will be different from the nominal value, so the resistance value error calculated using the charge and discharge time calculation formula of the capacitor may be relatively large. Taking into account that the hardware characteristics of the electronic component remain basically unchanged under the same working environment, it can be considered that the charge and discharge time of the capacitor is linearly related to the measured resistance, so the method of measuring the charge and discharge time can be used to measure the resistance. However, in actual use, it is necessary to pay attention to the following points: 1) The measurement accuracy is affected by the timing accuracy of the timer in the microcontroller. Under the same timer timing accuracy, the longer the charge and discharge time, the more accurate the measurement; 2) Considering the influence of the input leakage current of the measuring pin Pc, the actual measurement curve (the relationship curve between Rx and tx) is not linear. It is only when the current Ix flowing through the measured resistor Rx is much larger than the leakage current Ic of the measuring pin Pc that it is approximately linear. Therefore, this method requires that the measured resistor Rx meets the following conditions: Rxmin

Claims

1. A method for measuring resistance, characterized in that: The measurement circuit it uses includes microcontroller U1, capacitor C1, measurement port 1 and measurement port 2; The microcontroller U1 has at least GPIO function, external interrupt function and timer timing function, and its measurement pin Pc is connected to the measurement port 1; The capacitor C1 is connected in parallel between the measurement port 1 and the ground; The measuring port 1 and the measuring port 2 are used to connect the measured resistor Rx; The measuring port 2 is also connected to the measuring voltage Vc; The Vc is a constant voltage and does not exceed the voltage tolerance range of the measurement pin of the microcontroller U1, and can trigger an external interrupt of the microcontroller U1; The measurement steps are as follows: (1) Set the measurement pin PC of the microcontroller U1 to push-pull output mode, and the output high / low level represents the charge / discharge of capacitor C1; (2) Delay T1 to ensure that the capacitor C1 is fully charged / discharged; (3) Switch the measurement pin PC of the microcontroller U1 to input mode, enable the falling edge / low level interrupt or the rising edge / high level interrupt, and then start one or a group of timers to start timing; (4) Wait for the interrupt signal of the measuring foot to arrive; (5) Stop the timer and obtain the measurement time Tx; (6) Use Tx to calculate the value of Rx.

2. The resistance value measuring method according to claim 1, wherein: In step (6), the value of Rx can be calculated based on the following RC charge and discharge time calculation formula: tx=−Rx·C1·ln((Vt−Ve) / (Vs−Ve)) Where tx is the time in seconds corresponding to the measurement time Tx; Ve is the final voltage that can be reached during the charge / discharge process, which is also the measured voltage Vc in the present invention; Vt is the interrupt threshold voltage of the measurement pin Pc of the microcontroller U1, which can be obtained from its data sheet; Vs is the starting voltage of charge / discharge during the measurement process, When Vc=VDD, the starting voltage Vs=0V; When Vc is grounded, the starting voltage Vs=VDD.

3. The resistance value measuring method according to claim 1, characterized in that: In step (6), the value of Rx can be calculated using the following formula: Rx=k·Tx Where k is the linear coefficient. In the calibration process, we can use steps (1) to (5) to measure the known resistance R1 to obtain the measurement time T1, and then calculate k = R1 / T1.

4. The resistance value measuring method according to claim 1, wherein: When the measured voltage Vc=VDD, steps (1) to (3) are as follows: (1) Set the measurement pin PC of the microcontroller U1 to push-pull output mode, and output a low level to discharge the capacitor C1; (2) Delay T1 to wait for the capacitor to discharge completely; (3) Set the measurement pin PC of the microcontroller U1 to input mode and enable the rising edge / high level interrupt. At this time, the circuit will charge through the measured resistor Rx and then start one or a group of timers to start counting.

5. The resistance value measuring method according to claim 4, characterized in that: The resistance of the measured resistor Rx is limited by the maximum discharge current Ifmax allowed by the circuit, and its value should be greater than VDD / Ifmax. Ifmax is determined by the data sheet of each electronic component and the specific application requirements. Since the circuit is discharging and charging at the same time during steps (1) to (2), the actual discharge current If is between Ifmax-VDD / Rxmin and Ifmax. Therefore, the delay value T1 should not be less than VDD·C1 / (Ifmax-VDD / Rxmin). Rxmin is the minimum allowable measured resistance value.

6. The resistance value measuring method according to claim 1, wherein: When the measured voltage Vc is grounded, steps (1) to (3) are specifically as follows: (1) Set the measurement pin PC of the microcontroller U1 to push-pull output mode and output a high level to charge the capacitor C1; (2) Delay T1 to wait for capacitor C1 to be fully charged; (3) Set the measurement pin PC of the microcontroller U1 to input mode and enable the falling edge / low level interrupt. At this time, the circuit will discharge through the measured resistor Rx and then start one or a group of timers to start counting.

7. The resistance value measuring method according to claim 6, characterized in that: The resistance of the measured resistor Rx is limited by the maximum charging current Icmax allowed by the circuit, and its value should be greater than VDD / Icmax. Icmax is determined by the data sheet of each electronic component and the specific application requirements. Since the circuit is discharging and charging at the same time during steps (1) to (2), the actual charging current Ic is between Icmax-VDD / Rxmin and Icmax. Therefore, the delay value T1 should not be less than VDD·C1 / (Icmax-VDD / Rxmin), and Rxmin is the minimum allowable measured resistance value.

8. The resistance value measuring method according to any one of claims 1 to 7, characterized in that: To improve the measurement accuracy, the measured resistance Rx can be measured repeatedly multiple times to obtain the average value.