Calling a function inside an ISR

I want to use a timer interrupt and I want my ISR to look something like this:

void ISR()
{
 count++; 
 if(count == 500)
 {
   callFunction();
 }
}

Is this possible?

Is it possible?

Yes.

Will it work as expected?

Depends on the function called.

Is it sensible for non-trivial functions?

Very rarely.

Whandall: Is it possible?

Yes.

Will it work as expected?

Depends on the function called.

Is it sensible for non-trivial functions?

Very rarely.

Thank you for the quick reply! I shall post on this thread if I get further doubts!

General advice when using interrupts is that the interrupt servicing code should do as little as possible - say set a flag or something similarly small.

Your non-interrupt code should act when that flag is set, which probably means you need to avoid using delay.

abhir24: I want to use a timer interrupt and I want my ISR to look something like this:

void ISR()
{
 count++; 
 if(count == 500)
 {
   callFunction();
 }
}

Is this possible?

Don't do that if callFunction() could possibly take more than a few hundred microseconds.

boolean DoTheCall = false;
void ISR() {
  count++; 
  if (count == 500) {
    DoTheCall = true;
    count = 0;  // Did you forget this or is count reset somewhere else?
  }
}


void loop() {
  if (DoTheCall) {
callFunction();
DoTheCall = false;
  }
}

johnwasser: Don't do that if callFunction() could possibly take more than a few hundred microseconds.

I worked on the code in the evening after work and I came up with a very similar solution like your's, John. Thank you for the help, nevertheless.

wildbill: General advice when using interrupts is that the interrupt servicing code should do as little as possible - say set a flag or something similarly small.

Your non-interrupt code should act when that flag is set, which probably means you need to avoid using delay.

I used the ISR only to set a flag and then later polled that flag in the loop(). Worked great! Thank you!