RSS

Cascading TLC5940 LED Drivers

A while ago I created a circuit and some code to control the TLC5940 LED driver using a Netduino Mini. This chip allowed the programmer to control 16 LEDs using a serial interface. In the conclusions I noted that it should be possible to control two or more of these chips by cascading the serial output from one chip into another. This article discusses the additional hardware required along with the software to control up to 32 LEDs using two of these chips linked together.

It is assumed that you have read and understood the previous article before you proceed further.

Hardware

Linking two of these chips is a relatively simple affair and requires the LEDs you wish to control and only 1 additional component, namely a 2K2 ohm resistor, and some additional wire (assuming you are using breadboard).

Starting with the simplest part, the 2K2 ohm resistor connects the IREF pin on the second TLC5940 to ground. This sets the reference voltage for the LEDs connected to the second TLC5940.

The next part of the problem is to connect the two chips together. This is achieved by connecting the following pins:

TLC5940 (1)TLC5940 (2)
SCLKSCLK
BLANKBLANK
XLATXLAT
GSCLKGSCLK
VPRGVPRG
SOUTSIN
XERRXERR

DCPRG on TLC5940 is connected to Vcc as it is on the first driver chip and the LED controller pins connected to the appropriate LEDs.

This PDF (PWMLEDControlv0.03.pdf) contains the full circuit diagram showing the connections required.

Software

Now we have the additional LEDs in the circuit we will need to be able tell the software driver for the chips how many LEDs we want to control and then be able to control the brightness of the LEDs. In order to do this an additional parameter was added to the constructor numberOfLEDs. This parameter allows the system to work out how many TLC5940’s should be connected together. Once we have the number of chips calculated we can then work out the size of the buffers for the Dot Correction and the Grey Scale data.

The class uses two buffers for both the Dot Correction and the Grey Scale data. This may seem superfluous but doing this allows two different modes of operation:

  • Basic – The LEDs can be controlled using an interface which is simpler to use but is slower.
  • Fast – This mode is faster but requires the programmer to perform some of the tasks in the driver. The assumption here is that the programmer will have more understanding of the data which is changing and can therefore write more optimised code.

For the moment we will be discussing the basic mode. In this mode, the software driver hides much of the implementation and the user only really needs to perform three tasks:

  • Construct a new instance of the software driver.
  • Set the brightness of the LEDs (only the lower 12 bits are used).
  • Tell the driver to output the data to the TLC5940 chips.

Constructor

Making a new instance of the class in it’s most basic form is simply a case of telling the constructor how many LEDs you wish to control. In this case we have two TLC5940s connected together and so we have 32 LEDs:

Tlc5940 leds = new Tlc5940(numberOfLEDs: 32);

You can of course use the additional parameters to define the pins used for the various control signals or just use the defaults.

Setting a LED

The class contains a method which overloads the array indexing operator. Setting the brightness for a LED is simply a case of using this operator as follows:

leds[10] = 767;

This will set the brightness of LED 10 to the value 767.

An important note here is that the LEDs are numbered from 0 to 15 on the TLC5940 connected to the Netduino Mini, 16 to 31 on the next LED in sequence and so on.

Lighting the LEDs

The final piece of the puzzle is to output the data to the series of TLC5940s connected to the Netduino Mini. This is achieved by calling the Display method in the Tlc5940 class.

Source Code

The source code for the controller class and a simple main program can be found here (CascadedTLC5940.zip).

Conclusion

The work with this chip has not yet finished as there are still some points which need addressing in order to round off this class:

  • Dot Correction – this current outputs all 1’s and so there is no fine control for any of the outputs.
  • Error Detection and Status Information – It is possible to detect two types of errors and retrieve the status information from the TLC5940. This needs implementing.

One final item which needs addressing is to round off the code once these final feature have been implemented. A topic for another day.

Tags: , , ,

Wednesday, November 2nd, 2011 at 8:54 pm • Electronics, Netduino, Software DevelopmentRSS 2.0 feed Both comments and pings are currently closed.

Comments are closed.