Skip to main content
Visitor II
February 13, 2024
Solved

APB1 TIM2 clock frequency

  • February 13, 2024
  • 2 replies
  • 3073 views

I want to use tim 2 at the frequency of APB1 and not to the sysclock how i can do that, can somoene explain me or look at my code at the bottom to help me i want to use the 0.09375 frequency for my projet. thanks 

Capture d’écran 2024-02-13 102336.png

    This topic has been closed for replies.
    Best answer by GwenoleB

    Hello @Skyy_Tsuki ,

    The following statement is mentioned in RM0008, section RCC:

    The timer clock frequencies are automatically fixed by hardware. There are two cases:
    1. if the APB prescaler is 1, the timer clock frequencies are set to the same frequency as
    that of the APB domain to which the timers are connected.
    2. otherwise, they are set to twice (×2) the frequency of the APB domain to which the
    timers are connected.

    Currently, your APB prescaler is set to 2, therefore the second point is applied. 

    I could recommend you to divide by 2 the input clock frequency of timer by setting Internal Clock Division (CKD) parameter in CubeMX.

     

    Kind Regards,

    Gwénolé

    2 replies

    GwenoleBAnswer
    ST Employee
    February 13, 2024

    Hello @Skyy_Tsuki ,

    The following statement is mentioned in RM0008, section RCC:

    The timer clock frequencies are automatically fixed by hardware. There are two cases:
    1. if the APB prescaler is 1, the timer clock frequencies are set to the same frequency as
    that of the APB domain to which the timers are connected.
    2. otherwise, they are set to twice (×2) the frequency of the APB domain to which the
    timers are connected.

    Currently, your APB prescaler is set to 2, therefore the second point is applied. 

    I could recommend you to divide by 2 the input clock frequency of timer by setting Internal Clock Division (CKD) parameter in CubeMX.

     

    Kind Regards,

    Gwénolé

    Visitor II
    February 13, 2024

    Where i can divide on cube mx i don't see CKD in cubeMX and i have a question i have a period of 400ms for one period and the timer go crazy everytime i have one interrupt on my pin the timer show me 7048 or 128 or 3128 etc... i don't have never ever a constant value for my timer and my input signal is very slow i have the possibility to count the numbre of pulse during my two interrupts can you help me please.

    Super User
    February 13, 2024

    If you want the timer to run slower, just use its own prescaler TIMx_PSC.

    JW