View previous topic :: View next topic |
Author |
Message |
buckeyes1997
Joined: 12 May 2005 Posts: 15
|
play songs on a peizo buzzer? |
Posted: Sun May 29, 2005 7:52 am |
|
|
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
|
Re: play songs on a peizo buzzer? |
Posted: Sun May 29, 2005 10:36 am |
|
|
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
|
|
Posted: Sun May 29, 2005 2:31 pm |
|
|
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
|
|
Posted: Sun May 29, 2005 6:33 pm |
|
|
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
|
|
Posted: Mon May 30, 2005 12:03 am |
|
|
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
|
simple test without a 555 ? |
Posted: Wed Jun 01, 2005 2:08 pm |
|
|
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
|
Re: simple test without a 555 ? |
Posted: Wed Jun 01, 2005 2:12 pm |
|
|
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 ? |
Posted: Wed Jun 01, 2005 2:25 pm |
|
|
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
|
|
Posted: Tue Dec 20, 2005 2:49 am |
|
|
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
|
|
Posted: Tue Dec 20, 2005 7:43 am |
|
|
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
|
|
Posted: Tue Dec 20, 2005 9:11 am |
|
|
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
|
|
Posted: Wed Dec 21, 2005 8:48 am |
|
|
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
|
|
Posted: Wed Dec 21, 2005 12:19 pm |
|
|
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
|
|
Posted: Thu Dec 22, 2005 1:48 am |
|
|
Can you give a code example? |
|
|
Christophe
Joined: 10 May 2005 Posts: 323 Location: Belgium
|
|
Posted: Thu Dec 22, 2005 7:14 am |
|
|
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. |
|
|
|