The best way to think about Arduino Nano timers is to think about timers in a basic chip: ATmega328 . It has three timers:
- Timer 0: 8 bit, PWM on pin contacts 11 and 12
- 1:16 , 15 16
- 2: 8-, 17 5
:
, Arduino . , . , :
ISR(TIMER1_OVF_vect) {
...
}
1. TIMSK1. :
TIMSK1 |= (1<<TOIE1);
TIMSK1 |= BV(TOIE1);
TOIE1 ( 1, ) TIMSK1. , , ISR(TIMER1_OVF_vect) .
Arduino delay() (wiring.c):
void delay(unsigned long ms)
{
uint16_t start = (uint16_t)micros();
while (ms > 0) {
if (((uint16_t)micros() - start) >= 1000) {
ms--;
start += 1000;
}
}
}
micros(), timer0. Arduino timer0 , , count0 - , millis() .
delayMicroseconds(), , ; ; nop() ( ), . Arduino Nano 16 , :
if (--us == 0)
return;
us <<= 2;
us -= 2;
: