84. Timer Modes

Question.2

A square wave of 1 MHz is connected to digital pin 8 of Arduino UNO. In the given code, Timer1 (16-bit) is configured in Input Capture mode with no prescaler, and the CPU clock frequency is 16MHz. After execution of the following code, what will be printed on the serial monitor?

 

Code

uint16_t count = 0;

void setup() {
  pinMode(8, INPUT);
  Serial.begin(9600);
}

void loop() {

  // Input Capture Mode, noise canceler disabled, rising edge trigger, and no prescaling
  TCCR1A = 0;
  TCCR1B = 0x41; 

  TIFR1 = (1 << ICF1);  // clear the capture flag
  while ((TIFR1 & (1 << ICF1)) == 0); // wait for the first rising edge
  count = ICR1;         // capture timer counter register value on rising edge
  TIFR1 = (1 << ICF1);  // clear the capture flag
  while ((TIFR1 & (1 << ICF1)) == 0);  // wait for the second rising edge
  count = ICR1 - count;
  Serial.print(" Timer Ticks in one cycle = ");
  Serial.println(count);
  
  while (1);
}

Select Answer