dumb opamp circuit problem - Page 1
Forum section: electronics / beginners

author: gardner
author_rank: Regular Contributor
timestamp: August 14, 2016, 03:39:05 am
content: I am designing an op-amp circuit to map the voltage of a 12V lead acid battery to a voltage level suitable for an ATMEGA ADC. The useful range of battery voltage is ~10V to ~16V. I'm using a TI LM4040 4.096V shunt reference to power the circuit and to provide the voltage reference for the ADC.I am terrible at working out op-amp circuits, so I modeled the whole thing in LTSpice and dicked around with the dividers to find a set of E12 resistors that work. The circuit looks like this. The spice model does exactly what I want and all is well.When I built the circuit with a Microchip MCP602 it just didn't work. The output voltage wouldn't come close to the supply rail. Excuse the signal quality of my ramp generator, but this what I see. At vBat ~= 13.5 the vADC peaks at ~2.2VAfter flailing around quite a bit, I decided to try a different amp. I switched to an ST TS922 and now it works exactly as the spice model says it should. My ramp generator only goes from 10V to 15V, but the vADC goes to 3.9V and does reach basically to the + rail at a shade over 16V.I'd prefer to use the MCP602 amp since its current requirement is lower. I want this battery sense amplifier can be run using a digital output of the MCU directly to power it. The TS922 version of the circuit needs ~3mA on the shunt regulator to avoid dropping out, which might be a little much for my GPIO to source.Does anyone have any insight why the MCP602 won't work in this circuit but the TS922 will?

author: bobaruni
author_rank: Regular Contributor
timestamp: August 14, 2016, 04:43:18 am
content: While the MCP601 has rail to rail output, the Input common mode input range is VDD minus 1.2v, so if running the chip on 4.096V, the +Input will saturate after reaching 4.096-1.2 = 2.896V.If you limit the voltage on the + Input of the op-amp by changing your divider from the battery and increase the gain to compensate (and probably fiddle with the bias), it should work.I would also put a bit of capacitance on the + Input (across R8) to limit the effects of noise on the battery

author: rob77
author_rank: Super Contributor
timestamp: August 14, 2016, 07:44:48 am
content: powering the buffer opamp from the reference for the ADC is not a great solution. why not to use 5V regulator for the opamp + ADC and use the 4.096V reference as a reference only ?

author: rstofer
author_rank: Super Contributor
timestamp: August 14, 2016, 03:29:01 pm
content: Everything you need to know about offset and scaling with a single supply op amp is covered in Chapter 4 of Op Amps For Everyone:http://web.mit.edu/6.101/www/reference/op_amps_everyone.pdfI think you will find exactly what you are looking for because I did the very same battery exercise some years ago for a battery powered boat.

author: bson
author_rank: Unknown
timestamp: August 14, 2016, 08:43:37 pm
content: What do you need the op amp for? A divider will scale the voltage, so if you just want to monitor a battery for a product I wouldn't bother with the op amp. The op amp is necessary if you need fast sampling, but how rapidly will a 12V battery change?

author: rstofer
author_rank: Super Contributor
timestamp: August 14, 2016, 08:53:51 pm
content: Quote from: bson on August 14, 2016, 08:43:37 pmThe op amp is used to expand (or in this case shrink) the scale around the region of interest. The OP is interested in the region between 10V and 16V so one possible translation would have 10V register as 0V on the ADC and 16V register as 5V (assuming 5V ADC). So, the requirement would be to offset by 10V (leaving 0..6V) and then scaling by 5/6 (5 volts span represents 6V span on battery).Since this can all be represented by the equation y=mx+b it is pretty easy to solve with 4 resistors and an op amp. In this case b=-10 and m=5/6. Feed in a battery voltage 'x' and get an offset and scaled value for 'y'.It's all laid out in Chapter 4...ETA: If the battery voltage isn't scaled and offset, a huge portion of the ADC resolution is wasted.

author: gardner
author_rank: Regular Contributor
timestamp: August 14, 2016, 09:50:52 pm
content: Quote from: bobaruni on August 14, 2016, 04:43:18 amThank you! I'd totally missed that in the datasheet.If I change the + supply of the amp to the 5V logic level and re-jig the feedback network I have this, which works in LTSpice.

author: gardner
author_rank: Regular Contributor
timestamp: August 14, 2016, 10:44:35 pm
content: Quote from: rstofer on August 14, 2016, 08:53:51 pmYes. Section 4.3.1 looks like a good bet.Thanks.

author: gardner
author_rank: Regular Contributor
timestamp: August 15, 2016, 12:07:24 am
content: Quote from: bson on August 14, 2016, 08:43:37 pmAs rstofer mentioned, the intent is to concentrate the usable resolution of the ADC on the range of voltages that are meaningful. With a simple divider 80% of the ADC range is wasted and the resolution in the "interesting" range is needlessly limited.With a 6-cell (nominally 12 volt) flooded lead acid battery the lowest interesting voltage is about 10.5V -- this would be the point of total discharge while under a non-trivial load. On the upper end 15.5V to 15.75V would be the voltage used for an equalization charge. Things shift by another volt or so as temperature varies between -25C to +30C.This solution is intended to replace one where I am using a simple zener drop on the high side to put the useful voltage range into the range of the ADC. This has a bunch of problems with the temperature coefficient of the 10V zener and the dynamic resistance of the zener in the measured voltage ranges. Compensating for these is a PITA. The resulting accuracy is not so bad, but it is not good enough for my needs going forward.

author: gardner
author_rank: Regular Contributor
timestamp: August 16, 2016, 04:40:44 am
content: Success. Thanks for your help.This is now with the original MCP602 and does what I need.

author: Brutte
author_rank: Frequent Contributor
timestamp: August 16, 2016, 08:24:09 am
content: Quote from: gardner on August 14, 2016, 03:39:05 amDon't load reference this way as that defies its purpose.Use some LDO for power ripple rejection (mA) and reference for reference only (uA).QuoteThe IO of uC is tied to its core supply voltage in AVRs and it jumps up and down like crazy.for that concept.

author: bobaruni
author_rank: Regular Contributor
timestamp: August 16, 2016, 01:37:47 pm
content: QuoteWhile it's true that that's not the intended purpose for such an accurate reference, the use of it in this way will work just fine.The reference after all just acts like an accurate and well compensated Zener diode in a shunt regulator and that's fine in this circuit as the MCP602 draws very little current.

author: gardner
author_rank: Regular Contributor
timestamp: August 16, 2016, 05:28:37 pm
content: In order to get the headroom I needed on the common mode input range, I switched the amp's supply to the 5V logic supply -- but this would be the GPIO pin powering the circuit. The MCP602 is a low power device and since it doesn't have to be powered from the reference rail I can drop the reference shunt current to ~500uA and the whole power budget is ~1.5mA. The current requirements are well within what I can source out of a GPIO.But the potential noisiness of the GPIO as a supply rail is a concern. The shunt reference will reject the noise reasonably well, but the MCP602 might not have enough supply noise immunity to yield overall noise immunity. I can't have too much bypass capacitance on this GPIO driven rail for fear of overloading the GPIO.I can add an external switch, but it would have to be on the high side since any voltage drop or random resistance to ground would mess the whole thing up. Maybe a 2n3906. It is getting complicated and the power savings of switching it off is fairly negligible, so maybe just leaving it running all the time would be fine.Keep in mind that the ADC is only 10 bits with a least one LSB of uncertainty. The digitization precision of the whole setup will be +/-4mV (+/-6mV of Vbatt) at the absolute most optimistic, even with some oversampling and other software shenanigans. The goal of all this compared to what I had before is not super-high precision, but rather temperature stability and linearity. If the actual accuracy is ~+/25mV I will be in great shape.I would be interested in whether there are obvious sources of temperature instability. The shunt reference is temperature stable to 150ppm/C or 0.8% down to -25C. The resistors are all the same type and if their tempcos are similar, I should be alright. But that's ~25mV of uncertainty right there.

author: StillTrying
author_rank: Super Contributor
timestamp: August 16, 2016, 06:12:10 pm
content: Notice how these rail 2 rail op amps have a step in the middle.

author: gardner
author_rank: Regular Contributor
timestamp: August 16, 2016, 07:00:03 pm
content: The step is in my ramp generator, which is one of those crappy miniDDS FS085 jobbers.http://www.jyetech.com/Products/085/e08503K.phpThere is a serious problem with the DAC in this one I think. Maybe I will have a crack at fixing it, but I have no real concern for all I use it.The two traces in this screenshot are vbatt which is ramping from ~16V down to ~9.5V (channel 1, yellow) and the vADC (channel 2, blue) ramping from 4.096V (vref) to 0V.EDIT:I just looked at the schematic and the DAC on this is an R/2R network built out of 5% parts -- I'm probably lucky it works as well as it does.

author: suicidaleggroll
author_rank: Super Contributor
timestamp: August 16, 2016, 07:30:37 pm
content: Quote from: gardner on August 16, 2016, 05:28:37 pmYour math here shows why the op-amp is unnecessary. You claimed earlier that you needed to maximize the usable range of the ADC, but you don't, in fact you have more than enough resolution with a simple voltage divider given your target accuracy and reference stability.IMO an op-amp is overkill for this, but if you insist on using one, make sure you factor in the offset voltage and bias current and their temperature dependence when calculating your error budget, as well as the tolerance and temperature stability of the feedback resistors used to set the op-amp's offset and gain. You may find it's doing more harm than good.

author: gardner
author_rank: Regular Contributor
timestamp: August 16, 2016, 08:38:09 pm
content: Without the amplifier two LSBs on the ADC is ~30mV vs ~12mV with the amplifier. So the big gain is on the absolute magnitude of the quantization error.Either way around, the voltage reference is going to throw in ~25mV over -25C - 20C.According to the specs the offset voltage drift with temperature is ~120uV over -25C -- 20C and since the gain is only 1.5 I don't think this is going to kill me.Resistor tempcos are a thing either way around, but -- and this goes back to "I am not 100% clear I get opamps" -- I believe that the resistors in either case are principally functioning as voltage dividers, such that as long as they all have the same approximate tempco, the variations will self compensate to a large degree. In any event I have metal film jobs that are at least consistent.I do recognize that this is all being totally overanalyzed, but it gives me something to do.