Skip to main content
Visitor II
January 2, 2017
Question

Understanding acceleration data from IIS2DH

  • January 2, 2017
  • 3 replies
  • 3943 views
Posted on January 02, 2017 at 16:15

I've been trying to understand how to interpret and format the data I'm getting from the accelerometer. First, my setup:

Low power, 5.376KHz ODR, 16G full scale, normalresolution mode, ZHIE enabled, ZLOW disabled, THSset to 30

(First I need to understand how to interpret and format the data with the above configuration, then I can work on tuning things for my application).

I am using an Arduino to interface to the IIS2DH and getting AOI interrupts on INT1. All of this is working in my Arduino and code.

This is a Z probe for a 3D printer, so when the probe (accelerometer) strikes a solid surface, it generates an interrupt for the Z axis event (X and Y are not enabled). This all works. I get the interrupt and then fetch the OUT_Z_L and OUT_Z_H registers as 8 bit integers. It is from here that I need help understanding what I am getting and how to interpret it.

When I run my tests, I can print the output to the console to see what's going on. When I do this, for a typical probe 'hit', I see, in binary:

Z_H = b00001000

Z_L = b00001010

I do see small differences from probe point to probe point - there are 13 probesin a typical run so I see 13 pairs of values. Here's a full set in Z_H / Z_L order:

  1. 00001000 /00001001
  2. 00001001 /00001010
  3. 00001001 /00001001
  4. 00001001 /00001010
  5. 00001000 /00001010
  6. 00000111 /00000111
  7. 00000110 /00001000
  8. 00000110 /00001001
  9. 00001000 /00001001
  10. 00000111 /00001000
  11. 00000101 /00000111
  12. 00001001 /00001001
  13. 00001011 / 00001001

Does this make sense? It doesn't to me. I never see data in the high 4 bits of the low or high byte. I thought the data was left aligned and with my normal resolution (10 bits, correct?) I would expect to see nothing in the lower 6 bits of the low byte. Am I retrieving sensible data and if so, how do I reconstruct it into a value?

Thanks in advance!

#iis2dh

Note: this post was migrated and contained many threaded conversations, some content may be missing.
    This topic has been closed for replies.

    3 replies

    mhackneyAuthor
    Visitor II
    January 2, 2017
    Posted on January 02, 2017 at 16:21

    Ok, I overlooked the data sheet that Low Power mode is 8-bit data output. But that still does not explain why the data is not left aligned?

    Also, here is my complete configuration to sanity check:

    // setup CTRL_REG1

    accelerometer_write(CTRL_REG1, 0b10011100); // ODR 5.376kHz in LPMode [7-4] Low power enable [3] Z enable [2]

    // setup CTRL_REG2

    accelerometer_write(CTRL_REG2, 0b00110001); //

    // setup CTRL_REG3

    accelerometer_write(CTRL_REG3, 0b01000000); // AOI (And Or Interrupt) on INT1 en [6]

    // setup CTRL_REG6

    accelerometer_write(CTRL_REG6, 0b00000000); // 

    // setup CTRL_REG4

    accelerometer_write(CTRL_REG4, 0b00110000); // Full-scale selection 16G [5-4]

    // setup CTRL_REG5

    accelerometer_write(CTRL_REG5, 0b01001010); // FIFO enable [6] Latch INT1 [3]

    // setup INT1_CFG

    accelerometer_write(INT1_CFG, 0b00100000); // ZHIE enabled [5]

    // setup INT1_THS

    accelerometer_write(INT1_THS, Z_PROBE_SENSITIVITY);  // 40

    // setup INT1_DURATION

    accelerometer_write(INT1_DURATION, 0);
    ST Employee
    January 2, 2017
    Posted on January 02, 2017 at 22:30

    In Low Power mode the output is only 8-bit, so you should simply ignore the 

    Z_L byte. The data in

    Z_L byte are not valid.

    If you hit the sensor more, you should see also some values in high 4 bits of Z_H. For example if the configuration is FS=16g, Low Power mode the LSB=208mg, so to see 0b00010000 output value, you have to generate acceleration 3328mg.

    mhackneyAuthor
    Visitor II
    January 2, 2017
    Posted on January 02, 2017 at 22:53

    Thank you. Does this mean that with FS=16g and 8-bit output that all 8 bits of Z_H are valid? To make a 16 bit value from it. do I shift left 8 places and fill the right 8 places with 0?  

    Looking at my data above for probe point 1:

    1. 00001000 / 00001001

    What you are saying is that the low byte (00001001) should be ignored. So, what is the actual measured acceleration, is it: 00001000 (actually 00000000 00001000 if 16 bits) or something else?

    So in this case: 8 * 208mg = 1664mg or 1.664g This makes some sense so perhaps it is the correct way to interpret?

    And where did you get the 208mg for the LSB in FS=16g? In the datasheet it looks like it should be 186mg from table 57? So 8 * 208mg = 1.488g. Is this correct?

    Assuming my interpretation above is correct - that I can just use Z_H byte as-is, how is the data arranged in 10 and 12 bit resolution modes?

    ST Employee
    January 2, 2017
    Posted on January 02, 2017 at 23:29

    Yes, all 8 bits of Z_H are valid.

    Yes, if you need 16 bit value you can do it as you mentioned.

    Yes, your interpretation is corrent.

    The sensitivity for all configuration can be found in Table 3. Sorry for the confusion the 208mg/LSB is maximum value of the sensitivity, I looked at the wrong column. You should use typical value which is 188.68mg/LSB.

    In 8, 10, 12 bit resolution you always use the appropriate number of most significant bits.

    10 bit mode ... ((256*OUT_Z_H)+

    OUT_Z_L)>>6

    12 bit mode ... ((256*

    OUT_Z_H)+

    OUT_Z_L)>>4

    Visitor II
    November 22, 2017
    Posted on November 22, 2017 at 18:19

    Hello,

    I am new to this accelerometer sensor. I have configured the Interrupt 2 to work for my application and it finally is working great. But, I just don't understand how did you guys decide on the FS and THS value for your application? I had to do trial and error method and it was a tedious work. My goal for this question is to understand this concept so that I do not have to do this trial and error method all over again for different applications as well.

    Please help me. 

    ST Employee
    November 22, 2017
    Posted on November 22, 2017 at 21:32

    I depends what is your objective.

    - You can do some teoretical analysis. For example for tilt detection, you know the gravity is 1g and the you can use trigonometric functions to calculate the value for certain angle.

    - You can record acceleration data during some movement which you want to detect or analyze and then you process them offline in you computer, check the maximu and minuimum values and levels which the value raech during stimulation. This give you the information what FS and threshold you should use.

    - Trial and error is sometimes also used approach

    Visitor II
    November 27, 2017
    Posted on November 27, 2017 at 19:15

    Hello,

    Thank you for the advice and teaching me the method to arrive at better configuration of the accelerometer for different application. However, I have an another doubt regarding the THS register. According to the datasheet when I have configured my accelerometer at FS8, '1 LSb is 62 mg'. So, what does that exactly mean ?

    For example, when I have THS register set at 0x10 with INT1_CFG = 0x02(XHIE). So when exactly does the interrupt get enabled and what is the value of Threshold for that value of THS register ? I am sorry if I am being vague? I am not sure what will be the threshold value ?

    Also, you said for tilt it has to be 1g. Can I make the interrupt enabled 'only' when its tilted and not vibration ? If so, how would you configure the interrupt and accelerometer in whole? (Consider the tilting is at a normal place)