Author Topic: How can I use common cathode RGB LEDs when dimming using PWM from ATMEGA?  (Read 6156 times)

0 Members and 1 Guest are viewing this topic.

Offline cj9Topic starter

  • Contributor
  • Posts: 14
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 easy  :D

Thanks in advance!
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 10223
  • Country: nz
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.

« Last Edit: July 29, 2011, 12:31:11 pm by Psi »
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline cj9Topic starter

  • Contributor
  • Posts: 14
Hi Psi,

Thanks for your quick reply. Would this work for series LEDs too? The source voltage would be 20v+
 

Offline tecman

  • Frequent Contributor
  • **
  • Posts: 444
  • Country: us
Hi Psi,

Thanks for your quick reply. Would this work for series LEDs too? The source voltage would be 20v+

NO !  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
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 10223
  • Country: nz
Hi Psi,

Thanks for your quick reply. Would this work for series LEDs too? The source voltage would be 20v+

There are two issues here

1)  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.
« Last Edit: July 30, 2011, 12:23:25 am by Psi »
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline cj9Topic starter

  • Contributor
  • Posts: 14
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?
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 10223
  • Country: nz
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,000Hz

All 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.

« Last Edit: July 30, 2011, 11:35:55 pm by Psi »
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline Bored@Work

  • Super Contributor
  • ***
  • Posts: 3932
  • Country: 00
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.

No. 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.
I delete PMs unread. If you have something to say, say it in public.
For all else: Profile->[Modify Profile]Buddies/Ignore List->Edit Ignore List
 

Offline cj9Topic starter

  • Contributor
  • Posts: 14
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.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf