Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 4 of 4

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

  1. #1
    Junior Member
    Join Date
    Feb 2021
    Posts
    6

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

    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

  2. #2
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    1,443
    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.

  3. #3
    Junior Member
    Join Date
    Feb 2021
    Posts
    6
    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?

  4. #4
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    13,903
    Quote Originally Posted by gwpt View Post
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •