Ever have a need for a loud audio alarm, but don’t have the real estate or budget for a driver. Well, don’t despair; there is a simple way to boost the power of a little piezoelectric buzzer. All you have to do is drive it with a differential output; and if you have a spare ECCP on the microcontroller then you have everything you need to make some noise.
Start by configuring the ECCP for a Half H Bridge output drive, this puts out two PWM outputs that are the inverse of each other. Now just connect the two terminals of the buzzer to the two outputs and there you have it, a 10V PWM drive for your buzzer. The outputs are good for 20mA so most buzzers can be driven directly, and because the drive voltage is doubled, the output power is increased 4:1.
Now, for an interesting modification, play with the dead time setting out the ECCP. This holds both outputs inactive for a set time at each state transition of the output, effectively reducing the duty cycle of the drive on both the positive and negative side of the pulse. This has the effect of reducing the drive on the buzzer, so basically you get a course volume control for the buzzer.
Alright, what are the calculations required? Let’s assume a 4kHz buzzer and a 1 MIP instruction rate. The period should be set to 250 ( 1MIP / 4KHz). To generate a tone, set the duty cycle to 50%, and to turn the tone off set the duty cycle to 0%. To vary the volume, vary the dead time between 0 and 125. At 0 dead time, you get the full volume output, and at 125 the total dead time is 250 which effectively shuts off the outputs.
So, there you have it, a complete 10V drive for your buzzer, complete with a 125 step volume control and all it costs is a spare ECCP and two pins.