2018-06-05 01:30 PM
Hello guys.
When I used LPC17xx series in my last experience of ARM MCUs I used 2 timers one for generating interrupt every 1 second and one for counting the rising edges of the input CAP.
So I started reading the Reference menu of the stm32F2xx ,but there were a lot of timer functions described in timer section.I was confused which one to use for my purpose.
Now I know that how to set the timer to work as a TIME BASE,but for input I didn't know which one to use.One section described external clock mode 1 and the other external clock mode 2 and the other was input capture mode .
Which one should I use?
#stm32f2 #cube-hal2018-06-05 01:50 PM
There are several ways to measure frequency, and it's on case by case...
One simple way is free running timer and measure time between two successive input capture. Optionally an edge prescaler can be used prior to the capture for higher frequency signals.
Another way is to count input signal edges by using it as timer clock during one second.
2018-06-05 01:55 PM
For higher frequencies use the External Count mode, basically take TIM2_CH1 as the TIM_CLK
2018-06-05 10:04 PM
Hello,
Please have a look at PWM Input mode of timers. It allows you to measure length of 'H' and 'L' time of the input signal and storing them in the separate registers.
You can refer to existing application note
or some examples which you can find in#stm32f2
#cube%20hal
library folder, i.e..\STM32Cube_FW_F2_V1.7.0\Projects\STM32F207ZG-Nucleo\Examples\TIM\TIM_PWMInput\
if you prefer to operate on lower abstraction layer libraries, you can have a look at this:
.\STM32Cube_FW_F2_V1.7.0\Projects\STM32F207ZG-Nucleo\Examples_MIX\TIM\TIM_PWMInput\
Mentioned library you can find
.Best Regards,
Artur
2018-06-07 10:06 AM
I found a way to measure the frequency. But there are some parts that I can't figure out the difference between.
First is that I found that when using capture input mode after a capture occurs the CCR register is loaded with the content f the CNT.So what are external clock mode 1 (with TI input) and external clock mode 2 (with ETR input)?
2018-06-07 12:13 PM
The external clock makes CNT increment/decrement rather than the APBx clock source.
As I recall the clock routing allows for CH1 (TI1FP1),CH2 (TI2FP2) or ETR as a source
2018-06-07 04:06 PM
Clive One wrote:
The external clock makes CNT increment/decrement rather than the APBx clock source.
You mean it counts the input signals' edge defined by the software?
If it is a clock that used rather than APBx clock source, why it must be synchronized first?
As I recall the clock routing allows for CH1 (TI1FP1),CH2 (TI2FP2) or ETR as a source
And when we use ETR and when TI?
2018-06-07 04:07 PM
Forgot to ask that when using external clock modes what is the usage of TIMx->CCRx?
2018-06-07 04:30 PM
You still have to access the TIM peripheral registers in the APB clock domain, so the clock edge that increments the counter is coherent with the APB clock, and you don't get phase issues, and setup/hold violations.
The CCRx function as they did before, but now you're time stamping using a counter from a different clock
ie CCRx := CNT at your Input Capture Events
Or acts as a phase comparator in the Output modes
If you pushed a GPS 1PPS signal in as the external clock the TIMx->CNT would increment every second. Equally you could clock it with a 30.72 MHz or 19.2 MHz source if that's what you want to do.
If you drove a 1PPS into CH2, and 19.2 MHz into CH1, clocked the counter with CH1, and Input Captured on CH2, you'd observe CCR2 increase by 19,200,000 at each event.
2018-06-07 04:50 PM
Thank you.
Another question that I have is that when I use input capture to measure the frequency on every capture event the CCR register is loaded with CNT, but the CNT goes on without any reset. If I want to reset it after each capture what should I do? I tried some cube mx to do this but it didn't work.