<= error

davidwf

Senior Member
Trying to use this simple function

.....other lines & checks
IF current_temp <=min_temp then: do something .............: endif
....other lines & checks

only proceeds if the current_temp is below min_temp, if it is = to then it doesn't do anything.

Have I missed the obvious ?

Thanks in advance
 

westaust55

Moderator
Which version of the Programming Editor are you using?

Is the problem seen in the PE simulator, in the actual PICAXE chip (which one) or both?


Edit:
I tried the code:
Code:
FOR b0 = 1 TO 7
  IF b0 <= 5 THEN
    SERTXD ("<= 5")
  ELSE
    SERTXD (">5")
  ENDIF
NEXT b0
in the PE simulator for 08M, 14M, 20M,18X, 28X1/40X1 and 28X2/40X2 and it worked correctly for each PICAXE type selected.

Can you post the actual program code you are using.
 
Last edited:

hippy

Ex-Staff (retired)
I've never known <= not to work so the additional information westaust55 asks for would be helpful, also what values are in 'current_temp' and 'min_temp' ?

Posting you complete code may help. Is it a case of dealing with negative numbers ( negative temperatures ) which are actually represented by positive values ?
 

davidwf

Senior Member
Thanks for the prompt replies......it is my good old fridge thermostat controller, code attached as requested, code in question is on lines 117 to 122.

I am using the latest programming software (5.2.10) and a picaxe 08m

I appreciate the code is a bit messy but it works well and I am not up to speed enough to tidy it up....like I said it does work correctly apart from the anomoly mentioned.
Code is set to switch the compressor on at 5.0 deg C but it doesn't happen until 5.1, likewise it should go off at 3.5 deg C but stays on until temp drops to 3.4.
I appreciate that I could change these settings but I am intrigued as to why it doesn't switch at the = temps.

Just had a thought....yes, it does happen sometimes....Could it be because the code in line 129 / 130 isn't working it out accurately enough perhaps ??

Thanks again
Dave F
 

Attachments

Last edited:

hippy

Ex-Staff (retired)
Code is set to switch the compressor on at 5.0 deg C but it doesn't happen until 5.1, likewise it should go off at 3.5 deg C but stays on until temp drops to 3.4.
I suspect it's a 'logic error', similar to "turn off when <= X" but implemented with "keep on when > X" but erroneously being written as "keep on when >= X" or something like that, and similar for the other conditional.

Best bet is to run it through the simulator, force the temps to be those which cause a problem and see where the code goes to and why.
 

westaust55

Moderator
David,

Firstly, not the problem but PE is now at V5.2.11 (not 5.2.10)

Secondly, you problem appears at fist glance to be in the lines you suspected.
Code:
 	IF current_temp >[B][COLOR="red"]=[/COLOR][/B]min_temp and current_temp <=max_temp then: high green_led: [B][COLOR="Blue"]goto main[/COLOR][/B]: endif	; temp is within limits, leave "as is"
 	IF current_temp <[COLOR="Red"]=[/COLOR]min_temp then: high green_led: goto compressor_off: endif; Temp is at or below cool_temp, turn compressor off
[code]

So on an equals ( [B][COLOR="Red"]=[/COLOR][/B] ) situation you go back to the label [B][COLOR="Blue"]Main:[/COLOR][/B]
and thus  will never reach the next line with the [B]<=[/B] test if current_temp = min_temp
 

SAborn

Senior Member
Dave F,

I would just like to say how nice it is to see your code using symbols for your variables.

It is something that is often lacking here, and i for one do enjoy reading code that makes some logical sense as you read through it.

Well done from that aspect.
 

davidwf

Senior Member
westaust55 :
Thanks for the tips - I am now at 5.2.11

I just edited line 121 and I "THINK" it is correct....


saborn :
thanks for the feedback....as a beginner ( :rolleyes:) I find it easier to follow and, to me at least, more logical to use variable names rather than meaningless symbols ....that way I have an idea what it should be doing.
Likewise listing all the available variables at the top of the program ensures that I don't use the same one twice un-intentionally......we call it "belt and braces" over here :)
 

Attachments

Last edited:
Top