2023-09-14 03:00 PM
I am playing with the TIM_InputCapture example (calculates frequency of external pulse) for the NUCLEO-H563ZI dev board. The example works OK except:
There should be a way to trigger the latching of the count reg in SW rather than the timer. The pulse frequency is low enough that I can look at the pulse count in non-ISR code.
How do I (a) trigger the latching of the count reg, and (b) disable the timer event?
Solved! Go to Solution.
2023-09-14 03:50 PM
> There should be a way to trigger the latching of the count reg in SW rather than the timer.
Why? Just read out TIMx_CNT.
JW
2023-09-14 03:50 PM
> There should be a way to trigger the latching of the count reg in SW rather than the timer.
Why? Just read out TIMx_CNT.
JW
2023-09-14 04:26 PM
The CNT reg would continue to increment while I read the time. I would like to (a) disable interrupts, (b) latch the CNT reg, (c) read the time, (d) re-enable interrupts, (e) read the latched count.
Also, my attempts at reading the CNT reg yield unexpected results. The differences in the count compared to the input frequency and the time interval -- don't correlate at all.
2023-09-14 04:30 PM
The input capture function does this. It stores the value of CNT at the time of the trigger. You can't get more accurate than that. Your method would be subject to IRQ and software delays.
2023-09-14 11:59 PM - edited 2023-09-15 12:00 AM
Any software method is subject to IRQ and software delays, regardless of whether you disable/enable interrupts around it.
Reading out TIMx_CNT is a simple and short operation, you can't force capture in software any more effectively.
While you did not tell us any relevant details - which STM32, which timer, what clocks - your problems probably stem from timer having a limited overall period, probably you are using a 16-bit timer. Calculate how fast will it oferflow; try 32-bit timer, try using appropriate prescalers. Alternatively, you could count timer overflows in interrupt and factor them into your frequency calculation, but this is tricky and I recommend to avoid it.
You should also have some sort of timeout. That establishes a minimum input signal frequency. There is no such thing as measuring 0Hz input; to measure it precisely you would have to wait infinite time.
JW