cancel
Showing results for 
Search instead for 
Did you mean: 

LIS2DW12 axis orientation (sign)

CThue.1
Associate II

Hi,

I have a very simple (read: stupid) question in regards to the LIS2DW12 asix alignment (sign).

I have implemented my own driver, but it is heavily based on this code:

https://github.com/STMicroelectronics/STMems_Standard_C_drivers/blob/master/lis2dtw12_STdC/examples/lis2dtw12_read_data_polling.c

I basically does something like this:

data->x  =  static_cast<int16_t>(read_reg(REG_OUT_X_L));
data->x |= (static_cast<int16_t>(read_reg(REG_OUT_X_H)) << 8);
data->y  =  static_cast<int16_t>(read_reg(REG_OUT_Y_L));
data->y |= (static_cast<int16_t>(read_reg(REG_OUT_Y_H)) << 8);
data->z  =  static_cast<int16_t>(read_reg(REG_OUT_Z_L));
data->z |= (static_cast<int16_t>(read_reg(REG_OUT_Z_H)) << 8);

When I read the x, y and z data I get the following output in the terminal:

measurement: x = -116, y = -744, z = 17068
measurement: x = -180, y = -812, z = 17156
measurement: x = -252, y = -712, z = 16800
measurement: x = -204, y = -864, z = 17480
measurement: x = -172, y = -772, z = 17000
measurement: x = -160, y = -844, z = 17276
measurement: x = -136, y = -800, z = 17200
measurement: x = -212, y = -756, z = 16884
measurement: x = -208, y = -792, z = 17076
measurement: x = -188, y = -744, z = 17136
measurement: x = -208, y = -700, z = 16948

The chip is placed on the table with the sensor pointing upwards.

When I look in the datasheet I get the understanding that any positive force applied on the z-axis goes up - and since it is placed on the table only gravity is acting, meaning I should read a negative value. The full-scale value is +/-2g which seems to match well with 17000 (which is half of the 2g scale, considering that we have a int16 representation of -32,768 to 32,767... so I see 1g instead of -1g).

0693W00000BbGhiQAF.pngThis is what I don't get from the datasheet:

0693W00000BbGjFQAV.pngAnd I actually see the same behavior on x and y axis (so signs are flipped on all axis).

Hopefully someone can pin-point the clear error I'm doing.

BR,

Carsten

1 ACCEPTED SOLUTION

Accepted Solutions
Winfred LU
ST Employee

It is because the acceleration is defined as acceleration relative to the object (sensor) being free falling (no force is applied).

Image that if a sensor is free falling (assume that Z axis remains facing perfectly up without rotating), you shall read ZERO acceleration in the Z axis.

For the sensor that is put still on the table, compared to the free-falling sensor, it is accelerating 9.8 m/s2 toward the sky.

You may think of this in the way how the sensor is designed.

Inside the accelerometer, it is a flexible mechanical ruler, which will bend when when a force is applied. The ruler measures that force according to how much it bends.

To decide the direction, we put the ruler in space w/o gravity. When the ruler accelerates from left to right, the ruler shall bend to left like " ( ", which means the force is added to the ruler from right to left. Thus, we understand that the direction of the force is opposite to the direction of acceleration.

Now, we put the ruler on the table horizontally, out of the the gravity the ruler shall bend toward the ground like " U ", which means the force (gravity) is added toward the ground. Then, we get the acceleration positive toward the sky.

View solution in original post

4 REPLIES 4
Eleon BORLINI
ST Employee

Hi Carsten @CThue.1​ ,

the correct sign/value of acceleration along z axis is a common misunderstanding.

The convention for ST accelerometers is to have, in a steady flat condition, 0g along X and Y axis and +1g along z (indeed, about 17000, or half of the 2g scale). So, your readings are correct (even if you might expect -1g, or 0g, what is measured is the vincular reaction of the table).

If you drop the board, you'll see that this 1g goes towards 0g, and this is the free fall condition as measured by ST accelerometers.

Hope it is a bit clearer now. 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

Winfred LU
ST Employee

It is because the acceleration is defined as acceleration relative to the object (sensor) being free falling (no force is applied).

Image that if a sensor is free falling (assume that Z axis remains facing perfectly up without rotating), you shall read ZERO acceleration in the Z axis.

For the sensor that is put still on the table, compared to the free-falling sensor, it is accelerating 9.8 m/s2 toward the sky.

You may think of this in the way how the sensor is designed.

Inside the accelerometer, it is a flexible mechanical ruler, which will bend when when a force is applied. The ruler measures that force according to how much it bends.

To decide the direction, we put the ruler in space w/o gravity. When the ruler accelerates from left to right, the ruler shall bend to left like " ( ", which means the force is added to the ruler from right to left. Thus, we understand that the direction of the force is opposite to the direction of acceleration.

Now, we put the ruler on the table horizontally, out of the the gravity the ruler shall bend toward the ground like " U ", which means the force (gravity) is added toward the ground. Then, we get the acceleration positive toward the sky.

Hi Eleon,

Thanks for the quick answer.

I have set Winfred LU's amswer as "best answer", since this was more detailed and explained the concept a bit better for me.

Still thanks for you time on answering this!

-Carsten

Hi Winfred

Thank you for the quick and very detailed answer. This explain the problem in a nice and understandable way.

I have actually found a couple of datasheets that also explain the behavior (both from ST and Analog):

Both datasheets shows that the force measured is +1g when the chip is placed on the floor with the front facing up.

I have added them as a visual explaination to you fine answer in case other have a similar problem.

-Carsten