cancel
Showing results for 
Search instead for 
Did you mean: 

Measuring frequency - TIM2 value wrong

PSEBA.1
Associate II

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..

4 REPLIES 4
waclawek.jan
Super User

> my problem is that the value TIM2 is always wrong,

How wrong?

JW

TDK
Super User

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.

If you feel a post has answered your question, please click "Accept as Solution".

Hello,

Thanks for the reply. I'm new to STM32 and learning capture mode.

Is it possible to check my code using capture mode because it still isn't working?

Pwm no variation.

new File attached.

Best regards.

Sébastien.

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.

If you feel a post has answered your question, please click "Accept as Solution".