Demystifying the TLC5940

A free book/library by Matthew T. Pandina

This book explains how to turn the datasheet and application notes for the Texas Instruments 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 in the book was written for the AVR-GCC compiler and tested with an ATmega328P, but it can 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. Source code and schematics for a 24-bit, gamma corrected, persistence of vision device are also included in, under the code/rgb-pov and schematics/ directories respectively.

The latest source code for the TLC5940 library that contains optimizations, features, and chipset support beyond what is explained in the book is now hosted on my GitHub account.

Additional features include:
  • faster multiplexing
  • multiplex with common cathode or common anode RGB LEDs
  • ATmega328 or ATtiny85 support

One of the schematics from this book has even been included in an official application note for the TLC5940 provided by Texas Instruments!

Examples of the library being used in my projects:
SelectionFile type iconFile nameDescriptionSizeRevisionTimeUser
View Download
Free book  628k v. 9 Aug 1, 2011, 10:52 PM Matt Pandina

Complete source code listing for every project in the book, along with schematics and Makefiles. Now includes multiplexing code, and examples!  295k v. 21 Jan 8, 2012, 12:07 AM Matt Pandina