cancel
Showing results for 
Search instead for 
Did you mean: 

How to start and stop timer/counter using separate external pins (i.e. stopwatch)?

norlesh
Associate II

I need to accurately time the delay between two rising edges being triggered (charging time of a capacitor). The device I'm testing this out on is on a Nucleo-H743ZI but eventually want it to run on a Nucleo-F446RE so am not looking to use the HRTIM (which looks horrifically complex anyhow).

Is it possible to configure device so that a timer starts counting on the rising edge of an output pin, and stops counting on the rising edge of a separate input pin? Failing that how can I capture when the two edges occur? I'm using STM32CubeIDE which only generates HAL code (no LL option) for the H743 so I don't believe I can rely on any interrupt handlers having a consistent response time so would like to achieve this all through hardware configuration.

1 REPLY 1

You can't start and stop timer using 2 different pins, but the normal way to do these things is to connect the two signals to two pins corresponding to two channels of one timer, let that timer run freely, and use those two channels to capture the timer value at the respective edges. Then, in interrupt from these channels, one simply subtracts one captured value from the other to find out the time between the two edges.

Start with reading the Input capture mode subchapter of timer chapter in the reference manual.

JW