Library for TLC5940 16-channel PWM chip

Cool! Thanks! 16 is sufficient for my next project.

This library is fantastic. I've slowly been daisy-chaining chips together (as I'm something of a newbie) , and this explains why I can't get past 16 chips. If you're honestly interesting in making a custom version of the library, a version that supports 20 TLCs would be great...

I have to finish the web site with all the construction details.

I saw that you did. I really enjoy the way you explain your works. Nice, clear and clean!

Happy Thanksgiving! Have an update: Tlc5940_latest.zip

2008-11-26

  • Tlc.init() sets all channels to zero and updates.
  • Added TLC_PWM_PERIOD and TLC_GSCLK_PERIOD to tlc_config.h
  • Added TLC_CHANNEL_TYPE to tlc_config.h - Now the library supports 4096 TLCs! (if TLC_CHANNEL_TYPE is uint16_t)
  • Changed the examples to use TLC_CHANNEL_TYPE
  • set DATA_TRANSFER_MODE default to TLC_SPI

Since the DATA_TRANSFER_MODE is now TLC_SPI, be sure to change your hardware setup (or just set it back to TLC_BITBANG in tlc_config.h, then delete Tlc5940.o):

  • Arduino Digital Pin 11 (used to be pin 8) -> TLC pin 26
  • Arduino Digital Pin 13 (used to be pin 7) -> TLC pin 25

Thnx acleone for many updates!

Anybody tried the lastest version of library? 'cause mine doesn't work. only the first TLC5940 chip works (and it gets hot) but others brink pseudo-randomly. It worked fine with the previous versions.

for checking : The library is for arduino-0012, isn't it?
for checking : What I have to change is just reordering pin settings?

sorry. I forgot to delete tlc5940.o file. it seems work fine until now!
thnx!

does this only work on the arduino with a atmega168 ? or will it work on my older atmega8 board ?

Here's an Atmega8 version: Tlc5940__Atmega8_latest.zip

(I should have probably used preprocessor directives, but then I would have had to change all my horrible pin-out diagrams). Tell me if it works! The BasicUse example has hardware setup.

cool, thanks for that. I'll give it a shot over the weekend. I'll give you feedback.

Thanks again :slight_smile:

wanted to give a big thank you for the library, i look forward to using it soon.

It's been a while since I did something with an arduino. So, I might be missing something. Also, I haven't used this library before.
I try to get more than 1 led burning at a time. If I understand it right the "usingprogmem.pde" example should do this, right? but I don't see anything happening. The "basicuse.pde" example works, everything else seems to fail. What do I overlook?

Hi,

Is it possible to use this library with the same pinout as for the old code in the playground page?

That is:
TLC | Arduino

SIN -- D3
SCLK -- D4
XLAT -- D5
BLANK -- D9
GSCLK -- D11

I have a board that is wired like this, and I would like to use it with the new library.

I see that the pins are defined in tlc_config.h, but I am not sure how flexible is the library code to accept the mapping as above.
It is OK for me to use BITBANG mode for serial (which I think will be the only option in this case, isn't it?).

Many thanks,

I try to get more than 1 led burning at a time. If I understand it right the "usingprogmem.pde" example should do this, right?

The UsingProgmem example sets all the LEDs at once. If you want to turn on more than 1 LED, just use Tlc.set(channel, value);

/* Turn on channels 0-5 */
Tlc.set(0, 4095);
Tlc.set(1, 4095);
Tlc.set(2, 4095);
// ...
Tlc.update();

/* or use a loop: */
for(int i = 0; i <= 5; i++) {
  Tlc.set(i, 4095);
}
Tlc.update();

Is it possible to use this library with the same pinout as for the old code in the playground page?

Unfortunately not, because GSCLK, BLANK, and XLAT are driven by timers (the PWM outputs), so they can't be changed.

On the other hand, SIN and SCLK can be changed to anything in bit-bang mode.

Hi,

Unfortunately not, because GSCLK, BLANK, and XLAT are driven by timers (the PWM outputs), so they can't be changed.

well, the old code in the playground also uses timers1 and 2, but on pins 9 and 11, that's why I was hoping to be able to remap the pins for your library...

any hope?

thanks.

This library uses timer 1 (XLAT on pin 9, BLANK on pin 10, which could easily be switched to 10/9) and timer2 (GSCLK on pin 3, which could be switched to pin 11).

The old library uses timer2 for GSCLK, timer1 for BLANK, and timer0 for XLAT. It would be possible to switch XLAT to any pin but it violates the the timing in the TLC datasheet (everything should still work ok though). If you want to try it, open Tlc5940.cpp and add

      XLAT_PORT |= _BV(XLAT_PIN);
      XLAT_PORT &= ~_BV(XLAT_PIN);

at the beginning of the ISR on line 71.

As for switching GSCLK to pin 11, (which is OC2A), change:

  • TLC_GSCLK_PERIOD (line 181) in tlc_config.h to 1
  • Add _BV(COM2A0) to TCCR2A = ... on line 150 of Tlc5940.cpp and delete _BV(COM2B1)

I have no idea if this will work - does anyone know if can you set a compare match toggle on OC2A if the timer2 TOP is defined to be OCRA?

The UsingProgmem example sets all the LEDs at once. If you want to turn on more than 1 LED, just use Tlc.set(channel, value);

Well, the UsingProgmem example doesn't work for me. And I tried this as a simple example:

void loop()
{
  int channel = 0;
  while (channel < 11)
  {
    Tlc.clear();
    Tlc.set(channel, 4095);
    Tlc.set(channel+1, 4095);
    Tlc.update();
    delay(500);
    channel++;
  }
}

No LED lights up. Should this work on USB power? Or do I need a powersupply. I don't remember using a powersupply with the older TLC library's but, again, it has been while since I played with it.

This library uses timer 1 (XLAT on pin 9, BLANK on pin 10, which could easily be switched to 10/9) and timer2 (GSCLK on pin 3, which could be switched to pin 11).

The old library uses timer2 for GSCLK, timer1 for BLANK, and timer0 for XLAT. It would be possible to switch XLAT to any pin but it violates the the timing in the TLC datasheet (everything should still work ok though). If you want to try it, open Tlc5940.cpp and add

So is the stuff in the playground the old or the new stuff? Is the pinouts in the text file in the playground correct and up to date please?

Everything above "Older information" on the playground page is up to date. Make sure you have the latest library version. The latest version will always be available here.

Be sure to check your hardware setup: it's easy to forget to connect DCPRG (TLC pin 19) to +5V and VPRG (TLC pin 27) to GND.

As for running off USB power, it depends on how many LEDs you have connected; I wouldn't connect more than ~20 LEDs.

Thanks

Hey All!

As this is my first post, I thought I'd ask a nice easy question :slight_smile:

Is it possible to connect 3 tlc5940's to an arduino in parallel (i.e. all 3 use the same XLAT, BLANK, GSCLK, and SCLK but with separate SIN lines) so I can control an RGB LED matrix potentially more efficiently?

Basically I'm looking to make a 16x16 RGB LED panel to display animations / low res graphics from something like Processing - and I was thinking the number of columns I would need to multiplex (16) might be a bit too many if I have to shift out 192*3 bits per row.

Hence if I could simultaneously shift out 192 bits to 3 tlc5940's at once that would potentially increase my refresh rate by a factor of 3!

Any thoughts / ideas?

(Ps. I realise that this may mean instantiating 3 separate Tlc classes - but I can find no examples anywhere of this being done, and I don't want to run into problems with the pre-instantiated one.)

Thanks guys! :slight_smile: