Use software PWM. If instead of grounding one pin and turning the other one on and off to get the piezo to sound you swap both legs at the same time it'll double the effective voltage the piezo sees. It should increase the volume. Nigel explained that one to me a while back. It's like using a two way speaker instead of a single ended one.
The volume is pretty load as it is, and it is a lot easier to use the hardware PWM, but I may give this a try. Presumably doing it this way would get rid of the need for the 1K discharging resistor across the piezo.
In the meantime, I'm going to send off the prototype to Mrclox.
The volume is pretty load as it is, and it is a lot easier to use the hardware PWM, but I may give this a try. Presumably doing it this way would get rid of the need for the 1K discharging resistor across the piezo.
I built a new board with the piezo sounder connected to two PIC outputs and drove the two pins in opposite directions. I was surprised when the volume was actually lower in this configuration.
In the end I built three test configurations (labelled A, B and C in the diagram - other parts left off for clarity)
Driving the piezo speaker single ended with no discharge resistor (as in circuit A) gave quite low volume.
Driving the piezo speaker double ended (as in circuit C) was much louder.
Driving the piezo speaker single ended with the 1K discharge resistor (as in circuit B) was louder yet.
No, it doesn't. It turns out that my software PWM routine was at a different frequency than the hardware PWM. The device is quite frequency sensitive.
When I made sure they were operating at the same frequency, then the double ended method is noticably louder, although I wouldn't say it was significantly louder.
I wrote a program that drives the piezo speaker both ways, alternating every few seconds so that I could hear them juxtaposed.
The more I fiddle with this and zero in on the resonant frequency, the larger the difference in volume between the double ended approach and the single ended approach becomes.
You should sweep your PWM's frequency while listening to it to find out the resonance of the piezo. They're incredibly loud at resonance. You can use a variable that gradually increases in your delay loop