One Technology Way • P.O. Box 9106 • Norwood, MA 02062-9106 • Tel: 781/329-4700 • Fax: 781/326-8703 • www.analog.com
APPLICATION NOTE
A Compact Algorithm Using the ADXL202
Duty Cycle Output
by Harvey Weinberg
Introduction
There are many applications where high accuracy measurement of acceleration is less important than having a
simple and compact software algorithm. This application
note outlines a decode algorithm that measures only the
pulsewidth (T1) output of the ADXL202 and translates it to
degrees of tilt. In this algorithm, the period (T2) is not
measured, and no binary division is used.
In PIC assembly code, a total of 199 bytes of program
memory and 18 bytes of data memory are used. Even
more efficient memory (particularly data memory) usage
can be had with further optimization. A flow chart of the
algorithm is included so that the user may modify it or
port it to any 4- or 8-bit microcontroller with little effort.
Using this technique, we simplify tilt angle calculation
down to a simple 1 s per degree relationship. Any
modulo-2 factor of 500 s (e.g., 1000 s, 2000 s, and so
on) may be used as required.
Error Sources
Scale error is the most significant error source encountered when using this algorithm. We assume that the
overall scale factor is 16 m
multiple) in this algorithm, but the actual scale factor
may be anything from 10% per
results in a ±8∞error over ±40∞ of tilt. Another obvious
error source is having the wrong value for T2. A 1% error
in T2 will result in a 1% error in tilt angle resolution.
These errors may be eliminated by adding a trim to T2.
g
per s (or some modulo-2
g
to 15% per g. This
A discussion of error sources inherent in this method of
measurement is also included.
Principle of Operation
The ADXL202 outputs a pulsewidth modulated (PWM)
signal proportional to acceleration. Assuming that the
scale factor is fixed at 12.5
Where T1 is the pulsewidth and T2 is the period of the
ADXL202’s PWM output.
In a temperature stable environment, we can assume
that the average value of
we can rearrange the formula for
accelerationTT atg T= (( 1– 20 )2) 12.5%
Over a range of ±35∞ of tilt, each degree of tilt is very
close to 16 m
can take advantage of very easy modulo-2 division to
minimize computational requirements when calculating
tilt angle. For example:
g
. By choosing particular values of T2, we
Ts
2500
=
gss
1(500) (12.5%) 62.5
=¥=
sgs mg
1(162.5) 16
==
mm
%
per g:
T
2 does not change. Therefore
acceleration
m
mm
as:
Scale factor error and
together by adjusting
some modulo-2 multiple) relationship is maintained.
This is expressed by the following equation:
Tscalefactor210016=¥(() ( .))
So, for example, for a scale factor of 10%:
T2s=¥=1 ((0.10) (0.016)) 625 m
Adjusting T2 to 625 s in this case would eliminate the
errors due to scale factor and
Since scale factor variation may result in such large
errors, trimming T2 by adding a potentiometer in series
with R
trim may be omitted in applications where one is interested only in changes in tilt angle, and errors due to
scale factor and T2 inaccuracy can be tolerated.
T2 may drift over temperature by as much as a few percent. This is very difficult to compensate for using this
type of algorithm. It is suggested that another algorithm
be used in situations where this is problematic.
The assumption that over ±35∞ of tilt, each degree of tilt is
very close to 16 m
one degree of tilt is 17.45 m
14.38 m
g
. While at first glance this looks like a large
g
, is of course an approximation. At 1∞,
g
; at 35∞, one degree
of tilt is
source of error, it turns out that it only works out to ±1∞ of
error over a ±40∞ range of tilt as shown in Table I.
There is normally a certain amount of “jitter” in T2.
Since the duty cycle does not change as a result of this
jitter, T1 changes proportionally with T2. This error
source in minimized in the 0
g
calibration routine by taking the average value of T1 over 16 readings. This is not
done in normal sampling to allow wider bandwidth
operation. If wide bandwidth is not a concern, the user
may wish to modify the algorithm to include a similar
averaging scheme in normal sampling to minimize this
error due to T2 jitter.
The final source of error is from aliasing in the duty cycle
modulator itself. As discussed in the ADXL202 data
sheet, the analog bandwidth should be limited to
1/10 the duty cycle modulator frequency. So for a T2
period of 1000 s, the analog bandwidth should be
100 Hz or less.