Shop OBEX P1 Docs P2 Docs Learn Events
FOR LOOPs for delays instead of PAUSEs — Parallax Forums

FOR LOOPs for delays instead of PAUSEs

ArchiverArchiver Posts: 46,084
edited 2001-11-26 01:44 in General Discussion
Hi all,
I am interested in using FOR loops instead of pauses so my program
can do other things while it waits (or delays) such as poll for user
input. I went to Tracy's site and found out some execution times for
various for-loops. I just want to know how I can make use of those
statistics. Any help would be appreciated. Of course, I understand
that the actual delay time depends on the program nested in the for
loops. I just want to know a "ball park" way of creating for loops to
give the delay I want.

Thanks,
RP


for i = 1 TO 1 : next
[noparse][[/noparse]825]
.
330
.

for i = 1 TO 2 : next
[noparse][[/noparse]1582]
.
.
.

for i = 1 to 10 : next
[noparse][[/noparse]7691]
.
.
.

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2001-11-25 22:58
    RP -

    I used a hybrid of looping and pausing for an
    industrial controller. While moving through a timed
    recipe, a loop would call a subroutine to check for
    remote stop signal, call another subroutine to check
    for a interlocked status signal, increment a counter,
    check if time is up, then pause for something like 248
    milliseconds. Time was up when 4x the desired number
    of seconds was in the counter. Stopwatch testing over
    a 60-second step indicated whether the operand given
    to PAUSE needed to increase (to a max of 250, or 1/4
    second) or decrease (to accomodate execution time for
    the subroutines, counter increment, and if statement).


    One good thing about this was that the PAUSE command,
    usually limited to 65.535 seconds, could reach 4 1/2
    hours by using a WORD counter and a BYTE operand, the
    latter for a 1/4 second pause.

    One drawback: I am only paying attention to critical
    inputs every 1/4 second. This was okay for a project
    that is looking for an input state, but may not be if
    a momentary button press must be monitored. Changing
    from 1/4 seconds, where the PAUSE operand is less than
    250, to 1/10ths (100 ms), 1/20ths (50 ms), or 1/50ths
    (20 ms), say, makes exact timing on a larger scale
    less easily achievable.

    Bob Pence



    --- rpsu279@y... wrote:
    > Hi all,
    > I am interested in using FOR loops instead of pauses
    > so my program
    > can do other things while it waits (or delays) such
    > as poll for user
    > input. I went to Tracy's site and found out some
    > execution times for
    > various for-loops. I just want to know how I can
    > make use of those
    > statistics. Any help would be appreciated. Of
    > course, I understand
    > that the actual delay time depends on the program
    > nested in the for
    > loops. I just want to know a "ball park" way of
    > creating for loops to
    > give the delay I want.
    >
    > Thanks,
    > RP
    >
    >
    > for i = 1 TO 1 : next
    > [noparse][[/noparse]825]
    > .
    > 330
    > .
    >
    > for i = 1 TO 2 : next
    > [noparse][[/noparse]1582]
    > .
    > .
    > .
    >
    > for i = 1 to 10 : next
    > [noparse][[/noparse]7691]
    > .
    > .
    > .
    >
    >
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed.
    > Text in the Subject and Body of the message will be
    > ignored.
    >
    >
    > Your use of Yahoo! Groups is subject to
    > http://docs.yahoo.com/info/terms/
    >
    >


    __________________________________________________
    Do You Yahoo!?
    Yahoo! GeoCities - quick and easy web site hosting, just $8.95/month.
    http://geocities.yahoo.com/ps/info1
  • ArchiverArchiver Posts: 46,084
    edited 2001-11-26 01:44
    >Hi all,
    >I am interested in using FOR loops instead of pauses so my program
    >can do other things while it waits (or delays) such as poll for user
    >input. I went to Tracy's site and found out some execution times for
    >various for-loops. I just want to know how I can make use of those
    >statistics. Any help would be appreciated. Of course, I understand
    >that the actual delay time depends on the program nested in the for
    >loops. I just want to know a "ball park" way of creating for loops to
    >give the delay I want.
    >
    >Thanks,
    >RP

    It can be quite a chore to get exact timing if you are really down to
    the wire on speed. However, if the program is just waiting for user
    input and has to do a couple of quick tasks in the meantime,it can be
    paced with short pauses or NAPs.

    loop:
    ' check user input
    ' check machine status
    ' update outputs
    pause 48
    goto loop

    If the tasks take 2 milliseconds, then the 48 milliseconds makes the
    total time add up to 50, which is usually fast enough to respond to
    user input. If you need to run the loop in a more precise time
    interval, you need to be more picky about counting the microseconds.

    -- Tracy
Sign In or Register to comment.