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

C delay routine

I need to write a delay routine in C for a 80C251 . The delay has got to be about 30 seconds . Any ideas welcomed.

Parents
  • Hi Iain,

    you really shouldn't wait 30 seconds and let your processor do nothing else than waiting. That is a no-no for embedded applications.

    You should write an interrupt service routine for a timer (i.e. timer 0) that is invoked like every 10ms. The ISR should count down a volatile variable as long as it is not zero. And when you wait in your main loop, you can set that countdown variable at the beginning of your waiting periode and checking it in every loop for being zero. This way, you can determin the end of a waiting periode and do lotsa useful things while waiting.

    Take care
    Sven

Reply
  • Hi Iain,

    you really shouldn't wait 30 seconds and let your processor do nothing else than waiting. That is a no-no for embedded applications.

    You should write an interrupt service routine for a timer (i.e. timer 0) that is invoked like every 10ms. The ISR should count down a volatile variable as long as it is not zero. And when you wait in your main loop, you can set that countdown variable at the beginning of your waiting periode and checking it in every loop for being zero. This way, you can determin the end of a waiting periode and do lotsa useful things while waiting.

    Take care
    Sven

Children
  • you really shouldn't wait 30 seconds and let your processor do nothing else than waiting. That is a no-no for embedded applications.

    Not at all true. In low power applications it is very common to sleep for long periods of time waking up on interrupt to see if there is work to do. Remember, real-time only means you meet all your deadlines. It does not imply fast.

    If you truly need to do other processing while the ISR counts down a variable then you should use a task scheduler. Polling is usually a hack in this sort of situation.

    - Mark