MMA8452 Tap direction detection

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MMA8452 Tap direction detection

2,400 Views
fernandogomes
Contributor II

I'm using the SparkFun breakout board with the MMA8452 accelerometer to validate user interaction without buttons. I need to be able to identify the tap direction for that. I'm not understanding why there are bits for identifying the tap direction in the PULSE_SRC register but there is an applciation note that says to process the data in the FIFO to calculate the direction. Is it possible to read the tap direction only using the PULSE_SRC bits? Does this work well, or to get good results we must process the FIFO data after detecting the tap?

Thanks!

Fernando

Labels (1)
8 Replies

1,850 Views
david_diaz
NXP Employee
NXP Employee

Hello Fernando,

The read-only PULSE_SRC register, indicates a double or single pulse event has occurred and also which direction.

In this case, the most efficient way to access data is to use the internal 32-sample FIFO buffer because this minimizes the number of I2C transactions, but it does not mean that the PULSE_SRC register does not work properly without the FIFO.

As I mentioned before, it is possible to read the tap direction only using the PULSE_SRC register.

I hope this information helps.

If I misunderstood your question, feel free to let me know.  I will be glad to help.

Have a great day.

David Diaz.

1,850 Views
fernandogomes
Contributor II

Hi David, thanks for your answer! Can you clarify how it is more efficient to read the FIFO then using the direction bits on the PULSE_SRC register? As far as I understand from the application note AN4072, after reading the FIFO it is neessary to calculate max and min and calculate the differences, while reading a single register (PULSE_SRC) there are already three bits that indicate the tap direction. I am having some issues identifying the tap direction, and even to distinguish between taps on different axis. I'm not getting coherent results, at least not enough stable that I can use them to replace onventional buttons. This is a prototype for a product for a customer that wants to remove all the enclosure buttons, so the acelerometer could be a good alternative, but I need to get coherent results, taps in one axis shouldn't trigger taps in other axis, for example. Do you know if it is possible to achieve this with this type of accelerometer? Do you know any example that I could use as a base for this type of use?

Best regards

Fernando

0 Kudos
Reply

1,850 Views
david_diaz
NXP Employee
NXP Employee

Hello Fernando,

You may review the Application Note AN4073, in order to get a better understanding of using the FIFO in the MMA845X.

Indeed, The FIFO is very beneficial for saving overall system power by putting the processor into sleep mode until it needs to process data from the accelerometer; in other words, the FIFO allows the processor to sleep longer while samples are being collected inside the sensor.

The AN4073 mentioned before, counts with example codes using the FIFO as well as the registers of importance for using it.

Please refer to the Chapter 5.2 in order to get the desired example code.

Feel free to let me know if this information is useful for you.

If I misunderstood your question, feel free to let me know.  I will be glad to help.

Have a great day.

David Diaz.

Note: If this post answers your question, please click the Correct Answer button. Thank you!

0 Kudos
Reply

1,850 Views
fernandogomes
Contributor II

Hi David,

Thank you very much for your help. I was reading the code you proposed, but unfortunatly the chip I'm using is the MMA8452Q, so it doesn't have the FIFO, only the MMA8451 has the FIFO, am I right? Any other sugestion? What I find is that even with 'simple' tap detection implemented (not using the FIFO, only the TAP detection bits, as defined in AN4072, section 6.1) it is common to get TAPs detected in the wrong axes, for example a TAP in the x axis gets an event in the Y or Z axis.Is there any recomendation to have better results? It works well to detect that a device got a TAP but not well to distinguish the TAP axis or direction.

Best regards

Fernando

0 Kudos
Reply

1,850 Views
david_diaz
NXP Employee
NXP Employee

Hello Fernando,

Please accept my apologies for the delay.

Indeed, unfortunately the MMA8452Q devices does not count with FIFO buffer.

A single tap event is configured by specifying two things; the threshold to be crossed and the time duration that it lasts.

I would recommend to configure the PULSE_THSX,Y,Z and PULSE_TMLT registers in order to improve the results.

tap detection.jpg

Please let me know if the issue remains despite configuring the registers mentioned.

Thank you for writing to the NXP communities.

Have a great day.

David

0 Kudos
Reply

1,850 Views
fernandogomes
Contributor II

Hi David, thanks for your answer. I am already using these registers, I'm programming it according to the AN4072, page 17:

// AN4072, pag 17, TAP and Double-TAP Detection
writeRegister(CTRL_REG1, 0x10); //200 Hz, Standby Mode
writeRegister(PULSE_CFG, 0x3F); //Enable X, Y, Z Single Pulse and X, Y and Z Double Pulse with DPA = 0 no double pulse abort
writeRegister(PULSE_THSX, 0x20); //Set X Threshold to 2g
writeRegister(PULSE_THSY, 0x20); //Set Y Threshold to 2g
writeRegister(PULSE_THSZ, 0x40); //Set Z Threshold to 4g
writeRegister(PULSE_TMLT, 0x18); //60 ms
writeRegister(PULSE_LTCY, 0x28); //200 ms
writeRegister(PULSE_WIND, 0x3C); //300 ms
writeRegister(CTRL_REG3, 0x02); //Interrupt polarity active high (FG)
writeRegister(CTRL_REG4, 0x08); //Enable Pulse Interrupt Block in System CTRL_REG4
writeRegister(CTRL_REG5, 0x08); //Route Pulse Interrupt Block to INT1 hardware Pin CTRL_REG5
uint8_t CTRL_REG1_Data = readRegister(CTRL_REG1); //Read out the contents of the register
CTRL_REG1_Data |= 0x01; //Change the value in the register to Active Mode.
writeRegister(CTRL_REG1, CTRL_REG1_Data); //Write in the updated value to put the device in Active Mode

What I reported as a non deterministic behavior I found later a way to reproduce it, please tell me if this is expected. During my tests I power the system (the init code above runs), I have the accelerometer held horizontally and the tap and double tap on the X and Y axis work well (I'm not using the Z axis). The problem occurs in the 'next day', I left the system powered during the night for other tests only MCU related, but since I'm using a breakout board for the accelerometer, connected by flexible wires to the MCU, it "falls" getting the accelerometer in the vertical position during all the night. In the morning after I grab again the accelerometer in the horizontal position but the X and Y taps and double taps don't work well. I validated this suspicion keeping the accelerometer horizontal during the night (it worked well in the morning), or resetting the MCU in the morning (the init code above runs again, and the taps and double taps starts working well immediately). Is this the expected behavior? Does it have to do with calibration?

Best regards

Fernando

0 Kudos
Reply

1,850 Views
david_diaz
NXP Employee
NXP Employee

Hello Fernando,

Once again, accept my apologies for the delay.

Definitively, that is a weird situation. I have never heard something like that.

I would like to know if the temperature changes during the night.

Please be aware that the temperature change could affect the performance of the system.

In this case I would recommend setting the MMA8452 registers as follow:

       I2C_WriteRegister(CTRL_REG1, 0x0C);             // ODR = 400Hz, Reduced noise, Standby mode

       I2C_WriteRegister(XYZ_DATA_CFG_REG, 0x00);      // +/-2g range -> 1g = 16384/4 = 4096 counts

       I2C_WriteRegister(CTRL_REG2, 0x02);             // High Resolution mode

  

       I2C_WriteRegister(PULSE_CFG_REG, 0x15);         //Enable X, Y and Z Single Pulse

       I2C_WriteRegister(PULSE_THSX_REG, 0x20);        //Set X Threshold to 2.016g

       I2C_WriteRegister(PULSE_THSY_REG, 0x20);        //Set Y Threshold to 2.016g

       I2C_WriteRegister(PULSE_THSZ_REG, 0x2A);        //Set Z Threshold to 2.646g

       I2C_WriteRegister(PULSE_TMLT_REG, 0x28);        //Set Time Limit for Tap Detection to 25 ms

       I2C_WriteRegister(PULSE_LTCY_REG, 0x28);        //Set Latency Time to 50 ms

       I2C_WriteRegister(CTRL_REG4, 0x08);             //Pulse detection interrupt enabled

       I2C_WriteRegister(CTRL_REG5, 0x08);             //Route INT1 to system interrupt

  

       CTRL_REG1_val = I2C_ReadRegister(CTRL_REG1);   //Active Mode

       CTRL_REG1_val |= 0x01;

       I2C_WriteRegister(CTRL_REG1, CTRL_REG1_val);

Please let me know if the issue remains besides this configuration.

Finally, I would like to share with you, a sample project that could be useful for you.

Please find the sample project at MMA8451Q -Single Tap Detection Bare metal example project .

I hope you find it useful.

If I misunderstood your question, feel free to let me know.  I will be glad to help.

Have a great day.

David Diaz.

1,850 Views
fernandogomes
Contributor II

Dear David, thanks for your help, I'll try with your code to see if it

solves the issue. Some temperature change might occur during the night (no

heating during the night), but it won't be larger than 2ºC to 3ºC I think,

so it doesn't seem to me that this should be the problem. And also if i

keep the sensor in the horizontal position during the night (or if I reset

the MCU in the morning) it still works well in the morning. I'll reply here

when I test with your code!

Best regards

Fernando

On Fri, Feb 19, 2016 at 12:48 AM, david_diaz <admin@community.freescale.com>

0 Kudos
Reply