STM32 Timer is a powerful module, the timer is also very high frequency, timer can do some basic timing, also can do PWM output or input capture function.
Clock source problem:
There are eight named Timx , of which TIM1 and TIM8 hang on the APB2 bus, while tim2-tim7 hangs on
APB1 on the bus. Where TIM1&TIM8 is called Advanced control Timer. Their APB2 bus is also better than the APB1 bus. APB2 can work at 72MHz , while APB1 is 36MHzmaximum.
The timer's clock does not come directly from the APB1 or APB2, but from a multiplier that is input to APB1 or APB2 .
below with timer 2~7 The clock illustrates the effect of this multiplier: when apb1 has a prescaler factor of 1 , this multiplier does not work, the clock frequency of the timer equals apb1 frequency; apb1 the prescaler coefficient is other values ( that is, the prescaler coefficient is Span lang= "en-us" xml:lang= "en-US" >2 , 4 , 8 or 16) , this multiplier functions, the clock frequency of the timer equals apb1 twice times the frequency.
assuming ahb=36mhz because the Span lang= "en-us" xml:lang= "en-US" >apb1 the maximum allowable frequency is 36mhz , so apb1 the prescaler coefficient can take any value, when the prescaler coefficient =1 , the Span lang= "en-us" xml:lang= "en-US" >apb1=36mhz , tim2~7 clock frequency =36mhz ( multiplier does not work ; when the prescaler factor =2 , apb1=18mhz , under the action of the multiplier, tim2~7 =36mhz .
some would ask, since tim2~7 Clock frequency =36mhz , why not directly take apb1 The Prescaler factor =1 ? The answer is: apb1 to provide clocks not only for tim2~7 , The clock is also provided for other peripherals, and the multiplier allows the tim2~7 to still get a higher clock frequency when other peripherals are guaranteed to use a lower clock frequency.
Another example: When Ahb=72mhz , theAPB1 prescaler coefficient must be greater than 2, because the maximum frequency of APB1 can only be 36MHz. If the APB1 prescaler coefficient is =2, thetim2~7 can still get a 72MHz clock frequency because of the multiplier. The ability to use a higher clock frequency has undoubtedly increased the resolution of the timer, which is why the multiplier was designed.
(a) General timer of the relevant introduction