Pages: [1]   Go Down
Author Topic: tone() and analogWrite what are the limits  (Read 914 times)
0 Members and 1 Guest are viewing this topic.
Vienna
Offline Offline
Newbie
*
Karma: 0
Posts: 7
don't panic!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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-
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 178
Posts: 8064
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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)."
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
Edison Member
*
Karma: 9
Posts: 1010
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 331
Posts: 16464
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Vienna
Offline Offline
Newbie
*
Karma: 0
Posts: 7
don't panic!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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 "Use of the tone() function will interfere with PWM output on pins 3 and 11 (on boards other than the Mega). "

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-
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 178
Posts: 8064
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Pages: [1]   Go Up
Jump to: