There are as many as 8 timers in STM32, among which TIM1 and TIM8 are advanced timers that can generate three pairs of PWM complementary outputs. They are often used to drive three-phase motors. Their clocks are generated by the output of APB2. The other 6 are ordinary timers, and the clock is generated by the output of APB1.
The following figure is a screenshot of the timer clock part in the clock distribution diagram on the STM32 reference manual:
It can be seen from the figure that the timer clock is not directly from APB1 or APB2, but from a frequency multiplier whose input is APB1 or APB2, the blue part of the figure.
The function of this frequency multiplier is explained below with the clock of timer 2~7: When the prescaler coefficient of APB1 is 1, this frequency multiplier does not work, the clock frequency of the timer is equal to the frequency of APB1; when the prescaler of APB1 When the frequency division coefficient is other values ​​(ie, the prescaler coefficient is 2, 4, 8 or 16), this frequency multiplier works, and the clock frequency of the timer is equal to twice the frequency of APB1.
Assuming AHB=36MHz, because the maximum frequency allowed by APB1 is 36MHz, the prescaler coefficient of APB1 can take any value; when the prescaler coefficient=1, APB1=36MHz, and the clock frequency of TIM2~7=36MHz (multiplication When the prescaler coefficient=2, APB1=18MHz, under the action of the frequency multiplier, the clock frequency of TIM2~7=36MHz.
Some people may ask, since the clock frequency of TIM2~7=36MHz is needed, why not directly take the prescaler coefficient of APB1=1? The answer is: APB1 not only provides clocks for TIM2~7, but also provides clocks for other peripherals; setting this multiplier can ensure that other peripherals use lower clock frequencies, while TIM2~7 can still get higher Clock frequency.
To give another example: when AHB=72MHz, the prescaler coefficient of APB1 must be greater than 2, because the maximum frequency of APB1 can only be 36MHz. If the prescaler coefficient of APB1=2, TIM2~7 can still get a clock frequency of 72MHz because of this frequency multiplier. The ability to use a higher clock frequency will undoubtedly improve the resolution of the timer, which is exactly the original intention of designing this frequency multiplier.
Agriculture Staple,604 Fixing Nail,Hardware Staples Nail,Custom Agricultural Use Nail
Zhejiang Best Nail Industrial Co., Ltd. , https://www.beststaple.com