cancel
Showing results for 
Search instead for 
Did you mean: 

General questions on timers.

xpp07
Senior

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?

12 REPLIES 12
Khouloud GARSI
Lead II

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.

@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
Lead II

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.