"If "condition not working
realolman1
Posts: 55
I have a spin program that works
It contains a loop to increment seconds which works:
As soon as I add an "If" condition to the repeat loop, "sec" is always zero:
The "If" command is to compare the "sec" count to 60 for a minute passing.
MinuteHasPassed is a CON set to 60. I have tried making it a VAR and even tried comparing "sec" to 60 in the "If" command .
I have tried different indentations on the "IF" and in the "IF"
It seems that every time the "If" condition evaluates, it thinks "sec" is larger than or equal to what should be 60.
Either that, or it is only doing the repeat once, and never adding 1 to the "sec"
all I have to do is comment out the "If" command with its statements, and the "sec" increments properly
What I am trying to do is add a value to an array every 60 seconds. The code compiles and downloads to the propeller, and everything is happy... except me
What am I doing wrong?
Edit: I added another variable to the "repeat" loop that does not get modified anywhere, just incremented, and it works OK, ... so for some reason, it seems that the "If" statement is always true. I don't see how that could be possible.
I must have something wrong with the syntax of it. If the "If" is always true, ElapsedMinutes should be getting incremented, and it is not
It contains a loop to increment seconds which works:
Pub SecondTiming repeat waitcnt (clkfreq + cnt) ' one second wait sec:= sec +1 ' add one to seconds
As soon as I add an "If" condition to the repeat loop, "sec" is always zero:
Pub SecondTiming repeat waitcnt (clkfreq + cnt) ' one second wait sec:= sec +1 ' add one to seconds If sec >= MinuteHasPassed 'check second count against a minute AnalogRecord[ElapsedMinutes]:= value 'first iteration will be 0 sec:= 0 'reset seconds to 0 ElapsedMinutes:= ElapsedMinutes +1 'increment elapsed minutes
The "If" command is to compare the "sec" count to 60 for a minute passing.
MinuteHasPassed is a CON set to 60. I have tried making it a VAR and even tried comparing "sec" to 60 in the "If" command .
I have tried different indentations on the "IF" and in the "IF"
It seems that every time the "If" condition evaluates, it thinks "sec" is larger than or equal to what should be 60.
Either that, or it is only doing the repeat once, and never adding 1 to the "sec"
all I have to do is comment out the "If" command with its statements, and the "sec" increments properly
What I am trying to do is add a value to an array every 60 seconds. The code compiles and downloads to the propeller, and everything is happy... except me
What am I doing wrong?
Edit: I added another variable to the "repeat" loop that does not get modified anywhere, just incremented, and it works OK, ... so for some reason, it seems that the "If" statement is always true. I don't see how that could be possible.
I must have something wrong with the syntax of it. If the "If" is always true, ElapsedMinutes should be getting incremented, and it is not
Pub SecondTiming repeat waitcnt (clkfreq + cnt) ' one second wait sec:= sec +1 ' add one to seconds CountLoops :=CountLoops+1 'count loop iterations If sec >= MinuteHasPassed 'check second count against a minute AnalogRecord[ElapsedMinutes]:= value 'first iteration will be 0 sec:= 0 'reset seconds to 0 ElapsedMinutes:= ElapsedMinutes +1 'increment elapsed minutesThe problem here is: sec is always zero and so is ElapsedMinutes, but CountLoops increments... ???
Comments
thank you very much.
Only good thing that comes from being driven nuts about something like this is I bet I will never forget it.
Thank you
I will look it up
So long as your loop code comes in just under one second (to allow for other loop overhead), the loop will run exactly once per second.