Professional Documents
Culture Documents
An 1057 Application Note Using An Accele
An 1057 Application Note Using An Accele
Application Note
One Technology Way • P.O. Box 9106 • Norwood, MA 02062-9106, U.S.A. • Tel: 781.329.4700 • Fax: 781.461.3113 • www.analog.com
INTRODUCTION Inclination sensing uses the gravity vector and its projection
One common method for determining the tilt or inclination of on the axes of the accelerometer to determine the tilt angle.
a system is to integrate the output of a gyroscope. Although this Because gravity is a dc acceleration, any forces that result in
method is straightforward, error associated with null bias stability an additional dc acceleration corrupt the output signal and
can quickly compound as the integration period is increased, result in an incorrect calculation. Sources of dc acceleration
causing an apparent rotation even when the device is stationary. include the period of time when a vehicle is accelerating at
a constant rate and rotating devices that induce a centripetal
In some applications, where the net acceleration or force on acceleration on the accelerometer. In addition, rotating an
a system over time is gravity, an accelerometer can be used to accelerometer through gravity causes an apparent ac accelera-
measure the static angle of tilt or inclination. Such applications tion as the projection of gravity on the axes of interest changes.
include gaming, horizon detection in digital cameras, and detecting Any filtering of the acceleration signal before calculating the
the heading of a device in industrial and medical applications. inclination affects how quickly the output settles to the new
The underlying assumption in inclination sensing with an static value.
accelerometer is that the only acceleration stimulus is that This application note discusses the basic principles for converting
associated with gravity. In practice, signal processing can be the output of an accelerometer to an angle of inclination. This
performed on the signal output to remove high frequency discussion includes how to calculate the ideal inclination angle
content from the output signal, so some ac acceleration can for a single-axis, dual-axis, or triple-axis solution. In addition,
be tolerated. some basic information about calibration is included to reduce
error from offset and sensitivity mismatch.
Rev. 0 | Page 1 of 8
AN-1057 Application Note
TABLE OF CONTENTS
Introduction ...................................................................................... 1 Calibration for Offset and Sensitivity Mismatch Error ................7
Tilt/Inclination Calculation ............................................................ 3 Effects of Offset Error ...................................................................7
Single-Axis Tilt Calculation ........................................................ 3 Effects of Sensitivity Mismatch Error .........................................7
Dual-Axis Tilt Calculation .......................................................... 4 Basic Calibration Techniques ......................................................8
Triple-Axis Tilt Calculation ........................................................ 6
Rev. 0 | Page 2 of 8
Application Note AN-1057
TILT/INCLINATION CALCULATION Because the inclination calculation is done digitally, the output
Single-Axis Tilt Calculation acceleration is presented as a constant acceleration per least sig-
nificant bit (LSB), or code, obtained either from an analog-to-
In applications where inclination sensing is needed only over a
digital converter (ADC) or directly from a digital output part.
limited angle and with a somewhat coarse resolution, a single-axis
Because the output resolution is a constant acceleration, the
device (or a single axis of a multiple-axis device) can be used.
resolution in degrees of inclination is variable, with the best
For example, in Figure 1 a single axis (the x-axis in this example) resolution close to 0° and the worst resolution at ±90°.
is rotated through gravity. Because this approach uses only a
Figure 3 and Figure 4 show the incremental sensitivity for 1° and
single axis and requires the gravity vector, the calculated angle
0.25° inclination angle steps. The incremental sensitivity is the
of inclination is accurate only when the device is oriented such
output change, shown in mg, per inclination angle step, or
that the x-axis is always in the plane of gravity. Any rotation about
the other axes reduces the magnitude of the acceleration on the S [ g ] = 1 g × (sin(N + P ) − sin(N )) (2)
x-axis and results in error in the calculated angle of inclination. where:
+X
N is the current angle.
P is the step size.
+X θ
18
16
X: 24
1g 1g
Y: 16.01
14
08767-003
–100 –80 –60 –40 –20 0 20 40 60 80 100
When using a single-axis solution, note that the sensitivity— ANGLE OF INCLINATION, θ (Degrees)
that is, the change in output for some change in input—of the Figure 3. Incremental Inclination Sensitivity for 1° Steps
inclination calculation decreases as the angle between the horizon
4.5
and the x-axis increases, approaching 0 as the angle approaches
INCREMENTAL SENSITIVITY, S (mg/0.25°)
4.0
±90°. This can be seen in Figure 2, where the output acceleration, X: 23.5
in g, is plotted against the angle of inclination. Near ±90°, a large 3.5 Y: 4.005
0.8 Y: 2.006
1.5
0.6
⎛A [g] ⎞ –0.3
θ ≅ k × ⎜ X,OUT ⎟ (5)
⎜ 1g ⎟
⎝ ⎠ –0.4
–0.5
08767-006
where the inclination angle, θ, is in radians. –50 –40 –30 –20 –10 0 10 20 30 40 50
ANGLE OF INCLINATION, θ (Degrees)
Conversion to degrees is done by multiplying the result of
Figure 6. Calculated Angle Error for Different Scaling Factors
Equation 5 by (180/π). Figure 5 shows a comparison between
using the inverse sine function and the linear approximation Dual-Axis Tilt Calculation
with k equal to 1. As the magnitude of the inclination angle One limitation of single-axis inclination sensing is the need for
increases, the linear approximation begins to fail, and the a high resolution ADC or digital output to achieve a large range
calculated angle deviates from the actual angle. of valid inclination angles, as shown in Figure 3 and Figure 4.
50 Another limitation is that a single-axis measurement cannot
INVERSE SINE
40
LINEAR APPROXIMATION
provide a 360° measurement, because the acceleration generated
CALCULATED ANGLE, θCALC (Degrees)
30
at an inclination of N° is the same as the acceleration generated
at an inclination of 180° − N°. For some applications, this is accept-
20
able, but for applications that require higher resolution or the
10
ability to distinguish angles of inclination in a complete 360°
0 arc, a second axis, as shown in Figure 7, or a second sensor is
–10 necessary. If a second sensor is used, it should be oriented such
–20 that the sensing axis of the second sensor is orthogonal to the
–30
sensing axis of the first sensor.
+Y
–40 +Y
+X
–50
08767-005
Rev. 0 | Page 4 of 8
Application Note AN-1057
Constant Sensitivity As shown in Figure 3 and Figure 4, the sine function has the
The first major benefit of using a second axis is due to the orthogo- greatest rate of change near 0°, and it can be shown that the
nality of the axes. As in the single-axis solution, the acceleration cosine function has the least rate of change at this point. For
detected by the x-axis is proportional to the sine of the angle of this reason, the change in acceleration on the x-axis due to a
inclination. The y-axis acceleration, due to the orthogonality, is change in inclination is recognized before a change in accelera-
proportional to the cosine of the angle of inclination (see Figure 8). tion on the y-axis. Therefore, the resolution of the system near
As the incremental sensitivity of one axis is reduced, such as 0° depends primarily on the resolution of the x-axis. To detect
when the acceleration on that axis approaches +1 g or −1 g, the an inclination change of P°, the accelerometer must be able to
incremental sensitivity of the other axis increases. detect a change of approximately
ΔAOUT [ g ] ≅ 1 g × sin(P ) (8)
X-AXIS
1.0
Y-AXIS
Figure 9 can be used to determine the minimum necessary acceler-
OUTPUT ACCELERATION, AOUT (g)
0.8
0.6
ometer resolution—or maximum accelerometer scale factor—for a
0.4
desired inclination step size. Note that increased accelerometer
0.2
resolution corresponds with a reduction in accelerometer scale
0
factor and with the ability to detect a smaller change in output
–0.2
acceleration. Therefore, when selecting an accelerometer with
–0.4
the appropriate resolution, the scale factor should be less than
–0.6
the limit shown in Figure 9 for the intended inclination step size.
–0.8 100
–1.0 90
80
08767-008
However, an easier and more efficient approach is to use the ratio 10 X: 0.1
of the two values, which results in the following: 0
Y: 1.745 X: 0.25
Y: 4.363
A X,OUT 1 g × sin(θ ) –10
08767-009
= = tan(θ ) (6) –1 0 1 2 3 4 5 6
AY,OUT 1 g × cos(θ ) ANGLE OF INCLINATION STEP SIZE, P (Degrees)
Rev. 0 | Page 5 of 8
AN-1057 Application Note
If the system is tilted enough, such that very little acceleration due ⎛ ⎞
⎜ A Z ,OUT ⎟
to gravity is present in the xy-plane, the inclination angle step φ = cos −1 ⎜ ⎟⎟ (10)
size will be too coarse to be useful; therefore, it is recommended ⎜ A X ,OUT + A 2 Y ,OUT + A 2 Z ,OUT
2
⎝ ⎠
that tilt in the xz- or yz-plane be limited.
Given the assumption that the only measured acceleration is due
Complete 360° Tilt Sensing to gravity, the denominator of the operand in Equation 10 can
The third major benefit of using a second axis is the ability be replaced with a constant, ideally 1, because the RSS value of
to distinguish between each quadrant and to measure angles all the axes is constant when the only acceleration is gravity. The
throughout the entire 360° arc. As shown in Figure 10, each angles are shown in Figure 11, where Figure 11c shows θ only in
quadrant has a different combination of signs associated with the xy-plane, and Figure 11d shows φ as the angle between the
the x- and y-axis acceleration. z-axis and the gravity vector.
+90° (a) +Z (b)
+Z
II I
+X +Y
+X
+Y
+Y
+Y θ
+X 1g
1g
+X
1g 1g
+Y
X-AXIS + X-AXIS + +Z
Y-AXIS – Y-AXIS + +X
±180° 0°
X-AXIS – X-AXIS –
Y-AXIS – Y-AXIS + θ
+Y
+Z
08767-011
1g
1g
+X (c) (d)
Figure 11. Angles of Spherical Coordinate System
1g +Y 1g +X
Due to the similarities between the equations for the triple-axis
08767-010
III IV method and the equations for the single- and dual-axis methods,
–90° the analysis of the triple-axis solution is the same as for the single-
Figure 10. Angle of Inclination and Sign of Acceleration and dual-axis methods combined. The measurement of θ benefits
for Quadrant Detection from the ratio of two orthogonal axes, and a desired inclination
The inverse tangent function returns a value in Quadrant I if resolution requires a minimum accelerometer resolution as
the operand, AX,OUT/AY,OUT, is positive; if the operand is negative, described by Equation 8.
the inverse tangent function returns a value in Quadrant IV. The measurement of φ corresponds to the measurement of the
Because the operand in Quadrant II is negative, a value of 180° inclination angle for the single-axis solution, along with the method
should be added to the result of the calculation when the angle for determining the minimum accelerometer resolution needed
is in that quadrant. Because the operand in Quadrant III is for a specific inclination angle resolution over a desired range.
positive, a value of 180° should be subtracted from the result The difference is that the use of the inverse cosine function to
of the calculation when the angle is in that quadrant. The
determine φ results in a maximum incremental sensitivity when
correct quadrant of the calculated angle can be determined by
φ is 90° and a minimum incremental sensitivity at 0° and 180°.
examining the sign of the measured acceleration on each axis.
A plot similar to Figure 3 and Figure 4 can be generated by
Triple-Axis Tilt Calculation
substituting cosine for sine in Equation 2. It is important to
When a third axis is introduced, the orientation of the sensor note that although θ ranges from −180° to +180°, φ ranges only
can be determined in a complete sphere. The classical method from 0° to 180°. A negative angle for φ causes the angle of θ to
of rectangular (x, y, z) to spherical (ρ, θ, φ) conversion can be become negative.
used to relate the angle of tilt in the xy-plane, θ, and the angle
of inclination from the gravity vector, φ, to the measured
acceleration in each axis, as follows:
⎛A ⎞
θ = tan −1 ⎜ X ,OUT ⎟ (9)
⎜A ⎟
⎝ Y ,OUT ⎠
Rev. 0 | Page 6 of 8
Application Note AN-1057
An alternative method for inclination sensing with three axes is to CALIBRATION FOR OFFSET AND SENSITIVITY
determine the angle individually for each axis of the accelerometer MISMATCH ERROR
from a reference position. The reference position is taken as the
The analysis in this application note was done under the assump-
typical orientation of a device with the x- and y-axes in the plane
tion that an ideal accelerometer was used. This corresponds to a
of the horizon (0 g field) and the z-axis orthogonal to the horizon
device with no 0 g offset and with perfect sensitivity (expressed as
(1 g field). This is shown in Figure 12 with θ as the angle between
mV/g for an analog sensor or LSB/g for a digital sensor). Although
the horizon and the x-axis of the accelerometer, ψ as the angle
sensors come trimmed, the devices are mechanical in nature,
between the horizon and the y-axis of the accelerometer, and
which means that any static stress on the part after assembly of
φ as the angle between the gravity vector and the z-axis. When the system may affect the offset and sensitivity. This, combined
in the initial position of 0 g on the x- and y-axes and 1 g on the with the limits of factory calibration, can result in error beyond
z-axis, all calculated angles would be 0°. the allowable limits for the application.
(a) +Z (b)
+Z Effects of Offset Error
To demonstrate how large the error can be, imagine first a dual-
+Y axis solution with perfect sensitivity but with a 50 mg offset on
+Y
the x-axis. At 0° the x-axis reads 50 mg and the y-axis reads 1 g.
The resulting calculated angle would be 2.9°, resulting in an
θ error of 2.9°. At ±180° the x-axis would report 50 mg, whereas
+X 1g
1g the y-axis would report −1 g. This would result in a calculated
+X
+Z +Z angle and error of −2.9°. The error between the calculated angle
and the actual angle is shown in Figure 13 for this example. The
error due to an offset may not only be large compared to the
desired accuracy of the system, but it can vary, thus making it
difficult to simply calibrate out an error angle. This becomes
+Y
more complicated when an offset for multiple axes is included.
+X +Y θ 3
CALCULATED ANGLE ERROR, θERROR (Degrees)
08767-012
1g 1g
+X
(c) (d) 2
Figure 12. Angles for Independent Inclination Sensing
⎛ ⎞
⎜ A X,OUT ⎟ –1
θ = tan −1 ⎜ ⎟⎟ (11)
⎜ A Y ,OUT + A 2 Z ,OUT
2
⎝ ⎠ –2
⎛ ⎞
⎜ AY,OUT ⎟ –3
ψ = tan −1 ⎜
08767-013
⎟⎟ (12) –200 –150 –100 –50 0 50 100 150 200
⎜ A X ,OUT + A 2 Z ,OUT
2 ANGLE OF INCLINATION, θ (Degrees)
⎝ ⎠
Figure 13. Calculated Angle Error Due to Accelerometer Offset
⎛ A 2 X ,OUT + A 2 Y ,OUT ⎞
⎜ ⎟ Effects of Sensitivity Mismatch Error
φ = tan −1 ⎜ ⎟⎟ (13)
⎜ A Z ,OUT The main error component due to accelerometer sensitivity in
⎝ ⎠
a dual-axis inclination sensing application is when a difference
The apparent inversion of the operand in Equation 13 is due to in sensitivity exists between the axes of interest (as opposed to
the initial position being a 1 g field. If the horizon is desired as a single-axis solution, where any deviation between the actual
the reference for the z-axis, the operand can be inverted. A posi- sensitivity and the expected sensitivity results in an error).
tive angle means that the corresponding positive axis of the Because the ratio of the x- and y-axes is used, most of the error
accelerometer is pointed above the horizon, whereas a negative is cancelled if the sensitivities are the same.
angle means that the axis is pointed below the horizon.
Because the inverse tangent function and a ratio of accelerations
is used, the benefits mentioned in the dual-axis example apply,
namely that the effective incremental sensitivity is constant and
that the angles can be accurately measured for all points around
the unit sphere.
Rev. 0 | Page 7 of 8
AN-1057 Application Note
As an example of the effect of accelerometer sensitivity mismatch, A simple calibration method is to assume that the gain is 1 and
assume that a dual-axis solution is used with perfect offset trim, to measure the offset. This calibration then limits the accuracy
perfect sensitivity on the y-axis, and +5% sensitivity on the x-axis. of the system to the uncalibrated error in sensitivity. The simple
This means that in a 1 g field, the y-axis reports 1 g, whereas the calibration method can be done by placing the axis of interest
x-axis reports 1.05 g. Figure 14 shows the error in the calculated into a 0 g field and measuring the output, which would be equal
angle due to this sensitivity mismatch. Similar to offset error, to the offset. That value should then be subtracted from the output
the error due to accelerometer sensitivity mismatch varies over of the accelerometer before processing the signal. This is often
the entire range of rotation, making it difficult to compensate referred to as a no-turn or single-point calibration, because the
for the error after calculation of the inclination angle. Skewing typical orientation of a device puts the x- and y-axes in a 0 g
the mismatch further by varying the y-axis sensitivity results in field. If a three-axis device is used, at least one turn or a second
even greater error. point should be included for the z-axis.
2.0
A more accurate calibration method is to use two points per axis
CALCULATED ANGLE ERROR, θERROR (Degrees)
–1.0
These two points can be used to determine the offset and
gain as follows:
–1.5
AOFF [g] = 0.5 × (A+1g + A−1g) (17)
–2.0
08767-014
Rev. 0 | Page 8 of 8