arduino / arduino/ArduinoCore-avr
tone needs typecast in toggle_count calculation [imported]
- Dominant language
- C
- Stars
- 1.5k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
This is [Issue 1065](http://code.google.com/p/arduino/issues/detail?id=1065) moved from a Google Code project.
Added by 2012-10-07T14:50:44.000Z by [ElektorEmbedded](http://code.google.com/u/ElektorEmbedded/).
Please review that bug for more context and additional comments, but update this bug.
Original labels: Type-Defect, Priority-Medium
### Original description
**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
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.