Let me start by saying I'm a self-taught electronics hobbyist, so something
that may be abudnantly clear to a formally schooled engineer could be
totally lost on me.
With that preface....
I'm dabbling with my next PIC project and would eventually like to recreate
audio using a PIC chip. I figure I can use Windows to take an .mp3 file and
create an audio file with a stupid-simple codec, I can put the file on an
MMC card and insert the card into my PIC circuit, and read the file from the
PIC chip, but getting the data from there to a speaker is something I don't
know how to do.
(I wouldn't attempt decoding an mp3 file in PIC code. I'd make sure to use a
very simple codec.)
Would I just use a DAC, or is there a better way? Would Microchip's
MCP4821/4822 parts be suitable? What am I looking for in a part for this
purpose?
> I'm dabbling with my next PIC project and would eventually like to recreate
> audio using a PIC chip. I figure I can use Windows to take an .mp3 file and
> create an audio file with a stupid-simple codec, I can put the file on an
> MMC card and insert the card into my PIC circuit, and read the file from the
> PIC chip, but getting the data from there to a speaker is something I don't
> know how to do.
>
> (I wouldn't attempt decoding an mp3 file in PIC code. I'd make sure to use a
> very simple codec.)
>
> Would I just use a DAC, or is there a better way? Would Microchip's
> MCP4821/4822 parts be suitable? What am I looking for in a part for this
> purpose?
Matt,
there are a few options here. You mentioned DACs, which would be one
way to go. These generally take some serial data that the PIC could
easily spit out.
For a more direct approach, you can use the PIC's PWM unit and a
low-pass filter to generate some passable audio. Basically, you
generate a square wave where the duty cycle of each period is somewhat
proportional to the analog level that you want. Then you use an analog
filter to average out the values, and you can get something
representing a sound wave.
In this case, the frequency ranges get a bit difficult. You'd have to
check the data sheet for the PIC you're thinking of using and
determine the maximal PWM frequency where you still have full duty
cycle accuracy. This in turn will affect the maximal sound frequency
you can represent after filtering out the square wave parts.
In any case, you might also want to look at amplifier ICs - the PIC's
output drive capability will not make for a very loud sound, and
depending on how big a speaker you want to drive, you might want to
amplify things a bit.
>>Would I just use a DAC, or is there a better way? Would Microchip's
>>MCP4821/4822 parts be suitable? What am I looking for in a part for this
>>purpose?
For some basic "toys" or alike, you can use the Voltage Reference out
(available for example on 18F2620/2520) as a rough 4 bit DAC.
It has a high output impedance, so an OpAmp is mandatory (or an audio
amplifier, in your case).
Or, consider also a R-2R ladder if you feel like...
Reading WAV files is very easy, to begin with in your project. You can
sure use other codecs, but most of them won't perform good with HiFi audio.
I think I'm going to investigate the PWM solution. It sounds like it'll be
easier to implement, and my SPI bus may be busy enough that not having a DAC
hanging off it (needing new samples at 8kHz) will be a bonus.
>> Would I just use a DAC, or is there a better way? Would Microchip's
>> MCP4821/4822 parts be suitable? What am I looking for in a part for this
>> purpose?
>
> Matt,
>
> there are a few options here. You mentioned DACs, which would be one
> way to go. These generally take some serial data that the PIC could
> easily spit out.
>
> For a more direct approach, you can use the PIC's PWM unit and a
> low-pass filter to generate some passable audio. Basically, you
> generate a square wave where the duty cycle of each period is somewhat
> proportional to the analog level that you want. Then you use an analog
> filter to average out the values, and you can get something
> representing a sound wave.
> In this case, the frequency ranges get a bit difficult. You'd have to
> check the data sheet for the PIC you're thinking of using and
> determine the maximal PWM frequency where you still have full duty
> cycle accuracy. This in turn will affect the maximal sound frequency
> you can represent after filtering out the square wave parts.
>
> In any case, you might also want to look at amplifier ICs - the PIC's
> output drive capability will not make for a very loud sound, and
> depending on how big a speaker you want to drive, you might want to
> amplify things a bit.
>
> Hope this helps.
> Regards,
> - Marcel
>I'm dabbling with my next PIC project and would eventually like to
>recreate audio using a PIC chip. I figure I can use Windows to take
>an .mp3 file and create an audio file with a stupid-simple codec, I
>can put the file on an MMC card and insert the card into my PIC circuit,
>and read the file from the PIC chip, but getting the data from there
>to a speaker is something I don't know how to do.
>
>(I wouldn't attempt decoding an mp3 file in PIC code. I'd make sure
>to use a very simple codec.)
>
>Would I just use a DAC, or is there a better way? Would Microchip's
>MCP4821/4822 parts be suitable? What am I looking for in a part for
>this purpose?
Depending on the quality of audio you want, it may be sufficient to use the
PWM generator in the PIC to do a Class D style audio drive. Olin has an
example of doing this in his development environment at http://www.embedinc.com/pic/ and look for his 'HAL' example project. If you
go this route, take not of his instructions on order of install of the files
he has. He also has some PC applications for converting WAV files into a
downloadable format that suits his audio driver.
> Let me start by saying I'm a self-taught electronics hobbyist, so something
> that may be abudnantly clear to a formally schooled engineer could be
> totally lost on me.
>
> With that preface....
>
> I'm dabbling with my next PIC project and would eventually like to recreate
> audio using a PIC chip. I figure I can use Windows to take an .mp3 file and
> create an audio file with a stupid-simple codec, I can put the file on an
> MMC card and insert the card into my PIC circuit, and read the file from the
> PIC chip, but getting the data from there to a speaker is something I don't
> know how to do.
>
> (I wouldn't attempt decoding an mp3 file in PIC code. I'd make sure to use a
> very simple codec.)
>
> Would I just use a DAC, or is there a better way? Would Microchip's
> MCP4821/4822 parts be suitable? What am I looking for in a part for this
> purpose?
>
> Thanks!
>
> -Matt
>