Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
03/23/04 12:02
Read: times


 
#67271 - RE: Problem with delays
Responding to: ???'s previous message
Keil:
I could comment that it is likely that your desire to call a huge delay loop from inside your interrupt is going to lead to problems.

Now I will agree that it is technically feasible that such interrupt routines can be made to work under very carefully controlled conditions it is certainly not the advisable approach.

You would be far better off making your code include a short timer interrupt function that ran say once each 10 milliseconds. Inside this timer interrupt have it manage one or more global counter variables that are coded as:
unsigned char data TimerA;
unsigned char data TimerB;

void TimerISR(void) interrupt
{
    // ...

    if(TimerA != 0)
    {
       TimerA--;
    }
    if(TimerB != 0)
    {
       TimerB--;
    }

    // ...
}


Next have your external interrupt routine be made short. Have it do the bare minimum activity that must be done in real time near to the actual event time of the interrupt. Then have it set appropriate bit flags when the long delay times must be managed. The external interrupt routine could be responsible for setting say the TimerA variable above to a non-zero count.

Lastly reconfigure your mainline code to handle both its functions and the end of time delay activities for the external interrupt routine. The mainline could use the TimerB variable. Whenever a delay is required then the TimerB is set to some count (such as 200 for a 2 second delay then the timer interrupt runs at a 100 Hz rate [10 msec period]). The code can note the delay completion time by polling TimerB variable for a return to a zero value. At the same time the mainline code can be polling bit flags from the external interrupt routine and then corespondingly managing the TimerA variable for a zero value to note that the deferred activity from the external interrupt routine needs attention paid to it.

Michael Karas



List of 17 messages in thread
TopicAuthorDate
Problem with delays            01/01/70 00:00      
   RE: Problem with delays            01/01/70 00:00      
   RE: Problem with delays            01/01/70 00:00      
      RE: Problem with delays            01/01/70 00:00      
         RE: Problem with delays            01/01/70 00:00      
            RE: Problem with delays            01/01/70 00:00      
               RE: Problem with delays            01/01/70 00:00      
                  RE: Problem with delays            01/01/70 00:00      
                     RE: Problem with delays            01/01/70 00:00      
                        RE: Problem with delays            01/01/70 00:00      
                           RE: Problem with delays            01/01/70 00:00      
                              RE: Problem with delays            01/01/70 00:00      
   RE: Problem with delays            01/01/70 00:00      
   RE: Problem with delays            01/01/70 00:00      
      RE: Problem with delays            01/01/70 00:00      
         RE: Problem with delays            01/01/70 00:00      
   RE: Problem with delays            01/01/70 00:00      

Back to Subject List