Yup. I can't see bad GOSUB structure, nothing that stands out anyways.
The STATE can evolve from 0 to 3 in a single pass of that SELECT CASE. I can only assume the readings from your hardware makes it jump unexpectedly.
Are you able to debug in real time and step thru your code?
It's about the only way I can think of the visualize what is going on. I see you dump a lot of information but I'm unable to follow that manually through your logic.
I prefer to dump like this:
MAIN --------------------------------------------------
STEP 1, list of variables.
SUBROUTINE XYZ ----------------------------------------
STEP 1, list of variables.
STEP 2, list of variables.
SUBROUTINE ABC ----------------------------------------
STEP 1, list of variables.
...etc...
I find it easier to follow in the code this way. I place the STEPS in relevant places, like before & after IFs, etc.
Robert





Bookmarks