2022-09-26 04:35 AM
Hello guys,
I have just started working with stm32 controllers. I am trying to capture the frequency of signal using timer 2 input capture mode.
I am getting absolutely correct frequency if i use ARR = 65535 but when i use ARR = 0xffffffff (As timer 2 is 32bit) i am getting wrong result.
I am using this reference equation
Frequency = TIM_CLOCK / ((C2-C1)*(prescaler+1))
Where C2 = capture value 2 // Both Rising edge
C1 = capture value 1
TIM_CLOCK = 1Mhz
TIMER_PSC = 16-1
SYSTEM_CLOCK = 16Mhz
Please help if i am missing something.
Solved! Go to Solution.
2022-09-29 02:45 AM
After you've set PSC and ARR, e.g. somewhere between steps 5 and 8, do
TIM2->EGR = TIM_EGR_UG;
JW
2022-09-29 03:18 AM
Yes i did but still not working.
2022-09-29 03:20 AM
I think update event generation is only required if i change ARR/PSC after the timer has started.Here in my code i am setting both before i start timer.
2022-09-29 03:57 AM
> I think update event generation is only required if i change ARR/PSC after the timer has started
No.
JW
2022-09-29 04:19 AM
Okay. I have tried it still not working.
2022-09-29 05:18 AM
Post code you have tried (exactly that code, copy/paste) and numbers.
JW
2022-09-29 06:12 AM
It is working. Bymistake i wrote TIM1->EGR instead of TIM2->EGR.
Thank you very much for your time and efforts.