2025-07-24 6:47 AM - last edited on 2025-07-25 2:32 AM by Andrew Neil
Hello,
I have a project to measure the frequency (10Mhz) on an PA5 input and PWM output on PA6, with the counting triggered on PA0 (1PPS), CPU STM32F411, my problem is that the value TIM2 is always wrong, I must have around 10Mhz, I think that the configuration of my Timer 2 is not good but I don't see where the problem is.
File attached.
Best regards.
Sébastien..
2025-07-24 8:40 AM
> my problem is that the value TIM2 is always wrong,
How wrong?
JW
2025-07-24 8:56 AM - edited 2025-07-24 8:56 AM
Use input capture to measure the frequency of an incoming signal of high frequency. No chance of doing it accurately by setting a flag and then reading the timer's counter.
2025-07-25 2:15 AM
2025-07-25 7:34 AM
You're still relying on interrupts on every edge in order to capture. The chip simply can't interrupt at 10 MHz, it doesn't have the computational speed to do that.
Use DMA, put the captured IC value into an array and, after you receive at least 2 samples, post-process that array to find the frequency. Don't use circular DMA since the data will be overwritten before you check it.