# TLC5940 to PWM leds

**URL:** <https://forum.arduino.cc/t/tlc5940-to-pwm-leds/17406>\
**Category:** Interfacing\
**Created:** [February 29, 2008, 1:48pm UTC](https://forum.arduino.cc/t/tlc5940-to-pwm-leds/17406 "2008-02-29T13:48:22Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [February 29, 2008, 1:48pm UTC](https://forum.arduino.cc/t/tlc5940-to-pwm-leds/17406/1 "2008-02-29T13:48:22Z")

</div>

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](http://www.arduino.cc/playground/Learning/TLC5940) 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](http://pixelriot.com/pmatp/node/15) 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:  
[![](https://europe1.discourse-cdn.com/arduino/original/4X/7/c/a/7cab8f83509b36972eedcea97950c2b8e62d6efc.jpeg)](http://photo.djdecks.be/photos/large/1697/dscf0726.jpg)

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [February 29, 2008, 3:47pm UTC](https://forum.arduino.cc/t/tlc5940-to-pwm-leds/17406/2 "2008-02-29T15:47:41Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 1, 2008, 8:11am UTC](https://forum.arduino.cc/t/tlc5940-to-pwm-leds/17406/3 "2008-03-01T08:11:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 1, 2008, 9:06am UTC](https://forum.arduino.cc/t/tlc5940-to-pwm-leds/17406/4 "2008-03-01T09:06:15Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 1, 2008, 11:34pm UTC](https://forum.arduino.cc/t/tlc5940-to-pwm-leds/17406/5 "2008-03-01T23:34:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 2, 2008, 9:03pm UTC](https://forum.arduino.cc/t/tlc5940-to-pwm-leds/17406/6 "2008-03-02T21:03:00Z")

</div>

go here:  
[https://whatever.metalab.at/user/wizard23/tlc5940/arduino/TLC5940/](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

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 3, 2008, 4:42pm UTC](https://forum.arduino.cc/t/tlc5940-to-pwm-leds/17406/7 "2008-03-03T16:42:13Z")

</div>

> go here:  
> [https://whatever.metalab.at/user/wizard23/tlc5940/arduino/TLC5940/](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/](http://gonium.net/md/2007/04/18/tweaking-the-code/)

Rémi

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 6, 2008, 3:13pm UTC](https://forum.arduino.cc/t/tlc5940-to-pwm-leds/17406/8 "2008-03-06T15:13:37Z")

</div>

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

```cpp
//   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

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 6, 2008, 11:36pm UTC](https://forum.arduino.cc/t/tlc5940-to-pwm-leds/17406/9 "2008-03-06T23:36:55Z")

</div>

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/](https://whatever.metalab.at/user/wizard23/tlc5940/arduino/TLC5940/) with this code..

```arduino
/*
  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 🙂 Any pointers greatly appreciated.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 7, 2008, 12:03am UTC](https://forum.arduino.cc/t/tlc5940-to-pwm-leds/17406/10 "2008-03-07T00:03:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 8, 2008, 12:15am UTC](https://forum.arduino.cc/t/tlc5940-to-pwm-leds/17406/11 "2008-03-08T00:15:21Z")

</div>

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?" 🙂

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.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 13, 2008, 7:32pm UTC](https://forum.arduino.cc/t/tlc5940-to-pwm-leds/17406/12 "2008-03-13T19:32:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 16, 2008, 7:46pm UTC](https://forum.arduino.cc/t/tlc5940-to-pwm-leds/17406/13 "2008-03-16T19:46:56Z")

</div>

> go here:  
> [https://whatever.metalab.at/user/wizard23/tlc5940/arduino/TLC5940/](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?)

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 16, 2008, 9:19pm UTC](https://forum.arduino.cc/t/tlc5940-to-pwm-leds/17406/14 "2008-03-16T21:19:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 19, 2008, 11:33pm UTC](https://forum.arduino.cc/t/tlc5940-to-pwm-leds/17406/15 "2008-03-19T23:33:10Z")

</div>

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

> **[nud4001-d.pdf](https://www.onsemi.com/pdf/datasheet/nud4001-d.pdf)**

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.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 20, 2008, 1:59am UTC](https://forum.arduino.cc/t/tlc5940-to-pwm-leds/17406/16 "2008-03-20T01:59:15Z")

</div>

> go here:  
> [https://whatever.metalab.at/user/wizard23/tlc5940/arduino/TLC5940/](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.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 20, 2008, 11:08am UTC](https://forum.arduino.cc/t/tlc5940-to-pwm-leds/17406/17 "2008-03-20T11:08:39Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 20, 2008, 1:01pm UTC](https://forum.arduino.cc/t/tlc5940-to-pwm-leds/17406/18 "2008-03-20T13:01:50Z")

</div>

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:

> **[ULN2003A data sheet, product information and support | TI.com](https://www.ti.com/product/ULN2003A?utm_source=supplyframe&utm_medium=SEP&utm_campaign=not_alldatasheet&DCM=yes&dclid=CjgKEAjw7aqkBhDu2fr-zaPbqjQSJACyEyznCjQIUP5UbjhGTMYeOM2wodmrNwHcSmQi6X0TLBAuUfD_BwE)**
>
> TI’s ULN2003A is a 50-V, 7-ch darlington transistor array, -20C to 70C. Find parameters, ordering and quality information

> **[uln2003ai.pdf](https://www.ti.com/lit/ds/symlink/uln2003ai.pdf)**
>
> 1625.25 KB

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.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 20, 2008, 4:14pm UTC](https://forum.arduino.cc/t/tlc5940-to-pwm-leds/17406/19 "2008-03-20T16:14:07Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 20, 2008, 5:38pm UTC](https://forum.arduino.cc/t/tlc5940-to-pwm-leds/17406/20 "2008-03-20T17:38:08Z")

</div>

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)

[Next page](https://forum.arduino.cc/t/tlc5940-to-pwm-leds/17406.md?page=2)
