Go Down

Topic: Library for TLC5940 16-channel PWM chip (Read 35 times) previous topic - next topic

acleone

#20
Sep 02, 2008, 11:10 pm Last Edit: Sep 02, 2008, 11:32 pm by acleone Reason: 1
[size=12]Updates: TLC5940LEDv004.zip[/size]

For people who want to use the TLC5940 to drive motors, use the old library from the first post for now.  The PWM period for the TLC5940LED library is fixed at 488Hz, which might be too fast for driving a DC motor.

Just as a note, the TLC should act as GND for whatever you're using with it (voltage should flow from +5V, through whatever, and into the TLC pin).  If you want to use RGB LEDs, make sure the LED is common anode (meaning each color shares the same +5V pin)

nphillips:
Code: [Select]
(unsigned long)      fadeDelay = millis() + random(5000, 15000);
The last parameter of Tlc.newFade is the start time in millis.  v004 has proper commenting in the examples (sorry)!

Also, if you need to run more than 5 fades at once (if you call newFade more than 5 times before while(Tlc.updateFades());), you need to add more parameters to Tlc.init.  For say 10 fades at once, use Tlc.init(1 tlc, 10 fades).  Tlc.newFade(...) will return false if you have too many fades running at once.

nphillips

Quote
nphillips:
Code: [Select]
(unsigned long)      fadeDelay = millis() + random(5000, 15000);
The last parameter of Tlc.newFade is the start time in millis.  v004 has proper commenting in the examples (sorry)!
Ah hah! I suppose if I paid closer attention to your example, too, it would have been obvious. (testfades002 is what I used to help construct my code)

Quote
Also, if you need to run more than 5 fades at once (if you call newFade more than 5 times before while(Tlc.updateFades());), you need to add more parameters to Tlc.init.  For say 10 fades at once, use Tlc.init(1 tlc, 10 fades).  Tlc.newFade(...) will return false if you have too many fades running at once.
Is there an upper bound to this? Rather, will it break if I try to have it run a boat-load of fades? (I may end up looking at 32+ LEDs for one project....)

acleone

Quote
Is there an upper bound to this? Rather, will it break if I try to have it run a boat-load of fades? (I may end up looking at 32+ LEDs for one project....)

Each fade takes up 12 bytes of the 1024 byte SRAM.  I don't know how much SRAM is used normally, but I'm guessing you could have like 64 fades (768 bytes) at once.  Just keep trying higher values until something breaks!

But that's only running at once; if some finish and you want to start more, you could do something like
Code: [Select]

// create a bunch of fades
Tlc.newFade(...);
Tlc.newFade(...);
Tlc.newFade(...);
...
while (Tlc.updateFades()) {
 if(Tlc.newFade(...)) {
   // added successfully!
 } else {
   // too many fades right now
 }
}


nphillips

That worked perfectly, acleone!

Once again, thanks for the amazing library, and quick, helpful responses!

Now, I just need to buy more LEDs...  :o

Syvwlch

Quote

For people who want to use the TLC5940 to drive motors, use the old library from the first post for now.  The PWM period for the TLC5940LED library is fixed at 488Hz, which might be too fast for driving a DC motor.


As far as those 3V/80mA Sparkfun vibration motors are concerned, they seem to run fine at 500Hz, ramping up and down smoothly, based on prior experience. Alas, I won't be able to confirm with the TLC5940 for at least two weeks (vacation).

Quote

Just as a note, the TLC should act as GND for whatever you're using with it (voltage should flow from +5V, through whatever, and into the TLC pin).  


Thanks for the pointer. Turns out that's how I had it wired in the old setup (PWM pins on the low side) but now I'll make sure to carry it over to the TLC5940 setup.
----------
Mathieu

Go Up