SPIN - repeat until loop
homosapien
Posts: 147
in Propeller 1
I am trying to write a 'repeat until' statement that will loop until either a) a logic condition is met or b) a certain amount of time has passed. I'm thinking something like:
waitTime := cnt + clkfreq/2 REPEAT UNTIL (x == 1) OR (cnt > waitTime)
'code to be done after either x==1 or 1/2 second has passed.
Checking the logic condition (x==1) is easy, checking if time has passed is somewhat more complicated due to the case where there is counter rollover between the current value of cnt and the calculated waitTime, and I do not have a lot of clock cycles in this method to spend figuring out if there was rollover (and actually dealing with it).
So now I'm thinking about using a counter that is started right before the REPEAT statement and checking when PHSA is greater than some number that will get me the delay. This will eliminate the rollover issue if I pick my timer type/frequency correctly. Someone must have been done this before (the repeat until logic condition OR timeout is met). Am I making this more complicated than it has to be?
Nate
waitTime := cnt + clkfreq/2 REPEAT UNTIL (x == 1) OR (cnt > waitTime)
'code to be done after either x==1 or 1/2 second has passed.
Checking the logic condition (x==1) is easy, checking if time has passed is somewhat more complicated due to the case where there is counter rollover between the current value of cnt and the calculated waitTime, and I do not have a lot of clock cycles in this method to spend figuring out if there was rollover (and actually dealing with it).
So now I'm thinking about using a counter that is started right before the REPEAT statement and checking when PHSA is greater than some number that will get me the delay. This will eliminate the rollover issue if I pick my timer type/frequency correctly. Someone must have been done this before (the repeat until logic condition OR timeout is met). Am I making this more complicated than it has to be?
Nate
Comments
-Phil
Nate