SysTick delay function

Source: Internet
Author: User

Delay function with Systick (System tick timer)

1.4 Registers

Systick->ctrl,--control and status registers

Systick->load,--Reload register

Systick->val,--Current value register

Systick->calib,--Calibration value Register

There are their respective descriptions: reference address: http://blog.csdn.net/marike1314/article/details/5673684

2.systick programming

Set the clock source (one is directly equal to the HCLK clock, one is the HCLK/8)

Kernel clock Systick->ctrl |= systick_clksource_hclk; 0x00000004

External clock source Systick->ctrl &= SYSTICK_CLKSOURCE_HCLK_DIV8;//0XFFFFFFFB

If the HCLK clock is 8M

void Delay_1us (U16 value)
{
Set Systick clock Source hclk=8m

systick->load=value*8; Time-load time is 8M 8 times 1us

systick->val=0x00; Empty counter
systick->ctrl=0x00000005; Set the clock source to HCLK (8M) and start the countdown 0x00000004|0x01
while (!) ( systick->ctrl& (1<<16)); The wait time arrives at Systick->ctrl's Countflag to arrive at 1 o'clock time (while expression 1 will always loop, jumping out of the loop for 0 o'clock)
systick->ctrl=0x00000004; Turn off counters
}

SysTick delay function

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.