Piezo speaker question
Greg LaPolla
Posts: 323
I am using a piezo speaker and I can't seem to get it loud enough to hear it from inside a project box.
here is the code and the diagram is attached
Am I asking to much from the piezo ?
Greg
here is the code and the diagram is attached
CON _clkmode = xtal1 + pll16x ' set clock mode _xinfreq = 5_000_000 ' set external crystal freq OBJ PUB Main warn PRI warn ctra[noparse][[/noparse]30..26] := %00100 ctra[noparse][[/noparse]8..0] := 27 frqa := 224_734 repeat 3 repeat 30 !dira[noparse][[/noparse]27] waitcnt(clkfreq/30 + cnt) waitcnt(clkfreq + cnt) PRI alarm ctra[noparse][[/noparse]30..26] := %00100 ctra[noparse][[/noparse]8..0] := 27 frqa := 224_734 repeat 5 !dira[noparse][[/noparse]27] waitcnt(clkfreq + cnt)
Am I asking to much from the piezo ?
Greg
Comments
Leon
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Amateur radio callsign: G1HSM
Suzuki SV1000S motorcycle
Thanks
Greg
In addition to finding a resonant frequency of the piezo (<- there can be more than one that will work), you can also increase the volume by driving the piezo element differentially rather than single ended. See this thread... although it was written for a BS2, it will still apply here.
http://forums.parallax.com/showthread.php?p=464410
If you can't provide a solution in software by sacrificing two pins that you can drive 180 Deg out of phase
to supply a piezo, then the below circuit may be of some use to you. It is basically a two transistor inverter
designed to be able to handle a floating input. Note for use from a Propeller pin, substitute the 4.7K resistors with 3.3K resistors.
http://forums.parallax.com/attachment.php?attachmentid=36227
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Post Edited (Beau Schwabe (Parallax)) : 7/15/2009 6:00:07 AM GMT
I read through several spec sheets for various piezo's. One of them suggested placing a 1k resistor across the pins, (Resistor to do charging and discharging to a piezoelectric element - Value of about 1kΩ is good efficiency).
Does that achieve sorta what you were referring to? It did get significantly louder once I did that (Correctly as Leon noted).
Greg
*Peter*
P.S. I read your original post and you mentioned that you had the piezo inside the box. Bear in mind that this will muffle the sound a lot unless you mount the piezo against the inside of the box with a small hole of around 1 to 5mm for the sound. This is how it is done in all commercial projects, the hole may be very small but it makes a difference.
Post Edited (Peter Jakacki) : 7/14/2009 1:36:09 AM GMT
The circuit that you provided will only drive the piezo in a single ended mode, and using a 1K bias resistor works fine for this. If you do however find that you need even more volume, the differential drive approach that I provided a link to can help. Even if you have one I/O pin there is an inverter that will work perfectly with the piezo that I also provided a link to that will drive the piezo element differentially.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Is there an inverter specifically that you would recommend or is it best to just build one as you have diagrammed.
Greg
I have always just built one in this situation... A CMOS inverter would probably work just fine. The unique property of the inverter that I posted is that it can accept a floating or hi-Z input.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
I don't have any 2n3906 transistors, I only have 2n3904's. I thought I would attack the 2 pin method. I have been going over the Counter Modules and Circuit applications lab in the PE kit. I can't seem to find anything that would help. I understand the methodology, but I can seem to wrap my head around it completely.
Would you just alternate the pins back and forth between input and output ? using the code I originally posted using ctra and frqa I am not sure it will work. Do those counters get reset when you change the pin direction?
Greg
*Peter*
Thanks for the info. I am trying to get your example to work but It hangs here:
frq := fraction(Freq, CLKFREQ, s) 'Compute FRQA/FRQB value
What should that do ? I assume fraction is something you wrote.
I modified my code like this:
this works but doesn't seem any louder so I assume my code is not correct.
Greg
You need to set the destination field of CTRA to 19, not the source field of CTRB. The latter doesn't do anything, since you're not using CTRB.
-Phil
My line of thinking is to drive pins high and low and alternate input and output respectfully on the 2 pins.
Changing ctra to differential mode I understand, but what about the second pin ?
Greg
Basically all that happens is that one pin will be at 3.3V while the other will be at 0V, then it alternates (AC) so that it becomes 0V while the other will be at 3.3V. The piezo will with only two pins see a strong AC signal imposed across it which is ideal for this type of element as it is mostly capacitive in nature. Leaving a DC voltage on the piezo will have no effect at all or draw any current, it needs to be AC (in respect to the piezo).
3.3V
PIEZO
0V
0V
PIEZO
3.3V
3.3V
PIEZO
0V
If you want to specify a completely different complementary pin then you should add an extra parameter to the function and change the bits that write to the counter and direction register.
*Peter*
*Peter*
I have tried your code and I can't seem to make it work.
Here is what I have done:
I can seem to get anything out of the peizo with this. I even tried a repeat calling synth.
Greg
Try 1500 for starters
*Peter*
You need to add a repeat to your main code to keep the cog alive. Your program is dying right after the call to synth since Spin is doing an automatic cogstop. Repeatedly calling synth is only going to make it keep reinitializing.
-Phil
Posters, if you are going to post code then post the exact code otherwise we have no idea what really is going on.
*Peter*
that is c8. It plays fine with my code.
I changed it to 84_181 which is G6 still no go.
@Phil
I did use a repeat as I stated at the bottom neither worked.
*Peter*
Greg
*Peter*
You said you "even tried a repeat calling synth", which is different from what I suggested: namely, a naked repeat at the end of your main method, which serves to keep the cog alive. As I explained before, calling synth in a repeat loop just keeps reinitializing the counters, rather than letting them produce any sound.
-Phil
For your application, you might try something like this to generate a 3kHz signal...
Freq.Synth("A",PinA,PinB, 3000)
Where PinA and PinB would be your output pins connecting to the piezo.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
here is the final working copy
After running this I about blew my ear drums out. It will definitely be able to be heard outside the project box.
Thanks to Phil & Peter especially for being on the board late at night! You guys were a great help.
Thanks for the code. I was just re-reading the ctra section in the prop manual. What was confusing me was the BPIN reference for diff mode. I was looking at the ctra register map and discovered that bpin was 9 - 14. Once I realized that I found the error of my ways.
Greg