attach/detachInterrupt performance

I've searched around but haven't found a decent answer to this topic - What are the performance issues, if any, associated with the attach/detachInterrupt functions?

I'm working on a motor controller interface that also provides wheel quadrature information, which are working very well independently! The concern is that I know I am unable to count on getting back correct serial communication data (which is important) when I'm within the function that gets called with the attachInterrupt registration. If I call attach/detachInterrupt functions within the loop several times a second, which with my design does solve my problem, could this significantly slow me down, or is this not that significant?

I have a good background in software, but I've never looked into how the interrupt registration routines work. Any help is greatly appreciated!

I would say that is not important.

I use 2 external interrupts to read 2 servo signals which are updated every 20ms (about 50 times/second), and I checked my Serial monitor with an n++ counter in the loop as well as a Serial print of the millis() value at the end of each loop and it was catching all 50 updates per second on both channels. So you should be fine with only a few per second.

I also use the attach/detachinterrupt commands quite liberally in my code and it works very well… FWIW, I have used the Arduino Mega to decode 6 servo channels at once with the 6 external interrupts and it still has time to write the commands to the motor-controller each cycle.

Here is a piece of my code:

int servo1 = 2; 
unsigned long servo1_startPulse;
volatile unsigned servo1_val; 
int servo1_Ready;

void setup() {

pinMode(servo1, INPUT);
attachInterrupt(0, rc1_begin, RISING);    // catch interrupt 0 (digital pin 2) going HIGH and send to rc1()


void rc1_begin() {           // enter rc1_begin when interrupt pin goes HIGH.

  servo1_startPulse = micros();     // record microseconds() value as servo1_startPulse
  detachInterrupt(0);  // after recording the value, detach the interrupt from rc1_begin
  attachInterrupt(0, rc1_end, FALLING); // re-attach the interrupt as rc1_end, so we can record the value when it goes low

void rc1_end() {
 servo1_val = micros() - servo1_startPulse;  // when interrupt pin goes LOW, record the total pulse length by subtracting previous start value from current micros() vlaue.
 detachInterrupt(0);  // detach and get ready to go HIGH again
 attachInterrupt(0, rc1_begin, RISING); 
 if (servo1_val < 150 || servo1_val > 600) {  // only set the servo1_Ready flag if the value is a valid Servo pulse between 600-2400 microseconds.
  servo1_Ready = false; 
 else {
  servo1_Ready = true; // if not, don't pass the value to be processed

void loop() {

    Serial.print("ch1:  ");
    Serial.print("  ");


Thanks for the reply! I'm glad knowing your code works at those kind of speeds, which is roughly a bit faster than my own wheel encoder needs to be updated.. I double checked the hardware specifications and it seems to work fine. I ran through some of my own tests and again it just confirms that the overhead seems pretty small.. Which is great!