Pages: [1]   Go Down
Author Topic: External Interrupt ISR Execution Latency  (Read 1518 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 1
Posts: 77
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

Code:
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)
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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?
Logged

Offline Offline
Jr. Member
**
Karma: 1
Posts: 77
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Still need help on time calculations.
Logged

ottawa, canada
Online Online
God Member
*****
Karma: 6
Posts: 990
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Jr. Member
**
Karma: 1
Posts: 77
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Bill:

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

http://billgrundmann.wordpress.com/2009/03/02/the-overhead-of-arduino-interrupts/

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.

Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17263
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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
« Last Edit: July 23, 2012, 12:36:03 pm by retrolefty » Logged

Dubai, UAE
Offline Offline
Edison Member
*
Karma: 22
Posts: 1675
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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





Logged


Offline Offline
Jr. Member
**
Karma: 1
Posts: 77
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
so consisten latency is kind of important.
On a web server? I hardly think so.
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17263
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

Offline Offline
Jr. Member
**
Karma: 1
Posts: 77
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Just for the record, I don't use the ethernet for a web server.
Then, what, exactly, does this mean?
Quote
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.
Logged

Pages: [1]   Go Up
Jump to: