AN3840, Setting up the MMA7660FC to do Orientation Detection

Freescale Semiconductor
Application Note
AN3840
Rev 2, 9/2009
Setting up the MMA7660FC to do Orientation
Detection
by: Laura Salhuana
ACRONYMS
ODR: Output Data Rate
AMSR: Auto Sleep Sample Rate
FILT: Debounce filter bits of orientation detection debounce filter
PLINT: Portrait/Landscape Interrupt
FBINT: Front/Back Interrupt
INT: Interrupt
TILT: Tilt (0x03) Register
INTSU: Interrupt Setup (0x06) Register
SR: Sample Rate (0x08) Register
ABSTRACT
The MMA7660FC has the built in capability to do orientation detection. This feature gives the customer the capability to do
applications such as portrait/landscape in mobile phones/PMP/PDAs. The tilt orientation of the device is in 3 dimensions and is
identified in its last known static position. This allows a product to set its display orientation appropriately to either portrait or
landscape mode or to turn off the display when the device is placed upside down. The sensor provides 6 different positions: left,
right, up, down, back, and front, defined in Table 1 and Figure 1. This application note will explain how to configure the
MMA7660FC to do orientation detection given the desired sample rate or targeted power consumption.
Table 1. Orientation Detection Logic of when Interrupt will Occur
Orientation
Xg
Up
|Z| < 0.8g and |X| > |Y| and X < 0
Down
|Z| < 0.8g and |X| > |Y| and X > 0
Yg
Right
|Z| < 0.8g and |Y| > |X| and Y < 0
Left
|Z| < 0.8g and |Y| > |X| and Y > 0
Zg
Back
Z < -0.25g
Front
Z > 0.25g
© Freescale Semiconductor, Inc., 2009. All rights reserved.
Figure 1. Flow Chart of Orientation Detection Setup and Algorithm
AN3840
Sensors
Freescale Semiconductor
2
SAMPLE RATE
The sampling rate can be selected based on the targeted power consumption per the application specification or the desired
response rate of the orientation detection. When deciding on the response rate, keep in mind that the faster the sampling rate,
the faster the interrupt will occur. The trade-off is that the higher the sampling rate, the higher the power consumption is. The
following are the sample rates available in the MMA7660FC sensor with the corresponding approximate power consumption
rates.
NOTE: These current drain rates were tested in the factory and could vary given PCB board design.
Table 2. Sample Rate vs. Current Consumption
Sampling Rate
Current Consumption
Stand By
2.33 μA
1 SPS
46.9 μA
2 SPS
49.3 μA
4 SPS
54 μA
8 SPS
65.8 μA
16 SPS
89.2 μA
32 SPS
133 μA
64 SPS
221 μA
120 SPS
294 μA
REGISTER OVERVIEW FOR ORIENTATION DETECTION
The following are the registers that will be used and/or configured for orientation detection.
$03: Tilt Status (Read only)
TILT
D7
D6
D5
D4
D3
D2
D1
D0
X
Alert
X
PoLa[2]
PoLa[1]
PoLa[0]
BaFro[1]
BaFro[0]
0
0
0
0
0
0
0
0
$06: Interrupt Setup Register
INTSU - Read/Write
D7
D6
D5
D4
D3
D2
D1
D0
X
X
X
X
X
X
PLINT
FBINT
0
0
0
0
0
0
0
0
$08: Auto-Wake and Active Mode Portrait/Landscape Output data rates register (Read/Write)
SR – Sample Rate Register
D7
D6
D5
D4
D3
D2
D1
D0
FILT[2]
FILT[1]
FILT[0]
X
X
AMSR[2]
AMSR[1]
AMSR[0]
0
0
0
0
0
0
0
0
AN3840
Sensors
Freescale Semiconductor
3
Setting up the INTSU [0x06] Register for Orientation Detection Only
Based on the application specification of the MMA7660FC, the sensor can be configured to report back/front interrupts and/or
up/down/left/right interrupts. If the application targets to use back and front the FBINT bit must be set to 1. If the back and front
interrupt is not desired then set the FBINT bit to 0. If the application targets Up/Down/Left/Right interrupts then the PLINT bit must
be set to 1. If the Up/Down/Left/Right interrupt is not desired then set the PLINT bit should be set to 0.
INTSU- Read/Write
D7
D6
D5
D4
D3
D2
D1
D0
X
X
X
X
X
X
PLINT
FBINT
0
0
0
0
0
0
0
0
FBINT
0:Front/Back position change does not cause an interrupt
1:Front/Back position change causes an interrupt
PLINT
0:Up/Down/Right/Left position change does not cause an
interrupt
1:Up/Down/Right/Left position change causes an interrupt
NOTE: For further description of the INTSU (0x06) register, please refer to the MMA7660FC Data Sheet.
Setting up the SR (0x08) register for orientation detection only:
The sample rate must be selected based on target power consumption levels and/or desired response rate for the orientation
detection application. To set up the sample rate, the AMSR[3:0] must be configured. Given the selected sample rate a debounce
filter setting (FILT[3:0]) must be selected also. Application testing has been done to correlate the sample rate and the
recommended debounce filter setting. Refer to Table 3.
SR – Read/Write
D7
D6
D5
D4
D3
D2
D1
D0
FILT[2]
FILT[1]
FILT[0]
X
X
AMSR[2]
AMSR[1]
AMSR[0]
0
0
0
0
0
0
0
0
AMSR[2:0]
NAME
DESCRIPTION
000
AMPD
120 Samples/Second Active and Auto-Sleep Mode
For portrait/landscape detection: The device takes and averages 32 g-cell measurements every 8.36 ms in
Active Mode and Auto-Sleep. The update rate is 120 samples per second. These measurements update the
XOUT (0x00), YOUT (0x01), and ZOUT (0x02) registers also.
001
AM64
64 Samples/Second Active and Auto-Sleep Mode
For portrait/landscape detection: The device takes and averages 32 g-cell measurements every 15.625 ms
in Active Mode and Auto-Sleep. The update rate is 64 samples per second. These measurements update the
XOUT (0x00), YOUT (0x01), and ZOUT (0x02) registers also.
010
AM32
32 Samples/Second Active and Auto-Sleep Mode
For portrait/landscape detection: The device takes and averages 32 g-cell measurements every 31.25ms in
Active Mode and Auto-Sleep. The update rate is 32 samples per second. These measurements update XOUT
(0x00), YOUT (0x01), and ZOUT (0x02) registers also.
011
AM16
16 Samples/Second Active and Auto-Sleep Mode
For portrait/landscape detection: The device takes and averages 32 g-cell measurements every 62.5ms in
Active Mode and Auto-Sleep. The update rate is 16 samples per second. These measurements update the
XOUT (0x00), YOUT (0x01), and ZOUT (0x02) registers also.
AN3840
Sensors
Freescale Semiconductor
4
100
AM8
8 Samples/Second Active and Auto-Sleep Mode
For portrait/landscape detection: The device takes and averages 32 g-cell measurements every 125ms in
Active Mode and Auto-Sleep. The update rate is 8 samples per second. These measurements update the
XOUT (0x00), YOUT (0x01), and ZOUT (0x02) registers also.
101
AM4
4 Samples/Second Active and Auto-Sleep Mode
For portrait/landscape detection: The device takes and averages 32 g-cell measurements every 250ms in
Active Mode and Auto-Sleep. The update rate is 4 samples per second. These measurements update the
XOUT (0x00), YOUT (0x01), and ZOUT (0x02) registers also.
110
AM2
2 Samples/Second Active and Auto-Sleep Mode
For portrait/landscape detection: The device takes and averages 32 g-cell measurements every 500ms in
Active Mode and Auto-Sleep. The update rate is 2 samples per second. These measurements update the
XOUT (0x00), YOUT (0x01), and ZOUT (0x02) registers also.
111
AM1
1 Sample/Second Active and Auto-Sleep Mode
For portrait/landscape detection: The device takes and averages 32 g-cell measurements every 1000ms in
Active Mode and Auto-Sleep. The update rate is 1 samples per second. These measurements update the
XOUT (0x00), YOUT (0x01), and ZOUT (0x02) registers also.
FILT[2:0]
DESCRIPTION
000
Tilt debounce filtering is disabled. The device updates portrait/landscape every reading at the rate set by AMSR[2:0] or
AWSR[1:0]
001
2 measurement samples at the rate set by AMSR[2:0] or AWSR[1:0] have to match before the device updates
portrait/landscape data in TILT (0x03) register.
010
3 measurement samples at the rate set by AMSR[2:0] or AWSR[1:0] have to match before the device updates
portrait/landscape data in TILT (0x03) register.
011
4 measurement samples at the rate set by AMSR[2:0] or AWSR[1:0] have to match before the device updates
portrait/landscape data in TILT (0x03) register.
100
5 measurement samples at the rate set by AMSR[2:0] or AWSR[1:0] have to match before the device updates
portrait/landscape data in TILT (0x03) register.
101
6 measurement samples at the rate set by AMSR[2:0] or AWSR[1:0] have to match before the device updates
portrait/landscape data in TILT (0x03) register.
110
7 measurement samples at the rate set by AMSR[2:0] or AWSR[1:0] have to match before the device updates
portrait/landscape data in TILT (0x03) register.
111
8 measurement samples at the rate set by AMSR[2:0] or AWSR[1:0] have to match before the device updates
portrait/landscape data in TILT (0x03) register.
Table 3. Sample Rate vs. Debounce Filter Table
Sample Rate
Debounce Filter Setting
1 SPS
4
2 SPS
6
4 SPS
8
8 SPS
8
16 SPS
8
32 SPS
8
64 SPS
External Debounce Filter
120 SPS
External Debounce Filter
NOTE: The recommended values were tested on the RD3803MMA7660FC evaluation board. The values may change given the
mounting and position of the sensor on the PCB design.
AN3840
Sensors
Freescale Semiconductor
5
External Debounce Filter:
When using the MMA7660FC and sample rates higher than 32 SPS an external debounce filter must be added to avoid
flickering between positions due to involuntary human movement. The external debounce filter must be added to the application
microcontroller. Below is a flow chart and Pseudocode for the debounce filter.
Start
old_Tilt = 0
Debounce Count = 0
Filter Setting = n
No
Orientation
Interrupt?
Yes
No
Current_TILT = TILT
Register (0x03) BaFro
and/or PoLa bits
PSEUDOCODE:
//Configure Orientation Detection
Interrupts
FILTER_SETTING = n
If(TILT_Interrupt occurs)
read TILT Register
if(old_TILT ==
current_TILT)
Current_TILT
== old_TILT?
Debounce
Count++
If(Debounce Count == FILTER_SETTING)
Yes
//orientation =
current_TILT
Debounce Count++
No
Debounce
Count ==
Filter Setting?
Yes
Update Orientation
Position
Figure 2. External Debounce Filter
AN3840
Sensors
Freescale Semiconductor
6
HANDLING THE ORIENATION DETECTION INTERRUPT
When an interrupt occurs, the application must respond and read the TILT (0x03) register. When reading the TILT register the
bits of interest are the following POLA[4:2] and BAFRO[1:0]. The interrupt will be cleared when the TILT register is read.
NOTE: If the register is read and the Alert bit is high, the register must be read again.
TILT – Read Only
D7
D6
D5
D4
D3
D2
D1
D0
X
Alert
X
PoLa[2]
PoLa[1]
PoLa[0]
BaFro[1]
BaFro[0]
0
0
0
0
0
0
0
0
BaFro[1:0]
00:Unknown condition of front or back
01:Front:Equipment is lying on its front
10:Back:Equipment is lying on its back
Alert
0:Register data is valid
1:The register was read at the same time as MMA7660FC was
attempting to update the contents. Re-read the register
PoLa[2:0]
000:Unknown initial condition of up or down or left or right
001:Left:Equipment is in landscape mode to the left
010:Right:Equipment is in landscape mode to the right
101:Down:Equipment standing vertically in inverted
orientation (any markings are the wrong way up)
110:Up:Equipment standing vertically in normal orientation
(any markings are the right way up)
AN3840
Sensors
Freescale Semiconductor
7
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 010 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]
AN3840
Rev. 2
9/2009
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. 2009. All rights reserved.