View previous topic :: View next topic |
Author |
Message |
kevin5k
Joined: 08 Jan 2007 Posts: 41
|
No sound for 16f876A |
Posted: Sat Feb 10, 2007 6:48 pm |
|
|
I'm trying to make an 8ohm speaker sound off when it is activated. It is connected to pin_A0 of the 16F876A. Have verified that the PIC is working and the port is working (i.e Multimeter).
Connection is as such:
pin_A0 --> Capacitor (+) --> Capacitor (-) --> Speaker (+) --> Speaker (-) --> Gnd.
Am using an aluminum electrolytic 10uF capacitor. The positive & negative terminals of both the capacitor and speaker are illustrated above.
All i can hear when pin_A0 is activated is a soft 'boop'
Much help advice is appreciated. |
|
|
kender
Joined: 09 Aug 2004 Posts: 768 Location: Silicon Valley
|
Re: No sound for 16f876A |
Posted: Sat Feb 10, 2007 7:53 pm |
|
|
kevin5k wrote: | All i can hear when pin_A0 is activated is a soft 'boop' |
This sounds like a right result from a wrong signal. For a speaker to make sound, you need to drive it with a frequency, not just turn the pin high. Try making a square wave at some frequency between 100Hz and 20kHz and drive the speaker with it. Some buzzers will generate a frequency themselves (for an example, lookup CEM-1205C on DigiKey).
I�m not sure on this one, but you might also need a reverse-polarized diode from the high side of your speaker to ground. This will protect the PIC from inductive kickback. |
|
|
kevin5k
Joined: 08 Jan 2007 Posts: 41
|
|
Posted: Sun Feb 11, 2007 6:36 am |
|
|
But i just require a monotone sound to be played on the speaker....Anyone can help?Am using only a 4Mhz crystal.... |
|
|
kevin5k
Joined: 08 Jan 2007 Posts: 41
|
|
Posted: Sun Feb 11, 2007 10:10 am |
|
|
What i mean is that Just a simple beep will be sufficient
[quote="kevin5k"]But i just require a monotone sound to be played on the speaker....Anyone can help?Am using only a 4Mhz crystal....[/quote] |
|
|
SimpleAsPossible
Joined: 19 Jun 2004 Posts: 21
|
Clarification |
Posted: Sun Feb 11, 2007 12:59 pm |
|
|
The point kender is trying to make is that to make a short beep, you need to output an audible frequency for a short period of time. That is, your speaker needs to see a waveform like this:
Code: |
__________________/\ /\ /\ /\ /\ /\ /\ /\ __________________
silence \/ \/ \/ \/ \/ \/ \/ \/ silence
beep
|
So, instead of driving the speaker high, you need to drive it high, wait a short time (about 500 microseconds will work), then drive it low again and wait some more (probably the same 500 us). Then you repeat that high-low cycle a few times (about 100 times will give you a 100 ms beep -- 1/10 of a second). Try something like:
Code: |
// --------- untested code ---------
beep()
{
int8 x;
for ( x=0; x<100; x++ )
{
output_high( PIN_A5 );
delay_us( 500 );
output_low( PIN_A5 );
delay_us( 500 );
}
}
|
The monotone you are looking for is defined by the frequency of the high-low switching. The length of time the beep happens is defined by how long you spend switching. With 500 microsecond delays between low-high and high-low, you get a cycle time of 1 ms, which is 1000 Hz. That's a bit low for a beep, so you might want to decrease the time delays and increase the number of cycles.
Your circuit can also potentially destroy your output pin. Can you perhaps get a piezoelectric speaker from a local hobby/electronics store? You are dumping a lot of power into the speaker, using just the PIC's output pin. You could put a cheap logic chip between the PIC and the speaker/capacitor, and put it in a socket so if it blows up you can replace it.
At the very least, put about 50 ohms in series between the output pin and the capacitor. |
|
|
kevin5k
Joined: 08 Jan 2007 Posts: 41
|
|
Posted: Tue Feb 13, 2007 11:22 am |
|
|
Tks guys....will try out ur suggestion...... |
|
|
|