Software pulse width modulation

Pulse Width Modulation is a topic that tends to give a lot of beginners trouble. [Daqq], whose nixie plasma ball we covered a few days ago, has a simple but effective PWM project that you should take a look at. The circuit used 9 LEDs clustered together into 3 sets of RGB modules and connected them to an AVR ATtiny2313 through some current limiting resistors. Most of the time the PWM function of the AVR’s timers would be used to generate the signal but this application calls for 9 signals which is more than can be produced by this chip. The workaround is to generate the signals using software PWM.

Make sure you read up on PWM. Once you’ve got a good idea of what you’re trying to do, check out the code that [Daqq] included with his YALBlinkie project. When studying main.c from the project package, notice that a timer is running that periodically adjusts the duty cycle of each signal. Meanwhile the infinite loop within main constantly scans the output pins with the duty cycle values the timer is setting. This results in the amount of time the LEDs are illuminated being slowly changed, making them fade in and out.

I agree with you and I dont. the 8 bit binary calculator is fairly simple logic. it is a hack, to be sure, but this is actually much more useful, for the exact reasons stated… most chips only have a few PWM outputs, so it becomes necessary to utilize software.