cancel
Showing results for 
Search instead for 
Did you mean: 

Two's Complement for XL values

BDiva.1
Associate II

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Eleon BORLINI
ST Employee

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

View solution in original post

6 REPLIES 6
Eleon BORLINI
ST Employee

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

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?

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

Yes, for the FIFO data the spec explicitly states the data is signed since they are encoded with two's complement; but for the OUTX_L_A (28h) and OUTX_H_A (29h) for example are not explicitly state that they are signed two's complement values. see p.67 of LSM3DSO Datasheet (not App.Note as I mistakenly referenced in the original post.

Hi @BDiva.1​ ,

they are too.

If this can cause misunderstandings, I'll submit the point internally to the attention of our online documentation editors.

-Eleon

Thanks Eleon!