Skip to main content
Visitor II
April 6, 2021
Solved

Two's Complement for XL values

  • April 6, 2021
  • 1 reply
  • 1578 views

LSM6DSO Application Note, page 67: The value is expressed as a 16-bit word in two’s complement.

Question: is this a SIGNED or UNSIGNED value?

    This topic has been closed for replies.
    Best answer by Eleon BORLINI

    Hi @BDiva.1​ ,

    since it is reported in two's complement, it is a signed value (the physical principle interpretation is that acceleration can be negative if it is in the opposite verse -for example- of the earth gravity). You can check the direction of the acceleration / angular speed from the picture in the datasheet p.6:

    0693W000008yqDEQAY.png 

    LSB-to-physical units conversion formula (for the accelerometer) is the following one (lsm6dso_reg.c:(

    float_t lsm6dso_from_fs2_to_mg(int16_t lsb)
    {
     return ((float_t)lsb) * 0.061f;
    }

    If my reply answered your question, please click on Select as Best at the bottom of this post. This will help other users with the same issue to find the answer faster.

    -Eleon

    1 reply

    ST Employee
    April 7, 2021

    Hi @BDiva.1​ ,

    since it is reported in two's complement, it is a signed value (the physical principle interpretation is that acceleration can be negative if it is in the opposite verse -for example- of the earth gravity). You can check the direction of the acceleration / angular speed from the picture in the datasheet p.6:

    0693W000008yqDEQAY.png 

    LSB-to-physical units conversion formula (for the accelerometer) is the following one (lsm6dso_reg.c:(

    float_t lsm6dso_from_fs2_to_mg(int16_t lsb)
    {
     return ((float_t)lsb) * 0.061f;
    }

    If my reply answered your question, please click on Select as Best at the bottom of this post. This will help other users with the same issue to find the answer faster.

    -Eleon

    BDiva.1Author
    Visitor II
    April 7, 2021

    Eleon,

    1. This is weird that the SIGNED is not mentioned in the datasheet or the Application note, where it is specifically says for 5bit_signed and 8bit_signed values for the compressed data.
    2. In your examples, why the MSB value is not considered for conversion? Each XL value contains both MSB and LSB, right?
    ST Employee
    April 14, 2021

    Hi @BDiva.1​ ,

    in 1., you are speaking of "compressed data"... are you referring to the FIFO operation? Probably I'm not understanding which part of which application note are you referring to... can you please detail a bit more the reference?

    Note that in general all the thresholds and counter values are unsigned (integers), while the data output are signed floating...

    Regarding your question 2., the int16_t indicates a 16-bit words, that includes the concatenation of the MSB with the LSB. So you are right, each XL value contains both 8-bit data content. After the concatenation, you have to convert the 16-bit hexadecimal value into decimal via two's complement conversion.

    -Eleon