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

I was curious about delay and accuracy when using external hardware interrupts on INT0 and INT1 pins 2 and 3.  I need to respond to an external shutter signal generated by a digital camera to turn LED lamps on and off concurrently with the generated signal.  Because this is a video application, each execution need to be very consistent, or flicker will occur between each capture.

This is an example code I found to set this up:

The following example code is found at: http://www.engblaze.com/we-interrupt-this-program-to-bring-you-a-tutorial-on-arduino-interrupts/

Code:
#include <avr/interrupt.h>
                              //
void setup(void)
{
    pinMode(2, INPUT);
    digitalWrite(2, HIGH);    // Enable pullup resistor
    sei();                    // Enable global interrupts
    EIMSK |= (1 << INT0);     // Enable external interrupt INT0
    EICRA |= (1 << ISC01);    // Trigger INT0 on falling edge
}
                              //
void loop(void)
{
                              //
}
                              //
// Interrupt Service Routine attached to INT0 vector
ISR(EXT_INT0_vect)
{
    digitalWrite(13, !digitalRead(13));    // Toggle LED on pin 13
}

If I set up a hardware interrupt to set a pin HIGH during the trailing edge and LOW on a rising edge, how much time would elapse between the state changes and the pin changing HIGH/LOW?  How consistent woud the delay be between executions?  Are we talking microseconds, nanoseconds?  I was hoping for an accuracy of just a few microseconds.

Also, do the hardware interrupt pins use a timer, and does the timer frequency affect the response time?

Hardware: Nano 3.0/328p

Thanks for your guidence.
Logged

Montreal
Offline Offline
Faraday Member
**
Karma: 31
Posts: 2611
Per aspera ad astra.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
how much time would elapse between the state changes and the pin changing HIGH/LOW?
I've read a few times on this forum that latency interrupt around 3.5 usec, it's time required uCPU to finish current instruction, and push stuff in stack. This time would vary depends on this "current" instruction  1 - 4 cycles, 1/16 MHz or 62.5 nsec per cycle, so jitter expected be 62.5 to 250 nsec. Also shouldn't be interference with other interrupt subroutine, as it would delay much more, depends on the code inside interfering ISR function. My own experience with video synchro - extraction, shows pretty stable results,  jitter is only 1 or 2 cycles, so answering on next question:
Quote
How consistent woud the delay be between executions?  Are we talking microseconds, nanoseconds? 
Very consistent. Make sure, there is no "racing" interrupts, avoid digitalWrite, digitalRead, analogWrite etc, as they use cli(), sei() unreasonably often (IMHO).
Quote
Also, do the hardware interrupt pins use a timer, and does the timer frequency affect the response time?
No , timer is "independent" hardware.
Logged

Global Moderator
Melbourne, Australia
Offline Offline
Brattain Member
*****
Karma: 511
Posts: 19358
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I've done some timings here:

http://gammon.com.au/interrupts

Scroll down to "How long does it take to execute an ISR?" and also "How long before the processor starts entering an ISR?".
Logged

http://www.gammon.com.au/electronics

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

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

Thanks for your helpful comments, Magician!

Nick, you are a wealth of information, and I appreciate how often you respond thoughtfully to us Newbies, even though I'm middle-aged+!

I'm posting another question about Timers later today and provide my own working code.  It will ask how to set up a timer for a single execution.

Thanks,
Rennie
Logged

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

Hi,
   You could speed up your ISR by using direct port access instead of digitalWrite, see here -

http://www.arduino.cc/playground/Learning/PortManipulation

Duane B

rcarduino.blogspot.com
Logged


Pages: [1]   Go Up
Jump to: