cancel
Showing results for 
Search instead for 
Did you mean: 

problem with lsm6dsl free fall detection

MRedd.3
Associate II

Hi sir ,

I working with( LSM6DSL)STEVAL-MKI178V1 Dk board communicating with nrf52840 controller board.

i am able work pedometer and significant motion and tilt detection these modes are working but i am trying to generate free fall detection but i am not getting the out put .

here i am sharing the code let me know where i am missing.

 /* set output data rate to 416 Hz and enable X,Y,Z axis */

LIS6DSH_write_reg(LSM6DSL_ACC_GYRO_CTRL1_XL, 0x60); //0x20 5hz ,50 204hz

     /* Enable free fall interrupts and latch interrupt */

LIS6DSH_write_reg(LSM6DSL_ACC_GYRO_TAP_CFG1, 0x81);

     /* Tilt detector interrupt driven to INT1 pin   */

LIS6DSH_write_reg(LSM6DSL_ACC_GYRO_WAKE_UP_DUR, 0x00);

     LIS6DSH_write_reg(LSM6DSL_ACC_GYRO_FREE_FALL, 0x33);

     /* free fall event is enabled */

     LIS6DSH_write_reg(LSM6DSL_ACC_GYRO_MD1_CFG, 0x10);

i am reading the 1B register free fall detect bit is not setting .

can you tell me am i need to set any other registers and changes in my configuration. Thanks you

1 ACCEPTED SOLUTION

Accepted Solutions
TSand.1
Associate III

Hi, there is a C sample code on Github for the free fall (lsm6dsm_free_fall.c). The registers and the are the same between lsm6dsm and lsm6dsl.

 /* Set XL Output Data Rate. */
  lsm6dsm_xl_data_rate_set(&dev_ctx, LSM6DSM_XL_ODR_416Hz);
  /* Set 2g full XL scale. */
  lsm6dsm_xl_full_scale_set(&dev_ctx, LSM6DSM_2g);
  /*  Enable LIR. */
  lsm6dsm_int_notification_set(&dev_ctx, LSM6DSM_INT_LATCHED);
  /*  Set Free Fall duration to 3 and 6 samples event duration. */
  lsm6dsm_ff_dur_set(&dev_ctx, 0x06);
  lsm6dsm_ff_threshold_set(&dev_ctx, LSM6DSM_FF_TSH_312mg);
  /*  Enable interrupt generation on Free Fall INT1 pin. */
  lsm6dsm_pin_int1_route_get(&dev_ctx, &int_1_reg);
  int_1_reg.int1_ff = PROPERTY_ENABLE;
  lsm6dsm_pin_int1_route_set(&dev_ctx, int_1_reg);

Differently from your code (that is probably the one), here the duration of the fall is 3 and the event 6 samples. Moreover and the interrupt is latched.

You could try with these settings.

View solution in original post

3 REPLIES 3
TSand.1
Associate III

Hi, there is a C sample code on Github for the free fall (lsm6dsm_free_fall.c). The registers and the are the same between lsm6dsm and lsm6dsl.

 /* Set XL Output Data Rate. */
  lsm6dsm_xl_data_rate_set(&dev_ctx, LSM6DSM_XL_ODR_416Hz);
  /* Set 2g full XL scale. */
  lsm6dsm_xl_full_scale_set(&dev_ctx, LSM6DSM_2g);
  /*  Enable LIR. */
  lsm6dsm_int_notification_set(&dev_ctx, LSM6DSM_INT_LATCHED);
  /*  Set Free Fall duration to 3 and 6 samples event duration. */
  lsm6dsm_ff_dur_set(&dev_ctx, 0x06);
  lsm6dsm_ff_threshold_set(&dev_ctx, LSM6DSM_FF_TSH_312mg);
  /*  Enable interrupt generation on Free Fall INT1 pin. */
  lsm6dsm_pin_int1_route_get(&dev_ctx, &int_1_reg);
  int_1_reg.int1_ff = PROPERTY_ENABLE;
  lsm6dsm_pin_int1_route_set(&dev_ctx, int_1_reg);

Differently from your code (that is probably the one), here the duration of the fall is 3 and the event 6 samples. Moreover and the interrupt is latched.

You could try with these settings.

Hello sir ,

Thank you , free fall detection is working fine.

now i am working single tap and double tap detection , I configured as mentioned in below program ,the problem is when TAP the device single or double interrupt is generating properly but after generating the interrupt i am reading the TAP_SRS (1C) register in that SINGLE_TAP and Double _TAP bits are not setting. the received data is 0xA,0xC,0x9. can you please let me know where is the problem.

uint8_t Double_Tap_Detection(void)

{

   uint8_t reg_status=0;

    /* Turn on the accelerometer ODR_XL = 416 Hz, FS_XL = ±2 g */

LIS6DSH_write_reg(LSM6DSL_ACC_GYRO_CTRL1_XL, 0x60);  

    /* Enable interrupts and tap detection on X, Y, Z axis */

LIS6DSH_write_reg(LSM6DSL_ACC_GYRO_TAP_CFG1, 0x8E);

    /* Setting the threshold for tap recognition */

LIS6DSH_write_reg(LSM6DSL_ACC_GYRO_TAP_THS_6D, 0x8C);

    /* Set Quiet and Shock time windows */

LIS6DSH_write_reg(LSM6DSL_ACC_GYRO_INT_DUR2, 0x7F);

    /* Only single-tap enabled (SINGLE_DOUBLE_TAP = 0) */

LIS6DSH_write_reg(LSM6DSL_ACC_GYRO_WAKE_UP_THS, 0x80);\

     /* Single-tap interrupt driven to INT1 pin */

    LIS6DSH_write_reg(LSM6DSL_ACC_GYRO_MD1_CFG, 0x08);

    while(1)

    {

     reg_status= LIS6DSH_read_reg(0x1C);

     nrf_delay_ms(300);

     NRF_LOG_INFO(" tap src data %x",reg_status);

     nrf_delay_ms(500);

    }

}

TSand.1
Associate III

In the AN5040 app note I read:

If latched mode is enabled and the interrupt signal is driven to the interrupt pins, the value assigned to SINGLE_DOUBLE_TAP also affects the behavior of the interrupt signal: when it is set to 0, the latched mode is applied to the single-tap interrupt signal; when it is set to 1, the latched mode is applied to the double-tap interrupt signal only. The latched interrupt signal is kept active until the TAP_SRC register is read. If latched mode is enabled but the interrupt signal is not driven to the interrupt pins, the latch feature does not take effect.

You can then try to enable the LIR bit in TAP_CFG (58h) register and check if the SINGLE_TAP and DOUBLE_TAP are enabled.