I am trying to understand how tone function works. seems like I can use tone function in a non-PWM channel as well. can you please explain how tome() function was written? If a timer was used then how that was implemented?
Asked
Active
Viewed 904 times
-1
-
3You can check out the source code of `tone`: https://github.com/arduino/ArduinoCore-avr/blob/master/cores/arduino/Tone.cpp – CherryDT Aug 12 '20 at 06:52
-
with timer interrupt. tones are 'slow' for PWM – Juraj Aug 12 '20 at 07:13
1 Answers
1
The function uses timer interrupts to toggle an output pin.
The timer is set up using the frequency parameter. In the toneBegin function
The pin is toggled for a number of times that is calculated from duration and frequency.
https://github.com/arduino/ArduinoCore-avr/blob/master/cores/arduino/Tone.cpp

Piglet
- 27,501
- 3
- 20
- 43