Two's Complement for XL values
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2021-04-06 1:46 PM
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?
Solved! Go to Solution.
- Labels:
-
Accelerometers
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2021-04-07 12:20 AM
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:
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2021-04-07 12:20 AM
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:
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2021-04-07 7:51 AM
Eleon,
- 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.
- In your examples, why the MSB value is not considered for conversion? Each XL value contains both MSB and LSB, right?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2021-04-14 3:44 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2021-04-14 6:24 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2021-04-15 2:45 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2021-04-16 8:07 AM
Thanks Eleon!
