ELM Home Page

255-Voice PCM Sound Generator

September 11, 2010
Update: December 15, 2013

20pin AVR and SD

This is a simple sound generator based on 8-pin SD Audio Player. It is built with an Atmel ATtiny861 microcontroller and an SD memory card. The tiny861 has fast PWM outpus like tiny85 so that it can generate clear sound compared to any other AVR chips. On 20-pin device, many GPIO pins are available. It enables to control the sound generator by external signals.

Because it can be controlled with ease, this project is usable as sound module for toys, tone ringers, amusement machines and gadgets.


A MicroSD card is used as storage media and also SD and MMC can be used with proper socket conversion. It is controlled in SPI mode via USI. The audio signal is output in PWM and it can drive loudspeakers directly. It may be thought that the output current exceeds the rating but it is no problem because the output current is limited by output impedance at 3.3 volt supply voltage even if the output pin is tied to the rail. Therefore it cannot sound loud but it will create sufficient sound that listen on the desk with high efficiency speakers. An optional 100μH series inductor on the PWM output will reduce power consumption. When connect the audio outputs to the amplifier, the high frequency component must be filtered out with LPF. Do not input the PWM signals directly to the amplifier or the amplifier and speakers can be damaged.

Selecting an Audio Output Circuit

There are three different output circuit shown in the Circuit Diagram. These are exclusive each other. The firmware to be written into the AVR must be fit for the output configuration of the circuit. Each output configuration (Mono-OCL/Stereo/Mono-HR) correcponds the hex file (sdsg_mo.hex/sdsg_st.hex/sdsg_hr.hex). The fuse settings are combined with the hex files. However some AVR programmers may not support this sort of hex files and reject it on loading. If it is the case, remove fuse seciton from the hex file. The fuse values to be programmed are also found in the main.c.


Trigger Mode

Supported sound file format is RIFF/WAVE in LPCM, 8/16bit, mono/stereo and 8kHz-48kHz. Any other sound files, such as ADPCM, MP3 and AAC, must be converted into the PCM. The sound files must be named NNN.wav. The NNN is three digit number in range from 001 to 255. The sound files must be put into the root directory.

The control command is input as binary code by eight contacts (SW1-SW8) and the corresponding sound file will be played. e.g. SW1 corresponds to 001.wav, SW4 corresponds to 008.wav and SW1+SW5 corresponds to 017.wav. There are four operating modes, behavior of the sound generator on control command, can be configured by 000.txt on the root directory. Each mode works as follows:

Mode 0 : Level trigger
Plays a sound file corresponds to the input code in auto-repeat. When the input code is changed, the sound also be changed. When the input goes off(0), the audio output is stopped.
Mode 1 : Level trigger (sustained)
Same as mode 0 but the file is played until end of the file and then stopped when the input goes off.
Mode 2 : Edge trigger
Plays a sound file corresponds to the input code once. Any code change while a sound will be ignored.
Mode 3 : Edge trigger (re-triggerable)
Same as mode 2 but the code change is accepted while the sound. To re-rtigger with the same code, change input to 0 and then input the code again.
Mode 4 : Edge trigger (stop on release)
Same as mode 2 but the sound stops when the input goes off(0).

LED indicator

The LED indicates that a sound file is being played. It also flashes on any error. The number of flashes + a second of blank corresponds to the type of errors as follows:

Tech Notes