cancel
Showing results for 
Search instead for 
Did you mean: 

The best way for capturing low frequency signal

zexx86
Associate II
Posted on March 05, 2015 at 09:38

Hello,

I use STM32F103RBT6 @ 72Mhz to measure input frequency, but I need to measure frequencies between 500 to 3000Hz with PA1 pin - TIM2 CH2. What is the best way to do so?

I use code from STM32 examples - InputCapture that works, but measurable frequency is approx. 1000Hz+ which is not sufficient.

Can you tell me some better possiblities or possible modifications?

Thank you very much!
6 REPLIES 6
Posted on March 05, 2015 at 12:44

> but measurable frequency is approx. 1000Hz+ which is not sufficient.

Do you understand, why?

You can use the prescaler, if you are OK with the decrease in precision.

Or use a newer STM32 model with 32-bit timers.

JW

zexx86
Associate II
Posted on March 05, 2015 at 13:44

I have tried TIM_ICPrescaler - DIV2 and more but it has opposite effect. I need multiplicator, not divider if I am not wrong.

All in all precision is important too for me and also I can't change CPU.

Posted on March 05, 2015 at 14:03

The prescaler on the timer's timebase, not the the input. The input one will increase the period length over which the measurement is made, if you're already rolling the timer, then yes it will be worsened.

Drop the time base to 1us, 10us, 100us, 500us units. For long periods, consider interrupts and reading DWT_CYCCNT as 32-bit at 72 MHz, rollover is nearly a minute.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Posted on March 05, 2015 at 14:17

> For long periods, consider interrupts and reading DWT_CYCCNT as 32-bit at 72 MHz, rollover is nearly a minute.

There are no 32-bit timers on the 'F10x, that's why I recommended a newer STM32 above.

[EDIT] Ah, the debug counter, sorry, I overlooked that. Humm, wonder if DMA could be used to read that?[/EDIT][EDIT2]most likely it couldn't, the debug unit is inside the MCU, out of reach of the bus matrix/DMA[/EDIT2]

I can imagine a scheme with chained timers, but I won't recommend it given the apparent inexperience of OP. There may be bumps ahead.

JW

raptorhal2
Lead
Posted on March 05, 2015 at 15:29

32 bit precision can be obtained with a 16 bit timer by counting timer counter overflow interrupts and using 32 bit variables.

Cheers, Hal

 

zexx86
Associate II
Posted on March 05, 2015 at 16:33

Thank you very much!

Problem is fixed with higher prescaler value.

But I am afraid even with TIM_TimeBaseStructure.TIM_Prescaler = 0; precision is not as expected. I used 2 to solve my problem.

But now I have another problem, because I use TIM2 for more stuff where TimeBase is different. But I think I can solve it too.