Close

PCM on ATtiny85, part 3

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/25/2022 at 05:410 Comments

I have cleaned up my code for PCM on ATtiny85 and made it available as the pcm-tn85 library. It supports both synchronous and asynchronous playback, and sample bit depths of 8, 4, 2 or 1. It was written from scratch to take advantage of the high-frequency (64 MHz, which was good enough for me, or even a bit higher) ATtiny85 Timer 1. I implemented all the functionality in a header file, so no need to link an object or library file. Here's a short video showing a very simple circuit, and what it sounds like:

I have been pontificating on the evils of not low-pass filtering the PCM output signal, and here I do exactly that. In my defense, this is 4-bit audio, with a PWM frequency of 4 MHz, which I doubt will affect the speaker. I was surprised how well an ATtiny85 can directly drive an 8 Ω speaker. I think the DC current sourced by a pin can be as high as 40 mA at 5 V. Sounds like AC current gets close to that (the nice and loud chirping is in the range of 300 to 3,000 Hz and I use Vcc = 4 V here).

This will probably be my last post on this project for a while. I plan to do a Halloween post and I might port the PCM library to ATmega328P for that application. It should be possible to do 4-bit audio with 1 MHz PWM frequency on the ATmega328P. Using ATtiny85 Timer 1 for ultrasound transmission is another possibility that's fermenting in my mind. But before then I want to do some high-voltage analog stuff!

Discussions