From: firstname.lastname@example.org (Tom Bruhns)
Subject: Re: Connecting a PC-speaker to a PIC cpu
Date: 14 Nov 2002 18:12:33 -0800
NNTP-Posting-Date: 15 Nov 2002 02:12:33 GMT
To drive an 8 ohm load to 0.5W (if you really need that much power)
will take 2V rms, which for a sine wave is about 2.8V peak, or 5.6V
peak to peak. 2.8V across 8 ohms is around 300mA. The PIC is only
rated at 25mA output, I believe. So an amplifier is a good idea. You
don't really need much (if any) voltage gain, but you do need more
available output current. Since you are trying to use an amplifier
with a voltage gain of 50, you should cut the input to that amplifier
down with either a fixed attenuator, or a variable volume control.
Perhaps a 47kohm resistor from the filtered (see next paragraph) PWM
output to the amp input, and a 1k from the amp input to ground. If
you use a volume control, you might want to make it perhaps 1k (audio
taper), and still put a resistor from its input to the PWM filtered
output, or else you will only be able to use the first tiny bit of its
The PIC PWM output you have should be filtered before you put it into
the amplifier. You should filter out the PWM frequency, and indeed
you should filter out the DC unless you actually want to drive the DC
through the amplifier, which is very unlikely. So, a capacitor in
series is OK to filter out (block) the DC. Depending on the PWM
frequency and the sine-wave frequency, you may be able to use a simple
series R and shunt C as a filter to remove enough of the PWM frequency
for it to be useable. I'd try maybe R=1kohm, and C so that
R*C=1/(4*pi*f(sine)) -- the 4 instead of the usual 2, so that the
cutoff is a bit above the sine frequency.
But you may need to use more filtering than a simple one-pole filter
I'm surprised you don't hear _anything_ from the speaker when you hook
it right to the PIC port. If you haven't destroyed the PIC port
(which you probably haven't, if you still see good output there), then
you should be getting at least 25mA p-p in your 8 ohms speaker, and
that's about a milliwatt, I think. That should be PLENTY to hear, if
you're not in a really noisy environment. Good idea to put a
capacitor between the PIC output and the speaker, by the way, though
not absolutely necessary.
"Henrik" wrote in message news:...
> I am trying to connect a PC Speaker (0.5W, 8Ohm) to a PIC cpu (16f877). (I
> am not sure about the Watt of the speaker, I do not got it in front of me at
> the moment)
> I am using PWM modulation in the PIC to achieve a sinus wave. The output is
> a flawless sinus from the RB1 port (measured with a oscilloscope). But when
> I connect the PC speaker I get no sound. This, I assume is because the PIC
> cpu generates to low current(?). Anyone got a suggestion on a circuit that I
> can use so I get my sinus-wave-sound? I've tried using a LM386 effect
> amplifier, using the circuit for a gain of 50, on the data page. But the
> signal out from the amplifier doesn't look to good.
> * Should I have a capacitance between the input of the amplifier and the
> * Is there a easier way of using the PC speaker?
> Any help welcome.
> Cheers, Henrik