Close

Applications, part 1 (Do androids dream?)

A project log for Storing and playing back lofi audio on an MCU

Software and hardware for storing 8-kHz, 8-bit (or less) audio on an AVR MCU, and playing it back

johan-carlssonJohan Carlsson 06/22/2022 at 23:330 Comments

My son and his friend brought me onboard as a contractor on this project to do the electronics and software. Specifically my task was to make a 3D printed sheep bleat and blink. I found a suitable bleat and converted it into mono, 8-kHz, 8-bit wav. Here's what the audio data looks like:

It's exactly one second long (8,000 samples) with 8 kB of data, which would leave zero bytes of flash memory for instructions on an ATtiny85. Challenge accepted! Praise serendipity that my little library for PCM on ATtiny85 is now pretty much finished. With the software taken care of, here's my inept attempt at a schematic with a power amp for the PCM output, and some blinkenlights:

The LED ballast resistors were chosen to make the four LEDs about equally bright. There's a 4 kHz low-pass filter on pin 6 to suppress the 4 MHz PWM frequency. The power amp is just an emitter follower to lower the signal impedance. It does manage to drive a 4 Ω speaker, but with significant distortion. Fortunately a distorted bleat still sounds like a bleat. Vcc is about 4 V (from a Li-ion cell).

Here's the 3D-printed sheep after the cheap contractor did his damage:

Perfboard and hot glue, in 2022, sheesh. Well, you get what you pay for. And from the other side, showing the the 14500 Li-ion cell:

MCU in the lower left corner of the perfboard. Red, yellow, green and blue LEDs (with ballast resistors) to the right of the MCU. Low-pass filter in the upper left corner with the power amp to its right (10 μF yellow coupling cap, voltage divider for biasing, grid stopper, emitter resistor and a 2N3904 BJT) and finally a 1 mF black electrolytic cap to keep the DC off the speaker voice coil.

Last, but not least, some artistic touches added by my son:

And here it is in action: 

An even worse power amp!

There's pretty limited space on the back of a toy sheep, but as I was breadboarding the power amp I did try a variation with a small audio transformer with its primary coil between the collector and Vcc (and the speaker across the secondary). In principle this can both keep the DC off the voice coil, and lower the signal impedance. Here's the audio transformer I tried (with the sheep for scale):

Here's what that power-amp variation did to a 1 kHz sine wave:

Yikes, that's some interesting distortion! Looks like the collector current was more than sufficient to saturate the core of the audio transformer. So even for sub-watt audio power you'd need a bigger output transformer, or one for single-ended use (with an airgapped core), neither of which seem very practical. As a note to my future self, I might want to try a small transformer with two secondaries, one for the signal and the other for DC current to cancel the flux created by the DC collector current through the primary. A bit convoluted, but fun! Or try a Class B amp next time...

Discussions