Timer basics
The STM32F4 timers are very powerful, with advanced timers such as TIME1 and TIME8, general timers such as TIME2-TIM5, TIM9~TIM14, and basic timers such as TIME6 and TIME7, making a total of 14 timers. However, we mainly focus on general-purpose timers in our daily life.
I. Timer Related Registers
-
Counter Current Value Register CNT:
This carries out the counting up and counting down of data, and stores the current count value of the timer. -
Prescaler register TIMx_PSC.
The timer clock source is divided and output to reduce the frequency of the timer clock (CK_CNT) to obtain the desired timer clock frequency. -
Auto Reload Register TIMx_ARR.
Stores the value required for reloading. Assuming downward counting, when the value in CNT reaches 0, the timer reads the value in ARR and assigns it to CNT to re-count. And when counting up, when the value in the CNT reaches the value set in advance in the ARR, it will terminate this count. -
Status register (TIMx_SR):
This register is used to mark whether the various events/interrupts currently associated with the timer have occurred.
II Various parameters of the timer
1): Prescaler: Timer prescaler setting, the clock source passes through this divider before it is the timer clock, it sets the value of the TIMx_PSC register. It sets the value of the TIMx_PSC register. The value can be set from 0 to 65535 to achieve a frequency division from 1 to 65536.
2): CouterMode: the timer counting mode and controls whether the timer counts up, down or centre.
3): Period: the period of the timer, can be set from 0 to 65535. assume that in the timer pre-division we have got the clock after the division is 1MHz. the value of Period we set to 1000, so that the timer generate interrupt frequency is: 1MHz/1000=1KHz, which is 1ms timing period.
4): ClockDivision: clock division, set the timer clock CK_INT frequency and digital filter sampling clock frequency division ratio.
5): RepetitionCounter: Repetition counter, which is a special register bit for advanced control registers, and can be used to control the number of PWM outputs very easily.