Voltage Difference Detector (>100mV) from two different sources. - Page 1
Forum section: electronics / beginners

author: hgg
author_rank: Frequent Contributor
timestamp: February 23, 2014, 06:03:03 pm
content: Hi,I am trying to build a little circuit that will detect a voltage difference that is greater than 100mVbetween any two batteries. I though it would be easy but it turns out to be more complicatedthan the project it will be used in...I am using an opamp (lm358n) in its differential amplification setup in order to find the differenceof the voltages applied on its inverting and non inverting inputs. I have built a little split supplycircuit which powers the opamp with Vcc+ and Vcc-I am also using a custom voltage reference of 100mV with a 3.0V reference transistor and aadjustable voltage divider.I will be comparing the 100mV reference with the output of the differential opamp.So far so good. Everything works fine, but,The problem is that the difference of the two sources could be either positive or negative,depending on which opamp terminal you have connected the higher voltage source.(I discovered that afterwards... that's why I've also built a split supply circuit.)So my question is:Is there an electronics configuration equivalent to the mathematics ABS(x) function?.Or even better is there a way to do the same thing by powering the opamp with a single supply?I have found the following solution but it uses two more op-amps (!) and a diode.http://www.ti.com/lit/an/sboa068/sboa068.pdfOne of the authors is David Jones... Synonymy?Thanks.

author: hgg
author_rank: Frequent Contributor
timestamp: February 23, 2014, 07:47:41 pm
content: Ok,To answer my own question... it seems that there is no easy way around that problem.A possible solution is the following IC from Analog Devices :http://www.analog.com/library/analogdialogue/archives/44-04/absolute.htmlhttp://www.analog.com/static/imported-files/data_sheets/AD8276_8277.pdfSo I would need the AD8276 to take the difference, then the AD8277 to take the absolutevalue and finally a comparator to compare the result with a reference! All these just tocheck an absolute voltage difference.Arduino...

author: joe912
author_rank: Newbie
timestamp: February 23, 2014, 08:56:30 pm
content: I see two ways to easily do it off the top of my head.1. Do as you said but with two differential amplifiers. One battery to the inverting input and one to the non-inverting inupt. And on the other opamp reverse the inputs. Take the outputs of both the amplifiers and feed them to seperate 100mV comparators and take those outputs to an OR gate.2. Use a differential amplifier but shift the ground reference of the non-inverting side up to some voltage, say 1.0V. This should give you an output of 1.0V + voltage difference. Take the output of that amplifier and feed it into a windowed comparator set at .9V and 1.1V. Seehttp://www.st.com/st-web-ui/static/active/en/resource/technical/document/application_note/DM00050759.pdfsection 6.

author: hgg
author_rank: Frequent Contributor
timestamp: February 23, 2014, 09:32:02 pm
content: Hi,Thanks for your suggestions.Solution 1 uses too many parts as well as the one with the absolute value double op amps.I like the second solution better. I was trying to do something like that but I was not sureabout the "shifting the ground" part. I assume that I will be able to use a single supply inthis way, correct?Can you explain a bit more on how to shift the ground up? Shall I use a voltage dividerand connect its output to the non inverting terminal as well, leaving R4 in place?(Node of R2 and R4 in the graph below?)Thank you!

author: joe912
author_rank: Newbie
timestamp: February 23, 2014, 10:03:24 pm
content: Take the ground pin of R4 and tie it to 1.0V.I found this appnote from TI that talks about it too.http://www.ti.com/lit/an/sboa038/sboa038.pdf

author: hgg
author_rank: Frequent Contributor
timestamp: February 23, 2014, 10:08:32 pm
content: I see, ok thanks.I will try it.

author: hgg
author_rank: Frequent Contributor
timestamp: February 24, 2014, 10:33:50 am
content: Almost impossible to build with any reasonable accuracy for the 100mV range.I cannot use a resistor divider to lift the ground because my supply will be a batteryand will range from 8.2V down to 6V.I've tried to use the output from the 3V reference transistor so I can lift it up to 3V.I've connected the ground pin of R4 to the collector of the 3V reference but the 3Vbecomes 2.770V and it is no longer stable when I change the supply voltage.It changes about 30mV for the full range (8.2-6.0V)No simple solution in the horizon.Any other ideas?

author: AlfBaz
author_rank: Super Contributor
timestamp: February 24, 2014, 10:38:36 am
content: Is a bipolar supply out of the question?

author: hgg
author_rank: Frequent Contributor
timestamp: February 24, 2014, 10:44:14 am
content: It will be a portable device so I would prefer to avoid including a split rail supply because mostof them divide the voltage in half.Do you have any easy solution with a split rail supply? Just curious...

author: AlfBaz
author_rank: Super Contributor
timestamp: February 24, 2014, 12:12:17 pm
content: Sorry just read the thread properly, thought you were having a problem of driving near zero

author: AlfBaz
author_rank: Super Contributor
timestamp: February 25, 2014, 03:55:35 am
content: I messed around a little with your circuit idea and come up with the attached.Don't know if its got to many parts for your requirement but thought I'd give it a shot. Criticisms welcome as I am by no means an expertV1 is the power supply and varying it from 8.2 to 6V still produces the desired outputV3 represents the differential voltage you are trying to discriminate and here it goes from -200mV to +200mV over 200ms.U1 is the differential amp performing the subtraction and its "ground" reference is lifted to 1/2 the power supply by U3 which is used to provide a "lowish" impedance "ground"U2 is the closest reference I could find in LTspice to your 3V ref so R8, R6, R5 and R10 will need to be modified to suit your ref voltage. R6 and R5 should be trimmers so you can adjust the "trip" points."out" is where the final output is at. It is high when the input voltage is within the tolerances and low when outside of them.Also attached is the LTSpice asc file, just delete .txt off the endThe attached waveforms are all measured with reference to VG, the "virtual ground" created by U3. The output wave form is referenced to actual groundIt's just the basics in that I haven't fully stress tested it so I don't know how stable it is or if excessive currents exist in certain parts under certain conditions

author: hgg
author_rank: Frequent Contributor
timestamp: February 25, 2014, 07:53:57 am
content: Hi,Thank you for taking the time to find a solution. I will try the circuit on breadboard. I don'tlike simulators. Many things can go wrong...It looks like that in this version of the circuit I would have to use a lower value referencevoltage, something like 1.5V because its connected to virtual ground which has been liftedto half the supply. Near to 3V in the case of low battery.What is the purpose of D1 and D2 at the output node?Thanks.

author: AlfBaz
author_rank: Super Contributor
timestamp: February 25, 2014, 08:46:27 am
content: Quote from: hgg on February 25, 2014, 07:53:57 amWithout them if one of the op-amps is driving low and the other driving high, as is the case when one of the thresholds have been passed, you have a short circuit.PSLet us know how it bread boards

author: AlfBaz
author_rank: Super Contributor
timestamp: February 25, 2014, 08:52:43 am
content: Quote from: hgg on February 25, 2014, 07:53:57 amGiven the predicted input and output swings are very small in comparison to the voltage supply range you may be able to get away with biasing the virtual ground point closer to 0V, giving you the head room your ref needs.For example changing R12 to 50k will give you a VG of just over a volt

author: hgg
author_rank: Frequent Contributor
timestamp: February 25, 2014, 09:32:11 am
content: QuoteIndeed...I will try it and report back the results.Thank you.

author: hgg
author_rank: Frequent Contributor
timestamp: February 28, 2014, 05:40:16 pm
content: The results are that I've managed somehow to kill the reference voltage transistor I had...LP2950CZ 3.0VThe output was quite unstable until I used a 1uF input and a 10uF output coupling capacitors.After that the output was rock solid at 3.001V with loads up to 10mA. To test it I was poweringanother small circuit (with no capacitors. only a jfet and a couple of LEDs). I am not sure howI fried it. From 4V to 6V it continues to regulate properly but after 7V its output increasesproportionally. I guess that is a sign of a broken reference, correct?Maybe I forgot to discharge the capacitors, I don't know.What is the best way to protect a voltage reference?Shall I put a protection diode from its output to its input?Thanks.

author: hgg
author_rank: Frequent Contributor
timestamp: March 01, 2014, 04:39:31 pm
content: Hi,I have replaced the reference voltage and the circuit almost works...(I am using the circuit from Alfbaz, reply#10. Virtual ground is produced by U3,and Ref+ and Ref- values are measured from Th+, Th- relative to ground.I am using the LP2950CZ 3.0V reference which has an input, an output and a ground pin.Input is connected straight to Vcc (no R7 like in the schematic) and the ground to thevirtual ground from U3. I have also decoupled the output pin of the reference with acapacitor to ground. I tried the virtual ground as well but I get the same problem)While the 3V reference voltage, the virtual ground and the Ref +100mV voltages are pretty stable,the Ref -100mV is not! It changes in a linear way from 7V to 12V.I cannot find the reason.Can somebody please help?I have made a plot with all the measured voltages that shows the problem better.The circuit works accurately only with the input voltage it was calibrated on. By calibration I mean the3V reference resistor divider that produces +100mV and -100mV above and below to the virtual ground.From the graph you can see that the Ref+ is parallel and equidistant to Virtual Ground which meansthat is always correct no matter the input voltage Vcc. The problem is with Ref- that changes withrespect to Virtual ground!The plotted line on the left graph should have been astraighthorizontal line...Can you please help me solve the puzzle?

author: tszaboo
author_rank: Super Contributor
timestamp: March 01, 2014, 11:08:41 pm
content: Quote from: AlfBaz on February 25, 2014, 03:55:35 amI really wonder why you use opamps as comparators, while there are comparators. There is even the LM392 if you want to solve it with 80's technology.

author: AlfBaz
author_rank: Super Contributor
timestamp: March 01, 2014, 11:58:50 pm
content: Quote from: NANDBlog on March 01, 2014, 11:08:41 pmused the op-amps out of pure laziness. The circuit was meant as proof of concept rather than a final design and as is evident from Hgg's results the circuit seems to have fundamental flawsI think the problem is voltage from the 3V ref to Vg is relatively fixed but from Vg to ground its changing proportionally to the supply as U3's output is dependent on it's input divider supplied from Vcc

author: AlfBaz
author_rank: Super Contributor
timestamp: March 02, 2014, 06:29:56 am
content: Quote from: hgg on March 01, 2014, 04:39:31 pmDoes this mean you now have 2 refs?If so, another hack to the circuit that should work is placing the second 3V ref as an input to U3. This will steady Vg regardless of Vcc's variation and give th- a decent reference.You may even be able to do away with U3 altogether as I can't imagine the current drawn from this second reference to be any more than a couple of milliamps.One problem you may re-encounter is as Vcc drops you may not have enough voltage drop across the reference feeding the divider. The data sheet for your device gives a worse case required difference of 600mV at 100mA load current so it may be a lot less in this case

author: hgg
author_rank: Frequent Contributor
timestamp: March 02, 2014, 06:48:22 am
content: QuoteAlfbaz, you will not believe it, but I just woke up with the exact same solution!A good night sleep always helps!The graph helped me to find the problem. A single reference will provide a regulated Vref+ and whenpassed through U3 a regulated Vgnd as well. At least in theory. I will try it in a while. Breakfast time...Thanks again!NANDBlogthank you as well. I will use comparators in the final stage of course.

author: hgg
author_rank: Frequent Contributor
timestamp: March 02, 2014, 07:32:52 am
content: What I thought was to use the single reference that I had for both Vcc and Vgnd but itdoesn't work that way... Just tried it.Does this mean you now have 2 refs?[I had just one. You are right though, I will have to use two different references because they will beusing different grounds. I am not using shunt references but a 3V 100mA LDO so loading wouldnot be a problem I think.It becomes apparent why a precise multimeter is a must for electronics design.The UT61E is not bad actually, but now I want more precision!

author: AlfBaz
author_rank: Super Contributor
timestamp: March 02, 2014, 08:05:43 am
content: Quote from: hgg on March 02, 2014, 07:32:52 amLOL, I have this urge to issue the mandatory warning about getting into precision.. Once you start...

author: hgg
author_rank: Frequent Contributor
timestamp: March 02, 2014, 08:42:32 am
content: Indeed!The more you get involved in design the more you become a precision junky.There are however natural barriers that will stop you. Like the astronomical prices of thevery precise multimeters...For the virtual ground reference I think I will use the LM285Z-2.5 reference diode.In the datasheet it says that it has a 0.6R dynamic impedance. Does this meanthat I can bypass the opamp buffer and use it directly as a virtual ground?(I am trying to build the circuit with the least parts as you can see...)

author: AlfBaz
author_rank: Super Contributor
timestamp: March 02, 2014, 09:49:54 am
content: Quote from: hgg on March 02, 2014, 08:42:32 amThat part there can handle up to 20mA and I cant see a situation where the load for it will be anywhere near that, so yeah I can't see why you cant do away with the buffer

author: hgg
author_rank: Frequent Contributor
timestamp: March 02, 2014, 09:59:27 am
content: Great! I will order some of them next week and try again.Thank you!

author: hgg
author_rank: Frequent Contributor
timestamp: March 03, 2014, 04:06:15 pm
content: While waiting for the voltage references to arrive....In the datasheet of the LM311 there is a way to balance its voltage offset error. If you can use thismethod and instead of balancing it, you make it higher up to 100mV then you can connect the twoinput voltages and there you go! You have a voltage difference detector with just one part.A dual comparator.One voltage to one comparator and the other voltage to the other but with itsterminals reversed.Both voltages to both comparators but with their terminals reversed.One problem though. I cannot achieve an out of balance voltage greater than 30mV....The potentiometers with the closest values I had where 1K and 10K. The diagram uses a 3K.Do you think that this might be the reason?Do you know what is the maximum offset correction that the LM311 can take?

author: hgg
author_rank: Frequent Contributor
timestamp: March 07, 2014, 06:41:46 pm
content: I've tried, but its quite difficult to do it with only the offset error of the LM311.Anyway, the 2.5V vref arrived and lifting the ground as well with a voltage reference did it.Perfect rock solid +/- 100mV voltage difference detection!Thank you guys for your help!