Timing in SPIN
K2
Posts: 693
The following code snippet is obviously flawed. How is this fixed in SPIN without using something clunky like WAITCNT, that doesn't let the cog do anything else until the timed interval is up?
temp := 10_000_000 + cnt
repeat
if cnt => temp
temp += 10_000_000
(do stuff)
(do other stuff)

Comments
The correct way is to compare a difference, as in
if cnt - temp >= 0 'do stuffThis will work so long as the delay is less than 2^31