Using HPWM gives extra-loud piezo tones by pushing an out of phase signal through the piezo, equivalent to changing from a 0V/5V signal to 0V/10V signal.
Any of the out of phase HPWM pin pairs can be used ( AB, AD, BC, CD ), adjust the %1111 and %1010 as appropriate; this example should work with any of the pin pair combinations.
Be aware that this mechanism can generate high volume sound so suitable safety precautions to protect hearing must be taken before running the example program. Those who suffer from audiogenic seizures (AGS), other sound-induced epileptic responses or similar should not use this program.
' Generates 4kHz for a PICAXE at 4MHz
For b0 = 1 To 5
HPwm pwmSingle, pwmLHLH, %1010, 255, 513 ' Normal
Pause 500
HPwm pwmSingle, pwmLHLH, %1111, 255, 513 ' Louder
Pause 500
Next
I don't know what the maximum voltage allowed across a piezo is but even greater volumes could be achieved by using a MAX232 or similar which will push the equivalent of 0V/24V through the piezo. If a higher supply voltage is available a transistor or FET can probably be used with just a single PWM signal. The advantage of HPWM is that it allows two volume levels to be set, more could likely be achieved by using various R's on the HPWM outputs.
Any of the out of phase HPWM pin pairs can be used ( AB, AD, BC, CD ), adjust the %1111 and %1010 as appropriate; this example should work with any of the pin pair combinations.
Be aware that this mechanism can generate high volume sound so suitable safety precautions to protect hearing must be taken before running the example program. Those who suffer from audiogenic seizures (AGS), other sound-induced epileptic responses or similar should not use this program.
' Generates 4kHz for a PICAXE at 4MHz
For b0 = 1 To 5
HPwm pwmSingle, pwmLHLH, %1010, 255, 513 ' Normal
Pause 500
HPwm pwmSingle, pwmLHLH, %1111, 255, 513 ' Louder
Pause 500
Next
I don't know what the maximum voltage allowed across a piezo is but even greater volumes could be achieved by using a MAX232 or similar which will push the equivalent of 0V/24V through the piezo. If a higher supply voltage is available a transistor or FET can probably be used with just a single PWM signal. The advantage of HPWM is that it allows two volume levels to be set, more could likely be achieved by using various R's on the HPWM outputs.