gauranggoyal123 / arduino

Automatically exported from code.google.com/p/arduino
Other
0 stars 0 forks source link

tone needs typecast in toggle_count calculation #1065

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

call tone(13,32768,100);

What is the expected output? What do you see instead?

Expected output: a 100 ms burst of a 32768 Hz square wave.
Real output: nothing. 

The reason is an overflow in the calculation of toggle_count in the function 
tone. Overflow occurs for frequencies > 32767 Hz. Line 339:

      toggle_count = 2 * frequency * duration / 1000;

should be

      toggle_count = 2 * (long)frequency * duration / 1000;

What version of the Arduino software are you using? On what operating
system?  Which Arduino board are you using?

Arduino 1.0.1 on Windows 7 and an Arduino Uno board

Regards,
Clemens

Original issue reported on code.google.com by ElektorEmbedded on 7 Oct 2012 at 2:50