uSupply implementation - problem with current sensing - Page 1
Forum section: electronics / projects

author: mat_fr
author_rank: Contributor
timestamp: August 24, 2014, 10:38:23 pm
content: Hi there,First post for me, I take the occasion to thank Dave! Thanks to the videos I understood a lot more about electronics. I'm a computer programmer, and I've been into electronics as a hobby for a little more than a year now, using mainly arduinos and ready to use modules. But I now take more and more interest into understanding the real basics of electronics.As the videos regarding the uSupply design were really enlightening, I tried to implement a simplified version of it. Got myself an LT3080, an LM334 load... And the voltage regulation works quite well from the filtered PWM of the micro controller.The problem though, comes from the current sensing circuit, which is actually the most interesting part of the whole design in my beginner view. To test the principle I used a 1R 5W resistor, 4 10k resistors and an LM358. The load I use is a 27R power resistor, in order not to blow anything if the current control doesn't work. None of the used resistors are precision ones, it's just for the sake of proving the design. The 10k resistors pair nicely though. The op amp output is floating (except for the negative feedback).In my test the LM358 is powered by 12V/GND and the load is powered by the arduino 5V line (to avoid too much power being dissipaded).If the load is not connected to ground the output is sitting at 0.68VIf the load is connected (and gets warm quick ^^) the voltage drop accross the 1ohm resistor is 160mV according to my measurement, and the opamp output doesn't change a bit.I tried many combinations, but I can't get the opamp putting its output to 0V or 160mV as expected. Any idea would be welcome (even though I know I will go facepalm if I read that I made a silly mistake).

author: eneuro
author_rank: Super Contributor
timestamp: August 25, 2014, 01:29:26 am
content: Quote from: mat_fr on August 24, 2014, 10:38:23 pmmaybe try ALL combinations using automatedspicescriptsTI.com: LM358, LM358A PSpice Model (Simulation Models)without riskingtoo many chips?

author: mij59
author_rank: Frequent Contributor
timestamp: August 25, 2014, 04:30:38 am
content: Hi,The LM358 is not a rail to rail opamp, its not designed to sink current at zero volt output.

author: David Hess
author_rank: Super Contributor
timestamp: August 25, 2014, 06:19:03 am
content: The LM358 output stage is saturating trying to get to 0 volts. It can sink very little current below about 0.6 volts. Some operational amplifiers have outputs which will perform better but none will sink current when the output is at their negative power supply potential.The easiest way to fix this is to bias the ground reference up by 1 or 2 Vbe drops. I prefer using a different current sense circuit which does not require matched resistors although it will not work with the LM358 either but for a different reason:http://www.linear.com/solutions/1189

author: mat_fr
author_rank: Contributor
timestamp: August 25, 2014, 09:37:32 am
content: Thanks for your answersI know the LM358 is not rail to rail, but the datasheet says that it can get its output down to VDD/GND, so I supposed it would work (and it actually outputs down to 0V without the feedback resistor... without current flowing).So if I get it correctly the current flows through the feedback resistor and cannot get sunk in the op amp output. That current would be 5V/20k = 2.5mA. This would too high for the output at 0V?I measured different voltages on the inputs of the opamp, that seemed weired as I understood the opamp with a negative feedback had always its input at the same voltage, while in the operational range of course.Does this mean that Dave's design 3 is not working at all?(I tried using the buffer stage as in his design, not knowing what to do to make this work, and I figured by myself that it couldn't work with less than 1.5V drop, i.e. 1.5Amps, which defeats the whole purpose, but I thought the rest of the design could work ok).I'll try adding a bias, never done that before so I suppose it's a good exercice as wellThanks again.

author: David Hess
author_rank: Super Contributor
timestamp: August 25, 2014, 01:38:23 pm
content: Quote from: mat_fr on August 25, 2014, 09:37:32 amAbsolutely it is too high for an LM358 which can only sink 2.5 milliamps down to about 0.9 volts.QuoteIf the output is saturated, then there is no negative feedback.QuoteI would need to see the original design.QuoteI would add a pair of diodes in series with the ground connection to the lower 10k resistor and use that point as a virtual ground. Another option is to add a current sink to the output of the operational amplifier but that will not be possible (*) without a negative supply in which case that could be used directly anyway. There are better amplifiers which can get closer to to their negative supply but none will sink current at 0 volts.(*) There are a couple of ways to do this without a negative supply but they amount to making a negative supply anyway.

author: mat_fr
author_rank: Contributor
timestamp: August 25, 2014, 04:56:40 pm
content: QuoteIt can be found here :http://www.eevblog.com/projects/usupply/The revision C is the one using LM358 opamps. I thought it was a good choice for me as I have some of them lying around (and the other opamp used in rev A and B are low voltage apparently - I'm planning to use a 24V power supply).QuoteThanks for the tip. The words make sense but I'm not sure I see how to implement this... Does the joined schematics correspond to your description? If I use a pair of silicon diodes it would increase the bottom reference of the lower 10k resistor (gnd) point by 2x0.6V, so 1.2V. That would make my reference signal 3.7V instead of 2.5V. Am I correct? And then to use this result I should use another way to sustract the 1.2V when using the output value?BTW how is that different from changing the 10k/10k ratio to get the proper reference to 2.5V? The response from the opamp seems linear in either way from the LTSPICE simulation I just ran, but maybe I got it wrong at some point...

author: David Hess
author_rank: Super Contributor
timestamp: August 25, 2014, 05:18:49 pm
content: Quote from: mat_fr on August 25, 2014, 04:56:40 pmThe LM358 is a fine operational amplifier. It just has to be applied correctly.It looks to me like the design shown in the revision C schematic has some problems. The common mode input range of U12A is violated and U12B has the same problem with the output saturating close to the negative supply. My guess is that it works because it is only intended to measure and limit high currents (great than 1 amp) where those issues are not a problem.QuoteThat is correct but the junction between the upper diode and the lower resistor becomes the virtual ground for the output so the 1.2 volt change does not alter the output when measured from that point. This is inconvenient if you wanted a singled ended output referenced to the negative supply which is ground in this case but if you can make that virtual ground which is about 1.2 volts above the negative supply your output signal ground, then it is an easy way to solve a lot of problems.The alternative is to find a negative supply voltage for the operational amplifier or use a circuit like the one I linked although it requires an operational amplifier with an input common mode range that includes the positive supply which the LM358 is not. Designers used to use the ancient LM301 for that but today there are lots of choices.

author: mat_fr
author_rank: Contributor
timestamp: August 25, 2014, 06:44:46 pm
content: Quote from: David Hess on August 25, 2014, 05:18:49 pmFrom what I saw in another subject the U12A case was signaled and Dave acknowledged it. It was a long time ago, I don't know if the project is still ongoing. Maybe he changed his specs during design between rev B and C but it seemed to me that he intended to reach quite a fine precision in all parts of his design, with a 1mA precision on the limiter and a 1A maximum for the output current (maximum for the LT3080, although 2 could be used in parallel).QuoteGot it. Thanks a lot. I'll try to include this virtual ground in my design, don't know yet how to use it to limit the current using a comparator and an NPN but I will think of it a bit.Best regards

author: mat_fr
author_rank: Contributor
timestamp: August 26, 2014, 05:05:07 pm
content: Okay, I tried to find how to deal with the virtual gnd according to the initial specs : 0 to 1V from the uControler (using a filtered PWM and voltage divider) equals 0 to 1A limitation.If I don't want to deal with the virtual ground in software I have, I assume, to add the virtual ground to the signal from the uControler.So adding an opamp in summer configuration should do the trick.Here is what I came to with LTSPICE. I suppose it works properly from the different values tried (the comparator would drive an NPN to take the regulator's SET pin to ground). The bottom voltage source represents the Set voltage from the micro controler.I'm going to try this on breadboard. But I'm curious to know if my solution is the right one or if there is a more direct/obvious way to deal with it?

author: mikerj
author_rank: Super Contributor
timestamp: August 26, 2014, 09:12:13 pm
content: Creating a virtual ground is a perfectly acceptable way of doing things if you don't have a negative supply handy. However, forwards biased silicon diodes don't make good voltage references in practice due to their relatively high dynamic impedance at low currents and their temperature sensitivity (though fine for a quick proof of concept). A proper bandgap voltage reference would be a much better solution for your final design, even something very cheap like a TL431 would give far better stability than two forward biased silicon diodes.Note that raising the zero current voltage will reduce your available resolution if you are planning to hook an ADC up to the op-amp.The other option is to create a negative supply using e.g. a flying capacitor switcher, which are cheap and fairly easy to use. They can be quite electrically noisy though, especially when hooked up on a breadboard so bear that in mind.

author: mat_fr
author_rank: Contributor
timestamp: August 26, 2014, 09:41:08 pm
content: I have an LM385Z-2.5 available for this project, I suppose that would do.But with the diodes even if the virtual ground change slightly (I had 1.06V on my breadboard test), the goal is to add the same value to the signal from the micro, isn't it? In that case no matter if it's not hyper stable, or am I missing something?I tested it on breadboard and the output of the adder, once connected to the comparator, doesn't go lower than 1.20V instead of the expected 1.06 (virtual ground+0). I don't understand why, it seemed rather accurate before plugin it into the comparator. I suppose there is an interaction between the opamps/feedbacks...

author: mikerj
author_rank: Super Contributor
timestamp: August 26, 2014, 10:01:30 pm
content: Quote from: mat_fr on August 26, 2014, 09:41:08 pmIn terms of the actual current control, providing your the set-point voltage has the same offset as the feedback value then yes, it doesn't matter if it varies. However, if you are monitoring the current with an ADC that uses a separate voltage reference, then clearly any change in your virtual ground will cause inaccuracy in the monitored value.

author: David Hess
author_rank: Super Contributor
timestamp: August 26, 2014, 10:10:55 pm
content: Ideally the signal is processed relative to the new virtual ground so the change in common mode voltage do to the diodes is irrelevant. An ADC with differential input can do that automatically with a minimum of performance loss.If a comparator or error amplifier is used, then any reference voltage is setup relative to the virtual ground instead of the negative supply so again, drift cancels out.Maybe you would be better off using an operational amplifier which can operate linearly closer to the negative supply. That will not get you to zero but you can get closer to the negative supply than the LM358 can.

author: mat_fr
author_rank: Contributor
timestamp: August 26, 2014, 10:58:48 pm
content: I hear you both, thanks for your advices.Concerning another op amp which would get closer to its negative supply I'm a little lost, as I thought that the LM358 was capable of doing so. What spec am I looking for to be certain the op amp is right for my usage?

author: eneuro
author_rank: Super Contributor
timestamp: August 27, 2014, 09:50:40 am
content: Quote from: mikerj on August 26, 2014, 10:01:30 pmWhy not to use the same external voltage reference on AVref MCU pin?Only unsure which is minimum possible external VRef eg. on AVR MCUs-used to use TL431I between 2.495V and 4.20V on ATTiny85 AVR's.Update: AVR ATTiny85 for example has AVref in range minimum:2.0V to Vcc(172-175p of its full datasheet), so it can be a trap if someone tries to use lower external reference voltage than allowed for given MCU

author: Kevin.D
author_rank: Frequent Contributor
timestamp: August 27, 2014, 09:57:32 am
content: Quote from: mat_fr on August 24, 2014, 10:38:23 pmI dont know what data sheet you and others have been looking at but the data sheets I have for lm358 , all specify Output Voltage swingV(ol) = 5mV typ to 20mV max thats with a 10k load on the output .So seems like you have a broken opamp.Are your two supplies sharing a common gnd ?. What does the output go down to if you pull the + input down to gnd .?It should go down to at least 20mV max with your 10k load.

author: David Hess
author_rank: Super Contributor
timestamp: August 27, 2014, 01:19:40 pm
content: For a better operational amplifier you want one where the negative output voltage saturates closer to the negative rail. The LM358 gets to about 0.9 volts at 2.5 milliamps. An LT1013 which is a direct upgrade gets within about 0.3 volts. An LT1638 (up to 30 volt supply) or LMC6082 (up to 15 volt supply) will get within about 0.15 volts. Off hand I do not know of any operational amplifiers which will do better while sinking 2.5 milliamps.A pull-down resistor on the output of the amplifier will help but not enough to bother using. A better option would be to increase the value of the feedback resistor so the output sink current requirement is relaxed but this will require a low input bias current amplifier to maintain accuracy which is not a problem. The alternate high side current sense circuit I linked does even better than this by having no load pulling the output up.If you want to sink current all the way to zero volts, then a virtual ground or negative supply is needed.

author: mat_fr
author_rank: Contributor
timestamp: August 27, 2014, 02:20:06 pm
content: Quote from: Kevin.D on August 27, 2014, 09:57:32 amI have a bunch of them actually (some "inherited"from my father, too happy to give me his old thirty years old electronic parts, some got as samples from TI recently), the ones I used seemed to behave the same way but I'd have to make some more tests to be sure.QuoteAbsolutely: both lines come from the Arduino board (Vin <=> 12V and regulated 5V), both share the same ground on the board.QuoteGot to check that out.Quote from: David Hess on August 27, 2014, 01:19:40 pmOk, I think I will stick with the virtual ground solution if I can get something usefull out of it. I'm doing this as a learning project, so I don't intend to buy too much new components. Beside, I don't aim an extremely accurate current limit, but I'd like it to be rather low... the way I see it the advantage of a lab supply is to be able to feed a limited amount of current so as not to blow everything up in case of a problem. If 0.3 V corresponds to 300 mA it seems a rather high current already...BTW I'm still curious about the solution presented in LTSPICE in my message yesterday... Is it the correct solution to add the virtual ground to the input signal using a third op amp or is there a more intelligent solution (without using other fancy parts I mean)?

author: David Hess
author_rank: Super Contributor
timestamp: August 27, 2014, 03:05:24 pm
content: Quote from: mat_fr on August 27, 2014, 02:20:06 pmThe solution does not require a third operational amplifier. The output voltage is taken differentially between the signal output and virtual ground instead of the negative supply ground.In your case that means that any reference and the comparator use the virtual ground as their signal ground which completely solves the problem allowing currents down to zero within the accuracy of the preceding stages.

author: mat_fr
author_rank: Contributor
timestamp: August 27, 2014, 04:10:12 pm
content: OK that makes sense when reading a voltage from a voltmeter, I take the virtual ground as a reference point, and if reading the value from an ADC (I plan on using the Atmega one, so it's not that obvious how to do it). But if I want to use an opamp to drive the output transistor depending on the target/measure comparison I don't see how else to do it, unless I use the virtual ground as the op amp negative supply, but in that case I will want to output a value equals to the negative supply and the same problem occurs again...That's why I was searching how to add the virtual ground to the Target value from the micro...

author: Kevin.D
author_rank: Frequent Contributor
timestamp: August 27, 2014, 04:49:52 pm
content: Sorry ,forget what I said my brain is fried today.The lm358's are fine .without sinking anything they will get down to V(ol) of course but not whilst sinking any amount of current above a few uA .For want you want It's prob easier at the end of the day to provide a negative rail for your opamps ,since if you want the output to go down to 0 (u didn't say) then you will need one anway for a min load sink etc .

author: mat_fr
author_rank: Contributor
timestamp: August 27, 2014, 06:22:26 pm
content: That would probably be easier, but I was planning on using a 24V DC supply so I suppose a negative rail would be complicated to obtainWith a virtual ground as the negative supply the opamp used as comparator (without feedback) connected to a NPN should be OK, as nothing would be sunk anyway in case of a 0V output.But if I supply it with Vin/VirtGND the 0V output will be the virtual ground itself, so I might have a problem with the NPN turning on unexpectedly.Another problem I have is that my test circuit on breadboard doesn't regulate the current properly, more "shut it down once the limit has been reached". I don't now why but it seems that something is wrong in my "whole feedback" loop...Seems to work properly in LTSPICE though...

author: mikerj
author_rank: Super Contributor
timestamp: August 28, 2014, 08:43:48 am
content: Quote from: eneuro on August 27, 2014, 09:50:40 amIt depends entirely on what else the micro is doing. Using a very poor external reference just to make one of the inputs ratiometric may be ok, but that means you can't make any accurate measurements of values that are not referenced to the horrible virtual ground with the other channels.Davids suggestion of using an ADC with a differential input is a good idea if it's available, and you could also create pseudo-differential input by measuring the virtual ground with one channel and the current sense value with another channel and subtracting them in the firmware.

author: mat_fr
author_rank: Contributor
timestamp: August 28, 2014, 11:15:26 am
content: Quote from: mikerj on August 28, 2014, 08:43:48 amThat's actually what I had in mind, as I don't have any ADC available but plenty of Analog Channels on the Atmega328. But it prevents me from using a lower voltage reference for AREF, thus reducing the measurement precision (using 2.5V as AREF means 2.5/1024~=2.5mV per bit resolution, but if measuring the virtual ground I have to use the onboard 5V reference which gives a 5mV per bit resolution). No idea how to evaluate the accuracy though.

author: eneuro
author_rank: Super Contributor
timestamp: August 28, 2014, 06:43:32 pm
content: Quote from: mikerj on August 28, 2014, 08:43:48 amThe problem might be that there will be time difference between those two readings, while eg. @ 250kHz ADC clock and about 13 clock per ADC sampling about 52us delay. If we had to switch reference voltage that means as I well rember additional 25 ADC clock and be carefull and read if there is no bug hardware bug when switching reference voltage-as I remeber ATTiny85 had one-did'nt analysed it but read last time on AVRfreaks.So, switching between voltage references and reading 2 ADC channels means some delays and discarding first ADC read for some AVRs -I wrote ADC routine for that for ATTiny AVRs and had to look into its datasheet while forgot about it since than, but question is if those delays will be acceptable in application and check AVRfreaks for any known MCU HARDWARE bugs which happends-that can save a lot of time, while MCU does not work as expected from datasheet sometimes

author: mat_fr
author_rank: Contributor
timestamp: September 19, 2014, 03:05:26 pm
content: Hey guys,I wake this thread up just for a quick question on RevA/RevB project, for the sake of comprehension. I bought a MAX4080 to handle the current sensing (yeah, why not after all ?). I was just wondering what the RC filter (or isn't it one?) at the output of the MAX chip? I can understand it is to stabilize its output but the datasheet doesn't mention the need for any filtering.So I wondered if there was any obscure reason to add this filtering.

author: David Hess
author_rank: Super Contributor
timestamp: September 19, 2014, 07:30:50 pm
content: Quote from: mat_fr on September 19, 2014, 03:05:26 pmYou should start a new discussion thread.I do not see anything in the MAX4080 datasheet about requiring an output filter. It might have been added to reduce noise or to ignore short current spikes.

author: mat_fr
author_rank: Contributor
timestamp: September 19, 2014, 08:24:21 pm
content: You're right of course, I should have started another topic, I just didn't wan't to multiply the subjects, this one still being about the same project.Anyway, I breadboarded the circuit without the RC filter, with a MAX4080 and an LM358 to limit the Current and set the voltage, and it seems to (finally) work nicely.Thanks again for all your advices, I'll try to make a real thing out of it in the next few weeks.