cancel
Showing results for 
Search instead for 
Did you mean: 

IIS2DH (DM00171283) Single click detection?

Arpan Patel
Associate II
Posted on June 13, 2017 at 14:08

I am working with IIS2DH accelorometer an I would like to configure single/double click tap detection. For that, I have done following configuration:

I2C_WriteByte(&ctrl_1,1,0x5F); 

I2C_WriteByte(&ctrl_3,1,0x80);

I2C_WriteByte(&ctrl_6,1,0x82);

I2C_WriteByte(&ctrl_4,1,0x00);

I2C_WriteByte(&int1_config,1,0x00); 

I2C_WriteByte(&ctrl_5,1,0x40);

I2C_WriteByte(&click_config,1,0x15);

I read click source register for single click detection but values are different every time. Also,interrupt flag not set for microcontoller.

Is there any thing need to be wrong in my configuration?

Is any application note for IIS2DH(DM00171283)?

8 REPLIES 8
Miroslav BATEK
ST Employee
Posted on June 29, 2017 at 10:59

You configuration is correct, but you have to set also two configuration registers for single click detection (CLICK_THS, TIME_LIMIT).

If the device is configured for single-click event detection, an interrupt is generated when the input acceleration on the selected channel exceeds the programmed threshold CLICK_THS, and returns below it within a time window defined by the TIME_LIMIT register.

Posted on June 30, 2017 at 05:56

I2C_WriteByte(&ctrl_1,1,0x5F);

I2C_WriteByte(&ctrl_3,1,0x80);

I2C_WriteByte(&ctrl_6,1,0x82);

I2C_WriteByte(&ctrl_4,1,0x00);

I2C_WriteByte(&int1_config,1,0x00);

I2C_WriteByte(&ctrl_5,1,0x40);

I2C_WriteByte(&click_config,1,0x01);//only x axis click enable

I2C_WriteByte(&time_limit,1,0x05);

I2C_WriteByte(&click_ths,1,0x0D);

I have configured above registers and I read click source register continuously but when I click the accelerometer  interrupt is generated and click source values is getting from sensor is  0x09,0x01,0x51 from that value I thought only 0x51 is correct to match with the only X axis enable detection whereas, form the other two values, I had got the interrupt as well. Am I done correct configuration? and I have one more query that in above configuration time_limit and

click_ths 

register,I have load with 0x05 and 0x0d that means after how much time and after how much acceleration it generate the interrupt?

So, could help me on that issue. Thank you for your support.

Legacy member
Not applicable
Posted on June 30, 2017 at 16:40

Hello,

I only found this in

http://www.st.com/content/st_com/en/resource-selector.html

(can't search for older documents than September 7th, 2015) :

http://www.st.com/content/ccc/resource/technical/document/application_note/17/c9/44/8d/ff/25/4e/1f/CD001635pdf/files/CD001635pdf/jcr:content/translations/en.CD001635pdf

And one more discovered by Google

http://www.st.com/content/ccc/resource/technical/document/application_note/b4/d6/a1/42/8a/d1/4e/05/CD00196pdf/files/CD00196pdf/jcr:content/translations/en.CD00196pdf

Since the documents seem pretty similar, I would try to read the theory of operation in them.

Batek.Miroslav

‌, is there a similar application note for newer devices?

David

Posted on July 03, 2017 at 06:57

One more thing I would like to tell you that in the datasheet

of 

DM00171283 there are no such bit like LIR in the click source register. So, how to use and configure that register for single click detection? Furthermore, my previous query still not be answered. I got the interrupt on single click but  I only click one time, interrupt got multiple time. Please provide proper guidance for that. 

Posted on July 18, 2017 at 12:19

CLICK_THS ... 1 LSB = full scale/128 (in you case FS = 2g, CLICK_TSH = 0x05 ... 5 * 2g / 128 = 0.078g)

TIME_LIMIT ... 1 LSB = 1/ODR (in you case ODR = 100Hz, 

TIME_LIMIT = 0x0D ... 13 * 1 / 100 = 0.13s)

Concerning the behavior you described, I think the X and Sign bits (values 0x09 or 0x01) in CLICK_SRC register are set immediately when the CLICK_THS is reached and the IA bit (value 0x51 or 0x59) is set if the value returns below it within a time window defined by the TIME_LIMIT register. So the IA bit has latency of TIM_LIMIT time.

0690X00000607UfQAI.png

Basically

 you can you can mask other bits in you program and the CLICK using only the IA bit in CLICK_SRC register or use the hardware interrupt signals.

Posted on July 19, 2017 at 05:17

Thank you for your exceptional support.

I2C_WriteByte(&ctrl_1,1,0x5F);

I2C_WriteByte(&ctrl_3,1,0x80);

I2C_WriteByte(&ctrl_6,1,0x82);

I2C_WriteByte(&ctrl_4,1,0x20);// 8g sensitivity set

I2C_WriteByte(&int1_config,1,0x00);

I2C_WriteByte(&ctrl_5,1,0x40);

I2C_WriteByte(&click_config,1,0x15);//x,y,z, enable for click

I2C_WriteByte(&time_limit,1,0x05);

I2C_WriteByte(&click_ths,1,0x60);

As per your answer, I have configured all registers as per above specification. Moreover, I have used IA bit to mask for interrupt generation, in my code I have continuously read click source register and once IA bit is set I have read x,y, and z axis value and following reading I have got. It is fine or not? Furthermore, sometimes I have got multiple time IA bit set for single click. So, any method to overcome this issue? Now, it is working very fine.

click src 54

x axis is 9

y axis is -8

z axis is 55

******************

click src 54

x axis is -4

y axis is 32

z axis is -5

******************

click src 54

x axis is -12

y axis is -25

z axis is 80

******************

click src 5a

x axis is -7

y axis is 66

z axis is 127

******************

click src 54

x axis is -2

y axis is -24

z axis is 81

******************

click src 5c

x axis is -9

y axis is -84

z axis is 77

******************

click src 54

x axis is 2

y axis is 7

z axis is 34

******************

click src 52

x axis is 4

y axis is 12

z axis is -6

******************

click src 52

x axis is -1

y axis is 15

z axis is -6

******************

click src 52

x axis is 1

y axis is 6

z axis is 0

******************

I tap on particular hardware then I got the IA bit set but if I tap around the hardware nothing can happened. So, any specific region around the hardware to tap and got the interrupt?

Posted on July 19, 2017 at 15:36

The configuration and behavior seems OK to me.

Instead of continuous polling of CLICK_SRC register you can also use the hardware interrupt signal generated on INT1 or INT2 pin, if you have these signals connected to you microcontroller. In this case you can set the TIME_LATENCY and the interrupt will be kept active for this time (TIME_LATENCY) so it will mask multiple set of IA bit for single click. These multiple sets of IA bit are caused by bouncing of the device and this triggers the click detection multiple time. Another solution is to filter these multiple detection in software.

Concerning the region around the hardware, where the click is detected, it is really dependent on the board on which the sensor is soldered and mechanical construction of your device. You have to fine tune the sensitivity by the click threshold settings.
Posted on July 20, 2017 at 05:07

Hi Miroslav, I have done single click on both method by using hardware interrupt and IA bit masking. it is working fine. However, when I used hardware interrupt then once interrupt is active and I am reading click source register, sometimes it is shown value like below:

click src 2

x axis is -7

y axis is -4

z axis is 31

******************

click src 5a

x axis is -17

y axis is -11

z axis is 45

******************

click src 1

x axis is -28

y axis is -13

z axis is 73

******************

click src a

x axis is -4

y axis is 5

z axis is 15

******************

So, in the case like 0x02,0x01,0x0a IA bit is 0 means that interrupt is not active then how the hardware interrupt is activated? Can I use both condition to check interrupt is active or not? Ex. 

if(hw_interrupt_flag)

{

   if(click_source & (1<<6)

   {

         print('single click detect');

   }

}

One more concern is you told that multiple click detection issue is solved by using software filter so, how I achieve it?

Thanks for your support.