5
\$\begingroup\$

I'm wanting to use one of the Arduino's PWM output to control a high-powered LED. I can't remember the exact specifications, but it was considerably more current than the ATMega328 can provide.

I realise that this would usually be achieved with the use of a transistor, and a resistor to current-control the LED. However, I'm not wanting the LED to become less bright as the battery voltage sags, and therefore I'm wanting to use a constant current source instead of the resistor.

My first thought was to use an LM317. What I'm wanting to know, though, is if it can respond at the 64KHz it would need to?

Alternatively, could I use a simple MOSFET to achieve the same thing cheaper and simpler? (Then I wouldn't need a transistor nor constant current source, as the MOSFET would do both of these)

Thanks, Rob.

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Do you really need to modulate at 64 kHz? If you are just trying to control the visible brightness that's faster than required. Some more details as the voltage range you expect from the battery and the operating current and voltage of the LED would help provide a better answer. \$\endgroup\$ Dec 7 '09 at 12:37
  • \$\begingroup\$ robzy - After looking over the arduino documentation, the default PWM function only supports a frequency of 490 Hz. If you do analogWrite(1), this will translate into a PWM signal with a .39% duty cycle. Is it proper to refer to that as a 64kHz signal? \$\endgroup\$
    – J. Polfer
    Dec 7 '09 at 14:59
  • \$\begingroup\$ I am wanting to control the physical brightness, and colour, of an RGB LED. I'm pretty sure that I'm looking at current figures of 200mA for each colour of the LED. The battery voltage should be 3.5-4.5v, and the voltage of the LEDs vary between 2.5-3.2v. \$\endgroup\$
    – robzy
    Dec 8 '09 at 0:25
  • \$\begingroup\$ Some interesting answers but wasn't quite enough for my level of knowledge. Future readers may want to see this post for a lot of detail: joost.damad.be/2012/09/… \$\endgroup\$
    – user52720
    Sep 6 '14 at 22:22
6
\$\begingroup\$

You don't need 64kHz for this application, 200Hz is enough.

I've used the following design, for about 200mA current:

+5V --- LED --- transistor -(1)- shunt (1 Ohm) --- GND

(1) goes to the negativ input of an LM358 OpAmp. It is important that the OpAmp works down to the lower rail (GND), because there is only a small voltage on the shunt.

The output of the OpAmp drives the transistor via some appropriate resistor.

The positive input is connected to a voltage divider which is fed from the port pin. The voltage divider and the shunt determine the current through the LED.

\$\endgroup\$
2
  • \$\begingroup\$ Actually, I think I do need 64KHz. The PWM frequency is about 500Hz, which divides into periods of 2 milliseconds. At the lowest level (before turning off) it's on for 1/256 of that time, or 8 ms bursts. That works out to be 128KHz (I accidental used 128 levels in my original estimate). \$\endgroup\$
    – robzy
    Dec 7 '09 at 12:33
  • 2
    \$\begingroup\$ @robzy: you mean 8 us bursts, not 8 ms. And you're confusing pulse width with frequency. 500 Hz is 500 Hz, even if you have a .1% duty cycle. \$\endgroup\$ Jun 13 '11 at 15:36
4
\$\begingroup\$

The data sheet for a LM317 shows that its step response time is in the order of 10 uS. This will be too slow to modulate at 64 kHz.

A current source is the right approach. Depending on the total power you need to drive the LED a linear current source like starblue suggested might work, but if the power is higher you might need to use a buck regulator.

\$\endgroup\$
1
  • \$\begingroup\$ @Clint Lawrence - A single step in a 64kHz square wave is 15uS. If the LM317 has a slew rate of 10uS, couldn't it handle that square wave? \$\endgroup\$
    – J. Polfer
    Dec 7 '09 at 14:59
2
\$\begingroup\$

I would use an op-amp, resistor and FET to create a constant current sink. As the voltage drops the op-amp will drive the gate of the FET to maintain a constant-current through the sense resistor.

If you scroll down to the "Electronic Load" section at Luciani.org you will see a schematic of a "load cell" which is a constant current sink. You can PWM the sink by periodically setting the programmed current to zero.

I have my prototype working. It is in the "not-quite-ready" section at the wiblocks site.

\$\endgroup\$
0
\$\begingroup\$

You can place a precision, low-resistance resistor in series with the LED and use Arduino's analog input to measure the voltage drop across the resistor. You can compute the LED current from this measurement and adjust the duty-cycle of the PWM signal to compensate for battery voltage changes.

Note that this would not work if Arduino does not have a fixed reference voltage for Analog to Digital conversion.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.