(
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 connectionFirst 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.)
StabilityNow, 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