Skip to main content
Mesut TOPUZLU
Associate
June 28, 2017
Question

TIMER Update Event Not Affected from Changing CLOCK DIVISION Value

  • June 28, 2017
  • 7 replies
  • 1438 views
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)

    This topic has been closed for replies.

    7 replies

    Zt Liu
    Senior III
    June 29, 2017
    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
    June 29, 2017
    Posted on June 29, 2017 at 12:13

    by the way,

    your prescaler should be 16000-1

    Mesut TOPUZLU
    Associate
    June 29, 2017
    Posted on June 29, 2017 at 18:57

    thank you Mr. LIU

    Tesla DeLorean
    Guru
    March 4, 2018
    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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Daniel Koster
    Visitor II
    March 4, 2018
    Posted on March 04, 2018 at 18:51

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