Stop Program After X Seconds

hippy

Technical Support
Staff member
On the PICAXE M2 chips you can use the 'time' variable which increments about once every second, so can take action when 'time >= 120'.
 

westaust55

Moderator
And after the 2 minutes / 120 seconds, use the
STOP command
Which will stop all action until the power is cycled.
 

PhilHornby

Senior Member
M2 Series multi-tasking....

I need to stop my program after 2 Minutes, is there any way to do it, like an internal timer or multi threading?
Something like this? :-
Code:
[COLOR=blue]Start0:
      do
            [/COLOR][COLOR=green];
            ; This is the main program...
            ; ...running at 16MHz
            ;
            [/COLOR][COLOR=blue]Sertxd (cr[/COLOR][COLOR=black],[/COLOR][COLOR=blue]lf[/COLOR][COLOR=black],[/COLOR][COLOR=red]"Main program here"[/COLOR][COLOR=blue])
      loop
Start1:
      Pause [/COLOR][COLOR=navy]60000       [/COLOR][COLOR=green];wait one minute
      [/COLOR][COLOR=blue]Pause [/COLOR][COLOR=navy]60000       [/COLOR][COLOR=green];wait another minute
      ;
      ; we could just stop both tasks...
      ;
      [/COLOR][COLOR=blue]end   [/COLOR][COLOR=green];(stop could be used - which doesn't power everything down)
      ;
      ; ...or just the main one...
      ;
      [/COLOR][COLOR=blue]suspend [/COLOR][COLOR=navy]0
      [/COLOR][COLOR=green];
      ; ...in which case, we can carry on and do other things here
      ;
      [/COLOR][COLOR=blue]sertxd(cr[/COLOR][COLOR=black],[/COLOR][COLOR=blue]lf[/COLOR][COLOR=black],[/COLOR][COLOR=red]"Task 1 still alive"[/COLOR][COLOR=blue])
      [/COLOR][COLOR=green];
      [/COLOR][COLOR=blue]end [/COLOR][COLOR=green];?[/COLOR]
 

Tiago Severino

New Member
Hi Welcome
Doe's it need to restart after another time period

john
I just need to shutdown after 2 minutes

On the PICAXE M2 chips you can use the 'time' variable which increments about once every second, so can take action when 'time >= 120'.
I know but time doesn't increment when in pause command, and I'm using some functions with pause command

And after the 2 minutes / 120 seconds, use the
STOP command
Which will stop all action until the power is cycled.
Yes, but I need to know when it passed 2 minutes since program elapsed


Something like this? :-
Code:
[COLOR=blue]Start0:
      do
            [/COLOR][COLOR=green];
            ; This is the main program...
            ; ...running at 16MHz
            ;
            [/COLOR][COLOR=blue]Sertxd (cr[/COLOR][COLOR=black],[/COLOR][COLOR=blue]lf[/COLOR][COLOR=black],[/COLOR][COLOR=red]"Main program here"[/COLOR][COLOR=blue])
      loop
Start1:
      Pause [/COLOR][COLOR=navy]60000       [/COLOR][COLOR=green];wait one minute
      [/COLOR][COLOR=blue]Pause [/COLOR][COLOR=navy]60000       [/COLOR][COLOR=green];wait another minute
      ;
      ; we could just stop both tasks...
      ;
      [/COLOR][COLOR=blue]end   [/COLOR][COLOR=green];(stop could be used - which doesn't power everything down)
      ;
      ; ...or just the main one...
      ;
      [/COLOR][COLOR=blue]suspend [/COLOR][COLOR=navy]0
      [/COLOR][COLOR=green];
      ; ...in which case, we can carry on and do other things here
      ;
      [/COLOR][COLOR=blue]sertxd(cr[/COLOR][COLOR=black],[/COLOR][COLOR=blue]lf[/COLOR][COLOR=black],[/COLOR][COLOR=red]"Task 1 still alive"[/COLOR][COLOR=blue])
      [/COLOR][COLOR=green];
      [/COLOR][COLOR=blue]end [/COLOR][COLOR=green];?[/COLOR]
Will Start0 and Start1 run in parallel? Gonna try it
 

lbenson

Senior Member
I just need to shutdown after 2 minutes . . . I know but time doesn't increment when in pause command, and I'm using some functions with pause command
time certainly does increment during pauses.
Code:
#picaxe 08M2
pause 5000
sertxd(#time)
This prints "5".

If some of your pauses might carry you over the 120 second mark, break up the pauses into smaller pieces and check time in between pauses.
 

Tiago Severino

New Member
time certainly does increment during pauses.
Code:
#picaxe 08M2
pause 5000
sertxd(#time)
This prints "5".

If some of your pauses might carry you over the 120 second mark, break up the pauses into smaller pieces and check time in between pauses.
Oh my bad, it just don't increment with sleep command, thank you!
 
Top