Shop OBEX P1 Docs P2 Docs Learn Events
running a loop for 10 seconds — Parallax Forums

running a loop for 10 seconds

ArchiverArchiver Posts: 46,084
edited 2004-03-01 19:00 in General Discussion
I've got a simple loop that's looking for an active-high pushbutton
signal on 3 input pins:

firstloop:
IF IN1 = 1 THEN alpha
IF IN2 = 1 THEN bravo
IF IN3 = 1 THEN charlie
GOTO firstloop

When the stamp program is executed, I want to run this loop for 10
seconds, and then switch to a separate subroutine.

How can I make the loop above execute for only 10 seconds? I don't
want to add a pause at the end of each loop in case the momentary
button input happens during that pause. I've thought about using a
FOR-NEXT loop, but that only counts interations of cycles and not time
duration, correct? Any suggestions?

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2004-02-29 22:44
    In a message dated 2/29/2004 5:27:09 PM Eastern Standard Time,
    andywatson@m... writes:


    > firstloop:
    > IF IN1 = 1 THEN alpha
    > IF IN2 = 1 THEN bravo
    > IF IN3 = 1 THEN charlie
    > GOTO firstloop
    >
    > When the stamp program is executed, I want to run this loop for 10
    > seconds, and then switch to a separate subroutine.
    >
    > How can I make the loop above execute for only 10 seconds? I don't
    > want to add a pause at the end of each loop in case the momentary
    > button input happens during that pause. I've thought about using a
    > FOR-NEXT loop, but that only counts interations of cycles and not time
    > duration, correct? Any suggestions?
    >

    A Stamp executes 4000 instruction per second - 10 seconds = 40000
    instructions. So try this:

    x = 0
    loop1
    .....
    ....
    ....
    x = x + 1
    if x = 10000 then go somewhere else
    goto loop1

    You might have to adjust the 10000 value for x, but that should be pretty
    close.



    Sid Weaver
    W4EKQ
    Port Richey, FL


    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2004-02-29 23:26
    Put a short pad and counter in your loop like this:

    DO
    IF IN1 = 1 THEN Alpha
    IF IN2 = 1 THEN Bravo
    IF IN3 = 1 THEN Charlie
    PAUSE 25
    timer = timer + 1
    IF (timer >= 400) THEN EXIT
    LOOP
    GOTO Main

    -- Jon Williams
    -- Parallax


    Original Message
    From: andy_watson5 [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=bKD06DPLDkIMDdXhoocouxQUi5218xsu47XlfOltg-QBQbsxbhjqZZ5gCYW_uLujNsYLNQLXKGIfnA]andywatson@m...[/url
    Sent: Sunday, February 29, 2004 4:25 PM
    To: basicstamps@yahoogroups.com
    Subject: [noparse][[/noparse]basicstamps] running a loop for 10 seconds


    I've got a simple loop that's looking for an active-high pushbutton
    signal on 3 input pins:

    firstloop:
    IF IN1 = 1 THEN alpha
    IF IN2 = 1 THEN bravo
    IF IN3 = 1 THEN charlie
    GOTO firstloop

    When the stamp program is executed, I want to run this loop for 10
    seconds, and then switch to a separate subroutine.

    How can I make the loop above execute for only 10 seconds? I don't want
    to add a pause at the end of each loop in case the momentary button
    input happens during that pause. I've thought about using a FOR-NEXT
    loop, but that only counts interations of cycles and not time duration,
    correct? Any suggestions?
  • ArchiverArchiver Posts: 46,084
    edited 2004-03-01 03:05
    >
    > A Stamp executes 4000 instruction per second - 10 seconds = 40000
    > instructions.

    Is that rate the same for all stamp models? I thought I remembered
    seeing a table listing the rate for command executions for each of the
    stamp models, but I can't seem to find that table now.
  • ArchiverArchiver Posts: 46,084
    edited 2004-03-01 13:40
    In a message dated 2/29/2004 10:05:52 PM Eastern Standard Time,
    andywatson@m... writes:


    > > A Stamp executes 4000 instruction per second - 10 seconds = 40000
    > > instructions.
    >
    > Is that rate the same for all stamp models? I thought I remembered
    > seeing a table listing the rate for command executions for each of the
    > stamp models, but I can't seem to find that table now.
    >
    >

    That is for a BS2, and I think a BS2E. Go toe the Paarallax site, under
    Stamps, and look at the comparison table. The fastest is the BS2P at 12000 per
    sec. If you are using something other than a BS2 just adjust the 10000
    accordingly.

    Sid


    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2004-03-01 14:44
    Ah, yes. That's where I saw it. Thanks for pointing me in the right
    direction. I've read so much documentation lately that I can't
    always remember where I find stuff.

    I will have to say that I think Parallax does a superb job of making
    documentation available online. It's rare to find a company these
    days that goes the extra mile when providing product support.

    --- In basicstamps@yahoogroups.com, Newzed@a... wrote:
    > In a message dated 2/29/2004 10:05:52 PM Eastern Standard Time,
    > andywatson@m... writes:
    >
    >
    > > > A Stamp executes 4000 instruction per second - 10 seconds =
    40000
    > > > instructions.
    > >
    > > Is that rate the same for all stamp models? I thought I
    remembered
    > > seeing a table listing the rate for command executions for each
    of the
    > > stamp models, but I can't seem to find that table now.
    > >
    > >
    >
    > That is for a BS2, and I think a BS2E. Go toe the Paarallax site,
    under
    > Stamps, and look at the comparison table. The fastest is the BS2P
    at 12000 per
    > sec. If you are using something other than a BS2 just adjust the
    10000
    > accordingly.
    >
    > Sid
    >
    >
    > [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2004-03-01 19:00
    In more detail, each Stamp instruction takes a different amount of
    time. You might find this breakdown informative:

    http://www.emesystems.com/BS2speed.htm

    -- Tracy


    >--- In basicstamps@yahoogroups.com, Newzed@a... wrote:
    >> In a message dated 2/29/2004 10:05:52 PM Eastern Standard Time,
    >> andywatson@m... writes:
    >>
    >>
    >> > > A Stamp executes 4000 instruction per second - 10 seconds =
    >40000
    >> > > instructions.
    > > >
    >> > Is that rate the same for all stamp models? I thought I
    >remembered
    >> > seeing a table listing the rate for command executions for each
    >of the
    >> > stamp models, but I can't seem to find that table now.
    > > >
    >> >
    >>
    >> That is for a BS2, and I think a BS2E. Go toe the Paarallax site,
    >under
    >> Stamps, and look at the comparison table. The fastest is the BS2P
    >at 12000 per
    >> sec. If you are using something other than a BS2 just adjust the
    >10000
    >> accordingly.
    >>
    >
    > > Sid
Sign In or Register to comment.