You are on page 1of 4

Measure resistance with a microcontroller - EDN https://www.edn.

com/measure-resistance-with-a-microcontroller/
Advertisement

< https://www.edn.com/>

DESIGN < HTTPS://WWW.EDN.COM/CATEGORY/DESIGN/> DESIGN HOW-TO < HTTPS://WWW.EDN.COM/CATEGORY/DESIGN/DESIGN-HOW-TO/>

Measure resistance with a microcontroller

FEBRUARY 1, 2011 < HTTPS://WWW.EDN.COM/MEASURE-RESISTANCE-WITH- COMMENTS 3 < HTTPS://WWW.EDN.COM/MEASURE-RESISTANCE-


A-MICROCONTROLLER/> WITH-A-MICROCONTROLLER/#COMMENTS>
BY ADOLFO MONDRAGON < HTTPS://WWW.EDN.COM/AUTHOR/ADOLFO-MONDRAGON/>

Advertisement

Stepper motors contain coil windings that require resistance measurements. Measuring resistance in a production environment often requires some special circuits that minimize errors. Resistance
is easy to measure indirectly by using a constant-current source to force a voltage across the winding's unknown resistance, measuring the voltage, and applying Ohm's Law.

Figure 1 shows the basic concept of a circuit I designed to check the resistance of the wire coil winding of a stepper motor. An op amp configured as a differential amplifier produces a voltage
proportional to the unknown resistance. You can use this circuit to measure resistances—just start by identifying the range of resistances to measure. The stepper motor has a coil with a resistance
of 50 Ω ±15%, which ranges from 42.5 Ω to 57.5 Ω.

Next, define the scale measurement or digital value within the microcontroller. The nominal value of the DUT (device under test) should be close to half of the
scale selected. Thus, you should set the full-range scale from 0 Ω to 100 Ω.

Figure 1. The op amp


produces a voltage proportional
to the resistor under test where
the microcontroller digitizes the
voltage to calculate resistance.

Advertisement

If you use a microcontroller that contains a 10-bit ADC, it will produce a digital span from 0 to 1023 counts. Set the range of the ADC so that 0 Ω produces a count of 0 and 102.3 Ω produces a
count of 1023. This range simplifies the math and maximizes measurement precision. Half of this scale, 512 counts, represents 51.2 Ω. That's close to the nominal 50-Ω measurement of the DUT.
Table 1 shows the correlation among the input voltage to the ADC, the number of counts, and the coil's resistance.

Advertisement

The differential configuration of the op amp works as a four-wire measuring circuit similar to those used in many DMMs. Using separate wires for excitation
current and voltage measurement eliminates much of the common-mode noise and errors introduced from the DUT wiring and connections.

You must define the op amp's gain and, from that, the resistor values. In this circuit, the op amp provides adequate voltage for the microcontroller. It also provides isolation between the DUT and the
microcontroller's ADC input. To minimize errors, select resistors RA through RD so that the op amp operates at unity gain. To verify that you can run the op amp at unity gain, you must calculate the
current that passes through the coil. Using the values from Table 1, calculate the current (IIN ) needed to achieve a half scale of 51.2 Ω:

The constant-current source is based on an LM317 regulator, which can easily provide 48.8 mA. Thus, you can run the op amp at unity gain, which simplifies selection of the resistance values of RA
, RB , RC , and RD . For unity gain, all resistors should be equal. Their values should be considerably higher than the DUT's resistance. Keep the resistor values between 10 kΩ and 100 kΩ.

The circuit works best if you use resistors with 1% or better tolerance. If you need to reduce cost, then measure 5% resistors from a batch with a DMM. Select the four resistors that best match each
other's values. You may be able to achieve better than 1% matching this way.

The op amp also provides some isolation that can prevent dangerous voltages from reaching the microcontroller's ADC input. An op amp such as the LM6132 connected to a 5-V power supply will
limit the power supply's output voltage to 5 V, even under extreme conditions.

To operate an LM317 regulator as a constant-current source, you need to calculate a resistor value:

where IIN = 48.4 mA, so R = 25.86 Ω. You should, therefore, use a fixed 15-Ω resistor and a 20-Ω potentiometer.

1 de 4 08/02/2023, 16:18
Measure resistance with a microcontroller - EDN https://www.edn.com/measure-resistance-with-a-microcontroller/

– Capacitor C1 , connected at the output of the constant-current source, will stabilize oscillations caused by the inductance of the
winding coils from the stepper motor.
– Diode D1 , connected at pin 15 of the microcontroller, protects the microcontroller input from unexpected voltages when there are
components connected outside of the main circuit board.

Figure 2. The complete circuit shows the LM317 constant-current supply,the stepper motor under test, two LEDs, and an LCD screen.

Figure 3. A flow chart of the microcontroller code shows how the systemdecides pass/fail conditions and reports them to an LCD screen and the LEDs.

3 C O M M E N T S O N “ M E A S U R E R E S I S TA N C E W I T H A M I C R O C O N T R O L L E R ”

neil@autoscaninc.com
December 10, 2014

“There is an error in figure 1: the inverting and non-inverting input of the op-amp have been interchanged. This is fixed in figure 2.”

Log in to Reply

miguelfernando_55
January 21, 2019

2 de 4 08/02/2023, 16:18
Measure resistance with a microcontroller - EDN https://www.edn.com/measure-resistance-with-a-microcontroller/
“An upgrade to this good article would be to provide the power specifications, since the resistor from the current source should not be less than 1 watt, by my experience.n”

Log in to Reply

miguelfernando_55
January 21, 2019

“I am sorry. What I mean was P = R * I^2 = 0.1 watt. Not 1 watt.”

Log in to Reply

LE AV E A REP LY

You must Sign in < https://login.aspencore.com/d045a02d-767d-4f3f-80d7-695dce25d142/login/authorize?response_type=code&scope=profile%20email%20openid&client_id=cf5f876c-2b69-4672-892d-


1a3f9cd881ea&state=2fd7dcf39776b623112d8d7eb90daa99&redirect_uri=https%3A%2F%2Fwww.edn.com%2Fopenid-connect-authorize> or Register < https://login.aspencore.com/d045a02d-767d-4f3f-
80d7-695dce25d142/login/authorize?response_type=code&scope=profile%20email%20openid&client_id=cf5f876c-2b69-4672-892d-1a3f9cd881ea&state=2ee9724ab8f59e26afc183451a8543de&
redirect_uri=https%3A%2F%2Fwww.edn.com%2Fopenid-connect-authorize> to post a comment.

P R EV I OU S P OS T < H T T P S: / / W W W. E D N . C O M/ P R O D U C T- U PD AT E - 7 / > N E XT P O S T < H T T PS : / / W W W. E D N . C O M / MA N AG E- YO UR - M EA S U R E ME N T- ER R O R S / >

https://api.aspencore.com/syndication/v3/partnered-content/

Advertisement

Advertisement

Recent Posts

Fixing security threat with post-quantum crypto on eFPGA < https://www.edn.com/fixing-security-threat-with-post-quantum-crypto-on-efpga/> / Birds on power lines, another look < https://www.edn.com
/birds-on-power-lines-another-look/> / How gate driver enables a wide range of battery voltages < https://www.edn.com/how-gate-driver-enables-a-wide-range-of-battery-voltages/> / Managing chaos <
https://www.edn.com/managing-chaos/> / Cracking open an already-cracked calculator < https://www.edn.com/cracking-open-an-already-cracked-calculator/>

Archives

Select Month

Categories

Select Category

3 de 4 08/02/2023, 16:18

You might also like