PWM Audio Generation With An AVR

[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

  1. had the same idea when i made my AT-AT Lego Robot controled by an ATM Mega8 (

    ) for a school project, but didn’t knew how to do that… now it’s to late, but never the less a cool hack ;)

  2. 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:

    hope any of that helped,
    keep tinkering

  3. @ 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)

  4. 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.

  5. 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.

  6. 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 ;)


Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.