In SX Microcontrollers, SX/B Compiler and SX-Key Tool, Peter Van der Zee wrote: Hi Altitudeap; 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) ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=128282#m128393 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2006 (http://www.dotNetBB.com)