8000 add comments for tone max frequency limit · esp8266/Arduino@f5000ad · GitHub
[go: up one dir, main page]

Skip to content

Commit f5000ad

Browse files
committed
add comments for tone max frequency limit
1 parent a04c324 commit f5000ad

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

cores/esp8266/Tone.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@ static void _startTone(uint8_t _pin, uint32_t high, uint32_t low, unsigned long
3535

3636
pinMode(_pin, OUTPUT);
3737

38-
high = std::max(high, (uint32_t)100);
39-
low = std::max(low, (uint32_t)100);
38+
high = std::max(high, (uint32_t)100); // 5KHz maximum tone for Arduino compatibility
39+
low = std::max(low, (uint32_t)100); // (100us high + 100us low period = 5KHz)
4040

41-
if (startWaveform(_pin, high, low, (uint32_t) duration * 1000)) {
41+
duration *= 1000UL;
42+
duration -= duration % (high + low);
43+
if (startWaveform(_pin, high, low, duration)) {
4244
_toneMap |= 1 << _pin;
4345
}
4446
}

0 commit comments

Comments
 (0)
0