I think my IntervalTimer is causing timing issue (delay) with Interupt Pin

Status
Not open for further replies.

gwpt

Member
Hi there,

I have a timer and an interrupt pin set up as follows:

Code:
...
// ATN - Attention Active Low
   pinMode(ATNInteruptPin, INPUT_PULLDOWN);
   attachInterrupt(digitalPinToInterrupt(ATNInteruptPin), ATNHandler, CHANGE);

   myTimer.begin(StatusUpdateTimer, 250000);  // run every 0.25 seconds
...

The interrupt pin is listening to an IEEE-488 attention signal, and after that signal changes state, I must set a different pin to acknowledge the attention within 14us.
Assume I am receiving 100s of attention signals a second, without the timer enabled, this isn't a problem and works all the time. The interrupt goes into the method ATNHandler, I set the pin all good.

But if I enable the timer, occasionally and what seems random (every few seconds) the logic above fails, and the response to the attention signal doesn't occur in time.
I assume ATNHandler isn't being called in time.

I've tried this with no luck:

Code:
void ATNHandler()
{
  noInterrupts();
  if (atn == 0)
  {
    Attention();
  }
  interrupts();
  
}

As I hoped it would cause the timer to not interrupt the pin, so I figure that isn't the issue.

So all I can think of is when it fails, it is currently in the timer code, and it is simply taking too long to service the pin interrupt, i.e. to exit the timer code and service the interrupt.

Doe this sound right?
And if so, any suggestions on how to get around it?

thanks
 
Per default, both ISRs have the same priority. Thus the pin ISR won't interrupt the timer ISR.

Try
Code:
myTimer.begin(StatusUpdateTimer, 250000);  // run every 0.25 seconds
myTimer.priority(64); // set priority to 64 (higher numbers are lower priority). Pin ISR has 32 (IIRC)

This should allow the pin ISR to interrupt the timer ISR.
 
Great, thanks luni

One question, if the code in the timer ISR is interrupted by pin interrupt after the pin interrupt completes, will the remaining code in timer interrupt resume?
and if the timer interrupt had in turn, interrupted code in the main loop, will that code resume after the timer completes?
 
Great, thanks luni

One question, if the code in the timer ISR is interrupted by pin interrupt after the pin interrupt completes, will the remaining code in timer interrupt resume?
and if the timer interrupt had in turn, interrupted code in the main loop, will that code resume after the timer completes?

Yes, that is the nature of interrupts. Execution returns to the point and state of the interruption.
 
Status
Not open for further replies.
Back
Top