On playing audio using Atmega microcontrollers

I re­cently made a cir­cuit to demon­strate au­dio gen­er­a­tion us­ing an at­mega32a mi­cro­con­troller. And even though mostly knew the con­cepts in­volved, I ended up learn­ing a lot.

For one, I learnt that ma­trix boards are very an­noy­ing when deal­ing with mi­cro­con­troller pins. I ended up re­ally mess­ing up the cir­cuit’s back­side be­cause I had­n’t planned be­fore­hand (Did I men­tion that this is my first time us­ing a ma­trix board?).

Next, I learnt that CR2032 bat­ter­ies don’t last long. I re­ally don’t know how it hap­pened, but I had two nearly fresh CR2032 bat­ter­ies which both ran out in the span of two hours. I mean, Atmega32a con­sumes around 8mA at 8MHz. The R-2R DAC had an equiv­a­lent re­sis­tance of 2k ohms if I re­mem­ber cor­rectly. The to­tal cur­rent in the sys­tem can’t have been more than 15 to 20 mA of cur­rent in the sys­tem at any given time. Granted, that’s out of the specs of the bat­tery, but it should have gone at least 4 hours.

I also found this nifty code to re­verse bit or­der in a byte:

unsigned char reverse( unsigned char x ) { x =
((x >> 1) & 0x55) | ((x << 1) & 0xaa); x = ((x >> 2) & 0x33) | ((x << 2) &
0xcc); x = ((x >> 4) & 0x0f) | ((x << 4) & 0xf0); return x; }

This is bet­ter than loop­ing 8 times or some­thing and also looks beau­ti­ful. Win-win. (I have no idea how this func­tion works, though)

That is about all. The demo went nicely too. I think I will write a de­tailed post on all the things I had to do to get this to work, be­cause I had to learn a lot of things be­fore I got this kind of sys­tem work­ing the first time (most of the trou­bles had to do with con­vert­ing au­dio into sam­ples).