The stm32-M3 has a system time base timer, which is a 24-bit descending counter. After the system time base timer is set and enabled, the counter is reduced by one every time the system goes through a clock cycle. When the counter is reduced to 0, the base timer automatically loads the initial value, continue to count down, and the internal COUNTFLAG flag will be set to trigger the interruption.
The system time base timer function is simple, and only one time base timer can be provided as a tick clock. In an external crystal oscillator with 8 MHZ, the system clock frequency is 72 MHz by means of pl95. the decreasing frequency of the system clock timer can be set to 9 MHz (HCLK/8). Under this condition, set the initial value of the system timer to 90000 to generate a 10 ms time base value. If the interrupt is enabled, a 10 ms interruption occurs. It is gratifying that the interrupt bit of the time base timer does not need to be cleared, and the system will automatically clear the interrupt bit.
The following uses a simple program to change the light to one second.
[Cpp]
Void SysTick_Configuration (void)
{
/* Configure HCLK clock as your ick clock source */
SysTick_CLKSourceConfig (SysTick_CLKSource_HCLK_Div8); // The system clock is divided by 8.
/* SysTick interrupt each 1000Hz with HCLK equal to 72 MHz */
SysTick_SetReload (90000); // the cycle is 10 ms.
/* Enable the specified ick Interrupt */
SysTick_ITConfig (ENABLE); // ENABLE the interrupt
/* Enable the specified ick Counter */
Required ick_countercmd (required ick_counter_enable); // count allowed
}
Void javasickhandler (void)
{
Num ++;
If (num = 100)
{Num = 0; // the counter is cleared.
LED (); // hop Function
}
}
The system time-based timer is a very convenient timer, which is not as troublesome as the TIM timer. It is very convenient to use and can be used for some simple timing.
By rongdeguoqian