The ADXL outputs the acceleration as a PWM signal. The ratio between the pulse length and the period length is the measured acceleration.
A(g) = (Tpulse / Tperiod - 50%) / 12.5%/g
50% means 0g, 75% means +2g and 25% means -2g.
Tperiod
|---------------|
(a) (b) (a) (b)
_______ _______ _______ _______
X-AXIS ___/ \_______/ \_______/ \_______/ \_______
_____ _____ _____ _____
Y-AXIS ____/ \_________/ \_________/ \_________/ \________
(c) (d) (c) (d)
a,b,c,d are the different events recorded by the input capture routine
The ICP (Input Capture Pin) and Acomp (Analog Comparator) is used sample the x-axis and the y-axis alternativly. One axis is connected to the ICP pin and one axis is connected to the positive input of the analog comparator. The negative input of the comparator is biased with half the supply to the ADXL using two 47K resistors. Period time (Tp) is the average of "Time from rising edge of x-axis to rising edge of y-axis" and "Time from rising edge y-axis to rising edge of x-axis"
This algorithm is somewhat different than the one described in the application note. I think this algorithm is easier to understand and requires less computations.
The two different axis can be selected by changing the Analog Comparator Input Capture Enable bit in the Analog Comparator Control Status Register.
Ta = Counter sampled at (a)
Tc = Counter sampled at (c)
Tac = Time from rising X-axis edge to rising Y-axis edge
Tca = Time from rising Y-axis edge to rising X-axis edge
Tp = = Tperiod = Period Time = (Tac + Tca) / 2
Tx = Tab = length of X-axis pulse
Ty = Tcd = length of Y-axis pulse
- (a) Rising edge of X-Axis
- Tca = CNT - Tc
- Save Ta
- Enable output compare (Ta) overflow
- Tp = (Tac + Tca) / 2
- Enable X-axis falling edge
- (b) Falling edge of X-Axis
- Tx = CNT - Ta
- Switch to Y-axis
- Enable Y-axis rising edge
- (c) Rising edge of Y-Axis
- Tac = CNT - Ta
- Save Tc
- Enable output compare (Tc) overflow
- Tp = (Tca + Tac) / 2
- Enable Y-axis falling edge
- (d) Falling edge of Y-Axis
- Ty = CNT - Tc
- Switch to X-axis
- Enable X-axis rising edge
Ta and Tc are stored in one shared variable. The counter is never reset and is free running, it restarts at zero after 65355. 16 bit arethmetics is used to get correct number of ticks. To detect timer overflows (when period time is to long) output compare is enabled at (a) and (c) . If the interrupt triggers it means that the period time is to long and the prescaler or the Rset for the ADXL202 need to be adjusted.
By rotating the accelerometer 360 or more degrees both axis are subjected to +-1g. Calibration info is recorded during this rotation. ADXL_CalibrationInfo_t. See also User Manual.
During the rotation the minimum (Tmin) and maximum (Tmax) pulse length for each axis are saved along with the period time (Tpcal).
The zero g offset ratio (nomally 50%) is:
Z = (Tmin+Tmax) / (2*Tpcal)
The scale (nomally 12.5%/g) is:
S = ((Tmax - Tmin) / Tpcal) / 2.0g = (Tmax - Tmin) / (2.0g * Tpcal)
Expressed using zero g offset (Z) and scale (S) the acceleration is:
A(g) = ((Tpulse / Tperiod) - Z) / S
Tpulse / Tperiod - (Tmin+Tmax) / (2 * Tpcal)
A(g) = ----------------------------------------------
(Tmax - Tmin) / (2.0g * Tpcal)
Move (2.0g * Tpcal) division: Tpulse * (Tpcal * 2.0g) / Tperiod - (Tmin+Tmax) * (Tpcal * 2.0g) / (2*Tpcal)
A(g) = --------------------------------------------------------------------------
(Tmax - Tmin)
Multiply nomand denom by Tperiod, break out 1g and skip 2*Tpcal from subtraction element: 2 * Tpulse * Tpcal - (Tmin+Tmax) * Tperiod
A(g) = 1.0g * --------------------------------------------
(Tmax - Tmin) * Tperiod
Copyright 2002 Jörgen
Birkler. For accelR8 Accelerometer on
Mon Jan 19 21:43:20 2004 by Doxygen 1.3.5.