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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
Marshall Brown
10/11/12 15:58
Read: 697 times
New Zealand

#188629 - The timer simply increments
Responding to: Erik Malund's previous message
Sorry for any confusion

The timer ISR is

void ONE_KHZ_ISR (void) interrupt 5 {
    TF2 = 0;                            // Reset Interrupt

   WDTCN = 0xA5;
   gb_mSecTick = TRUE;
   timer_count++;						//this is count for our sort out timers tick
										//we use this to make sure we don't miss a timer event 
										//if we take too long processing something, this will always fire.



I would have thought that is pretty short.....

Then at some non critical non ISR point in my code I call.


//call this on a 1mSec or more tick that is not on an interrupt.
void TIMERS_sort_out_timers(void){
	unsigned char i;
	unsigned int elapsed_msecs;

	elapsed_msecs = timer_count;
	timer_count = 0;

	for (i = 0; i < NUMBER_OF_TIMERS; i++){				//step through each of our timers
		if (timer_array[i].current_value != 0){			//see if we have already expired.
//			timer_array[i].current_value --;			//if not then decrement the timer toward 0 
			timer_array[i].current_value -= elapsed_msecs;			//if not then decrement the timer toward 0 or past 0 
			if (timer_array[i].current_value <= 0){		//now see if we have timed out
				if (timer_array[i].timer_type == timer_periodic){	//if we run on a periodic timer 
					timer_array[i].current_value = timer_array[i].reset_value;	//reload the timer 
				timer_array[i].timeout_func(timer_array[i].func_args);			//if we have timed out then perform the function in our callback.


In this manner I am not hanging around in an interrupt.

And I'm not processing an expired timer in the ISR?


List of 13 messages in thread
Timers - Function Pointers      Marshall Brown      10/03/12 21:08      
   Too much for a '51?      Oliver Sedlacek      10/04/12 02:05      
      I Agree      Marshall Brown      10/04/12 03:27      
   Function Pointers...      Andy Neil      10/04/12 05:50      
   you are violating KISS      Erik Malund      10/04/12 08:41      
   Various Timer Functions        Michael Karas      10/06/12 01:14      
      Thanks Michael      Marshall Brown      10/06/12 23:34      
         regardless, you are violating KISS        Erik Malund      10/09/12 07:44      
            even on ARM      Stefan KAnev      10/09/12 13:40      
            The timer simply increments      Marshall Brown      10/11/12 15:58      
               bug      Marshall Brown      10/11/12 16:08      
                  more bugs      Maarten Brock      10/13/12 14:30      
                     thanks      Marshall Brown      10/14/12 13:31      

Back to Subject List