Using an LM358 to amplify the voltage drop of across a sense resistor - Page 1
Forum section: electronics / beginners

author: derGoldstein
author_rank: Regular Contributor
timestamp: May 07, 2017, 11:45:06 pm
content: I'm trying to build a simple ammeter by amplifying the voltage drop across a sense resistor on the low-side of the circuit, and feeding it into the ADC of an MCU (an attiny84 for now). I'm attaching the current-sense part of the circuit. I'm using an LM358 as the op-amp, configured as a 11-times non-inverting amplifier with some noise rejection.Here's the amperage I'm putting through the resistor, the voltage as measured across the resistor, and the output of the attached circuit:0.2A 0.007V 0.068V0.5A 0.04V 0.43V1A 0.094V 1.03V1.5A 0.15V 1.66V2A 0.21V 2.3VSo it's a fairly consistent 11-times output.However, I don't do analog stuff very often, and I know that whenever I do there's some catch that I'm probably not even aware of. Is this a suitable circuit for this particular purpose? I'm not looking to measure spikes, so I'm not concerned about catching sharp increases/decreases. I also know that using this sense resistor value and op-amp voltage I should expect the op-amp to peak at around 4.5V, so I'm capped at measuring around 4A max.Any advice on how to improve the circuit and/or if there's anything I'm missing is appreciated.

author: danadak
author_rank: Super Contributor
timestamp: May 08, 2017, 01:05:24 am
content: You have .1 uF Cload on output of LM358, that's not a good idea forstability reasons due to reduced phase margin. Either reduce it byadding an R from output to cap which helps decouple the C as seen byLM358. R ~ 100 ohms or use spice and take a look at phase marginvs R. Shoot for 45 degrees or better.There is a small offset due to bias current flowing thru unbalanced Zinof the + and - input. ~ 1.5 mV. Newer RRIO OpAmps have lower bias.Also extend unloaded output swing to rail, giving you more range.Also make sure you connect ground end of 10K G setting R close toshunt ground end to mitigate ground drop load current error.Regards, Dana.Regards, Dana.

author: David Hess
author_rank: Super Contributor
timestamp: May 08, 2017, 03:04:52 am
content: Quote from: danadak on May 08, 2017, 01:05:24 amOr use a much larger value of capacitance with some added ESR. A 10uF aluminum electrolytic or solid tantalum capacitor will lower the frequency response so much that the gain will fall below 1 before there is enough phase lag to cause oscillation. The ESR adds phase lead.QuoteNot just newer RRIO operational amplifier have this advantage; improved replacements for the LM358 like the LT1013 and OP290 also have lower input bias current. I have used the LT1006 and OP90 (single amplifier versions) in this exact application before.One thing to watch out for with the LM324/LM358 is that its output cannot sink much current close to ground. Either use a pull down resistor or current sink to help or use an improved operational amplifier which can sink more current close to ground if this is a requirement.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: May 08, 2017, 07:00:27 am
content: 1. Filter the input. Insert a series R or L, and parallel C. (If using L and C, add some ESR to the inductor, so that R = sqrt(L/C).) This prevents RF (sharp changes in load, or ambient noise, or..) from being rectified by the LM358 (which it excels at doing).1a. You have an RC across the amp, which reduces high frequency gain, but doesn't eliminate it: the noninverting configuration has the form 1+ratio, and it's that "one" where the input is fed through, not filtered by C15. The input RC fixes this.1b. The series resistance also decouples the low-impedance shunt resistor from the amp, so accidental surges (shorting, ESD, etc.) won't destroy it. This can be enhanced by adding clamp diodes (e.g., 2 x 1N4148 or 1 x BAV99, from GND to +IN to +5V)2. If you aren't limited on current consumption, consider adding a load (R from OUT to GND, or decreasing the feedback resistor values), so the LM358 output stage stays in class A operation. Yes, it's a class C output stage, and yes, even in slow applications like this, it will make itself known!3. Yeah, nix the FILTER part. C loading is a no-no here. (Again, fix it on the input side!)LM358 will pull down to some 10s of mV, and up to about 3V, in this configuration. If that's enough for your application, then you're great. The suggestion of using a better amp might also be entertained; there's no shortage of good ones to choose from, even in a nearby price range.And if you need reduced power consumption, you can save a lot by using an intentionally slow amp. 5V CMOS op-amps with fT well under 1MHz will run on microamperes!Tim

author: Zero999
author_rank: Super Contributor
timestamp: May 08, 2017, 12:18:59 pm
content: Yes, it's true that a capacitor on the output is a bad idea and will make over/under-shoot and oscillation more likely.To minimise the offset voltage, the input impedance seen by both inputs should be the same. Put a resistor in series with the +input with the same value as R11 & R12 connected in parallel.

author: derGoldstein
author_rank: Regular Contributor
timestamp: May 08, 2017, 01:46:37 pm
content: Thank you for all the feedback!I updated the circuit -- attached.I removed the capacitance on the output, and put an RC on the input to filter it. I used a 10k value on R13 so it's close to the impedance on the negative input. I didn't know what value to use on C16, so I tried a few values and saw that 100nF cleaned up the output.The output is now quite a bit less noisy! I don't have a scope at the moment but I get a much cleaner signal on the ADC and the bar graph on my DMM isn't jumping around anymore.Should I be putting a resistor between the output of the opamp and the ADC? The ADC should always be high-impedance, so putting a resistor in front of it shouldn't effect the op-amp's function, and in case I do something stupid like initialize the IO as digital I'd like the MCU not to blow up.Quote from: David Hess on May 08, 2017, 03:04:52 amI think I'm seeing it when testing lower current. I have to put around 200mA through the sense resistor for the output of the op-amp to get to the 11-times multiplier and stay there. When you say a pull-down resistor, do you mean a resistor from the output of the op-amp to ground? How much should I be letting through?The problem with getting an alternative op amp is that there are thousands of them and I don't know what characteristics I'm looking for.I know I should look for a single-channel, rail-to-rail op amp with a low offset that doesn't need to sink/source much current. I also know that it doesn't have to be high-precision, and doesn't have to be fast, but I have no clue how either of these are measured. When I do a parametric search I'm just staring at parameters I know nothing about...There are also op-amps that are specifically designed for current-sense amplification. Those are a bit easier to understand because the datasheets are very specific about how to design the circuit.

author: w2aew
author_rank: Super Contributor
timestamp: May 08, 2017, 01:58:20 pm
content: Here is some detail on the LM358 output stage, pull-down resistors, and cross-over distortion:

author: Seekonk
author_rank: Super Contributor
timestamp: May 08, 2017, 01:59:46 pm
content: One issue you will have with various opamps is operating so near ground and dealing with offsets. Often designers will add an offset voltage to the input to raise the inputs above ground.

author: David Hess
author_rank: Super Contributor
timestamp: May 08, 2017, 02:27:05 pm
content: Quote from: derGoldstein on May 08, 2017, 01:46:37 pmTo start off with, I would use a pulldown resistor to ground which the operational amplifier can reasonably drive; for the LM358, that is 2.2k although if your output voltage range is low then it can be a lower resistance. That may be sufficient for your application.QuoteUnfortunately most selections guides are not much help here. I gave a couple of examples of improved LM358s like the LT1013 and OP290. The single versions of these are the LT1006 and OP90.Look for a single supply or rail-to-rail input amplifier which has a single supply or rail-to-rail output. The problem with the LM358/LM324 is that its low side emitter follower output can only sink appreciable current down to about 0.6 volts. The designers of the LT1013 and OP290 recognized this is a problem and solved or at least improved the situation. Modern single supply and especially rail-to-rail output amplifiers have common emitter (or CMOS) output stages so they can sink current to within millivolts of the negative supply. There are lots of modern rail-to-rail operational amplifiers these days.There is another way to solve the LM358 output problem which I have used occasionally. An optocoupler which provides access to the base of the output transistor (or has a photodiode output but these are rare) can be used to sink current below the negative supply if the output voltage range is limited. At one point I was grading 4N25s for parts that would sink more than 100 microamps.

author: tecman
author_rank: Frequent Contributor
timestamp: May 08, 2017, 04:47:40 pm
content: Your better option is to configure the op-amp as a differential amplifier. Connect the inputs directly to the resistor. This will greatly reduce the effects of common mode voltage and drops in sense wiring.Paul

author: Zero999
author_rank: Super Contributor
timestamp: May 08, 2017, 04:56:44 pm
content: Quote from: Seekonk on May 08, 2017, 01:59:46 pmThe LM358's inputs will work slightly below negative supply which helps and R12 & R13 will provide some offset, about 450µV, assuming a bias current of 45nA. The resistor values could be increased to add more offset, at the expense of noise and greater inaccuracy due to the offset current.

author: derGoldstein
author_rank: Regular Contributor
timestamp: May 09, 2017, 05:31:53 pm
content: Quote from: tecman on May 08, 2017, 04:47:40 pmI started off trying that, but I kept getting weird results and for some reason simulating it didn't work properly.Here's the latest version of the circuit (attached). Ignore the 4-pin header on the right, it's just a test point. The part count is much higher than I anticipated, but the improvements are worth it.It can track the voltage drop across the resistor down to around 0.003V, but it only becomes practically accurate at around 0.01V. When it gets up to 0.02V it matches the multimeter output quite well, the accuracy seems to be between 5% (at around 0.02V) to 1.5% (0.05V and above). That's fine for now.Is there anything I can do with the spare op-amp on the LM358 that might be useful to either increase stability or accuracy? Otherwise I'll just terminate it.I'll have to look into the dedicated current-sense amplifier chips, they seem cheap enough and are specifically designed for this with very few external components. Some of them even do high-side sensing so I don't have to interrupt the ground.

author: David Hess
author_rank: Super Contributor
timestamp: May 09, 2017, 11:19:33 pm
content: Quote from: derGoldstein on May 09, 2017, 05:31:53 pmOperational amplifiers which have an input range which includes their positive supply can be used for high side current sensing as well. The ancient 301A is one of them but many old JFET input operational amplifiers will work also.I always wished for an NPN input version of the LM324/LM358 single supply design but the 301A is the closest anybody ever got to one.

author: danadak
author_rank: Super Contributor
timestamp: May 10, 2017, 10:59:02 am
content: R1, C16 possible issues -1) R1 takes a voltage OpAmp low output Z and translates it into a relativelyhigh Z which in turn makes the loading affect the voltage read of the OpAmpoutput.2) C16, when power supply is turned off, potentially will discharge thru OpAmpinput base connection of its front end diff amp, may have to contact vendorto see if thats OK. There has been history in industry of some OpAmps thatget damaged from such unwanted current paths.Regards, Dana.

author: MrAl
author_rank: Super Contributor
timestamp: May 10, 2017, 01:14:36 pm
content: Hi,Another thing to watch out for is the power dissipation in the sense resistor.Using a 0.1 ohm resistor at 4 amps will mean 1.6 watts of power dissipation.A 5 watt or even 10 watt resistor might be a good idea, or a resistor made for current sensing even better.These circuits often depend a lot on what kind of accuracy you are looking for. Low accuracy not too specific, high accuracy more attention to detail and parts selection.If you need an output filter, use a resistor and capacitor, take the output from across the capacitor.Beware the size of the resistor between the op amp output and ADC input or between op amp output and output filter capacitor. ADC inputs have high input Z but not so high input R, so a high R series resistor causes more temperature drift in the measurements due to ADC bias current drift.

author: Zero999
author_rank: Super Contributor
timestamp: May 10, 2017, 10:38:14 pm
content: Quote from: danadak on May 10, 2017, 10:59:02 amIndeed, 100k is a heck of a high impedance for the output of an amplifier. What is it supposed to be driving? If it's a long cable which present a capacitive load to the op-amp, then a lower value such as 100R should be used, otherwise it's totally unnecessary.QuoteI thought the LM358 could tolerate its inputs being taken to the IC's maximum rated voltage, irrespective of the supply voltage?http://www.ti.com/lit/ds/symlink/lm158-n.pdf

author: David Hess
author_rank: Super Contributor
timestamp: May 10, 2017, 11:07:29 pm
content: Quote from: Hero999 on May 10, 2017, 10:38:14 pmI think that is the case although I have never taken advantage of it. The PNP transistors used on these old NPN processes have low performance but a high base-emitter breakdown voltage.

author: derGoldstein
author_rank: Regular Contributor
timestamp: May 10, 2017, 11:40:32 pm
content: Quote from: MrAl on May 10, 2017, 01:14:36 pmI'm using one of those 1W current-sense resistors. I'm going to decrease the resistance if I can, and if I can't then I'll put 2 of them in parallel to improve heat dissipation. I'm not expecting more than 5 amps to go across it/them, but I'll of course test and make sure the temperature doesn't get too high.Quote from: MrAl on May 10, 2017, 01:14:36 pmI don't need high accuracy at this point. Even just 5% is ok, I just need to have a rough idea of what's going on.Quote from: MrAl on May 10, 2017, 01:14:36 pmYeah, I'm getting this a lot, I'll reduce the resistance to around 1k. All I want to do is make sure that if I mess something up and setup the ADC pin as a digital IO by accident, that the op amp doesn't kill my MCU.