Skip to main content
Visitor II
January 2, 2018
Solved

Movement detection with LIS2DH

  • January 2, 2018
  • 14 replies
  • 5302 views
Posted on January 02, 2018 at 15:59

HI everybody,

I'm working with the LIS2DH for a motion sensor, and I'm using the embbeded functions of motion detection for drive the state machine of my MCU.

The operation is simple, but I have some trouble with the sensor.

I want to detect a movement if the duration is min 5sec, and I want to detect End of movement if the duration is 5sec.  

So I use the IA1 funtion with INT1 output for detection movement.

And IA2 function with INT2 output for End of movement detection.

Both INT output are OK with the detection, but I have non stable operation. Sometimes the INT1 toggles witout reason, sometime it's INT2.....

So if you run with the sensor in your hand, the INT1 output is high after 5sec. And if you put the sensor on the floor, the INT2 output is high after 5sec.

Sample is 1Hz ,Range is 2G.

High filter is set.

INT1_CFG is set to High level detection on X, Y , Z.  OR condition

INT2_CFG is set to Low level

detection on X, Y , Z.  OR condition

INT1_duration & INT2_duration are set to 0x05 in order to have 5sec of time detection.

INT1_threshold & INT2_threshold are set to 0x02, in order to have high sensivity.

Below the setting of the LIS2DH:

status_t LIS2DH_Init(void)

{

SPI1_Initialize();

CS_LIS1_SetHigh();

CS_LIS2_SetHigh();

LIS2DH_WriteReg(LIS2DH1,LIS3DH_CTRL_REG1,0x1F);

LIS2DH_WriteReg(LIS2DH1,LIS3DH_CTRL_REG2,0x03);

LIS2DH_WriteReg(LIS2DH1,LIS3DH_CTRL_REG3,0x40);

LIS2DH_WriteReg(LIS2DH1,LIS3DH_CTRL_REG4,0x80);

LIS2DH_WriteReg(LIS2DH1,LIS3DH_CTRL_REG5,0x00);

LIS2DH_WriteReg(LIS2DH1,LIS3DH_CTRL_REG6,0x20);

//START detection

LIS2DH_WriteReg(LIS2DH1,LIS3DH_INT1_CFG,0x02);

LIS2DH_WriteReg(LIS2DH1,LIS3DH_INT1_THS,0x02);

LIS2DH_WriteReg(LIS2DH1,LIS3DH_INT1_DURATION,0x05);

//STOP detection

LIS2DH_WriteReg(LIS2DH1,LIS3DH_INT2_CFG,0x15);

LIS2DH_WriteReg(LIS2DH1,LIS3DH_INT2_THS,0x02);

LIS2DH_WriteReg(LIS2DH1,LIS3DH_INT2_DURATION,0x05);

return MEMS_SUCCESS;

}

Could you please help to understant and solve this problème?

Thanks a lot for your support.

wilfried

    This topic has been closed for replies.
    Best answer by wilfried walezack
    Posted on February 27, 2018 at 11:20

    Hi Miroslav,

    I'm validated your first proposal. So I toggle the CS of the opposite sensor after a writing or a reading on the first sensor. Just a last question, I put a delay à 50us for the toggle of the CS.:

    CS_LIS2_SetLow();__delay_us(50);CS_LIS2_SetHigh();

    This delay is working on my board. Do you think it's a good delay for get a stable working ?

    Thanks a lot for your support.

    wilfried

    14 replies

    ST Employee
    February 27, 2018
    Posted on February 27, 2018 at 14:32

    50us delay should work well.

    Visitor II
    April 11, 2018
    Posted on April 11, 2018 at 22:49

    Hi Miroslav,

    I'm looking now for use the FIFO mode of the LIS2DH.

    I'm understand how the 3 different fifo modes according the application note, but I have one questions,

    I have to analsye the XYZ datas when a shock is triggered from the sensor, so the best way is to use the Stream to fifo mode in order to  set the INT1 trigger when the shock is detected and to stop automatically the fill of the fifo when the fifo is full. But I want to be sure to get 15 or 20 samples before the INT1 in order to analyse the XYZ values after the shock.

    How is it possible to be sure to get 15 or 20 samples after the interrup? 

    Thanks for your support.

    wilfried

    ST Employee
    April 12, 2018
    Posted on April 12, 2018 at 09:55

    I'm not sure if you need samples before or after the interrupt or both.

    It is not a problem to get data before the interrupt. To get data after the interrupt you have to read them in the real time, or start FIFO mode from the MCU immediately when the trigger occurs.

    Please read this thread

    https://community.st.com/0D50X00009XkWbLSAV

    It is also valid for LIS2DH.

    Visitor II
    April 27, 2018
    Posted on April 27, 2018 at 14:07

    Hi Miroslav,

    I have an mis understanding about the resolution of the INT1_THS register acoording the selected scale.

    This register is 7 bit value , so:

    for FS= 2g  1LSB = 2/127 = 16mg  OK with the datasheet

    FS= 4g  1LSB = 4/127 = 32mg  OK with the datasheet

    FS= 8g  1LSB = 8/127 = 62mg  OK with the datasheet

    FS= 16g  1LSB = 16/127 = 125mg  KO with the datasheet, according the datasheet 1 LSB = 186mg 

    and if I put the 0x01 int the INT1_THS with my bread board and unico I have 192mg

    What's the correct value?

    Other question:

    I'm using high resolution mode with 10Hz for ODR and FS 16G. so the resolution is 12bits. 

    In the specification, the sensitivity for this setting is 12 mg/digit. but this not match with 12bits ...

    What's the Fifo resolution in this case?

    Best regards

    wilfried

    0690X0000060Ao0QAE.png
    ST Employee
    May 3, 2018
    Posted on May 03, 2018 at 09:48

    The correct value of 1LSB threshold fro FS = 16G is 186mg. The sensor has different sensitivity in case of 16g range.

    FIFO stores only 10 bit values.

    Visitor II
    April 12, 2019

    Hi,

    The software is UNICO from ST. This is a usefull software for test the ST devise as MEMS sensor.

    regards