cancel
Showing results for 
Search instead for 
Did you mean: 

TIMER Update Event Not Affected from Changing CLOCK DIVISION Value

Mesut TOPUZLU
Associate II
Posted on June 29, 2017 at 00:14

Hi. I use Keil Compiler and HAL lib. I configure TIM4 as normal timer (time base counter) and implement Update event with HAL_TIM_PeriodElapsedCallback function. My initialization code below;

__HAL_RCC_TIM4_CLK_ENABLE(); 

TIM4_Handler.Instance=TIM4;

TIM4_Handler.Init.Prescaler=16000; // 16 MHZ/16000 = 1000 Hz -> 1 ms inc/dec period

TIM4_Handler.Init.CounterMode=TIM_COUNTERMODE_UP;

TIM4_Handler.Init.Period=1000; // 1msec x 1000 = 1 sec overflow inerrupt

TIM4_Handler.Init.ClockDivision=TIM_CLOCKDIVISION_DIV1; 

TIM4_Handler.Init.RepetitionCounter=0; 

HAL_TIM_Base_Init(&TIM4_Handler);

When I run code like above, UEV interrupt occure in 1 sec. This is normal

But when I change clock division  suc as TIM_CLOCKDIVISION_DIV4, this period is not affected. There is an UEV interrupt in 1 sec.

What is the problem?  (Note that my APB1/2 clock is 16MHZ)

7 REPLIES 7
Zt Liu
Senior III
Posted on June 29, 2017 at 11:49

hi,

It works as expected!

''Clock division'' has nothing to do the clock prescaler.(okay, terminology is quite confusing!)

The CKD(clock division) bits and PSC bits(prescaler bits) have different meanings,

The former is about dead time and filter settings, it has nothing to do with prescaling as the name suggests. 

Check the datasheet!

0690X00000607YEQAY.png

Zt

Zt Liu
Senior III
Posted on June 29, 2017 at 12:13

by the way,

your prescaler should be 16000-1

Posted on June 29, 2017 at 18:57

thank you Mr. LIU

Posted on March 04, 2018 at 15:02

Thanks! I was also confused!

But the prescaler value of 16000 is right, it is the clock divider, so 16000000/16000 = 1 KHz freq = 1 ms.

The Period should be XX - 1, like 1000 - 1 = 999 for 1 sec.

Cheers

Posted on March 04, 2018 at 18:23

Both Prescaler and Period values are expressed as N-1

Update Rate = TIMCLK / (P * Q)

Where

TIM4_Handler.Init.Prescaler = Q - 1;

TIM4_Handler.Init.Period = P - 1;

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on March 04, 2018 at 17:33

But the prescaler value of 16000 is right, it is the clock divider, so 16000000/16000 = 1 KHz freq = 1 ms.

No.

0690X00000609v0QAA.png

JW

Posted on March 04, 2018 at 18:51

Good, now it is clear, thanks for the update!