Author Topic: timeout function using "tick32HasExpired"  (Read 2714 times)


  • Sr. Member
  • ****
  • Posts: 34
    • View Profile
timeout function using "tick32HasExpired"
« on: March 06, 2014, 06:04:01 PM »

I have been using "tickHasExpired" to do other timing tasks with no problems, but when I try to do a longer count e.g. 2 mins, it did not work.

What I want to do:
The push button is pressed, start the operation, start the timer to delay for 2 mins.  If nothing happens, time out occurs and stop the operation.  If something happens, restart the timer.

How I did:
DWORD tmrSystemTimeOut;

  if Push button pressed
     tmrSystemTimeOut = tick32Get(); //timeout period
     tick32UpdateMin(tmrSystemTimeOut, 2); //start counting system time out in 2 min
  if (tick32HasExpired(tmrSystemTimeOut))

  if something happens
    tmrSystemTimeOut = tick32Get();
    tick32UpdateMin(tmrSystemTimeOut, 2); //start counting system time out in 2 mins

The tmrSystemTimeOut has never expired some how.  And if I use 16-bit tick function "tickHasExpired" instead for 30 secs, it works perfectly. 

Please anyone, I am stuck.

« Last Edit: March 06, 2014, 09:37:41 PM by modtro2 »


  • Administrator
  • Hero Member
  • *****
  • Posts: 564
    • View Profile
Re: timeout function using "tick32HasExpired"
« Reply #1 on: March 14, 2014, 03:00:25 PM »
Hi Bua

The following code works fine for me (using current 2.03 Beta):

Code: [Select]
int main(void) {
    DWORD tmr32Task1Hour;           //Do something every hour (32-bit, 1ms Timer)
    tmr32Task1Hour = tick32Get();   //Set with current 32-bit tick.
    while(1) {
        //Do something every 2 minutes
        if (tick32HasExpired(tmr32Task1Hour)) {
            tick32UpdateMin(tmr32Task1Hour, 2); //Expire again in 2 minutes
            //..... Add code here to be executed every hour
    }//end while