This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Delay function in C using P89c51RD2HBP

How to calculate the exact delay without the use of the timer?

For example if i want a 10ms delay, i need to achieve this delay using the for loop not with help of the in built timer.

Is there any formula or calculation to do the delay?

I dont know how to get it. I am using P89c51RD2HBP microcontroller.

Currently i am using a random delay which is worst case delay.

Anybody can say how to do the correct delay using the loop method.

Parents
  • "If you write a timing loop in C, then you can't be sure that the compiler will always generate exactly the same code from release to release, or optimization to optimization."

    It's worse than that, Jim: Even unsing the same compiler release with the same oprimisation settings, you still cannot be certain!!

    eg, if the compiler initially decides to use a register for your loop counter, then you write some extra code, and the compiler decides to use the register for something else other than your loop counter - your loop timing will change!

    A change of Memory Model would also probably change the timing.

    See this thread for a perfect illustration of why any attempt to write accurate timing loops in 'C' is futile:
    http://www.keil.com/forum/docs/thread8664.asp

Reply
  • "If you write a timing loop in C, then you can't be sure that the compiler will always generate exactly the same code from release to release, or optimization to optimization."

    It's worse than that, Jim: Even unsing the same compiler release with the same oprimisation settings, you still cannot be certain!!

    eg, if the compiler initially decides to use a register for your loop counter, then you write some extra code, and the compiler decides to use the register for something else other than your loop counter - your loop timing will change!

    A change of Memory Model would also probably change the timing.

    See this thread for a perfect illustration of why any attempt to write accurate timing loops in 'C' is futile:
    http://www.keil.com/forum/docs/thread8664.asp

Children
No data