Problems with MIN on PicAxe18 and 18X

robots42

New Member
I couldn't find anything on the forum about this, surely I can't be the only one!
I even just now uploade the latest Editor but doesn't make a difference.

On an 18 MIN is wrong and in fact does a MAX
On an 18X MIN is flakey

or is it my brains day off?

{The reason isn't in appendix 30459.642.a.345.f.g sub para 6.gfd.483.34.thu.76.bd is it?}

Code:
Editor 5.1.5
	Firmware version 2.3 (PICAXE-18 Firmware version 3)
        ---------------------------------------------------
	Min doesn't work, does a Max      40 min 20 =>40, 5 min 20 =>5


Editor 5.2.0
	Firmware version 2.3 (PICAXE-18 Firmware version 3)
	Firmware version 8.1 (PICAXE-18x Firmware version 1)
        ---------------------------------------------------
  Simulator
	bytevar =wordvar  /4 min 180        'doesn't work, min ignored

	bytevar =wordvar /4 
	bytevar =bytevar min 180	             'works

  Hardware
	Firmware version 2.3 (PICAXE-18 Firmware version 3)
        ---------------------------------------------------
	bytevar =bytevar min 20
	Min doesn't work, does a Max      40 min 20 =>40, 5 min 20 =>5

	Firmware version 8.1 (PICAXE-18x Firmware version 1)
        ---------------------------------------------------
	bytevar =wordvar /4 min 180	'doesn't work, min ignored

	bytevar =wordvar /4 
	bytevar =bytevar min 180	'works
David
 

BeanieBots

Moderator
Not sure what you expect it to do but it has always done what I expect it to do.

X Min Y will return X if it is bigger than Y but will never return a number smaller than Y.

It can get a little complex if MIN comes after a calculation which can result in a rollover.
eg b0=b0-10 MIN 5
if b0=12 then b0-10=2 so the result would be 5
if b0=8 then b0-10=254 so the result would be 254 and NOT the expected 5

EDIT:
Just noticed how old your 18X firmware is!
I have some 'old' 18Xs with 8.6 firmware. MIN & MAX work fine on them.

On both 18 and 28 the MIN/MAX functions were corrected at V5 firmware.
Not sure about the others.
 
Last edited:

westaust55

Moderator
MIN function

Are you trying to use the MIN function correctly?

It is not the same as the Minimum function in say MS Excel where it finds and uses the lowest value.

The MIN command is a limiting factor, which ensures that a value is never less than a preset value. In this example the value is never less than 50.
When the result of the division is less than 50 the min command limits the value to 50.

let b1 = 100 / b2 MIN 50
if b2 = 1 then b1 = 100
if b2 = 2 then b1 = 50
if b2 = 3 then b1 = 50 ‘ limited to 50​
Rev Ed / technical – please note for future corection that the word “division" is spelt wrong in the manual 2 bottom of page 20
 

BeanieBots

Moderator
Thanks westaust, that was actually a 'typo' on my part. I've corrected my post. Checking "firmware.txt" shows that robots42 probably has a genuine bug in that very early firmware version.
 

hippy

Ex-Staff (retired)
It has to be very old PICAXE firmware to have the MIN/MAX bug ( and I'm not exactly sure how that manifested itself ).

Most often it's more likely to be a misunderstanding as to what MIN and MAX do ( been there, done that, got the T-shirt ). They do not, as westaust55 says, work as finding the minimum or maximum of two values but are limiting functions; X MIN Y means regardless of X the result will never be below a minimum of Y, X MAX Y means regardless of X the result will never exceed a maximum of Y.

Rather confusingly X MIN Y delivers the maximum of the two values, X MAX Y delivers the minimum of the two values.
 
Top