How can I use common cathode RGB LEDs when dimming using PWM from ATMEGA? - Page 1
Forum section: electronics / beginners

author: cj9
author_rank: Contributor
timestamp: July 29, 2011, 12:15:47 pm
content: Hi!I have created a circuit using ATMEGA8515 which uses PWM to dim LEDs. The anodes of the LEDs are connected to the voltage source and cathodes to the output channels of the microcontroller.I am now looking at using RGB LEDs, but the problem is that most of them use a common cathode. Could anyone suggest a possible way to use the PWM to vary the voltage on the anode so that I can use common cathode LEDs? It's probably really easyThanks in advance!

author: Psi
author_rank: Super Contributor
timestamp: July 29, 2011, 12:22:48 pm
content: Atmega outputs can source or sink current.So you can either- have the led & resistor from an atmega output to VCC and set the pin low to turn the led on.- have the led & resistor from an atmega output to GND and set the pin high to turn the led on.

author: cj9
author_rank: Contributor
timestamp: July 29, 2011, 04:16:24 pm
content: Hi Psi,Thanks for your quick reply. Would this work for series LEDs too? The source voltage would be 20v+

author: tecman
author_rank: Frequent Contributor
timestamp: July 29, 2011, 11:49:47 pm
content: Quote from: cj9 on July 29, 2011, 04:16:24 pmNO ! When the output is off, the CPU pin will see high voltage (20 volts-LED drop). You will see a small diode drop at very low currents (below illumination level) and the voltage will exceed the max voltage capability of the CPU and likely damage it. You can use a small NPN transistor turned on by the output (source HI=ON) and use the transistor to sink the LED string.paul

author: Psi
author_rank: Super Contributor
timestamp: July 30, 2011, 12:20:53 am
content: Quote from: cj9 on July 29, 2011, 04:16:24 pmThere are two issues here1) If you power them directly from the atmega you can only connect the other end to the same supply or ground that the atmega is running from, not a higher voltage.If you need a higher voltage then you need to use a external transistor.2) If you want to run a string of leds in series then you can't use common anode OR common cathode leds. Neither will work. You'd need an RGB led that has separate pins for each leds anode and cathode.

author: cj9
author_rank: Contributor
timestamp: July 30, 2011, 11:17:43 am
content: Thanks again for your quick replies.About having LEDs in series; I was meaning if I was to not use RGB diodes and instead separate red, green and blue ones.I had thought about using a transistor, my only worry would if it would work with PWM?

author: Psi
author_rank: Super Contributor
timestamp: July 30, 2011, 11:34:02 pm
content: There is already two transistor (probably fets) inside the atmega to switch the output pins high low.So yeah, a transistor will work perfectly fine at passing the PWM signal. PWM is pretty slow compared to what a transistor can handle. eg, 1,000Hz PWM and the transistor can switch at 100,000,000HzAll you need to do is make sure the current you feed into the base is high enough to turn the transistor fully on given your load current.Simply put, if the transistor has a gain of 100 and your load draws 1A then you need to put more than 1A/100 = 0.01A (10mA) into the base. So you might pick a base resistor that puts 20mA in for example.

author: Bored@Work
author_rank: Super Contributor
timestamp: July 31, 2011, 08:46:28 am
content: Quote from: Psi on July 30, 2011, 11:34:02 pmNo. When using a transistor (BJT) as a switch, you operate it in saturation. The current gain in saturation is much lower than the nominal current gain, 10 is usually used. For power transistors even less.

author: cj9
author_rank: Contributor
timestamp: August 01, 2011, 01:12:39 pm
content: So if I use RGB LEDs with separate anodes and cathodes, I can use a transistor as an amplifier so control the brightness of the LEDs with PWM. Then I can use either a resistor, or LED driver circuit to limit the current to the LEDs. Would this work?Thanks.