Skip to content

LED driver feedback loop

Pekka Nikander edited this page Jun 3, 2013 · 5 revisions

This page explains how to create a feedback loop in a PWM controlled SMPS converter. In the example case, we measure the voltage drop over a 1 Ohm shunt resistor, placed between the LED and ground. The current flowing through the LED causes a voltage drop over the shunt resistor. The voltage drop is passed through a low pass filter to an ADC PIN on the MCU.

The capacitor in the low pass filter has been chosen to be relatively large (100 pF) to provide enough of current to the ADC measurement capacitor. As our designed lowest PWM frequency is 50 kHz, the low pass filter has designed with cut off frequency is 25 kHz. Consequently, we use a 47 kOhm resistor. The values in the schematics have an even lower cut off frequency, 15 kHz, and therefore a 100 kOhm resistor.

The ADC value is simply read in the loop, and if it above a threshold, the PWM is cut off.

static const int PWM_PIN = 5;
static const int ADC_PIN = A0;
static const int VOLTAGE_DROP_TRESHOLD = 20; // About 300 mA at 3.3V voltage and 8-bit resolution

void setup() {
   setPWMFrequency(PWM_PIN, 50000, 8);  // 50 kHz frequency, 8 bits resolution
   analogWrite(PWM_PIN, 12);            // 5% duty cycle
}

void loop() {
   int voltage_drop = analogRead(ADC_PIN);
   if (voltage_drop > VOLTAGE_DROP_TRESHOLD) {
       analogWrite(PWM_PIN, 0);         // Shut down the PWM signal
   }
}

Note that for anything more complicated but driving the LED at a relatively low duty, you most probably need something more complicated. The ADC readings may be quite noisy, and you may want to design a low-pass filter also at the digital side, into your program code.

PoE LED driver schematics with low-pass filter highlighted

Figure 1. Schematics for a Power-over-Ethernet LED driver, with the low-pass filter highlighted

If you have some previous experience in electronics and you manage to get here, the instructors have a few operational amplifiers at hand. In such a case, you may want to replace the 1 Ohm shunt resistor with a 0.1 Ohm one, and design a better analog low-pass filter with an operational amplifier. The low-pass filter wikipedia page has some basic examples.

Clone this wiki locally