Maybe the timer in capture mode is what you need here (still don't know the exact output of the sensor). In capture mode you can trigger an interrupt on a falling edge, take the timer value and store it, change the edge to a rising detection and then when the interrupt happens, store the new timer value and compare both to calculate the elapsed time. If your sensor works with a duty cycle output, I would try this way.
↧