Repeat problem...
jvrproductions
Posts: 61
Hello and thank for any help. I have the following code. The problem is that for some reason went current its = to target i want outa 3 and 4 to go off wait 60 seconds and next outa 5 need to go off. but instead the program wait about 6 sec and put off all at the same time...
Thanks
if ac == 2 if current > target repeat 1 outa[5] := %1 ' fan on outa[4] := %0 waitcnt (clkfreq * 20 + cnt) outa[3] := %1 ' a/c on elseif current == target repeat 1 outa[3] := %0 outa[4] := %0 waitcnt (clkfreq * 60 + cnt) outa[5] := %0 elseif current < target outa[5] := %0 outa[3] := %0 outa[4] := %0
Thanks
Comments
From the Prop manual, page 219 version 1.1:
IMPORTANT: Since WAITCNT pauses the cog until the System Counter matches the given value, care must be taken to ensure that the given value was not already surpassed by the System Counter. If the System Counter already passed the given value before the wait hardware activated then the cog will appear to have halted permanently when, in fact, it is waiting for the counter to exceed 32 bits and wrap around to the given value. Even at 80 MHz, it takes over 53 seconds for the 32-bit System Counter to wrap around!
In a sense, I think you're encountering something like the opposite of what that warning pertains to. You're hitting that system clock value before the 53 seconds wrap around has happened.
You're using too large a wait period. You could break it into two 30 second waits or you could use one of the clock objects to keep track of time. (I personally think two waits would be easier in this case.)
repeat 1
;o)
If you have more than one time where you need to wait > 53 seconds you could create a function which waits for seconds:
Can current jump past the target value? I'm just noticing that 3 through 5 all get turned off at the same time if "current < target".
Could the problem be in a different area of code? (i.e. where the value of current is set)
Are the values of current and target in integer form? Sometimes people forget that the > and < operators only work for integers and they try to do comparisons with real numbers, etc.
[video=youtube_share;toYoGafc-lA]
...when
... is so much more obvious -- and doesn't require comments. CONstants are your friends!
Here's a stab at reformatting your method to make it more readable -- without constant names as I don't know what all pins do.