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)
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
During the rotation the minimum (Tmin) and maximum (Tmax) pulse length for each axis are saved along with the period time (Tpcal).
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)
Tpulse * (Tpcal * 2.0g) / Tperiod - (Tmin+Tmax) * (Tpcal * 2.0g) / (2*Tpcal)
A(g) = --------------------------------------------------------------------------
(Tmax - Tmin)
2 * Tpulse * Tpcal - (Tmin+Tmax) * Tperiod
A(g) = 1.0g * --------------------------------------------
(Tmax - Tmin) * Tperiod