Possible causes for halting SPIN code execution
idbruce
Posts: 6,197
Hello Everyone
I have a program that is halting execution for some inexplicable reason. What are some of the causes that will halt SPIN code execution?
Will inadequate stack space for one cog stop all SPIN code execution, or would it just affect that single cog?
Just to start any possible list that may result from this post, I will post the most obvious as #1
I have a program that is halting execution for some inexplicable reason. What are some of the causes that will halt SPIN code execution?
Will inadequate stack space for one cog stop all SPIN code execution, or would it just affect that single cog?
Just to start any possible list that may result from this post, I will post the most obvious as #1
- Loss of power
Comments
3. Flawed algorithm
(not to imply that these are your problems, but it's usually what it turns out for with me)
Paul
Until I realised that a variable I was using was only byte sized and it needed to be long sized to be used for TRUE or FALSE comparisons.
I had a bad cogstop in the Stop method of an object. The first thing the Start method did was call Stop in case a cog was already being used (pretty standard process). But, unfortunately the cogstop command in Stop was always stopping cog 0 (essentially because of a typo).
So every time I tried to initialize this new cog, I was stopping the one interpreting my main routine.
Things are or are not inside IF statements or REPEAT loops when they should not be or should be.
AND or OR statements are wrong.
Greater than or less than statements are in a range different than intended.
Integers are used when you really meant to use decimal numbers, especially when comparisons are made between numbers.
Just tossing those out there.
This is all good information. Keep the ideas coming.
Infinite loop
Overwriting a main RAM value used elsewhere
Using a pointer as a value or a value as a pointer
Bad or unexpected input values
Code is waiting for an input from its author, but its author needs more coffee and forgot to hit the ENTER key.
Hope my explanation gives you insight to my thoughts.
Paul
On EDIT:
I know you have had issues in the past with posting your code for proprietary reasons but it may help to have someone else look at your code. Perhaps there is someone you trust that you could share your code with privately.
This is not quite my problem, but close. I have not figured it out completely, but I have narrowed the problem down to two functions which perform sensor readings. And the two functions have worked perfectly in the past. So I am assuming that the problem is due to a recent alteration.
Here is the situation. On my wire bending CNC, I have a bending head which is constructed from 1/2" steel rod and two hardened 1/6" dowel pins pressed into to the top of the steel rod. One dowel pin is the center pin, and the other is the bending pin. To quickly and accurately position the bending head for CW and CCW bends, I have painted the entire bending head flat black except for a small stripe adjacent to and parellel to the bending pin, and I am using two QRB1114 reflective object sensors to achieve the proper CW or CCW positioning with the following code.
However, during a recent alteration, the diameter of the bending head was reduced by approximately 1/16", and I have not altered sensor placement to compensate for the change. I am assuming this is the problem. However, in the past, improper sensor placement either caused the bending head to spin continuously or just stop at improper locations. I never had these functions just stop program execution before.
Anyhow, I appreciate all the comments. It is a good subject with good input for troubleshooting. I hope the input keeps coming.
Bruce
EDIT: Additionally, I have also recently altered the MIN_SPEED constant value. This could also be part of the problem.
Any chance that the small change in geometry has effected a reflection you did not intend? Could the light source be hitting the flat black at such a raking angle that it is glancing off, bouncing around, hitting reflective metal parts and messing up the measurement? The QRB is in IR, and flat black paint might look black in the visible spectrum but be more reflective than you think in IR.
Just a thought.
I would say the geometry change may have affected it. If I move each sensor 1/32" closer to the bending head to compensate for the 1/16" diameter change, it may work perfectly again. But I also suspect the MIN_SPEED constant alteration.
It works perfectly or it halts program execution. Whatever it is, it is right at the borderline.
EDIT: I ran your loop under SpinSim, and it takes about 2500 cycles per loop. So CounterOffset should not be allowed to get below this. A minimum value of 3000 should be safe to use.
A very useful debugging tool is the ability to track the progression of your code as it runs. You can debug messages to the console for this purpose, or, if your application uses the PC connection for other use, you can use a simple LCD display. But you can use these tools to track the entry (and exit) points into the various routines. When the program stops, you will know where it stopped and narrow your search down to that area. At that point you can focus on displaying the status of variables in that method to see if something if ending up outside of nromal range.
Both of those functions should read
I believe you hit the nail on the head. I have not tried that fix yet, but that is definitely a typo and programming error. Good catch!
Bruce
except that for showing the execution-progress you add
a variable and change the value depending on the executed part of the code
if .....
DebugVar := 1
case ....
DebugVar := 2
do xyz..
DebugVar := 3
repeat .....
DebugVar := DebugVar +1
etc.
best regards
Stefan
Bruce