cancel
Showing results for 
Search instead for 
Did you mean: 

Hi all, I am back with another problem!! I am using timer 2 in 103C8 controller for 0.1 Sec time delay. However, it is generating 5 times the calculated delay. My initialization code for this delay is given below. Timer interrupt is enabled.

Parmin Nayani
Associate III

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.

7 REPLIES 7

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

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Parmin Nayani
Associate III

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?

Read out and check/post content of RCC registers.

What is the primary clock source? A crystal in HSE? What is its frequency?

JW

ONadr.1
Senior III

Is not the problem that your couner count UP? (65536-7200) count to interrupt?

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.

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.

While at it, read out and post also TIM registers content.

JW