Pages: [1]   Go Down
Author Topic: max frequency of tone()  (Read 2373 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi everyone,

I'm trying to use the native tone() function to generate a 38KHz signal for IR transmission however I don't believe I'm getting the correct output.

tone(13, 38000,1000) should give me a 38KHz signal on pin13 for 1 second, however I only see the pin on for a very short time (definitely not one second). I lowered the frequency to 30000 (30KHz) and the duration is correct. I'm just wondering what the maximum frequency tone() is able to correctly produce?

I would like to use the tone() function instead of creating my own because it's non-blocking. :-?


=== update ===
i think i just answered my own question: most likely the argument for frequency is an int, which means the max value is 2^15... JUST shy of 38000.

Any suggestions for how I can get the library to support an unsigned int or long as the frequency argument?
« Last Edit: March 17, 2010, 03:26:39 am by friedrice4u » Logged

Phoenix, Arizona USA
Offline Offline
Faraday Member
**
Karma: 39
Posts: 5551
Where's the beer?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Try a frequency of 32767 - if that works, but 32768 doesn't, then that is your answer (the frequency variable is an unsigned int, maybe?) - hmm, I am looking at the tone ref:

http://arduino.cc/en/Reference/Tone

Why don't these things tell you what the type of variable the arguments are? It would be very helpful!

Logged

I will not respond to Arduino help PM's from random forum users; if you have such a question, start a new topic thread.

Phoenix, Arizona USA
Offline Offline
Faraday Member
**
Karma: 39
Posts: 5551
Where's the beer?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yep - I think we both hit on it! Its actually a signed int (-32768 to 32767) instead of an unsigned int (0-65535)...

As far as changing it - off the top of my head, no idea!

 smiley
Logged

I will not respond to Arduino help PM's from random forum users; if you have such a question, start a new topic thread.

Phoenix, Arizona USA
Offline Offline
Faraday Member
**
Karma: 39
Posts: 5551
Where's the beer?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Have you tried passing it as 38000U?
Logged

I will not respond to Arduino help PM's from random forum users; if you have such a question, start a new topic thread.

Pages: [1]   Go Up
Jump to: