max frequency of tone()

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?

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:

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

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!


Have you tried passing it as 38000U?