# How should I select the resistors for this constant-current application for a 317?

Over at OnSemi, they have a little doc about using a 317 voltage-reg as a current source: http://www.onsemi.com/pub_link/Collateral/AND8109-D.PDF

Their final example, providing constant current to an indeterminate number of strings of LED's is exactly what I'm looking for. I, somewhat, grasp how to choose the value of the "sense" resistor for each string, but they don't explain how to choose the resistor on the base of the transistor... and it's not completely clear to me what will happen if I choose a value which is too low, too high, and how to choose the optimum value.

You just need enough drive to easily sink the ADJ pin current, so the reference voltage can appear between Vout and the collector of the transistor. Because Vout is connected to the base, the transistor collector-emitter voltage will be very small since the collector must be Vref (~1.25V) lower than the base (e.g. it needs to be saturated)
This ~1.25V appears across Rsense, so it's easy to calculate the current (Vref / Rsense, or if you want be exact - Vref + transistor_sat_voltage / Rsense)

Since the ADJ pin current is very small, you don't need a small resistor. Check the ADJ pin current (which according to the datasheet is a max of 100uA)

Say you have a transistor with a gain of 100, the base current of your transistor needs to be a minimum of 100uA / 100 = 1uA. If we are conservative lets assume a minimum gain of 20 (gain drops at saturation)

So we need 100uA / 20 = 5uA into the base. We know that there will be around 1.25 Vref (plus a small amount for the transistor saturation voltage) between the Vout/R4 junction and the anode of LED1. We also know that a transistor has a drop of around 0.7V from base to emitter. So:

(1.25V - 0.7V) / 5uA = 110kΩ (at this base current 0.6V is probably a better estimate for Vbe, but it's not really important as long as we are close enough)

Let's pick 100kΩ since it's an easy value to find, and close enough. I think almost anything between e.g. 1kΩ and 200kΩ will do for a decent transistor, the current should only change by a very small amount over this range. Head toward the lower end for power transistors if you are planning on driving high current LEDs.

Note that for more than one string of LEDs, the ADJ pin current will be shared between the transistors, so you can take this into account if you wish and try higher value resistors, but since sharing will not be perfectly equal I'd stick with the simple equations above.

Oli has given a good explanation of what the maximum resistance value is, let's investigate what happens on the low-end. If R4 is sufficiently small (or if the LED drive current is small), the amount of current sourced from the emitter becomes significant.

Thus, the net current sourced to the LED chain is:

$$I_{LED} = I_{sense} + I_{E}\\ I_{LED} = \frac{1.25 + V_{BE}}{R_1} + \frac{V_{BE}}{R_4} + I_C$$

Typical small LED's are driven from around 10mA-20mA. Let's assume we want our set current to be ~5% accurate compared to a setup with negligible emitter current. That means the amount of current sourced through the emitter should be less than 5% that sourced through R1 so at most there is 400uA flowing through R4 (from Oli's post there's ~100uA flowing from the collector).

So, that means R4_min = 1V / 400uA = 2.5kohms

1V is a higher Vbe saturation voltage than typical, but is still in the realm of possibility depending on which transistor you have and the operating conditions.