Shop OBEX P1 Docs P2 Docs Learn Events
Condition Evaluation — Parallax Forums

Condition Evaluation

btutorbtutor Posts: 7
edited 2009-02-27 15:55 in BASIC Stamp
I'm sure this is a noob question but I can't seem to figure it out.

Why does this UNTIL evaluate as TRUE on the 1st iteration:

PhotoDelta               CON  100     ' Difference required between light readings

HIGH 7                                                     ' Turn on LED
servo = 0                                                  
HIGH 6                                                     ' Charge cap
PAUSE 100
RCTIME 6, 1, lastPhotoTime                                 ' Read discharge time
DEBUG "lastPhotoTime = ", DEC lastPhotoTime, CR
photoTime = lastPhotoTime                                  ' Init var
DO
  lastPhotoTime = photoTime                                ' Keep last reading
  servoPos = Servo0Up                                      
  SEROUT PSCSerial, PSCBaud+$8000,[noparse][[/noparse]"!SC", servo, Ramp, servoPos.LOWBYTE, servoPos.HIGHBYTE, CR]
  PAUSE ValveOpenTime
  servoPos = Servo0Dw
  SEROUT PSCSerial, PSCBaud+$8000,[noparse][[/noparse]"!SC", servo, Ramp, servoPos.LOWBYTE, servoPos.HIGHBYTE, CR]
  PAUSE PixelPause
  HIGH 6                                                   ' Charge cap
  PAUSE 100
  RCTIME 6, 1, photoTime                                   ' Read discharge time
  DEBUG "photoTime = ", DEC photoTime, CR
  DEBUG "sub = ", SDEC (photoTime - lastPhotoTime), CR
  DEBUG "PhotoDelta = ", DEC PhotoDelta, CR
[color=red][b]LOOP UNTIL photoTime - lastPhotoTime > PhotoDelta[/b][/color]      
LOW 7                                                      ' Turn off LED

DEBUG "photo reached delta", CR
STOP

This is the DEBUG output:

lastPhotoTime = 220
photoTime = 210
sub = -10
PhotoDelta = 100
photo reached delta

Comments

  • TWRackersTWRackers Posts: 33
    edited 2009-02-27 15:55
    According to the BASIC Stamp Manual, "all comparisons are performed using unsigned, 16-bit math" (emphasis mine).· So you can't compare negative with positive values and get what you'd expect.· Try rewriting your comparison as

    LOOP UNTIL photoTime > PhotoDelta + lastPhotoTime
    

    Post Edited (TWRackers) : 2/27/2009 4:03:05 PM GMT
Sign In or Register to comment.