Welcome, Guest. Please Login or Register
YaBB - Yet another Bulletin Board
09.02.2010 at 18:03:57
News: Server upgrade went fine, you are now at the new system


Pages: 1 2 3 ... 16
Library for TLC5940 16-channel PWM chip (Read 62234 times)
acleone
Junior Member
**
Offline

Arduino rocks my
socks

Posts: 81
Seattle, WA
Library for TLC5940 16-channel PWM chip
08.08.2008 at 06:47:37
 
The TLC5940 is a 16-channel, constant-current sink LED driver.  Each channel has an individually adjustable 4096-step grayscale PWM brightness control and a 64-step, constant-current sink (no LED resistors needed!).

This library supports daisy-chaining multiple chips together.  I haven't tried this library on anything but a Diecimila, so YMMV.

The most useful functions:
Tlc.analogWrite(channel (0 - 15), value (0 - 4095), chip (0 - n));
Tlc.analogWriteAll(value (0- 4095), chip (0 - n));
Tlc.setPWMperiod(PWM period (0 - n) milliseconds);

TLC5940.zip:
http://students.washington.edu/acleone/codes/arduino_TLC5940_library/TLC5940.zip...

Browse the library:
http://students.washington.edu/acleone/codes/arduino_TLC5940_library/TLC5940/

In progress: TLC5940 Servo Library


Change log:

v001 - 08-08-08: Cleaned everything up a bit.  Renamed stopPWM() to stopTimers() and made a resetTimers().  Added a setPWMuPeriod(uPeriod) for setting the PWM period in microseconds.  Changed readXERR() to return 1 if there is an error (LED shorted/broken), 0 otherwise.
Back to top
 
« Last Edit: 08.08.2008 at 19:59:35 by acleone »  
View Profile | WWW   IP Logged
acleone
Junior Member
**
Offline

Arduino rocks my
socks

Posts: 81
Seattle, WA
Internals
Reply #1 - 08.08.2008 at 17:02:58
 
A bit more on how this library is using Timer1 and Timer2 to run GSCLK and BLANK:

The PWM on the TLC5940 works by counting the number of GSCLK pulses; a setting of 2048 will mean the LED stays on for 2048 pulses and then turns off for the rest of the cycle.  After 4096 pulses, the counter needs to be reset by a pulse on BLANK.  In the library, I'm using Timer2 to generate the GSCLK pulses and Timer1 to generate the BLANK pulse.
Back to top
 
 
View Profile | WWW   IP Logged
lwhi
YaBB Newbies
*
Offline

Arduino rocks

Posts: 24

Re: Library for TLC5940 16-channel PWM chip
Reply #2 - 08.08.2008 at 19:43:47
 
My god - thanks, this is great... I've just ordered some of these from TI, and have been reading through the data-sheet trying to come up with a plan of attack.
Back to top
 
 
View Profile   IP Logged
nphillips
Junior Member
**
Offline

Slowly Developing

Posts: 68

Re: Library for TLC5940 16-channel PWM chip
Reply #3 - 20.08.2008 at 19:30:22
 
I'm trying to fade multiple LEDs, independently, and at different rates. Is it possible to have the TLC5940 (or the arduino, for that matter) to run a series of "analogWrite" commands independently?

In other words, send one "fade channel0 from 4095 to 0 in 5000ms" and, before it's finished, send "fade channel1 from 0 to 4095 in 2500ms".

I know I could chain them together, so that as soon as channel0 finishes its fade, channel1 would begin...but that's not what I'm aiming for.
Back to top
 
 
View Profile   IP Logged
melka
Senior Member
****
Offline



Posts: 363
Grenoble/Lyon - France
Gender: male
Re: Library for TLC5940 16-channel PWM chip
Reply #4 - 20.08.2008 at 20:43:31
 
sooo many thanks ^^
Back to top
 
 
View Profile | WWW | MSN   IP Logged
acleone
Junior Member
**
Offline

Arduino rocks my
socks

Posts: 81
Seattle, WA
Re: Library for TLC5940 16-channel PWM chip
Reply #5 - 22.08.2008 at 02:04:42
 
nphillips wrote on 20.08.2008 at 19:30:22:
I'm trying to fade multiple LEDs, independently, and at different rates. Is it possible to have the TLC5940 (or the arduino, for that matter) to run a series of "analogWrite" commands independently?

In other words, send one "fade channel0 from 4095 to 0 in 5000ms" and, before it's finished, send "fade channel1 from 0 to 4095 in 2500ms".

I know I could chain them together, so that as soon as channel0 finishes its fade, channel1 would begin...but that's not what I'm aiming for.


I'm writing some improvements this weekend that changes to the way the library handles the BLANK pulses, and I think it would be pretty easy to add fading too:
1. When we pulse BLANK, check to see if any fades should happen, and calculate the PWM output
2. set an "updated" flag or something to let the user know they should call updatePWMs(). <- I don't think you could call updatePWMs() in 1. because it would put too much code in an interrupt, breaking Serial and stuff

The changes I'm making to the way BLANK pulses:
- Instead of outputting BLANK as a PWM on TIMER1, use TIMER1 to count GSCLK pulses and call an interrupt to pulse BLANK.
Back to top
 
 
View Profile | WWW   IP Logged
nphillips
Junior Member
**
Offline

Slowly Developing

Posts: 68

Re: Library for TLC5940 16-channel PWM chip
Reply #6 - 22.08.2008 at 18:34:54
 
Nice! I think I understand what you're talking about...but not really  Huh I'm new to all of this

Thanks for all of your work, acleone! I'm eager to see what changes you're able to make over the next few days!
Back to top
 
 
View Profile   IP Logged
acleone
Junior Member
**
Offline

Arduino rocks my
socks

Posts: 81
Seattle, WA
Re: Library for TLC5940 16-channel PWM chip
Reply #7 - 22.08.2008 at 18:51:13
 
woot! Ti shipped me more TLC5940 samples today!

The project that I've been working on is building a 4096^3-colors version of SpokePOV that uses a secure-digital card for storage, so full video should be possible.
Back to top
 
 
View Profile | WWW   IP Logged
lwhi
YaBB Newbies
*
Offline

Arduino rocks

Posts: 24

Re: Library for TLC5940 16-channel PWM chip
Reply #8 - 22.08.2008 at 20:17:50
 
Your project sounds impressive - does that mean you'll be controlling 3x30 led outputs?  are you going to need 6 TLC5940 to control the lot - or is it possible to multiplex the TLC5940 output pins?
Back to top
 
 
View Profile   IP Logged
acleone
Junior Member
**
Offline

Arduino rocks my
socks

Posts: 81
Seattle, WA
Re: Library for TLC5940 16-channel PWM chip
Reply #9 - 22.08.2008 at 21:52:53
 
lwhi wrote on 22.08.2008 at 20:17:50:
Your project sounds impressive - does that mean you'll be controlling 3x30 led outputs?  are you going to need 6 TLC5940 to control the lot - or is it possible to multiplex the TLC5940 output pins?


I wasn't planning on multiplexing, so at least 6.  I'm assuming that a single rotation of the wheel will have ~30 PWM periods, which means one image is (24 bytes per tlc)*(6 tlc's)*(30 periods) = 4.32KB.  That comes out to ~231 frames per 1MB of SD card space.
Back to top
 
 
View Profile | WWW   IP Logged
acleone
Junior Member
**
Offline

Arduino rocks my
socks

Posts: 81
Seattle, WA
Re: Library for TLC5940 16-channel PWM chip
Reply #10 - 29.08.2008 at 02:45:49
 
I'm not done commenting yet, but if anyone wants to test out the latest beta, you can download it here: TLC5940LEDv003.zip

A few of the changes:
  • See TLC5940LED_pins.h for the pin setup.
  • Added fading functionality: Tlc.newFade(channel, ms duration, start value, end value, when to start).  See the examples.
  • Added the ability to play animations from program memory (14kB!) .  See the examples again.
  • See TLC5940LED.h for all the function name changes

I'll release a finished version soon which will include an animation creator to make animations.
Back to top
 
 
View Profile | WWW   IP Logged
nphillips
Junior Member
**
Offline

Slowly Developing

Posts: 68

Re: Library for TLC5940 16-channel PWM chip
Reply #11 - 29.08.2008 at 19:40:38
 
You may have just ruined my weekend, acleone!

I'm at work, and don't have my arduino here to play with (and if I did, I'd probably get in trouble  Cheesy), but I can't wait to get home to try this stuff out. It looks exactly like what I wanted it to do.

You're awesome!

EDIT: WOW! I took a look at the code and examples, and if I'm understanding it right, it looks like you've really done some fantastic work. Now I want to try and leave work early!
Back to top
 
 
View Profile   IP Logged
RobotGuy
YaBB Newbies
*
Offline

Arduino rocks

Posts: 21

Re: Library for TLC5940 16-channel PWM chip
Reply #12 - 01.09.2008 at 07:08:05
 
[color=#666699][/color]acleone wrote on 29.08.2008 at 02:45:49:
A few of the changes:
  • See TLC5940LED_pins.h for the pin setup.
  • Added fading functionality: Tlc.newFade(channel, ms duration, start value, end value, when to start).  See the examples.
  • Added the ability to play animations from program memory (14kB!) .  See the examples again.
  • See TLC5940LED.h for all the function name changes
I'll release a finished version soon which will include an animation creator to make animations.

This is excellent! I have a bunch of the TLC5940's here and have been wanting to tinker and see what I can do with them.  One thing I want to do is use 3 of these for a 16 channel RGB LED controller. Thank you very much for making chips like the TLC5940 easier for us to use!  Smiley Smiley

8-Dale
Back to top
 
 
View Profile   IP Logged
macegr
God Member
*****
Offline

Arduino Ninja

Posts: 689

Re: Library for TLC5940 16-channel PWM chip
Reply #13 - 01.09.2008 at 09:39:19
 
At 10mph you're getting about 2 revolutions per second. With a single spokepov, that's too flickery to be called a persistent image. You'll probably want three spokes, and that only gets you the equivalent of a 6Hz update. And then both sides...and then two wheels. That's a lot of TLC5940s. 72 of them, actually.

You might not be happy with the brightness control. It's PWM, which will be visible on a moving LED. If you can achieve a 5MHz grayscale clock, you get almost 10 full PWM cycles for each of the 256 radial slices. That might be enough to not confuse the image you're trying to generate.

I know a guy who makes POV displays that have variable brightness, and he's actually using a simple resistor DAC for 3 bit brightness control on each LED. This doesn't use pulses to vary the apparent brightness, so it doesn't disrupt the virtual pixels on the POV display.
Back to top
 
 
View Profile | WWW   IP Logged
Syvwlch
Full Member
***
Offline

Ard at work

Posts: 192
New Jersey
Gender: male
Re: Library for TLC5940 16-channel PWM chip
Reply #14 - 01.09.2008 at 13:42:35
 
Thanks for the library!

I'm going to get my hands on a sample TLC5940 and try it, it seems like the perfect solution to drive 16 small vibe motors (haptic hatband, don't ask Smiley ) with that 120mA per output rating!
Back to top
 
 
View Profile | WWW   IP Logged
Pages: 1 2 3 ... 16