Transistor current limiter, microcontroller controlled?

I've come across a few transistor current limiter schematics, similar to this one:

However, I am not entirely sure how I could implement microcontroller functionality to control this. I think Rsense would cause Q2 to conduct if at a threshold (0.65V assumably) and Rbias will determine how much it will be limited, however that is unclear to me, especially if Rsense will be somewhere highside and just turning on Q2 with my uC seems to not do anything (in simulation at least)

How would I come up with the formulas for a variable limit that I can control? I would rather not have to use a digital potentiometer in place of R2, if I can somehow have sense voltage compared with a comparator with a voltage my uC defines, that'd be great! But how could I start the limiting? What do I "turn on" when the sense resistor shows enough current? Does Rbias have to be there to limit it to a certain level, and I'll end up having to use a digipot anyway?

Any solutions to a uC controlled current limiter would be great, that can be controlled easily with just a pin or two.

• This is not a current limiter, but a current source...if you want a uC-controlled current source, you can just use a transistor and drive it with the ADC, controlling the range of voltages... – clabacchio Mar 15 '12 at 6:52
• Remove Q2 and have an opamp compare a control voltage with the voltage across Rsense. If Vrsense > Vcontrok then opamp shuts down Q1 somewhat. If too low it turns Q1 on more. – Russell McMahon Mar 15 '12 at 7:31

At $V_{SET}$ you provide a voltage between 0V - 1V to get the current drawn at OUT limited to 0A - 1A. Lets assume a voltage of 10V at OUT.
For 0V at $V_{SET}$ the voltage $V_{Adder}$ will be $\frac{0 + 10}{2}V=5V$. This is also the voltage at the non-inverting input of the opamp. The opamp tries to keep 5V at his non-inverting input by driving the transistors. When you get 5V at the non-inverting input the voltage accross the 1R resistor is 0V, because you got 10V on his left and 10V on his right side. The current will be 0A.
The circuit is linear so you get a linear relationship between the voltage $V_{SET}$ and the limited current.
To control the limiting of the current by a microcontroller you could apply a filtered PWM signal to $V_{SET}$.