Software pulse width modulation
posted Sep 17th 2009 2:00pm by Mike Szczysfiled under: led hacks
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.
Because ATtiny2313's are very inexpensive, this is a great way to jump into using the AVR line of microprocessors. You will need a programmer but there are ways of using an Arduino to program these chips. To learn more about timer interrupts and how these chips work, check out the tutorial section over at AVR freaks. Also take a look at the avr-libc documentation for an explanation of how to fix the deprecated sbi and cbi commands in [Daqq's] code.
Go there and see video...http://hackaday.com/2009/09/17/software-pulse-width-modulation/
Don
No comments:
Post a Comment