How the ISR (ANALOG_COMP_vect) to run inside a Tab?

Hi,
Here is a multi_Tabs sketch, the test code included:
Tab1_setup();
and
Tab1_loop();

my question is how the ISR section that doesn't inside setup and loop, can run?

ISR (ANALOG_COMP_vect)
{
  byte count = 0;
  for (byte i = 0; i < 50; i++) {
    if ( ACSR & 0x20 )
      count++;
  }

  if (count > 48)
    per++;
}

Thanks
Adam

ppp3

ppp4

"ISR" in the function macro ISR is an abbreviation for "Interrupt Service Routine", which is automatically called by uC when the corresponding interrupt (from analog comparator in this case) occurs.
Of course, it is necessary that global interrupts are enabled and that analog comparator interrupts are enabled.
Then the contents of the ISR will be executed if the conditions for generating the interrupt are met.

1 Like

You have to set up the comparison conditions you want inside setup(). Global interrupts are on by default...

void setup()
{
  ACSR = B01011010; // comparator interrupt enabled and tripped on falling edge.
}

See the datasheet of the Atmel328 for all the details

1 Like

Thank you.

Thanks.