Go Down

Topic: max frequency of tone() (Read 2798 times) previous topic - next topic

Quan

Mar 17, 2010, 08:53 am Last Edit: Mar 17, 2010, 09:26 am by friedrice4u Reason: 1
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?

cr0sh

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!

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

cr0sh

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!

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

cr0sh

Have you tried passing it as 38000U?
I will not respond to Arduino help PM's from random forum users; if you have such a question, start a new topic thread.

Go Up