High side current sense using differential opamp - Page 1
Forum section: electronics / beginners

author: npelov
author_rank: Frequent Contributor
timestamp: June 20, 2018, 03:56:15 pm
content: I have differential opamp (1/4 LM324) measuring the current through 8 ohm load (R6) via high side shunt (R1). I started with higher values (I think 3.9k and 15k) of the resistors but I've got 0.6V output offset. I tried to calculate what caused the output offset:Iofs max = 100 nA * 15k = 1.5mVVofs max = 3mVtotal offset 4.5mV * gain 4 = 18mV - doesn't match the 600mV.I lowered the values to 750 ohms and 3k, but then I got even higher output voltage without any thing on the input ~ 800mV.I know that input has to be (V+) - 2V, that's why I can't have gain more than 4. With gain of 4 R4 and R5 make divider (by 5) that leaves the In+ 12/5 = 2.4V below V+. minimum voltage should be 3.35*3 = 10.05V, so In+ will be (V+)-2.01V. Since output won't go below 0V the same is true for In-.To measure without current I disconnect R6 (the load) from ground, leaving the shunt connected to V+Is there anything I'm missing or I killed the opamp somehow.More info:The other 3/4 of the opamp work just fine. I measure battery voltages of 3 cell li-ion battery with gain = 0.5. I measured the voltage directly on their inputs - it's 0.5 to 1.5 mV. However the 4-th amp shows difference 165 mV (last measurement) on it's inputs. 10V on the positive and 10.165V on the negative input. The supply voltage is currently 12.5VWith this setup the opamp has to sink 12.5V/3750 ohm = 3.3mA. That's not too high. Minimum sink capability is 10mA. Well in some cases minimum is 5mA, but 3.3 is lower than that.

author: npelov
author_rank: Frequent Contributor
timestamp: June 20, 2018, 05:46:57 pm
content: Update: Same setup works on low side shunt. Why does it have problem with high side? I tried gain = 1 so the inputs are in the middle of supply voltage and I still get high offset with no current flowing. I also tried another opamp (LM358) - same results.P.S. I messed up the gain calculation. with 3k and 750 it's 3000/750 = 4, (not 5)

author: StillTrying
author_rank: Super Contributor
timestamp: June 20, 2018, 09:57:57 pm
content: "I lowered the values to 750 ohms and 3k, but then I got even higher output voltage without any thing on the input ~ 800mV."That's what the data sheet says, when sinking 3.3mA the minimum voltage the output can go down to is about 0.8V.

author: npelov
author_rank: Frequent Contributor
timestamp: June 20, 2018, 10:09:48 pm
content: I was jus readingTI datasheetand I saw that at Vo=200mV output current is just 30uA. Then I saw the graph - sinking current vs output voltage. I either need lower current, negative supply or output transistor (mosfet?). Thanks!2N7002 should be able to go down to 5ohm * 3mA =15 mV. And it has only 50pF max input capacitance.

author: Eka
author_rank: Regular Contributor
timestamp: June 20, 2018, 11:09:01 pm
content: Quote from: npelov on June 20, 2018, 05:46:57 pmThe power supplies for the op-amp need to be centered around the voltage at the high side current shunt. So if your high side voltage is 12 volts and your op-amp needs +5 and -5 volts, then you need supplies that are at 18 volts and 7 volts to power the op-amp. If the op-amp also needs to be connected to ground, then it's ground would be connected to 12 volts. Now that the op-amp is powered and operating properly, a circuit to translate the output from being centered around 12VDC to the voltage range the rest of your circuit is is needed. I'm not an op-amp guru so I'll leave that to others. What I do know is this is a common problem and chips have been made to make it much easier to implement a high side current shunt monitor.This is a link to TI's high side current shunt monitors with analog, comparator, and digital outputs. Some even provide integrated shunts. The digital output ones have integrated analog to digital converters, and many have current and voltage monitoring and will do all that is needed to track power use.http://www.ti.com/amplifier-circuit/current-sense/overview.html

author: npelov
author_rank: Frequent Contributor
timestamp: June 21, 2018, 12:36:24 am
content: @Eka LM358 and LM324 are single supply opamps, they don't need + and - supply. It's a bit tricky when the output gets near the negative rail - the closer you get to it the lower the current sink capability (I didn't know that). That's what I didn't take into account. If I had -1V for the negative supply it would be fine. But I don't have. Even though I'm aiming for low price (LM324 costs 1/5 of the price of a current monitor) I would use current monitor if it was available locally. I've ordered few and while I'm waiting for them I'm trying to make it work with the opamp.Negative supply can be done with charge pump, but they are also not that cheap. Of course for the two current senses I need one charge pump, so it's better than two current monitors.I know why it works at the low side. When there is near 0 volts on the Vin- the opamp does not have to sink few mA and it can get closer to the negative supply.I'm thinking something like (the output goes to ADC, max output resistance should be 10k, so this should be ok, adc input capacitance is 50 pF):... I don't have much experience with source follower. I read in wiki that output impedance is ~ 1/gm(transconductance) which is min 80, typ 320 mS for 2N7002. So 1/80mS = 12.5 Ohms. Should be a problem driving 50pF. Even though capacitive loads of the transistor and the ADC are not big I've added series resistance and integrating capacitor. Maybe the capacitor can be smaller, but I don't need that much speed and I don' know how to check for stability.

author: KrudyZ
author_rank: Frequent Contributor
timestamp: June 21, 2018, 02:28:01 am
content: If you are OK with a fixed zero current offset then you could replace R5 with a resistor divider between the supply and ground. The gain and CM rejection would stay the same as long as the Thevenin equivalent of the divider is the same as the current R5. Your offset would fluctuate with supply voltage variations so you might want to stabilize the top side of the divider if your supply is wobbly. Adding the offset at zero current will get you away from the requirement of driving the output all the way to the negative rail. Depending on what is being fed by this signal the offset might or might not be a problem. The LM324 / LM358 have fairly high offset voltages so accuracy probably won't be too good. However this could be calibrated out, since offset drift is much less of a problem.Rudy

author: StillTrying
author_rank: Super Contributor
timestamp: June 21, 2018, 06:06:59 am
content: "I don't have much experience with source follower."I thought the idea was to use it in common emitter,to get very close to 0V output. Something like this, works in simulation might needin practice.

author: Sudo_apt-get_install_yum
author_rank: Regular Contributor
timestamp: June 21, 2018, 08:10:59 am
content: I’ve been using theLT6106for most of my current measuring; it works great and is super easy to use! If you need more accuracy you can use theLTC6102it needs a few more components but is more accurate.Highly recommend these!

author: Zero999
author_rank: Super Contributor
timestamp: June 21, 2018, 08:37:09 am
content: Quote from: npelov on June 21, 2018, 12:36:24 amNow you have R8 and R2 acting as a potential divider, when the MOSFET is off.A source follower only has a low impedance for pulling up the voltage, when pulling it down, the impedance is equal to the source resistor.To work with the LM358 you need to increase the values of the feedback resistors, so it sinks less current, or add a current sink to the output, to pull it down it bit more.

author: npelov
author_rank: Frequent Contributor
timestamp: June 21, 2018, 08:52:28 am
content: Well I can use 2N7002 to pull down (a BJT can't pull down closely to zero). So the output impedance will be a combination of Rdson and R2 depening on how much the trnasistor is turned on. With the transistor off the output impedance is 2k, but it shouldn't go higher than 2.5V so Rdson should be the dominating resistance here.

author: npelov
author_rank: Frequent Contributor
timestamp: June 21, 2018, 09:16:31 am
content: @StillTryingWell The idea was to use "common emiter", but then I searched for other people doing it and I read about common drain. However they used negative supply, so it never goes near the negative rail. So I get back to common source (if that's a thing)@Sudo_apt-get_install_yum - First of all great nick name. I don't understand these debian guys. I don't need accuracy, but if I did maybe current-source type ICs are not the best idea. Using the drop on a resistor has it's disadvantages. I ordered ZXCT1107SA-7 (as a current mode) and CS30BL as a current to voltage converter because it has a buffer on the output. The problem is that it's fixed gain and there is shortage of gain of 20. For gain of 50 or 100 I have to use lower than 0.1 resistor which increases the expenses for resistor. Not that much, but it all adds up when I have 2 or 3 current senses. I think it'll be 2 - charge current and load current.

author: npelov
author_rank: Frequent Contributor
timestamp: June 21, 2018, 09:35:41 am
content: One thing is that I did want to use high side shunt because I had arrangement like this:And you always havenegative voltageon one shunt. I don't know why I though I really need negative supply to use inverting opamp. But if positive input is at ground then negative should be at 0 even if shunt voltage is negative and I still get positive output:So the whole high side could be avoided in this case (I don't really need common ground between battery, charger and load), but since I had a lot of problems before with high side current sensing I want to figure this out once and for all and never had to think about it again whenever I need high side current sensing.

author: Zero999
author_rank: Super Contributor
timestamp: June 21, 2018, 10:41:39 am
content: Quote from: npelov on June 21, 2018, 08:52:28 amYou have a lot of gain there, so frequency compensation is going to be difficult. How about using a current mirror with two BJTs/MOSFETs, to pull the output down?

author: StillTrying
author_rank: Super Contributor
timestamp: June 21, 2018, 01:11:26 pm
content: Quote from: npelov on June 21, 2018, 08:52:28 amThe large amount of gain and negative feedback makes the output impedancemuchlower than that, as long as there's stilla reasonable amountof current flowing through the pull up or pull down resistor.I've justmeasuredthe output impedance of my simulation with the 8k2 pull up, at 600mV output, supplying +/- 1mA at 1kHz the output impedance was ~0.025 ohm.

author: Zero999
author_rank: Super Contributor
timestamp: June 21, 2018, 02:09:50 pm
content: Quote from: StillTrying on June 21, 2018, 01:11:26 pmThat's only when the loop is closed. The output still can't go lower than R8 and R2 would allow. With a single supply, the loop will be broken at output voltages near the supply rail, resulting in a high output impedance.

author: rstofer
author_rank: Super Contributor
timestamp: June 21, 2018, 03:40:09 pm
content: Quote from: npelov on June 21, 2018, 09:35:41 amMaybe that's why they invented high side current sense amplifiers. Here's a design note from Maxim but there are many other devices on the market.https://www.maximintegrated.com/en/app-notes/index.mvp/id/746A typical shunt for industrial use drops 50 mV at nominal full current. Even if we're measuring 200A, the drop is still only 50 mVhttps://www.amazon.com/AMMETER-SHUNT-500-AMP-MILLIVOLT/dp/B005BHPG6K

author: npelov
author_rank: Frequent Contributor
timestamp: June 21, 2018, 11:03:29 pm
content: Quote from: Hero999 on June 21, 2018, 02:09:50 pmCan't go lower? Why? Inthis schematicit's enough to put few volts on the MOSFET gate and it'll go pretty low. R2 is pull up to 12V. The opamp inputs sit at 4/5*12V - about 9.6V, so the feedback resistor R8 pulls to 9.6. But they are quite high compared to how low the transistor's Rdson can go (2-5 ohms). To simplify things let's say that R8 and R2 are both connected to 12V. then they form divider with Rdson R2||R8 = 1875 + Rdson = 1880 / 5 => drop on transistor when fully on is Vds = 12V/376 = 0.032V. Well that's not perfect, but it's better than 0.8VCurrent sense amplifiers are not the holy grail. I've seen some specifications and they are pretty bad. MAX4372 has maximum error 2.5% at 25 deg. C or 5.5% over the temp range. The 3-pin ones that use a resistor for the drop have bad accuracy at low currents because of current at Vsense = 0mV. The diff. amps are just precision opamps with precision resistors in an expensive package, but you only pick them if you need good accuracy, and if you do = you'll have to implement some software/hardware offset and gain correction anyway.For me I think ZXCT1107 should do the job. It's relatively low price and I don't need much accuracy. But as I saidmy goal was to understand why the high side sensing didn't work, what are the issues that you face when sensing on the high side and how could you solve them. I can only decide if it's worth dicking around with a regular opamp or choose dedicated current sense chip if I knew the limitations.

author: bson
author_rank: Unknown
timestamp: June 22, 2018, 02:58:10 am
content: You're making this overly complicated... did you rule out a subtracting amplifier for some reason? Is the high side too high for the common voltage range?

author: Zero999
author_rank: Super Contributor
timestamp: June 22, 2018, 07:55:01 am
content: Quote from: npelov on June 21, 2018, 11:03:29 pmI was referring to the source follower configuration.https://www.eevblog.com/forum/beginners/differential-opamp-behaviour/?action=dlattach;attach=460285;imageYes, that circuit can go lower but is it stable? As I said previously, it's got a lot of gain. I notice you've got C1 to provide some frequency compensation but is it enough? I suspect not. It's extremely likely that circuit will oscillate.QuoteHave you thought about using an op-amp which can work up to the positive rail, in a current mirror configuration?The op-amp only needs to work up to 5V and 5V rail-to-rail op-amps are cheap.The P-MOSFET could even be swapped for a PNP BJT, which will reduce the accuracy slightly, due to the base current, but it's chaper and possibly make it more stable, since it has less capacitance, than the MOSFET.http://www.analog.com/en/analog-dialogue/articles/high-side-current-sensing-wide-dynamic-range.html

author: npelov
author_rank: Frequent Contributor
timestamp: June 22, 2018, 09:28:28 am
content: Quote from: Hero999 on June 22, 2018, 07:55:01 amI have no idea if it will be stable. Having mosfet in the loop is always tricky. I thought the low input capacitance of 2N7002 would help to stabilize.Quote from: Hero999 on June 22, 2018, 07:55:01 amThat circuit is definitely interesting. I was thinking about two 12V lead acid batteries. The charger would have supply of >=30V. Most of the current sense don't go that far. And this circuit should minimize current - at higher voltages few mA means a lot of wasted power. Zero drift is not required unless precision is needed. Maybe I can use MCP601/MCP602 because its low power consumption (I don't have to burn a lot of current through Rbias and it has low offset current so R1 can be higher.Thanks!

author: Zero999
author_rank: Super Contributor
timestamp: June 22, 2018, 10:52:09 am
content: Quote from: npelov on June 22, 2018, 09:28:28 amThe input capacitance of the MOSFET, will only make oscillation more likely, as it introduces an additional phase shift. The biggest problem is the gain of the MOSFET, increases the total gain to above unity, when the op-amp's phase shift is 180o, causing oscillation.QuoteI forgot to mention that one downside to that circuit is the output impedance will be equal to RL, but that won't be a problem if the load impedance is very high or a buffer could be added.Another possibility is an op-amp with P-channel J-FET inputs, such as the TL072, which will work with the inputs at the positive supply rail. Although do take note that this isn't a guaranteed specification, so is probably not suitable for mass production.http://www.ti.com/lit/ds/slos080n/slos080n.pdf

author: npelov
author_rank: Frequent Contributor
timestamp: June 22, 2018, 12:01:56 pm
content: Quote from: Hero999 on June 22, 2018, 10:52:09 amAnd that's why it's good that it's as low. But the gain ... could it be fixed by rising the integrating capacitor. I'm interested because I had a lot of problems with constant current load with a mosfet I thought gate charge is the only problem. How can you drive a mosfet with an opamp without without oscillation? Any requirements to the opamp? Any components to reduce the mosfet gain?The current mirror is just fine. In this case I'll feed it to PIC ADC input which needs something with input impedance <=10k. And if I have to buffer it after it's amplified it's not that big deal - I can do it with any opamp. It's not like it'll multiply offset of 1mV by 100. Well maybe it's good to have lower bias current - like MCP601 I mentioned. The problem is that I can't Use dual opamp (MCP601) because the supply of the first opamp is lifted off the ground. And if I have two high side shunts at different voltages, again I have to use separate chips.

author: Zero999
author_rank: Super Contributor
timestamp: June 22, 2018, 01:16:12 pm
content: Quote from: npelov on June 22, 2018, 12:01:56 pmThe problem is, the MOSFET is in common source configuration, which has a high gain. It would still oscillate, if it were replaced with a BJT, which could even make matters worse, since it has even more gain. Increasing the value of the gate resistor and adding another resistor between the gate and source, would help to reduce the gain to a more manageable level.QuoteYou could use a dual op-amp IC for the two high side shunts and another dual op-amp IC for the buffer.