Stm32-M3 system time base Timer

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.