No Pause

TTOP

New Member
If you want to pause part of a program for 500milliseconds but do not want to use "pause 500" because that will pause the entire program, what would be used?

inc W1
if W1 = "what value to equal 500 miilseconds?" then do something endif

or

inc W1
if pinc.1 = 1 and W1 = "what value to equal 500milliseconds? then high c.0 endif
if W1 = 500milliseconds then W1 = 0 endif
 

erco

Senior Member
Classic problem. You need to run a loop to continue executing whatever commands (monitoring pins, sensors, blinking LEDs, etc) need to continue during your half second interval. There are a few ways to do it, perhaps a FOR/NEXT loop experimentally calibrated to last ~500 milliseconds, or an interrupt, of course.
 

TTOP

New Member
Classic problem. You need to run a loop to continue executing whatever commands (monitoring pins, sensors, blinking LEDs, etc) need to continue during your half second interval. There are a few ways to do it, perhaps a FOR/NEXT loop experimentally calibrated to last ~500 milliseconds, or an interrupt, of course.
Won't a FOR/NEXT loop still pause the rest of the program until the loop is finished?
 

premelec

Senior Member
@TTOP - perhaps be more specific what you are trying to do- you can have a variable increment each time you go through a lot of procedures and do something and reset when it hits certain value for instance...
 

TTOP

New Member
@TTOP - perhaps be more specific what you are trying to do- you can have a variable increment each time you go through a lot of procedures and do something and reset when it hits certain value for instance...
premelec, ok on having a variable increment each time and then do something and then reset the variable but how do you determine what the value of the variable should be to equal 500 milliseconds?
 

srnet

Senior Member
If you want to pause part of a program for 500milliseconds but do not want to use "pause 500" because that will pause the entire program, what would be used?
More details required perhaps ?

You want to pause (stop for a while) a program but still have the program running ?
 

westaust55

Moderator
You may also be able to consider an M2 PICAXE part and use separate tasks but we need more and clear information on what you are trying to achieve.
 

TTOP

New Member
More details required perhaps ?

You want to pause (stop for a while) a program but still have the program running ?
No- only delay certain commands in the program while the whole program does not delay and keeps running.
 

techElder

Well-known member
The point is that you are thinking that "certain commands" are separate from "the whole program". Its all one program.

If you pause somewhere, you are pausing everywhere.

You can split your pause and interleave it amongst "certain commands", but we can't read your mind.

Several folks have asked you to provide more information. Now here's one more ...
 

TTOP

New Member
Did you see/read posts 8 and 9 ? (no response to either)

See PICAXE Manual 1 page 63 to 64.

With an M2 PICAXE part using multi-tasking when there a pause in one process operation immediately recognises that nothing is currently happening in that task and moves on to the next task.
I will study that multi task option.

inc W1
inc W2
inc W3
if W1 = whatever value = 500 ms then toggle c.0 endif
if W1 = whatever value = 500ms then W1 = 0 endif
if W2 = whatever value = 5 seconds then toggle c.1 endif
if W2 = whatever value = 5 seconds then W2 = 0 endif
if W3 = whatever value = 10 seconds then toggle c.2 endif
if W3 = whatever value = 10 seconds then W3= 0 endif
 

westaust55

Moderator
Seeing you post above, some further possibilities for the longer times and depending upon the accuracy you need:

IF you have an M2 part (multitasking capable) then consider the pre-defined system variable "time"
IF you have an X1 or X2 part then consider the pre-defined system variable "timer" (in conjunction with the SETTIMER command.


There have been some relatively recent threads about the time/timer variable and the effect of running at higher clock speeds.
Running at twice default speed may result in a time interval of 500 ms rather than 1 second.

EDIT:
One such thread here: http://www.picaxeforum.co.uk/showthread.php?27057-Time-variable-at-m1-and-lower-frequencies&highlight=time
But with and M2 part looking here: http://www.picaxe.com/BASIC-Commands/Time-Delays/time
seems that you would need to run at 32 MHz to get 0.5 sec duration between the timer variable incrementing which will conflict with multitasking which defaults to 16 MHz clock speed - so its one or the other.
 
Last edited:

TTOP

New Member
Seeing you post above, some further possibilities for the longer times and depending upon the accuracy you need:

IF you have an M2 part (multitasking capable) then consider the pre-defined system variable "time"
IF you have an X1 or X2 part then consider the pre-defined system variable "timer" (in conjunction with the SETTIMER command.


There have been some relatively recent threads about the time/timer variable and the effect of running at higher clock speeds.
Running at twice default speed may result in a time interval of 500 ms rather than 1 second.

EDIT:
One such thread here: http://www.picaxeforum.co.uk/showthread.php?27057-Time-variable-at-m1-and-lower-frequencies&highlight=time
But with and M2 part looking here: http://www.picaxe.com/BASIC-Commands/Time-Delays/time
seems that you would need to run at 32 MHz to get 0.5 sec duration between the timer variable incrementing which will conflict with multitasking which defaults to 16 MHz clock speed - so its one or the other.
very good west, I will look into those links. I'm thinking of monitoring inputs with READADC and when a certain voltage is detected it causes timers to begin, like a delay-on timer, but while that timer is counting down the inputs still need to always be monitored continuosly, when a pause is used it will delay-on but it will also pause the whole program, thats why I asked if part of the program could be paused, what I meant was could a part of the program be delayed while the rest of the program keeps continuosly monitors the READADC inputs. It looks like INC variables will work.
 

lbenson

Senior Member
It can depend on how accurate you need to be. Following the suggestion of westaust55 to run with "setfreq M32", this code catches every 20th value of the "time" variable, toggling an led on c.1 pretty close to every 10 seconds (tested live on an 08M2):
Code:
#picaxe 08M2
#terminal 38400

setfreq M32

symbol lastTime = b12

high c.1
pause 2000
do
  if time <> lastTime then
    b13 = time // 20
    if b13 = 0 then
      lastTime = time
      toggle c.1
'      sertxd("!")
    endif
  endif
loop
With that, "time" is a free-running half-second timer. To make something happen in, say, 20 seconds, you can then say "firstEvent = time + 40" and then "if time >= firstEvent then ' do something", and so on for as many events as you like. So
Code:
#terminal 38400

setfreq M32

symbol lastTime = b12
symbol firstEventTime = w7
symbol secondEventTime = w8

high c.1
pause 2000
firstEventTime = time + 20 ' happens in 10 seconds
secondEventTime = time + 30 ' happens in 15 seconds

do
  if time >= firstEventTime and firstEventTime <> $ffff then
    ' do something for first event
    firstEventTime = time + 20 ' happens in another 10 seconds
  endif
  if time >= secondEventTime and secondEventTime <> $ffff then
    ' do something for second event
    secondEventTime = $ffff ' won't happen again unless reset
  endif
  ' do other stuff
loop
This will execute the first event every 10 seconds, and the second event after 15 seconds, but then not again unless you reset secondEventTime somewhere else later.

Note that "time" will overflow to 0 about 4 times a day (at a half-second per tick), so if that is a problem, then you will need to reset "time" before it overflows, and reset any active event timers. Note also that some commands will throw off the timer.
 

luisss

New Member
Hi the picaxe manual 2 explains you can use pause comand for max 65 sec, for more time you can use a loop of "n" events to obtain the required time, this is an example to obtain timings of 1 hour on/off for a thermostat.

for b3=1 to 2

if b3=1 then high 1
end if

if b3=2 then low 0,1
end if

for b4=1 to 239
pause 15000
readtemp 7,T
readadc 0,H
let H=H-41*100/158

if H<35 and b3=1 then high 0
end if

if H>50 and b3=1 then low 0
end if

next b4

next b3

goto main
 
Top