Preston Kent

Free Running Timer

Discussion created by Preston Kent on Feb 14, 2007
Latest reply on Feb 23, 2007 by Preston Kent
I am using CW5.7 on a HC08.
 
I do not think there is a need to use interrupts but I have been wrong before :smileyhappy:
I would like to use boolean logic to start timing and when the timer reaches a certain time, before an action. The problem seems to be that the Beans seem to count events rather than true time. I do not have a firm grasp of the definition of event but I guess it is has something with lines of code executed.
 
I am currently using the FreeCntr32 timing function which does not seem to give me the expected results.
 
This is the simplest code in which I get a true account of time. But if I make it more complicated, hence more instructions between reading times, the time values start to become illogical going from 1 sec to 11k, and that is when I step through the code with the debugger. I maybe a bit slow but not that slow stepping through code.
 
So is there some free running  timer that I might be able to tap in to for measuring time?
 
Simple Code:
Code:
  while(1){    if(i > 50000){      if(One_Shot == 0){        FC321_Reset();        One_Shot = 1;      }else{        FC321_GetTimeSec(&time);        if(time > 5){                    One_Shot = 0;          i = 0;        }      }    }else{      i++;    }  }//while(1)

 The more complicated code.
Code:
  while(1)  {    /* If there has a been a successful rack in and rack out procedure      increment the number of complete racking cycles by 1 */    if(Successful_RackIn && Successful_RackOut){      Cycles_Complete++;      Successful_RackIn = 0;      Successful_RackOut = 0;    }        /* If the Close button is pushed on the HMI and the breaker is either      racked in or racked out, and open, allow the breaker to close */    if(HMI_Close){      if(PS_In && !PS_Out){        if(!Rack_MOC_NO && Rack_MOC_NC){          Enable_Close = 1;        }      }else if (!PS_In && PS_Out){        if(!Rack_MOC_NO && Rack_MOC_NC){          Enable_Close = 1;        }      }    }        /* If the breaker is allowed to close, allow 2 seconds to elapse for      the mechanical closing of the breaker */    if(Enable_Close){      if(One_Shot == 0){        FC321_Reset();        One_Shot = 1;        Close_BKR = 1;      }else{        FC321_GetTimeSec(&Time_Close);        if(Time_Close > 2){          if(Enable_Close){            Enable_Close = 0;            One_Shot = 0;          }        }      }    }        if(i > 5){      if(One_Shot == 0){        FC321_Reset();        One_Shot = 1;      }else{        FC321_GetTimeSec(&time);        if(time > 5){                    One_Shot = 0;          i = 0;        }      }    }        if(i > 10){      Enable_Close = 1;      i = 0;    }else{      i++;    }  }//while(1)

 

Message Edited by Joxer on 2007-02-1408:48 AM

Message Edited by Joxer on 2007-02-1408:49 AM

Outcomes