Configuring a Timer to measure high time on a GPIO
I'd like to be able to configure a channel for TIM2 (or any 32 bit timer) on an MCU. (STM32G474 in this example) to accumulate the total HIGH time over continuous wave forms. I know I can accomplish this using IC mode and do the math in an ISR by detecting each edge, but I was wondering if there was a way to do it completely in HW.
For example I'd like to monitor the total open time in (µS) of a solenoid valve controlled by another device. So, I would like to set up TIM2 to run at 1MHz and then accumulate all the cycles that it's channel 1 is high.
I know there are ways to kind of do this for a single waveform, but I'm looking to capture the accumulated high times over 1000's of wave forms. I would then like to be able to read & reset that timer's register every so many seconds.
