How can I control LED brightness from an MCU without using PWM

image

I want to turn 4 LEDs off, on, or anywhere in between with an MCU. I do not want to use PWM because I have to avoid flicker on camera.

I have a DAC on the MCU that can output between 0 and 2.8V, and a power rail of 5V that can source enough current to drive the LEDs. I have looked at several options like using the linear region of a BJT as an amplifier or the ohmic region of a MOSFET as a variable resistor, but none of them seem particularly reliable.

In this question: MOSFET as a voltage controlled resistor Someone has said in the comments:

are you really trying to replace the resistor, or do you just want something that converts the 0-2.5V from your DAC to 0.12-4V? There are much more elegant, accurate, and cheaper ways to do the latter.

But nobody said what these elegant and accurate ways are, what are they?

Using current sense and an op-amp will make your life easier. Here's a circuit that can supply as much current as you like, controlled by a DAC (simulate it here):



You can adjust the range of currents you want by changing the DAC voltage divider value, sense resistor, or both.

The op-amp type shown in the sim is an LM324, but you can choose a single-unit device as the LMV321 which is available in an SOT23-6 package.

The only bit of trickery I've done is that I've used a PNP/NPN pair instead of a single pass transistor in order to keep the drive within the LM324's output voltage range.

You didn't mention your current requirements. (EDIT: you did in the comments - 20mA LEDs.)

voltage controlled current sink.



simulate this circuit – Schematic created using CircuitLab

There's an approximately 0.6V offset because of the transistor \$V_{BE}\$ below that the leds will be dark, but above that the current should start flowing and be linear at 100 ohms, (which is 10mA per volt)

I have shown the LEDs in series-parallel, but depending on what supply voltages are convenient you can rearrange them.

Below is the LTspice sim of a five transistor circuit that generates a (fairly) linear constant-current for all four LEDs from the DAC input voltage (green trace) without requiring an op amp:

PNP emitter-follower Q5 provides a high input impedance and effectively cancels the transistor input Vbe offset.

R6 provides a path to ground for Q5's base current if the DAC output can't sink current.

The value of the emitter resistors determines the max LED current (here about 10mA for a 2.8V DAC voltage).

Note that input voltage will need to be reduced if LEDs with significantly higher forward drop than the red LEDs in this sim, to avoid saturating the transistors with a 5V supply.



Here's a linear solution:



simulate this circuit – Schematic created using CircuitLab

R1 & R2 attenuate the DAC output voltage, to produce between 0V and 220mV at X, in response to 0 to +2.8V at node DAC. R5 senses LED current \$I\$, by developing a voltage \$V_Y = IR_5\$. I use a closed loop to ensure \$V_Y=V_X\$, thereby setting current between 0A and a maximum of:

$$ I_{MAX} = \frac{V_{Y(MAX)}}{R_5} = \frac{220mV}{0.1\Omega} = 2.2A $$

Be sure to use a MOSFET with low \$V_{GS(TH)}\$, preferably less than 2V. The MOSFET could dissipate 4W of power at maximum current, so it should have a heatsink. R5 can dissipate close to 0.5W, so that should also be quite beefy.

The op-amp's inputs will be operating down to 0V, and the output may need to get close to 0V too, so you must use an op-amp capable of this. The LM358 or LM324, or most so-called "single-supply" op-amps will work. The op-amp must also be "unity-gain stable".

You can also use the microcontroller's PWM output to obtain a reasonably steady DC voltage, using a low-pass filter. The above circuit can be adapted for PWM:



simulate this circuit

The filter formed by R2, R3, C1 and C2 here, has a cut-off frequency of about 15Hz, and to avoid excessive flickering, PWM frequency should not be under 1kHz.

Search for "Voltage controlled constant current source". A typical result (of many) is this. If your DAC's output is good enough you may not even need the Op-Amp buffer. Another article that shows LEDs being driven is here. Neither article is exactly what you want, but you should be able to adapt their circuits to your needs. Obviously your 4 LEDs cannot ne in series with only a 5V supply.

While BJTs can be used as controlled constant current source (see other answers) they dissipate a relevant portion of the consumed power. In case you want to drive LEDs with significant power you might be better off using a switched-mode LED driver/constant current source.

There are dedicated ICs which can be controlled with analog voltage (for example AL8860).

Here's a circuit with 6 tiny components that should what you requested. It's set up for 20mA total at 2.8V in. The 4-resistor network helps the LEDs share current and drops 0.5V at 20mA. The input DAC voltage is divided down to 0-1V and that voltage appearing across R3 gives you about 0-20mA total (5mA each LED).

If it is important that the LEDs be completely off with the DAC output at 0V you might need to add a resistor from 5V to the inverting input of the op-amp. If the op-amp has Vos of +9mV then as much as 180uA could flow through the LEDs (45uA each) which is a fair bit. A 27kΩ resistor to +5 would deal with that.



simulate this circuit – Schematic created using CircuitLab

For a really, really simple solution that avoids flicker, use PWM with a capacitor in parallel with the LED. If you need fast response times, use a high frequency on the PWM and a small capacitor.

Ask AI
#1 #2 #3 #4 #5 #6 #7 #8 #9 #10 #11 #12 #13 #14 #15 #16 #17 #18 #19 #20 #21 #22 #23 #24 #25 #26 #27 #28 #29 #30 #31 #32 #33 #34 #35 #36 #37 #38 #39 #40 #41 #42 #43 #44 #45 #46 #47 #48 #49 #50 #51 #52 #53 #54 #55 #56 #57 #58 #59 #60 #61 #62 #63 #64 #65 #66 #67 #68 #69 #70