High-Precision-AD-DA-Board icon indicating copy to clipboard operation
High-Precision-AD-DA-Board copied to clipboard

Negative values get discarded

Open userx14 opened this issue 5 years ago • 0 comments

The code in ADS1256.py seems to destroy negative values with an 'and filter'.

        if (read & 0x800000):
            read &= 0xF000000



Probably this should have been

        if (read & 0x800000):
            read |= 0xFF000000

so that the output value is compatible with int32



My code for differential readout conversion in python with the fix is:

#v_ref must be float e.g. 5.0
def convert2float(raw_val,v_ref):
    if(raw_val>0x7fffff):
        return ((raw_val-0x100000000)*v_ref/0x7fffff)
    else:
        return (raw_val*v_ref/0x7fffff)

userx14 avatar Oct 27 '19 19:10 userx14