Demystifying the TLC5940

A free book and 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.

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: