toneAC - Twice the volume, higher quality and frequency Arduino tone library

teckel:
Concept is simple. I wanted to create an AC type output from two PWM pins using the same timer (timer 1) at a very high speed. The purpose is to create a higher sound pressure level output from a piezoelectric transducer than the standard pulsed-DC method used in the Tone library. Basically, instead of a pulsed-DC +5v and 0v (5 volt range) signal, driving two pins out of phase yields an effective +5v and -5v (10 volt range).

The tone library won't work as it doesn't do in/out of phase (also may have high frequency issues when the ATmega is running at low speed). The TimerOne library won't work because it also doesn't do in/out of phase PWM.

I couldn't find such a library, so I wrote a very fast port register level library that provides a perfect in-phase and out of phase PWM signal on two PWM pins. On an Arduino Uno you would tie the piezoelectric buzzer to pins 9 and 10 and using my library specify the frequency and you're done. Even if running the ATmega at 4 MHz like I was, this library can still create an ultrasonic frequency, and much louder than with the Tone library as it's driving both pins out of phase with each other. It always keeps the duty at 50% for the highest output.

Anyway, did I miss a library that does this? Or, is there interest in me turning it into a library for the community. It wouldn't be difficult, but there's no reason to bother if no one is interested. Think of it like a high-power and faster version of the Tone library but fixed to the assigned PWM pins for timer 1 (9 & 10 for Uno) (14 & 15 for Teensy 2.0) (11 & 12 for Mega).

Tim

While I don't have a project right now that would use it, why would anyone say no to a new useful library?

Yes...Yes..Yes...