CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

No sound for 16f876A

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
kevin5k



Joined: 08 Jan 2007
Posts: 41

View user's profile Send private message

No sound for 16f876A
PostPosted: Sat Feb 10, 2007 6:48 pm     Reply with quote

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' Crying or Very sad

Much help advice is appreciated.
kender



Joined: 09 Aug 2004
Posts: 768
Location: Silicon Valley

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

Re: No sound for 16f876A
PostPosted: Sat Feb 10, 2007 7:53 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Feb 11, 2007 6:36 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Feb 11, 2007 10:10 am     Reply with quote

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

View user's profile Send private message

Clarification
PostPosted: Sun Feb 11, 2007 12:59 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Feb 13, 2007 11:22 am     Reply with quote

Tks guys....will try out ur suggestion...... Surprised
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group