TLC5940 to PWM leds

Hi,
I'm working on a project to control the brightness of 8 high-power leds indepently using an Arduino and a TLC5940. Later I also want to add DMX input.
I have experience with programming, but only a little experience with electronics, so I still have some questions.

I am using this tutorial I found here to get started, and I have connected the TLC5940 like this:

GND - GND
VCC - 5V
SIN - Pin 2
BLANK - Pin 9 (TIMER1)
GSCLCK- Pin 11 (TIMER2)
XLAT - Pin 3
SCLCK - Pin 4
VPRG - Pin 5
DCPRG - Pin 6 (to program current limiter)

If I understand the tutorial correct, I can just leave XERR and SOUT disconnected?
And if I don't need the dot correction setting, I can just connect DCPRG to 5V?

The tutorial also doesn't mention IREF. From the pictures here it seems that this is connected to a resistor that is connected to GND?
In the datasheet I found a picture where a 640 Ohm resistor is connected, is this correct?
If I understand correctly, the current through this resistor is also applied to the outputs, so using 5V I can simply calculate the required resistor for the current that I need (and 640 ohm means only 8 mA)?

Also, is the DC programming just a linear value scale that current (so a value of 32 would mean half the current) or does it work differently?
In the beginning of the playground example, the DC is set to 3, so this means hardly any current will be delivered to the outputs?

I can understand most of the program, but the Timer part looks a little cryptic, and I haven't found any tutorials on how the timers should be set, can anyone give me a pointer to some more info?

Finally, if the outputs are indeed current-limited, I can just connect leds to it without a resistor?

Here's what my test setup looks like at the moment:

Small update: Reading further in the datasheet, I found out that the formula for the output current is
Imax = (1.24 / Riref) * 31.5
So when using 640 Ohm, that means 61mA on the outputs.

I also copied and changed a little the playground example, and I had to make 2 small changes to make it compile:
TOIE2A should TOIE2 and OCR2 should be OCR2A
This was already mentioned in another topic, but maybe someone could change this in the tutorial?

also: make sure you send 3.3V to the TLC5940 chip. If you send higher than 3.6V it will have a current-sink of 120ma

this was the main issue i had with this chip

I checked the datasheet again, and it says that the High-level input voltage should be at most Vcc.
If you connect 3.3V to Vcc, wouldn't the output pins from the Arduino still switch between GND and 5V?
Or was this no problem for you?

i didnt have problems with logic voltage of the arduino pins; the serial communication worked fine.

it was the supply voltage and the reference resistor that got in my way.

i.e. my chip would get really hot when i sent it 5v from the arduino, then i reread the data-sheet and sent it 3.3v from the arduino and it worked

go here:
https://whatever.metalab.at/user/wizard23/tlc5940/arduino/TLC5940/

and download the TLC5940 library; it's super simple to use and it works with the diecimila

go here:
https://whatever.metalab.at/user/wizard23/tlc5940/arduino/TLC5940/

and download the TLC5940 library; it's super simple to use and it works with the diecimila

Good, thank you, but it's don't work with an atmeaga8,
It's look work with atmega8 and 168 with this tips :
http://gonium.net/md/2007/04/18/tweaking-the-code/

Rémi

hello Nima

Your librairy look very good, I can compile it.
I have spend many time for try to understant it but I don't manage to use it

I have just understant where connects the pins enter arduino and the TLC5940 with the folow lines

//   SCLK_PIN  =  8
//   XLAT_PIN  =  9
//   BLANK_PIN = 10
//   GSCLK_PIN = 11
//   VPRG_PIN  = 12
//   SIN_PIN   = 13

// AVR pins:
#define TLCPORT PORTB
#define SCLK_PIN PB0
#define XLAT_PIN PB1
#define BLANK_PIN PB2
#define GSCLK_PIN PB3
#define VPRG_PIN PB4
#define SIN_PIN PB5

but in the datasheet it's say at the page 12 "Only 3 pins are needed to input data into the device"
and I don't understant why you use 6 pins and PORTB

Hi, I'm new. I'm a reasonable coder but very new to the electronics bit.

I'm also trying to interface a TLC5940 and having some trouble.

I have connected:-

Arduino TLC5940
GND GND
+5V VCC
+5V IREF
+5V DCPRG
DOUT8 SCLK
DOUT9 XLAT
DOUT10 BLANK
DOUT11 GSCLK
DOUT12 VPRG
DOUT13 SIN

And I have an LED between GND and an output pin on the TLC5940.

I'm using the class from https://whatever.metalab.at/user/wizard23/tlc5940/arduino/TLC5940/ with this code..

/*
  The TLC5940 library must be installed first:
  Copy (or symlink) the TLC5940 folder to <Arduino-dir>/hardware/libraries/
*/

#include <TLC5940.h>

// Parameter 1 is number of tlc5940 chips in series, 
// parameter 2 is number of grayscale bits per led.
TLC5940 leds(1, 8);

void setup()
{
  Serial.begin(115200);
  
  // FIXME: Pin allocation should be configures here
  leds.init();
  leds.clear(); // Clear framebuffer
  leds.display(); // Display framebuffer

  Serial.println("TLC5940 tester");
}

byte ledcounter = 0;
int intcounter = 0;

// Some super-simple test animation
void loop()
{
  leds.clear();
  intcounter++;
  if (intcounter > 255) intcounter = 0;
  for (byte i=0;i<16;i++) {
    leds.setLED(i, intcounter);
  }
  leds.display();
  delay(20);
}

But I get absolutely nothing happening. I'm at a bit of a loss as to how you go about debugging this sort of thing without an oscilloscope :slight_smile: Any pointers greatly appreciated.

Correction.. IREF is connected to ground via 1k resistor.

K. The answer was that I had made a foolish mistake. Perhaps this forum should feature a prompt every time you click "post" that asks "Are you sure you haven't made a foolish mistake?" :slight_smile:

I had it wired up as if the TLC5940 was going to source rather than sink the current. Swapped it round and it works fine.

Hi!

I used the above code and pinout and everything works perfectly, however I try to drive 3 TLC5940 and this proves more difficult.
I understood that the chips must be daisy chained like this: ARDUINO PIN13 > SIN - TCL1 - SOUT > SIN TCL2 SOUT > SIN TCL 3
I understood that all other pins from Arduino to TCL chips should be paralleled (so SCLK, XLAT, BLANK, GSCLK, VPRG are connected in parallel to the 3 TCL chips).

Then about the code. I modified this line : "TLC5940 leds(2, 8);" , so that it takes 3 chips, 8 bit pwm
Now I want to send the 48 channels 8bit values.
"for (byte i=0;i<48;i++) {
leds.setLED(i, 255);
}"

Well it blinks a few time. If I change i<16, then it works (even without modifying the TCL5940 declaration line, parameter 1 the number of chips) on the last chip in the chain.

Anybody succeded in daisy chaining TCL5940???

Thanks

go here:
https://whatever.metalab.at/user/wizard23/tlc5940/arduino/TLC5940/

and download the TLC5940 library; it's super simple to use and it works with the diecimila

Thanks, I got it working quite fast!

I also tried both 5V and 3.3V, but after about half an hour with 3 leds connected and about 600 ohm between Iref and GND it didn't feel warm at all.
My leds are glowing less intense though, but that might not be a problem since it will be used with transistors to switch high-power leds (350mA)

At the moment I still have a resistor between each of my leds and the tlc, but if I understand correctly this is not necessary since the tlc will limit the current? (and thus it won't be necessary to add a resistor when using it with transistors either?)

to the best of my knowledge: i dont think resistors for each LED is required either.

Thanks, now I have another question.
I want to use this chip with high power leds (350 mA)
So far I've found a LED driver that I think would be suited

But the problem is my electronics knowledge is not enough to know how to switch this using the TLC5940
I need a transistor for this I think, but I'm not sure what kind or which one. Someone I'm working with on this told be that this would be difficult because the TLC-5940 is current sink.

go here:
https://whatever.metalab.at/user/wizard23/tlc5940/arduino/TLC5940/

and download the TLC5940 library; it's super simple to use and it works with the diecimila

I realised yesterday that, while this library works very nicely, pins 0-15 on the NT package seem to come out in reverse order to the datasheet... i.e. if you do
leds.setLED(15, 255);
You actually set pin 0 not pin 15.

It's a minor point but it confused me for quite a while. I'm easily confused.

For anybody interested my problem was related to voltage/current provided by arduino board, the TLC5940 is very sensible to small variations, and when using 5V, arduino has not enough power for 2 TLC. Using 3.3V everything works fine.

Now I use ledstrips, 12V 240mA per strip. When I power them thru the TLC they are quite dimmed, even using the 32 Ohm resistor(to Iref) for maximum current output and powering the TLC with 5V. SO I have similar question to Adion, how to raise current. Obvious is to parallel the TLC outputs, but it doesn't work so nice that 2 outputs would double the current ouput, in my tests in raises the output by 10-20% only.

Yeah, I found out that the output numbers from the library are swapped as well.

@Jeromelab: I think the datasheet also mentions that the phase on the different outputs may be shifted, so that could explain why parallel connections don't work.

Anyway, I did find something interesting:

They are only about 70 eurocent for which you get 7 transistors with 50V max output voltage and 500mA max output current.
If you search on the product folder, you will notice that the TLC5940 is mentioned in the 'complementary product' section, so it looks like it is exactly what we need.
Unfortunately the datasheet doesn't mention how to use the 2 together, so we still have to find that out.

Well I guess you simply output TTL level pwm signals (so 5V) from the TLC directly to the inputs of the ULN2003 (or ULN2803 it makes more sense since it has 8 inputs/outputs, 2 of them for each TLC). But since TLC is outputing low side and ULN 2003 is expecting HIGH signals will it work?

Are you powering your LED array separately or from the power supply from Arduino?

I dont think arduino can power all the LED's alone, you should have a separate power for the LED;s, and just use arduino and TLC for active-low and completing the circuit.

That's what im doing and I havent had any problems yet.

(I'm also using IN4001 diodes to protect the chip and arduino)