PulseIn don't work well

noted. thanks for the tips!

my thought would be run loop for a while and gather "gap"s in a buffer. when the buffer is full, report the values and quit. that way you wouldn't risk missing as much stuff while you are printing "gap" and disabling interrupts.

I guess in the code I posted, you would do

cli();//disable interrupts
uint32_t printgap = gap;
sei();//enable interrupts
Serial.print(printgap);