# Adjusting the output current using a microcontroller

I have an LED driver. The current limit is set by the resistor RIADJ. Now there is 3.24 kΩ, which is equal to the current ~ 1 A.

Also, the current can be adjusted by supplying an external current IEXT.

To regulate the current, I collected the amount as in the figure below. I would like to regulate the current from 0 to 1 A with a microcontroller. From the microcontroller, I give a PWM signal of various duty cycles:

When the duty cycle is 0 %, then the current flows only through the resistor RIADJ and the current is set to ~1 A.

When the duty cycle is 50 %, then the external current IEXT is applied and the current on the LEDs will be ~ 0.5 A.

When the duty cycle is 100 %, then the external current IEXT is applied and the current on the LEDs will be ~ 0 A.

But in reality, I can’t choose the resistors so accurately to ensure that at 100 % filling of the PWM signal, the current is exactly 387.35 μA in order to get a current on the LEDs of 0 A. And the voltage to the microcontroller is not always ideal 3.3 V and can be from 3.2-3.4 V, which will also affect the current... Moreover, I noticed such a feature, if you change the 510 Ω resistor, say to 270 Ω, then the current will go in the opposite direction, which will still lead to the fact that the LEDs will glow.

How can I adjust the output current from 0 to 1 A with a microcontroller?

I understood what my mistake was and why, if you change the 510 Ohm resistor to 270 Ohm, the current will go in the opposite direction and the LEDs will still glow. I just don't have enough tension. The current monitor of this microcircuit is powered by an internal source of 5.4 V, and I have only 3.3 V from the microcontroller minus 0.7 V drop across the diode.

• If the Microcontroller has an analogue input, you could get it to read the current output and automatically trim the PWM. Commented Dec 2, 2022 at 8:29