Author Topic: Current source feedback capacitor  (Read 120546 times)

0 Members and 1 Guest are viewing this topic.

Offline OM222OTopic starter

  • Frequent Contributor
  • **
  • Posts: 768
  • Country: gb
Current source feedback capacitor
« on: May 16, 2019, 05:03:49 pm »
I've been having a few issues regarding oscillations on the output of op amps that are used for constant current sources. there doesn't seem to be any rhyme or reason behind it either, for the most part I've ordered the op amps and actually tested them in the exact same circuit to see if they are suitable or not, which is obviously less than ideal. there are two suggestions that are always provided: adding a resistor to the output of the op amp, and adding a capacitor between the output and the inverting input.
http://tinyurl.com/yxjyktlf


I have used 1k resistor (which is the max I can use in order to drive the darlington pair)
and a 100nF capacitor which doesn't seem to do much.
after adding both the oscillations were better but still far from good enough. I was wondering if a larger capacitor , for example 1uF would be a better choice as it passes more AC and provides a better feedback?
I don't have any suitable capacitors to test right now (wrong value or wrong footprint) but I'm not sure if increasing the capacitor is a bad idea because op amps tend to have issues with driving capacitive loads. is there a way to calculate the values rather just trial and error that I'm missing out? if not, what are the general ball park values that I should test?
 

Online NiHaoMike

  • Super Contributor
  • ***
  • Posts: 9137
  • Country: us
  • "Don't turn it on - Take it apart!"
    • Facebook Page
Re: Current source feedback capacitor
« Reply #1 on: May 16, 2019, 05:11:28 pm »
Add a resistor between the shunt and inverting side of the opamp so that the opamp isn't trying to drive a heavily capacitive load.
Cryptocurrency has taught me to love math and at the same time be baffled by it.

Cryptocurrency lesson 0: Altcoins and Bitcoin are not the same thing.
 

Offline OM222OTopic starter

  • Frequent Contributor
  • **
  • Posts: 768
  • Country: gb
Re: Current source feedback capacitor
« Reply #2 on: May 16, 2019, 05:17:17 pm »
Add a resistor between the shunt and inverting side of the opamp so that the opamp isn't trying to drive a heavily capacitive load.

wouldn't that defeat the purpose of the capacitor which is to provide quick feed back?
Also I think this is way too many extra components to stabilize an op amp and feels like wrong design.
 

Offline Benta

  • Super Contributor
  • ***
  • Posts: 6011
  • Country: de
Re: Current source feedback capacitor
« Reply #3 on: May 16, 2019, 05:46:42 pm »
Which opamps? Are they unity-gain stable? Decoupling (I know, but still...)? You provide far too little specific information.




 

Offline Kalvin

  • Super Contributor
  • ***
  • Posts: 2145
  • Country: fi
  • Embedded SW/HW.
Re: Current source feedback capacitor
« Reply #4 on: May 16, 2019, 05:54:54 pm »
Add a resistor between the shunt and inverting side of the opamp so that the opamp isn't trying to drive a heavily capacitive load.

wouldn't that defeat the purpose of the capacitor which is to provide quick feed back?
Also I think this is way too many extra components to stabilize an op amp and feels like wrong design.

Nope. Replace the wire between the 1 ohm sense resistor and the 1 uF capacitor with a 10 kohm resistor (for example). Then you can also reduce the capacitor value from 1 uF down to 10 nF or less in order to speedup the control loop response.
« Last Edit: May 16, 2019, 05:57:33 pm by Kalvin »
 
The following users thanked this post: NiHaoMike

Offline OM222OTopic starter

  • Frequent Contributor
  • **
  • Posts: 768
  • Country: gb
Re: Current source feedback capacitor
« Reply #5 on: May 16, 2019, 05:58:03 pm »
Which opamps? Are they unity-gain stable? Decoupling (I know, but still...)? You provide far too little specific information.

TLV9002 specifically is notorious! behaves completely out of whack no matter what. Also the MCP6V01 is sometimes stable and sometimes not!
on the other hand MCP6002 and the MAX4238 pretty much work fine all the time. they are all advertised as unity gain stable and have around 1MHz GBWP.

the behavior is also not consistent and some values of the shunt resistor cause more oscillations than others.
the question is not specific since the problem varies with seemingly similar parts (tlv9002 and mcp6002 are very similar, MCP6v01 and MAX4238 are also quiet similar). decoupling is also taken care of. as I mentioned before I'm not sure if there is a way to tell if there will be problems before purchasing the op amp. I can't make it dedicated to a specific value of shunt resistor either as I frequently use universal shunts in my designs and cover a range of 10uA to 1A using that method and I want stability across all ranges, not just one!
 

Offline OM222OTopic starter

  • Frequent Contributor
  • **
  • Posts: 768
  • Country: gb
Re: Current source feedback capacitor
« Reply #6 on: May 16, 2019, 06:01:37 pm »
Add a resistor between the shunt and inverting side of the opamp so that the opamp isn't trying to drive a heavily capacitive load.

wouldn't that defeat the purpose of the capacitor which is to provide quick feed back?
Also I think this is way too many extra components to stabilize an op amp and feels like wrong design.

Nope. Replace the wire between the 1 ohm sense resistor and the 1 uF capacitor with a 10 kohm resistor (for example). Then you can also reduce the capacitor value from 1 uF down to 10 nF or less in order to speedup the control loop response.

the 1ohm shunt can be as large as 100k on the smallest current range (10uA) does the ratio of the resistances matter or is the 10k that you mentioned just a part of the feedback loop and not important in value?
 

Offline Kalvin

  • Super Contributor
  • ***
  • Posts: 2145
  • Country: fi
  • Embedded SW/HW.
Re: Current source feedback capacitor
« Reply #7 on: May 16, 2019, 06:22:39 pm »
Add a resistor between the shunt and inverting side of the opamp so that the opamp isn't trying to drive a heavily capacitive load.

wouldn't that defeat the purpose of the capacitor which is to provide quick feed back?
Also I think this is way too many extra components to stabilize an op amp and feels like wrong design.

Nope. Replace the wire between the 1 ohm sense resistor and the 1 uF capacitor with a 10 kohm resistor (for example). Then you can also reduce the capacitor value from 1 uF down to 10 nF or less in order to speedup the control loop response.

the 1ohm shunt can be as large as 100k on the smallest current range (10uA) does the ratio of the resistances matter or is the 10k that you mentioned just a part of the feedback loop and not important in value?

I would sat that the 10 kohm resistor is part of the compensation loop. You should evaluate loop's performance and stability with 100 kohm sense resistor value, too. If may turn out that you need to tweak the 10 kohm resistor value for best performance when increasing the sense resistor value.
 

Offline OM222OTopic starter

  • Frequent Contributor
  • **
  • Posts: 768
  • Country: gb
Re: Current source feedback capacitor
« Reply #8 on: May 16, 2019, 06:47:28 pm »
the main goal was to avoid fiddling around with components and just trying out random values  :-/O so far nobody has posted an equation or solution to check whether there will be loop stability problems or not. I did a bit of search but pretty much every video uses gain of the op amp which in this case is not easy to measure?
 

Offline Benta

  • Super Contributor
  • ***
  • Posts: 6011
  • Country: de
Re: Current source feedback capacitor
« Reply #9 on: May 16, 2019, 07:04:47 pm »
the main goal was to avoid fiddling around with components and just trying out random values  :-/O so far nobody has posted an equation or solution to check whether there will be loop stability problems or not. I did a bit of search but pretty much every video uses gain of the op amp which in this case is not easy to measure?

Your issue is really extremely odd. I've built more opamp/transistor current sources than I can count and have never had problems like this.
Could you say something about the oscillations? frequency, amplitude/measuring method/probe...
 

Offline mikerj

  • Super Contributor
  • ***
  • Posts: 3282
  • Country: gb
Re: Current source feedback capacitor
« Reply #10 on: May 16, 2019, 08:11:02 pm »
Add a resistor between the shunt and inverting side of the opamp so that the opamp isn't trying to drive a heavily capacitive load.

wouldn't that defeat the purpose of the capacitor which is to provide quick feed back?
Also I think this is way too many extra components to stabilize an op amp and feels like wrong design.

It certainly isn't "too many components", I'm puzzled why you would think this?  Just look at the schematic and ask yourself how much of the signal being fed back by the 1uF capacitor is actually going to make it to the op-amp inverting input when you are shunting it to ground with a 1 ohm resistor?

If you are going to change that shunt resistor by 5 orders of magnitude then you have a problem since you are going to end up with a very large resistor value isolating the cap from the shunt (megohms) and a correspondingly small capacitor, making the circuit performance more dependant on parasitics.

Why don't you just simulate the the circuit and look at the open loop frequency response, so you can check gain and phase margin?
 

Offline OM222OTopic starter

  • Frequent Contributor
  • **
  • Posts: 768
  • Country: gb
Re: Current source feedback capacitor
« Reply #11 on: May 16, 2019, 09:45:13 pm »
the main goal was to avoid fiddling around with components and just trying out random values  :-/O so far nobody has posted an equation or solution to check whether there will be loop stability problems or not. I did a bit of search but pretty much every video uses gain of the op amp which in this case is not easy to measure?

Your issue is really extremely odd. I've built more opamp/transistor current sources than I can count and have never had problems like this.
Could you say something about the oscillations? frequency, amplitude/measuring method/probe...

Here is a video using the TLV9002 which is the worst one by far:
https://streamable.com/ioakx

the scope is AC coupled and it's set to 20mV/div.
the 1A range was so bad that it would end up at about 700mA instead of 1A so I excluded it for this test.
the ranges tested in order are: 100uA,1mA,10mA,100mA and 10uA.
As you can see 100uA and 1mA are fine, 10mA has 40mV pk-pk oscillations, 100mA is fine again but 10uA has some weird triangular looking oscillation  :-// and as mentioned before 1A is excluded as it was a total failure! in the meanwhile replacing it with the MCP6002 (has the same footprint and I had a few on hand) fixed the issue all together, only the 1A range had slight oscillations, but nothing too bad! I made another board and tested the MAX4238 and MCP6V01 (again, pin compatible) and this time MCP6V01 had some issues on a few ranges and the MAX4238 was fine |O
the problem is not consistent at all and I'm not sure what I'm doing wrong here. In the original design I didn't have a base resistor for the darlington pair, so I cut the track and bodged a 1K resistor to the TLV9002. no improvements. I then bodged a 100nF cap from the output to the inverting terminal and again, almost no change.

here is the schematic if it helps:

Fets are digital N channel fets and are controlled by an MCU, but on the second board which I mentioned, I just used jumper pins to eliminate any effects they could have, but the results were the same, so they can't be to blame in this case. I thought maybe buffering the 1V input is causing some sort of delay / phase shift so I tried it with only one side of the TLV9002 but it was just as bad. it really seems op amp dependent rather than whatever else is on the circuit which is very frustrating!
 

Offline OM222OTopic starter

  • Frequent Contributor
  • **
  • Posts: 768
  • Country: gb
Re: Current source feedback capacitor
« Reply #12 on: May 16, 2019, 09:48:36 pm »
Add a resistor between the shunt and inverting side of the opamp so that the opamp isn't trying to drive a heavily capacitive load.

wouldn't that defeat the purpose of the capacitor which is to provide quick feed back?
Also I think this is way too many extra components to stabilize an op amp and feels like wrong design.

It certainly isn't "too many components", I'm puzzled why you would think this?  Just look at the schematic and ask yourself how much of the signal being fed back by the 1uF capacitor is actually going to make it to the op-amp inverting input when you are shunting it to ground with a 1 ohm resistor?

If you are going to change that shunt resistor by 5 orders of magnitude then you have a problem since you are going to end up with a very large resistor value isolating the cap from the shunt (megohms) and a correspondingly small capacitor, making the circuit performance more dependant on parasitics.

Why don't you just simulate the the circuit and look at the open loop frequency response, so you can check gain and phase margin?

I tried using ltspice but the zip folder of spice parts provided by T.I didn't want to play nicely. I'm also not sure how to simulate for the open loop frequency response? if you can guide me a bit, I might be able to do it. thanks.
 

Offline mikerj

  • Super Contributor
  • ***
  • Posts: 3282
  • Country: gb
Re: Current source feedback capacitor
« Reply #13 on: May 17, 2019, 07:05:15 am »
Linear Technology have a really useful video showing exactly how to do this step by step.

 

Offline Benta

  • Super Contributor
  • ***
  • Posts: 6011
  • Country: de
Re: Current source feedback capacitor
« Reply #14 on: May 17, 2019, 07:40:50 pm »
After seeing your schematic, a lot of things become clear.
The opamps are working correctly (anything else would have surprised me), but your circuit is not in the least doing what you think.

You are doing a lot of no-nos.

The simple opamp/transistor current source (which you showed in your first post) is supposed to be used with the load placed between supply and collector of the output transistor. This always works!

Your circuit places the load at the emitter of the transistor (I have surmised that "Force" is your load). In series with your load, you have the current sense resistor of 1 ohm. And on top of that, you have a feedback resistor of ~200 kohms between load and sense resistor.

I can hardly imagine a setup that's more prone to instability than this, adding on top that the load is an unknown.

Re-design needed.
 

Offline OM222OTopic starter

  • Frequent Contributor
  • **
  • Posts: 768
  • Country: gb
Re: Current source feedback capacitor
« Reply #15 on: May 17, 2019, 09:41:57 pm »
After seeing your schematic, a lot of things become clear.
The opamps are working correctly (anything else would have surprised me), but your circuit is not in the least doing what you think.

You are doing a lot of no-nos.

The simple opamp/transistor current source (which you showed in your first post) is supposed to be used with the load placed between supply and collector of the output transistor. This always works!

Your circuit places the load at the emitter of the transistor (I have surmised that "Force" is your load). In series with your load, you have the current sense resistor of 1 ohm. And on top of that, you have a feedback resistor of ~200 kohms between load and sense resistor.

I can hardly imagine a setup that's more prone to instability than this, adding on top that the load is an unknown.

Re-design needed.
That is correct but the tests were carried out with the force terminals shorted together, so effectively a pcb track if you wish. Therefore it's not a load related issue. I can't place the the load between Vcc and collector because base current will not flow through it which is taken into account at the emitter. If I want to do that, I have to use a fet which can cause oscillations due to gate capacitance ... besides the load is always only purely resistive, so I can't see how placing it between collector and the shunt can cause problems  :-// It also doesn't explain the difference between op amp behaviours and across some ranges only. If that was causing issues, I would assume all ranges would have issues, not just 10uA,10mA and 1A?

Edit: I also remembered the maximum amount of feedback resistance between the active shunt and the inverting input is only 100k, not 200 (all resistors are in parallel). this concept of universal shunt is also nothing new (Dave did a video about it) and can't be blamed in this case, since the inverting input has "infinite" impedance anyways. 100k in series with infinite is not going to cause issues  ;)
Before suggesting re-design, consider the fact that 3 out of the 7 op amps I tested have worked without an issue on all ranges and only some exhibit weird effects. I'm more interested in knowing WHY this happens and HOW to fix it for future reference, rather than this specific implementation since different op amps have fixed this issue. Thanks
« Last Edit: May 18, 2019, 04:03:24 am by OM222O »
 

Offline D Straney

  • Regular Contributor
  • *
  • Posts: 207
  • Country: us
Re: Current source feedback capacitor
« Reply #16 on: May 18, 2019, 03:14:16 pm »
(Edit: fixed formatting, added more about the current sense ranging)

As a EE who does a lot of analog, it pains me to see some of the misconceptions or unexplained rules of thumb going around here - hope I can clear it up to everyone's satisfaction :)

Load connection
First off, this is unrelated to the stability as of right now, but yes, in most cases (unless you have specific requirements and know what you're doing) you really should put your load from the positive supply to the collector.  There's two problems with putting it in series with the emitter here:
1. It cuts into your headroom available, and you'll only be able to put a very small voltage across your load.  Let's say your op-amp can reliably drive to within 100 mV of the +5V rail (you seem to be using all rail-to-rail output ones, which makes sense for single-supply low-voltage).  With 5V-0.1V = 4.9V on the op-amp output, let's say you drop another 0.1V across your 1K base resistor (there's calculations involved here but I'm just going with gut feel for a ballpark estimate) to put 4.9V-0.1V = 4.8V on your transistor's base.  Because you're using a Darlington transistor, you now have two Vbe voltage drops, so 4.8V - 2*(about 0.7V) = 3.4V.  So you can put 3.4V on the high side of your load; now since the low side of your load, the current sense resistor, is being forced to 1V by your circuit as shown, the load can have a maximum of 3.4V - 1.0V = 2.4V across it.
Maybe this isn't a problem for your application and you only need 1V max across the load, but I'm just illustrating the calculations involved.  On the other hand, if you put your load from +5V to collector, the high side of your load would be at 5V, and the low side of your load would be, at lowest, 1V (current sense resistor) + (about 0.7V) + (about 0.4V) (Vbe for output transistor and Vce for "pre-driver" transistor, that keeps them out of saturation) = 2.1V.  The largest voltage you can now put across your load is 5V - 2.1V = 2.9V.  Not a huge improvement, but the real gains come if you use a supply higher than +5V.  Because you now aren't limited to what the op-amp can drive, you can put any voltage you want (up to what your transistor can take).  If you use a 100V supply, you could even put 100V-2.1V = 97.9V across your load!
Hopefully a diagram will explain better how I counted the voltage drops: see "voltage overhead.jpg" (for some reason the standard editing tools aren't showing up)
2. The other reason not to put your load in series with the emitter is that it will appear in the feedback loop, and now has the potential to affect the stability of your op-amp more directly.  I can get into the math if you ask, but as this is just a sidenote would rather not right now.  If your load is going to be a fixed, known resistance then this could work out ok; however, if this is a "general-purpose" current source designed to drive all kinds of different loads, then it'll likely cause problems at some point.

As for the base current adding to the sensed but not the load current: yes!  That's a tradeoff which given everything else, is worth it because of points #1 and #2 above.  What kind of accuracy are you looking for?  The amount of base current which "sneaks in" depends on your transistor's beta though, and if the beta is high enough it really doesn't matter - this is why ballpark error calculations and keeping overall requirements in mind is important: if you have the extreme-audiophile mentality of "do the best possible even if it doesn't make a perceptible difference to my application", then you can very easily make one specification unnecessarily good at the expense of causing very real problems with other specifications which you do care about.  The datasheet is your friend, do the numbers! :)  In your case, the MJD6039 shows a minimum beta of 1,000 at a collector current of 1A (which gives you an output error of -0.1%), and "typical" beta of maybe 200 at 40 mA (see the plot on page 4).  It's hard to tell for your 10uA range, because the plot doesn't go that low, but let's say the beta gets down to 100 at some point: that means the base current would add 1% to the sensed current, and your load current would have an error of -1%.  If you're only looking for +/- 10% accuracy, then this shouldn't matter; if you're looking for better than 1%, then find a different transistor!  Additionally, at the lowest range, the current through the MJD6039's internal base-to-emitter resistors may matter too: figure 12 shows a 60-ohm Vbe resistor across the output transistor, which with a conservatively-low Vbe of 0.6V, still means that resistor adds 10 mA (!) to the emitter current.

That piece was important, because it showed that if even you did connect the load in series with the emitter, it seems that it shouldn't be able to put out any less than 10 mA with the transistor on, because that internal Vbe resistor will require a minimum of 10mA emitter current!  If your circuit can actually put out 1 mA emitter current in real life, then what's likely happening is that the transistors aren't actually being switched on (no collector current), but the op-amp is driving the entire emitter current itself through the Darlington's Vbe resistors.

The way to correct this is to pick a different transistor.  Personally I'd use a Darlington made out of two individual transistors; use a high-current (maybe 2A or so) one for the "output" and a much smaller one (maybe 100 or 200 mA) for the "pre-driver".  If you can get a minimum beta of, let's say, 20 out of the first and 100 out of the second, then you have a total beta of 2,000, and your emitter current will only cause a -0.05% error in your output current.  Check the beta curves to make sure they don't get really low at low currents, like the huge parabola in figure 7 of the MJD6039's datasheet.  I'd recommend a couple transistors, but would have to spend a lot of time picking through datasheets first!
(You also could use a MOSFET, and make up for the capacitance by using a large gate resistor and making the control loop slow; however, a lot of the available switching MOSFETs aren't happy with linear operation because of the many-paralleled-mini-MOSFETs construction, and will show thermal runaway if you leave them in linear mode: see this appnote for more info.)

Stability
Now, the main problem of stability!  First, let's look at the very simplest case - a current source without the "extra components":

There's a couple potential sources of instability here.
1. Driving an emitter-follower (your darlington transistor is essentially an emitter-follower amplifier driving the current-sense resistor as a load) with a voltage source results in negative impedance weirdness because of all sorts of valid but a bit hard-to-follow math.  I don't think this is an issue here though as your 1K base resistor should be (the good kind of) overkill.
2. The control loop involving the op amp itself could be unstable.  That's what I think is happening here.

If you just have a typical inverting or non-inverting op-amp circuit which gives some voltage gain, then the stability is relatively simple - the only parts involved in the loop are the op-amp itself, and some attenuation from the feedback resistors.  As long as the op-amp is unity-gain stable, then there's no problems.  However, when using it as a current source here, you're adding in all kinds of extra stuff to the loop.  Now instead of...
Op-amp -> Feedback resistor divider
...your loop looks more like this:
Op-amp -> Driver transistor -> (Range selection circuitry ->) Current-sense resistor

The driver transistor piece is particularly problematic: the 1K base resistor and the transistor's base capacitances form a sort of low-pass filter, except it's more complicated than just a singe pole in the frequency response.  Either way, adding extra delay to the loop causes the phase to drop faster and can easily make the loop unstable on its own.  (If you're not familiar with basic control-loop frequency analysis yet, then it's worth reading up on, as it's very useful.)  Also, the combination of transistor beta and current-sense resistor value change the gain of the loop; if you look at figure 2-27 of the MCP6V01 datasheet, you can see that increasing the gain of the loop by 10 dB would put the loop's crossover at 5 Mhz, where the phase has already crossed -180 degrees, and you'd have an oscillator!

Your range-switching circuit also adds all kinds of extra capacitances to various places because of the MOSFETs - some of these may not matter but some likely will.  Even if you bypass the drain-to-source with a jumper wire, it only removes the on-resistance: the capacitances will still be there.  I don't know what MOSFETs you're using, but when you're on a higher current range, the 180K||180K and minimum 100pF Cgs of Q2-2 will make a low-pass filter at 18 kHz, which I can almost guarantee will cause problems, especially in combination with the Cds of the last couple stages, and the similar low-pass filters (180 kHz and 1.8 Mhz) added by the 9K and 900-ohm resistors.  See "ranging.jpg" if you're not sure what I'm talking about.

The easiest way to stabilize the loop (ignoring the ranging circuit issues), as suggested before by multiple people, is to add a resistor between the current sense point, and the op-amp's inverting input - see "stable current source.jpg".  The values to use aren't totally arbitrary though - the reason this works, is because it essentially forms a "bypass" for the loop.  In the back-of-envelope approximations, capacitors are essentially open circuits at DC, and short circuits at infinite frequency, right?  So let's look at the very-low-frequency case: the impedance of the capacitor is way above the impedance of the resistor, and so both components might as well not be there (resistor "disappears" because inverting input is high-impedance) - the circuit now looks like the "no compensation components" version, which regulates DC current the way you want it to.  Now let's look at the very-high-frequency case: the impedance of the capacitor is now way below the impedance of the resistor, and so the resistor (and the rest of the current source circuitry) might as well not be there - the capacitor is essentially creating a short back to the inverting input, and creating a unity-gain buffer, which is inherently stable.  It's not acting as a well-regulated current source at this frequency, but that's ok.

So what this resistor and capacitor combination are doing, is bypassing the current-feedback parts of the circuit and turning the amp into an (inherently stable) unity-gain buffer at high frequencies.  Because all the instability-causing phase/gain weirdness added by the transistor, etc. is at "high frequencies" (for unknown values of "high"), if you turn the op-amp back into a pumpkin, errr, I mean, a unity-gain buffer before the loop response gets weird/unstable, then it can still (a) regulate current at DC/low frequency, (b) not oscillate (be stable at high frequency).

How to choose the R and C values?  The frequency where the op-amp will start transitioning from current-source mode to unity-gain-buffer mode will be where the impedance of the capacitor becomes comparable to the impedance of the resistor.  The formula is the same as for a low-pass filter: f = 1/(2*pi*R*C).  For example, if you picked a 10K resistor and 10nF capacitor, the transition would start happening around 1.6 kHz.  Choosing this frequency is a tradeoff between current-source response speed, and stability.  The lower you set this frequency, the slower your current source will respond to setpoint changes, but the more stable it'll be.  I'd recommend starting with something stupidly low (10K and 100 nF for 160 Hz, maybe) and making sure it's stable there before continuing.  You can then try and model the loop stability in LTSpice, or just keep bumping up the phase by reducing the capacitor (by a factor of 2 each time, maybe) until it becomes unstable, and then back off to the last couple values.  I'm not against a little bit of "try it and see" on challenging-to-simulate (for non-experts) circuits, as long as you understand the reasons for everything. :)

Now, why does this circuit work fine for some people and not for others?  And why do some op-amps work while others are unstable?  For one thing, as I explained before, the external components are what create the instability, and so the exact components and component values will decide what's stable or unstable.  Using a different driver transistor with lower capacitance, for example, would cause less loop delay and be less likely to make it unstable.  A single transistor vs. a Darlington would also change the loop response, as would using a different base resistor, and different current sense resistors.  Using an op-amp with a lower GBP would also be less likely to be unstable.  There's no guarantee that two op-amps with the same GBP have the same loop response though: look at the gain and phase plots (TLV9001: figure 9, MCP6V01: figure 2-27, MCP6001: figure 2-11, MAX4238: page 5) of your different op-amps and you'll see that they have different loop characteristics.  The TLV9002 in particular has a large 1.2k output impedance, which easily could affect the loop response when driving the transistor.  By choosing the right resistor and cap for stability though, you should be able to use any of these op-amps.

Also, remember to re-arrange your current-sense ranging so that the MOSFETs don't add a bunch of low-pass filters to your loop!

This all may sound overly complicated, but hey, that's the way it is - when things seems simple in electronics it's actually just because you're sitting on top of a stack of approximations a mile high :)
« Last Edit: May 18, 2019, 03:29:09 pm by D Straney »
 
The following users thanked this post: ggchab, Neomys Sapiens, bmdaly, OM222O, HendriXML

Offline OM222OTopic starter

  • Frequent Contributor
  • **
  • Posts: 768
  • Country: gb
Re: Current source feedback capacitor
« Reply #17 on: May 18, 2019, 05:25:36 pm »
Thank you so much!
A few clarifications: I have since switched to the BUB941ZT which is a beefier darlington pair, but unfortunately the datasheet is even more scarce. no capacitance values, no BE resistor values, etc. also handling the heat is not an issue if I decide to go down the mosfet path since the 1A range is rarely used, and even then at very short pulse times, but I would like to stick with the current design. the collector has also been connected to the supply rail (9v battery) so I can choose a better LDO and not cause a bunch of noise on the analog circuit when the transistor turns on.

The voltage requirements are also not that important in this case and the 2.4v mentioned is more than enough. This circuit is meant to create the "force" section of a milliohm meter wich can measure upto 200k or so since it was easy to add a few more resistors and get the extra range. The ADC that reads the value is the ADS1219 24 bit sigma-delta ADC with internal reference of 2.048V and if the voltage ever gets higher than that, the next value up of shunt resistor will be selected and vice versa. the ADC is accurate (not resolution!) to +-10uV and I don't want to introduce errors with the means of base current, but I can try cutting and moving a few tracks when I get the PCBs for the 3rd revision  :-+

Regarding lower ranges: there is an 8k resistor from the base to emitter in series with the 60ohm one, but I'm not sure if I'm making a mistake or not. I checked the actual current (not just voltage across shunt / shunt value) and yes, it is providing 10uA,100uA, 1mA and 10mA accurately (ignoring the oscillations) so even if the amp is directly driving that current it still works fine for my application.
I have also included footprints for the extra feedback resistor and capacitor on the PCB so I can easily replace them with different values (not to mention bodge soldering isn't fun). I will aslo stick with the MAX4238 since it provides the least amount of error and is known to be stable even without extra components, but I can see why the TLV9002 and MCP6V01 failed so bad (the phase margin being so low compared to others) and again, thanks for the detailed explanation.

The mosfets that I use for range switching are the cheapest dual N channel logic fets I could find that pass 1A, not much thought was put into them, but I can replace them if they are causing instability. The part number is: N3018SD

I'm also going to include the full schematic and PCB layout in case it helps, please let me know if I'm doing something stupidly wrong and need to redesign.
I'm also not sure how to re-arrange the ranging mosfets to avoid them adding low pass filters to the feedback loop ... I'm sorry if this sounds dumb but I can't see any other place to put them (except between the resistors and ground, which adds the RDS-on to the shunts and throws off their accuracy which means buying much more expensive fets with low RDS-on. In all implementations of the universal shunt, the fets are placed in the exact same location  :-/O
 

Offline D Straney

  • Regular Contributor
  • *
  • Posts: 207
  • Country: us
Re: Current source feedback capacitor
« Reply #18 on: May 19, 2019, 03:33:21 am »
Ok, the application makes sense now!  Keeping the existing configuration seems reasonable given the low voltage range needed and the nicely resistive loads being used.  It's obnoxious that the Darlington's datasheet doesn't say much besides an emphatic "VERY RUGGED BIPOLAR TECHNOLOGY": I'm only about 30 but it somehow inexplicably makes me nostalgic for better-spec'ed transistors back in the 70's.  What I was getting at with the internal-Vbe-resistor values, is just to be aware that the op-amp may be supplying the current directly on the lower ranges instead of the Darlington - if the amount of emitter current required to hit the setpoint and "satisfy" the op-amp creates a voltage drop across the second internal resistor that's below the second transistor's turn-on Vbe, the second transistor in the Darlington won't actually turn on and all the output current will be coming from the op-amp.  That's probably ok though as the MAX4238 seems like it can drive a good deal of current, so the Darlington will just step in to help it out at some point.

Good call on keeping the power vs. control supplies separate.

Range switching: No, that's not dumb, it's not trivial figuring out exactly how to do the switching here.  I didn't have anything better off the top of my head before or I would've said something - can see the attraction of not having to stick anything directly in series with the current sense.  Here's the options I can think of:
1. Keep it the same, but make the loop really, really slow.  90K and ~800pF Cgs puts a pole at 2.2 kHz, which will fuck up the loop phase around that point.  If you can put that unity-gain-buffer transition frequency at maybe 100 Hz it might be ok.  The limiting factor here is settling time: how long do you want to have to wait for a reading?  If the loop response for the current source is mostly defined by a single pole due to the stability R and C (it's not actually, but it's not a terrible worst-case approximation), then it's nice and easy to estimate.  A low-pass filter / RC circuit is also just a single-pole system, and in the time-domain it has an exponential approach to its final value: Vout = Vin*(1-e^(-t/RC)).  By calculating different values of e^(-x) you can see how many "RC time constants" you need to wait to get within a certain percentage of the final value.  For example, e^(-4.6) = 0.01, showing that 4.6 time constants gets you to 1% error.  If you're aiming for 0.01% error, then 7 time constants will get you there.  If the current source should be able to settle to that precision in, let's say, 100 ms, then that means you can make RC = 0.014, which means the transition-to-unity-gain-buffer frequency could be as low as 11 Hz (because 1/(2*pi*0.014) = 11.1).  So in a vague ballpark sense, if you put that RC frequency at 100 Hz, it may be reliably stable, and should settle to 0.01% within about 10 ms or less.
2. If you need faster current source settling times than what approach #1 can give you, use higher-resistance/lower-capacitance MOSFETs for the ranges < 1A.  The 22 mOhm MOSFET is good to use for the 1A range, but you could use higher-resistance/lower-capacitance MOSFET for the lower ranges: the lowest range is where the capacitance matters the most, because it has larger resistance (the two parallel 180K resistors) in series with it.  Ciss is the parameter to watch here: that's the combination of Cgs and Cgd (and Cgd is usually much smaller than Cgs) - don't trust the electrical characteristics table, because different MOSFETs are specified at all kinds of different drain voltages, which makes the non-linear capacitances vary: look at a plot like Figure 10 for the DMN3018 and see what the 1V Ciss is.
3. You could use two sets of MOSFETs: one set (low-resistance, high-capacitance) to select the shunt for the current flow, and another set (high-resistance, low-capacitance) to select the shunt to sense from.  This is probably unnecessarily complex though, given that approaches #1 (and #2 if necessary) seem pretty reasonable.

Other misc. thoughts:
* I have to admit I don't entirely understand why what seems to be the ADC's "current sense" differential input (AIN2, 3) is sensing between 1.024V and shunt+, instead of between shunt+ and gnd?
* To be honest, there's a good chance the final reading probably isn't going to give an effective 24 bits of resolution due to the accuracy of your shunt resistors and probably various other things (input impedances of the ADC, temperature coefficients of resistors/ADC's voltage reference/copper traces, noise on the supply lines, maybe internal reference tolerance without special calibration step, etc.).  It sounds like cost is (understandably) one of your concerns, so I'd bet you wouldn't lose any actual accuracy by using a 16-bit ADC instead: the ADC itself may lose a bit or two to various forms of error, but even so you'll still be getting a resolution of < 0.01%, which is probably better than the initial tolerance + thermal drift of the current sense resistors you're using :)  The guys in the metrology section would have better advice about this than me.
* Be generous with the decoupling caps; unless the datasheet specifically recommends a single one, on the ADC I'd put one each of those 100nF's on both DVDD and AVDD, and probably one of the 1uF's on each as well.  This is where things get into a bit of the "black magic" territory, and it's better to have overkill but no problems, than have hard-to-track-down problems later caused by subtle supply voltage interaction effects.  The ADC is the part where noise is going to matter the most (digital supply noise causing noise in the analog section and distorting your readings), so I'd worry about it much more than the microcontroller, for example.  Also worth putting a 0-ohm 0805 resistor in series with both AVDD and DVDD, between the decoupling caps and the common +5V - this will leave you the option of adding a resistor or ferrite bead later for noise suppression if necessary.
* For the battery input, you can make it pretty robust by adding a series diode (to prevent reverse-polarity problems when somebody touches the terminals backwards by mistake) and fuse.  I'd also put either a "good-sized" (maybe 100uF) aluminum or tantalum cap after the switch, just going by gut feel here - this helps in two ways: (1) keeps the +9V supply from sagging too much when the current source turns on at its full range, due to the battery's internal resistance, (2) the "high" (few ohms) ESR of this capacitor will damp any resonances due to stray inductance in the battery leads, etc. when the switch turns on.  The low ESR of ceramics is great for supply decoupling, but it also means that if you add some inductance and apply a voltage step, you can get some nice large ringing as well (can over-voltage regulators, etc. if not careful).
For choosing a capacitor value to hold up the battery voltage during a 1A pulse, you can do a worst-case calculation: since I=C dV/dt, dV = I*dt/C, and if you assume the battery is supplying none of the current during the pulse and it's all coming from the capacitor (which is why it's a worst-case!) then you can pick a capacitor value that gives you a minimal voltage sag (<= 1V?) for a 1A pulse of whatever length you use.
 
The following users thanked this post: Neomys Sapiens

Offline OM222OTopic starter

  • Frequent Contributor
  • **
  • Posts: 768
  • Country: gb
Re: Current source feedback capacitor
« Reply #19 on: May 19, 2019, 02:21:43 pm »
The absolute fastest response is not important in this case and I will order a few different fets instead of the DMN3018 with lower capacitance and reasonable resistance (I think FDS6930B  would be a suitable replacement). just in case that makes a big difference. As you mentioned using a 10k resistor and 100nF for the feedback of the unity gain buffer, the frequency will be about 160Hz which is pretty good.

Approach #2 also seems reasonable but it will increase production time (I'll be making them by hand) significantly as well as reducing the volume discount of DMN3018s  :P I might try it later but it's not a priority. using different mosfets for shunt selection vs feedback requires a lot more space on the PCB than I currently have :(

Regarding the ADC connections, I can get single ended readings of any nodes, and it was important to me to know the 1.024V output since it has a 1mV initial tolerance but low drift. I also need to monitor shunt+ to detect when the load is present (since I want the device to be mostly automatic). the 10uA range is always on and if a load is connected, the differential reading between the shunt+ and 1.024 drops to almost 0 which is a neat way of detecting load without wasting a bunch of battery.
About the ADC: I searched for 16 bit ADCs first and the cheapest was the ADS1115. then I said: oh well, let's just see what the 24 bit ADCs go for. the price difference between ADS1219 (24 bit) and ADS1115(16 bit) was less than 0.5$, even less so in volume! so that was a no brainer for me. the added precision is really nice at such a small difference. The resistors are quiet expensive too, the cheapest one is 0.14$ in volume. I only cheaped out where it didn't affect accuracy since I hate it when chinese take a good concept and cheap out so much that the final product is not worth it at all. I've included the BOM so far in case you're interested in the exact parts used.

Also surprisingly I have had no issues with the ADC (after destroying 5 of them that is  :-DD) and they work surprisingly well! especially with the RC filter in place which takes care of high frequency noise and the ADC being sigma delta which takes care of the rest of the noise. I will check the VDDs with a scope to see if there are any weird droops / noise sources but I doubt I'll find anything. the board is also really small and each chip has at least a 100nF decoupling cap, which will help out with that issue. the MCU is also put into deep sleep (even the clock is stopped!) while taking ADC readings and the data ready pin wakes up the MCU after the conversion to take the result. I'm not sure how many samples I'll be taking but there will be an averaging too.

I'm actually planning on making the power button a soft power (add a pull down resistor to the EN pin of the LDO and connected the Vin directly to VBAT) depending on the quiescent current. I will leave a 1206 footprint so I can add a 47u tantalum (just something I have on hand) and see how it goes.

Edit: I forgot to mention that I'm not using an external oscillator for the MCU clock either. I tried my best to have no noise sources while taking ADC readings.
« Last Edit: May 20, 2019, 03:16:59 am by OM222O »
 

Offline D Straney

  • Regular Contributor
  • *
  • Posts: 207
  • Country: us
Re: Current source feedback capacitor
« Reply #20 on: May 20, 2019, 04:42:26 pm »
Yeah if you're not looking for a super-fast settling time then might as well get the volume discount and go for approach #1 there.  Makes sense with the inputs, the dual-1nF-capacitor on the two inputs threw me off, looked like a differential thing.

Seems like a good way to autorange: the way you phrased that though, I've got to check, are you using the ADC's shunt+ reading for the actual resistance calculation?  If you are, then awesome, ignore the rest of this paragraph!  If you're not, then you can give a nice bump to your accuracy by not trusting the current source to be perfect: if you do resistance=(measured voltage)/(ideal current), then all the errors of the current source (op-amp offset and drift, input bias*10K, etc.) will show up in your measurement.  On the other hand, if you measure the exact voltage coming off the current shunt, then the current source accuracy doesn't really matter as it only has to be somewhere around the right value, and the only remaining errors will be from the shunt resistor(s) themselves and the ADC.

Ooh, nice trick on shutting down the uC's clock during the conversion.  Glad you've got the uC digital noise taken care of, but the other possible source of analog noise is from the ADC's own digital section, which will still be doing things during the conversion: especially because while you can reduce uncorrelated white noise by averaging, averaging won't get rid of noise caused by things like spikes on AVDD at certain parts of the conversion process.  Probing VDD seems like a good idea, but just for the future I'd at least personally add some extra caps there just as cheap insurance :) May not actually be necessary, but easier than proving that they're not necessary.

I'm surprised the price difference was so small, but hey, if you can spare the extra $0.5 and want to, then go for it!  However there is a difference between added resolution and added accuracy.  Not trying to be a dick here, just don't want you to have any illusions about suddenly having an 8-digit meter on your hands :)  If you've done all the accuracy calculations already then skip this paragraph too, just laying it out in case you haven't yet.  Looking at your BOM (thanks for sharing), it's easy to do some sample calculations with the resistors (which seem like exactly the right kind to use for this, by the way):
1A range: 1% initial tolerance, although this can be calibrated out, but what about thermal drift? +/- 10C is a reasonable swing even if you're using this at room temperature, plus maybe another 5C for heating during the pulse (at full load) and 50 ppm/K -> +0.075%, -0.05% range
Other ranges: 0.1% initial tolerance, and as these are 25 ppm/K parts the range due to estimated thermal drift is now about +0.038%, - 0.025%
The ADC's input bias current (+/- 5nA) will create a +/- 0.5mV offset with the 100K source impedance into shunt+ (0.05% of full-scale, 0.5% at the very bottom of the range).  Its 10 pA/K drift will create an 0.01% offset worst-case (at the very bottom of the range, again).
Other sources of fixed error are ADC's gain error (+/- 0.01%), and the voltage reference initial tolerance (+/-0.15%).  For non-calibrate-able error there's also the ADC's internal reference 110 ppm (0.01%) long-term drift.  I'm leaving out the ADC's internal reference drift (because it's tiny near 25C), the ADC's gain error drift, and the ADC's input offset because those end up being way smaller than the other errors.
Overall, it looks like you can get worst-case initial error of +/- 1.2-1.7% (1A range) or 0.26-0.76% (other ranges), and non-constant errors of +/- 0.1% (1A range) or 0.06% (other ranges).

A 47uF tantalum sounds good for the power, and I'd stress again the usefulness of a series diode and small fuse (although by increasing the source impedance of the battery you may also want to bulk up the tantalum's value at that point).  Having reverse-polarity protection on all my power inputs has saved me tons of times from my own stupidity, and if you're putting them out into the wild with other people then who knows what they'll do with it.  On the subject of protection, it could also be worth putting some 1K series resistors between sense+ and sense- and the ADC inputs; in case of external ESD / somebody sticking a charged cap into it by mistake / etc. it'll at least limit the current through the ADC's input protection diodes a lot and give it a much better chance of surviving.  The error added by the bias current through those resistors will be infinitesimal compared to the other errors calculated above.

Also one more thing: some vias at the gnd side of R3 could help - for the 1A range, it'll help spread the high return current to the battery across both the gnd planes, and keep that extra gnd resistance from affecting your measurement as much.  Although if you're careful about where the battery- connection is and reserve the bottom gnd plane for signals only (by making the only bottom-to-top gnd plane connection at R3's gnd side), it could also have the effect of making a Kelvin sense for your current shunt to the ADC.  I haven't done the numbers and so don't know if the effect is actually significant or not, but if you're aiming for some serious precision, then copper has an absolutely awful temperature coefficient!

Anyways, apologies for the wall of text, this is what happens when I'm waiting for an annoyingly-long test to run at work and need to keep the brain active somehow...

Offline OM222OTopic starter

  • Frequent Contributor
  • **
  • Posts: 768
  • Country: gb
Re: Current source feedback capacitor
« Reply #21 on: May 20, 2019, 08:22:00 pm »
I will add an extra 1uF capacitor to the ADC supply rail and test to see if it reduces the noise or not  :-+
I am also taking into account the inaccuracies of the 1.024V reference and don't assume a perfect current source  :phew:
I know I will not be getting 400nV accuracy like the datasheet advertises but based on test results from version 2, the 10uV digit was absolutely solid (no jumps / noise) and I went based on that as my accuracy, but the results were much better than that   :-/O I think the absolute amount of uncertainty was about +-2uV (almost an order of magnitude better).

Regarding the ADC inputs: the mux is extremely felixable! it can do 4 single channels or 2 differential channels (only between pins 0 & 1 or 2 & 3 or 1 & 2) which is fantastic. It also doesn't make much difference if I take a differential reading or single ended for the load detection: If I take a single ended reading of shunt+ I should compare and see if it's above lets say 1V. If I take a differential reading between shunt+ and 1.024V then I should check to see if it's less than again lets say 24mV  ;D

The ADC inputs are all protected via 1k resistors (RN1 & RN2), then they have a 1nF X2Y (feed through) capacitor which suppresses noise to ground and a 100nF capacitor which suppresses differential noise (both are C0G caps and the X2Y is capacitance matched) although I screwed up the resistor network purchase and there is no matching (they are 1% tolerance) but I didn't have issues with differential noise in the few prototypes I have made and I really don't want to re order 250 resistors if they're not causing issues  :palm:

For the reverse polarity I actually plan on using a P-Channel fet (DMP3099L-7 ) since I also have a bunch of them ordered from V2 (it was used as soft power but the new LDO already has that option) which means I can re-use the same parts and it also adds battery life since there isn't a 0.7V diode drop. win-win if you ask me   :-DMM

The error calculations were very helpful since I didn't bother with them and wanted to do a check after I was happy with the general design (first version was awful! version 2 was better but still had some issues. V3 is almost there but I can still see a few issues with it) so thank you for doing them. it at least confirms I'm on the right track and not totally off! for the resistors I honestly couldn't get anything better unless approaching insane territory (>1$ per resistor) which would obviously blow the budget so I'm happy with these. I would have liked a better 1ohm resistor however they only come in massive packages since I chose a high power rating, >2W to be exact to give some margin, I don't like to run a 1W resistor at 1W, even if it's a pulsed load) and they are less optimized for tempco / absolute tolerance. I can calibrate out the constant errors using a milliohm meter (funny how it's always so much easier if you had one of the things you were making, to help you with making it   :-DD) which I don't have. maybe someone can calibrate one unit for me and I'll be able to use that for the rest, but that will have to wait for later.

the grounds will be heavily stitched with vias all around the edges of the board (not present in the pictures I uploaded since they are the last step and I'm still refining the PCB design). the screw holes also use vias (I will enlarge them a bit more) and are connected to ground which will further help with grounding.

I really appreciate the time you put into these posts and it feels nice to have confirmation that I'm not doing things totally wrong from an experienced engineer. Best of luck with the tests and I hope you have more of them  ;) that way I will be able to get more valuable information  :-+
« Last Edit: May 20, 2019, 11:59:59 pm by OM222O »
 

Offline Jay_Diddy_B

  • Super Contributor
  • ***
  • Posts: 2735
  • Country: ca
Re: Current source feedback capacitor
« Reply #22 on: May 21, 2019, 05:23:03 am »
Hi,

I have had a look at this circuit in LTspice.

First I have to make a model of the Darlington transistor. Since the internal base emitter resistors are unknown, I have to guess the values and measure the current gain until the curve matches.








This is close enough to analyze the full circuit.




I have substituted MOSFETs that are in the supplied LTspice library.



I should get collector of 1mA in this configuration, but the collector current is only 437uA.



The reason is that you need about 0.5mA of base current to turn on the Darlington.

I have attached the LTspice model.

Check this thread for stabilizing a current sink:

https://www.eevblog.com/forum/projects/dynamic-electronic-load-project/

Regards,
Jay_Diddy_B
« Last Edit: May 21, 2019, 05:29:55 am by Jay_Diddy_B »
 

Offline OM222OTopic starter

  • Frequent Contributor
  • **
  • Posts: 768
  • Country: gb
Re: Current source feedback capacitor
« Reply #23 on: May 21, 2019, 06:50:32 am »
Thank you Jay_Diddy_B but you had 2 major errors:
1) not all the current comes from V1 :) some of it comes from the base of the darlington pair which is exactly load is placed at emitter, not collector (please read the previous posts)
2) the LT1013 is not even remotely similar to the op amps I was using, i.e: chopper and rail to rail

if you probe at the 1ohm shunt resistor, 1mA is flowing through it:


Also the fets don't seem to be logic level. I don't think this simulation is valid but gives me a good starting point. again thanks for the effort!

Also I'm not sure what V4 does in this case, can you please explain a bit in more details?
« Last Edit: May 21, 2019, 06:57:00 am by OM222O »
 

Offline Jay_Diddy_B

  • Super Contributor
  • ***
  • Posts: 2735
  • Country: ca
Re: Current source feedback capacitor
« Reply #24 on: May 21, 2019, 10:18:05 am »
Hi,

It was not clear where the load was. (It is case of a picture or schematic is worth a 1000 words).

The current that is regulated is the emitter current of the Darlington transistor.

The op-amp can be replaced by a zero-drift op-amp like the LTC2050. This is a RRIO chopper stabilized part with 3 MHz of GBW.

The op-amp characteristics should not show up in the circuit performance. C1 and R8 set the position of the dominant pole.

It doesn't matter that the Si4412DY have a higher Gate threshold voltage. I am driving them 5V. They should be fully enhanced. I get representative capacitors without having to resort to third party models.

AC analysis


Voltage source V4 is used to measure the control loop gain. You plot V(b)/V(a) to get the Bode plot.







(Try changing R8 or C1)


You can use this to measure the phase margin.

I have attached revised LTspice models.

Regards,
Jay_Diddy_B



« Last Edit: May 21, 2019, 10:20:50 am by Jay_Diddy_B »
 
The following users thanked this post: exe


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf