3. Systick Timer:

Source: Internet
Author: User

1, SysTick is a 24-bit decrement counter, SysTick set the initial value and enable, every 1 system clock cycle, the count is reduced by 1.

Counting to 0 o'clock, the SysTick counter automatically resets the initial value and continues counting, while the internal Countflag flag is set to trigger an interrupt if the interrupt is enabled.

2. Register

STK_CSR, 0xe000e010, control register

Stk_load, 0xe000e014, Reload Register

Stk_val, 0xe000e018, current value register

STK_CALRB, 0xe000e01c, calibration value Register

3. STK_CSR Control Register

No. 0 bit: Enable,systick Enable bit (0: Turn off Systick function; 1: Turn on Systick function)

1th bit: Tickint,systick interrupt Enable bit (0: Shutdown Systick interrupt; 1: Turn on Systick interrupt)

2nd bit: Clksource,systick Clock Source Selection (0: Use HCLK/8 as Systick clock; 1: Use HCLK as Systick clock)

16th bit: Countflag,systick count comparison flag, if SysTick has counted to 0 after the last read of this register, the bit is 1. If the bit is read, the bit is automatically zeroed

4. Stk_load Reload Register
The Systick is a descending timer, and when the timer decrements to 0 o'clock, the value in the Reload register is reloaded and continues to start decreasing.
The Stk_load overload register is a 24-bit register with a maximum count of 0xFFFFFF.

5. Stk_val Current Value Register
It is also a 24-bit register that returns the value of the current inverted count when read, writes it to zero, and clears the COUNTFLAG flag in the Systick control and status register.

6, STK_CALRB Calibration value Register

7. Timer use Routine

1 /*main.c*/2 3#include"pbdata.h"//calling custom public function libraries4 5 voidRcc_configuration (void);//system clock initialization function declaration6 voidGpio_configuration (void);//Gpio initialization function declaration7 8 intMainvoid)//void cannot void define main function9 {TenRcc_configuration ();//system Clock Initialization One      A      -      -      theGpio_configuration ();//Port Initialization -      -  - /*Enter GPIO processing*/ +    while(1) -   { +Gpio_setbits (gpiob,gpio_pin_5);//Specifies that the port is set to high A      atDelay_ms ( +);//1s,delay, defining itself in the Public function library -   -Gpio_resetbits (gpiob,gpio_pin_5);//specify port setting low level -  -Delay_ms ( +);//1s,delay, defining itself in the Public function library -   } in } -      to      +     voidRcc_configuration (void)//High initialization function of system clock -   { the          *Systeminit ();//initialization of the system $Rcc_apb2periphclockcmd (rcc_apb2periph_gpiob,enable);//corresponds to Gpio clock enablePanax Notoginseng     } -      the      +     voidGpio_configuration (void)//Gpio initialization function A   { theGpio_inittypedef gpio_initstructure;//defines a struct-body variable for a gpio setting +  -         /*struct variable Assignment*/ $Gpio_initstructure.gpio_pin=gpio_pin_5;////PIN Configuration $Gpio_initstructure.gpio_speed=gpio_speed_50mhz;//Configuration Frequency -GPIO_INITSTRUCTURE.GPIO_MODE=GPIO_MODE_OUT_PP;//push-Pull output -          the          /*corresponding GPIO initialization*/ -Gpio_init (gpiob,&gpio_initstructure);Wuyi   } the      -  Wu      -  About     
View Code
1 /*PBDATA.C*/2 3#include"pbdata.h"4 5 6U8 dt=0;7 8 voiddelay (u32 ncount)9 {Ten    for(; ncount!=0; ncount--); One } A  -  -  the  - /*microsecond level delay*/ - voidDelay_us (u32 NUS) - { + u32 temp; -Systick->load =9*nus;//load the initial value, 72m/8=9m, which is 1/9us,9*1/9us, so it's done 9 times . +Systick->val=0x00;//empty the counter and automatically set the value of the counter you set. ASystick->ctrl=0x01;//enable, minus 0 action (no interruption), external clock at      -      Do -     { -temp=systick->ctrl;//flag, wait until it's been reduced to 0. -} while((temp&0x01) && (! ( temp& (1<< -))));//wait Time arrives -      inSystick->ctrl=0x00;//Turn off Counters -Systick->val =0x00;//Empty Counter to } +  -  the  * /*millisecond-level delay*/ $ voidDelay_ms (U16 NMS)Panax Notoginseng { - u32 temp; theSystick->load =9000*NMS;//load the initial value, 72m/8=9m, which is 1/9us,9*1/9us, so it's done 9,000 times . +Systick->val=0x00;//empty the counter and automatically set the value of the counter you set. ASystick->ctrl=0x01;//enable, minus 0 action (no interruption), external clock the      +      Do -     { $temp=systick->ctrl;//flag, wait until it's been reduced to 0. $} while((temp&0x01) && (! ( temp& (1<< -))));//wait Time arrives -      -Systick->ctrl=0x00;//Turn off Counters theSystick->val =0x00;//Empty Counter -}
View Code
1 /*pbdata.h*/2 3 #ifndef _pbdata_h4 #define_pbdata_h5 6#include"stm32f10x.h"7 8 /*Custom Global Variables*/9 externU8 DT;Ten  One /*Custom Functions*/ A voiddelay (u32 ncount); - voidDelay_us (u32 nus); - voidDelay_ms (U16 NMS); the  - #endif
View Code


8, Timer use example download

http://download.csdn.net/detail/a1181803348/8737749

3. Systick Timer:

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.