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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
10/31/11 10:14
Read: times


 
#184474 - try this - maybe
Responding to: ???'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            01/01/70 00:00      
   General ISR Design Principle            01/01/70 00:00      
      Incorrect use of ISR            01/01/70 00:00      
         the missed issue            01/01/70 00:00      
      Delay Routines....            01/01/70 00:00      
         Thanks a million...            01/01/70 00:00      
            us, not ms            01/01/70 00:00      
      try this - maybe            01/01/70 00:00      
         Thanks Brown..            01/01/70 00:00      

Back to Subject List