InterruptIn Latency 51uS, Is this normal?

06 May 2010 . Edited: 07 May 2010

Can anyone advise on the InterruptIn latency period, it appears to be 51uS but this just seems far too long, especially when compared to that of PIC microcontrollers (10's of cycles).

The test code below invokes an interrupt on the low going edge of a switch input. I measure the period with a scope from when the switch goes low to the point where the interupt code executes by controlling an i/o pin.

Part of my application reads an encoder (1000ppr) but with an interrupt latency of 51uS this is not possible, I hope I have made a fundamental error so I would appreciate any advice.

 

#include "mbed.h"

DigitalOut led(LED1);               // mbed led
DigitalOut isr(p21);                // isr test o/p: 1=start of encoder ISR, 0= end of encoder ISR: Connect to scope B channel 
InterruptIn pushSwitch(p18);            // switch input (to gnd): Also connect to scope A channel (falling edge trigger source) 
          
void switch_low() {                 // ISR: encoder signals 'A' rising edge detect.
isr = 1;                            // start of ISR 
wait(0.000004f);                    // high pulse to isr output
isr = 0;                            // end of ISR 
}

int main(){

isr=0;                              // ensure isr o/p low
pushSwitch.fall(&switch_low);           // attach the address of the switch_low function to the falling edge isr
pushSwitch.mode(PullUp);                // create weak pullup on switch i/p

while(1){
led = !led;                         // flash led in main 
wait(0.5);
}

}