83. Timer Programming

Question.5

In the following code the Timer0 overflows after a duration in a loop().

After executing the following code in Arduino UNO how much time duration does Timer0 overflow flag will set(1 cycle of a void loop())?

  • System clock : 16 MHz
  • Prescaler : 1

Code :

void setup() {
  noInterrupts();          // Disable interrupts
  TCCR0A = 0;              // Clear Timer0 control register A
  TCCR0B = 0;              // Clear Timer0 control register B
  TCNT0 = 248;             // Preload Timer0 counter for 8 cycles (0.5 µs)

  TCCR0B |= (1 << CS00);    // Set prescaler to 1 (no prescaling)
  interrupts();             // Enable interrupts
 
}

void loop() {
 
  TCNT0 = 248;          // Reload Timer0 counter
  while (!(TIFR0 & (1 << TOV0))) {
    // Wait for the overflow flag
  }
  TIFR0 |= (1 << TOV0);     // Clear Timer0 overflow flag
}

Select Answer