Main Content

10-bit PWM from the ATtiny85

The ATtiny85 microcontroller has two 8-bit timers. Using them can be controlled dimming of LEDs. 8 bit is not enough if you want to have a brightness change adapted to the human eye. Gamma correction causes visible jumps in brightness, especially at low brightness. The ATtiny85 microcontroller can with timer 1 produce even better resolution. In this article, we’ll show you how to do it.

8-bit dimming
Here are some examples of LED dimmers I’ve created. But they all suffer the same defect. Jumps in brightness are visible at low brightness. You can see the examples with videos that make it very easy to see the defects.

LED strip dimmer with ATtiny85
1 W soft LED light
16-bit dimming
If you have a 16-bit timer microcontroller, LED dimming is easier. You only have to set the appropriate timer mode and the microcontroller will take care of everything. An example with higher bit resolutions can be found on these pages.

16-bit PWM resolution for Arduino
10-bit PWM from ATtiny85
Inspiration for this code I found on the Internet in the blog 10 or 12-bit DAC from the ATtiny85. The author describes the bit increasing technique in detail. It works in such a way that the timer 1 has specific features that allow it to be set to HIGH and LOW. With the interrupt at the appropriate intervals, the timer is set by first setting in one cycle to HIGH and in the following cycle to an 8-bit PWM value. The result is, for example, 512 values instead of 256. The article explains 10-bit and 12-bit resolution, but it does not differ much from this algorithm.”

Link to article