Go Down

Topic: toneAC v1.2 - Twice the volume, higher quality, higher frequency, etc. (Read 17 times) previous topic - next topic

teckel

As promised, the pin flexible and timer 2 version of toneAC was released.  You can download it from the toneAC development page here:

toneAC2 - v1.0

This is an alternate version of toneAC that uses timer 2 instead of timer 1 and allows for any two pins to be used.  You should still try to use toneAC first, as it's more accurate, higher quality, allows for higher frequencies, and creates smaller code.  However, if you're having a conflict with timer 1, or just can't use the PWM pins for timer 1, then toneAC2 may be your answer.

toneAC2 is a replacement to the standard tone library with the advantage of nearly twice the volume, 800 bytes smaller compiled code size, and less stress on the speaker. This alternate version uses timer 2 and allows for flexible pin assignment. The primary version (toneAC) allows for higher frequencies, higher quality, and even smaller code size. However, toneAC is fixed to using the PWM timer 1 pins unlike toneAC2 which can use any two pins. Both exclusively use port registers for the fast and smallest code possible.

Let me know if there's any problem.  Oh, I didn't add Leonardo and Teensy 2.0 support.  I forgot how different timer 4 was on those compared to timer 2.  It seemed too much like work to make it compatible so I released it as-is.

Tim
Arduino - Teensy - Raspberry Pi
My libraries: NewPing - LCDBitmap - toneAC - NewTone - TimerFreeTone

Krodal


teckel


I'm waiting for toneAC version 1.2.


Sorry about that, kind of forgot about releasing it.  It's been packaged for distribution for 7 days but I was working with someone via PM to confirm compatibility. In any case, v1.2 is now online and ready to download.

Download:
toneAC v1.2

New in v1.2:
Fixed a counter error which went "over the top" and caused periods of silence (thanks Krodal). For advanced users needing tight code, the TONEAC_TINY switch in toneAC.h activates a version of toneAC() that saves 110 bytes. With TONEAC_TINY, the syntax is toneAC(frequency, length) while playing the note at full volume forever in the background. Added support for the ATmega 640, 644, 1281, 1284P and 2561 microcontrollers.

Tim
Arduino - Teensy - Raspberry Pi
My libraries: NewPing - LCDBitmap - toneAC - NewTone - TimerFreeTone

Krodal

Library toneAC version 1.2 tested with Uno, Leonardo, Mega 2560, ATmega8 16MHz. Everything is okay.
Library toneAC version 1.2 with option TONEAC_TINY tested with ATmega8 16MHz. Also okay, 140 bytes smaller.

The TONEAC_TINY version has implications for the source code.
If I would use toneAC(1000,5); and switch to TONEAC_TINY, I must change that line. That is not obvious, since it is the same function "toneAC".
The second parameter changes from volume to duration.
Adding a second parameter (an unused volume byte) changes the size saving from 140 to 106.
I don't know what to think of it.

What about a ToneAC page in the Playground section ?


robtillaart

Quote
What about a ToneAC page in the Playground section ?

Good idea!
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up