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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
06/21/10 13:52
Read: times


 
#176804 - Using Timer May Still be Possible
Responding to: ???'s previous message
It may still be possible to use timers for the delay. Take a look at what you already use the timers for and most likely one can be adapted to operation as follows:

Have a timer generate a periodic timer interrupt. Select a suitable interrupt period based upon the time base resolution you need. Intervals of 1msec and 10msec are good ones to work with.

Then allocate a few global variables such as:

volatile unsigned char timer_A;
volatile unsigned char timer_B;


At system initialize time set timer_A and timer_B equal to zero.

In the timer interrupt routine have some code that looks like this:

if{timer_A > 0)
{
    timer_A = timer_A - 1;
}
if(timer_B > 0)
{
    timer_B = timer_B - 1;
}


(Note that the above can also be written as timer_A--;)

Anyplace on your main code thread that you need a time delay use code that places a count into one of timer_A or timer_B. The count placed there is equal to the desired time delay divided by the timer interrupt interval time. If you used a 10msec timer interval then these "software timers" can be used for delays of 10msec to 2.55 seconds.

Detect the end of the time delay in the main code block by periodically checking if the timer value has gone to zero.

if(timer_A == 0)
{
    take action
}


You can use this technique to make longer time delays by programming a timer as:

volatile unsigned int timer_C;


However be aware that in the main code space it is necessary to protect access to these multibyte timers by disabling interrupts around code that sets the timer values and code that checks the value for the zero value.

Michael Karas



List of 23 messages in thread
TopicAuthorDate
Ideas for Multi-tap keyboard routine            01/01/70 00:00      
   just follow            01/01/70 00:00      
   Multi-tap is not too difficult            01/01/70 00:00      
      Two-step operation. Keyboard input + post-processing            01/01/70 00:00      
         State Machine!            01/01/70 00:00      
            Agree 100%            01/01/70 00:00      
               Time to code            01/01/70 00:00      
                  Software Timers!            01/01/70 00:00      
                     Practical Limits            01/01/70 00:00      
                        Don't lock up in infinite loops everywhere            01/01/70 00:00      
                           In the pseudo code...            01/01/70 00:00      
                           State Machine            01/01/70 00:00      
                              Divide by 5            01/01/70 00:00      
                                 Timer resolution            01/01/70 00:00      
                              State Machine            01/01/70 00:00      
                              Looks not bad programming practice            01/01/70 00:00      
                  Using Timer May Still be Possible            01/01/70 00:00      
                     Done !            01/01/70 00:00      
                        Very Cool!!!            01/01/70 00:00      
                        Compare with zero is better            01/01/70 00:00      
                           Avoid ISR jitter using timer T1            01/01/70 00:00      
                           Code!            01/01/70 00:00      
                              Thanks Munish...            01/01/70 00:00      

Back to Subject List