Navigation

Demystifying the TLC5940

A free book/library by Matthew T. Pandina

This book explains how to turn the datasheet and application notes for the TLC5940, a 16 channel LED driver with dot correction and grayscale PWM control, into an unencumbered C library for use with an AVR microcontroller. This library uses the CLKO pin of the AVR to drive the GSCLK line of the TLC5940, which allows grayscale values to be updated at 3906.25 Hz with a CLKI/O of 16 MHz, and 4882.8125 Hz with a CLKI/O of 20 MHz.

The first project in the book guides you through creating a reference implementation based on the official TLC5940 programming flowchart. The subsequent projects build upon this implementation, first refactoring it to be ISR-based, then optimizing it to use hardware SPI, then adding features, and finally turning it into a fully functional library, which can be reused for multiple projects.

The sample code was written for the AVR-GCC compiler and tested with an ATmega328P, but it should be easily modified to work with other compilers and/or microcontrollers.

Also available is a zip file with the complete source code for every project in the book, along with schematics and Makefiles.

10/1/2011: I haven't updated the book yet, but I added (configurable) multiplexing support to the library. You can use either common cathode or common anode RGB LEDs. Download src.zip and look inside code/ch9 for the updated library, and demonstration code.

1/8/2011: I updated the src.zip with the new multiplexing code, which is much faster than the previous version. Client code should not need modification, unless it previously depended on the internal structure of the grayscale data, which has changed. Unless you are bypassing the API functions to directly set the grayscale values with memcpy (like the rgb-pov example does) this should not affect you. The code in rgb-pov/software/ that turns a PNG file into a data.c file has been updated to generate files that conform to this new internal format.