TIM_PRESCALER: Timer pre-divider setting, through which the clock source is the timer clock, which sets the value of the TIMX_PSC register. The range can be set from 0 to 65535 to achieve 1 to 65536 frequency division.

TIM_PERIOD: The timer period, which essentially sets the value of the auto-reload register to be updated to the shadow register when the event is generated. The range can be set from 0 to 65535.

According to the frequency of the timer clock, such as the frequency of the clock is 72MHz, it can be understood that the STM32 will count 72M times in one second. The pre-frequency division coefficient is to divide the frequency, such as the frequency division coefficient is 72, then the frequency of the clock will become 72MHz /72= 1MHz. However, it should be noted that the value should be 72-1 when setting.

Assuming the frequency division coefficient is 72-1, the frequency becomes 1MHz, which means that the STM32 counts 1M times per second, or once per us.

OK, the next step is to determine the preload value. For example, 1ms is needed. Since 1ms=1us*1000, the preload value is 1000-1. And so on, in the case that the pre-frequency division coefficient is determined, the duration of the timing is determined by the pre-load value. And the reason why we want to subtract one from the value, is that we’re counting from zero, so we want to subtract one.

The original link: https://blog.csdn.net/ZIIllII…

// For a frequency of 71MHz, interrupt once at 500ms. These two parameters are set as follows: TIM_PRESCALER =7199; // Tim_period =4999; // The value of the automatic reload register period of the next update event load activity // The frequency divide is 7200, Using 72000000/7200=10000Hz // the cycle at this point is 1/10000=0.0001s //500ms=0.0001s*5000 times //5000-1=4999 times // that is, through 4999 times of system operation, it is 500ms