cancel
Showing results for 
Search instead for 
Did you mean: 

lsm6ds3 Relative tilt function

ZhangTao
Associate II

the first interrupt is generated if the device is rotated by an angle greater than 35 degrees

from the start position and remains in the blue zone for a period of time of at least 2 seconds

1�?35 degrees. What is its principle calculation formula?At least how many axes changed I can think a Relative tilt happen?

2�? When the chip is placed horizontally or vertically, The chip rotates 180 degrees along the central axis,this behavior is a  Relative tilt ?generate a interrupt ?

7 REPLIES 7
Eleon BORLINI
ST Employee

Hi @Community member​ , about your 1st question, there is some literature documentation produced by STMicroelectronics that explains you how the Tilt is calculated and

As regard the code implementation of the Tilt embedded digital feature in lsm6ds3, I suggest you to check the online examples on Github (lsm6ds3_tilt.c), if not already done.

A higher-level library running on STM32 is also available under the name of MotionTL (tilt measurement library in X-CUBE-MEMS1 expansion for STM32Cube): you cha find HERE the detailed description.

Hope these hints may help you in the tilt app development. Btw, the answer to your second question is that if the Tilt function is running and you rotate your device of 180°, the interrupt will be generated since the device recognizes the tilt event. Regards

ZhangTao
Associate II

hello Eleon BORLINI,

thank you your answer.

(1)Now my tilt function is OK, but I have some questions at some special test scenes。

I enable the sensor tilt function in my device by blow codes:

1. Write 20h to CTRL1_XL // Turn on the accelerometer // ODR_XL = 26 Hz, FS_XL = ±2 g

2. Write 0Ch to CTRL10_C // Enable embedded functions // Enable tilt detection

3. Write 02h to MD1_CFG // Tilt detector interrupt driven to INT1 pin

FS_XL = ±2 g I setting ±4 g is ok?

Is no other regs need to be config?

(2)

I read AN4509.

Single-axis tilt sensing is supported, but I can not tested it.

Is Single-axis tilt sensing need gyroscope enable? Now gyroscope I disable it.

Do you have some devices to me?

thank you!

Hi @Community member​ ,

(1) The 2g FS is recommended (because the algorithm is based on the gravity 1g vector angle detection, and the 2g FS has the best sensitivity resolution, resulting in the best angle resolution), but the function should work properly also for the 4g FS.

(2) For the single axis tilt detection, I suggest you to check the code on Github (lsm6ds3_tilt.c). You can act on the "tap register configuration" to select the X, Y or Z axis (or all together). Please chek if it can be of any help for you.

 /* Set XL Output Data Rate:The tilt function works at 26 Hz,
   * so the accelerometer ODR must be set at 26 Hz or higher values
   */
  lsm6ds3_xl_data_rate_set(&dev_ctx, LSM6DS3_XL_ODR_26Hz);
 
  /* Set 2g full XL scale */
  lsm6ds3_xl_full_scale_set(&dev_ctx, LSM6DS3_2g);
 
  /* Enable Tilt function */
  lsm6ds3_tilt_sens_set(&dev_ctx, PROPERTY_ENABLE);
 
  /* Enable interrupt generation on Tilt INT1 pin */
  lsm6ds3_int_notification_set(&dev_ctx, LSM6DS3_INT_LATCHED);
  lsm6ds3_tap_detection_on_z_set(&dev_ctx, PROPERTY_ENABLE);
  lsm6ds3_tap_detection_on_y_set(&dev_ctx, PROPERTY_ENABLE);
  lsm6ds3_tap_detection_on_x_set(&dev_ctx, PROPERTY_ENABLE);
  lsm6ds3_pin_int1_route_get(&dev_ctx, &int_1_reg);
  int_1_reg.int1_tilt = PROPERTY_ENABLE;
  lsm6ds3_pin_int1_route_set(&dev_ctx, &int_1_reg);

Regards

ZhangTao
Associate II

@Eleon BORLINI​ 

I check lsm6ds3_tilt.c

I found some problems:

 /* Enable Tilt function */

 lsm6ds3_tilt_sens_set(&dev_ctx, PROPERTY_ENABLE);

int32_t lsm6ds3_tilt_sens_set(stmdev_ctx_t *ctx, uint8_t val)

{

 lsm6ds3_ctrl10_c_t ctrl10_c;

 lsm6ds3_tap_cfg_t tap_cfg;

 int32_t ret;

 ret = 0;

 if (val == PROPERTY_ENABLE){

  ret = lsm6ds3_read_reg(ctx, LSM6DS3_CTRL10_C, (uint8_t*)&ctrl10_c, 1);

  if(ret == 0){

   ctrl10_c.func_en = PROPERTY_ENABLE;

   ret = lsm6ds3_write_reg(ctx, LSM6DS3_CTRL10_C, (uint8_t*)&ctrl10_c, 1);

  }

 }

 if(ret == 0){

  ret = lsm6ds3_read_reg(ctx, LSM6DS3_TAP_CFG, (uint8_t*)&tap_cfg, 1);

 }

 if(ret == 0){

  tap_cfg.tilt_en = (uint8_t)val;

  ret = lsm6ds3_write_reg(ctx, LSM6DS3_TAP_CFG, (uint8_t*)&tap_cfg, 1);

 }

 return ret;

}

#define LSM6DS3_TAP_CFG              0x58U

typedef struct {

 uint8_t lir             : 1;

 uint8_t tap_z_en          : 1;

 uint8_t tap_y_en          : 1;

 uint8_t tap_x_en          : 1;

 uint8_t slope_fds          : 1;

 uint8_t tilt_en           : 1;

 uint8_t ****_en           : 1;

 uint8_t timer_en          : 1;

} lsm6ds3_tap_cfg_t;

TAP_CFG (58h) have tilt_en bit?

I check LSM6DS3TR-C datasheet DocID030071 Rev 3.

0693W000001tG0kQAE.png

I can not find tilt_en bit in TAP_CFG.

but CTRL10_C (19h) have tilt_en bit

 

I enable the sensor tilt function in my device by blow codes from AN5130 - Rev 1.6.3 Relative tilt.

1. Write 20h to CTRL1_XL // Turn on the accelerometer // ODR_XL = 26 Hz, FS_XL = ±2 g

2. Write 0Ch to CTRL10_C // Enable embedded functions // Enable tilt detection

3. Write 02h to MD1_CFG // Tilt detector interrupt driven to INT1 pin

please confirm it. thank you!

Hi @Community member​ , uhm... thank you for your notification, I'll share it internally to our C library developer. You should be right: is it working with the tilt_en bit bit of CTRL10_C (19h) register? Regards

Eleon BORLINI
ST Employee

Hi @Community member​ , internally checked, and please note that the LSM6DS3TR-C and the LSM6DS3 part numbers are different devices with different datasheets. The LSM6DS3 has a TAP_CFG (58h) register tilt_en bit, so the code is correct. Regards

0693W000003BKKUQA4.png

ZhangTao
Associate II

@Eleon BORLINI​ ,thank you!

I check my chip.