Author Topic: A mcu-based milliohm meter  (Read 28039 times)

0 Members and 1 Guest are viewing this topic.

dannyf

• Super Contributor
• Posts: 8221
• Country:
Re: A mcu-based milliohm meter
« Reply #25 on: January 21, 2014, 11:47:40 am »
Having re-read his paper, I think his analysis of the pins' output resistance is flawed - he basically assumed away the problem he was trying to analyze.

The current flows in two direction in this approach, from pin 1 to pin2 and then from pin2 to pin 1. A central but unspoken assumption is that the two current is identical (or at least close enough). For that to be true, the output resistance has to satisfy certain conditions - none of them requires the two pins to have the same output resistance.

We usually think of the pin's output resistance to be one, from 20 - 50ohm depending on the mcus used, and in serial with the output drive, just as the paper's author assumed. As his analysis shows and you would think intuitively as well, you don't require the two pins to have the same output resistance for the current to be the same in both directions - Page 3 of his paper deals with that, fairly concisely.

However, there are actually two output resistance: one when the pin is high ("high output resistance") and another when the pin is low ("low output resistance"). A little bit of math will show that the current is the same in both directions if pin 1's high output resistance + pin 2's low output resistance = pin 1's low output resistance + pin 2's high output resistance.

I had done some analysis way back that showed me the high output resistance on some Luminary chips (8ma drive I think) to be mostly within 1ohm difference (mostly < 0.5ohm). No analysis on low output resistance. and nothing done on the avr or pic (which the author used).

So I thought it was safe to assume that there are some differences from pin to pin, but the difference is probably within 1 ohm.

Because of that, you want to use substantial current limiting resistors - I used 380ohm resistors -> 6ma drive. That would mean that my accuracy would be around 6mohm, vs. accuracy of 15mohm in the author's case.

You could have further reduced the current to minimize the impact from output resistance mismatches but that limits your low range as well. So it is a balancing act.
================================
https://dannyelectronics.wordpress.com/

G0HZU

• Super Contributor
• Posts: 3156
• Country:
Re: A mcu-based milliohm meter
« Reply #26 on: January 21, 2014, 08:57:32 pm »
How would I know if it is accurate?

I have a .47ohm resistor, a 15ohm resistor.

The .47ohm resistor (+ unknown wire resistance) measured  out to be about 570mohm - the reading varies based on the touch points on the leads.
If you don't have any accurate shunts then you could measure the resistance of a length of solid copper wire. It's easy to measure the resistance of the wire beforehand using ohms law. eg you might have a wire with 40 milliohms resistance.

Then measure it with your meter. Then halve the length of the wire and measure again. Keep halving the length of the wire to see if you get an accurate straight line down to a few milliohms.

This all assumes you do the testing at a very low test frequency to avoid errors due to the inductance of the wire.
« Last Edit: January 21, 2014, 09:00:47 pm by G0HZU »

dannyf

• Super Contributor
• Posts: 8221
• Country:
Re: A mcu-based milliohm meter
« Reply #27 on: January 21, 2014, 10:22:50 pm »
DC vs. AC exciatation signal:

we discussed the pros / cons of each earlier - fundamentally they are the same: by flowing a known signal through an unknown resistor and measuring the voltage drop gives you the resistance reading.

In my last re-read of the article that EmmanuelFaure linked to, it stated that the individual adc readings vary wildly - as you would expect, yet the difference between the successive readings is very stable.

I can confirm that it is indeed the case, particularly in cases where high gain is used - the readings are actually visibly changing if you just put your finger on the mcu or lift it.

That speaks to the beauty of this ac excitation approach: it is inherently immune to drift / offset from the adc amplifier (or external amplifier if it is used).

BTW, the code provided in the link by EmmanuelFaure has two unnecessary steps of subtracting 512 from each reading - it is totally not needed.
================================
https://dannyelectronics.wordpress.com/

dannyf

• Super Contributor
• Posts: 8221
• Country:
Re: A mcu-based milliohm meter
« Reply #28 on: January 22, 2014, 12:22:04 pm »
Quote
Also, the same approach could be used to measure inductance / capacitance / esr - difficult with a dc source.

Here is an example of how the same approach could be used to measure esr.

ESR + C1 is the dut. R1/R2 are the current limiting resistors and V1/V2 are the out-of-phase excitation sources.

The green trace is the differential voltage across the dut. The vertical drops corresponds to 2 * ESR * Current. Current in this case is about 5v/(2*380) = 7ma plus so you should expect about 14mv voltage drop - about right.

The slope at the top corresponds to Current / Capacitance * Measurement time. For fixed current + measurement time, the slope is inversely proportional to the capacitance.

The advantage here with the ac excitation + differential amplifier is that you don't have to deal with drift + offset.
================================
https://dannyelectronics.wordpress.com/

dannyf

• Super Contributor
• Posts: 8221
• Country:
Re: A mcu-based milliohm meter
« Reply #29 on: January 22, 2014, 08:11:27 pm »
To do list:

1) calibration: the code now assumes that the excitation current is the same - there ought to be some variations in that. So we have to provide a means for the user to specify that. I think a +/-10% range will do. This will also compensate for variations in the bandgap reference.

2) two-wire vs. four-wire connection: two-wire connections will work, but its calibration will be a little bit tedious. One approach may be to use four-wire connection to calibrate the module and then use relative measurement to null out the wire resistance.

3) compensation for dut's impact on the excitation current: as we are not using a constant current source and the dut is in the path of current flow, the resistance of the dut will impact the current thus the measurement. However, this impact is bounded at its upper end (<5% for the 10x gain setting and < 0.1% for the 20x gain setting). If we implement autoranging (to 10x gain), we will compensate for the dut resistance.

4) autoranging: a potentially useful feature is to autorange the meter, from 10x to 200x, based on the dut's measurement. at 10x, we can measure from 40mohm to about 40ohm; at 200x, we can measure from 2mohm to about 2ohm.

5) esr capabilities: the hardware set-up is identical and the measurement workflow is almost identical. That would be a nice addition.

6) variable drive: the drive current is about 6ma (@ 380Ohm x 2), or 7ma (@ 330ohm x 2). Good for low resistance measurement. If we further lower the drive current to 2.5ma (@ 1Kohm x 2), we can extend the upper-end of the metter to 110 - 120ohm range.

7) relative / zeroing: For the two-wire mode to be useful, we will have to zero out the wire resistance. That's fairly easy to implement.

Once my Leonardo gets here, I will start working on the list.

================================
https://dannyelectronics.wordpress.com/

dannyf

• Super Contributor
• Posts: 8221
• Country:
Re: A mcu-based milliohm meter
« Reply #30 on: January 22, 2014, 11:09:32 pm »
Quote
4) autoranging:

Implemented.
================================
https://dannyelectronics.wordpress.com/

Rufus

• Super Contributor
• Posts: 2095
Re: A mcu-based milliohm meter
« Reply #31 on: January 22, 2014, 11:12:45 pm »
To do list:

1) calibration: the code now assumes that the excitation current is the same - there ought to be some variations in that. So we have to provide a means for the user to specify that. I think a +/-10% range will do. This will also compensate for variations in the bandgap reference.

I wonder why I bother posting sometimes.

The following users thanked this post: sipo75

dannyf

• Super Contributor
• Posts: 8221
• Country:
Re: A mcu-based milliohm meter
« Reply #32 on: January 22, 2014, 11:13:32 pm »
Quote
3) compensation for dut's impact on the excitation current:

Implemented.
================================
https://dannyelectronics.wordpress.com/

dannyf

• Super Contributor
• Posts: 8221
• Country:
Re: A mcu-based milliohm meter
« Reply #33 on: January 23, 2014, 01:16:58 am »
Quote
]1) calibration:

In progress.

Why do you need calibration?

The meter works by sending a "known" current through an unknown resistor and measures the voltage drop over the resistor to obtain its resistance.

The "known" current is (largely) determined by those two current limiting resistors (380ohm * 2 vs. milliohms for the dut - which we have corrected in software).

For the meter I am building now, I know precisely what the current is - I measured it to be around 6000ua for the current limiting resistors I used. So when I specified that in the code and compiled the code to that value, no calibration is needed.

Unfortunately, you don't have that luxury. For the "software", it always assumes the current to be what's specified in the code. Obviously, when you use different current limiting resistors, or run the code under different Vcc, or due to chip to chip variance, the actual current going through the dut will likely differ from those specified in the code.

Thus you need calibration.

================================
https://dannyelectronics.wordpress.com/

dannyf

• Super Contributor
• Posts: 8221
• Country:
Re: A mcu-based milliohm meter
« Reply #34 on: January 23, 2014, 01:22:09 am »
How to implement the calibration?

The simplest would be to use buttons but I am an anti-button kind of guy so I would use pot instead. A smaller trimmer would be used to dial in the adjustments to the current setting. I plan to allow +/- 32ua adjustments, for ease hand tweaking.

Once the adjustments are dialed in, the base current is modified and saved into eeprom for future uses: the current will be read back for measurements and / or calibration in the future.

This approach allows for the opportunity to dial in unlimited adjustments, through as many calibration sessions as needed. That means you can use any value current limiting resistors as you want and they don't need to be precision resistors at all.
================================
https://dannyelectronics.wordpress.com/

dannyf

• Super Contributor
• Posts: 8221
• Country:
Re: A mcu-based milliohm meter
« Reply #35 on: January 23, 2014, 01:39:25 am »
There are three possible ways to calibrate the meter:

1) a resistor of known value (needs to be less than the maximum range of the meter): in 4-wire mode, turn the meter into calibration mode, and measure the known resistor. Adjust the trimmer - the lcd will display the "measured" resistor value and modified current reading, in ua. Repeat until the lcd displays the correct resistor value.

2) a ua meter: put the ua meter on the milliohm meter to measure its "resistance" - the ua meter is now a dut to the milliohm meter. The ua meter will show the current flowing through itself (=dut). Adjust the trimmer until the displayed current matches that of the reading from the ua meter. You would need to have a ua meter with as low of burden voltage as possible.

3) two resistors: pick two resistors of known value - they don't need to be precision resistors and their values don't need to be precise. Pick the first resistor (R1) to be small (<1ohm), 0.47ohm or 0.22ohm for example. Pick the 2nd resistor (R2) to be 10 - 20ohm range (again, no need to be very precise). Use your multimeter to measure the resistance of the 2nd resistor - most meters will give fairly good measurement on this resistor.

Put the meter in calibration mode - it will display measured resistance + modified current reading.

Put the first resistor on the meter - it should show one reading; Then parallel it with the 2nd resistor - the reading should decline by a little bit: R1 - R1 * R2 / (R1 + R2) = R1 * R1 / (R1 + R2) = R1 / (1 + R2 / R1). Since R2 >> R1, the changes will be dominated by R2, which you have fairly good measurement of.

You just need to adjust the trimmer now to reproduce the expected changes.

This approach is more tedious but works in cases where your equipment is limited, and in 2-wire mode as well - I actually showed that approach a while back.

Now, I just need to code all that into the chip,
================================
https://dannyelectronics.wordpress.com/

dannyf

• Super Contributor
• Posts: 8221
• Country:
Re: A mcu-based milliohm meter
« Reply #36 on: January 23, 2014, 08:45:16 pm »
Quote
1) calibration:

Done!

Now, working on relative / zeroing.
================================
https://dannyelectronics.wordpress.com/

dannyf

• Super Contributor
• Posts: 8221
• Country:
Re: A mcu-based milliohm meter
« Reply #37 on: January 23, 2014, 09:42:18 pm »
Quote
working on relative / zeroing.

Done!

The first picture is the measurement of absolute resistance - 579mohm, between wires + a 470mohm resistor. 278 is the adc reading.

I then zero'd the wire resistance by shorting the leads. and then put on the 470mohm resistor. The same reading of 278 now translates into a 474mohm "relative" reading, just for the resistor - see the 2nd picture.

Next step:

My Leonardo is in so now I just need to implement this on the Leonardo / atmega32U4. After that, I will work on the ESR measurements.

================================
https://dannyelectronics.wordpress.com/

dannyf

• Super Contributor
• Posts: 8221
• Country:
Re: A mcu-based milliohm meter
« Reply #38 on: January 23, 2014, 09:59:00 pm »

Th highest I have seen is actually 1022. Never 1023.
================================
https://dannyelectronics.wordpress.com/

dannyf

• Super Contributor
• Posts: 8221
• Country:
Re: A mcu-based milliohm meter
« Reply #39 on: January 23, 2014, 10:17:02 pm »
The meter defaults to 200x gain.

When the resistance is greater than 1.5ohm (user specified), it switches over to 10x gain automatically.

Range is 2mohm - 40ohm, with 2mohm resolution (<2ohm) and 40mohm resolution for 2ohm or higher.

Accuracy: don't know yet. Likely better than 5% + 10mohm - my experience with avr adc accuracy.
================================
https://dannyelectronics.wordpress.com/

dannyf

• Super Contributor
• Posts: 8221
• Country:
Re: A mcu-based milliohm meter
« Reply #40 on: January 23, 2014, 10:22:43 pm »
Meter behavior:

1) on boot up, the meter tests if the avr is a virgin avr - aka it has no value for charge current calibration in the eeprom. If so, it writes the default value (about 6000ua, representing an avr driving a 800ohm load at 5v Vcc). The meter will display that value briefly.
2) If the calibration key is pressed, the meter goes into calibration.
3) If not, or calibration is done, it starts to measure the resistance. Update speed is about 5x per second.
4) during the measurement phase, user can zero current reading to obtain relative reading any time, by pressing the relative / zero key (the same key as the calibration key actually). When that key is pressed, two measurements are shown on the lcd, v1 and v2 (adc readings accumulators for the two charge cycle).

Calibration:
1) if you pressed the calibration key while powering on the meter, it goes into calibration where you can adjust the charge current while a known resistor is being measured.
2) Press the calibration key in this phase saves the calibration results into eeprom.
3) If no key is pressed, the meter times out and goes into measurement mode with the old calibration result.

================================
https://dannyelectronics.wordpress.com/

dannyf

• Super Contributor
• Posts: 8221
• Country:
Re: A mcu-based milliohm meter
« Reply #41 on: January 23, 2014, 10:26:31 pm »
Parts used:

mcu: Teensy ++ 2.0 (usb1286) now and Leonardo (atmega32u4) in the future.
lcd: hd44780. I used 16x2, driven by a shift register (to be removed in the final version).
resistors: 380ohm x 2 (can be user calibrated. no precision resistors required).
pot: a trimmer (10k. value not critical).
switch / button: 1.
posts: 4.

maybe some capacitors for decoupling.
================================
https://dannyelectronics.wordpress.com/

dannyf

• Super Contributor
• Posts: 8221
• Country:
Re: A mcu-based milliohm meter
« Reply #42 on: November 13, 2014, 01:39:42 am »
I spent sometime rethinking about this project, and decided that I want to shrink it down to a more minimalist approach.

Here is an implementation on an ATTINY85 running the adc at 20x gain.

The principle is the same: apply a current through the dut and measure the voltage drop through the differential adc at 20x. The current through the dut is limited by two resistors (150ohm, picked to limit the current through the pins to less than 20ma).

The output is read through a pwm generator by a voltage meter (or alternatively an amp meter, with a slightly different and simpler circuitry - not shown here).

For a total of 3 resistors + 1 capacitor + 2 optional resistors, you have yourself a milliohm meter.

The current through the dut is about 15ma, using internal 1.1v reference, the adc's resolution is about 50uv (1100mv / 1024 / 20). So the milliohm meter has a resolution of 50uv / 15ma = 3mohm, and a maximum range of 3ohm.

However, as we have only 8-bit pwm available on this particular chip, I am limited to 3ohm / 256 = 10mohm.

Here is the meter measuring a 0.1ohm resistor. As the meter is caliberated to 1ohm/1v, we should expect a reading of 100mv.

================================
https://dannyelectronics.wordpress.com/

The following users thanked this post: sipo75

dannyf

• Super Contributor
• Posts: 8221
• Country:
Re: A mcu-based milliohm meter
« Reply #43 on: November 13, 2014, 01:47:15 am »
How about a test on real resistors?

How about two real resistors? 100mohm x 2 power resistors.

Each measures to 85.8mohm, slightly different from the expected value.

One reason is that the resistors are indeed off. Another is that my software assumes 5v Vcc and my actual Vcc is 4.9v. So I should expect 2% off on the adc side and another 2% off on the pwm side.
================================
https://dannyelectronics.wordpress.com/

dannyf

• Super Contributor
• Posts: 8221
• Country:
Re: A mcu-based milliohm meter
« Reply #44 on: November 13, 2014, 01:50:39 am »
Another test - what about paralleling the two resistors?

I should get 85.8mohm / 2 = 43mohm, right?

I got instead, 48.0mohm - the numbers actually fluctuated between 47.9mohm and 48.0mohm.

Vs. my expected value, the overall error rate is 10%.
================================
https://dannyelectronics.wordpress.com/

dannyf

• Super Contributor
• Posts: 8221
• Country:
Re: A mcu-based milliohm meter
« Reply #45 on: November 13, 2014, 02:01:12 am »
Room for improvement:

1) Better caliberation - this can be done a pot on across the capacitor + a precision resistor; or a serial pot for a coil meter. The 150ohm resistors don't need to be precision resistors at all.

2) Better software - I didn't attempt to null the adc in the software. I would expect that more work can be done there;

3) Better adc - the attiny's adc has a maximum gain of 20x. There are plenty of avrs with 40x, 100x or 200x adc.

4) Better pwm - this particular avr has only 8-bit pwm. 10-bit pwm would offer more display resolution. However, I don't expect that to be more than marginal.

5) External amplifier: Using an instrumentation amplifier (either a real one or a 2-opamp one) would easily increase the gain and provides better resolution on the low end. That can be done with a dual opamp (ne5532 for example) + three resistors.

6) Better topology - a real high precision milliohm meter can be done with an external adc - differential input, differential external reference input, 16 bit or more. Put the dut in serial with the precision resistor. The differential adc across the dut and the differential external reference across the precision resistor. The output is ratiometric to the precision resistor.

Alternatively, you can simply use a low drift resistor in place of the precision resistor and use the precision resistor instead to caliberate the meter.

I thought for a couple dollars, this provides an interesting way to measure low resistance.

BTW, the same approach can be used to measure low voltage too.
================================
https://dannyelectronics.wordpress.com/

dannyf

• Super Contributor
• Posts: 8221
• Country:
Re: A mcu-based milliohm meter
« Reply #46 on: November 13, 2014, 02:03:24 am »
I didn't do this in the test but you should use kelvin clips to minimize wire resistance.
================================
https://dannyelectronics.wordpress.com/

nuno

• Frequent Contributor
• Posts: 606
• Country:
Re: A mcu-based milliohm meter
« Reply #47 on: November 13, 2014, 02:29:39 am »
The gain on the diferential ADC mode is a nominal value, which means you will have a gain error. Best way to calibrate is to do a 2 point measurement (use points near the extremes of your range for best accuracy) and then linearly interpolate on readings (because this system is linear). This will calibrate for "the entire system" parts, from resistor tolerances to gain tolerances Vref tol etc. I usually go directly from the ADC count reading into my desired final value, no need to have other units in between.

I would also use the internal Vref to generate the test current (buffered through an ampop), for its better stability (vs a power rail voltage).
« Last Edit: November 13, 2014, 02:35:02 am by nuno »

dannyf

• Super Contributor
• Posts: 8221
• Country:
Re: A mcu-based milliohm meter
« Reply #48 on: November 13, 2014, 02:44:11 am »
I implemented nulling and put a ghetto kelvin clip in place. Single resistors measure out to be 104.8 - 104.9mohm, very stable.

Paralleling those two resistors yields 51.8 - 53.5mohm mostly.

Pictures are attached:
« Last Edit: November 13, 2014, 02:47:42 am by dannyf »
================================
https://dannyelectronics.wordpress.com/

Vgkid

• Super Contributor
• Posts: 2727
• Country:
Re: A mcu-based milliohm meter
« Reply #49 on: November 13, 2014, 03:06:07 am »