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

Drive a Piezo Transducer with PIC

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



Joined: 08 Nov 2007
Posts: 6

View user's profile Send private message

Drive a Piezo Transducer with PIC
PostPosted: Fri Feb 08, 2008 6:51 am     Reply with quote

Hi

I´m trying to drive a transducer with my pic182455. It is directly connected to pin B4. The thing is that I cant get it to sound loud. The resonant freq. is 2400Hz.

My code:
Void Beep()
{
for(i=0; i<100; ++i)
{
OUTPUT_HIGH(PIN_B4);
Delay_us(207);
OUTPUT_LOW(PIN_B4);
Delay_us(207);
}
}




Has anyone been able to drive a transducer with PIC?
nuwavedc



Joined: 06 Feb 2008
Posts: 17

View user's profile Send private message

PostPosted: Fri Feb 08, 2008 7:44 am     Reply with quote

So I take it that it is sounding quietly? I would take a look at the wave form with an oscilliscope and see what it looks like. Driving Piezos with ports never worked well for me.

You would be beter off tying the element between two ports and driving it like an H bridge configuration. Which means that PX1 is set high and PX2 is set low and then PX1 is set low and PX2 is set high. And then the cylcle reverses. This will effectively double the voltage seen by the piezo. Or you can buy a self oscillating type.

I show the mod for your code below just suggesting that the other port tied to the Piezo is B5.

Hope that helps.

Code:

Void Beep()
{
for(i=0; i<100; ++i)
{
OUTPUT_HIGH(PIN_B4);
OUTPUT_LOW(PIN_B5);
Delay_us(207);
OUTPUT_LOW(PIN_B4);
OUTPUT_HIGH(PIN_B5);
Delay_us(207);
}
}

_________________
Thanks,

NuWaveDC
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Fri Feb 08, 2008 8:27 am     Reply with quote

If you have a spare RS232 driver channel you can drive a piezo much louder with that than a 5V PIC pin. 5V H bridge is good, RS232 is a little better, RS232 H bridge is better still.
_________________
The search for better is endless. Instead simply find very good and get the job done.
SET



Joined: 15 Nov 2005
Posts: 161
Location: Glasgow, UK

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

PostPosted: Fri Feb 08, 2008 9:11 am     Reply with quote

Quote:
You would be beter off tying the element between two ports and driving it like an H bridge configuration. Which means that PX1 is set high and PX2 is set low and then PX1 is set low and PX2 is set high. And then the cylcle reverses. This will effectively double the voltage seen by the piezo. Or you can buy a self oscillating type.


Have done this with reasonable results - not ear shattering but easily audible. Be warned though needed a fairly big (25mm dia) device to be Ok.
Guest








PostPosted: Fri Feb 08, 2008 4:08 pm     Reply with quote

I had some luck with a PWM port - you can adjust the frequency to get a nice resonance with the transducer - adjust the frequency and duty cycle for the proper harmonic content for that 'Just right' sound.

I had a small 1" transducer and it was loud enough for an instrument - click, click, click for key presses - but it would not have been loud enough for an alarm.

If all you need is user feedback kind of noises - it can be loud enough.

HTH - Steve H.
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