Demystifying the TLC5940
A free book by Matt Pandina
About four months ago I started writing a tutorial, which ended up getting so large that it turned into a book. In the process of writing the book, I taught myself how to use LaTeX, and then gEDA to make the schematics.
Demystifying the TLC5940 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 CLK_IO of 16 MHz, and 4882.8125 Hz with a CLK_IO 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.
Here is a photo of the persistence of vision toy I created using the library:
I used three TLC5940 chips, and four 10-segment LED bargraphs.
Even if you have no interest in learning about the TLC5940, you may still find this book useful, as I tried to cover the general process of turning a datasheet into code, along with pitfalls I encountered along the way.
I am very eager for feedback, so let me know what you guys think!