Tuesday, 25 February 2014

Testing an audio-based toy

It's baby Elvis' birthday soon, so I promised I'd make a personalised toy for him. I thought it would be a doddle, as we've already got all the component parts for a really cool "talking toy" from other projects, it'd just be a matter of sticking them together.

As it turns out, the 16F1825 mcu used to play 8-bit wav files is running at pretty much capacity, meaning there aren't enough cycles left to get a good/consistent analogue read in between grabbing chunks of audio off the sd card. It took a few hours to work this one out, so in the end, the original "alarm clock" SD-reading code has ended up butchered into a dedicated "serial in" audio file playing device, while a second PIC is used to take analogue readings to monitor when the resistance value across two terminals has changed (a brief description of this idea is here)

The end result is pretty encouraging - we've now got a general purpose audio playing circuit, to which you simply send a filename over UART/serial (in DOS 8.3 format) and it finds the file in the root of the (FAT16 formatted) SD card, and simply plays it.

So our secondary chip can spend as long as it likes taking analogue inputs, averaging them out, comparing to previous results and so on - and when it's decided the input value has changed noticeably, it simply generates the filename of a sound effect to play and sends it over serial.

Because the audio playing PIC is using interrupts to keep the audio data arriving just in time, we can use a PORTB change interrupt to tell it to stop playing and listen to the incoming filename. Once a full filename has been received, the audio playing PIC simply opens the file on the SD card and starts to play the new audio sample.

Unfortunately for testing we had only two prepared audio files (the audio has to be turned into 8-bit, mono, 22khz, headerless, raw unsigned PCM data) so the demo sounds like a nasty, tinny, cracked church bell, and a mess of static (it's supposed to be a thunderstorm during the opening bars of NTrance's Set You Free).

Here's the breadboarded circuit on it's own custom PCB, with the two PIC microcontrollers side-by-side, ready to fit inside a nice plastic enclosure:

The "closed version" includes a micro USB socket so that pretty much any phone charger (I've tried it with both iPhone and Android chargers) can be used to provide the 5v power supply (which in turn is fed into an LV33CD 3.3V voltage regulator so the SD card doesn't get upset about running at too high a voltage).

Once the audio starts playing properly, it's not too bad!
Perhaps there's some kind of low-pass filter we can put on the speaker to get  rid of the PWM carrier signal....

No comments:

Post a Comment