Shop OBEX P1 Docs P2 Docs Learn Events
Calculated timeout from repeat loop — Parallax Forums

Calculated timeout from repeat loop

average joeaverage joe Posts: 795
edited 2013-09-09 22:36 in Propeller 1
I'm a bit lost on the best way to handle a timeout from a repeat loop. Basically, I'd like to repeat until a condition is true, or a timeout period has elapsed. My trouble is handling a clock wraparound.

Example :
PRI GetMark | tout
  tout := _syncTimeout
  tout += cnt
  repeat
    RX(@d)  
  until GetPacketType == _mark  or (cnt > tout)

This will work perfectly fine, as long as cnt + _syncTimeout is less than $7FFF_FFFF. If not, it causes tout to be evaluated improperly. I've been thinking about the best way to do this and still drawing a blank. Any help would be greatly appreciated as always!

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2013-09-09 22:31
    Provided your timeout stays in range (e.g. ~27sec @80MHz) this should do. Just make sure you compare against the delta, never absolute values.
    PRI GetMark | tout
      tout := cnt
      repeat
        RX(@d)  
      until GetPacketType == _mark  or ((cnt - tout) > _syncTimeout)
    
  • average joeaverage joe Posts: 795
    edited 2013-09-09 22:32
    I knew there was an easy way to handle it, just couldn't think how. Thanks again. I owe ya big time ;)
  • JonnyMacJonnyMac Posts: 9,107
    edited 2013-09-09 22:36
    This is just re-arranging terms... how I tend to do it (with butt-obvious code).
    t0 := -cnt
      repeat
        ' do something
        elapsed := t0 + cnt
        if (elapsed => TIME_OUT)
          return TO_CODE
    
Sign In or Register to comment.