Analog Devices AN603 Application Notes

AN-603
a
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
Introduction
There are many applications where high accuracy mea­surement 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 encoun­tered 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 ±40of 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
acceleration T T g duty cycle= (( 1/ 2) – (0 )) 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
acceleration T T at g T= (( 1– 2 0 ) 2) 12.5%
Over a range of ±35of 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
2 500
=
gs s
1 (500 ) (12.5%) 62.5
=¥=
sg s 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:
T scalefactor21 0016(( ) ( . ))
So, for example, for a scale factor of 10%:
T2 s=¥=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 inter­ested 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 per­cent. 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.
as shown in Figure 1 is recommended. This
SET
T
2 error may be trimmed out
T
2 such that the 16 mg per s (or
T
2 accuracy.
REV. 0
© Analog Devices, Inc., 2002
AN-603
Table I. Tilt Angle vs. Error
Tilt Angle
g
Generated T1 in ␮s Error
00.000 0 0
20.034 2 0
40.069 4 0
60.104 6 0
80.139 8 0
10 0.173 10 0
12 0.207 12 0
14 0.241 15 1
16 0.275 17 1
18 0.309 19 1
20 0.342 21 1
22 0.374 23 1
24 0.406 25 1
26 0.438 27 1
The assumption that over ±35of 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 tak­ing 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.
V
DD
28 0.469 29 1
30 0.500 31 1
32 0.529 33 1
34 0.559 34 0
36 0.587 36 0
38 0.615 38 0
40 0.642 40 0
20k
50k
Y
FILT
Figure 1. Circuit for Trimming T2
C
DC
X
FILT
–2–
REV. 0
Program Listing and Flow Chart
;***********************************************************************
;
;********** 202-T1.ASM ***************************************
;********** REVISION: 0 ***************************************
;
; RELEASED: SEPT. 16, 1998
; REVISED:
;
; THIS SOFTWARE USES T1 MEASUREMENTS ONLY TO DETERMINE ACCELERATION
; EXPERIENCED BY THE ADXL202. THE OUTPUT IS A 1-BYTE HEXADECIMAL
; NUMBER PER AXIS OF RANGE 00 TO FF. THE MOST SIGNIFICANT BIT IS A SIGN
; BIT. A 1 IN THE MSB INDICATES POSITIVE ACCELERATION. A 0 IN THE MSB
AN-603
; INDICATES NEGATIVE ACCELERATION. TO MAKE THE SOFTWARE AS COMPACT AS
; POSSIBLE, T2 IS ASSUMED TO HAVE A FIXED VALUE. VARIATION FROM THIS
; VALUE WILL RESULT IN ERROR. IT IS ALSO ASSUMED THAT THE FACTOR OF
; IS FIXED AS SHOWN IN THE TABLE BELOW. SO FOR TILT MEASUREMENT OVER
; 40 DEGREES, THIS ROUTINE IS ACCURATE TO APPROXIMATELY ONE DEGREE.
; SINCE THE OUTPUT IS A 1-BYTE NUMBER, RESPONSE IS LIMITED TO ⫾ 1 g.
;
; T2 (IN mSEC)
; 1000 0.008 2
; 2000 0.004 4
; 4000 0.002 8
; 8000 0.001 16
;
;======================================================================
g
/T1 (HOW MANY g FOR 1 mSEC) mSEC/DEGREE
g
/T1
LIST P=16C62A ;SPECIFY PROCESSOR
;======================================================================
REV. 0
–3–
AN-603
;======================================================================
;
; REGISTER DEFINITIONS
;
;======================================================================
W EQU H'0000'
F EQU H'0001'
;----- REGISTER FILES--------------------------------------------------
INDF EQU H'0000'
TMR0 EQU H'0001'
PCL EQU H'0002'
STATUS EQU H'0003'
FSR EQU H'0004'
PORTA EQU H'0005'
PORTB EQU H'0006'
PORTC EQU H'0007'
PCLATH EQU H'000A'
INTCON EQU H'000B'
PIR1 EQU H'000C'
TMR1L EQU H'000E'
TMR1H EQU H'000F'
T1CON EQU H'0010'
TMR2 EQU H'0011'
T2CON EQU H'0012'
SSPBUF EQU H'0013'
SSPCON EQU H'0014'
CCPR1L EQU H'0015'
CCPR1H EQU H'0016'
CCP1CON EQU H'0017'
–4–
REV. 0
OPTION_REG EQU H'0081'
TRISA EQU H'0085'
TRISB EQU H'0086'
TRISC EQU H'0087'
PIE1 EQU H'008C'
PCON EQU H'008E'
PR2 EQU H'0092'
SSPADD EQU H'0093'
SSPSTAT EQU H'0094'
;----- STATUS BITS ----------------------------------------------------
AN-603
IRP EQU H'0007'
RP1 EQU H'0006'
RP0 EQU H'0005'
NOT_TO EQU H'0004'
NOT_PD EQU H'0003'
Z EQU H'0002'
DC EQU H'0001'
C EQU H'0000'
;----- INTCON BITS ----------------------------------------------------
GIE EQU H'0007'
PEIE EQU H'0006'
T0IE EQU H'0005'
INTE EQU H'0004'
RBIE EQU H'0003'
T0IF EQU H'0002'
INTF EQU H'0001'
REV. 0
–5–
AN-603
RBIF EQU H'0000'
;----- PIR1 BITS ------------------------------------------------------
SSPIF EQU H'0003'
CCP1IF EQU H'0002'
TMR2IF EQU H'0001'
TMR1IF EQU H'0000'
;----- T1CON BITS -----------------------------------------------------
T1CKPS1 EQU H'0005'
T1CKPS0 EQU H'0004'
T1OSCEN EQU H'0003'
NOT_T1SYNC EQU H'0002'
T1INSYNC EQU H'0002' ;BACKWARD COMPATIBILITY
TMR1CS EQU H'0001'
TMR1ON EQU H'0000'
;----- T2CON BITS -----------------------------------------------------
TOUTPS3 EQU H'0006'
TOUTPS2 EQU H'0005'
TOUTPS1 EQU H'0004'
TOUTPS0 EQU H'0003'
TMR2ON EQU H'0002'
T2CKPS1 EQU H'0001'
T2CKPS0 EQU H'0000'
;----- SSPCON BITS ----------------------------------------------------
–6–
REV. 0
Loading...
+ 14 hidden pages