Abstract
The disableTimer() initializes the timer/counter set by tone().
It checks the timer/counter number and stops it.
Source Code
The disableTimer() is defined in hardware/arduino/avr/cores/arduino/Tone.cpp as below.
|
|
The input is _timer which is type uint8_t. There is no output value.
It branches according to the _timer. Currently it is 2 or -1. If the _timer is -1, it dose nothing and returns. If the _timer is 2, it sets TIMSK2, TCCR2A, TCCR2B and OCR2A to reset the timer/counter.
|
|
The TIMSK2 is a register to control interrupt mask. In the tone() it sets the OCIE2A bit to 1 to enable interrupt. Here it reset to 0 using bitWrite() to disable interrupt.
The TCCR2A and TCCR2B are registers to control timer/counter2. See analogWrite().
It sets the WGM20 bit of TCCR2A. In this case, timer/counter2 operates as Phase Correct PWM mode, which is used by analogWrite(). In the init(), dose the same.
The TCCR2B is set to bitwise AND of TCCR2B and 0b11111000, then set CS22 bit. This holds upper 5 bits and sets CS22 of lower 3 bits. This sets the division ratio of the clock to 64. In the init(), dose the same too.
Version
Arduino AVR Boards 1.8.6
Last Update
March 21, 2023