Convert PWM to constant current (programmable current source)

Thread Starter

Najossmith

Joined Sep 12, 2018
13
Attached is a schematic of my setup (with a few measurements) and a picture of my breadboard.

Schematic:
-Vcc/Vee are +/- 14V to satisfy the min +/-10V and +/-15V max
-I have the PWM sweeping from 0 to 255 to get a filtered voltage between 0 and 3.2
-I am not getting a current at A (the diode)
-I swapped out the PNP for a NPN (2N2905A)
Measurements:
-Vbe = 10V?
-Vbc = 0.23V?
-V+ = 1.3 - 3.2 V (from RC)
-V- = 1.57 V and does not "follow" Vout
-Vout = 11.5V

Picture:
-Red wire to Op Amp is +14V
-Orange wire to Op amp is -14V
-Green 1 is feedback between emitter/resistor node to inverting
-Green 2 is V+ from the RC filter
-Brown wires are going to my DMM measuring current
-Orange to left-most resistor is PWM
-Diode goes to 5V

Thoughts?
 

Attachments

crutschow

Joined Mar 14, 2008
38,508
Thoughts?
The 2N2905 is a PNP not an NPN.
Try a 2N2219, a 2N2222, or similar.

Below is the LTspice simulation with a 2N2222 and a 741 op amp (I didn't have a model for yours).
I had to change the value of emitter resistor to 16Ω and attenuate the input by 50% to get a full 100mA through the laser with a 5V supply.
Shown are duty-cycles of 10%, 50%, and 95%.

upload_2018-9-13_13-39-29.png
 
Last edited:

ebeowulf17

Joined Aug 12, 2014
3,307
The 2N2905 is a PNP not an NPN.
Try a 2N2219, a 2N2222, or similar.

Below is the LTspice simulation with a 2N2222 and a 741 op amp (I didn't have a model for yours).
I had to change the value of emitter resistor to 16Ω and attenuate the input by 50% to get a full 100mA through the laser with a 5V supply.
Shown are duty-cycles of 10%, 50%, and 95%.

View attachment 159838
I realize after seeing your sims that I had a brain-fart on how set point ripple would relate to RC time constant selection. It's clicked again for me, but I hope my wonky descriptions didn't mislead anyone. There's a lot more ripple for any given time constant than what I imagined when I was typing earlier!

Also, @danadak, thanks for sharing resources on filtering PWM - those should set the record straight on anything I described incorrectly up above.
 

crutschow

Joined Mar 14, 2008
38,508
Since the op amp is already configured as a follower, which is the active part of a Sallen-Key filter, here's the circuit changed to such a 2-pole LP filter configuration by adding one resistor and one capacitor.
This significantly reduces the ripple with essentially the same or better settling time as compared to the single-pole RC filter.

upload_2018-9-13_20-53-0.png
 
Last edited:

Thread Starter

Najossmith

Joined Sep 12, 2018
13
Since the op amp is already configured as a follower, which is the active part of a Sallen-Key filter, here's the circuit changed to such a 2-pole LP filter configuration by adding one resistor and one capacitor.
This significantly reduces the ripple with essentially the same or better settling time as compared to the single-pole RC filter.

View attachment 159861
If I add up the voltages from the 5 Vcc to ground through the diode, transistor, and resistor wouldn't I get 5 (Vcc) - 0.8 (laser) - (1.4 transistor) = 2.8? Which would then drive the voltage at my inverting input because the voltage at the cap can swing? This is what seems to happen when I build it in the lab.

I'm wondering if I can put a buffer between my inverting input and the RC filter to alleviate that issue.

Thoughts?
 

Thread Starter

Najossmith

Joined Sep 12, 2018
13
If I add up the voltages from the 5 Vcc to ground through the diode, transistor, and resistor wouldn't I get 5 (Vcc) - 0.8 (laser) - (1.4 transistor) = 2.8? Which would then drive the voltage at the inverting input up? And once that happens, the non-inverting input can no longer adjust the inverting side. This is what seems to happen when I build it in the lab.

I'm wondering if I can put a buffer between the RC filter and the op amp I can alleviate that issue.

Thoughts?
 

ebp

Joined Feb 8, 2018
2,332
There is no point using a buffer because the voltages remain the same and the current into or out of the amp's inputs is orders of magnitude lower than the current in the emitter resistor or the attenuating/filter for the PWM signal.

The voltage at both op amp inputs, provided it is in control, is the product of the emitter resistor and the current. If you want 100 mA and choose a 10 ohm emitter resistor, full-scale control voltage is 1.0 V. You could probably go to double that with a 5 V supply without difficulty. The only merit to a higher voltage across the emitter resistor is reduction of relative error due to amplifier input offset voltage. With a 10 ohm emitter resistor, the gain is 100 µA per millivolt, so (say) 5 mV of input offset voltage (a very mediocre amp by today's standards) gives you an error of 0.5 mA, which I suspect is quite tolerable. Using a 20 ohm emitter resistor with the same amp would half that error.

Another source of error is the base current of the transistor. The emitter resistor "senses" the emitter current which is the sum of the base current and the collector current. This can lead to a few percent of error if the transistor gain is not high enough.

You don't need a particularly fast op amp for this sort of circuit, even if the load is fairly dynamic. If you fix the base-emitter voltage of a bipolar transistor you get a pretty constant collector current even when Vce is varied, so the amp's biggest job is to look after slow phenomena like temperature-related changes.
 

ebeowulf17

Joined Aug 12, 2014
3,307
If I add up the voltages from the 5 Vcc to ground through the diode, transistor, and resistor wouldn't I get 5 (Vcc) - 0.8 (laser) - (1.4 transistor) = 2.8? Which would then drive the voltage at my inverting input because the voltage at the cap can swing? This is what seems to happen when I build it in the lab.

I'm wondering if I can put a buffer between my inverting input and the RC filter to alleviate that issue.

Thoughts?
Did you see the bit in @crutschow's post about having the wrong transistor? I don't think you need to worry about buffers, subtleties of RC filters, or anything else until you've got a suitable transistor in place.
The 2N2905 is a PNP not an NPN.
Try a 2N2219, a 2N2222, or similar.
 

Bordodynov

Joined May 20, 2015
3,431
Did you see the bit in @crutschow's post about having the wrong transistor? I don't think you need to worry about buffers, subtleties of RC filters, or anything else until you've got a suitable transistor in place.
And from myself I'll dab: and do not worry until you have suitable opamp. In my scheme, you will see the most suitable operational amplifier in a suitable package and almost the cheapest (except 741).
 

Thread Starter

Najossmith

Joined Sep 12, 2018
13
I appreciate all the input from everyone, it has helped tremendously. This community has made the barrier of entry much more accesible to less experienced folks and I think that is really important for the future.

My laser is lasing so it's a good day. I'm sure I'll be back in the future.

Thanks again,
Nathan
 
Top