External Interrupt ISR Execution Latency

Is there any way to estimate the time it takes for an ISR() interrupt routine on an external interrupt pin to begin execution? The interrupt calls this function:

void LED_V3::StartTimer()
{
  TCCR1A = 0;        // reset timer 1
  TCCR1B = 0;
  
 // set up Timer 1
  TCNT1 = 0;         // reset counter

  
  OCR1A =  m_timerCounter;       // compare A register value 

 
  TIFR1 |= _BV (OCF1A);    // clear interrupt flag
  TIMSK1 = _BV (OCIE1A);   // interrupt on Compare A Match  
}

My setup:
Arduino Nano 3.0 w/ATmega 328
Interrupt Input on Pin 2 (Trigger On Input Low)

Interrupt Input on Pin 2 (Trigger On Input Low)

This means that your ISR will be called over and over as long as the pin is LOW. Is this really what you want? Or do you really want FALLING?

No, that wouldn't be good. "Falling" it is.

Still need help on time calculations.

There's an excellent writeup linked to by a thread On this site - search for interrupt latency maybe. I believe the basic answer is several microseconds but there are ways to improve it.

Bill:

Thanks for the response. I didn't find the link on a search, but I did fine this third party post:

I'd like to know about the methods of improving latency. I'll bet it involves writing assembly language (I suck at that!).

Also, do you think the delay will be consistent on each iteration? Even if it's 5 microseconds, I can deal with it if it's always the same.

Also, do you think the delay will be consistent on each iteration? Even if it's 5 microseconds, I can deal with it if it's always the same.

Well the arduino timer 0 is used in most sketches to support millis() and other timing functions and it uses interrupts so there is always the chance at any given instance where your user interrupt activates but if the timer ISR is active the user interrupt has to wait for the timer interrupt ISR to finish, so there is always going to be some small possible variation in latency timing. It is possible for you to disable timer 0 interrupts in your start-up code but that will eliminate being able to use some of the standard arduino supplied functions.

Lefty

Hi,

Whats your application, there may be better alternatives or the inaccuracy may be more than compensated by the reaction time of the rest of the circuit, for example in my RC Cars I often have three interrupts queued up and it introduces an error of 1 or 2% but as I am physically incapable of steering my car with greater than 1% accuracy and the car is physically incapable of reacting to the occasional 1 or 2% error it has absolutely no impact.

Your application may of course require better accuracy but if it doesn't your just making unnecessary work for yourself

Duane B

if the timer ISR is active the user interrupt has to wait for the timer interrupt ISR to finish

Since I call a single iteration of Timer1 in this interrupt, I know that Timer1 won't be busy. As far as Timer0 goes, I don't think I would have any code beyond the Ethernet polling that would be operating that would use it.

My application is film scanning. The delay between the incoming pulse on INT0 affects the vertical framing of each frame, so consisten latency is kind of important.

so consisten latency is kind of important.

On a web server? I hardly think so.

renniejohnson:

if the timer ISR is active the user interrupt has to wait for the timer interrupt ISR to finish

Since I call a single iteration of Timer1 in this interrupt, I know that Timer1 won't be busy. As far as Timer0 goes, I don't think I would have any code beyond the Ethernet polling that would be operating that would use it.

I don't know anything about Ethernet, but the arduino start-up default sketch coding will activate timer0 unless you take explicit steps to disable timer0 interrupts, and as I said disabling timer0 will break certain arduino functions you might be using.

My application is film scanning. The delay between the incoming pulse on INT0 affects the vertical framing of each frame, so consisten latency is kind of important.

On a web server? I hardly think so.

Just for the record, I don't use the ethernet for a web server. This is single client server for a PC workstation. The client app is my own application that is designed to understand and work with the Arduino sketch for maximum efficiency. But I'm sure it's still doing some Timer0 stuff under the hood.

Just for the record, I don't use the ethernet for a web server.

Then, what, exactly, does this mean?

As far as Timer0 goes, I don't think I would have any code beyond the Ethernet polling that would be operating that would use it.