Using An Accelerometer for Inclination Sensing

By Christopher J. Fisher

Contributed By Convergence Promotions LLC


Cell phones now commonly change screen orientation as the user rotates the phone. This article discusses the basic principles and needed calculations for converting the output of an accelerometer to an angle of inclination.


One common method for determining the tilt or inclination of a system is to integrate the output of a gyroscope. Although this method is straightforward, error associated with null bias stability can quickly compound as the integration period is increased, causing an apparent rotation even when the device is stationary.

In some applications, where the net acceleration or force on a system over time is gravity, an accelerometer can be used to measure the static angle of tilt or inclination. Such applications include gaming, horizon detection in digital cameras, and detecting the heading of a device in industrial and medical applications.

The underlying assumption in inclination sensing with an accelerometer is that the only acceleration stimulus is that associated with gravity. In practice, signal processing can be performed on the signal output to remove high frequency content from the output signal, so some AC acceleration can be tolerated.

Inclination sensing uses the gravity vector, and its projection on the axes of the accelerometer, to determine the tilt angle. Because gravity is a DC acceleration, any forces that result in an additional DC acceleration corrupt the output signal and result in an incorrect calculation. Sources of DC acceleration include the period of time when a vehicle is accelerating at a constant rate and rotating devices that induce a centripetal acceleration on the accelerometer. In addition, rotating an accelerometer through gravity causes an apparent AC acceleration as the projection of gravity on the axes of interest changes. Any filtering of the acceleration signal before calculating the inclination affects how quickly the output settles to the new static value.

This article discusses the basic principles for converting the output of an accelerometer to an angle of inclination. This discussion includes how to calculate the ideal inclination angle for a single-axis, dual-axis, or triple-axis solution. In addition, some basic information about calibration is included to reduce error from offset and sensitivity mismatch.

Tilt/Inclination calculation

Single-axis tilt calculation

In applications where inclination sensing is needed only over a limited angle, and with a somewhat coarse resolution, a single-axis device (or a single axis of a multiple-axis device) can be used.

For example, in Figure 1 a single axis (the x-axis in this example) is rotated through gravity. Because this approach uses only a single axis and requires the gravity vector, the calculated angle of inclination is accurate only when the device is oriented so 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 x-axis and results in error in the calculated angle of inclination.
Figure 1: Single axis used for tilt sensing.
Figure 1: Single axis used for tilt sensing.

Referring to basic trigonometry, the projection of the gravity vector on the x-axis produces an output acceleration equal to the sine of the angle between the accelerometer x-axis and the horizon. The horizon is typically taken to be the plane orthogonal to the gravity vector. For an ideal value of 1 g for gravity, the output acceleration is:

Equation 1.

When using a single-axis solution, note that the sensitivity — that is, the change in output for some change in input — of the inclination calculation decreases as the angle between the horizon and the x-axis increases, approaching zero as the angle approaches ±90°. This can be seen in Figure 2, where the output acceleration, in g, is plotted against the angle of inclination. Near ±90°, a large change in inclination angle results in a small change in output acceleration.

Because the inclination calculation is done digitally, the output acceleration is presented as a constant acceleration per least significant bit (LSB) or code, obtained either from an analog-to-digital converter (ADC) or directly from a digital output part. Because the output resolution is a constant acceleration, the resolution in degrees of inclination is variable, with the best resolution close to 0° and the worst resolution at ±90°.

Figure 2: Output acceleration versus angle of inclination for single-axis inclination sensing.
Figure 2: Output acceleration versus angle of inclination for single-axis inclination sensing.

Figures 3 and 4 show the incremental sensitivity for 1° and 0.25° inclination angle steps. The incremental sensitivity is the output change, shown in mg, per inclination angle step, or


Equation 2.

where:
N is the current angle.
P is the step size.

Figure 3: Incremental inclination sensitivity for 1° steps.
Figure 3: Incremental inclination sensitivity for 1° steps.

These curves can be used to determine the minimum necessary resolution when measuring the output acceleration in order to meet the desired inclination resolution for the entire range of an application. For example, designing for a maximum step size of 1°, a resolution of at least 8 mg/LSB is necessary for a range of ±63°. Similarly, to achieve a maximum step size of 0.25° for a range of ±63° requires a resolution of at least 2 mg/LSB. Note that, if enough either is present, oversampling can be used to achieve better resolution.

Figure 4: Incremental inclination sensitivity for 0.25° steps.
Figure 4: Incremental inclination sensitivity for 0.25° steps.

Because the output of the accelerometer obeys a sinusoidal relationship as it is rotated through gravity, conversion from acceleration to angle is done using the inverse sine function,

Equation 3.

where the inclination angle, θ, is in radians.

If a narrow range of inclination is required, a linear approximation can be used in place of the inverse sine function. The linear approximation relates to the approximation of sine for small angles,

Equation 4.

where the inclination angle, θ, is in radians.

Equation 5.

where the inclination angle, θ, is in radians.

Conversion to degrees is done by multiplying the result of Equation 5 by (180/π). Figure 5 shows a comparison between using the inverse sine function and the linear approximation with k equal to 1. As the magnitude of the inclination angle increases, the linear approximation begins to fail, and the calculated angle deviates from the actual angle.

Because the calculated angle is plotted against the actual angle of inclination, the linear approximation appears to bend near the ends. This is because the linear approximation is linear only when compared to the output acceleration and, as shown in Figure 2, the output acceleration behaves similarly as the actual angle of inclination is increased. However, the inverse sine function should produce an output that is one-to-one with the actual angle of inclination, causing the calculated angle to be a straight line when plotted against the actual angle of inclination.

Figure 5: Comparison of inverse sine function and linear approximation for inclination angle calculation.
Figure 5: Comparison of inverse sine function and linear approximation for inclination angle calculation.

As an example, if the desired resolution of inclination sensing is 1°, an error of ±0.5° is acceptable because it is below the rounding error of the calculation. If the error between the actual angle of inclination and the calculated angle of inclination is plotted for k equal to 1, as shown in Figure 6, the valid range for the linear approximation is only ±20°. If the scaling factor is adjusted such that the error is maximized, but kept within the calculation rounding limits, the valid range of the linear approximation increases to greater than ±30°.

Figure 6: Calculated angle error for different scaling factors.
Figure 6: Calculated angle error for different scaling factors.

Dual-axis tilt calculation

One limitation of single-axis inclination sensing is the need for a high-resolution ADC or digital output to achieve a large range of valid inclination angles, as shown in Figures 3 and 4. Another limitation is that a single-axis measurement cannot provide a 360° measurement, because the acceleration generated at an inclination of N° is the same as the acceleration generated at an inclination of 180° — N°.

For some applications this is acceptable, but for applications that require higher resolution, or the ability to distinguish angles of inclination in a complete 360° arc, a second axis, as shown in Figure 7, or a second sensor is necessary. If a second sensor is used, it should be oriented such that the sensing axis of the first sensor.

Figure 7: Two axes used for tilt sensing.
Figure 7: Two axes used for tilt sensing.

There are three major benefits to including a second axis in determining the angle of inclination. These benefits are described in the following sections.

Constant sensitivity

The first major benefit of using a second axis is due to the orthogonality of the axes. As in the single-axis solution, the acceleration detected by the x-axis is proportional to the sine of the angle of inclination. The y-axis acceleration, due to the orthogonality, is proportional to the cosine of the angle of inclination (see Figure 8). As the incremental sensitivity of one axis is reduced, such as when the acceleration on that axis approaches +1 g or -1 g, the incremental sensitivity of the other axis increases.

Figure 8: Output acceleration versus angle of inclination for dual-axis inclination sensing.
Figure 8: Output acceleration versus angle of inclination for dual-axis inclination sensing.

One method to convert the measured acceleration to an inclination angle is to compute the inverse sine of the x-axis and the inverse cosine of the y-axis, similar to the single-axis solution. However, an easier and more efficient approach is to use the ratio of the two values, which results in the following:

Equation 6.


Equation 7.

where the inclination angle, θ, is in radians.

Unlike the single-axis example, using the ratio of the two axes to determine the angle of inclination makes determining an incremental sensitivity very difficult. Instead, it is more useful to determine the minimum necessary accelerometer resolution, given a desired inclination resolution. Given that the incremental sensitivity of one axis increases as the other decreases, the net result is an effective incremental sensitivity that is roughly constant. This means that the selection of an accelerometer with sufficient resolution to achieve the desired inclination step size at one angle is sufficient for all angles.

To determine the minimum necessary accelerometer resolution, Equation 6 is examined to determine where the resolution limitations are. Because the output of each axis relies on the sine or cosine of the angle of inclination, and the angle of inclination for each function is the same, the minimum resolvable angle corresponds to the minimum resolvable acceleration.

As shown in Figures 3 and 4, the sine function has the greatest rate of change near 0°, and the cosine function has the least rate of change at this point. For this reason, the change in acceleration on the x-axis due to a change in inclination is recognized before a change in acceleration on the y-axis. Therefore, the resolution of the system near 0° depends primarily on the resolution of the x-axis. To detect an inclination change of P°, the accelerometer must be able to detect a change of approximately:

Equation 8.

Figure 9 can be used to determine the minimum necessary accelerometer resolution — or maximum accelerometer scale factor — for a desired inclination step size. Note that increased accelerometer resolution corresponds with a reduction in accelerometer scale factor and with the ability to detect a smaller change in output acceleration. Therefore, when selecting an accelerometer with the appropriate resolution, the scale factor should be less than the limit shown in Figure 9 for the intended inclination step size.

Figure 9: Minimum accelerometer resolution for a desired angle of inclination resolution.
Figure 9: Minimum accelerometer resolution for a desired angle of inclination resolution.

Reduced dependence on alignment with plane of gravity

The second major benefit of using at least two axes is that unlike the single-axis solution, where tilt in any axis other than the x-axis can cause significant error, the use of a second axis allows for an accurate value to be measured even when inclination in the third axis is present. This is because the effective incremental sensitivity is proportional to the root-sum-square (RSS) value of gravity on the axes of interest.

When gravity is completely contained in the xy-plane, the RSS value of acceleration detected on those axes is ideally equal to 1 g . If tilt is present in the xz- or yz-plane, the total acceleration due to gravity is reduced, which also reduces the effective incremental sensitivity. This, in turn, increases the inclination step size for a given accelerometer resolution, but still provides an accurate measurement. The resulting angle from the inclination calculation corresponds to the rotation in the xy-plane.

If the system is tilted enough, such that very little acceleration due to gravity is present in the xy-plane, the inclination angle step size will be too coarse to be useful. Therefore, it is recommended that tilt in the xz- or yz-plane be limited.

Complete 360° tilt sensing

The third major benefit of using a second axis is the ability to distinguish between each quadrant and to measure angles throughout the entire 360° arc. As shown in Figure 10, each quadrant has a different combination of signs associated with the x- and y-axis acceleration.

Figure 10: Angle of inclination and sign of acceleration for quadrant detection.
Figure 10: Angle of inclination and sign of acceleration for quadrant detection.

The inverse tangent function returns a value in Quadrant I if the operand, AX,OUT/AY,OUT, is positive; if the operand is negative, the inverse tangent function returns a value in Quadrant IV. Because the operand in Quadrant II is negative, a value of 180° should be added to the result of the calculation when the angle is in that quadrant.

Because the operand in Quadrant III is positive, a value of 180° should be subtracted from the result of the calculation when the angle is in that quadrant. The correct quadrant of the calculated angle can be determined by examining the sign of the measured acceleration on each axis.

Triple-axis tilt calculation

When a third axis is introduced, the orientation of the sensor can be determined in a complete sphere. The classical method of rectangular (x, y, z) to spherical (ρ, θ, φ) conversion can be 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:

Equation 9.


Equation 10.

Given the assumption that the only measured acceleration is due to gravity, the denominator of the operand in Equation 10 can be replaced with a constant, ideally 1, because the RSS value of all the axes is constant when the only acceleration is gravity. The angles are shown in Figure 11, where Figure 11c shows θ only in the xy-plane, and Figure 11d shows φ as the angle between the z-axis and the gravity vector.

Figure 11: Angles of spherical coordinate system.
Figure 11: Angles of spherical coordinate system.

Due to the similarities between the equations for the triple-axis method and the equations for the single- and dual-axis methods, the analysis of the triple-axis solution is the same as for the single- and dual-axis methods combined. The measurement of θ benefits from the ratio of two orthogonal axes, and a desired inclination resolution requires a minimum accelerometer resolution as described by Equation 8.

The measurement of φ corresponds to the measurement of the inclination angle for the single-axis solution, along with the method for determining the minimum accelerometer resolution needed for a specific inclination angle resolution over a desired range. The difference is the use of the inverse cosine function to determine φ results in a maximum incremental sensitivity, when φ is 90° and a minimum incremental sensitivity at 0° and 180°.

A plot similar to Figures 3 and 4 can be generated by substituting cosine for sine in Equation 2. It is important to note that although θ ranges from -180° to +180°, φ ranges only from 0° to 180°. A negative angle for φ causes the angle of θ to become negative.

An alternative method for inclination sensing with three axes is to determine the angle individually for each axis of the accelerometer from a reference position. The reference position is taken as the typical orientation of a device, with the x- and y-axes in the plane of the horizon (0 g field) and the z-axis orthogonal to the horizon (1 g field). This is shown in Figure 12, with θ as the angle between the horizon and the x-axis of the accelerometer, ψ as the angle between the horizon and the y-axis of the accelerometer, and φ as the angle between the gravity vector and the z-axis. When in the initial position of 0 g on the x- and y-axes and 1 g on the z-axis, all calculated angles would be 0°.

Figure 12: Angles for independent inclination sensing.
Figure 12: Angles for independent inclination sensing.

Basic trigonometry can be used to show that the angles of inclination can be calculated using Equation 11, Equation 12, and Equation 13.

Equation 11.


Equation 12.


Equation 13.

The apparent inversion of the operand in Equation 13 is due to the initial position being a 1 g field. If the horizon is desired as the reference for the z-axis, the operand can be inverted. A positive angle means that the corresponding positive axis of the accelerometer is pointed above the horizon, whereas a negative angle means that the axis is pointed below the horizon.

Because the inverse tangent function and a ratio of accelerations are 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.

Calibration for offset and sensitivity mismatch error

The analysis in this application note was done under the assumption that an ideal accelerometer was used. This corresponds to a device with no 0 g offset and with perfect sensitivity (expressed as mV/g for an analog sensor or LSB/g for a digital sensor). Although sensors come trimmed, the devices are mechanical in nature, which means that any static stress on the part after assembly of the system may affect the offset and sensitivity. This, combined with the limits of factory calibration, can result in error beyond the allowable limits for the application.

Effects of offset error

To demonstrate how large the error can be, imagine first a dual-axis solution with perfect sensitivity, but with a 50 mg offset on 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 the y-axis would report -1 g. This would result in a calculated 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 more complicated when an offset for multiple axes is included.

Figure 13: Calculated angle error due to accelerometer offset.
Figure 13: Calculated angle error due to accelerometer offset.

Effects of sensitivity mismatch error

The main error component due to accelerometer sensitivity in a dual-axis inclination sensing application is when a difference in sensitivity exists between the axis of interest (as opposed to a single-axis solution, where any deviation between the actual sensitivity and the expected sensitivity results in an error). Because the ratio of the x- and y-axes is used, most of the error is cancelled if the sensitivities are the same.

As an example of the effect of accelerometer sensitivity mismatch, assume that a dual-axis solution is used with perfect offset trim, perfect sensitivity on the y-axis, and +5 percent sensitivity on the x-axis. This means that in a 1 g field, the y-axis reports 1 g, whereas the x-axis reports 1.05 g. Figure 14 shows the error in the calculated angle due to this sensitivity mismatch. Similar to offset error, the error due to accelerometer sensitivity mismatch varies over the entire range of rotation, making it difficult to compensate for the error after calculation of the inclination angle. Skewing the mismatch further by varying the y-axis sensitivity results in even greater error.

Figure 14: Calculated angle error due to accelerometer sensitivity mismatch.
Figure 14: Calculated angle error due to accelerometer sensitivity mismatch.

Basic calibration techniques

When the errors due to offset and sensitivity mismatch are combined, the error can become quite large and well beyond the acceptable limits in an inclination sensing application. To reduce this error, the offset and sensitivity should be calibrated and the calibrated output acceleration used to calculate the angle of inclination. When including the effects of offset and sensitivity, the accelerometer output is as follows:

Equation 14.

where:
AOFF is the offset error, in g.

Gain is the gain of the accelerometer, ideally a value of 1.

AACTUAL is the real acceleration acting on the accelerometer and the desired value, in g.

A simple calibration method is to assume that the gain is 1 and to measure the offset. This calibration then limits the accuracy of the system to the uncalibrated error in sensitivity. The simple calibration method can be done by placing the axis of interest into a 0 g field and measuring the output, which would be equal to the offset. That value should then be subtracted from the output of the accelerometer before processing the signal. This is often referred to as no-turn or single-point calibration, because the typical orientation of a device puts the x- and y-axes in the 0 g field. If a three-axis device is used, at least one turn or second point should be included for the z-axis.

A more accurate calibration method is to use two points per axis of interest (up to six points for a three-axis design). When an axis is placed into a +1 g and -1 g field, the measured outputs are as follows:

Equation 15.


Equation 16.

where the offset, AOFF, is in g.

These two points can be used to determine the offset and gain as follows:

Equation 17.


Equation 18.

where the +1 g and -1 g measurements, A+1g and A-1g, are in g.

This type of calibration also helps to minimize cross-axis sensitivity effects as the orthogonal axes are in a 0 g field when making the measurements for the axis of interest. These values would be used by first subtracting the offset from the accelerometer measurement and then dividing the result by the gain.

Equation 19.

where AOUT and AOFF are in g.

The calculations of AOFF and gain in Equation 15 through Equation 19 assume that the acceleration values, A+1g and A-1g are in g. If acceleration in mg is used, the calculation of AOFF in Equation 17 remains unchanged, but the calculation of gain in Equation 18 should be divided by 1,000 to account for the change in units.

Disclaimer: The opinions, beliefs, and viewpoints expressed by the various authors and/or forum participants on this website do not necessarily reflect the opinions, beliefs, and viewpoints of Digi-Key Electronics or official policies of Digi-Key Electronics.

About this author

Christopher J. Fisher

Article authored by Christopher J. Fisher of Analog Devices, Inc.

About this publisher

Convergence Promotions LLC