Bug in the OSTC3 setting O2% in a gasmix from a computer

Anton Lundin glance at acc.umu.se
Wed Oct 15 16:57:07 PDT 2014


Hi.

I'm currently hacking on Subsurface, and more specific the code to
configure your OSTC3 from it.

I have seen some wierd problems with setting a O2% value from the
computer. Every O2 value in the range 21..99 works as it should, but i
can't set it to 100% or anything below 21%. In any of those case it
changes the O2 value to the default 21%. I've spent a fair amount of
time debugging Subsurface but as far as i can see everything there looks
as it should.

Then started to suspect a bug in the OSTC3, based on the weird range of
values that works, so i to some time and dove down into the OSTC3 code
base and found some interesting bits.

When looking at the OSTC3 asm thats up on bitbucket, i found that you're
using some macros to setup the ranges for the options, and if the value
is outside the range defined for that option. 

In option_table_begin: (src/option_table.asm:139) you start defining the
ranges for O2 values:
OPTION_UINT8    oGas1O2,        .7 ,.100,   .21,    tPercent, .40,     opt_gas_O2_ratio+0

And the OPTION_UINT8 macro defines them as:
OPTION_UINT8    MACRO   lbl, min, max, default, unit, eeprom, register

And everything this far looks ok.

But when i look at the option_check: code (src/options.asm:175) i find
the folowing:

        movf    opt_min,W
        cpfsgt  INDF1                   ; bigger then opt_min?
        bra     option_check_reset      ; No, reset option
        movf    INDF1,W
        cpfsgt  opt_max                 ; bigger then INDF1?
        bra     option_check_reset      ; No, reset option
        return                          ; in range, return


I think you have two bugs in this code, one being that its impossible to
set values below 21, and another that you can't set it to the max value.

When studying the Pic18F series asembler, as far as i understand it
compares with cpfsgt by doing (f) - (W) and if its zero or overflows,
aka f > W it skips the next instruction, the option_check_reset.

In the case of trying to set a O2 value of say, 100% this results to:

W = 7
f = 100
if (f - W) <= 0
  goto option_check_reset
W = 100
f = 100
if (f - W) <= 0
  goto option_check_reset


I would guess that the way to solve this is to change the opt_max to
101.



Why i can't write O2 values below 21% i haven't manage to figure out,
but you guys might be able to figure that one out.


//Anton



-- 
Anton Lundin	+46702-161604


More information about the subsurface mailing list