2022-10-13 07:37 PM
htim2.Init.Prescaler = 1000;
htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
htim2.Init.Period = 7200;
htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
However if I change the prescaler to 200, I get the correct delay.
HAL_RCC_GetPCLK1Freq () function returns 36 MHz. Timer 2 clock source, which is APB1 will be 72 MHz. Where am I making a mistake? Thank you for your time.
2022-10-13 08:41 PM
The values are N-1
But that doesn't explain the situation. Perhaps look at the crystal value, and those of the PLL.
Check HSE_VALUE
2022-10-14 04:20 AM
Hi Tesla DeLorean,
Thanks for the reply. The strange thing is even the USB works, which means the 48 MHz derived from the main clock is matching. When I change the 1000 prescaler to 200 I get 0.1 Sec interval. To find this out I have global variable in which I am loading 10 and waiting for it to go to 0. In the timer interrupt, I am decrementing this count if not 0. This is generating almost 1 Sec delay. Is there anything else I can check?
2022-10-14 05:22 AM
Read out and check/post content of RCC registers.
What is the primary clock source? A crystal in HSE? What is its frequency?
JW
2022-10-14 05:29 AM
Is not the problem that your couner count UP? (65536-7200) count to interrupt?
2022-10-14 07:49 AM
Hi ONadr.1,
Yes I also thought of this and tried with down count. Still the timing was same. Come to think of it there must be difference between down and up counting. Will check again. Thanks.
2022-10-14 07:53 AM
Hi JW,
HSE is 8MHz crystal. the problem does not look like that of the main clock as USB, which requires reasonably accurate clock, is working fine in CDC mode. Will read out the RCC registers and post. Thank you.
2022-10-15 02:06 AM
While at it, read out and post also TIM registers content.
JW