Arduino Forum

Forum 2005-2010 (read only) => General => Exhibition => Topic started by: KnuttyD on Oct 28, 2010, 07:02 pm

Title: PWM over Shift Register Library (For RGB LED's)
Post by: KnuttyD on Oct 28, 2010, 07:02 pm
Hey guys:

Heres the lib I've been working on for a couple of months now (Well... more like a bunch of functions, but I'm working on incorporating it into a class and eventually its own library :p ).

These are a bunch of functions (and a framework) for using PWM over Shift Registers (specificly 74HC595's). The library us used for just general RGB LED's, as that is what it is specifacly set up for. It wouldent take much code, though, to make it work for general PWM tho  ;D. In fact, I'm working on adding this functionality to the library now...

Heres a vidio of it in action:

http://www.youtube.com/watch?v=C3s8qDhUwlo

[media]http://www.youtube.com/watch?v=C3s8qDhUwlo
[/media]

Happy coding!

Heres the souce code: (754 lines, 22667 chars  ;) )
http://drafts.thatcompdude.com/arduino/RGB_led_pwmViaShift2_ver5/RGB_led_pwmViaShift2_ver5.pde

Here are versions 2 - 5. Dont bother using anything older than ver5 tho, there old and VERY pre-alpha quality  :P
http://drafts.thatcompdude.com/arduino/
Title: Re: PWM over Shift Register Library (For RGB LED's)
Post by: rocketgeek on Oct 28, 2010, 07:13 pm
That's awesome. I have a couple of PCBs I'm selling on my website (www.logos-electro.com) that use daisy-chained 595s to drive high current outputs. Would you mind if I linked to your code once it's up?
Title: Re: PWM over Shift Register Library (For RGB LED's)
Post by: KnuttyD on Oct 28, 2010, 07:35 pm
Quote
That's awesome. I have a couple of PCBs I'm selling on my website (www.logos-electro.com) that use daisy-chained 595s to drive high current outputs. Would you mind if I linked to your code once it's up?


Yea, sure you can. I am working on integrating the code into another one of my projects (which I may or may not make open source), so in the future it /may/ not be open to the public (probably will stay open tho  ;D ). I would love to help you with your project. The code it set up so its not very hard to make it work for just about any PWM (or just basic HIGH/LOW) output to 595's.
Title: Re: PWM over Shift Register Library (For RGB LED's)
Post by: mowcius on Oct 28, 2010, 08:03 pm
Well that's freaky.

I think about RGB LEDs and how to run a load of them. Think of shift registers then remember that they aren't PWM...

Less than a minute later... see this thread!

Cool stuff! I will be testing it out!

Mowcius
Title: Re: PWM over Shift Register Library (For RGB LED's)
Post by: m.ryandesign on Oct 28, 2010, 08:49 pm
This is a great project, thank you for working on it for the community!

I look forward to learning from your code.
Title: Re: PWM over Shift Register Library (For RGB LED's)
Post by: mowcius on Oct 28, 2010, 08:56 pm
Mowcius waits patiently for KnuttyD to return home  :D
Title: Re: PWM over Shift Register Library (For RGB LED's)
Post by: KnuttyD on Oct 29, 2010, 01:03 am
Quote
This is a great project, thank you for working on it for the community!

I look forward to learning from your code.


Thanks!

Heres the souce code: (754 lines, 22667 chars  ;) )
http://drafts.thatcompdude.com/arduino/RGB_led_pwmViaShift2_ver5/RGB_led_pwmViaShift2_ver5.pde

Here are versions 2 - 5. Dont bother using anything older than ver5 tho, there old and VERY pre-alpha quality  :P
http://drafts.thatcompdude.com/arduino/
Title: Re: PWM over Shift Register Library (For RGB LED's)
Post by: m.ryandesign on Oct 29, 2010, 02:12 am
Huge thanks! It is people like you that keep me learning and experimenting.

I look forward to someday sharing innovations of my own.

Cheers,

-Miles
Title: Re: PWM over Shift Register Library (For RGB LED's)
Post by: KnuttyD on Oct 30, 2010, 04:02 am
More minor fixes in the lib

+Faster ISR
+Clean up variable defs
Title: Re: PWM over Shift Register Library (For RGB LED's)
Post by: fujii on Oct 30, 2010, 11:18 pm
Hmm I'm working on some home automation project (lots of PWM controlled LED's included, more than my arduino mega can handle) so I think this is what i'm looking for BUT i never worked with a shift register. I know i can get myself to the point to understand them but a shematic and a sample code would be really awesome. insertbegemotehere-> ::)
Title: Re: PWM over Shift Register Library (For RGB LED's)
Post by: radames on Oct 31, 2010, 05:28 am
great!!

Could you draw your circuit schematic??
thanks..
Title: Re: PWM over Shift Register Library (For RGB LED's)
Post by: defsdoor on Nov 03, 2010, 12:50 pm
Any chance you can document or explain the code ?  

I've have a read through and think I see whats going on but would like to be sure.

I'd like to make use of this instead of using tlc5940s (too expensive, hard to get hold of and currently in my prototype flickering madly) but might have to squeeze a few more 74595s into it for my project.  I assume the quantity that it can drive is down to the time taken to shift the data out within each interrupt ?
Title: Re: PWM over Shift Register Library (For RGB LED's)
Post by: KnuttyD on Nov 09, 2010, 07:27 pm
Sure, I'll try to get to it soon!

For now, take a look at the ShiftOut() tutorial. the registers are hooked up almost Exactly like they are in the tutorial.

Placement of the LED's on the registers is a little harder, tho  ::). Ill try to get a schematic up soon.
Title: Re: PWM over Shift Register Library (For RGB LED's)
Post by: frustro on Nov 15, 2010, 05:30 am
still have a lot to learn, so forgive my ignorance.  

Are you using common anode or common cathode?
Why?
Do you think that this would work with the other type?
Title: Re: PWM over Shift Register Library (For RGB LED's)
Post by: polaris on Nov 19, 2010, 05:21 am
if it's not too much trouble could you please post the schematic? I'm trying to figure out whether to use this or some tlc940s for my project.
Title: Re: PWM over Shift Register Library (For RGB LED's)
Post by: defsdoor on Nov 19, 2010, 11:01 am
http://www.arduino.cc/en/Tutorial/ShiftOut is the basic schematic.  The only difference here is the code to drive it.

The 74595 can sink or drive current so you can use it with Common Anode or Cathode LEDs - you might have to reverse the on or off logic as on will be off and vice versa.

As for TLC5940s - there is an issue with the library at the moment that results in flicker, bleed over etc..  Someone posted working alternate code but I cannot find it on the forum right now.  I do need to test it myself as I had stalled my project that relied on them due to this issue.
Title: Re: PWM over Shift Register Library (For RGB LED's)
Post by: frustro on Nov 21, 2010, 01:46 am
Yay!  Looking at the images on your website, I was able to reconstruct the design.  I have a little "flitter" after it loops through the function, I put a 103 cap on the latch pins, not sure what's happening there.

For those asking for a schematic,   in his code, the PWM pins are

#define __dataPin 9
#define __clockPin 10
#define __latchPin 11

A 75HC595 wires up pretty easily,  you can reference the ShiftOut tutorial here http://www.arduino.cc/en/Tutorial/ShiftOut

As for the daisy chain of the 595's....

PIN 11       SH_CP       Shift register (clock pin)
PIN 12       ST_CP       Storage register clock pin (latch pin)

are linked from one to the next, so from 11 to 11 and from 12 to 12.

The serial data is output on PIN 9       Q7" Serial Out

and PIN 14 DS       Serial data input.

So from the first 595 to the second go from pin 9 to 14 and so forth.

Here is a vid with 4 RGB's.  
http://www.youtube.com/watch?v=4gtaJ8iAxcQ
I will expand to 16 and update here in a bit.


16. going 32 next
http://www.youtube.com/watch?v=EPVKdHAFTfc

Title: Re: PWM over Shift Register Library (For RGB LED's)
Post by: frustro on Dec 06, 2010, 09:50 pm
http://www.youtube.com/watch?v=yBboDZGsW9Q
Knob allows me to control the length and rate.
Button to change between the two.
switch to change direction.
Title: Re: PWM over Shift Register Library (For RGB LED's)
Post by: 6OPMEHTAJIb on Jan 23, 2011, 01:36 pm
Great project! It is possible to run LED cube (monocolor or RGB) on this code? In cube we need multiplex layers and address rows.