In K10 microcontroller how can we get a real time delay like delayms(100) or delayus(100) for 100 ms and 100 us delay?

cancel
Showing results for 
Search instead for 
Did you mean: 

In K10 microcontroller how can we get a real time delay like delayms(100) or delayus(100) for 100 ms and 100 us delay?

Jump to solution
501 Views
psjhawer
Contributor II

Hi All,

I'm using an MK10DX128VLH5 IC in my project. I want to give a delay of exactly 3 secs in between 2 operations. Is there an inbuilt function or something that can give me this exact delay??.

Meanwhile if u guys can help me with the amount of delay the followingfunction gives when run, it would help me solve the issue more easier. The following code is already used in an existing code which i need to change for an upgraded product.

Delay_t(20000);

void Delay_t(unsigned int i){

  int k;

while(i--){

    for(k=0;k<10;k++){ 

  asm ("NOP");

    }

  }

}

The CPU Configuration is as follows:

pastedImage_1.png

Please help ASAP. Plz let me know if any other information is required..

Thanks in advance,

Prafful

Tags (3)
0 Kudos
1 Solution
314 Views
santiago_gonzal
NXP Employee
NXP Employee

Hello,

In embedded projects usually you don't block the MCU to wait for such big amounts of time. Instead you can use a timer to get notified via an interrupt after the time has passed.

This tutorial will help you:

http://mcuoneclipse.com/2012/08/13/tutorial-timer-led-with-processor-expert-for-kinetis/

Regards,

Santiago

View solution in original post

0 Kudos
3 Replies
314 Views
jeremyzhou
NXP TechSupport
NXP TechSupport

Hi Prafful,

Santiago illustrated one way to get precise delay, and I'd like to suggest that you can also use the systick timer to implement precise delay.

You could check the detail description of systick timer through the thread as follow.

Where is detail description for Systick for KL?
Have a great day,
Ping

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

315 Views
santiago_gonzal
NXP Employee
NXP Employee

Hello,

In embedded projects usually you don't block the MCU to wait for such big amounts of time. Instead you can use a timer to get notified via an interrupt after the time has passed.

This tutorial will help you:

http://mcuoneclipse.com/2012/08/13/tutorial-timer-led-with-processor-expert-for-kinetis/

Regards,

Santiago

0 Kudos
314 Views
psjhawer
Contributor II

Thanks for your reply santiago.gonzalez The timer inturrupt was very helpful and made my day. :smileyhappy: The tutorial u suggested was also very helpful. Thanks once again..

Regards,

Prafful

:smileyhappy::smileygrin::smileyhappy:

0 Kudos