AN3917 Rev 0, 02/2010 Freescale Semiconductor Application Note Motion and Freefall Detection Using the MMA8450Q by: Kimberly Tuck Applications Engineer 1.0 Introduction The MMA8450Q has two (2) embedded functions for both Motion and/or Freefall along with a very flexible interrupt routing scheme. Motion is often used to simply alert the main processor that the device is currently in use. This can be accomplished with the Motion function and/or with the Transient function, described in AN3918. The motion detection is an embedded function that can save overall system power by using an interrupt scheme. This feature alerts the main processor when a motion/tilt threshold or Freefall event has occurred. Result: This feature saves the system processor from reading out the XYZ data continually and running a software algorithm to compare data with thresholds. 1.1 Key Words Motion, Freefall, Interrupt, Transient Detection, Acceleration, Tumble, Debounce, Embedded, Tilt, Configuration Registers, DBCNTM bit, Threshold, Sensor © Freescale Semiconductor, Inc., 2010. All rights reserved. TABLE OF CONTENTS 1.0 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.1 Key Words . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.2 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 2.0 MMA8450Q Consumer 3-axis Accelerometer 3 x 3 x 1 mm . . . . . . . . . . . . . . 2 2.1 Key Features of the MMA8450Q . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 2.2 Two (2) Programmable Interrupt Pins for 8 Interrupt Sources 2 2.3 Application Notes for the MMA8450Q . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 3.0 Motion and Freefall Applications Using the MMA8450Q Accelerometer . . 3 3.1 Freefall Detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 3.2 Motion Detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 3.3 Signature of Linear Freefall and Rotational Fall . . . . . . . . . . . . . . . . . . . . . . . 4 3.4 Motion/Freefall Embedded Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 4.0 Register Settings for the Motion/ Freefall Function . . . . . . . . . . . . . . . . . . . 4 4.1 Register 0x23: FF/MT Config 1 - Configuration Register . . . . . . . . . . . . . . . . 4 4.1.1 Configuring the MMA8450Q for Motion Detection . . . . . . . . . . . . . . . . 5 4.1.2 Configuring the MMA8450Q for Freefall Detection . . . . . . . . . . . . . . . 5 4.2 Register 0x25 FF_MT_THS_1 Register (Read/Write) - Setting the Threshold . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5 4.2.1 Example: Setting the Threshold for Motion Detection . . . . . . . . . . . . . 7 4.2.2 Example: Setting the Threshold for Freefall Detection . . . . . . . . . . . . 7 4.3 Register 0x26 FF_MT_COUNT_1 Register (Read/Write) - Setting the Debounce Counter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 4.4 Register 0x24 FF_MT_SRC_1 Register (Read Only) - Motion/Freefall Source Detection Register 7 5.0 Configuring the Motion/Freefall to an Interrupt Pin . . . . . . . . . . . . . . . . . . . . 8 6.0 Details for Configuring the MMA8450Q for Motion/Freefall Detection . . . . 9 6.1 Example Steps for Configuring Motion Detection . . . . . . . . . . . . . . . . . . . . . 10 6.2 Example Steps for Configuring Linear Freefall Detection . . . . . . . . . . . . . . . 11 1.2 Summary A. The advantage of having two embedded functions to detect either Motion or linear Freefall which are routed to the choice of two interrupt pins allows for many combinations of events to be detected meeting the needs of many different use cases. For example: The embedded Motion/Freefall function can be used to detect a tumble using both the linear Freefall on one channel and the Motion detection to detect the spin on another channel. B. The status register for the Motion/Freefall function is only read when a change has occurred. C. Less processing is required on the microcontroller or processor with the embedded function since the condition is detected internally. The XYZ registers are not polled and data is not manipulated by the processor to detect the events. D. The threshold and debounce counter are changeable in either the active or standby mode to allow for adjustments after the part has transitioned from the wake to the sleep mode. E. Motion detection varies from Transient detection. The motion detection can trigger on a change in a static acceleration value such as tilt. F. The latch will hold the EA bit until the status register is read to indicate an event is active, but the other bits in the status register are never latched. The status must be read immediately to determine the condition of the axes when an event occurs. 2.0 MMA8450Q Consumer 3-axis Accelerometer 3 x 3 x 1 mm NC VDD 16 15 14 1 NC 3 SCL 4 GND 5 16 Pin QFN 3mm x 3 mm x 1mm 13 GND 12 GND 11 INT1 10 GND 9 6 7 8 EN 2 SA0 NC MMA8450Q SDA VDD NC The MMA8450Q has a selectable dynamic range of ±2g, ±4g and ±8g with sensitivities of 1024 counts/g, 512 counts/g and 256 counts/g respectively. The device offers either 8-bit or 12-bit XYZ output data for algorithm development. The chip shot and pinout are shown in Figure 1. INT2 Figure 1. MMA8450Q Consumer 3-axis Accelerometer 3 x 3 x 1 mm 2.1 Key Features of the MMA8450Q 1. 2. 3. 4. 5. 6. 7. 2.2 Shutdown Mode: Typical < 1 μA, Standby Mode 3 μA Low Power Mode current consumption ranges from 27 μA (1.56 - 50 Hz) to 120 μA (400 Hz) Normal Mode current consumption ranges from 42 μA (1.56 - 50 Hz) to 225 μA (400 Hz) I2C digital output interface (operates up to 400 kHz Fast Mode) 12-bit and 8-bit data output, 8-bit high pass filtered data output Post Board Mount Offset < ±50 mg typical Self Test X, Y and Z axes Two (2) Programmable Interrupt Pins for 8 Interrupt Sources 1. Embedded 4 channels of Motion detection a. Freefall or Motion detection: 2 channels b. Tap detection: 1 channel c. Transient detection: 1 channel 2. Embedded orientation (Portrait/Landscape) detection with hysteresis compensation 3. Embedded automatic ODR change for auto-wake-up and return-to-sleep 4. Embedded 32 sample FIFO 5. Data Ready Interrupt AN3917 2 Sensors Freescale Semiconductor 2.3 Application Notes for the MMA8450Q The following is a list of Freescale Application Notes written for the MMA8450Q: • AN3915, Embedded Orientation Detection Using the MMA8450Q • AN3916, Offset Calibration of the MMA8450Q • AN3917, Motion and Freefall Detection Using the MMA8450Q • AN3918, High Pass Filtered Data and Transient Detection Using the MMA8450Q • AN3919, MMA8450Q Single/Double and Directional Tap Detection • AN3920, Using the 32 Sample First In First Out (FIFO) in the MMA8450Q • AN3921, Low Power Modes and Auto-Wake/Sleep Using the MMA8450Q • AN3922, Data Manipulation and Basic Settings of the MMA8450Q • AN3923, MMA8450Q Design Checklist and Board Mounting Guidelines 3.0 Motion and Freefall Applications Using the MMA8450Q Accelerometer There are many applications that could potentially use Motion and/or Freefall. Some examples are the following: • Simpler motion signatures for gesturing (tilt thresholds, generic motions, linear freefalls • Human motion monitoring (specific parameters for motion and freefall) • Tamper detection on doors (detecting a threshold is exceeded or a change in tilt) • Shock detection or motion detection tracking assets (a threshold is exceeded) • Risk of an object falling: hard disk drives (linear freefall and motion) • Field meter monitoring for large motion/falls of the meters (tilt threshold change) 3.1 Freefall Detection The Freefall function of the MMA8450Q detects linear freefall when X and Y and Z are below a set threshold. Typically this set threshold is below 0.35g. Although Freefall is often considered to be linear, this is often not entirely true in many fall use cases. Many falls can be tumbles which may cause the object to spin while falling. 3.2 Motion Detection Motion detection can be used to alert that the device has exceeded a specific acceleration. This event could be due to a tilt or due to an acceleration that exceeds a value from a linear motion as shown Figure 2. Figure 2. Motion Detection per Tilt or Linear Acceleration The motion function can be used for detecting tumble. The signature of a tumble is shown in Figure 3. During the rotation of the tumble the magnitude of the three axes is much greater than 0g. In order to detect tumble, for example, the motion detection condition must be set to detect for X or Y or Z > 2g. It is also important to set the debounce counter to about 100 ms to avoid false readings. The debounce counter acts like a filter to determine whether the condition exists for 100 ms or longer. AN3917 Sensors Freescale Semiconductor 3 Figure 3. Rotational Freefall Signature 3.3 Signature of Linear Freefall and Rotational Fall Figure 4, shows the signature of a Linear Freefall and a Rotational Fall. Both are falling events that require different conditions for detection. To be able to capture either a Linear Freefall or a Rotational Fall, the Motion/Freefall1 embedded function can be used to detect the Linear Freefall while the Motion/Freefall2 can be used to detect the Rotational Fall (motion) or vise versa. Each function can be routed to the same interrupt pin or routed to separate interrupt pins. Figure 4. Fall Event Showing Linear and Rotational Fall 3.4 Motion/Freefall Embedded Function The Motion function of the MMA8450Q compares the enabled X, Y, and/or Z-axis to determine if the acceleration output is greater than the set threshold. It does not compare a change in acceleration. Therefore, a tilt value could exceed the threshold to make this condition true. If an exact change in acceleration is the desired output the embedded transient detection can be used to configure the change in acceleration level for Motion detection. The transient detection eliminates the effects of gravity by passing the data through a high pass filter to eliminate static accelerations. 4.0 Register Settings for the Motion/ Freefall Function There are four (4) registers associated with the Motion/Freefall embedded function. Note the Motion Freefall1 and the Motion/Freefall2 have the same configuration and functionality. 1. Register 0x23 FF/MT Config 1 - Motion/Freefall Configuration 2. Register 0x25 FF_MT_THS_1 - Setting the Threshold 3. Register 0x26 FF_MT_COUNT_1 - Setting the Debounce Counter 4. Register 0x24 FF_MT_SRC_1 - Motion/Freefall Source Detection Refer to Table 11 for the complete list of all registers that can be used with Motion/Freefall. AN3917 4 Sensors Freescale Semiconductor 4.1 Register 0x23: FF/MT Config 1 - Configuration Register The first register is the Motion/Freefall Configuration Register shown in Table 1. This register determines which axes to enable with regards to three (3) conditions: 1. Which axes will be involved, 2. Whether the event will be a linear freefall or a motion and, 3. Whether the event detected should be latched or not into the source register. Table 1. Register 0x23: FF/MT Config 1 - Configuration Register (Read/Write) and Description Reg 0x23 ELE OAE ZHEFE ZLEFE YHEFE YLEFE XHEFE XLEFE Motion 1 1 0 0 1 0 1 0 Freefall 1 0 0 1 0 1 0 1 4.1.1 Configuring the MMA8450Q for Motion Detection For Motion detection the condition should be set for the enabled axes to exceed the threshold. The logic will be an “OR” condition to make the condition true. The “high” condition bits should be enabled only, since Motion is detecting a (>) greater than threshold condition. Therefore ZHEFE, YHEFE and XHEFE are valid for Motion detection. Note the low condition bits such as XLEFE, YLEFE and ZLEFE are not valid. In this example shown in Table 2. only the X and Y axes are considered. Table 2. Motion Example 1: X or Y > 3g Reg 0x23 ELE OAE ZHEFE ZLEFE YHEFE YLEFE XHEFE XLEFE Motion 1 1 0 0 1 0 1 0 Example Code: IIC_RegWrite(0x23, 0xCA); //Enable Latch, Motion, X-axis, Y-axis 4.1.2 Configuring the MMA8450Q for Freefall Detection For Freefall detection the condition should be set so that the enabled axes have an acceleration value below (<) the threshold. The logic will be an “And” condition to make the condition true. Note that all axes do not necessarily need to be enabled, but for a true freefall condition it is advised to set all three axes. In the Freefall Mode the ZLEFE, YLEFE and XLEFE bits are valid. Note that the ZHEFE, YHEFE and XHEFE are not valid since they are used for Motion detection only. An example of linear freefall is shown in Table 3. Table 3. Freefall Example 1: X AND Y AND Z < 0.2g Reg 0x23 ELE OAE ZHEFE ZLEFE YHEFE YLEFE XHEFE XLEFE Freefall 1 0 0 1 0 1 0 1 Example Code: IIC_RegWrite(0x23, 0x95); //Enable Latch, Freefall, X-axis, Y-axis and Z-axis 4.2 Register 0x25 FF_MT_THS_1 Register (Read/Write) - Setting the Threshold The threshold for the event is set in Register 0x25, shown in Table 4. The minimum threshold resolution is dependent on the selected acceleration g range and the threshold register has a range of 0 to 127 counts. Therefore: • If the selected acceleration g range is 8g mode (FS = 11), the minimum threshold resolution is 0.063g/LSB. The maximum threshold is 8g. • If the selected acceleration g range is 4g mode (FS = 10), the minimum threshold resolution is 0.0315g/LSB. The maximum threshold is 4g • If the selected acceleration g range is 2g mode (FS = 01), the minimum threshold resolution is 0.01575g/LSB. The maximum threshold is 2g. Table 4. Register 0x25 FF_MT_THS_1 Register (Read/Write) Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 DBCNTM THS6 THS5 THS4 THS3 THS2 THS1 THS0 Note: • For Motion detection the condition is > Threshold (Figure 5) • For Freefall the condition is < Threshold (Figure 5) • All thresholds are absolute value. AN3917 Sensors Freescale Semiconductor 5 +Full Scale X (Y, Z) High g Region High g+ Threshold X (Y, Z) Low g Region Positive Acceleration Low g Threshold High g- Threshold Negative Acceleration X (Y, Z) High g Region -Full Scale Figure 5. Freefall Condition (Illustration) The DCNTM bit is best understood from the diagram in Figure 6. The default value is for the counter to be in the increment/decrement mode. Low g Event on all 3-axis (Freefall) Count Threshold (a) FF_MT Counter Value EA FF Low g Event on all 3-axis (Freefall) DBCNTM = 1 Count Threshold FF_MT Counter Value (b) EA FF Low g Event on all 3-axis (Freefall) DBCNTM = 0 Count Threshold FF_MT Counter Value (c) EA FF Figure 6. DBCNTM Bit Function (Illustration) AN3917 6 Sensors Freescale Semiconductor 4.2.1 Example: Setting the Threshold for Motion Detection Motion Example 1: X or Y > 3g The device must be in either 4g or 8g mode. Assuming the device is in 4g mode, therefore, the step count would be 0.0315g/LSB; therefore 3g/0.0315g = 95.2, which can be rounded to 96 counts. Note the threshold can be changed in either the Active or the Standby Mode. This may be useful for readjusting the threshold while in the active mode after an event has occurred. The DBCNTM bit will be kept cleared. Example Code: IIC_RegWrite(0x25, 0x60); //Set Threshold to 96 counts 4.2.2 Example: Setting the Threshold for Freefall Detection Freefall Example 1: X AND Y AND Z < 0.2g In this example the device could be either 2g, 4g, or 8g mode. Assuming 2g mode, the step count is 0.01575g/LSB. Therefore 0.2g/0.01575g = 12.7, which rounds to 13 counts. Also for this example the DBCNTM bit will be kept cleared to filter out spurious noise. Example Code: IIC_RegWrite(0x25, 0x0D); // Set Threshold to 13 counts 4.3 Register 0x26 FF_MT_COUNT_1 Register (Read/Write) - Setting the Debounce Counter Register 0x26 shown in Table 5 is an 8-bit counter used for low pass filtering. Table 5. Register 0x26 FF_MT_COUNT_1 (Read/Write) Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 D7 D6 D5 D4 D3 D2 D1 D0 The time step used for the debounce sample count depends on the ODR chosen. The relationship is shown inTable 6. Table 6. FF_MT_COUNT_1 Relationship with the ODR Output Data Rate (Hz) Step Duration Range 400 2.5 ms 2.5 ms – 0.637s 200 5 ms 5 ms – 1.275s 100 10 ms 10 ms – 2.55s 50 20 ms 20 ms – 5.1s 12.5 80 ms 80 ms – 20.4s 1.56 640 ms 640 ms – 163s An ODR of 100 Hz and a FF_MT_COUNT_1 value of 10 would result in minimum debounce response time of 100 ms. Note: the debounce counter can be changed in the active or the standby mode. This may be desirable when the device changes from the wake mode to the sleep mode as the ODR may change. This will change the timing of the debounce counter. Example Code: IIC_RegWrite(0x26, 0x0A); // 100 ms debounce timing 4.4 Register 0x24 FF_MT_SRC_1 Register (Read Only) - Motion/Freefall Source Detection Register Register 0x24 shown in Table 7 keeps track of the acceleration events which trigger. The EA (Event Active) bit is used in combination with the INT_EN_FF_MT_1 bit (Register 0x3B) and INT_CFG_FF_MT_1 bit (Register 0x3C) to generate the Freefall/Motion interrupt in register 0x15 (System Status Interrupt Register). Note: When the latch is enabled in Register 0x23 (Bit 7 ELE) only the “EA” bit, Bit 6 will remain set until the source register is read. Reading the source register clears the interrupt in Register 0x15 and clears the EA bit in Register 0x24. Table 7. Events Detected in the Motion/Freefall Source Detection Register (Read Only) and Legend Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 — EA ZHE ZLE YHE YLE XHE XLE AN3917 Sensors Freescale Semiconductor 7 5.0 Configuring the Motion/Freefall to an Interrupt Pin In order to set up the system to route to a hardware interrupt pin, the System Interrupt (Bit 1or 2 in Reg 0x3B) must be enabled. The MMA8450Q allows for eight (8) separate types of interrupts. Two (2) of these are reserved for Motion/Freefall. There is one for Motion/Freefall1 and one for Motion/Freefall2. For example, to configure the Motion/Freefall1 function, the following two steps should be followed. Step 1: Enable the Interrupt Bit 1 and/or Bit 2 in Register 0x3B shown in Table 8. Table 8. 0x3B CTRL_REG4 Register (Read/Write) – Interrupt Enable Description and Legend Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 INT_EN_ASLP INT_EN_FIFO INT_EN_TRANS INT_EN_LNDPRT INT_EN_PULSE Bit 2 Bit 1 INT_EN_FF_MT_1 INT_EN_FF_MT_2 Bit 0 INT_EN_DRDY The corresponding interrupt enable bit allows the Motion/Freefall interrupt to route its event detection flag to the interrupt controller of the system. The interrupt controller routes the enabled function to the INT1 or INT2 pin. To enable the Freefall/Motion1 function, set Bit 2 in Register 0x3B as follows: Example Code: IIC_RegWrite(0x3B, 0x04); Step 2: Route the interrupt to INT1 or to INT2. This is done in register 0x3C shown in Table 9. Table 9. 0x3C CTRL_REG5 Register (Read/Write) Bit 7 Bit 6 INT_CFG_ASLP INT_CFG_FIFO Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 INT_CFG_TRANS INT_CFG_LNDPRT INT_CFG_PULSE INT_CFG_FF_MT_1 INT_CFG_FF_MT_2 INT_CFG_DRDY Note: To set Motion/Freefall1 to INT1 set Bit 2 in register 0x3C. Example Code: IIC_RegWrite(0x3C,0x04); 5.1 Reading the System Interrupt Status Source Register In the interrupt source register shown in Table 10 the status of the various embedded functions can be determined. The bits that are set (logic ‘1’) indicate which function has asserted an interrupt; conversely, the bits that are cleared (logic ‘0’) indicate which function has not asserted or has de-asserted an interrupt. The interrupts are rising edge sensitive. The bits are set by a low to high transition and are cleared by reading the appropriate interrupt source register. Table 10. 0x15 INT_SOURCE: System Interrupt Status Register (Read Only) Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 SRC_ASLP SRC_FIFO SRC_TRANS SRC_LNDPRT SRC_PULSE SRC_FF_MT_1 SRC_FF_MT_2 SRC_DRDY AN3917 8 Sensors Freescale Semiconductor AN3917 9 6.0 Details for Configuring the MMA8450Q for Motion/Freefall Detection The registers of importance for configuring the MMA8450Q for Motion detection or Freefall detection are listed in Table 11. Table 11. Registers of Importance for Setting up the Motion/Freefall Detection Sensors Freescale Semiconductor Reg Name Definition Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 15 INT_SOURCE Interrupt Status R SRC_ASLP SRC_FIFO SRC_TRANS SRC_LNDPRT SRC_PULSE SRC_FF_MT_1 SRC_FF_MT_2 SRC_DRDY 23 FF_MT_CFG_1 FF/Motion Config 1 R/W ELE OAE ZHEFE ZLEFE YHEFE YLEFE XHEFE XLEFE 24 FF_MT_SRC_1 FF/Motion Source 1 R — EA ZHE ZLE YHE YLE XHE XLE 25 FF_MT_THS_1 FF/Motion Threshold 1 R/W DBCNTM THS6 THS5 THS4 THS3 THS2 THS1 THS0 26 FF_MT_COUNT_1 FF/Motion Debounce R/W D7 D6 D5 D4 D3 D2 D1 D0 27 FF_MT_CFG_2 FF/Motion Config 2 R/W ELE OAE ZHEFE ZLEFE YHEFE YLEFE XHEFE XLEFE 28 FF_MT_SRC_2 FF/Motion Source 2 R — EA ZHE ZLE YHE YLE XHE XLE 29 FF_MT_THS_2 FF/Motion Threshold 2 R/W DBCNTM THS6 THS5 THS4 THS3 THS2 THS1 THS0 2A FF_MT_COUNT_2 FF/Motion Debounce 2 R/W D7 D6 D5 D4 D3 D2 D1 D0 3B CTRL_REG4 Control Reg4 R/W (Interrupt Enable Map) INT_EN _ASLP INT_EN _FIFO INT_EN _TRANS INT_EN_LNDPRT INT_EN_PULSE INT_EN_FF_MT_1 INT_EN_FF_MT_2 INT_EN_DRDY 3C CTRL_REG5 Control Reg5 R/W (Interrupt Configuration) INT_CFG_ASLP INT_CFG_FIFO INT_CFG_TRANS INT_CFG_FF_MT_1 INT_CFG_FF_MT_2 INT_CFG_DRDY INT_CFG_LNDPRT INT_CFG_PULSE 6.1 Example Steps for Configuring Motion Detection X or Y >3g using MFF1Function 4g, 100 Hz ODR Step 1: Put the device into Standby Mode: Register 0x38 CtrlReg1 IIC_RegWrite(0x38, 0x08); // Set the device in 100 Hz ODR, Standby Step 2: Set Configuration Register for Motion Detection by setting the “OR” condition OAE = 1, enabling XHigh and YHigh and the latch IIC_RegWrite(0x23,0xCA) Step 3: Threshold Setting Value for the Motion detection of > 3g Note: In 4g mode each count is 31.5 mg • 3g/0.0315g = 95.2; // Round up to 96 IIC_RegWrite(0x25, 0x60) Step 4: Set the debounce counter to eliminate false readings for 100 Hz sample rate with a requirement of 100 ms timer. Note: 100 ms/10 ms (steps) = 10 counts IIC_RegWrite(0x26, 0x0A); Step 5: Enable Motion/Freefall1 Interrupt Function in the System (Ctrl Reg4) IIC_RegWrite(0x3B, 0x04); Step 6: Route the Motion/Freefall1 Interrupt Function to INT 1 hardware pin (CtrlReg5) IIC_RegWrite(0x3C, 0x04); Step 7: Put the device in 4g Active Mode IIC_RegWrite(0x38, 0x0A); //100Hz, 4g Mode Step 8: Write Interrupt Service Routine Reading the System Interrupt Status and the Motion/Freefall1 Status Interrupt void isr_KBI (void) { //clear the interrupt flag CLEAR_KBI_INTERRUPT; //Determine source of interrupt by reading the system interrupt IntSourceSystem=IIC_RegRead(0x15); // Set up Case statement here to service all of the possible interrupts if ((Int_SourceSystem &0x04)==0x04) { //Perform an Action since Motion Flag has been set //Read the Motion/Freefall1 Function to clear the interrupt IntSourceMFF1=IIC_RegRead(0x24); //Can parse out data to perform a specific action based on the //axes that made the condition true } } AN3917 10 Sensors Freescale Semiconductor 6.2 Example Steps for Configuring Linear Freefall Detection X AND Y AND Z <0.2g using MFF2Function 2g Mode, 50Hz ODR Step 1: Put the device in Standby Mode: Register 0x38 CtrlReg1 IIC_RegWrite(0x38, 0x0C); // Set the device in 50 Hz ODR, Standby Step 2: Configuration Register set for Freefall Detection enabling “AND” condition, OAE = 0, Enabling XLow, YLow, ZLow, and the Latch IIC_RegWrite(0x27, 0x95); Step 3: Threshold Setting Value for the resulting acceleration < 0.2g Note: In 2g mode each count is 15.75 mg • 0.2g/0.01575 = 12.7 counts // Round up to 13 counts IIC_RegWrite(0x29, 0x0D); Step 4: Set the debounce counter to eliminate false positive readings for 50Hz sample rate with a requirement of 120 ms timer. Note: 120 ms/20 ms (steps) = 6 counts IIC_RegWrite(0x2A, 0x06); Step 5: Enable Motion/Freefall2 Interrupt Function in the System (Ctrl Reg 4) IIC_RegWrite(0x3B, 0x02); Step 6: Route the Motion/Freefall2 Interrupt Function to INT 2 hardware pin (CtrlReg5) IIC_RegWrite(0x3C, 0x00); Step 7: Put the device in 2g Active Mode, 50 Hz IIC_RegWrite(0x38, 0x0D); Step 8: Write Interrupt Service Routine Reading the System Interrupt Status and the Motion/Freefall2 Status Interrupt void isr_KBI (void) { //clear the interrupt flag CLEAR_KBI_INTERRUPT; //Determine source of the interrupt by first reading the system interrupt IntSourceSystem=IIC_RegRead(0x15); // Set up Case statement here to service all of the possible interrupts if ((IntSourceSystem&0x02)==0x02) { //Perform an Action since Freefall Flag has been set //Read the Motion/Freefall2 Function to clear the interrupt IntSourceMFF2=IIC_RegRead(0x28); //Can parse out data to perform a specific action based on the axes } } AN3917 Sensors Freescale Semiconductor 11 How to Reach Us: Home Page: www.freescale.com Web Support: http://www.freescale.com/support USA/Europe or Locations Not Listed: Freescale Semiconductor, Inc. Technical Information Center, EL516 2100 East Elliot Road Tempe, Arizona 85284 1-800-521-6274 or +1-480-768-2130 www.freescale.com/support Europe, Middle East, and Africa: Freescale Halbleiter Deutschland GmbH Technical Information Center Schatzbogen 7 81829 Muenchen, Germany +44 1296 380 456 (English) +46 8 52200080 (English) +49 89 92103 559 (German) +33 1 69 35 48 48 (French) www.freescale.com/support Japan: Freescale Semiconductor Japan Ltd. Headquarters ARCO Tower 15F 1-8-1, Shimo-Meguro, Meguro-ku, Tokyo 153-0064 Japan 0120 191014 or +81 3 5437 9125 [email protected] Asia/Pacific: Freescale Semiconductor China Ltd. Exchange Building 23F No. 118 Jianguo Road Chaoyang District Beijing 100022 China +86 10 5879 8000 [email protected] For Literature Requests Only: 1-800-441-2447 or +1-303-675-2140 Fax: +1-303-675-2150 [email protected] Information in this document is provided solely to enable system and software implementers to use Freescale Semiconductor products. There are no express or implied copyright licenses granted hereunder to design or fabricate any integrated circuits or integrated circuits based on the information in this document. Freescale Semiconductor reserves the right to make changes without further notice to any products herein. Freescale Semiconductor makes no warranty, representation or guarantee regarding the suitability of its products for any particular purpose, nor does Freescale Semiconductor assume any liability arising out of the application or use of any product or circuit, and specifically disclaims any and all liability, including without limitation consequential or incidental damages. “Typical” parameters that may be provided in Freescale Semiconductor data sheets and/or specifications can and do vary in different applications and actual performance may vary over time. All operating parameters, including “Typicals”, must be validated for each customer application by customer’s technical experts. Freescale Semiconductor does not convey any license under its patent rights nor the rights of others. Freescale Semiconductor products are not designed, intended, or authorized for use as components in systems intended for surgical implant into the body, or other applications intended to support or sustain life, or for any other application in which the failure of the Freescale Semiconductor product could create a situation where personal injury or death may occur. Should Buyer purchase or use Freescale Semiconductor products for any such unintended or unauthorized application, Buyer shall indemnify and hold Freescale Semiconductor and its officers, employees, subsidiaries, affiliates, and distributors harmless against all claims, costs, damages, and expenses, and reasonable attorney fees arising out of, directly or indirectly, any claim of personal injury or death associated with such unintended or unauthorized use, even if such claim alleges that Freescale Semiconductor was negligent regarding the design or manufacture of the part. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2010. All rights reserved. AN3917 Rev. 0 02/2010