100 mA current sink with LM317 does not work above 25V

I needed a current sink for something and I arranged one with LM317T:

simulate this circuit – Schematic created using CircuitLab

It has a switch to select whether I want to sink 100mA or 500mA of current. I've plotted the whole thing for completeness, the actual problematic part is only the 100 mA side, through the 12 ohm resistor. Both the SPDT and the resistors are beefy enough to handle the current.

After assembling it and putting a heatsink on the LM317, I measured what's the max power that can be dissipated. I used a bench power supply connected across my device (no other load besides the circuit above). At 12V in, and configured to sink 500 mA, it stayed within the SOA indefinitely, and the current was stable, so 6W were okay to dissipate with the heatsink I chose (it could handle more, briefly). Figuring that at 30V / 100 mA, the dissipation would be only 3W , I also tried it, but I noticed that while the current started at 100 mA, it quickly backed down, as if some kind of protection was triggering inside the IC. The problem starts at around 25V in, below that I get the expected 100 mA indefinitely.

What kind of non-ideal behaviour am I hitting here? The datasheet doesn't mention anything other than the resistor being needed, and also the circuit is within the design limits (indeed, at 20V/100 mA the heatsink is much cooler than at 12V/500 mA). I'm almost sure that heat/power isn't the culprit here.

EDIT:

As suggested in the comments, the oscilloscope traces revealed the issue, it was oscillating, at around 3 MHz:

Top trace is Vout-Vadj (i.e., Vout-Gnd), 1V/div. Bottom is Vin-Vadj, 5V/div. The oscillation appears at Vin > 15V, and only becomes worse at higher voltages. No oscillation for Iout=500mA, even at Vin=30V.

So I guess I should put some 10µF across IN-ADJ, right?

• When you are testing this, is Vout grounded? Do you have an input capacitorson the LM317? Are you able to post a photo of your test circuit? Can you measure the output voltage with an oscilloscope and post the trace? Oct 17, 2017 at 18:17
• Yes, do you have a scope. It may have gone into some sort of oscillation. Oct 17, 2017 at 18:41
• You keep switching between "source" and "sink", does that mean you're trying both? Oct 17, 2017 at 19:12
• Thanks, I edited my question to address comments. Yes, Vout is grounded - the LM317 thing is connected across the power rails of the opamp. There are no input capacitors. I'll post a scope trace later when I get to the lab. Oct 17, 2017 at 21:14
• "the LM317 thing is connected across the power rails of the opamp." - Which power rails, and what would this have to do with it? Oct 17, 2017 at 22:40

The LM317 is oscillating because you are not using any bypass capacitors.

Read through the datasheet and pay careful attention to this section on page 13:

8.4.1 External Capacitors

An input bypass capacitor is recommended...

The adjustment terminal can be bypassed to ground on the LM317-N to improve ripple rejection...

...like any feedback circuit, certain values of external capacitance can cause excessive ringing. This occurs with values between 500 pF and 5000 pF.

The most important capacitor is the input bypass and they recommend .1uF ceramic disc capacitor which is a pretty safe choice.

You can also bypass the ADJ pin by connecting a capacitor from ADJ->GND (not IN, like you mentioned in your edit) and/or a capacitor from OUT->GND if input decoupling is insufficient to correct the oscillation you are seeing.

• The 100 nF across In-Adj pins solved the issue completely, thank you very much :) Oct 19, 2017 at 22:49