AN4071, High-Pass Filtered Data and Transient Detection Using the MMA8451, 2, 3Q - Application Notes

Document Number: AN4071
Rev 1, 10/2011
Freescale Semiconductor
Application Note
High-Pass Filtered Data and Transient
Detection Using the MMA8451, 2, 3Q
by: Kimberly Tuck
Applications Engineer
1.0
Introduction
The acceleration readings from the sensor couple both
static and dynamic accelerations. Many tilt based applications
such as orientation detection, scrolling and tilt based gaming
apps use the accelerometer analyzing the change in static
acceleration due to gravity only. These functions are often
best when they’ve been low-pass filtered because the highfrequency data is considered noise. There are many functions
where the accelerometer must analyze the dynamic
acceleration. Functions such as taps, flicks, shakes and step
counting are based on the analysis of the change in the
acceleration with no regard for the static acceleration. These
functions interpret the acceleration threshold change and
direction of motion. It is simpler to interpret the dynamic
acceleration data when the static component has been
removed.
The MMA8451, 2, 3Q has a built-in high-pass filter. In the
MMA8451, 2Q the output data can go through the high-pass
filter, eliminating the offset (DC) and low frequencies (well
below the cutoff). Note that the MMA8453Q does not have the
capability to read out data from the high-pass filter. The highpass filter cutoff frequency can be set by the user to four
different frequencies which are dependent on the Output Data
Rate (ODR) and the oversampling mode. A higher cutoff
frequency ensures the DC data or slower moving data will be
filtered out, allowing only the higher frequencies to pass. The
MMA8451, 2, 3Q contain an embedded transient function
which analyzes the high-pass filtered data allowing the user to
set a preset threshold with an added debounce counter to
ensure the event happens for a set duration. The threshold
represents a change in acceleration to be exceeded. This
embedded function can be routed to an interrupt pin to detect
jolts on different axes and will display the direction of the jolt.
© 2010, 2011 Freescale Semiconductor, Inc. All rights reserved.
TABLE OF CONTENTS
1.0 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1 Key Words . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2.0 MMA8451, 2, 3Q Consumer 3-axis Accelerometer 3 by 3 by 1 mm . . . . . 2
2.1 Output Data, Sample Rates and Dynamic Ranges of all Three Products . . . 3
2.1.1 MMA8451Q . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.1.2 MMA8452Q . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.1.3 MMA8453Q Note: No HPF Data. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
3.0 Comparison of Motion Detection and Transient Detection . . . . . . . . . . . 3
3.1 Use Case 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
3.2 Use Case 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
4.0 Transient Settings and Interpretation of the Data . . . . . . . . . . . . . . . . . . 5
4.1 High-Pass Filter Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
5.0 Using the HPF Data to Write Algorithms such as Directional Shake . . . 7
6.0 Configuring the Embedded Transient Detection . . . . . . . . . . . . . . . . . . . 9
6.1 Register 0x1D:TRANSIENT_CFG Transient Configuration Register . . . . . . . 9
6.2 Register 0x1F: TRANSIENT_THS Transient Threshold Register . . . . . . . . 10
6.3 Register 0x20: TRANSIENT_COUNT Transient Debounce Register . . . . . . 10
6.4 Register 0x1E:TRANSIENT_SRC Transient Source Register . . . . . . . . . . . 11
6.5 Configuring the Transient Detection to an Interrupt Pin. . . . . . . . . . . . . . . . . 11
6.6 Reading the System Interrupt Status Source Register . . . . . . . . . . . . . . . . . 11
7.0 Details for Configuring the MMA8451, 2, 3Q for Transient Detection . 12
Table 11.Registers of Importance for Setting up the Transient Detection and Using
the HPF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
7.1 Example Steps for Configuring Transient Detection . . . . . . . . . . . . . . . . . . . 13
1.1
Key Words
Accelerometer, Static Acceleration, Image Stabilization, HighPass Filter (HPF), Transient, HPF Data, 3-Axis
Accelerometer, Embedded Motion Detection, Embedded
Transient Detection, Vibration, Shake, Directional Shake,
Displacement, Velocity, Sensor, Interrupt, DBCNTM Bit, Jolt
1.2
Summary
A. The high-pass filter is used to eliminate the static acceleration when the HPF_OUT bit is set.
B. Different cutoff frequencies from the high-pass filter affect the output data and the embedded functions using the
high-pass filter.
C. The high-pass filtered data is useful for writing algorithms which require an analysis of the change in acceleration
and simplifies the data analysis by eliminating the static acceleration.
D. The transient function is interrupt driven and saves on current consumption and unnecessary processing because
the logic is internal to the sensor.
E. An algorithm for directional shake can be reliably detected by analyzing the (high-pass filter) data.
F. The high-pass filter data can be used for image stability applications, compensating for the jitter of the user’s hands
and/or from the environment.
G. The transient function can be used to detect a change in acceleration that exceeds a set threshold. This is slightly
different than the motion detection function.
H. The transient threshold and debounce counter can be changed in either standby or active mode to allow for
adjustments after the part has transitioned from wake to sleep mode.
I. Note the MMA8453Q does not have the option for high-pass filtered data, although it does contain the transient
function and the tap function uses the high-pass filter.
2.0
MMA8451, 2, 3Q Consumer 3-axis Accelerometer 3 by 3 by 1 mm
2
NC
3
SCL
4
GND
5
NC
VDD
14
MMA845xQ
16-Pin QFN
(Top View)
6
7
13
NC
12
GND
11
INT1
10
GND
9
INT2
8
NC
BYP
15
SA0
1
16
SDA
VDDIO
NC
The MMA8451, 2, 3Q has a selectable dynamic range of ±2g, ±4g, ±8g. The device has 8 different output data rates, selectable
high-pass filter cutoff frequencies, and high-pass filtered data. The available resolution of the data and the embedded features is
dependant on the specific device.
Note: The MMA8450Q has a different memory map and has a slightly different pinout configuration.
Figure 1. MMA8451, 2, 3Q Consumer 3-axis Accelerometer 3 by 3 by 1 mm
AN4071
2
Sensors
Freescale Semiconductor, Inc.
2.1
2.1.1
Output Data, Sample Rates and Dynamic Ranges of all Three Products
MMA8451Q
1. 14-bit data
2g (4096 counts/g = 0.25 mg/LSB) 4g (2048 counts/g = 0.5 mg/LSB) 8g (1024 counts/g = 1 mg/LSB)
2. 8-bit data
2g (64 counts/g = 15.6 mg/LSB) 4g (32 counts/g = 31.25 mg/LSB) 8g (16 counts/g = 62.5 mg/LSB)
3. Embedded 32 sample FIFO (MMA8451Q)
2.1.2
MMA8452Q
1. 12-bit data
2g (1024 counts/g = 1 mg/LSB) 4g (512 counts/g = 2 mg/LSB) 8g (256 counts/g = 3.9 mg/LSB)
2. 8-bit data
2g (64 counts/g = 15.6 mg/LSB) 4g (32 counts/g = 31.25 mg/LSB) 8g (16 counts/g = 62.5 mg/LSB)
2.1.3
MMA8453Q Note: No HPF Data
1. 10-bit data
2g (256 counts/g = 3.9 mg/LSB) 4g (128 counts/g = 7.8 mg/LSB) 8g (64 counts/g = 15.6 mg/LSB)
2. 8-bit data
2g (64 counts/g = 15.6 mg/LSB) 4g (32 counts/g = 31.25 mg/LSB) 8g (16 counts/g = 62.5 mg/LSB)
3.0
Comparison of Motion Detection and Transient Detection
The transient function (with HPF enabled) is different from the motion detection embedded function in MMA8451, 2, 3Q. Refer
to Freescale application note AN4070 for details on the motion detection. The intended use of these functions is different.
A. The embedded motion function triggers an interrupt when any of the enabled axes has exceeded a set acceleration
threshold.
• Motion detection is useful when the device may be tilted in an orientation and the interest is to know if the
acceleration in one axis has crossed a specified threshold amount measured from 0g.The motion detection
analyzes change in threshold considering both static and dynamic acceleration.
B. The transient detection embedded function compares whether any of the enabled axes has exceeded a set change
in acceleration disregarding the static acceleration. The data that is compared to the threshold to be exceeded is
high-pass filtered data.
• Transient detection is useful when the device may be tilted in an orientation (i.e., there is some non-zero reading
on one or more of X, Y and Z) and the interest is more on the dynamic acceleration crossing a specified threshold
amount in a short amount of time (frequency being the reciprocal of time) regardless of what the current value is.
Example
If a change in acceleration of 0.5g in any axes was the target for an application, then it would be challenging to use the embedded motion detection function for detecting this change. The reason for this can be better understood with an example:
Assume that the device was oriented such that X = 0.24g, Y = 0.44g and Z = 0.82g; it would be challenging to detect a 0.5g
change in acceleration in any of the axes using the motion detect function since the new readings have to be outside the range
X = -0.26g to 0.74g, Y = -0.06g to 0.94g and Z = 0.32g to 1.32g. Because only a single threshold setting can be chosen for each
axes when using the motion detect embedded function and because of the need to detect acceleration outside a range, it would,
therefore, be seen as impossible to choose a threshold that would detect a 0.5 change in acceleration for any of the axes.
3.1
Use Case 1
Use Case 1 Transient: Unknown Orientation with Specific Acceleration Change for Detection
A use case example for transient detection may be when the device containing the accelerometer is in an environment of an
unknown orientation or changing orientation and a small amplitude, but quick disturbance must be detected, e.g., when the device is accelerating through 0g to +1g to -1g and a subtle impact force (change in acceleration of 0.5g) is used as an indication
to wake the device or as a motion signature of an event. The accelerometer reading combines the gravity and the linear
acceleration reading. It is much simpler to decouple the two by eliminating the effect of gravity. Using the example above, assume
that the device was oriented such that at given time T, X = 0.24g, Y = 0.44g and Z = 0.82g. If transient detection is enabled on
all 3 axes with a threshold of 0.5g and an ODR of 100 Hz, any time that X goes outside of the range -0.26g to 0.74g within
T + 10 ms, a transient detect interrupt would be generated. Eliminating the static acceleration on the device simplifies the condition to focus on the change in acceleration only, since the orientation is of no consequence in this situation. Figure 2 demonstrates
that the sensor detects both the static and the dynamic acceleration. Decoupling the static from the dynamic acceleration can
simplify the analysis.
AN4071
Sensors
Freescale Semiconductor, Inc.
3
Δ
Δ
DC
Δ
Figure 2. Device in an Unknown Orientation While Detecting Change in Acceleration
3.2
Use Case 2
Use Case 2: Image Stabilization
Another use case example for using data processed by the high-pass filter is for users viewing their PDA while in a car/bus or
on a train to provide image stabilization in a shaky environment. Small motions/vibrations can be compensated for with the
change in X, Y and Z movement through a stabilization routine, while a large change in motion could change the mode of the
device.
As shown in Figure 3, an image on a PDA that appears to be shaking can dynamically be compensated by shifting the screen
content in the opposite direction of the shake. The data must first be filtered to eliminate the gravity component to analyze the
change in acceleration of the axes. A mass spring damper model is a reasonable way to analyze the system to reduce display
shaking since the spring allows the mass to move in the opposite direction of the shake and dampers would prevent oscillation
of the mass. This type of model only requires the acceleration to compensate for the shaking. The parameters of the model can
be tuned based on the amplitudes and frequency of the oscillations in the environment since different environments may affect
the usability of the stabilization capabilities. For more information on this type of image stabilization technique there have been
various publications written for example, Rahmati et al1.
ΔY
?
y
ΔX
?x
Screen
Image
Figure 3. PDA Image Stabilization in a Train, Bus, Car, or Vibrating Environment
1. A. Rahmati, C. Shepard, L. Zhong, “No Shake: Content Stabilization for Shaking Screens of Mobile Device”, in Proc. IEEE Int. Conf. Pervasive
Computing and Communication (PerCom), March 2009.
AN4071
4
Sensors
Freescale Semiconductor, Inc.
4.0
Transient Settings and Interpretation of the Data
Figure 4 is a display of the 8-bit high-pass filtered data in 8g mode. The high-pass filter is set to 4 Hz with the sampling rate at
400 Hz. The sensitivity is 16 counts/g. The embedded block is set to detect when the HPF data exceeds 0.5g. This shows that
the device can be vibrating, or bouncing at a low acceleration level and the event will not be detected until the change in acceleration exceeds 0.5g.
Figure 4. HPF Data in the Embedded Transient Function with Threshold ±0.5g
4.1
High-Pass Filter Values
The high-pass filter values available scale with the output data rate in the MMA8451, 2, 3Q. Table 1 and Table 2, list the output
high-pass filter register where the cutoff frequency values are stored for every corresponding data rate. The values for SEL1 and
SEL0 refers to the cutoff frequency on the high-pass filter. Note that the oversampling mode also changes the cutoff frequency
options. It is expected that the customer will choose one or perhaps two oversampling modes and stay with those. Note that it
doesn’t make sense to use the High-Pass Filter in the High-Resolution Mode for output data rates of 12.5 Hz and below.
Table 1. High-Pass Filter Register 0x0F (Read/Write)
Bit 7
Bit 6
0
0
Bit 5
Bit 4
Pulse_HPF_BYP Pulse_LPF_EN
Bit 3
Bit 2
Bit 1
Bit 0
0
0
SEL1
SEL0
Table 2. HP_FILTER_CUTOFF Setting Options
Oversampling Mode = Normal
SEL1
SEL0
800 Hz
400 Hz
200 Hz
100 Hz
50 Hz
12.5 Hz
6.25 Hz
1.56 Hz
0
0
16 Hz
16 Hz
8 Hz
4 Hz
2 Hz
2 Hz
2 Hz
2 Hz
0
1
8 Hz
8 Hz
4 Hz
2 Hz
1 Hz
1 Hz
1 Hz
1 Hz
1
0
4 Hz
4 Hz
2 Hz
1 Hz
0.5 Hz
0.5 Hz
0.5 Hz
0.5 Hz
1
1
2 Hz
2 Hz
1 Hz
0.5 Hz
0.25 Hz
0.25 Hz
0.25 Hz
0.25 Hz
Oversampling Mode = Low Noise Low Power
0
0
16 Hz
16 Hz
8 Hz
4 Hz
2 Hz
0.5 Hz
0.5 Hz
0.5 Hz
0
1
8 Hz
8 Hz
4 Hz
2 Hz
1 Hz
0.25 Hz
0.25 Hz
0.25 Hz
1
0
4 Hz
4 Hz
2 Hz
1 Hz
0.5 Hz
0.125 Hz
0.125 Hz
0.125 Hz
1
1
2 Hz
2 Hz
1 Hz
0.5 Hz
0.25 Hz
0.063 Hz
0.063 Hz
0.063 Hz
Oversampling Mode = High Resolution
0
0
16 Hz
16 Hz
16 Hz
16 Hz
16 Hz
16 Hz
16 Hz
16 Hz
0
1
8 Hz
8 Hz
8 Hz
8 Hz
8 Hz
8 Hz
8 Hz
8 Hz
1
0
4 Hz
4 Hz
4 Hz
4 Hz
4 Hz
4 Hz
4 Hz
4 Hz
1
1
2 Hz
2 Hz
2 Hz
2 Hz
2 Hz
2 Hz
2 Hz
2 Hz
AN4071
Sensors
Freescale Semiconductor, Inc.
5
Table 2. HP_FILTER_CUTOFF Setting Options
Oversampling Mode = Low Power
0
0
16 Hz
8 Hz
4 Hz
2 Hz
1 Hz
0.25 Hz
0.25 Hz
0.25 Hz
0
1
8 Hz
4 Hz
2 Hz
1 Hz
0.5 Hz
0.125 Hz
0.125 Hz
0.125 Hz
1
0
4 Hz
2 Hz
1 Hz
0.5 Hz
0.25 Hz
0.063 Hz
0.063 Hz
0.063 Hz
1
1
2 Hz
1 Hz
0.5 Hz
0.25 Hz
0.125 Hz
0.031 Hz
0.031 Hz
0.031 Hz
Figure 5 shows a 0.8 Hz -1.5 Hz Z-axis only motion at 400 Hz ODR with the filter set at 4 Hz. Much of the motion at 1 Hz is
filtered out and the accelerometer reading remains between 0 to -1 counts.
Figure 5. 4 Hz High-Pass Filtered Transient Data with approximately 1 Hz Motion
Figure 6 shows 1 Hz of motion, 50 Hz ODR with no high-pass filter, with fairly controlled Z-axis only motion. The part is held
in the X = 0g, Y = 0g, Z = -1g configuration since the Z-axis is bouncing with the center around -16 counts (16 counts/g), while X
and Y are close to 0 counts.
Figure 6. XYZ Output Data with no High-Pass Filter Showing Approximately 1 Hz Motion
AN4071
6
Sensors
Freescale Semiconductor, Inc.
5.0
Using the HPF Data to Write Algorithms such as Directional Shake
Refer to Figure 7, “Directional Shake Showing Position, Velocity, Acceleration”. The high-pass filtered data can be used to
write algorithms such as for directional shake. This application could be used in a motion based game on a cell phone for detecting the direction of the motion. Directional shake is an application that requires a change in acceleration with the direction of the
acceleration change indicated by the initial change sign, followed by a “rebound”, which is a change in acceleration in the opposite direction. This occurs because the proof mass moves in the opposite direction of the package. Therefore as the hand accelerates in the positive direction, the proof mass accelerates in the negative direction. Next, as the hand decelerates and stops
(Velocity = 0), the proof mass accelerates in the opposite (positive) direction. By analyzing the output acceleration from the
directional shake signature, one can use the HPF data to write a very simple algorithm. In the MMA8451Q the high-pass filtered
data can be accessed as either 14-bit or 8-bit data through the FIFO. The FIFO helps to minimize the amount of transactions
required for algorithm analysis by the application processor.
Figure 7. Directional Shake Showing Position, Velocity, Acceleration
AN4071
Sensors
Freescale Semiconductor, Inc.
7
Figure 8 shows the Z-axis while shaking in the downward direction. The device was shaken 8 times, consecutively, in the
direction of gravity. Note that the deceleration was followed by a larger positive acceleration each time. This is very repeatable.
Repeatability of a motion with distinct characteristics is another important factor that can be leveraged while writing an algorithm
to detect a condition such as directional shake. This algorithm would look for a change in acceleration above a threshold. Next,
it would check the sign of the acceleration, followed by another change in acceleration above a threshold of opposite sign. The
algorithm would have to choose appropriate thresholds based on sensor placement and based on how the user is expected to
flick the device. Sometimes these algorithms require a bit of usability testing under various conditions with different users to
analyze the range of thresholds, and the timing required.
Figure 8. Z-Axis Directional Shake with Downward Motion
The graph in Figure 9 shows the accelerometer shaken upward producing the opposite results of the graph in Figure 8.
Acceleration initially increases (positive) and then rebounds with a larger negative acceleration each time. Directional shake has
a very distinct signature which is very repeatable. This is an ideal application using the transient data that is obtained from the
ac celerometer.
Figure 9. Z-Axis Directional Shake with Upward Motion
AN4071
8
Sensors
Freescale Semiconductor, Inc.
As seen in Figure 10, the same applies in the X and Y direction. Below are the graphed results of a shake on the Y-axis in the
positive direction. In this case the Y-axis is at zero g’s to start and then is accelerated toward the positive direction. This produces
similar results to the Z-axis, with a negative initial acceleration followed by positive rebound acceleration.
Figure 10. Y-Axis Positive Directional Shake Acceleration Output
The high-pass filtered XYZ data is available by reading registers 0x01 through 0x06 (the data registers), when the HPF_OUT
bit is set in Register 0x0E. Note it is not possible to read out the regular data and the high-pass filtered data at the same time.
This is only possible in the MMA8450Q device. Note: The MMA8451, 2, 3Q devices all have embedded directional shake. The
directional information is updated every time the event is detected. This saves the user from writing an algorithm to detect the
direction unless the user wants to develop a very specific customized algorithm.
6.0
Configuring the Embedded Transient Detection
There are four (4) registers associated with the embedded transient detection function. These are registers 0x1D to 0x20.
1. Register 0x1D Transient_CFG - Transient Configuration
2. Register 0x1F Transient_THS - Setting the Threshold
3. Register 0x20 Transient_COUNT - Setting the Debounce Counter
4. Register 0x1E Transient_SRC - Transient Source Detection
This embedded function is used to detect a change in acceleration greater than a set threshold for a determined period of time.
The function can be routed to one of the two interrupt pins on the accelerometer.
6.1
Register 0x1D:TRANSIENT_CFG Transient Configuration Register
The transient detection mechanism can be configured to raise an interrupt when the magnitude of the high-pass filtered acceleration is greater than the set threshold. The TRANSIENT_CFG register is used to enable the transient interrupt generation
mechanism for the 3 axes (X, Y, Z) of acceleration. The transient configuration register and descriptions are shown below in
Table 3.
Table 3. Register 0x1D TRANSIENT_CFG Register (Read/Write) and Description
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
—
—
—
ELE
ZTEFE
YTEFE
XTEFE
HPF_BYP
Note that if ELE = 1, the latch is enabled and the status will remain until it is read. The status register does not need to be read
immediately upon assertion since the status values can be latched until it is read. Also note if the HPF_BYP bit is set then the
Transient function will behave like the Motion function. This will bypass the high-pass filter and will compare the regular data to
the set threshold.
Example: X or Y > 6g with Latch enabled for time period of 60 ms at 50 Hz ODR
Code Example: IIC_RegWrite(0x1D, 0x16); //This enables the X-axis and the Y-axis only with the Latch
AN4071
Sensors
Freescale Semiconductor, Inc.
9
6.2
Register 0x1F: TRANSIENT_THS Transient Threshold Register
The TRANSIENT_THS register shown in Table 4 sets the threshold limit for the detection of the transient acceleration. The
value in the TRANSIENT_THS register corresponds to a g value which is compared against the values of the high-pass filtered
data. If the high-pass filtered acceleration exceeds the threshold limit, an event flag is raised and an interrupt is generated assuming the interrupts have been configured and enabled.
Table 4. Register 0x1F TRANSIENT_THS Register (Read/Write) and Description
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
DBCNTM
THS6
THS5
THS4
THS3
THS2
THS1
THS0
The threshold THS[6:0] is a 7-bit unsigned number. The minimum threshold resolution is 0.063g and the threshold register has
a range of 0 to 127counts. The maximum threshold is 8g. The threshold range is not dependent on the set Full Scale in Register
0x0E.
Example: X or Y > 6g with Latch enabled for time period of 60 ms at 50 Hz ODR
Since the minimum time step is 0.063g per count, the calculation is as follows:
6g/ 0.063g = 95.2 counts, round to 96 counts
Code Example: IIC_RegWrite(0x1F, 0x60); //Threshold set to 96 counts (6.048g)
6.3
Register 0x20: TRANSIENT_COUNT Transient Debounce Register
The TRANSIENT_COUNT shown inTable 5 sets the number of debounce counts (timing) required for the condition to persist.
Note that the timer for the transient as well as for all the other embedded functions is dependent on the oversampling mode of
the system.
Table 5. Register 0x20 TRANSIENT_COUNT Register (Read/Write) and Description
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 for the debounce counter is set by the value of the system ODR as shown in Table 6.
Table 6. TRANSIENT_COUNT Relationship with the ODR
Max Time Range (s)
Time Step (ms)
ODR (Hz)
Normal
LPLN
HighRes
LP
Normal
LPLN
HighRes
LP
800
0.319
0.319
0.319
0.319
1.25
1.25
1.25
1.25
400
0.638
0.638
0.638
0.638
2.5
2.5
2.5
2.5
200
1.28
1.28
0.638
1.28
5
5
2.5
5
100
2.55
2.55
0.638
2.55
10
10
2.5
10
50
5.1
5.1
0.638
5.1
20
20
2.5
20
12.5
5.1
20.4
0.638
20.4
20
80
2.5
80
6.25
5.1
20.4
0.638
40.8
20
80
2.5
160
1.56
5.1
20.4
0.638
40.8
20
80
2.5
160
Example: X or Y > 6g with Latch enabled for time period of 60 ms at 50 Hz ODR
60 ms total time/ 20 ms (at 50 Hz) = 3 counts
Code Example: IIC_RegWrite(0x20, 0x03);
AN4071
10
Sensors
Freescale Semiconductor, Inc.
6.4
Register 0x1E:TRANSIENT_SRC Transient Source Register
The transient event source flag register shown in Table 7 contains bit fields which can be used to determine which event has
occurred when a bit is set. Reading this register will clear the interrupt and status if it has been latched. The axis of the event and
the direction of the acceleration is given in the source register.
Table 7. Register 0x1E TRANSIENT_SRC Register (Read Only) and Description
6.5
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
—
EA
ZTRANSE
Z_Trans_Pol
YTRANSE
Y_Trans_Pol
XTRANSE
X_Trans_Pol
Configuring the Transient Detection to an Interrupt Pin
In order to set up the system to route to a hardware interrupt pin, the System Interrupt (bit 5 in Reg 0x2D) must be enabled in
Table 8. The MMA8451, 2, 3Q allows for seven (7) separate types of interrupts. One (1) of these is reserved for transient detection. To configure the Transient function, the following two step procedure should be followed.
Step 1: Enable the Interrupt in Register 0x2D shown in Table 8.
Table 8. Register 0x2D CTRL_REG4 Register (Read/Write)
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
INT_EN_ASLP
INT_EN_FIFO
INT_EN_TRANS
INT_EN_LNDPRT
INT_EN_PULSE
INT_EN_FF_MT
—
INT_EN_DRDY
The corresponding interrupt enable bit allows the function 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 Transient function, set bit 5 in register 0x2D as follows:
Code Example: IIC_RegWrite(0x2D, 0x20);
Step 2: Route the interrupt to INT1 or to INT2 shown in Table 9.
Table 9. 0x2E CTRL_REG5 Register (Read/Write) and Description
Bit 7
Bit 6
INT_CFG_ASLP
INT_CFG_FIFO
Bit 5
Bit 4
Bit 3
Bit 2
INT_CFG_TRANS INT_CFG_LNDPRT INT_CFG_PULSE INT_CFG_FF_MT
Bit 1
Bit 0
—
INT_CFG_DRDY
To set the Transient function to INT 1, set bit 5 in register 0x2E.
Code Example: IIC_RegWrite(0x2E,0x20);
6.6
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 deasserted 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. 0x0C 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
—
SRC_DRDY
AN4071
Sensors
Freescale Semiconductor, Inc.
11
7.0
Details for Configuring the MMA8451, 2, 3Q for Transient Detection
The registers of importance for configuring the MMA8451, 2, 3Q for transient detection are listed below in Table 11.
Table 11. Registers of Importance for Setting up the Transient Detection and Using the HPF
Reg
Name
Definition
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
0E
XYZ_DATA_CFG
Data Cfg R/W
0
0
0
HPF_OUT
0
0
FS1
FS0
0C
INT_SOURCE
Interrupt Status
SRC_ASLP
SRC_FIFO
SRC_TRANS
SRC_LNDPRT
SRC_PULSE
SRC_FF_MT_1
SRC_FF_MT_2
SRC_DRDY
0F
HP_FILTER_CUTOFF
HP Filter Setting
R/W
—
0
0
0
0
0
SEL1
SEL0
1D
TRANSIENT_CFG
Transient Config
R/W
—
—
—
ELE
ZTEFE
YTEFE
XTEFE
HPF_BYP
1E
TRANSIENT_SRC
Transient Source R
—
EA
ZTRANSE
Z_Trans_Pol
YTRANSE
Y_Trans_Pol
XTRANSE
X_Trans_Pol
1F
TRANSIENT_THS
Transient Threshold
R/W
DBCNTM
THS6
THS5
THS4
THS3
THS2
THS1
THS0
20
TRANSIENT_COUNT
Transient Debounce
R/W
D7
D6
D5
D4
D3
D2
D1
D0
2D
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
—
INT_EN_DRDY
2E
CTRL_REG5
Control Reg5 R/W
(Interrupt Config Map)
INT_CFG _ASLP
INT_CFG_FIFO
INT_CFG_TRANS INT_CFG_LNDPRT INT_CFG_PULSE INT_CFG _FF_MT
—
INT_CFG_DRDY
AN4071
12
Sensors
Freescale Semiconductor, Inc.
7.1
Example Steps for Configuring Transient Detection
Change in X or Y > 0.5g for 50 ms at 100 Hz ODR, Normal mode
Step 1: Put the device in Standby Mode: Register 0x2A CTRL_REG1
IIC_RegWrite(0x2A, 0x18); //Set device in 100 Hz ODR, Standby
Step 2: Enable X and Y Axes and enable the latch: Register 0x1D Configuration Register
IIC_RegWrite (0x1D, 0x16); Enable Latch, Enable X and Enable Y
Step 3: Set the Threshold: Register 0x1F
Note: Step count is 0.063g per count
0.5g / 0.063g = 7.93. Therefore set the threshold to 8 counts
IIC_RegWrite(0x1F, 0x08);
Step 4: Set the Debounce Counter for 50 ms: Register 0x20
Note: 100 Hz ODR, therefore 10 ms step sizes
IIC_RegWrite(0x20, 0x05);
Step 5: Enable Transient Detection Interrupt in the System (CTRL_REG4)
IIC_RegWrite(0x2D, 0x20);
Step 6: Route the Transient Interrupt to INT 1 hardware pin (CTRL_REG5)
IIC_RegWrite(0x2E, 0x20);
Step 7: Put the device in Active Mode: Register 0x2A CTRL_REG1
CTRL_REG1_Data = IIC_RegRead(0x2A); //Read out the contents of the register
CTRL_REG1_Data| = 0x01; //Change the value in the register to Active Mode.
IIC_RegWrite(0x2A, CTRL_REG1_Data); //Write in the updated value to put the device in
Active Mode
Step 8: Write Interrupt Service Routine Reading the System Interrupt Status and the Transient Status
Interrupt void isr_KBI (void)
{
//clear the interrupt flag
CLEAR_KBI_INTERRUPT;
//Determine source of interrupt by reading the system interrupt register
Int_SourceSystem = IIC_RegRead(0x0C);
//Set up Case statement here to service all of the possible interrupts
if ((Int_SourceSystem&0x20)==0x20)
{
//Perform an Action since Transient Flag has been set
//Read the Transient to clear system interrupt and Transient
Int_SourceTrans = IIC_RegRead(0x1E);
//Can parse out the data to perform a specific action based on the
//axes or direction that made the condition true
}
}
AN4071
Sensors
Freescale Semiconductor, Inc.
13
Related Documentation
The MMA845xQ device features and operations are described in a variety of reference manuals, user guides, and application
notes. To find the most-current versions of these documents:
1.
Go to the Freescale homepage at:
http://www.freescale.com/
2.
3.
In the Keyword search box at the top of the page, enter the device number MMA845xQ.
In the Refine Your Result pane on the left, click on the Documentation link.
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:
Freescale Semiconductor Literature Distribution Center
1-800-441-2447 or +1-303-675-2140
Fax: +1-303-675-2150
[email protected]
AN4071
Rev. 1
10/2011
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.,
Reg. U.S. Pat. & Tm. Off. The Energy Efficiency Solutions Logo and Xtrinsic are
trademarks of Freescale Semiconductor, Inc.
All other product or service names are the property of their respective owners.
© 2011 Freescale Semiconductor, Inc. All rights reserved.
Similar pages