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/31/11 04:14
Read: 370 times
Hamilton
New Zealand


 
#184474 - try this - maybe
Responding to: Michael Karas's previous message

Here's how I do it



//-----------------------------------------------------------------------------
// TIMER2_ISR
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters   : None
//
// This is the ISR for the TIMER2.  
//
//-----------------------------------------------------------------------------
void ONE_KHZ_ISR (void) interrupt 5 {
    TF2 = 0;                            // Reset Interrupt


    WDTCN = 0xA5;  //this is not ideal but needed here for other reasons.
    gui_mSecCount++;
    gb_mSecTick = TRUE;
	guc_LCD_delay_mSec--;
}



 



then in my main() function


 while(1){
	

        if (gb_mSecTick == TRUE) {
            gb_mSecTick = FALSE;
            fun1mSec();
        }
        

        if (gb_10mSecTick == TRUE) {
            gb_10mSecTick = FALSE;
            fun10mSec();
        }


        if (gb_100mSecTick == TRUE) {
            gb_100mSecTick = FALSE;
            fun100mSec();
        }


        if (gb_250mSecTick == TRUE) {
            gb_250mSecTick = FALSE;
            fun250mSec();
        }


        if (gb_SecTick == TRUE) {
            gb_SecTick = FALSE;
            fun1Sec();
        }
        
        if (gb_MinTick == TRUE) {

            gb_MinTick = FALSE;
            fun1Min();
        }

    }
}





//this function carries out the period timed functions
//that are not time critical.
void fun1mSec(void) {
    //kick the dog
    if (gui_mSecCount % 10 == 0){
       gb_10mSecTick = TRUE;
    }


    if (gui_mSecCount % 100 == 0){
        gb_100mSecTick = TRUE;
    }
    
    if (gui_mSecCount % 250 == 0){
        gb_250mSecTick = TRUE;
    }


    if (gui_mSecCount % 1000 == 0){
        gb_SecTick = TRUE;
    }



    if (gui_mSecCount >=60000){
        gui_mSecCount = 0;   
        gb_MinTick = TRUE;
    
    }

}
 .... and so on




 



These are not time critical values, here, they are ABOUT the time period you expect, for time critical functions you can use the other timers. not associated with your tick function



List of 9 messages in thread
TopicAuthorDate
Multiple calls to segment      Raj Nambiar      10/29/11 05:01      
   General ISR Design Principle        Michael Karas      10/29/11 06:14      
      Incorrect use of ISR      Per Westermark      10/29/11 07:06      
         the missed issue      Erik Malund      10/29/11 08:07      
      Delay Routines....      Michael Karas      10/29/11 09:34      
         Thanks a million...      Raj Nambiar      10/31/11 02:07      
            us, not ms      Per Westermark      10/31/11 04:27      
      try this - maybe      Marshall Brown      10/31/11 04:14      
         Thanks Brown..      Raj Nambiar      11/04/11 09:44      

Back to Subject List