I know this sounds as crazy as the day is long, but I’m having difficulty figuring out why the “<” less-than operator isn’t working in my IF statement. Somehow, it always returns TRUE.
“chDat”, “rVal”, “tmp”, etc. are all type INT.
chDat = analogRead(A6);
rVal = ReadEEWord(cfgRulesVal);
tmp = rVal / 20; // set "about" to 10% up/down (5% either way)
switch (rChan >> 6) // returns 0-3; rChan is a CHAR (byte)
{
case 1: if (chDat < rVal) goto Trap; // LESS THAN
case 2: if ((chDat > (rVal - tmp)) && (chDat < (rVal + tmp))) goto Trap; // ABOUT
case 3: if (chDat > rVal) goto Trap; // MORE THAN
}
// 4: If we got here, the condition does not match.
continue; // Jump to the next iteration of the FOR{}
// 4: Condition matches
Trap: {...}
The “more than” works perfectly, as does the first half of “about.” BUT…if “less than” is specified, execution always jumps to Trap: regardless of the input value. I don’t need BREAKs on the SWITCH, as the GOTO pretty much takes care of that. (Yes, harp on me about using GOTO all you want…but AFAIK, that’s not the problem!)
As in:
condition LESS THAN: chDat = 501, rVal = 58 -> Trap (Condition TRUE)?!?!?!
condition LESS THAN: chDat = 0, rVal = 58 -> Trap (TRUE)
(There’s no way to make this condition return false)
condition ABOUT: chDat = 0, rVal = 2984 -> continue (FALSE)
condition ABOUT: chDat = 2888, rVal = 2984 -> Trap (TRUE)
condition ABOUT: chDat = 4096, rVal = 2984 -> Trap (TRUE)!?!??!?!
MORE THAN works as expected:
condition MORE THAN: chDat = 2986, rVal = 3686 -> continue (FALSE)
condition MORE THAN: chDat = 4032, rVal = 3686 -> Trap (TRUE)
What in the world is going on? Is it my code, or a seemingly impossible bug in the Core firmware? All my FOR{var, var < 45; var++} loops are working correctly, so I'm really confused.


)