Author Topic: Using an LM358 to amplify the voltage drop of across a sense resistor  (Read 14344 times)

0 Members and 1 Guest are viewing this topic.

Offline derGoldsteinTopic starter

  • Regular Contributor
  • *
  • Posts: 149
  • Country: il
    • RapidFlux
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.068V
0.5A    0.04V      0.43V
1A       0.094V    1.03V
1.5A    0.15V      1.66V
2A       0.21V      2.3V

So 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.
 

Offline danadak

  • Super Contributor
  • ***
  • Posts: 1875
  • Country: us
  • Reactor Operator SSN-583, Retired EE
You have .1 uF Cload on output of LM358, that's not a good idea for
stability reasons due to reduced phase margin. Either reduce it by
adding an R from output to cap which helps decouple the C as seen by
LM358. R ~ 100 ohms or use spice and take a look at phase margin
vs R. Shoot for 45 degrees or better.

There is a small offset due to bias current flowing thru unbalanced Zin
of 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 to
shunt ground end to mitigate ground drop load current error.


Regards, Dana.

Regards, Dana.
Love Cypress PSOC, ATTiny, Bit Slice, OpAmps, Oscilloscopes, and Analog Gurus like Pease, Miller, Widlar, Dobkin, obsessed with being an engineer
 
The following users thanked this post: derGoldstein

Offline David Hess

  • Super Contributor
  • ***
  • Posts: 16622
  • Country: us
  • DavidH
You have .1 uF Cload on output of LM358, that's not a good idea for
stability reasons due to reduced phase margin. Either reduce it by
adding an R from output to cap which helps decouple the C as seen by
LM358. R ~ 100 ohms or use spice and take a look at phase margin
vs R. Shoot for 45 degrees or better.

Or 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.

Quote
There is a small offset due to bias current flowing thru unbalanced Zin
of the + and - input. ~ 1.5 mV. Newer RRIO OpAmps have lower bias.
Also extend unloaded output swing to rail, giving you more range.

Not 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.
 
The following users thanked this post: derGoldstein

Online T3sl4co1l

  • Super Contributor
  • ***
  • Posts: 21698
  • Country: us
  • Expert, Analog Electronics, PCB Layout, EMC
    • Seven Transistor Labs
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
Seven Transistor Labs, LLC
Electronic design, from concept to prototype.
Bringing a project to life?  Send me a message!
 
The following users thanked this post: derGoldstein

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19532
  • Country: gb
  • 0999
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.
 
The following users thanked this post: derGoldstein

Offline derGoldsteinTopic starter

  • Regular Contributor
  • *
  • Posts: 149
  • Country: il
    • RapidFlux
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.

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.

I 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.
 

Offline w2aew

  • Super Contributor
  • ***
  • Posts: 1780
  • Country: us
  • I usTa cuDnt speL enjinere, noW I aR wuN
    • My YouTube Channel
Here is some detail on the LM358 output stage, pull-down resistors, and cross-over distortion:

YouTube channel: https://www.youtube.com/w2aew
FAE for Tektronix
Technical Coordinator for the ARRL Northern NJ Section
 
The following users thanked this post: SkyMaster, derGoldstein

Offline Seekonk

  • Super Contributor
  • ***
  • Posts: 1938
  • Country: us
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.
 
The following users thanked this post: derGoldstein

Offline David Hess

  • Super Contributor
  • ***
  • Posts: 16622
  • Country: us
  • DavidH
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.

I 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?

To 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.

Quote
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.

Unfortunately 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.
 
The following users thanked this post: derGoldstein

Offline tecman

  • Frequent Contributor
  • **
  • Posts: 444
  • Country: us
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

 
The following users thanked this post: derGoldstein

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19532
  • Country: gb
  • 0999
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.
The 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.
 
The following users thanked this post: derGoldstein

Offline derGoldsteinTopic starter

  • Regular Contributor
  • *
  • Posts: 149
  • Country: il
    • RapidFlux
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.

I 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.
 

Offline David Hess

  • Super Contributor
  • ***
  • Posts: 16622
  • Country: us
  • DavidH
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.

Operational 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.
 
The following users thanked this post: derGoldstein

Offline danadak

  • Super Contributor
  • ***
  • Posts: 1875
  • Country: us
  • Reactor Operator SSN-583, Retired EE
R1, C16 possible issues -

1) R1 takes a voltage OpAmp low output Z and translates it into a relatively
high  Z which in turn makes the loading affect the voltage read of the OpAmp
output.

2) C16, when power supply is turned off, potentially will discharge thru OpAmp
input base connection of its front end diff amp, may have to contact vendor
to see if thats OK. There has been history in industry of some OpAmps that
get damaged from such unwanted current paths.


Regards, Dana.
Love Cypress PSOC, ATTiny, Bit Slice, OpAmps, Oscilloscopes, and Analog Gurus like Pease, Miller, Widlar, Dobkin, obsessed with being an engineer
 
The following users thanked this post: derGoldstein

Offline MrAl

  • Super Contributor
  • ***
  • Posts: 1444
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.
 
The following users thanked this post: derGoldstein

Online Zero999

  • Super Contributor
  • ***
  • Posts: 19532
  • Country: gb
  • 0999
R1, C16 possible issues -

1) R1 takes a voltage OpAmp low output Z and translates it into a relatively
high  Z which in turn makes the loading affect the voltage read of the OpAmp
output.
Indeed, 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.

Quote
2) C16, when power supply is turned off, potentially will discharge thru OpAmp
input base connection of its front end diff amp, may have to contact vendor
to see if thats OK. There has been history in industry of some OpAmps that
get damaged from such unwanted current paths.
I 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
 
The following users thanked this post: derGoldstein

Offline David Hess

  • Super Contributor
  • ***
  • Posts: 16622
  • Country: us
  • DavidH
I 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

I 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.
 
The following users thanked this post: derGoldstein

Offline derGoldsteinTopic starter

  • Regular Contributor
  • *
  • Posts: 149
  • Country: il
    • RapidFlux
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.

I'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.

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.

I 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.

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.

Yeah, 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.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf