Arduino Micro 16 MHz incorrect micros()?

Hello. I’m trying to capture signal from a IR remote control through TSOP-1736 IR sensor and Arduino Micro 16 MHz. Here is the code:

const int ARDUINO_MICRO_INTTERRUPT_ON_PIN3 = 0;
const int BUFFER_LEN = 40;

unsigned long periods[BUFFER_LEN];
int i = 0;
unsigned long lastMicros = 0;
unsigned long mcs;
volatile boolean isRunning = false;

void sensorInterruptHandler() {
  isRunning = true;
}

void setup() {
 attachInterrupt(ARDUINO_MICRO_INTTERRUPT_ON_PIN3, sensorInterruptHandler, CHANGE);  
 Serial.begin(9600);
}

void loop() {
  if(!isRunning) {
     return; 
  }
  if(i == BUFFER_LEN) {
    detachInterrupt(ARDUINO_MICRO_INTTERRUPT_ON_PIN3);
    for(int x = 1; x < BUFFER_LEN; ++x) {
       Serial.print(periods[x]);
       Serial.print(" ");
    }
    Serial.println();
    Serial.flush();
    lastMicros = 0;
    delay(1500);
    i = 0;
    attachInterrupt(ARDUINO_MICRO_INTTERRUPT_ON_PIN3, sensorInterruptHandler, CHANGE);
  } else {
    mcs = micros();
    if(lastMicros > mcs) {
       Serial.print("Overflow!"); 
    }
    periods[i] = mcs - lastMicros;
    lastMicros = mcs;
    ++i;
  }
  isRunning = false;
}

But my readings are not correct (problem places marked with “*”):

2680 900 496 808 520 376 512 368 468 856 908 428 460 424 468 424 464 416 464 424 464 420 468 420 468 420 460 424 464 424 464 420 468 420 908 416 460 904 876
2684 896 484 820 520 368 520 368 1344 1312 520 368 528 360 456 428 464 420 468 420 468 420 468 416 464 424 468 420 464 420 468 420 908 416 464 872 904 83656 2684
2680 900 492 816 524 360 520 368 464 860 908 428 460 428 460 424 464 424 468 416 472 416 460 424 464 424 464 424 468 416 460 428 460 424 904 424 468 864 912
2680 904 492 812 516 372 516 368 1356 1304 516 372 516 368 468 428 460 420 460 424 464 420 468 420 468 420 460 432 456 424 464 424 912 412 468 864 904 83656 2684
2676 904 488 816 524 364 524 364 1348 1308 524 364 524 364 460 424 464 424 468 420 468 416 460 424 464 424 468 420 468 416 460 428 912 412 468 896 880 83652 2680
2676 904 496 812 520 364 524 364 460 864 912 424 468 416 472 416 460 424 464 424 468 420 468 416 460 428 460 428 464 420 468 416 472 424 904 416 464 896 880

It’s definitely not an overflow since “Overflow!” has never been printed. These problem periods are in some kind of range between few microseconds and always in the same position - 9 and 10. The remote control I use always sends me the same signal shown below, so the problem not in the remote control itself. Even when I strip down the code to write time periods in UART, sometimes I see a huge gap between periods. That makes me think there is something wrong with micros() or how I’m using it.
Could you tell me what am I doing wrong and where these strange delays came from?
What I tried so far:

  • moving the writing part to the interrupt itself;
  • playing with enabling/disabling interrupts;
  • put all code inside while(true){};
  • enabling and disabling uart;
  • writing in a huge array and only then print it;
  • update IDE.
    Nothing works.

What sort of data are you trying to receive?

IR data is often just Serial data. Have a look at this IR Thread.

...R

What happens when a pin interrupt fires while executing micros?

Nice catch, but I've tried this, too.

byte oldSREG = SREG;
noInterrupts();
mcs = micros();
periods[i] = mcs - lastMicros;
lastMicros = mcs;
++i;
SREG = oldSREG;

Result: still same strange values.

What result do you get with higher baud rate?

It’s a shame. I carefully studied IR-signal through Audacity one more time and guess what? IR control sometimes DOES produce these strange delays. I should have done this at the first place instead of messing with the code.
Results: Arduino is OK, micros() is OK, delays are OK.
That is, this thread is no longer useful and does not require responses. Thanks for your time.