ToneAC library with Teensy3

Status
Not open for further replies.

Kian

Active member
Hi all,

Just wondering if anyone has used the toneAC library for Arduino on the Teensy3. The library requires specific pins on different microcontrollers so I am not even sure if it would work on the Teensy3.



Cheers,
Kian
 
Please give this a try.

It will output the tone only on pin 3. I didn't manage to recreate the 2 pin feature of toneAC (yet), but the rest should work.
 

Attachments

  • toneAC.cpp
    4 KB · Views: 377
Thanks Paul for the quick response. I had the impression that I need 2 PWM pins on the microcontroller in order to create a "AC" signal. How different is this code you have written?? I presume that it would only give 50% volume right?

Cheers,
Kian
 
Yes, you need the differential pair to get the gain boost. Also note that the Teensy 3.0 is 3.3Volts and not 5V.
A better way to go is to drive the direction pin of a full bridge motor driver that is set up to drive the speaker. This gives you both differential and enough drive for a loudspeaker.
 
The differential signal (which is not yet supported on Teensy3) provides twice the voltage. That might be helpful if you're driving a high impedance piezo transducer that needs more voltage at relatively low current. If you really need 5 volts peak-to-peak using a Teensy3, I'd suggest running the single output into a 74ACHT14 buffer chip (one signal through 1 of the 6 buffers, the other through 2 of the 6 for the negative polarity copy).

For driving an ordinary low impedance (8 or 4 ohm) speaker, the extra voltage really does not help. You're placing at least a 100 ohm resistor in series (a 220 ohm would be wiser), so almost all the voltage is across the resistor. Most of the power dissipates into heating the resistor, not making audio output. For driving a 8 or 4 ohm speaker much louder, you really need a transistor to increase the current. There's no point to using 2 pins for differential drive.

Also, the differential drive does NOT necessarily give you a truly AC waveform. The technique toneAC uses creates an output with a very substantial DC component at volume settings 1 to 9. You really should use a capacitor in series with the speaker.
 
Yes, you need the capacitor for low impedance loads or to add a resistor for capacitive loads like piezo or piezoceramic transducers.
Maxim and TI make custom voltage boosting ampifiers for piezoceramic speaker and their datasheets and app. notes help you compute the right
values, e.g. http://www.maximintegrated.com/app-notes/index.mvp/id/4164

In my fingerphone I use differential drive directly from the Atmega 328P (http://cnmat.berkeley.edu/system/files/attachments/+Nime2012FingerPhone.CR_.pdf)
What made the most difference to sound level though was the choice of driving waveform (sawtooth) and its frequency and bending the paper the transducer was mounted
on. The bending causes stiffness that helps with conversion of the bending waves in the paper to acoustic energy in the air.
 
I'm the author of toneAC and a Teensy 2.0/3.0 owner.

I've found that toneAC will make piezo or a standard 8 Ohm speaker much louder with a resistor. It's not quite twice as loud, but close. The entire purpose of creating toneAC was to generate higher sound pressure levels (higher volume). It's not an AC signal, it's just two pins generating square waves that are 180 degrees out of phase from each other. So in a way, instead of driving a speaker at 5 volts, you're driving it at 10 volts. This generates a higher volume of sound. 6dB would be twice as loud, and twice the voltage is about 5dB louder in my tests with toneAC.

Basically, with just a standard DC square wave you're only ever driving the speaker/piezo membrane in one direction. With toneAC, you're driving it in both directions so the membrane moves twice as far. This generates a higher volume level. The other advantage is that it's better for the piezo membrane as driving it only in one direction will cause it to deform over time. Sending the piezo an alternating polarity keeps the stress equal in both directions which won't cause it to deform.

In any case. This is all true if running toneAC on the ATmega. While the Teensy 3.0 modifications will play tones, it's not louder than any other method of sound output as it only drives one pin.

Tim Eckel
 
Last edited:
I'm considering adding an analogWritePolarity() function for 1.15. When that's available, it will be feasible to create the 2 pin output without embedding direct register access into the library (something I'd like to avoid).
 
I would like to see an API function too. What is hard though is knowing which pins are paired with which - on implementations with timers there are lots of constraints and the Arduino doesn't yet have a capability API for pin/feature mapping.
 
Arduino doesn't yet have a capability API for pin/feature mapping.

In the early days of Teensy, I repeatedly begged them to add such a feature. I submitted several attempts, but all were rejected.

It turned out to be much easier to just patch every widely used library.
 
Yes, I am engineering my way around this problem with an inordinate number of #ifdef's and testing sessions - hopefully so you don't have to
patch our libraries. The Arduino approach isn't scalable or inclusive and it has the side effect of raising the cost of "keeping up" which "weeds out"
board developers unable to keep up with the IDE and libraries entrained to them (e.g. Maple). It looks like library developers are feeling the strain now too.
I imagine the response from Arduino to be the usual one: "we need to focus on giving our users a stable, reliable platform." I am old enough to have heard this many times: ATT's commercial UNIX, Sun, Wang, DEC etc. Where are those companies/products now? Their users defected to alternatives where their needs were more readily met.
 
Status
Not open for further replies.
Back
Top