HIGH RESOLUTION Interrupt PWM timer

16 Aug 2010 . Edited: 16 Aug 2010

Is there any way to use interrupts to time a pwm to an accuracy of +- 1 us? It seems the read_us() doesn't seem to give high enough resolution.

16 Aug 2010

I've written a routine with a timer_us, and it's very precise.

16 Aug 2010

Do you have the code? When I did a simple interrupt with read_us() I was getting +-4us.

17 Aug 2010

void rising() {                                 // Rising edge on the serial comm
    timer.start();                              // Start the timer
    return;
}
void falling() {
    timer.stop();                               // Stop timer
    buffer[i]=timer.read_us();                  // Read timer to buffer[i] i=turns
    timer.reset();                              // Reset timer
    i++;                                        // increment i.
    return;
}
This worked beautifully.

You can leave out the buffer part of course.