12 PWM Outputs From a Single ATtiny85
So what can you do with the humble and inexpensive ATtiny85? While it only features 5 GPIO pins (6 if you count the reset pin), David…
So what can you do with the humble and inexpensive ATtiny85? While it only features five GPIO pins (six if you count the reset pin), David Johnson-Davies shows that it’s possible to control 12 LEDs at a variety of brightness levels using one of these mini but mighty microcontrollers.
This was accomplished using a timer to generate an interrupt, with an interrupt service routine (ISR) that toggles each output as appropriate to produce the proper PWM output timing. By itself, this would allow for up to five PWM outputs. This build, however, takes things several steps further, using a technique called Charlieplexing to drive 12 LED outputs in a grid arrangement with only 4 I/O pins. This leaves a single ATtiny85 GPIO available for control, whether that’s via a sensor, serial input, or simply a button.
In the typical Technoblogy style, the whole project is laid out neatly on a small breadboard, with 12 red LEDs arranged in a circle. While this meant DJD wasn’t able to get the LEDs in the proper numerical order, he compensated for this in the program with an “Order[]” array function to make the circular arrangement sequence nicely. Since the ISR takes around 15ms to run on an 8MHz clock, the number of analog levels was restricted to 64, leaving the processor free to perform other tasks when its not interrupted to flash the LEDs.