Delay Function in msec

cancel
Showing results for 
Search instead for 
Did you mean: 

Delay Function in msec

846 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by superkato on Wed Apr 08 05:25:05 MST 2015
Hi,

does someone has a example for a simple delay function in milliseconds?

like:
Delay(1000); //1sec delay


void Delay(uint32_t msecs)
{
  while (msecs != 0)   
  {
    //do something with the systicktimer;
  }

}



Labels (1)
0 Kudos
2 Replies

252 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Wed Apr 08 09:24:24 MST 2015
http://www.lpcware.com/content/forum/what-do-you-use-to-delay
0 Kudos

252 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by nerd herd on Wed Apr 08 07:28:55 MST 2015
Hi superkato,

Just to get your thought process going, a basic delay function can be implemented by using a timer interrupt (Systick works fine) and sleep mode. The idea is that you start a timer that will count for the desired delay duration. While it is counting, the MCU can be put into Sleep mode ensuring no code is being executed. Once the timer goes off, the interrupt will wake up the MCU and resume code execution. You can then disable the timer and exit the delay function.
0 Kudos