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 support@ccsinfo.com

play songs on a peizo buzzer?
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
buckeyes1997



Joined: 12 May 2005
Posts: 15

View user's profile Send private message

play songs on a peizo buzzer?
PostPosted: Sun May 29, 2005 7:52 am     Reply with quote

how can i play a song on a peizo buzzer? when i apply voltage it generates a pitch i dont think a lower voltage changes the pitch but even if it does i dont think thats a feasible method. im guessing i have to pulse the buzzer at varying frequencies to get different pitches??

i have done a search for it on the forum but most cases use the PWM built into the PICs. I wont be using a PIC with the PWM. i will need to manually setup the pulse widths and timings.
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

Re: play songs on a peizo buzzer?
PostPosted: Sun May 29, 2005 10:36 am     Reply with quote

buckeyes1997 wrote:
i have done a search for it on the forum but most cases use the PWM built into the PICs. I wont be using a PIC with the PWM. i will need to manually setup the pulse widths and timings.


I think you just answered your own question. You are going to need to modify the examples you found so that you are toggling the output bits in a more "manual" method. Either use a timer and its interrupt or you could count instructions and brute force it.

There have been some discussions in the past on how to do PWM when you don't have a PIC with the dedicated hardware or you need to add more PWM channels than there was hardware. Those discussions should be helpful in this case. A search on PWM will probably turn them up along with 10,000 other things. Maybe search for SOFTWARE PWM.
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
Ttelmah
Guest







PostPosted: Sun May 29, 2005 2:31 pm     Reply with quote

I'd be slightly suspicious, that you can't.
There are two basic 'types' of piezo modules. The first is a simple transducer, and requires an AC drive. The second contains an oscillator, and buzzes. For the AC drive units, it'd be possible to simply generate a train of pulses, and make something faintly musical. This can be done with a programmable oscillator, or with simple 'bit banging'. The latter is like the 'bit banging' sound code, that was done years ago on early computers, that didn't have a speaker. However I doubt if the buzzer units will work with this, and the effct may not be what is expected at all. I'd suggest making an experiment, before writing any code. Get an NE555, wire it as a simple 1Khz oscillator, and try feeding the module off this. If you hear a 1Khz tone, then 'great', but I suspect this will not be what the unit produces.

Best Wishes
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Sun May 29, 2005 6:33 pm     Reply with quote

I've used cheap little 4kHz piezeo (for example Kobitone PB1267) as signaling devices where my code plays different beep patterns with different tones. Works reasonably well. Not exactly Harmin-Kardin (spelling?) quality but it gets the job done.

There is code in the archive that plays Xmas carols (Mark's, can't remember right now) and that also works OK with the above mentioned Kobitone. Just tried for giggles. I should re-work the code so it play's Iron Butterfly's "Innagaddavida".

Murata-Erie and a few others make similar piezeo's. Just the bimetal disk inside a little platic box to act as its echo chamber or sounding board. PWM +5V (+3.3V works for some, read the specs) at the tuned frequency and you get the loudest and most annoying output possible. Other frequencies still produce tones, but at varying dB.
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Mon May 30, 2005 12:03 am     Reply with quote

I've done it and posted code as rwyoung has stated. It's in the code library and there is a test program that runs on a PICDEM 2 Plus board.
buckeyes1997



Joined: 12 May 2005
Posts: 15

View user's profile Send private message

simple test without a 555 ?
PostPosted: Wed Jun 01, 2005 2:08 pm     Reply with quote

i think you guys are correct. the "buzzer' im using seems to turn on and off and not vary frequency at all. im guessing it has a built in drive circuit which controls the frequency and im simply turning it on and off at different rates.

i will write a simple program to create a few different waveforms that will be "bit banged" to the unit and ill see if it changes pitch. basically all i would need to do is vary the period(frequency) of the pulse train right?

i dont want MP3 quality just the ability to play something recognizable when a project is turned on or something happens.

thanks
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

Re: simple test without a 555 ?
PostPosted: Wed Jun 01, 2005 2:12 pm     Reply with quote

buckeyes1997 wrote:
i think you guys are correct. the "buzzer' im using seems to turn on and off and not vary frequency at all. im guessing it has a built in drive circuit which controls the frequency and im simply turning it on and off at different rates.

i will write a simple program to create a few different waveforms that will be "bit banged" to the unit and ill see if it changes pitch. basically all i would need to do is vary the period(frequency) of the pulse train right?

i dont want MP3 quality just the ability to play something recognizable when a project is turned on or something happens.

thanks


If applying voltage to the device will make a tone then you need to get a different kind of piezo, one that you must pwm yourself.
Ttelmah
Guest







Re: simple test without a 555 ?
PostPosted: Wed Jun 01, 2005 2:25 pm     Reply with quote

buckeyes1997 wrote:
i think you guys are correct. the "buzzer' im using seems to turn on and off and not vary frequency at all. im guessing it has a built in drive circuit which controls the frequency and im simply turning it on and off at different rates.

i will write a simple program to create a few different waveforms that will be "bit banged" to the unit and ill see if it changes pitch. basically all i would need to do is vary the period(frequency) of the pulse train right?

i dont want MP3 quality just the ability to play something recognizable when a project is turned on or something happens.

thanks


This is what I thought, from your wording 'buzzer'. You need a simple piezo transducer, which can be made to reproduce tones.

Best Wishes
Christophe



Joined: 10 May 2005
Posts: 323
Location: Belgium

View user's profile Send private message

PostPosted: Tue Dec 20, 2005 2:49 am     Reply with quote

So I'm bringing back this old topic because I need to drive a buzzer too.

What is the best way of wiring the piezo buzzer?
Vpic = 3V

1/

+ : Port C0
- : ground

2/

+: C0
-:C1

3/
+: 5V
-: port c0
Brian S



Joined: 06 Sep 2005
Posts: 13

View user's profile Send private message

PostPosted: Tue Dec 20, 2005 7:43 am     Reply with quote

Yes, use a "piezo transducer", not a "piezo buzzer". Do not drive
with more than about 12V p-p, or it may be damaged. See the
data sheet for maximum voltage; it is usually fairly low.

Try to mount it so the active surface looks through a large hole in
the PCB. This gives much better volume and tone. The bigger board,
the better tone. Glue transducer to PCB using elastic glue, like RTV.
SherpaDoug



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

View user's profile Send private message

PostPosted: Tue Dec 20, 2005 9:11 am     Reply with quote

If you connect a piezo transducer to two port pins and drive them oppositely you will get about four times the sound volume than if you use one port pin and ground. Or you can use one port pin and an inverter. Two port pins has the advantage that you can select two volume levels by software, either drive the second pin or leave it low.
Using +5V instead of GND makes no difference.
_________________
The search for better is endless. Instead simply find very good and get the job done.
Christophe



Joined: 10 May 2005
Posts: 323
Location: Belgium

View user's profile Send private message

PostPosted: Wed Dec 21, 2005 8:48 am     Reply with quote

How can you drive those pins then?

pin + : high
pin - : low

and then what?

pin + : low
pin -: high
SherpaDoug



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

View user's profile Send private message

PostPosted: Wed Dec 21, 2005 12:19 pm     Reply with quote

I would set one pin high and the other low, then use an XOR mask on the port to toggle both bits.
_________________
The search for better is endless. Instead simply find very good and get the job done.
Christophe



Joined: 10 May 2005
Posts: 323
Location: Belgium

View user's profile Send private message

PostPosted: Thu Dec 22, 2005 1:48 am     Reply with quote

Can you give a code example?
Christophe



Joined: 10 May 2005
Posts: 323
Location: Belgium

View user's profile Send private message

PostPosted: Thu Dec 22, 2005 7:14 am     Reply with quote

So,

that would be

output_high(C0);
output_low(C1);
X0R(portc, 1111 1111);

output(portC);

the problem is that all port C pins are changing and becoming outputs. I don't want that because they are used for other purposes.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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