2015-03-05 12:38 AM
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!2015-03-05 03:44 AM
> 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. JW2015-03-05 04:44 AM
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.2015-03-05 05:03 AM
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.2015-03-05 05:17 AM
> 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. JW2015-03-05 06:29 AM
32 bit precision can be obtained with a 16 bit timer by counting timer counter overflow interrupts and using 32 bit variables.
Cheers, Hal2015-03-05 07:33 AM
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.