Go Down

Topic: tone() and analogWrite what are the limits (Read 1 time) previous topic - next topic

huebsch

Folks!
I'm using analogWrite to drive LEDs via power FETs. To improve theuser interface I want to confirm key strokes with short beeps. Currently I use 4 analog outputs - all fine. As soon as I engage a tone() command one of the analog outputs dies. I guess I'm hitting a limit on Interrupts or so but as far as I was able to find resources I do not expect that.
I'm using a leonardo board.

Any ideas or pointers where I could find information to a solution?
tks
-AH-

johnwasser

http://arduino.cc/en/Reference/Tone
"Use of the tone() function will interfere with PWM output on pins 3 and 11 (on boards other than the Mega)."
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Krodal

Can you tell us how you use the pins.
We need to know exactly which pins you are using.
Arduino Leonardo: http://arduino.cc/en/Main/arduinoBoardLeonardo

The analog input no longer working makes no sense.
Do you use a lot of ram ?
Or do you use an analog input that is capable of PWM output ?

My best guess is, that you use a lot of ram (buffers, arrays, strings, variables), and have a stack/ram overflow.

retrolefty


Can you tell us how you use the pins.
We need to know exactly which pins you are using.
Arduino Leonardo: http://arduino.cc/en/Main/arduinoBoardLeonardo

The analog input no longer working makes no sense.
Do you use a lot of ram ?
Or do you use an analog input that is capable of PWM output ?

My best guess is, that you use a lot of ram (buffers, arrays, strings, variables), and have a stack/ram overflow.


That's not what he said. He has analogWrites() (PWM outputs) stop working when he uses  the tone library.

Bottom line, AnalogWrite commands use timer resources to support the pwm output pins. The ton library uses timers depending on how many simultaneous notes you wish to use. So there can be a conflict for timer resources, so careful selection of pin numbers used and a understanding of the timer resources available is the key to allowing both functionalities to exist in the same sketch. Different atmega chips have different number of timers so that is also a variable to consider.

Lefty

huebsch

Folks!
Thanks for the advice I was sure it will turn out as a layer 8 issue! I've checked the tone() page several times but I have overseen the hint "[font=Courier]Use of the tone() function will interfere with PWM output on pins 3 and 11 (on boards other than the Mega). [/font]"

On my Leonardo the interference of the tone function is not on pin 3 but on pin 5. It took me some more time to verify each analog output line to find this out. I x-checked that with 3 Leonardos.

How can we feed back this info to update the reference page for tone()?
-AH-

johnwasser


How can we feed back this info to update the reference page for tone()?
-AH-


Request the change in a post to the Community->Website and Forum forum.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Go Up