Go Down

Topic: NewTone Library - Plug-in replacement for Tone library - Better, smaller, faster (Read 40668 times) previous topic - next topic

Zainwan

Hi,

Does this library works together with addressable LED strips (NeoPixel library)?
Because to get the tight timing needed by the LED strips interrupts are disabled while sending the data.
So the original Tone() library doesnt work for me. Wondering if newTone Library works?

mcmahonrw


teckel

Any plans for supporting ATtiny85 (Adafruit Trinket)?
Not sure if it would be possible do to the use of timers.  But, I do know that my TimerFreeTone library is compatible with the ATtiny 85 (and just about any other platform as it doesn't use timers).

Tim

My platforms Arduino, Teensy 3.2, Arduino Pro Mini, ATmega328
My libraries: NewPing, LCDBitmap, toneAC, toneAC2, NewTone, TimerFreeTone
My projects: https://dogblocker.com & https://baconorbeer.com
My beer: Great Lakes Brewing Co. Lake Erie Monster

HoracioDos

Hi!

I'm very new to Arduino and electronics. I'm building a capacitive touch morse keyer and I need to generate a 800 to 1200 Hz tone. I still don't know for sure if a sine wave is needed or a square wave is good enough to TX with a simple LPF.

Does the NewTone() make a square wave output like tone()?

I have found that NewTone(pin, freq) makes a little noise when it's ended with noNewTone(), but if I set a duration, the tone ends clean.

I would like to code something like this example, but with a fixed duration. Do you have other library that I could use?

Thanks in advance.

teckel

Hi!

I'm very new to Arduino and electronics. I'm building a capacitive touch morse keyer and I need to generate a 800 to 1200 Hz tone. I still don't know for sure if a sine wave is needed or a square wave is good enough to TX with a simple LPF.

Does the NewTone() make a square wave output like tone()?

I have found that NewTone(pin, freq) makes a little noise when it's ended with noNewTone(), but if I set a duration, the tone ends clean.

I would like to code something like this example, but with a fixed duration. Do you have other library that I could use?

Thanks in advance.
Yes, NewTone creates a square wave.  The Arduino can't output a sine wave.  If you need a sine wave, I would suggest using a Teensy 3.2

If you end a tone early it may stop in the middle of the high state.  If it ends on it's own, it always finishes the high state before ending. 

I don't understand your last question.  You want to code something like what example?  NewTone does do a fixed duration so I'm confused.

Tim
My platforms Arduino, Teensy 3.2, Arduino Pro Mini, ATmega328
My libraries: NewPing, LCDBitmap, toneAC, toneAC2, NewTone, TimerFreeTone
My projects: https://dogblocker.com & https://baconorbeer.com
My beer: Great Lakes Brewing Co. Lake Erie Monster

HoracioDos

Hello Tim!

Thanks for your quick answer.

I have attached in the previous post an example from make magazine that creates a sine wave that never ends. I'm trying to merge your library and this example to generate a sine wave with a fixed duration. As I dont want to abuse of your time ¿Do you know or have something already made that I can use?

For example teensy 3.2 could be an option.

Again Thanks!
H

teckel

Hello Tim!

Thanks for your quick answer.

I have attached in the previous post an example from make magazine that creates a sine wave that never ends. I'm trying to merge your library and this example to generate a sine wave with a fixed duration. As I dont want to abuse of your time ¿Do you know or have something already made that I can use?

For example teensy 3.2 could be an option.

Again Thanks!
H
Just so you know, this doesn't generate a sine wave.  It creates a simulated sine wave.  You could create a sketch that would modify this SineWave sketch and create a function that would play a simulated sine wave at a preset frequency.  But, it will still be a simulated sine wave, not an actual sine wave.

Keep in mind that a digital pin can only be on or off.  So, no matter the code, that's all it can output.  This SineWave sketch doesn't actually produce anything close to an actual sine wave.  In other words, if you really need a sine wave, this SineWave sketch isn't going to do it for you.

Tim
My platforms Arduino, Teensy 3.2, Arduino Pro Mini, ATmega328
My libraries: NewPing, LCDBitmap, toneAC, toneAC2, NewTone, TimerFreeTone
My projects: https://dogblocker.com & https://baconorbeer.com
My beer: Great Lakes Brewing Co. Lake Erie Monster

HoracioDos

Thank you Tim for explaining me so clearly. You have helped a lot and made think about other options.

outlookhazy

Certainly not the author's fault, but FYI I attempted to use this as a drop-in replacement for tone in my application and caused a small fire... (I'm driving an inductor/oscillator pretty hard). Not sure if the duty cycle was higher, or it just kept the pin high for too long for some other reason.
The only other library i'm using in this sketch is debounce, I don't think there are any timer conflicts there

teckel

Certainly not the author's fault, but FYI I attempted to use this as a drop-in replacement for tone in my application and caused a small fire... (I'm driving an inductor/oscillator pretty hard). Not sure if the duty cycle was higher, or it just kept the pin high for too long for some other reason.
The only other library i'm using in this sketch is debounce, I don't think there are any timer conflicts there
A timer conflict wouldn't cause it and even if the pin was kept high for a long time it wouldn't cause a fire at 5 volts.  Something else is wrong, it's not the software.

Tim
My platforms Arduino, Teensy 3.2, Arduino Pro Mini, ATmega328
My libraries: NewPing, LCDBitmap, toneAC, toneAC2, NewTone, TimerFreeTone
My projects: https://dogblocker.com & https://baconorbeer.com
My beer: Great Lakes Brewing Co. Lake Erie Monster

srnet

You may be intersted in a problem I have encountered when using TimerFreeTone on a DUE;

http://forum.arduino.cc/index.php?topic=442298.msg3044752#msg3044752

I dont think the problem is with TimerFreeTone, but something unique to the DUE, whereby the timing (TimerFreeTone or bitbanging) gets messed up depending on where the code ends up in memory.
$50SAT is now Silent (but probably still running)
http://www.50dollarsat.info/
http://www.loratracker.uk/

teckel

You may be intersted in a problem I have encountered when using TimerFreeTone on a DUE;

http://forum.arduino.cc/index.php?topic=442298.msg3044752#msg3044752

I dont think the problem is with TimerFreeTone, but something unique to the DUE, whereby the timing (TimerFreeTone or bitbanging) gets messed up depending on where the code ends up in memory.
All TimerFreeTone is does is set a pin high, delay, set pin low, delay, repeat until duration is met.  This would also be the same with the code you wrote on your own.  Therefore, there must be something happening with the delayMicroseconds() function on the Due.

While TimerFreeTone doesn't use a timer interrupt, other code could be which could cause problems with the delayMicroseconds() function.  For example, Serial.write() uses interrupts which could throw off the delayMicroseconds() function, which in turn would mess up TimerFreeTone.

I believe you've answered your own question.  Serial.write() effects the timer functions on the DUE for a few ms as it writes data to the serial port.  So, if you must use a Serial.write(), add a delay after so it doesn't mess with the frequency you're trying to generate with TimerFreeTone.

The other solution is to use one of the timers on the DUE to replace TimerFreeTone.  While TimerFreeTone will work on the DUE, there's far better and more accurate ways of doing it on the DUE.

Tim
My platforms Arduino, Teensy 3.2, Arduino Pro Mini, ATmega328
My libraries: NewPing, LCDBitmap, toneAC, toneAC2, NewTone, TimerFreeTone
My projects: https://dogblocker.com & https://baconorbeer.com
My beer: Great Lakes Brewing Co. Lake Erie Monster

2knuckels

PLAYBACK of RAW wave data

Im playing around with your Newtone lib, and I want to playback a raw sound file (1 second) loaded in the flash mem of the nano.

My problem is in what format do I have to provide the sound data that it plays correctly

(The origin is a wav file which I converted to raw 8 bit data with the correct sample rate 2 kHz).

In your comments of the toneAC thread I read, that it is easy to playback raw sound data.

I would be glad if you or some else could give me a hint how to do it.

(I can not use a media player because I want to modify the frequency during runtime)

teckel

PLAYBACK of RAW wave data

Im playing around with your Newtone lib, and I want to playback a raw sound file (1 second) loaded in the flash mem of the nano.

My problem is in what format do I have to provide the sound data that it plays correctly

(The origin is a wav file which I converted to raw 8 bit data with the correct sample rate 2 kHz).

In your comments of the toneAC thread I read, that it is easy to playback raw sound data.

I would be glad if you or some else could give me a hint how to do it.

(I can not use a media player because I want to modify the frequency during runtime)

The sample NewTone library sketch (https://bitbucket.org/teckel12/arduino-new-tone/wiki/Home#!example) plays back a song.  You would use a similar process to convert your raw sample to frequencies and build an array would you would then loop through.

Tim
My platforms Arduino, Teensy 3.2, Arduino Pro Mini, ATmega328
My libraries: NewPing, LCDBitmap, toneAC, toneAC2, NewTone, TimerFreeTone
My projects: https://dogblocker.com & https://baconorbeer.com
My beer: Great Lakes Brewing Co. Lake Erie Monster

2knuckels

Thank you for the quick reply.
So I am on the right way, ->
I only have to find the right delays, because the main frequencies I got with an FFT.
(15 Hz, 38 Hz, 79 Hz peak 2, 92 Hz peak 1, 115 Hz, 184 Hz, 267 Hz peak 3)
In case someone has already found the "melody" for the lightsaber "hum" it would be kind to post it.

Go Up