-1
\$\begingroup\$

I am writing code for an STM32L433RC MCU that returns the tick period of a timer (TIM1, TIM2, TIM6, etc.) using the LL driver but I can't figure out how to calculate the timer clock frequency programmatically. The documentation clearly shows that the timers are clocked by a multiple of PCLK1 or PCLK2 depending on which timer is being used. The part I can't work out is how do I know what the multiplier is? If I know the multiplier then I can calculate the timer clock frequency easily. I read a blog saying it is automatically set in hardware when the APB1/2 pre-scalers are set, however it did not go into further details. I cant find anything in any of the datasheets or manuals I have read except for the diagram that shows the multiplier as either x1 or x2 (see the image I have attached). Does anybody have any insight into this?

enter image description here

\$\endgroup\$
2
  • \$\begingroup\$ Look at the documentation for the part, the reference manual (not programmers manual, the reference manual). As well as the source for whatever library you are using if you are using a library. \$\endgroup\$ – old_timer Apr 15 at 5:27
  • \$\begingroup\$ I should have mentioned that I was using the reference manual. I did end up finding the information in section 6.2.14 of the reference manual (RM0394). I should have read it in more detail before asking this question. I assumed that since the registers descriptions made no mention of it that it must not be in there. Thanks. \$\endgroup\$ – bm9703123 Apr 16 at 1:32
3
\$\begingroup\$

It automatically changes when you change the APBx prescaler. If the respective APB prescaler is >1 (2, 4, 8 or 16) then it is x2 otherwise it is x1.

You can see this from the CubeMX configuration tool. I'm sure it's somewhere in the documentation. Since the maximum frequency of the APBx is 80MHz this enforces a maximum frequency of 80MHz for the timer clocks.

Screen cap:

enter image description here

\$\endgroup\$
2
  • 1
    \$\begingroup\$ If it's there I certainly can't find it, at least not knowing what the reason was. \$\endgroup\$ – DKNguyen Apr 14 at 2:53
  • 1
    \$\begingroup\$ @DKNguyen I have faith, but not enough to spend much time looking. \$\endgroup\$ – Spehro Pefhany Apr 14 at 2:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.