DO LOOP problem driving me mad!

I hope this is trivial, but I've been trying for a whole day now to discover why something's not happening and have tracked it down eventually to a bit variable getting set when I'm not expecting it to.

The much abbreviated code is:
Code:
IF fwd_thrtl = 1 THEN ; the throttle has been moved into the forward position. 
		;
		DO UNTIL Fwd_pb = 1 OR fwd_thrtl = 0
			GOSUB eval_jystk  	; update throttle position in case
						; it's returned to centre
		LOOP
		;
		stp_state = 0
		GOTO jsf_active   		; enter the jsf_active loop
	ENDIF
Using SERTXD (thanks to whoever suggested that recently) I can see that the bit variable "stp_state" = 1 until the program comes into this section when fwd_thrtl = 1.

While the program stays in the DO UNTIL loop, stp_state should still be 1, but it seems to get set to 0 which results in things not happening when they should. It appears therefore that the code outside the DO LOOP is being executed at least once.

Does anyone know if this is this possible please? Or have I made a mistake somewhere else (quite possible!)?
 

hippy

Technical Support
Staff member
While the program stays in the DO UNTIL loop, stp_state should still be 1, but it seems to get set to 0 which results in things not happening when they should.
That can only mean that something is changing 'stp_state' or, as it's a bit variable, something is changing the 'b' or 'w' variable it is a part of.

That would be occurring in the 'eval_jystk' routine, or perhaps in an interrupt if you have one enabled.

You could put a SERTXD of 'stp_state' before the 'GOSUB eval_jystk; and have one after to check that the variable state is changing within that. Then you can add SERTXD in your 'eval_jystk' routine to narrow it down if it's not obvious.

I tend to number my SERTXD and only have the last one emit CR,LF so it's easier to see what's happening ...

Code:
MySub:
  SerTxd( "{1}=", #stp_state )
  something = something_else
  SerTxd( "{2}=", #stp_state )
  something_else = something_more 
  SerTxd( "{3}=", #stp_state, CR, LF )
  Return
If it shows "{1}=1{2}=0{3}=0" there's a clash with 'something'. If it's "{1}=1{2}=1{3}=0" there's a clash with 'something_else'.

Not all problems will be immediately obvious. A clash with either 'something' or 'something_else' may result in 'stp_state' still being set to 1.
 
Brilliant!

Thanks Hippy, I hadn't thought to look in 'eval_jystk' which is indeed where it's getting set a bit prematurely (for other reasons) so I need to think how to do it to it a bit differently now.

Cheers.
 
Top