Shop OBEX P1 Docs P2 Docs Learn Events
Timer — Parallax Forums

Timer

weizenheimer37weizenheimer37 Posts: 2
edited 2008-10-31 00:18 in BASIC Stamp
I am looking for a way to time out a command. I have my code waiting for IN4 to return true, and then continue on with my code. I want my code to be able to keep track of how long it waits for IN4 to return true, and move on to the future code if IN4 never returns true after a specified amount of time (about 6 seconds). Is there any way that I can do this? I am coding in pBasic 2.5, and using the BS2p Stamp. I just started working with this stuff a couple of weeks ago, and this is the one thing I have not been able to figure out. Any help would be awesome! Thanks.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-10-30 20:59
    The Stamps don't have a real time clock although some statements (like PAUSE or PULSOUT) have very accurate timing.

    The way this is often done is to test IN4. If false, the program pauses for some specific time (like 10ms), then checks again while keeping a count of the number of times the program has PAUSEd. When that count exceeds some value (like 600), the program has timed out and goes to do somethine else.

    timeOut var word
       timeOut = 0
    waitFor:
       if in4 = 1 then goto gotActivity
       timeOut = timeOut + 1
       pause 10
       if timeOut < 600 then goto waitFor
    timedOut:
    
    
  • weizenheimer37weizenheimer37 Posts: 2
    edited 2008-10-30 21:18
    Okay, I will try that. Thanks.
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2008-10-31 00:18
    weizenheimer37
    You can also try this demo as well I have used this a few time and works very well

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}


    Chg··· PIN··· 0
    cntr·· VAR··· Word


    · cntr = 0


    · DO
    ··· ' do other loop stuff
    ··· cntr = cntr + 1 * Chg············ 'If input stays HIGH· then EXIT
    ··· IF (cntr = 300) THEN EXIT·······' This controls for how long it looks at a input to see if it says true
    · LOOP



    ' With the BS2 you can have parenthesis in an expression so the (1 - Chg)
    ' part inverts that value.


    ·cntr = 0


    · DO
    ··· ' do other loop stuff
    ··· cntr = cntr + 1 * (1 - Chg)······· 'If input stays LOW then EXIT
    ··· IF (cntr = 300) THEN EXIT········ ' This controls for how long it looks at a input to see if it says true

    · LOOP

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam
Sign In or Register to comment.