PDA

View Full Version : sometimes skips code



rasplund
- 5th September 2006, 03:18
settle:


gosub A_to_D
high yellow_l : high yellow_r
if amp < 14 or amp > 18 then pause 500
if amp < 14 or amp > 18 then settle
if amp > 14 and amp < 18 then pause 7000
gosub A_to_D
if amp < 14 or amp > 18 then settle
if amp > 14 and amp < 18 then low yellow_l : low yellow_r : ampon = 0

the PIC16F877 is waiting for the amp value to settle. sometimes this code works..sometimes it appears to skip line 6 (no delay) and line 9 (outputs are not set low). Any one have any suggestions??

Melanie
- 5th September 2006, 11:21
The first observation is that for example if amp=14 then it doesn't meet any criteria.

The second is I always try to put multiple conditional statements within parenthesis... sometimes, (certainly on early PBP compilers) multiple conditions were not actioned in what I considered a logical fashion, so rather than...

if amp < 14 or amp > 18 then pause 500

...I chose to write...

if (amp < 14) or (amp > 18) then pause 500

...then there's no ambiguity as to what conditions are tested against what other conditions.

rasplund
- 5th September 2006, 12:44
Thank you Melonie. I have been staring at this code for so long and I have missed the obvious....defining actions for the values 14 and 18 fixed it.

sayzer
- 5th September 2006, 13:44
Hi rasplund,

How did you get this work ?
if amp > 14 and amp < 18 then low yellow_l : low yellow_r : ampon = 0

In my compiler, ":" does not work with IF statement on the same line, and also there is no ENDIF.

So this code should do the following.



IF (amp > 14) and (amp < 18) then
low yellow_l
ENDIF

low yellow_r
ampon = 0



In this case,
low yellow_r and ampon = 0 will work free of the IF statement.

Was it what you needed or you needed these two inside the IF statement?





____________________________________