From: John Popelish
Organization: This space not available for advertising.
X-Mailer: Mozilla 4.7 [en] (Win98; U)
Subject: Re: Connecting a PC-speaker to a PIC cpu
Date: Thu, 14 Nov 2002 23:26:35 GMT
NNTP-Posting-Date: Thu, 14 Nov 2002 18:26:35 EST
> 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
The PIC can only pull down while supplying a few 10s of milliamps, and
can pull up with only a couple ma. The speaker needs something like a
couple hundred milliamps in each direction to provide usable volume.
The 386 can supply this amount of current if it has a little more than
5 volts available as a supply. If you have a 5 volt regulator, you
can feed the amplifier from the unregulated supply.
The 386 has a built in gain of 50 which is way to high for the several
volt swing from the PWM, but it is not easy to stabilize at a gain of
1 to 3 which is what you need. Instead, build a simple passive
attenuator and low pass filter to reduce signal voltage to about a
tenth of a volt and smooth out some of the PWM ripple. you might try
something like a .1 uf capacitor to the PIC output (to block the DC
component of the signal) followed by a 100k resistor. Connect the far
end of this resistor to both a 2.2k resistor and a .01 uf cap, with
the other end of both connected to ground. The signal between the
100k and 2.2k resistors will be about .1 volt, that has all
frequencies above 10 kHz attenuated further. That should greatly
reduce the distortion out of the 386.