Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Adjusting LED brightness

Status
Not open for further replies.

Yaani

Newbie level 4
Joined
Jan 19, 2012
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,341
Hi,

I would like to know how do you actually control the brightness of the LED by interfacing it with a microcontroller? I've came across the PWM technique but not too sure how do i go about doing it. Does anyone has any recommendations?
 

basically, the duty cycle ,i.e., the relative pulsewidth of your PWM signal determines the LED brightness. Depending on what uC you are using, you would set the input value to the PWM module to correspond to the desired brightness.
 

PWM is the correct technique. In simple terms, it allows your LED circuit to receive full voltage when it is "on", and zero voltage when it's "off". By adjusting the amount of on vs. off time, you control the intensity/"brightness". 100% on/ 0% off = 100% brightness... 60% on/ 40% off = 60% brightness, etc. By toggling between on and off very quickly, it appears to the human eye that the light from the LED is steady, even though the LED is really just flashing between on and off very rapidly (faster than the eye can detect).

Some interesting associate reading:
Frame rate - Wikipedia, the free encyclopedia
 

The frequency of the PWM could be 160 Hz and higher, though you can experiment lower frequencies and see when a noticeable flicker starts.
 

Errmmm...thanks for the info everyone. But how do I put that into a simple circuit to make a prototype? Do I have to specifically buy a hardware PWM and design a schematic diagram to interface it with my microcontroller or do I have to implement it in a programming language?

Is there any resources to help me for my reference? Thank you.
 

Obviously it is cheaper and easier if implemented in microcontroller. In conventional low cost MCUs, this can be implemented using a timer interrupt (if one is available). Some MCUs has buit in an output (or more) connected to a PWM timer. In this case, one just need loading the duty cycle in a special byte (0 to 255). If the MCU is rather busy and uses all internal timers an external circuit would be needed which will be driven digitally by a few MCU pins or also by one MCU pin but delivering a rather low frequency PWM (its average DC voltage determines the duty cycle of the external circuit). The external PWM circuit may consist of a triangular oscillator and a comparator. The variable reference for the comparator would be then the average DC voltage of the rather low frequency PWM from the MCU. In my last project, I used the PWM timer in SST89E58RDA (I guess there are many others).
 

A simple PWM signal can be generated using a 555 timer to create a triangle wave. This reference waveform is fed into a comparator, along with a control voltage (typically from a potentiometer voltage divider). The output of the comparator swings from Vmin to Vmax (depending on the chip you use and voltages you supply to it). The following image shows the signals going into the comparator on the top, and the output PWM signal on the bottom.
**broken link removed**

As the triangle wave's voltage rises above the reference voltage, the PWM output goes low. When the triangle wave voltage becomes less than the reference, the comparator's output goes high. By adjusting the reference voltage higher, the positive pulses become wider (LED will be supplied power longer, and appear brighter). By moving the reference voltage lower, the pulses become narrower, the LED is "on" for a shorter percentage of time, and the brightness is decreased.

Here is a link to a site that discusses a comparator based PWM generator.
Voltage Controlled PWM Generator

And a page that shows you how to wire up a 555 timer to create a triangle-wave.
Triangle Waveform Generator circuit with 555
 

So it is actually possible to control brightness of the led light by using pwm method which is just connecting the pwm output pin from the microcontroller straight to the vcc and gnd of the led light without using any external circuit? Signals are then programmed in the microcontoller itself to control the current/voltage.
 

Don´t forget to put a capacitor at LED bus in order to reduce instantaneous voltage variation around average level.

It is not mandatory, but could improve device lifetime, especially if being of a higher energy wavelengh ( as blue color ), wich are more sensitive to fail.


+++
 

So it is actually possible to control brightness of the led light by using pwm method which is just connecting the pwm output pin from the microcontroller straight to the vcc and gnd of the led light without using any external circuit? Signals are then programmed in the microcontoller itself to control the current/voltage.

Yes, it's possible, but you may need to spend a good bit of time modeling the switching characteristics of the microcontroller and adding additional compensation components around your LED (andre's cap averaging comment). The primary risk with this approach is: what happens when your microcontroller locks up and the PWM control pin remains in the "active" position for too long? If you can damage the LED this way, then you'll have to weight the risk of inadvertently killing your LEDs against the benefit of reduced circuit components (although, you may not be reducing the complexity... just shifting it). Having spent a number of years finding new and inventive ways to inadvertently break circuits under development, I like to build in safety margin where possible, in order to save myself from fixing parts of my system that should "just work"... like LEDs. I'd rather spend my time working on the new, untested, unique parts of my design; not the stuff that should be straight-forward and robust.
 

Thanks for the info. But if there's such a risk, is there any circuit recommendations or any other simple method that i can put into use to interface the led with microcontroller? Cause i'm actually quite new to the electronic stuffs and im required to come out with a prototype within a short period of time. So I probably need a straight-forward and simple design to help me implement this project. :(
 

I don't think you can hurt your LEDs. If you set full-on to be maximum LED current, then you'll never get more than that. In other words, say you want maximum current to be 10mA. Pick your series resistor accordingly, then you can adjust your brightness from maximum (duty cycle=100%) to min (DC=0)
 

Thanks for the info. But if there's such a risk, is there any circuit recommendations or any other simple method that i can put into use to interface the led with microcontroller? Cause i'm actually quite new to the electronic stuffs and im required to come out with a prototype within a short period of time. So I probably need a straight-forward and simple design to help me implement this project. :(

This is the simplest circuit out there to do what you want.


The circuit above uses a transistor as a simple switch to turn the LED on and off. For simplicities sake, I'd use a MOSFET instead of a BJT. A small-signal N-channel enhancement mode FET is what you want. Something like a 2N7002 would do the job (max current at least 50 mA, Vgs(th) < 4.0V).

Since a FET doesn't need current to turn on, R1 can be something small like 100 ohms. R2 is used to force the FET "off" when the microcontroller control pin goes low. Make it on the order of 1kohm. If the microcontroller pin goes to 5V, then the current through the R1+R2 voltage divider circuit will be ~4.5 mA (verify that the microcontroller can source at least that much current... if not, make R2 bigger, just use Ohms Law, V=I*R). If you use 100 and 1000 ohms, then the voltage at the FET's gate pin will be Vout = Vin*R2/(R1+R2) = 5*1000/(100+1000) = 4.55V (which is bigger than Vgs(th), the threshold turn-on voltage for the gate-to-source pins).

To determine R3, you need to know the supply voltage (VDD), the nominal current and voltage of your LED. I'll use a 5V supply, and 2V @ 10 mA for an example. R3 is selected so it'll limit the current through the LED. If we assume the FET is a perfect switch (no voltage drop, looks like a wire), then the voltage across R3 is 5V-2V = 3 volts. Since R3 and the LED will have the same current flowing through them (they are in series), the current through R3 = current through the LED = 10 mA. Now that we know V and I for the resistor, we use Ohms Law to solve for R. V=I*R, 3V = 0.010A * R. R = 3/0.01 = 300 ohms. The power dissipated in the resistor is P = V*I = V²/R = I²*R. So, Pdiss = 3V*0.010 = 0.030 watts = 30mW, so most any SMT resistors would work, up to 1/4W leaded carbon resistors. To use a different voltage/current LED, just walk back through the steps/equations I outlined and recalculate the necessary values.

Hope that helps get your prototype going.
 

The question was how to do it with a microcontroller. That means PWM
 

The question was how to do it with a microcontroller. That means PWM

The OP mentioned that he was a novice, and needed advice on a simple circuit to interface the LED with the MCU.

... is there any circuit recommendations or any other simple method that i can put into use to interface the led with microcontroller? Cause i'm actually quite new to the electronic stuffs and im required to come out with a prototype within a short period of time. So I probably need a straight-forward and simple design to help me implement this project. :(

PWM implementation for an MCU had been discussed in early replies. The circuit I illustrated can be used to drive the LED for low frequency PWM-based dimming, and is the last item the OP asked about.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top