I'm trying to make a 0-25 mA current limiter. I want to take a control voltage of 0-5 V as input and have it control a current of 0-25 mA through a restive load (the restive load may vary between 0-200Ω, it's represented as R2 below).
Here is my circuit:
T1 is a P-channel mosfet (P/N FQT5P10) and O1/2 is a rail-to-rail op-amp (P/N OPA2170). I want the varying voltage at V2 to control the current through R2.
The O2 op-amp is used to make a differential amplifier with a gain of 2. Example: 25mA of current through the load R2, op-amp O2's output should be 5V (marked CSense). The output from op-amp O2 is then the input to op-amp O1. Op-amp O1 compares the control voltage with O2's feedback to limit the current. Or at least that's my intention.
I have simulated this circuit in NL5 circuit simulator, and it works great in the simulation. But today I actually built the circuit, and it oscillates.
I have triple checked my pin-out and wiring, and messed around with lots of other things, but the circuit still just oscillates. When V2 is a higher value the oscillation is slower. What I am seeing on the DSO is that mosfet T1 goes between full on and full off, and CSense is a triangle wave that varies in amplitude with the control voltage. A higher control voltage makes CSense have higher amplitude and lower frequency. The oscillation frequency varies from about 50kHz to 150kHz.
I can post screen shots from my DSO if it helps.
I've been working on this all night, and it's starting to drive me crazy. Any help at all would be greatly appreciated.
Edit: I built the circuit in CircuitLab. It works perfectly there too. Why not in real life?
Update: I have changed R3 to 10K. It reduced the frequency of oscillation to ~20-30 kHz.
Update Everyone is focusing on O1, but I think the problem is in the O2 circuit. Below is a DSO screen shot. V2 is at 1.25 VDC. The yellow trace is the voltage over R2 @ 100Ω. The red trace is the output of O2 (marked as CSense in my schematics). I would expect the red trace to be 2x the yellow trace, but instead it's a completely different shape! What in the world is going on?
For clarity: I would expect the yellow line to be 0.625 VDC, and the red line to be 1.25 VDC (same as the V2 input). Also my power supply is ~8 VDC here, things blow up at 24.