Stupid Do While question
Lone_husky
Posts: 13
I have a reasonably dumb question that I know is simple but for some reason I can't figure it out.
I have two conditions based on a light sensor that starts at a baseline value, decreases and then returns near that baseline.
1. a running differential that is positive when is goes below a certain threshold, aka, stops changing very much
2. a particular ratio that returns back near to a previous baseline
I want the program to detect either one of these conditions and then mark the time. I designed it this way because while the ratio returning to the previous baseline is more accurate, it sometimes never returns, based on some uncontrollable factors so I wanted an independent method that would trigger the conditional when the sensor output is not varying too much
so the following code is supposed to accomplish this, but I think I have my conditional statement fouled up and can't seem to make it so that either statement when true (or false) exists the Loop.
DO WHILE (diff > diff_min AND baseline < ratio)
GOSUB Acquire
GOSUB differential
LOOP
I think that the DO WHILE loop continues while the statement is true, so I thought the above code would work, because the conditional statement is only positive when both are positive and as soon as one become negative, the loop terminates and the program proceeds. Does this make sense????? Is there a better way to do this? Any help would be appreciated.
Thanks
-Vassilios
I have two conditions based on a light sensor that starts at a baseline value, decreases and then returns near that baseline.
1. a running differential that is positive when is goes below a certain threshold, aka, stops changing very much
2. a particular ratio that returns back near to a previous baseline
I want the program to detect either one of these conditions and then mark the time. I designed it this way because while the ratio returning to the previous baseline is more accurate, it sometimes never returns, based on some uncontrollable factors so I wanted an independent method that would trigger the conditional when the sensor output is not varying too much
so the following code is supposed to accomplish this, but I think I have my conditional statement fouled up and can't seem to make it so that either statement when true (or false) exists the Loop.
DO WHILE (diff > diff_min AND baseline < ratio)
GOSUB Acquire
GOSUB differential
LOOP
I think that the DO WHILE loop continues while the statement is true, so I thought the above code would work, because the conditional statement is only positive when both are positive and as soon as one become negative, the loop terminates and the program proceeds. Does this make sense????? Is there a better way to do this? Any help would be appreciated.
Thanks
-Vassilios
Comments
Your problem might be in your subroutines. You didn't post them So we may never now?
What I'm getting at is a little more info might help.
______________$WMc%_____
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The Truth is out there············································ BoogerWoods, FL. USA
DO WHILE (diff > diff_min AND devAddr < ratio)
GOSUB Acquire
GOSUB differential
LOOP
The subroutines are as follows
DEBUG DEC diff, TAB, DEC diff_min, TAB, DEC devAddr, TAB, DEC ratio,CR
That could help a lot to see why the condition is not met. The logic of the WHILE statement seems correct. That is, it will drop out of the loop when either condition is no longer true.
I see what you are doing in the acquire subroutine, but not in the differential subroutine. Average of 10 samples? It looks more like it is comparing the current ratio (smoothed) with the ratio two iterations before (also smoothed).
But to reiterate, please show us some DEBUG data with 4 fields. The something is off with the numbers.
The value of I has to stay within the limits of 0 to 64.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
DO
(commands)
LOOP WHILE (condition)
not DO WHILE.
Which one you use depends on if you want to run the code block before evaluating stuff.
Your way of code is a little different than the norm.This could be a compiler confused issue.What does Your Main look like?
____________$WMc%____________
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The Truth is out there············································ BoogerWoods, FL. USA