Texas Instruments TLC5940

The TLC5940 is a 16 channel PWM unit with 12 bit duty cycle control (0 - 4095), 6 bit current limit control (0 - 63), and a daisy chainable serial interface. It is handy for expanding the number of PWM outputs available. The datasheet is available at http://www.ti.com/lit/gpn/tlc5940.

Some details about issues discovered using the chip and Eagle footprint for TLC5941: tlc594x and Arduino

Download the Arduino Library

The source/downloads for the library are on Google Code: http://code.google.com/p/tlc5940arduino/

Install

Unzip the Tlc5940 folder to <Arduino Folder>/hardware/libraries/

Getting Started

Open the BasicUse example in the Arduino IDE. It should be in File→Sketchbook→Examples→Library-Tlc5940.

Hardware Setup

Normal setup and wiring by [acleone]: png.

A hardware setup adding TIP122 transistors to the TLC5940 to achieve higher currents can be found here:here

Servos

The library can (as of r8) drive servos off the PWM channels. This means you can drive up to 16 servos at once, as well as use any spare channels for your other PWM needs! See File→Sketchbook→Examples→Library-Tlc5940→Servos for an example.

RGB LED

When using with RGB LEDs get LEDs with common anode. Common cathode will not work properly.

More Information

A full reference for the library

Link isn't working, so... Usage: Tlc.init(); Tlc.clear(); sets all the grayscale values to zero, but does not send them to the TLCs. To actually send the data, call Tlc.update() Tlc.update(); updates all pins Tlc.set(channel, value); channel is pin number. As of December 7, 2011, pin number just keeps going up as you go to more and more daisy-chained chips. So, if you have two chips, and you want to talk to the last pin on the second chip, you address it to channel 32. Like so: Tlc.set(32, x); x can be from zero to 4095. It appears that you have to tell the library how many chips you are using.

Also see this post in the forum for the latest information.


Older information

This doesn't pertain to the library above, but it's still helpful.

There are a couple of wrinkles to using one with an Arduino, but nothing that can't be overcome.

First, for a serial interfaced part it has a rather large number of signals. Fortunately we can ignore many of them if we wish.

  • XERR : open collector, wire or-ed output that lets you know a TLC5940 is over heated or has a burnt out LED. We can ignore this as it will always be on unless you have current using elements on all of the outputs.
  • SOUT: serial data out from the TLC5940. Unless you wish to try to read the error bits you do not need this to come to the Arduino. If you have more than one TLC5940 this is the line you daisy chain to the SIN of the next package.
  • DCPRG: this selects the source of the current limiter register, you could just tie it high.
  • XLAT: you will need this to latch data after shifting.
  • SCLK: you will need this to shift data.
  • SIN: serial in to TLC5940, this is the output from the Arduino.
  • VPRG: you need this to select either the current limit registers or the duty cycle registers for writing.
  • GSCLK: this is the clock for the PWM. We will reprogram TIMER2 in the Arduino to make this signal. That will cost us the native PWM on that timer, digital 11 on a mega8, 11 and 3 on a mega168.
  • BLANK: this marks the end of a PWM cycle in addition to blanking the output. We will reprogram TIMER1 to generate this signal. That will cost us the native PWMs on digital 9 and digital 10. (Tie a real, physical pull-up resistor on this line to keep things blanked while your Arduino boots. Depending on your hardware, it is possible that the TLC5940 would come up in a configuration that would dissipate too much power.)

What? Why are you taking away PWMs?

The GSCLK and BLANK signals need to be stable and accurate or the outputs of the TLC5940 will be erratic. By using the hardware timers we can make those be solid no matter what is going on in the sketch. Besides, it costs you 3 to 4 8 bit PWMs and gets you 16 to 640 12 bit PWMs. It's a fair trade.

Power? Did you just say "dissipate too much power"?

Yes. If you leave the current limiters wide open you shouldn't have a problem unless you are trying to light a room. Even then, probably not. But when you turn the current limiters down to the point that they are dropping significant voltage and you are running significant current you can overheat the package. There is a section in the datasheet on this, but if you don't want to worry about it then just set all the DC registers to 63 and stick your finger on the package now and again to see if it gets hot.

Servos

Hobby servos are driven by short, high, pulses every 10-40ms. The constants have been chosen in the following sample code to allow you to drive servos as well as LEDs or motors. Because the servos use high pulses and the TLC5940 is active low on the outputs the useful servo values are all at the upper end.

  • 3993, 0xf99: 500 microseconds
  • 3584, 0xe00: 1500 microseconds
  • 3168, 0xc60: 2500 microsecond

That will drive my cheap HS-311 through about 180 degrees. Do be careful not to hold your servo past its limits. It will probably use a lot of power and possibly burn up its motor if you try to hold it there. Remember: the outputs only sink current, you will want a pull-up resistor on here.

Motors

I suppose you can drive DC motors with this. Do put bypass diodes on your motor to protect the output stage of the TLC5940 from the inductive kick at motor turn off.

The Missing Part

This device has a nifty eeprom for storing the current limits so you could set that once then let it be. Unfortunately it takes a 22 volt level on VPRG to do that and I don't have one handy and wasn't about to make one, so I just ignore the eeprom. Good riddance. Saves me a pin.

For an older example of interfacing with this chip, see: OldCode

Share