News:

Let's find out together what makes a PIC Tick!

Main Menu

voltage to led current conversion in a v small package

Started by TimB, Jun 30, 2024, 06:10 PM

Previous topic - Next topic

TimB


I use slot opto sensors, I had to change from one type to another and as you would expect the led brightness changed. I went from 3.3v and 680 ohm resistor down to 200 ohm for the led drive.

I could just tune the resistor to match the transparency of my medium and gap width but looking at the pic i'm using it has a DAC.
So I'm looking at a self-tune system where I can adjust the current through the led and monitor the signal until it's just right.

The issue is I need to convert the 0-3.3v to current control. I have seen circuits using an op-amp and NPN resistors and am sure that will work but I have no board room for an op-amp and transistor. I could make room for a SOT23 device.

My question is there a very simple way to use the DAC output to control the LED current preferably with minimum parts eg a not much more than a SOT23


top204

If your microcontroller has an on-board op-amp, you can try that as a simple buffer for the DAC, or even the on-board comparator works as an op-amp at low frequencies. I don't think the DAC output, itself, will give enough current to drive an LED.

trastikata

If you have PWM pin on the PIC, the pins can usually handle 25mA which is enough for most LEDs.  Maybe simple PWM and RC filter?

TimB

Quote from: trastikata on Jun 30, 2024, 07:26 PMIf you have PWM pin on the PIC, the pins can usually handle 25mA which is enough for most LEDs.  Maybe simple PWM and RC filter?

So simple! I thought about PWM but not adding an RC filter Dow! :-[

Thanks Les

The pic does not have a opamp I think PWM is the way to go

david

I know they say 25mA but there's not a lot of output swing at those currents due to the combined Pch and Nch On resistances but I'm sure you won't need that sort of current.  I would suspect rather than a brightness change it's more likely to be a LED threshold change and you're moving closer to a voltage drive due to the low overhead available.
If 200R is about in the region of correct brightness then you will need to have a value somewhat lower than this for the R value of the RC filter and a substantial amount of capacitance depending on the ripple you can tolerate.
Note that a diode/LED is an evil type of load for an RC filter resulting in significant current ripple and by adding some resistance in series with the LED after the RC filter reduces this considerably.
I would also suggest that it may be beneficial to operate the PWM by pulling the LED cathode low (rather than lift the anode high) as the Nch On resistances are generally lower.  Use the highest PWM frequency you can that still allows the resolution you need as this will help reduce the capacitance required.  The modelled data shows LED sourcing rather than LED sinking and the PWM generator has zero impedance whereas the PIC may have several hundred ohms.

Cheers,
David

ken_k

Many good suggestions so far. I have found using a PIC at high pulsed output currents can sometimes be detrimental to other functions. One solution could be using the PIC to drive a small FET gate via a resistor so the gates has negligible effect in the PIC. The LED and a series resistor could be connect to the FET drain, the series resistor could even connect to an unregulated higher voltage so no ripple and noise on the PIC rail. I often off-load pics when very accurate ADC results are required. This solution would involve one extra active component maybe a SOT-23 FET, and no capacitor. If the LED resistor was connected to say 12V the current would be more predictable.

trastikata

Quote from: david on Jul 01, 2024, 12:02 AMNote that a diode/LED is an evil type of load for an RC filter resulting in significant current ripple and by adding some resistance in series with the LED after the RC filter reduces this considerably.

There are plenty 47uF or even 100uF caps in 0805 sizes rated 4.5v or 6.3v. But another thought maybe L-R-C filter for better ripple response?

david

47uF would certainly help but you still should use an R-C-R network to get the best effect.  The LED as a load goes from open circuit to near short circuit and hence the ripple.  I would want to see the curves of output current vs output voltage also.
I like the low threshold voltage FET idea as it allows the use of 10k/0.1uF filter and with a modest source resistor (LED in the drain) it will roughly approach a voltage to current sink.  The PIC's DAC could also be used with the FET, once you've passed the threshold voltage.  No filter required.

David

david

Actually - a small signal NPN transistor with something like 100R in its emitter does pretty well also.

ken_k

Sorry I did not read the post properly thinking the LED brightness was simply for viewing the LED.
As it seems filtering is important, Davids bipolar transistor with a 100 ohm emitter resistor may be the best solution.
I have ran a spice simulation. Changing the voltage supply from 5 to 12V makes little difference in the LED current. It would be best to use the highest gain NPN transistor. Watch the dissipation if higher current and voltages are used. The voltage drop across the base resistor is <70 mV at max current. Changes in the LED forward voltage will be insignificant. As the transistor warms up some small change will be noted. 3.3 volts is not a lot to work with. Is there a higher voltage available for the LED collector circuit? Remove the .txt to run the sim

Edit #1 Ooops left the forward voltage of the kenLED at .1 volt it was meant to be 1 Volt enter whatever your LED is.

Edit # 2 Back for another edit I changed the LED voltage drop on my sim to 1.5V and the output current looks identical (as it should) so I wont repost the file.

BTW working on a geiger counter.

Edit #3 one can ADC across the emitter resistor to view LED current.



JonW

We use an RC + PWM or DAC into a BJT with an Emitter load resistor for constant current; it works well.  ISink = (VPWM - VBE)/RE

With a high-efficiency low current LED, a 10k and 100nF into a BJT base of a 2N3904 with a 100R resistor works well. Keeps the current from the PIC low too if you get a high HFE.  Run PWM at a few tens of kHz


TimB


Thanks so much everyone with the detailed help. Way beyond what I hoped for!

Tim