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.
The multiplexing code even runs fast enough to create a 24-bit, gamma corrected, persistence of vision toy. Source code and schematics for this are also included in src.zip, under the code/rgb-pov and schematics/ directories respectively.
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.
Demystifying the TLC5940
|Selection||File type icon||File name||Description||Size||Revision||Time||User|
|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|