Sound using PIC

Thread Starter

Sniperchang

Joined Jul 1, 2009
6
Hey guys,

I wanted to try outputting sounds using a PIC, but there's a few things I'm not sure about.

I was thinking of trying both using PWM and a DAC. Since I don't have the DAC yet, let's start with PWM.

I'm thinking, PWM->Low Pass filter (cap + resistor) -> Op-Amp or amplifying circuit -> coupling cap -> 8ohm, 0.5W speaker.

What I'm not sure about is the calculations for the output voltages of the Op-Amp (and current drawn)(Or do I need some other amplifying circuit?). Is 8 ohms for a speaker technically resistance or perhaps inductance? Is it important to remove DC for speakers?

For DAC: DAC-> Op-Amp or amplifying circuit -> cap -> Speaker.

Thanks for any help. If been looking around the net for these answers, but I've been having rotten luck.
 

hgmjr

Joined Jan 28, 2005
9,027
You may want to look into building a CLASS-D amplifier and then use the microcontroller to generate the PWM input for it.

hgmjr
 

Thread Starter

Sniperchang

Joined Jul 1, 2009
6
Thank you for your reply. I did some quick research, and it does seem a Class-D amp is ideal with PWM.

I also learned that DC in speakers is generally bad, but I'm still not sure about speaker calulations.
 

kkazem

Joined Jul 23, 2009
160
Hi,
A PWM amp is a D/A converter and is also called a CLASS-D (switching) amp. For a single channel, I recommend using a full-bridge topology. There are IC's out there from STS (SGS Thompson) and others that have an interface from a PWM signal from a processor (like a PIC chip) to the speaker needing only the VDD power supply for the amp and an L-C filter between one of the bridge outputs and the speaker. The current needed depends on the max power you want to drive the speaker to and the supply voltage to the PWM full bridge. The calculation is as follows: Pwr=E^2/(Zspeaker), rearranging, we get that:
E (supply voltage) = sqrt(PWR * Zspeaker) = sqrt(0.5 * 8) = sqrt(4) = 2 VDC per half cycle (peak), so for 0.5 watt peak-peak, you'll need a 4 volts DC supply or greater. For minimal distortion, I recommend a switching carrier frequency of 20 KHz to9 25 KHz or more, and you'll need an L-C filter between the PWM bridge output and the speaker. For mono, you need 2 to 4 PWM signals from the PIC chip to drive the full bridge. There is more than one topology which is why I say you need 2 to 4 PWM signals, depending on the exact topology you use. Go online and do a google search on PWM IC's and PWM MOSFET driver IC's. International Rectifier has gook app notes as does Linear Technology, SGS Thompson (STS), Texas Instruments, Microchip, and others.

Good luck,
Kamran Kazem
 
Last edited by a moderator:

THE_RB

Joined Feb 11, 2008
5,438
The problem with both PWM and DAC systems is data storage, you need LOTS of memory to hold the sound data. Say at 22kHz 8bit sound you won't even get a second of sound in most PICs.

But there is a 1bit sound system that can be used on PICs, it reduces the required sound storage by 8:1 (it makes the sound a bit scratchy but is fine for speech etc). Here is free windows software to convert wave files to the 1bit sound;
http://www.romanblack.com/picsound.htm

And if you don't want to build your own hardware PIC->eeprom->amp etc and write your own PIC code there is a neat little ready made PCB here that you just need to load your sounds into, it has 1megabit of onboard sound storage and a pre-programmed PIC;
http://www.talkbotbrain.com/
 
Top