[Dane] sent in his sweet AVR hack. He used the PWM output to play pre-recorded audio output. It’s not very high quality, but it could be useful for adding low cost audio feedback to your projects.
13 thoughts on “PWM Audio Generation With An AVR”
Leave a Reply
Please be kind and respectful to help make the comments section excellent. (Comment Policy)
Go Dane! You’re the man!
had the same idea when i made my AT-AT Lego Robot controled by an ATM Mega8 ( http://youtube.com/watch?v=s9pL9znb0SU ) for a school project, but didn’t knew how to do that… now it’s to late, but never the less a cool hack ;)
Awesome walker robot. genorating 4 seperate servo channels musthave consumed quite a bit of the available space. If your still tinkering with lots of servos, there’s a pretty cool routine in bascom-avr (basic compiler) called “config servos”, and after configuration, you can just write:
servo(1)= variable. as you can guess, its sets the servo to that value. link to pdf:
http://www.mcselec.com/index.php?option=com_docman&task=doc_download&gid=140&Itemid=54
hope any of that helped,
keep tinkering
@ Dane
yeah, the source code was pretty hard to design, cause i wrote it with AVR Studio 4 (and its build-in compiler). If i would have used the C/++ compiler, it would have been much easier to write the code, ’cause of the ability to create for-loops much more easily, instead of inserting jumps, adds, if-like-loops and so on.
The hardest part was the “two legs moving the same time” thing.
Because of the limited capability of the AT Mega8 it’s just possible to run one timer at the time, so it means you can just run one leg AND THAN the other. So i had to jump after every cycle to the next leg and back again etc etc etc…
Source code is, printed on normal sheets with Arial 12, ’bout 10 sites pure sickness x)
There is a series of articles about audio with Arduino AVRs at uCHobby that could be interesting.
http://www.uchobby.com/index.php/2008/01/08/arduino-audio-dac-options/
If there’s enough interest i could probably throw this together on an arduino (what i was origionally going to do)
-Dane
somewhat interesting, but way too bulky of an approach if you wanted the avr to make sound without being tethered to a computer (that already has a sound card). what would be really impressive is a routine for playing speech coded audio using adpcm, or even linear predictive coding with celp. an atmega with decent flash could store up to a couple minutes of audio that way.
Funny, just read this article yesterday which implements audio interface with the mega32 and was thinking of trying it out…
http://www.riccibitti.com/witnesscam/entry/witnesscam.htm
not really a hack… and nothing really impressive as there are many PIC-based audio players taht do the same.
Or eaven better: MP3.
Still in dev but rather close to a usable portable MP3 player. Have a look here : http://forum.microchip.com/tm.aspx?m=166133
lost track of the dsPIC .ogg player, tought.
Max
Thanks for the reply. The link is really interesting. the goal of this ‘hack’ was to add audio output using a low speed, cheap micro controller and a few cents of components… To process mp3 files, you would need either a separate decoder ic, or a relatively fast micro with software mp3 decoding, using unsigned, non-floating point math. these are both perfectly acceptable methods, but require components that arent available in every lab . you did get me thinking though,… how hard would it be to make an mp3 decoding library for something like a cheap AVR. it sure would be sweet, instead of buying a 18 dollar VS1002, just program an avr / pic. thanks for the idea.
Surely you can use the open sourced mp3 lib used in the dsPIC mp3 player if you find any AVR powerfull enought.
ogg is more complex from what I recall…
But hey, dsPIC are pretty cheap from microchip: free ;)
Max
simple sound generation tutorial
http://extremeelectronics.co.in/avr-tutorials/sound-generation-by-avr-micro-tutorial-i/
The link to his project is broken!