Suspected Bug - Micros or Interrupts

Thanks for the detailed test case, it really helps a lot - I meant to look at this particular bug a couple of months ago when others noticed it but didn't because there wasn't full code to reproduce the bug. Nevertheless it's still taken hours of hard work and I haven't completely fixed it, although I think I've improved things.

Basically there is a very complicated race condition going on. There are SysTick interrups every millisecond which micros() uses to calculate the thousands of microseconds in the result, and also your pin change interrupt. Bad things can happen if the SysTick interrupt triggers while you are in the middle of the pin change - it has to wait for your interrupt to finish before it can update the millis counter which messes up the timing.

Please try the following: In hardware/arduino/sam/cores/arduino/wiring.c change the function micros() to this:

uint32_t micros( void )
{
volatile    uint32_t ticks, ticks2;
volatile        uint32_t pend, pend2;
volatile     uint32_t count, count2;

        ticks2  = SysTick->VAL & 0xffffff;
        pend2   = ((SCB->ICSR & SCB_ICSR_PENDSTSET_Msk)||((SCB->SHCSR & SCB_SHCSR_SYSTICKACT_Msk)))  ? 1 : 0;
        count2  = GetTickCount();

do {
        ticks=ticks2;
        pend=pend2;
        count=count2;
        ticks2  = SysTick->VAL & 0xffffff;
        pend2   = ((SCB->ICSR & SCB_ICSR_PENDSTSET_Msk)||((SCB->SHCSR & SCB_SHCSR_SYSTICKACT_Msk)))  ? 1 : 0;
        count2  = GetTickCount();
} while ((pend != pend2) || (count != count2) || (ticks < ticks2));

    volatile uint32_t r=((count+pend) * 1000) + ((84000  - ticks) / 84) ;

        return r;
}

It is complicated to describe but what it does is repeatedly read the timer values and detects pending timer ticks until it thinks it has sensible readings, then it calculates micros from those. I tried it on your code for 5 minutes and it was OK and I've tested it for monotonicity for 5 minutes too, but there's so much code out there that uses micros() I can't guarantee it works on everything.