Is it possible to change the volume of a piezo in software
Brian Carpenter
Posts: 728
i read someware that if i use a reistor ladder and a few different pins this would be atainable.· Any thoughts?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It's Only A Stupid Question If You Have Not Googled It First!!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
It's Only A Stupid Question If You Have Not Googled It First!!
Comments
Are you driving it at a fixed frequency, or does it vary within the application?
If it is a "fixed" frequency, then you might be able to find a resonate frequency near the frequency that you desire.
My point is that the resonate frequency will be noticeably louder than a non-resonate frequency. Using this characteristic,
you could effectively change the volume simply by shifting the frequency slightly in or out of resonance.
To find the resonate frequency, just create a test program to sweep a range of frequencies and note where certain peaks are.
Here is a push-pull Piezo amplifier circuit that will efficiently drive a piezo off of a single I/O pin.
http://forums.parallax.com/attachment.php?attachmentid=36227
Also, check out this thread...
http://forums.parallax.com/showthread.php?p=468648
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
P.S. the datasheet for your piezo speaker probably has an average figure for the resonant frequency of that specific speaker, you could start your search around there.
There are yet several other ways to achieve this. If you simply want medium to low volume, just create a single ended (one side of the piezo grounded) pulse-density modulated DAC output that alternates between two voltage levels at the desired resonant frequency of the piezo. Typically somewhere in the 2.5 kHz range. This requires only one DAC (one port bit, a resistor and a capacitor), and the volume is determined by the levels chosen for the DAC levels. And those can be determined in software. Altogether probably a dozen or so lines of ISR assembly routine.
If you need low to higher volume, then make two of those, and run them in opposite phase. This requires two DACs (two port bits, resistors and capacitors), and around two dozen lines of ISR assembler code.
These two approaches use the DACs to generate square waves. You can also go fancier, with another dozen or so lines and generate sine waves, but for a piezo which has a very dominant fundamental, that might not be worth it. You'll have to try.
You can garner a lot of what I'm referring to here, including dual sinewave generation software from perusing one of my entries in last year's Parallax contest. There, with two DACs, I created two separate sinewaves, each of a selectable frequency. If you chose the frequencies to be the same, then also the phase between them can be selected. That is a third way to generate variable levels; the difference between two sinewaves of the same frequency and amplitude is itself a sinewave of the same frequency; its amplitude is a function of the phase relationship between the two; zero when in-phase, and maximum when fully out of phase.
Have fun trying this.
Cheers,
Peter (pjv)