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.
[youtube=http://www.youtube.com/watch?v=YAT7-fsnA4Q]
now that may be usefull. but the music on the video….
hi daqq
Excellent post! There is code that runs on a PIC18F4550 that I used about a year ago to perform a similar task. Suppose I should get the writeup finished.. ;)
hooray! hack a day is taking the “this isnt a hack” comments seriously!!! hardly any crap today!
also i think the dude put pinky and the brain on in the background himself, on purpose. it made me lol.
Pinky and the Brain was an excellent show
Pour a Bawls on the curb for fallen cartoon comrades
this is a hack.
The binary calculator is just as much if not more of a hack than this.
@Thomascpp
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.
Remove this if not within the rules but here is a good starting point with the AVRs. This is the first part in the series:
http://metku.net/index.html?path=articles/microcontroller-part-1/index_eng
lololololololol pinky and the brain.
Perhaps I should refer to this article whenever ppl bug me about my 2-year-old PWM demo video. Although mine used a PIC. Here it is again: http://www.youtube.com/watch?v=UufFRRQs1P0