Designing a resistance measurement algorithm - Page 1
Forum section: electronics / general

author: BorisRap
author_rank: Contributor
timestamp: November 22, 2023, 08:04:38 am
content: Hello, I'm designing a software for an already built hardware.The idea is to measure resistance between two points using a sine wave.Like show in the schematic below, a micro controller will generate a 10Khz (not variable) sine wave with a variable amplitude form 0 to 3.3V. The sine will be feeded through the resistor to measureRxthrough an opamp in inverting configuration and measured again by the micro controller.There is 3 calibration resistors and 3 gain resistors of 100R, 1K and 10K. Each analog switch can be closed independently by the software, they have a unknown resistance of around 2.5 Ohms each, but I think they match closely. The analog switches are ADG714.The reason there are 3 gain resistors is to increase the measuring range as much as possible.The capacitor in the output of the DAC is to eliminate DC bias to the resistor being measured.In a nutshell:-We can change the amplitude of the sine wave-We can select the gain resistor from 3 options-We can use 3 known calibration resistors-We can measure the Vrms of the return sine and the output sine wave-The resistance to measure is unknown from the begging, so we can't make assumptionsPrecision: I don't have in the moment a goal precision for the device, obviously it will be more precise in the range of 2-5K compared to the range of 10-50 Ohms. But the measurements I'm trying to perform are in that range.Anyways the reference and gain resistor values shouldn't change the algorithms underlying logic.I just want to do a software that measures as precise as this hardware can.Do you have any suggestions on how could I do the algorithm to maximize the precision? I'm not asking for any code in particular, just the steps I should do.Switches: ADG714Opamps: AD8604Micro: STM32G071Thank you!

author: guenthert
author_rank: Frequent Contributor
timestamp: November 22, 2023, 08:51:13 am
content: There are of course many ways to skin the cat, but I don't see the motivation to use (sine wave) AC here. The only benefit obvious to me is the elimination of potential errors due to thermal EMF (and the disadvantage of additional errors when measuring WW resistors), but I'm not yet convinced that this set-up will be precise enough for that to matter.An AC drive would be beneficial in a bridge configuration, where the difference in potential in the two arms will be very small. If then signal components not matching the frequency (and phase) of the generator are rejected (perhaps in the digital realm), great sensitivity could be archived, a poor man's lock-in amplifier so to speak. In combination with precision resistors in the bridge this should yield good precision of measurement of the unknown resistor.> I don't have in the moment a goal precision for the deviceWell, I would start with that, actually.

author: BorisRap
author_rank: Contributor
timestamp: November 22, 2023, 09:41:57 am
content: Quote from: guenthert on November 22, 2023, 08:51:13 amThe reason to use a sine wave is because this actually measures the conductivity of solutions, a sine wave is used to prevent electrolysis. I didn't mention it because as long as we stick to the instruction of using a sine wave it doesn't matter if its a liquid or a resistor, the algorithm doesn't change.As I mention, the hardware is already done.The precision doesn't really matter as long is the best possible for the hardware. I'm just asking for ideas on how to use the reference and gain resistors and what math to do to get the best precision for THIS circuit.Thank you

author: miro123
author_rank: Frequent Contributor
timestamp: November 22, 2023, 10:01:54 am
content: Quote from: BorisRap on November 22, 2023, 08:04:38 am10KHz sine is quite challenging to achieve . Good RMS or PP estimation can be achieved for at least of 10 prefferebly 500 times higer sample frequency/100kSps ..5MSps/. Otherwise the digitizing artifact are quite high. Something in 100Hz range is easier to achieve with stm32G0 and DMA - stm32G4xx will make you life easier due to hardware floating point support and separated memory bus for CPU and DMA->periphery.

author: BorisRap
author_rank: Contributor
timestamp: November 22, 2023, 10:07:39 am
content: Quote from: miro123 on November 22, 2023, 10:01:54 amHi, thanks!I the sine generator is already done, it generates a smooth enough wave. It's split in 200 steps, in the oscilloscope it looks just like a real sine wave.Edit: To calculate the RMS I'm sampling at 1MSps, but I'll check into the G4 series, thank youEdit2: Mistake: I ment to say 1MSps

author: MasterT
author_rank: Frequent Contributor
timestamp: November 22, 2023, 03:02:38 pm
content: Limiting factors for precision I see noise & linearity, basicaly same as for any high quality audio adc. I would flip on horizontal axes switches-resistors in the negative feedback, to remove common mode voltage over switches.Selecting right OPA is not easy task, low noise at 10kHz understandable, but also linearity - imply high GBW. And last things it should not be upset by driving aggressive SAR adc, anti-alliasing filter (kick-back reductor) is not an option.Regarding software, Goertzel for 10kHz is the best solution, G4 likely to get 1 msps in real time . RMS value of the sine wave oversampled /averaged by algorith I'd estimate to 1ppm level acuracy on 1 sec time base, 12bits + 10bits oversampled, but linerity of the adc would cut it at the level listed in uCPU DS , -70dBc or so translates into 300 ppm.

author: David Hess
author_rank: Super Contributor
timestamp: November 22, 2023, 03:23:18 pm
content: The capacitive reactance is 1.6 ohms at 10 kHz, so were you planning on making a phase measurement between the DAC/ADC and the ADC? Otherwise this is going to affect the accuracy as the phase shifts with different input resistors selected.It is too bad that you have already made your hardware. Jim Williams published several designs for accurate AC resistance measurement for your application.

author: BorisRap
author_rank: Contributor
timestamp: November 22, 2023, 03:38:55 pm
content: Quote from: David Hess on November 22, 2023, 03:23:18 pmThanks, I wasn't planning on making a phase measurement, I was planning on just measuring the gain of the system. Capturing a bunch of cycles, calculating the RMS of the input and the output and then calculating the gain, after that using the gain to solve for Rx

author: Kleinstein
author_rank: Super Contributor
timestamp: November 22, 2023, 04:02:51 pm
content: 10 kHz is already quite high. An due to the limited GBW of the OP-amp the virtual ground at the inverting input is not accurately at zero. So a lower frequency would be preferred.Another point is the resistance of the switches. As shown this would add to the resistors. For the feedback side the CM voltage would change with the signal and this can effect the resistance.On the other side the inverting input does not like the extra capacitance to ground from the switches and one may need extra capacitors in the feedback.Ideally one would use seprate switches for the current and voltage part. With a more limited range one may get away with fewer resistors, possibly just 1 resistor.For the SW to look at the signal the preferred way is to use some kind of I/Q demodulation. So make use of the known drive signal phase and get separate in phase of quadrature amplitudes. This allow quite good noise and hum suppression. In addition one would also get data on the phase and thus capacitive / inductive component of the impedance. The phase data with the reference resistors would also allow to compensate for phase shifts of the amplifier part.One may not even need to measure the drive amplitude, if the reference resistor is used for comparison. The drive amplitude would be a thing is the ref. resistors are used only infrequent (e.g. daily) and maybe with more manula switching / relays instead of electronic switches.With electrolytic resisance there can be a mit of bulk solution and electrode effects. So ideally one would measure with 4 electrondes to separate the parts.

author: David Hess
author_rank: Super Contributor
timestamp: November 22, 2023, 04:44:52 pm
content: Quote from: BorisRap on November 22, 2023, 03:38:55 pmThe problem as I see it is that the capacitor is adding an error term in the form of phase shift which varies with the input resistor selected, including the resistance being measured. If the first ADC was measuring the output side of the capacitor, then this would not matter.This error term is not great, but I would expect it to limit accuracy unless accounted for. I think this will require making the measurements or calibration at more than one frequency.

author: mawyatt
author_rank: Super Contributor
timestamp: November 22, 2023, 04:45:24 pm
content: Why not commutate the input and op-amp output with a synchronous sampling technique and displace the sine DAC?Best,

author: Kleinstein
author_rank: Super Contributor
timestamp: November 22, 2023, 07:05:27 pm
content: The simple square wave modulation is defintely an option, but would need some extra care with the series capacitor. With the capacitor the resistor no longer sees a simple square wave.The sine wave modulation would also ideally measure the amplitude and phase after the capacitor and can than better / easier correct for the series capacitor.

author: MarkT
author_rank: Frequent Contributor
timestamp: November 22, 2023, 08:53:12 pm
content: Quote from: BorisRap on November 22, 2023, 09:41:57 amWell liquid electrolytes are complicated, not really like normal resistors, be aware what you measure at one frequency and field strength may not apply to other regimes. For instance the conductivity of water is all over the shop between DC and MHz, and not purely resistive.

author: alm
author_rank: Super Contributor
timestamp: November 22, 2023, 09:11:26 pm
content: I think you'll end up building an LCR/impedance meter, regardless of if you plan to or not. So better measure reactance rather than make it an unknown error source.

author: ivo
author_rank: Regular Contributor
timestamp: November 23, 2023, 11:45:10 am
content: Quote from: BorisRap on November 22, 2023, 09:41:57 amThis is the wrong way to go about getting help. People are curious beasts, if you tell them you are doing some strange way of X they must work with when everyone knows Y is much simpler, you know what will happen? Everyone will completely forget about helping you with X, and instead wonder curiously why you aren't going with Y. It tends to work out especially badly for people who refuse to reveal the context around a question or situation to help align potential helpers with their goals, reasonings and limitations. Knowing why such a situation came about can even put someone in a much better mindset and frame of reference to help answer a question, than just having to do it 'out of thin air, as an academic exercise'.Using a sine wave to measure as alm said looks like you'll likely get the most use out of doing a 2D measurement, i.e getting complex reactance/impedance, just as what a proper LCR would do. Pure resistance just ends up being the horizontal component pulled out of that plane. Dave has a video or two that lightly details what they do to measure a bit of kit, responding to voltage vs current. Search 'complex impedance' on youtube and you should get a bunch of videos referring to the topic.

author: MK
author_rank: Regular Contributor
timestamp: November 24, 2023, 10:00:20 am
content: One product I worked on a while ago measured the ac impedance of a liquid, and its sensitivity was initially ruined by the tempco of capacitance of the coax used to take the signal to the liquid. In the end they had to used a polythene/air gapped coax, that may bite you later in your journey to make it work. We also had to keep each liquid sample at a steady temperature +- 0.001C.

author: Kleinstein
author_rank: Super Contributor
timestamp: November 24, 2023, 12:01:45 pm
content: The way the circuit is done, the capacitance of the cables does not matter much. It is only that if the capacitance gets too large (e.g. long cable) the TIA part may become unstable an oscillate.

author: GigaJoe
author_rank: Frequent Contributor
timestamp: December 04, 2023, 04:37:28 pm
content: measure , my 2 silly cents:in the end we need to measure amplification coefficient. soo ... the coefficient is the proportion between in and out signals ...so .. if we get a differential amplifier , feed in and out, - then we get an output signal corresponding to the coefficient value.then , I guess it doesn't matter , in overall , it RMS , or averaging, or P-P , we need convert it in DC, let say AD637, and measure DC, in the end. or , use P-P detector, measure peak of 10 wave forms, reset it , and average the accumulated value, for a second or so ...it can be simplified as an addendum unit to connect to any multimeter, measure AC, for example, with logging, LXI , you name it ...