Shop OBEX P1 Docs P2 Docs Learn Events
Repeat until command? — Parallax Forums

Repeat until command?

GrantmcFGrantmcF Posts: 30
edited 2012-09-12 21:23 in Propeller 1
I am trying to run a pump for a set amount of time without slowing down the main program. I am starting the the pump in a new cog and trying to run it for 4 minutes. I can only get the pump to come on if I don't use the until command. Am I configuring it wrong or is there a better way to do this? The display functions are just to verify that a new cog was started and are not necessary to the final code. Yes I know about indents but the auto correct keeps taking them out.

Var

Long Relay_cog
Long Relay_Stack[32]


OBJ
Lcd : "Debug_Lcd"

Lcd.init(Lcd_Pin, 19200,4)
Relay_cog := cognew( Prewet2,@ Relay_Stack)+1
Lcd.cls
Lcd.decx(Relay_cog,2)
cogstop(Relay_cog~ -1)

Pub Prewet2

repeat until (clkfreq*240 + cnt)
Dira[13..15] :=1 'Sets direction of pins 13-15 to output
outa[13..15] :=0 'Sets pin 13 high and pins 14 and 15 low

Comments

  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-09-12 19:28
    You need a condition with your "until" statement.

    As it is written now your loop will always stop whenever "(clkfreq*240 + cnt)" isn't zero (which is almost all the time).

    You also need to keep in mind the "cnt" rolls over in less than one minute.

    I'd suggest keeping track of how many seconds pass and check the number of seconds against 240.

    It would also help if you used code blocks when posting code. Here's a link to Phil's tutorial on how to use them.

    attachment.php?attachmentid=78421&d=1297987572
  • AribaAriba Posts: 2,690
    edited 2012-09-12 20:49
    You can do something like that to wait 4 minutes (240 seconds):
      repeat 240                 ' wait 4 minutes
        waitcnt(clkfreq + cnt)   ' wait 1 second
    
    It will not be 100% exact because of the additional time the loop instructions need, but the error will be only some hundert microseconds.

    Andy
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-09-12 21:23
    You can make it more accurate this way:
    time := cnt
    repeat 240
      waitcnt(time += clkfreq)
    

    -Phil
Sign In or Register to comment.