2024-10-28 11:36 AM
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.
2024-10-28 11:48 AM
Start and stop a second timer with each pulse and then read the second timer accumulated count register when done ?
2024-10-28 12:20 PM
Connect the external signal to TIMx_ETR and select it as TRGI source TIMx_SMCR.TS=0b111 (you can try also TIMx_CH1 or TIMx_CH2 and .TS=0b101/0b110 respectively); then set TIMx_SMCR.SMS=0b101 for Gated mode.
Clock the timer from internal clock as usually.
JW