2016-06-23 12:54 PM
I want to measure how long a signal is high as accurately as possible (preferably down to the microsecond). I started by triggering an EXTI interrupt one both the rising and falling edge of the signal. The EXTI handler would check if the signal is high or low. If high, it would start a timer, and if low it would end it and return how long the timer was active. I tried to implement this with SysTick but I fear it is not accurate enough. I thought about using a TIM but I don't know how to return how long the timer was running... Any advice?
2016-06-23 01:16 PM
For a continuous signal, I'd use PWM Input mode, otherwise Input Capture where Channel 1 and 2 were configured to timestamp opposite edges of the same signal.
On an F4, I'd use a 32-bit timer clocking between 84 MHz and 1 MHz, and compute the delta ticks between rising and falling edges..