Resistance, capacitance and inductance measuring device and method based on single-chip microcomputer
By using a microcontroller-based resistance, capacitance, and inductance measuring device, the measurement range is automatically determined, solving the problems of error and low efficiency caused by manual selection of the measurement range in the existing technology, and realizing fast and accurate resistance, capacitance, and inductance measurement.
Patent Information
- Application Number
- CN202511097858.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-06
- Publication Date
- 2025-11-25
AI Technical Summary
Existing resistance, capacitance, and inductance measurement equipment requires manual selection of the measurement range, which can easily lead to excessive errors or failure to measure, and is also inefficient.
A microcontroller-based resistance, capacitance, and inductance measuring device is used. Through a function switching module, signal generator, loading module, comparator, and analog-to-digital converter, the measurement range is automatically determined, waveform control signals are generated, and resistance, capacitance, and inductance are measured.
It eliminates the need to manually determine the measurement range, enabling quick and accurate measurement of resistance, capacitance, and inductance, thus improving measurement efficiency.
Smart Images

Figure CN121008087A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of circuit element measurement technology, specifically to a device and method for measuring resistance, capacitance and inductance based on a microcontroller. Background Technology
[0002] In electronic systems, resistors, capacitors, and inductors are all essential electronic components, making measuring devices for these components indispensable. However, existing measuring devices have some shortcomings. For example, when measuring resistance with a commonly used multimeter, the measurement range needs to be manually selected based on the values of the resistor, capacitor, and inductor. Incorrect selection of the measurement range can lead to excessively large measurement errors, or even make measurement impossible. Furthermore, repeatedly adjusting the measurement range is time-consuming and inefficient. Summary of the Invention
[0003] To address the shortcomings of existing technologies, this invention provides a microcontroller-based resistor, capacitor, and inductance measurement device and method. This eliminates the need for manual determination of the measurement range; only the type of the component under test needs to be determined to automatically and quickly measure the resistance, capacitance, and inductance, making it more convenient and significantly improving measurement efficiency.
[0004] To achieve the above objectives, the specific solution adopted by the present invention is as follows: a resistance, capacitance, and inductance measuring device based on a microcontroller, comprising: Microcontroller; The function switching module is electrically connected to the microcontroller and is used to send a measurement target signal to the microcontroller so that the microcontroller outputs a waveform control signal. The measurement target signal is a resistance measurement signal, a capacitance measurement signal, or an inductance measurement signal. A signal generator, electrically connected to the microcontroller, is used to generate a sine wave based on a waveform control signal; The loading module is electrically connected to the signal generator and is used to apply a sine wave to the device under test and cooperate with the device under test to form a low-pass filter circuit. The comparator, electrically connected to the loading module, is used to acquire the output wave from the low-pass filter circuit and compare it with the sine wave to generate a difference signal, which is then sent to the microcontroller. An analog-to-digital converter, electrically connected to the loading module, is used to convert the output wave and transmit it to the microcontroller.
[0005] As a further optimization of the above-mentioned microcontroller-based resistance, capacitance and inductance measuring device: the microcontroller is set to STC89C52, the signal generator is set to MAX038, the comparator is set to LM339, and the analog-to-digital converter is set to AD7821.
[0006] As a further optimization of the above-mentioned microcontroller-based resistance, capacitance and inductance measurement device: the function switching module includes switches KA1, KA2 and KA3. The first terminals of switches KA1, KA2 and KA3 are all grounded. The second terminals of switches KA1, KA2 and KA3 are each connected to a pull-up resistor. The three pull-up resistors are electrically connected to the P2.0, P2.1 and P2.2 pins of the microcontroller, respectively.
[0007] As a further optimization of the aforementioned microcontroller-based resistance, capacitance, and inductance measurement device: the device further includes a drive output module, which includes a Darlington transistor and a relay group. The relay group includes relays K1, K2, K3, K4, K5, K6, and K7. The seven input pins of the Darlington transistor are electrically connected to the seven I / O ports of the microcontroller in a one-to-one correspondence. The seven output pins of the Darlington transistor are used to drive relays K1, K2, K3, K4, K5, K6, and K7 respectively. Relays K1, K2, and K3 are electrically connected to the loading module, and relays K4, K5, K6, and K7 are electrically connected to the signal generator.
[0008] As a further optimization of the above-mentioned microcontroller-based resistance, capacitance and inductance measuring device: relays K4, K5, K6 and K7 each include two normally open contacts, one of which is connected between the REF pin and the IIN pin of the signal generator, and the other normally open contact is connected to the COSC pin of the signal generator and grounded.
[0009] As a further optimization of the above-mentioned microcontroller-based resistance, capacitance and inductance measuring device, the device further includes a display module, which is electrically connected to the microcontroller.
[0010] As a further optimization of the above-mentioned microcontroller-based resistance, capacitance and inductance measurement device: a first operational amplifier is provided between the signal generator and the loading module.
[0011] As a further optimization of the above-mentioned microcontroller-based resistance, capacitance and inductance measurement device: a second operational amplifier is provided between the loading module and the comparator.
[0012] A method for measuring resistance, capacitance, and inductance based on a microcontroller, and based on the aforementioned microcontroller-based resistance, capacitance, and inductance measuring device, the method includes the following steps: Initialize the microcontroller and set global variables; The function switching module is adjusted according to the type of the component under test to generate a waveform control signal that matches the component under test; The signal generator is used to generate a sine wave based on a waveform control signal; The loading module is used to apply a sine wave to the component under test, and the low-pass filter circuit generates an output wave. The comparator is used to compare the output wave and the sine wave to generate a difference signal, which is then sent to the microcontroller. The magic converter is used to convert the output wave and send it to the microcontroller.
[0013] As a further optimization of the above-mentioned microcontroller-based resistance, capacitance and inductance measurement method: after receiving the output wave, the microcontroller adjusts the waveform control signal based on the amplitude of the output wave and sends it to the signal generator.
[0014] Beneficial effects: This invention eliminates the need to manually determine the measurement range; it only requires determining the type of the component under test to automatically and quickly measure the resistance, capacitance, and inductance, making it more convenient and significantly improving measurement efficiency. Attached Figure Description
[0015] Figure 1 This is a circuit diagram of the measuring device of the present invention; Figure 2 It is a waveform diagram corresponding to the circuit diagram of this invention. Detailed Implementation
[0016] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0017] like Figure 1 and Figure 2 As shown, a microcontroller-based resistance, capacitance, and inductance measuring device includes a microcontroller, a function switching module, a signal generator, a loading module, a comparator, and an analog-to-digital converter.
[0018] Microcontroller.
[0019] The function switching module is electrically connected to the microcontroller and is used to send a measurement target signal to the microcontroller so that the microcontroller outputs a waveform control signal. The measurement target signal is a resistance measurement signal, a capacitance measurement signal, or an inductance measurement signal.
[0020] A signal generator, electrically connected to a microcontroller, is used to generate sine waves based on waveform control signals.
[0021] The loading module is electrically connected to the signal generator and is used to apply a sine wave to the device under test. It also works with the device under test to form a low-pass filter circuit. A first operational amplifier is provided between the signal generator and the loading module.
[0022] The comparator, electrically connected to the loading module, is used to acquire the output wave from the low-pass filter circuit and compare it with the sine wave to generate a difference signal that is sent to the microcontroller. A second operational amplifier is provided between the loading module and the comparator.
[0023] An analog-to-digital converter, electrically connected to a loading module, is used to convert the output wave and send it to a microcontroller.
[0024] In a specific embodiment of the present invention, such as Figure 1 As shown, the selection of each component is as follows. Figure 1 In the diagram, Rx, Cx, and Lx represent the resistance, capacitance, and inductance to be measured, respectively.
[0025] The microcontroller is set to STC89C52, using a 12MHz crystal with a clock cycle of 1µs. A +9V battery is selected as the system input power supply; a power supply chip obtains ±5V voltage from the +9V battery.
[0026] The signal generator is model MAX038. The power supply pins V+ and V- are connected to +5V and -5V respectively. The A1 pin is connected to +5V, and the OUT pin is set to output a sine wave with an amplitude of ±1V. The DADJ pin is connected to ground so that the positive and negative half-cycles of the sine wave each account for 50%. The FDAJ pin is connected to ground, so that the frequency of the output sine wave signal is f = Iin(uA) / CF(pF)×106(Hz), where Iin is the current of the pin IIN and CF is the capacitance of the external capacitor connected to the pin COSC. In order to adjust the frequency of the output sine wave, four relays with two normally open contacts are introduced. The REF pin of the signal generator chip MAX038 outputs a reference power supply of 2.5V. This pin is connected to four precision resistors R1 to R4, and further connected to the IIN pin of the signal generator chip MAX038 through the normally open contacts K4-2 to K7-2 of four relays K4 to K7. At any given time, only one of the four relays K4 to K7 is energized, that is, only one of the four precision resistors R1 to R4 is connected to the loop between pins REF and IIN. Assuming the connected resistance is RF (kΩ), according to the chip datasheet, Iin (uA) = 2.5 / (RF+3.3).
[0027] The COSC pin of the signal generator chip MAX038 is connected to four precision capacitors C1 to C4 via the normally open contacts K4-1 to K7-1 of four relays K4 to K7, and further connected to ground. At any given time, only one of the four relays K4 to K7 is energized, meaning only one of the four precision capacitors C1 to C4 is connected to the loop between the COSC pin and ground. The resistance of this loop is CF (pF), thus allowing us to use the formula f = Iin(uA) / CF(pF) × 10. 6 (Hz), the OUT pin obtains sine wave signals of different frequencies.
[0028] The MAX038 signal generator chip outputs a sine wave signal with frequency f at pin OUT, and its amplitude is ±1V. The signal expression is r1 = sin(wt), where the angular frequency w = 2πf. To increase the amplitude of the sine wave signal, a high-speed first operational amplifier of model MAX442 is used. The OUT pin of the MAX038 signal generator chip is connected to the non-inverting input pin IN0 of the first operational amplifier. The output pin VOUT of the first operational amplifier is connected to the inverting input pin IN- through resistor R5, and simultaneously connected to ground through resistor R6. It can be seen that the first operational amplifier is connected as a non-inverting proportional operational amplifier circuit. Taking R5 = 810Ω and R6 = 270Ω, the amplification factor of the first operational amplifier is 4, and the amplitude of the sine wave signal output by the first operational amplifier is ±4V. The signal expression is r2 = 4sin(wt).
[0029] The comparator model is set to LM339, which contains two comparators. Comparator 1's non-inverting input pin IN1+ is connected to the output of the second operational amplifier, and its inverting input pin IN1- is grounded, thus converting the output sine wave of the low-pass filter circuit into a square wave. Comparator 2's non-inverting input pin IN2+ is connected to the output of the first operational amplifier, and its inverting input pin IN2- is grounded, thus converting the input sine wave of the low-pass filter circuit into a square wave. The outputs of Comparator 1 and Comparator 2 of the LM339 are connected to NOT gate 1 and NOT gate 2, respectively. The outputs of NOT gate 1 and NOT gate 2 are connected to the external interrupt input pins / INT1 and / INT0 of the STC89C52 microcontroller to measure the phase difference between the two signals. Assuming the falling edge time difference between the two signals is Δt, the phase difference is...
[0030] The analog-to-digital converter (ADC) is designated as AD7821. Its analog input terminal 20VIN is connected to the VOUT pin of the second operational amplifier, which outputs a sine wave signal. The 8-bit digital output signals DB0 to DB7 of the AD7821 are connected to P0.0 to P0.7 of the ST89C52 microcontroller. The MODE pin is connected to ground to set the AD7821 to read / write mode. The write signal / WR, read signal / RD, and chip select signal / CS are connected to P2.5 to P2.7 of the ST89C52 microcontroller, respectively. The AD7821 uses a single +5V power supply, and the reference power supply Vref+ uses +5V, provided by the reference power supply chip. After the analog-to-digital conversion is completed, the interrupt output signal / INT is connected to the / INT3 pin of the ST89C52 microcontroller.
[0031] The sinusoidal signal r2 = 4sin(wt) output by the first operational amplifier is connected to Rx, R7, and Lx. The other ends of Rx, R7, and Lx are connected to the normally open contacts K1-1 to K3-1 of three relays K1 to K3. The other ends of K1-1 to K3-1 are connected to the non-inverting input IN0 of the second operational amplifier (model MAX442), and are also connected to the normally open contacts K1-2 to K3-2 of three relays K1 to K3. The other ends of K1-2 to K3-2 are connected to capacitor C5, capacitor Cx under test, and resistor R7, respectively. The other ends of capacitor C5, capacitor Cx under test, and resistor R7 are all connected to ground.
[0032] Furthermore, the function switching module includes switches KA1, KA2, and KA3. The first terminals of switches KA1, KA2, and KA3 are all grounded. The second terminals of each of switches KA1, KA2, and KA3 are each connected to a pull-up resistor. These three pull-up resistors are electrically connected to pins P2.0, P2.1, and P2.2 of the microcontroller, respectively. More specifically, one end of each of the three switches KA1 to KA3 is connected to ground, and the other end is connected to a pull-up resistor, which is also connected to pins P2.0 to P2.2 of the STC89C52 microcontroller. Only one of the three switches can be closed at a time. When KA1 is closed, it indicates resistance measurement; when KA2 is closed, it indicates capacitance measurement; and when KA3 is closed, it indicates inductance measurement.
[0033] The device also includes a drive output module, which comprises a Darlington transistor and a relay group. The relay group includes relays K1, K2, K3, K4, K5, K6, and K7. The seven input pins of the Darlington transistor are electrically connected to the seven I / O ports of the microcontroller, corresponding one-to-one. The seven output pins of the Darlington transistor are used to drive relays K1, K2, K3, K4, K5, K6, and K7. Relays K1, K2, and K3 are electrically connected to the loading module, while relays K4, K5, K6, and K7 are electrically connected to the signal generator. Each relay (K4, K5, K6, and K7) includes two normally open contacts. One normally open contact is connected between the REF and IIN pins of the signal generator, and the other normally open contact is connected to the COSC pin of the signal generator and grounded.
[0034] More specifically, the seven I / O ports P1.1 to P1.7 of the STC89C52 microcontroller are connected to the seven input pins 1 to 7 of the Darlington transistor ULN2003, and the corresponding seven output pins 16 to 10 of the Darlington transistor, which drive seven relays K1 to K7 respectively. All seven relays K1 to K7 are driven by a high-level signal, and each has two normally open contacts. For example, relay K1 has two normally open contacts, K1-1 and K1-2, and so on.
[0035] The measurement principles of resistance, capacitance, and inductance are explained below.
[0036] To measure the resistance Rx, the STC89C52 microcontroller's P1.1 is set to 1, driving relay K1 to conduct. This causes its two normally open contacts K1-1 and K1-2 to conduct. The low-pass filter circuit consists of resistor Rx and capacitor C5. The transfer function of the low-pass filter circuit is... The input signal to the low-pass filter circuit is r2 = 4sin(wt), and the IN0 pin of the second operational amplifier is the output signal of the low-pass filter circuit. The steady-state expression of this signal is: As can be seen, the input signal is a sine wave, and the steady-state output signal is also a sine wave with frequency f. Only the amplitude and phase change; the amplitude increases. The phase lags by arctan(wRxC5), so the phase difference between the two signals before and after the low-pass filter circuit is measured. Then, since the capacitor C5 is known, the resistance to be measured can be calculated.
[0037] To measure the capacitance Cx, the STC89C52 microcontroller's P1.2 is set to 1, driving relay K2 to conduct. This causes its two normally open contacts, K2-1 and K2-2, to conduct. The low-pass filter circuit consists of resistor R7 and capacitor Cx. The transfer function of the low-pass filter circuit is... The input signal to the low-pass filter circuit is r2 = 4sin(wt), and the output signal of the low-pass filter circuit is pin IN0 of the second operational amplifier.
[0038] The steady-state expression of this signal is: As can be seen, the input signal is a sine wave, and the steady-state output signal is also a sine wave with frequency f. Only the amplitude and phase change; the amplitude increases. The phase lags by arctan(ωR7Cx), so after measuring the phase difference between the two signals, since the resistance R7 is known, the capacitance to be measured can be calculated.
[0039] To measure the magnitude of the inductance Lx, the STC89C52 microcontroller's P1.3 is set to 1, driving relay K3 to conduct. This causes its two normally open contacts, K3-1 and K3-2, to conduct. The low-pass filter circuit consists of inductor Lx and resistor R8. The transfer function of the low-pass filter circuit is... The input signal to the low-pass filter circuit is r2 = 4sin(wt), and the IN0 pin of the second operational amplifier is the output signal of the low-pass filter circuit. The steady-state expression of this signal is: As can be seen, the input signal is a sine wave, and the steady-state output signal is also a sine wave with frequency f. Only the amplitude and phase change; the amplitude increases. The phase lags by arctan(ωLx / R8), so after measuring the phase difference between the two signals, the inductance to be measured can be calculated since the resistance R8 is known.
[0040] To increase the input impedance of the low-pass filter circuit, the output signal of the low-pass filter circuit is connected to the non-inverting input pin IN0 of the high-speed second operational amplifier of model MAX442. The output pin VOUT of the second operational amplifier is connected to the inverting input pin IN- of the second operational amplifier. That is, the second operational amplifier acts as an emitter follower, isolating the previous low-pass filter. Its output signal expression is equal to the output of the previous low-pass filter circuit. In other words, the output of the VOUT pin is still u.
[0041] The transfer function formulas for the three low-pass filter circuits show the cutoff frequency of the low-pass filter circuit when measuring resistance Rx. When measuring capacitor Cx, the cutoff frequency of the low-pass filter circuit. When measuring inductance Lx, the cutoff frequency of the low-pass filter circuit. This cutoff frequency can be used as the highest angular frequency of the input sine wave of the low-pass filter circuit.
[0042] The higher the frequency of the sine wave signal, the faster the measurement speed. However, the frequency of the sine wave signal is limited by the cutoff frequency, which in turn is related to the magnitude of the measurement.
[0043] The measurement range for resistance Rx in this system is set to 0–100 MΩ, the measurement range for capacitance Cx is 50 pF–20 uF, and the measurement range for inductance Lx is 1 uH–10 h.
[0044] Choosing C5 = 1nF, when Rx = 100MΩ, the cutoff frequency is... This frequency is relatively low; as the resistance Rx decreases, the cutoff frequency increases; for example, when Rx = 100kΩ, the cutoff frequency... =1600Hz; In order to improve the measurement speed, it is necessary to switch the frequency of different sine wave input signals according to the resistance value.
[0045] With R7 = 100Ω, when Cx = 20uF, the cutoff frequency is... This frequency is relatively low; the cutoff frequency increases as the capacitance value decreases; for example, when Cx = 20nF, the cutoff frequency... To improve measurement speed, it is necessary to switch the frequency of different sine wave input signals according to the capacitance value.
[0046] With R8 = 100kΩ selected, when Lx = 10H, the cutoff frequency is... This frequency is relatively low; as the inductance value of the inductor under test decreases, the cutoff frequency will increase; for example, when Lx = 10mH, the cutoff frequency... Because of the large cutoff frequency, it is not necessary to switch the frequency of the sine wave input signal.
[0047] In summary, the frequency of the sine wave signal output by the MAX308 signal generator can be set to approximately 1Hz, 10Hz, 100Hz, and 1kHz. Therefore, based on the sine wave frequency formula for the MAX308 mentioned above, the resistance values of R1 to R4 and the capacitance values of C1 to C4 are set as follows: C1=50uF, R1=47kΩ; C2=50uF, R2=1.69kΩ; C3=5uF, R3=1.69kΩ; C4=0.5uF, R4=1.69kΩ.
[0048] To speed up the measurement process, a higher sine wave signal frequency of 1kHz can be used initially. When the required cutoff frequency is low, the frequency can be switched to a lower sine wave signal frequency. Since the measurement is unknown, the cutoff frequency can be determined by the attenuation of the output sine wave signal amplitude; that is, the amplitude of the sine wave signal output by the low-pass filter circuit is attenuated to the input amplitude. At that time, it was assumed that the cutoff frequency was too low, and the frequency of the input sine wave needed to be reduced.
[0049] To facilitate quick acquisition of measurement results by users, the device also includes a display module, which is electrically connected to the microcontroller. More specifically, the display module is configured as an OLED module, with its SCL and SDA pins connected to P2.3 and P2.4 of the STC89C52 microcontroller, respectively. These two I / O ports of the microcontroller simulate the I2C protocol to achieve display control of the OLED module.
[0050] The present invention also provides a method for measuring resistance, capacitance and inductance based on a microcontroller, and the method includes steps S1 to S6 based on the above-mentioned microcontroller-based resistance, capacitance and inductance measuring device.
[0051] S1. Initialize the microcontroller and set the global variables snum, Δφ, and Δt to 0.
[0052] S2. Adjust the function switching module according to the type of the component under test to generate a waveform control signal that matches the component under test. Specifically, acquire the state of pins P2.0 to P2.2 and operate according to the pin state: If P2.0 = 0, it indicates resistance measurement, so set pin P1.7 to high level, drive relay K1, its normally open contacts K1-1 and K1-2 close, and a low-pass filter circuit is formed by Rx and C5; if P2.1 = 0, it indicates capacitance measurement, so set pin P1.6 to high level, drive relay K2, its normally open contacts K2-1 and K2-2 close, and a low-pass filter circuit is formed by R7 and Cx; if P2.2 = 0, it indicates inductance measurement, so output a high level on pin P1.5, drive relay K3, its normally open contacts K3-1 and K3-2 close, and a low-pass filter circuit is formed by Lx and R8.
[0053] S3. A sine wave is generated based on a waveform control signal using a signal generator. Specifically, the STC89C52 microcontroller outputs a high level from P1.1, driving relay K7. Its normally open contacts K7-1 and K7-2 close, and the MAX308 signal generator produces a sine wave r1 = sin(wt) with a frequency f of 1kHz and an amplitude of ±1V, where w = 2πf. After passing through the first operational amplifier, the sine wave r1 = sin(wt) becomes a sine wave r2 = 4sin(wt) with an amplitude of ±4V. If the sine wave r2 = 4sin(wt) passes through a low-pass filter circuit composed of the resistor Rx and capacitor C5, a sine wave is generated. If a sine wave is generated after passing through a low-pass filter circuit composed of resistor R7 and capacitor Cx under test... If a sine wave is generated after passing through a low-pass filter circuit composed of the inductor Lx and resistor R8, The amplitude of the output sine wave is attenuated and the phase is lagging. After passing through the second operational amplifier, the sine wave u has improved its load capacity, and the waveform remains unchanged, still being u. The sine wave signals r2 and u before and after the low-pass filter circuit are respectively introduced into the phase input terminals of comparator 1 and comparator 2 of the comparator chip LM339, thereby converting the two sine waves into square wave signals. The two square wave signals are introduced into the external interrupt input pins / INT0 and / INT1 of the microcontroller STC89C52 after passing through the NOT gate.
[0054] S4. Apply a sine wave to the component under test using the loading module, and generate an output wave based on the low-pass filter circuit.
[0055] S5. A comparator is used to compare the output wave and the sine wave to generate a difference signal, which is then sent to the microcontroller. Subsequently, calculations are performed based on the formula; the formula for calculating the resistance to be measured is as follows: The formula for calculating the capacitance under test is: The formula for calculating the inductance under test is:
[0056] S6. The output wave is converted using a magic converter and sent to the microcontroller. After receiving the output wave, the microcontroller adjusts the waveform control signal based on the amplitude of the output wave and sends it to the signal generator.
[0057] Furthermore, the interrupt handling method is as follows.
[0058] In the interrupt service routine of / INT0, the global variable snum is incremented by 1. If snum is greater than 2, timer 0 is started; otherwise, the process exits and continues to wait for an interrupt. The main purpose is to wait for two cycles to allow the sinusoidal signal output by the low-pass filter circuit to enter a steady state before performing the corresponding measurement. At the same time, the / INT1 interrupt is enabled.
[0059] In the interrupt service method of Timer 0, increment ynum by 1 to record the number of overflows of Timer 0.
[0060] In the interrupt service routine of / INT1, the value of timer 0 is first read and stored in the variable tx, and then timer 0 is turned off; then timer 1 is started as a timer interrupt, with a timing period of 1 / 4 of the sine wave period, which is the peak value of the sine wave.
[0061] In the Timer 1 interrupt service routine, if the current measurement is of inductance, the time difference Δt is directly calculated as (ynum × 65536 + tx) × 10. -6 (s), phase difference Disable Timer 1 interrupt and exit.
[0062] If the measurement is of resistance or capacitance, the STC89C52 microcontroller sets P2.7 to 0, activating the AD7821 analog-to-digital converter to perform analog-to-digital conversion, obtaining the amplitude of the sinusoidal signal output from the low-pass filter. If the amplitude is greater than... Then calculate the time difference Δt = (ynum × 65536 + tx) × 10 -6 Phase difference Then set variables snum and ynum to 0, disable Timer 1 interrupt and exit; otherwise, make the following settings based on the current device under test and sine wave frequency.
[0063] If the current measurement is of resistance or capacitance, and the sine wave frequency is 1kHz, the STC89C52 microcontroller sets variables snum and ynum to 0; P1.1 outputs a low level, turning off relay K7; P1.2 outputs a high level, driving relay K6, whose normally open contacts K6-1 and K6-2 close, and the MAX308 signal generator produces a sine wave r1 = sin(wt) with a frequency f of 100Hz and an amplitude of ±1V; Timer 1 interrupt is turned off and the process exits.
[0064] If the current measurement is of resistance or capacitance, and the sine wave frequency is 100Hz, the STC89C52 microcontroller sets variables snum and ynum to 0; P1.2 outputs a low level, turning off relay K6; P1.3 outputs a high level, driving relay K5, whose normally open contacts K5-1 and K5-2 close, and the MAX308 signal generator produces a sine wave r1 = sin(wt) with a frequency f of 10Hz and an amplitude of ±1V; Timer 1 interrupt is turned off and the process exits.
[0065] If the current measurement is of capacitance and the sine wave frequency is 10Hz, then set variables snum and ynum to 0; calculate the time difference Δt = (ynum × 65536 + tx) × 10. -6 Phase difference Disable Timer 1 interrupt and exit.
[0066] If the current measurement is of resistance and the sine wave frequency f is 10Hz, the STC89C52 microcontroller sets variables snum and ynum to 0; P1.3 outputs a low level, turning off relay K5; P1.4 outputs a high level, driving relay K4, whose normally open contacts K4-1 and K4-2 close, and the MAX308 signal generator produces a sine wave r1 = sin(wt) with a frequency f of 1Hz and an amplitude of ±1V; Timer 1 interrupt is turned off and the process exits.
[0067] If the current sine wave frequency f is 1Hz, then set the variable snum to 0; calculate the time difference Δt = (ynum × 65536 + tx) × 10 -6 Phase difference Disable Timer 1 interrupt and exit.
[0068] The following provides a specific measurement procedure. The object being measured is a resistor with a resistance value of 100MΩ. The complete measurement procedure is as follows.
[0069] Step 1: Initialize the system using the STC89C52 microcontroller and set the global variables snum, Δφ, and Δt to 0.
[0070] Step 2: Since P2.0 = 0, indicating that resistance measurement is being performed, pin P1.7 is set to high level to drive relay K1. Its normally open contacts K1-1 and K1-2 are closed, and a low-pass filter circuit is formed by Rx and C5.
[0071] Step 3: The STC89C52 microcontroller outputs a high level on P1.1, driving the relay K7. Its normally open contacts K7-1 and K7-2 close, and the MAX308 signal generator produces a sine wave with a frequency f of 1kHz and an amplitude of ±1V. After passing through the first operational amplifier, the sine wave becomes a sine wave with an amplitude of ±4V. If the sine wave passes through the low-pass filter circuit composed of the resistor Rx and capacitor C5, a sine wave is generated. If f = 1kHz, the amplitude of the output sine wave is attenuated and the phase is lagging. After passing through the second operational amplifier, the above sine wave u has improved the load capacity, and the waveform remains unchanged. The sine wave signals before and after the low-pass filter circuit are introduced into the phase input terminals of comparator 1 and comparator 2 of the comparator chip LM339, respectively, thereby converting the two sine waves into square wave signals. The above two square wave signals are introduced into the external interrupt input pins / INT0 and / INT1 of the microcontroller STC89C52.
[0072] Step 4: Select the formula to calculate based on the component under test. Since the phase difference of the resistor under test has not yet been calculated and its initial value is 0, it will initially be displayed as 0 on the OLED screen.
[0073] The following are the methods for handling various interrupt services.
[0074] Step 5: In the first interrupt service routine of / INT0, the global variable snum is incremented by 1, resulting in snum = 1; in the second interrupt service routine of / INT0, the global variable snum is incremented by 1, resulting in snum = 2; in the third interrupt service routine of / INT0, the global variable snum is incremented by 1, resulting in snum = 3; at this point, the sinusoidal signal output by the low-pass filter has entered a steady state and can be measured accordingly; start timer 0; enable / INT1 interrupt.
[0075] Step 6: In the first overflow interrupt service method of Timer 0, record the overflow count ynum of Timer 0 and increment it by 1 to get ynum = 1.
[0076] Step 7: In the first interrupt service routine of / INT1, first read the value of Timer 0 and store it in the variable tx, and then disable the Timer 0 interrupt; then set the Timer 1 timer interrupt, with the timing period being 1 / 4 of the sine wave period, which is the peak value of the sine wave, and then disable the / INT1 interrupt.
[0077] Step 8, in the first interrupt service routine of Timer 1, since the resistance is being measured, the STC89C52 microcontroller sets P2.7 to 0, starting the AD7821 analog-to-digital converter to perform analog-to-digital conversion, resulting in a low-pass filter output sinusoidal signal with an amplitude of 0.0063, which is less than... The STC89C52 microcontroller sets variables snum and ynmu to 0; P1.1 outputs a low level, turning off relay K7; P1.2 outputs a high level, driving relay K6, whose normally open contacts K6-1 and K6-2 close, and the MAX308 signal generator produces a sine wave r1 = sin(wt) with a frequency of 100Hz and an amplitude of ±1V; Timer 1 interrupt is turned off and the process exits.
[0078] Step 9: Repeat steps (5) to (7) above. In step (8), the analog-to-digital converter AD7821 performs analog-to-digital conversion, resulting in a low-pass filter output sinusoidal signal with an amplitude of 0.063, which is less than... The STC89C52 microcontroller sets variables snum and ynmu to 0; P1.2 outputs a low level, turning off relay K6; P1.3 outputs a high level, driving relay K5, whose normally open contacts K5-1 and K5-2 close, and the MAX308 signal generator produces a sine wave r1 = sin(wt) with a frequency of 10Hz and an amplitude of ±1V; Timer 1 interrupt is turned off and the process exits.
[0079] Step 10: Repeat steps (5) to (7) above. In step (8), the analog-to-digital converter AD7821 performs analog-to-digital conversion, resulting in a low-pass filter output sinusoidal signal with an amplitude of 0.63, which is less than... The STC89C52 microcontroller sets variables snum and ynmu to 0; P1.3 outputs a low level, turning off relay K5; P1.4 outputs a high level, driving relay K4, whose normally open contacts K4-1 and K4-2 close, and the MAX308 signal generator produces a sine wave r1 = sin(wt) with a frequency of 1Hz and an amplitude of ±1V; the timer 1 interrupt is turned off and the process exits.
[0080] Step 11: Repeat steps (5) to (7) above. In step (8), the analog-to-digital converter AD7821 performs analog-to-digital conversion, resulting in a low-pass filter output sinusoidal signal with an amplitude of 6.3, which is greater than... Then set variables snum and ynmu to 0; Calculate the time difference Δt = (ynum × 65536 + tx) × 10 6 = (1×65536+23710)×10 6 = 89246 (µs), phase difference Disable Timer 1 interrupt and exit.
[0081] Step 12, Perform the calculation And it will be displayed on an OLED screen.
[0082] The above description of the disclosed embodiments enables those skilled in the art to make or use the invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the invention. Therefore, the invention is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A resistor, capacitor, and inductance measuring device based on a microcontroller, characterized in that, include: Microcontroller; The function switching module is electrically connected to the microcontroller and is used to send a measurement target signal to the microcontroller so that the microcontroller outputs a waveform control signal. The measurement target signal is a resistance measurement signal, a capacitance measurement signal, or an inductance measurement signal. A signal generator, electrically connected to the microcontroller, is used to generate a sine wave based on a waveform control signal; The loading module is electrically connected to the signal generator and is used to apply a sine wave to the device under test and cooperate with the device under test to form a low-pass filter circuit. The comparator, electrically connected to the loading module, is used to acquire the output wave from the low-pass filter circuit and compare it with the sine wave to generate a difference signal, which is then sent to the microcontroller. An analog-to-digital converter, electrically connected to the loading module, is used to convert the output wave and transmit it to the microcontroller.
2. The resistance, capacitance, and inductance measuring device based on a microcontroller as described in claim 1, characterized in that, The microcontroller is designated as STC89C52, the signal generator as MAX038, the comparator as LM339, and the analog-to-digital converter as AD7821.
3. The resistance, capacitance, and inductance measuring device based on a microcontroller as described in claim 2, characterized in that, The function switching module includes switches KA1, KA2, and KA3. The first terminals of switches KA1, KA2, and KA3 are all grounded. The second terminals of switches KA1, KA2, and KA3 are each connected to a pull-up resistor. The three pull-up resistors are electrically connected to the P2.0, P2.1, and P2.2 pins of the microcontroller, respectively.
4. The resistance, capacitance, and inductance measuring device based on a microcontroller as described in claim 2, characterized in that, The device further includes a drive output module, which comprises a Darlington transistor and a relay group. The relay group includes relays K1, K2, K3, K4, K5, K6, and K7. The seven input pins of the Darlington transistor are electrically connected to the seven I / O ports of the microcontroller in a one-to-one correspondence. The seven output pins of the Darlington transistor are used to drive relays K1, K2, K3, K4, K5, K6, and K7 respectively. Relays K1, K2, and K3 are electrically connected to the loading module, and relays K4, K5, K6, and K7 are electrically connected to the signal generator.
5. The resistance, capacitance, and inductance measuring device based on a microcontroller as described in claim 4, characterized in that, Relays K4, K5, K6, and K7 each include two normally open contacts. One normally open contact is connected between the REF and IIN pins of the signal generator, and the other normally open contact is connected to the COSC pin of the signal generator and grounded.
6. The resistance, capacitance, and inductance measuring device based on a microcontroller as described in claim 1, characterized in that, The device also includes a display module, which is electrically connected to the microcontroller.
7. The resistance, capacitance, and inductance measuring device based on a microcontroller as described in claim 1, characterized in that, A first operational amplifier is provided between the signal generator and the loading module.
8. The resistance, capacitance, and inductance measuring device based on a microcontroller as described in claim 1, characterized in that, A second operational amplifier is provided between the loading module and the comparator.
9. A method for measuring resistance, capacitance, and inductance based on a microcontroller, wherein the device for measuring resistance, capacitance, and inductance based on a microcontroller is described in any one of claims 1-8, characterized in that, The method includes the following steps: Initialize the microcontroller and set global variables; The function switching module is adjusted according to the type of the component under test to generate a waveform control signal that matches the component under test; The signal generator is used to generate a sine wave based on a waveform control signal; The loading module is used to apply a sine wave to the component under test, and the low-pass filter circuit generates an output wave. The comparator is used to compare the output wave and the sine wave to generate a difference signal, which is then sent to the microcontroller. The magic converter is used to convert the output wave and send it to the microcontroller.
10. The method for measuring resistance, capacitance, and inductance based on a microcontroller as described in claim 9, characterized in that, After receiving the output wave, the microcontroller adjusts the waveform control signal based on the amplitude of the output wave and sends it to the signal generator.