Go Down

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

bigengineer

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?

gonp

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,

acleone

Quote
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);
Code: [Select]
/* 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();


Quote
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.

gonp

Hi,

Quote
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.


acleone

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
Code: [Select]
     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?

bigengineer

Quote


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:
Code: [Select]
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.

Mike Mc

Quote
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?

acleone

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.

Mike Mc


Jon Lee

Hey All!

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

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! :)

acleone

It would be possible, but it is definitely not more efficient.  This is because data is shifted out via the hardware SPI module, which runs at 8MHz (or 1 bit every two clock cycles)!  At first thought, it seems like it would be faster to set up three different data lines and clock them at the same time, but just to set up each line it takes an AND and CP (2 clock cycles) for each bit, then a clock pulse will be 2 cycles, etc.  The dedicated hardware will be much faster than the software implementation.

The library's default display cycle is 976.5625Hz.  For the entire display this would be a frame rate of 61.035Hz.

Your limiting factor will definitely be the serial data transfer rate.  One refresh takes 12*3*16*16 = 9216 bits.  If you use the fastest serial speed, 115200, and account for the start/stop bit, you could deliver 92160 bits/sec, or 10 frames per second.  There will be some processing overhead, even if the serial data went straight out to the tlc's, so realistically it would be ~8Hz.

See this thread for a similar project with an 8x8 grid.

About instantiating three separate instances; it won't work because the library just has one data buffer.

Mike Mc

Please help. I have downloaded the latest library but I get this error message when running some test code....

In function 'void loop()':
error: 'class Tlc5940' has no member named 'newFade'

acleone

I haven't implemented fading after I redid the library a while back.

Here's all the functions in the library currently:
[olist]

Mike Mc



Go Up