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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
02/28/03 19:22
Read: times


 
#40318 - RE: Using Timers
Responding to: ???'s previous message
Thats what I do....I have one timer interrupt that runs say at 1KHz (1 millisecond). Then I have a series of "timer variables" that are used by the main line code. Depending upon length of delay I will have some that are 2 bytes and some that are 1 byte. The one byte timers can support delays of up to 255 mSec (about 1/4 second). The 2 byte timers can support delays of 65535 mSec which is just over a minute.

The timer interrupt code looks at each timer variable and if it is non-zero it then decrements the variable.

In the mainline code you simply load a count of milliseconds delay into the timer variable and then in whatever else is going on you can poll this timer variable for a zero/nonzero value. As long as the thing is non zero you know the time delay has not expired.

When using the 16-bit type counters it is necessary to disable interrupts during the setting of the 2 byte variable or during the polling of the value for the timer expire. I sometimes use a technique with the 16-bit variety of allocating a bit flag per timer variable in the bit data area. Then upon setting the timer variable I set the corresponding bit flag. When the timer interrupt decrements a timer variable to zero it then clears the bit flag. Thus when the mainline code needs to poll a timer state it simply has to look at the flag bit and there is no need to disable interrupts during the polling process.

Michael Karas


List of 11 messages in thread
TopicAuthorDate
Using Timers            01/01/70 00:00      
   RE: Using Timers            01/01/70 00:00      
      RE: Using Timers            01/01/70 00:00      
   RE: Using Timers            01/01/70 00:00      
   RE: Using Timers            01/01/70 00:00      
      RE: Using Timers            01/01/70 00:00      
   RE: Using Timers            01/01/70 00:00      
      RE: Using Timers            01/01/70 00:00      
         RE: Using Timers            01/01/70 00:00      
            RE: Using Timers            01/01/70 00:00      
               RE: Using Timers            01/01/70 00:00      

Back to Subject List