Skip to main content
xpp07
Associate III
September 23, 2018
Solved

General questions on timers.

  • September 23, 2018
  • 12 replies
  • 4266 views

Hello,

I'm still learning how to handle timers in CubeMx. I've got some simple questions.

I'm using TIM1 and TIM2 of the L432KC. In the clock tree, I see APB1/APB2 peripheral and timer clocks bus frequencies. I thought that when I set a prescaler, the APBx timer clock frequency is the one divided by the prescaler, but actually is the APBx peripheral clock frequency. What's the real difference?

Second question:

I've set timer 2 in PWM input to measure the period of an input signal. So,

.....

period = HAL_TIM_ReadCapturedValue(&htim1, TIM_CHANNEL_2);

....

Does this say the period in milliseconds, right?

Third question:

I read in an app note:

The TIMxCLK frequency is set to 72 MHz, the prescaler is 0x0 so the TIM2 counter clock frequency is 72 MHz. So the minimum frequency value to measure is 1100 Hz.

How do I calculate that minimun frequency?

Last question:

When setting the PWM input mode or input capture mode to measure an external signal, how do I choose the prescaler and counter period effectively in CubeMx according to my frequencies range?

    This topic has been closed for replies.
    Best answer by Khouloud GARSI

    Hi @XP.1acheco​ ,

    • Correct, if you want to have a 10kHz PWM frequency, prescaler should be one using your configuration.
    • Right, regarding the timer clocks, "APBx timer clock" is only dedicated for the timer peripherals.

    Khouloud.

    12 replies

    Dave Nadler
    Senior III
    October 22, 2018

    @Khouloud GARSI​, perhaps you could clarify:

    Which (APB1 timer clock or APB2 timer clock) is input to a specific timer?

    Where is this documented?

    Thanks!

    PS: I know it does not matter in the above example, but it does matter for my clock tree...

    Khouloud GARSI
    ST Employee
    October 23, 2018

    Hi @Dave Nadler​ ,

    In order to have this information, you may have a look on "RCC_APB1ENR" and "RCC_APB2ENR" registers in the reference manual.

    You're always welcome!

    PS: Please next time create a new thread :smiling_face_with_smiling_eyes:

    Khouloud.