Author Topic: Driving RGB leds with common cathode separately with PWM?  (Read 1854 times)

Offline PspKicks316

  • Acidmods Alumni
  • Mad Bomber
  • *
  • Posts: 5709
  • Post quality +5/-4
  • Gender: Male
Driving RGB leds with common cathode separately with PWM?
« on: November 29, 2009, 08:42:15 AM »
At the moment I only have common cathode RGB leds...but I need to drive the colors separately with PWM.
I've got the + wired to the PWM source and the color - wired to GND.
Obviously, using just this I can't control each of them separately.

How would I do this, then? ><

Offline Blizzrad

  • Chaos Lover
  • *
  • Posts: 267
  • Post quality +0/-0
Re: Driving RGB leds with common cathode separately with PWM?
« Reply #1 on: November 29, 2009, 09:39:48 AM »
It sounds like you might have common anode LEDs (common + lead, separate - leads). The configuration depends on what you are driving the LEDs with, one way is to have the common anode of the three LEDs connected directly to the + power supply, and the switching transistors and current limiting resistors for each separate color can be placed between the cathode leads and ground.
« Last Edit: November 29, 2009, 09:48:41 AM by Blizzrad »

Offline PspKicks316

  • Acidmods Alumni
  • Mad Bomber
  • *
  • Posts: 5709
  • Post quality +5/-4
  • Gender: Male
Re: Driving RGB leds with common cathode separately with PWM?
« Reply #2 on: November 29, 2009, 10:07:59 AM »
Oh right. I'm always getting cathode and anode mixed up.

And, would you be able to be a little more descriptive? I don't think I get what you mean, haha.

Offline Blizzrad

  • Chaos Lover
  • *
  • Posts: 267
  • Post quality +0/-0
Re: Driving RGB leds with common cathode separately with PWM?
« Reply #3 on: November 29, 2009, 10:16:34 AM »
How many LEDs are you trying to drive, and what are you driving them with?

Offline PspKicks316

  • Acidmods Alumni
  • Mad Bomber
  • *
  • Posts: 5709
  • Post quality +5/-4
  • Gender: Male
Re: Driving RGB leds with common cathode separately with PWM?
« Reply #4 on: November 29, 2009, 10:19:37 AM »
An Arduino to drive them, and I'm only driving 1 RGB led at the moment (testing stuff out).
I'm using PWM to fade each color separately...or trying to.
I'm familiar with PWM on the Arduino and know what I'm doing, so that's not a problem.

Offline Blizzrad

  • Chaos Lover
  • *
  • Posts: 267
  • Post quality +0/-0
Re: Driving RGB leds with common cathode separately with PWM?
« Reply #5 on: November 29, 2009, 10:41:12 AM »
Ok, that helps. If you are just testing stuff out then you can :

  - connect the common anode pin of the RGB LED to your +5v supply
  - connect appropriately valued current limiting resistors in series between the cathode leads for each individual color and the PWM pins on your arduino

Since microcontrollers aren't intended for driving high current loads directly, it is a better idea to use external transistors for switching, but you can get away with it in cases like this providing you keep the current low enough.

Note that if your code is set up for common cathode LEDs this will invert the PWM effect since they will now illuminate when the pin is low instead of high. You can adjust for this by inverting the variables that are sent to your PWM generation routine.

Offline PspKicks316

  • Acidmods Alumni
  • Mad Bomber
  • *
  • Posts: 5709
  • Post quality +5/-4
  • Gender: Male
Re: Driving RGB leds with common cathode separately with PWM?
« Reply #6 on: November 29, 2009, 10:43:39 AM »
Invert....like as in negative values?
I think I'm missing something here. PWM can be used on the negative lead...? I thought PWM was positive. PWM goes from 0-255 on this..

EDIT: WOAH I GOT IT. Awesome. Thank you so much Blizzrad!
« Last Edit: November 29, 2009, 10:58:02 AM by PspKicks316 »

Offline Blizzrad

  • Chaos Lover
  • *
  • Posts: 267
  • Post quality +0/-0
Re: Driving RGB leds with common cathode separately with PWM?
« Reply #7 on: November 29, 2009, 11:00:30 AM »
By invert I mean using the bitwise compliment (~) of the variable, so ~255 = 0, and ~0 = 255.

When set as outputs, the I/O pins on a microcontroller can source or sink current depending on the potential of what is connected to them. The PWM is switching your arduino pin continually between 0v and 5v, so if an LED with 5v on its anode has its cathode lead connected to the PWM pin, current will flow into the pin when it is at 0v, and no current will flow when it is at 5v since the potential is equal.

edit: Just saw your edit, glad to see you got it working.

Offline PspKicks316

  • Acidmods Alumni
  • Mad Bomber
  • *
  • Posts: 5709
  • Post quality +5/-4
  • Gender: Male
Re: Driving RGB leds with common cathode separately with PWM?
« Reply #8 on: November 29, 2009, 11:04:14 AM »
That is so awesome. That really helped a lot. Thanks!

 

SMF spam blocked by CleanTalk
SimplePortal 2.3.5 © 2008-2012, SimplePortal