AN1611 Impact and Tilt Measurement Using Accelerometer

Freescale Semiconductor
Application Note
AN1611
Rev 3, 10/2004
Impact Measurement Using Accelerometers
by: C.S. Chua
Sensor Application Engineering, Singapore, A/P
INTRODUCTION
This application note describes the concept of measuring
impact of an object using an accelerometer, microcontroller
hardware/software and a liquid crystal display. Due to the wide
frequency response of the accelerometer from d.c. to 400 Hz,
the device is able to measure both the static acceleration from
the Earth’s gravity and the shock or vibration from an impact.
This design uses a 40g accelerometer and yields a minimum
acceleration range of -40g to +40g.
-θ
+θ
SIDE VIEW
PCB
FRONT VIEW
1.0 g
Figure 1. Orientation of Accelerometer
CONCEPT OF IMPACT MEASUREMENT
During an impact, the accelerometer will be oriented as
shown in Figure 1 to measure the deceleration experienced by
the object from dc to 400 Hz. Normally, the peak impact pulse
is in the order of a few miniseconds. Figure 2 shows a typical
crash waveform of a toy car having a stiff bumper.
© Freescale Semiconductor, Inc., 2004. All rights reserved.
50
PEAK IMPACT PULSE
40
30
DECELERATION (G)
20
10
0
-10
-20
-30
-40
0
10
20
30
40
50
60
TIME (ms)
Figure 2. Typical Crash Pattern
HARDWARE DESCRIPTION AND OPERATION
Since the accelerometer is fully signal-conditioned by its
internal op-amp and temperature compensation, the output of
the accelerometer can be directly interfaced with an analogto-digital (A/D) converter for digitization. A filter consists of one
RC network should be added if the connection between the
output of the accelerometer and the A/D converter is a long
track or cable. This stray capacitance may change the position
of the internal pole which would drive the output amplifier of
the accelerometer into oscillation or unstability. In this design,
the cut-off frequency is chosen to be 15.9 kHz which also acts
as an anti-alias filter for the A/D converter. The 3 dB frequency
can be approximated by the following equation.
1
f-3db = ---------------2πRC
Referring to the schematic, Figure 3, the accelerometer is
connected to PORT D bit 5 and the output of the amplifier is
connected to PORT D bit 6 of the microcontroller. This port is
an input to the on-chip 8-bit analog-to-digital (A/D) converter.
Typically, the accelerometer provides a signal output to the
microprocessor of approximately 0.3 Vdc at -55g to 4.7 Vdc at
+55g of acceleration. However, Freescale only guarantees the
accuracy within ±40g range. Using the same reference
voltage for the A/D converter and accelerometer minimizes
the number of additional components, but does sacrifice
resolution. The resolution is defined by the following:
V out
count = ------------- × 255
5
The count at 0g = [2.5/5] × 255 ∝ 128
The count at +25g = [3.5/5] × 255 ∝ 179
The count at -25g = [1.5/5] × 255 ∝ 77
Therefore the resolution 0.5g/count
The output of the accelerometer is ratiometric to the voltage
applied to it. The accelerometer and the reference voltages
are connected to a common supply; this yields a system that
is ratiometric. By nature of this ratiometric system, variations
in the voltage of the power supplied to the system will have no
effect on the system accuracy.
The liquid crystal display (LCD) is directly driven from I/O
ports A, B, and C on the microcontroller. The operation of a
LCD requires that the data and backplane (BP) pins must be
driven by an alternating signal. This function is provided by a
software routine that toggles the data and backplane at
approximately a 30 Hz rate. Other than the LCD, one light
emitting diode (LED) are connected to the pulse length
converter (PLM) of the microcontroller. This LED will light up
for 3 seconds when an impact greater or equal to 7g is
detected.
The microcontroller section of the system requires certain
support hardware to allow it to function. The MC34064P-5
provides an undervoltage sense function which is used to
reset the microprocessor at system power-up. The 4 MHz
crystal provides the external portion of the oscillator function
for clocking the microcontroller and provides a stable base for
time bases functions, for instance calculation of pulse rate.
AN1611, Rev 3
2
Sensor Products
Freescale Semiconductor
SOFTWARE DESCRIPTION
Upon power-up of the system, the LCD will display CAL for
approximately four seconds. During this period, the output of
the accelerometer are sampled and averaged to obtain the
zero offset voltage or zero acceleration. This value will be
saved in the RAM which is used by the equation below to
calculate the impact in term of g-force. One point to note is that
the accelerometer should remain stationary during the zero
calibration.
Impact = [count – countoffset] × resolution
In this software program, the output of the accelerometer is
calculated every 650 µs. During an impact, the peak
deceleration is measured and displayed on the LCD for three
seconds before resetting it to zero. In the mean time, if a
higher impact is detected, the value on the LCD will be
updated accordingly.
However, when a low g is detected (e.g. 1.0g), the value will
not be displayed. Instead, more samples will be taken for
further averaging to eliminate the random noise and high
frequency component. Due to the fact that tilting is a low g and
low frequency signal, large number of sampling is preferred to
avoid unstable display. Moreover, the display value will not
hold for three seconds as in the case of an impact.
Figure 4 is a flowchart for the program that controls the
system.
AN1611, Rev 3
Sensor Products
Freescale Semiconductor
3
R2
MC78L05ACP
4
10 M
5.0 V REGULATOR
X1
22 p
4.0 MHz
C3
1
OUTPUT
GND
2
INPUT
3
ON/OFF SWITCH
270 R
C1
100 µ
D1
9.0 V BATTERY
PB0
PB1
PB2
PB3
PB4
PB5
PB6
PB7
PA0
PA1
PA2
PA3
PA4
PA5
PA6
PA7
VRH
VRL
39
38
37
36
35
34
33
32
31
30
29
28
27
26
25
24
8
7
60
12
27
26
25
24
15
14
13
28
37
36
35
34
7
6
5
L 40
BP
1
BP
G4
F4
A4
B4
C4
D4
E4
8
DP2 2
DP3
32
G2
G3
31
F2 DP E F
F3 30
A2
A3 29
B2 D 1
G A B3 11
C2
C3 10
C
B
D2
D3
9
E2
E3
DP L L
DP1
G1
F1
A1
4
B1
C1
D1 DP
E1
3
LCD5657
PD0/AN0
PD1/AN1
PD2/AN2
PD3/AN3
PD4/AN4
PD5/AN5
PD6/AN6
PD7/AN7
PC0
PC1
PC2/ECLK
PC3
PC4
PC5
PC6
PC7
PLMA
PLMB
ROI
16
23
22
21
20
19
18
17
1
14
13
12
11
9
5
4
3
49
48
47
46
45
44
43
42
20
21
TDO
SCLK
OPEN
52
51
JUMPER
22
23
R6
TCAP1
TCAP2
R5
TCMP1
TCMP2
18
19
16
RST
2
1
C4
RST
IRQ
4.7 k
OSC1
+5.0 V
R1
3
VDD
GND
OSC2
2
10
+5.0 V
17
+5.0 V
MC34064
INPUT
R7
JUMPER
+5.0 V
MC68HC05B16CFN
22 p
R4
Accelerometer
+5.0 V
J2
10 k
R3
10 k
+5.0 V
J1
C2
+5.0 V
100 n
R8
C2′
REWORK
VS
10 n
1.0 k
OUTPUT
3
C3′
Figure 3. Impact Measurement Schematic Drawing
SELF-TEST
4
BYPASS
GND
2
6
0.1 µ
C1′
0.1 µ
AN1611, Rev 3
Sensor Products
Freescale Semiconductor
START
INITIALIZATION CLEAR I/O PORTS
DISPLAY “CAL” FOR
4 SECONDS
AUTO-ZERO
READ ACCELEROMETER
N
CURRENT
VALUE > 2.0 g?
ACCUMLATE THE DATA
Y
N
IS THE
NUMBER OF SAMPLES
ACCUMULATE
= 128?
IS THE IMPACT
> 7.0 g?
N
Y
Y
ACTIVATE THE
BUZZER/LED
TAKE THE AVERAGE
OF THE DATA
IS THE
CURRENT VALUE
> PEAK VALUE?
Y
IS THE 3 SECOND
FOR THE PEAK VALUE
DISPLAY OVER?
N
N
N
Y
HAS THE PEAK
VALUE BEEN DISPLAYED
> 3 SECONDS?
OUTPUT THE CURRENT
Y
PEAK VALUE = CURRENT VALUE
SET 3 SECONDS FOR THE TIMER
INTERRUPT
OUTPUT PEAK VALUE
TO LED
Figure 4. Main Program Flowchart
AN1611, Rev 3
Sensor Products
Freescale Semiconductor
5
SOFTWARE SOURCE/ASSEMBLY PROGRAM CODE
******************************************************************************
*
*
*
Accelerometer Demo Car Version 2.0
*
*
*
*
The following code is written for MC68HC705B16 using MMDS05 software
*
*
Version 1.01
*
*
CASM05 - Command line assembler Version 3.04
*
*
P & E Microcomputer Systems, Inc.
*
*
*
*
Written by : C.S. Chua
*
*
29 August 1996
*
*
*
*
*
*
Copyright Freescale Electronics Pte Ltd 1996
*
*
All rights Reserved
*
*
*
*
This software is the property of Freescale Electronics Pte Ltd.
*
*
*
*
Any usage or redistribution of this software without the express
*
*
written consent of Freescale is strictly prohibited.
*
*
*
*
Freescale reserves the right to make changes without notice to any
*
*
products herein to improve reliability, function, or design. Freescale *
*
does not assume liability arising out of the application or use of any
*
*
product or circuit described herein, neither does it convey license
*
*
under its patents rights nor the rights of others. Freescale products are *
*
not designed, intended or authorised for use as component in systems
*
*
intended to support or sustain life or for any other application in
*
*
which the failure of the Freescale product could create a situation
*
*
a situation where personal injury or death may occur. Should the buyer
*
*
shall indemnify and hold Freescale products for any such unintended or
*
*
unauthorised application, buyer shall indemnify and hold Freescale and
*
*
its officers, employees, subsidiaries, affiliates, and distributors
*
*
harmless against all claims, costs, damages, expenses and reasonable
*
*
attorney fees arising out of, directly or indirectly, any claim of
*
*
personal injury or death associated with such unintended or unauthorised *
*
use, even if such claim alleges that Freescale was negligent regarding
*
*
the design or manufacture of the part.
*
*
*
*
Freescale and the Freescale logo are registered trademarks of Freescale Inc.*
*
*
*
Freescale Inc. is an equal opportunity/affirmative action employer.
*
*
*
******************************************************************************
******************************************************************************
*
*
*
Software Description
*
*
*
*
This software is used to read the output of the accelerometer MMA2200W
*
*
and display it to a LCD as gravity force. It ranges from -55g to +55g
*
*
with 0g as zero acceleration or constant velocity. The resolution is
*
*
0.5g.
*
*
*
*
The program will read from the accelerometer and hold the maximum
*
*
deceleration value for about 3.0 seconds before resetting. At the same
*
*
time, the buzzer/LED is activated if the impact is more than 7.0g.
*
*
However, if the maximum deceleration changes before 3.0 seconds, it
*
*
will update the display using the new value. Note that positive value
*
*
implies deceleration whereas negative value implies acceleration
*
*
*
******************************************************************************
******************************************
*
*
*
Initialisation
*
*
*
******************************************
PORTA
EQU
$00
; Last digit
PORTB
PORTC
ADDATA
ADSTAT
PLMA
MISC
TCONTROL
TSTATUS
OCMPHI1
EQU
EQU
EQU
EQU
EQU
EQU
EQU
EQU
EQU
$01
$02
$08
$09
$0A
$0C
$12
$13
$16
;
;
;
;
;
;
;
;
;
Second digit (and negative sign)
First digit (and decimal point)
ADC Data
ADC Status
Pulse Length Modulator (Output to Buzzer)
Miscellaneous Register (slow/fast mode)
Timer control register
Timer Status Register
Output Compare Register 1 High Byte
AN1611, Rev 3
6
Sensor Products
Freescale Semiconductor
OCMPLO1
EQU
$17
; Output Compare Register 1 Low Byte
TCNTHI
EQU
$18
; Timer Count Register High Byte
TCNTLO
EQU
$19
; Timer Count Register Low Byte
OCMPHI2
EQU
$1E
; Output Compare Register 2 High Byte
OCMPLO2
EQU
$1F
; Output Compare Register 2 Low Byte
******************************************
*
*
*
User-defined RAM
*
*
*
******************************************
SIGN
EQU
$54
; Acceleration (-) or deceleration (+)
PRESHI2
EQU
$55
; MSB of accumulated acceleration
PRESHI
EQU
$56
PRESLO
EQU
$57
; LSB of accumulated acceleration
PTEMPHI
EQU
$58
; Acceleration High Byte (Temp storage)
PTEMPLO
EQU
$59
; Acceleration Low Byte (Temp storage)
ACCHI
EQU
$5A
; Temp storage of acc value (High byte)
ACCLO
EQU
$5B
;
(Low byte)
ADCOUNTER
EQU
$5C
; Sampling Counter
AVERAGE_H
EQU
$5D
; MSB of the accumulated data of low g
AVERAGE_M
EQU
$5E
AVERAGE_L
EQU
$5F
; LSB of the accumulated data of low g
SHIFT_CNT
EQU
$60
; Counter for shifting the accumulated data
AVE_CNT1
EQU
$61
; Number of samples in the accumulated data
AVE_CNT2
EQU
$75
TEMPTCNTHI
EQU
$62
; Temp storage for Timer count register
TEMPTCNTLO
EQU
$63
; Temp storage for Timer count register
DECHI
EQU
$64
; Decimal digit high byte
DECLO
EQU
$65
; Decimal digit low byte
DCOFFSETHI
EQU
$66
; DC offset of the output (high byte)
DCOFFSETLO
EQU
$67
; DC offset of the output (low byte)
MAXACC
EQU
$68
; Maximum acceleration
TEMPHI
EQU
$69
TEMPLO
EQU
$6A
TEMP1
EQU
$6B
; Temporary location for ACC during delay
TEMP2
EQU
$6C
; Temporary location for ACC during ISR
DIV_LO
EQU
$6D
; No of sampling (low byte)
DIV_HI
EQU
$6E
; No of sampling (high byte)
NO_SHIFT
EQU
$6F
; No of right shift to get average value
ZERO_ACC
EQU
$70
; Zero acceleration in no of ADC steps
HOLD_CNT
EQU
$71
; Hold time counter
HOLD_DONE
EQU
$72
; Hold time up flag
START_TIME
EQU
$73
; Start of count down flag
RSHIFT
EQU
$74
; No of shifting required for division
ORG
$300
; ROM space 0300 to 3DFE (15,104 bytes)
DB
$FC
; Display "0"
DB
$30
; Display "1"
DB
$DA
; Display "2"
DB
$7A
; Display "3"
DB
$36
; Display "4"
DB
$6E
; Display "5"
DB
$EE
; Display "6"
DB
$38
; Display "7"
DB
$FE
; Display "8"
DB
$7E
; Display "9"
HUNDREDHI
DB
$00
; High byte of hundreds
HUNDREDLO
DB
$64
; Low byte of hundreds
TENHI
DB
$00
; High byte of tens
TENLO
DB
$0A
; Low byte of tens
******************************************
*
*
*
Program starts here upon hard reset *
*
*
******************************************
RESET
CLR
PORTC
; Port C = 0
CLR
PORTB
; Port B = 0
CLR
PORTA
; Port A = 0
LDA
#$FF
STA
$06
; Port C as output
STA
$05
; Port B as output
STA
$04
; Port A as output
LDA
TSTATUS
; Dummy read the timer status register
CLR
OCMPHI2
; so as to clear the OCF
CLR
OCMPHI1
LDA
OCMPLO2
JSR
COMPRGT
CLR
START_TIME
AN1611, Rev 3
Sensor Products
Freescale Semiconductor
7
IDLE
REPEAT
SHIFTING
LDA
STA
CLI
LDA
STA
LDA
STA
LDA
STA
LDA
JSR
DECA
BNE
LDA
STA
LDA
STA
LDA
STA
JSR
LDX
LDA
STA
MUL
STA
TXA
STA
CLR
LDA
STA
LDA
STA
LDA
STA
LDA
STA
JSR
CLR
CLR
CLR
CLR
CLR
CLR
CLR
JSR
LDA
ADD
CMP
BLO
LDA
ADD
STA
CLRA
ADC
STA
CLRA
ADC
STA
LDA
ADD
STA
CLRA
ADC
STA
CMP
BNE
LDA
CMP
BNE
INC
LSR
ROR
ROR
LDA
CMP
BLO
LDA
#$40
TCONTROL
; Enable the output compare interrupt
; Interrupt begins here
; Port C = 1100 1100
Letter "C"
#$CC
PORTC
#$BE
PORTB
#$C4
PORTA
#16
DLY20
Letter "A"
; Port A = 1100 0100
Letter "L"
;
;
;
;
;
;
;
;
IDLE
#$00
DIV_LO
#$80
DIV_HI
#!15
NO_SHIFT
READAD
#5
PTEMPLO
ZERO_ACC
Idling for a while (16*0.125 = 2 sec)
for the zero offset to stabilize
before perform auto-zero
Sample the data 32,768 times and take
the average 8000 H = 32,768
Right shift of 15 equivalent to divide
by 32,768
Overall sampling time = 1.033 s)
; Zero acceleration calibration
; Calculate the zero offset
; DC offset = PTEMPLO * 5
DCOFFSETLO
DCOFFSETHI
HOLD_CNT
#$10
DIV_LO
#$00
DIV_HI
#$4
NO_SHIFT
ZERO_ACC
MAXACC
ADTOLCD
START_TIME
AVE_CNT1
AVE_CNT2
SHIFT_CNT
AVERAGE_L
AVERAGE_M
AVERAGE_H
READAD
ZERO_ACC
#$04
PTEMPLO
CRASH
PTEMPLO
AVERAGE_L
AVERAGE_L
; Port B = 1011 1110
; Save the zero offset in the RAM
;
;
;
;
;
Sample the data 16 times and take
the average 0100 H = 16
Right shift of 4 equivalent to divide
by 16
Overall sampling time = 650 us
; Display 0.0g at the start
; Read acceleration from ADC
;
;
;
;
;
If the acceleration < 2.0g
Accumulate the averaged results
for 128 times and take the averaging
again to achieve more stable
reading at low g
AVERAGE_M
AVERAGE_M
AVERAGE_H
AVERAGE_H
#$01
AVE_CNT1
AVE_CNT1
AVE_CNT2
AVE_CNT2
#$04
REPEAT
AVE_CNT1
#$00
REPEAT
SHIFT_CNT
AVERAGE_H
AVERAGE_M
AVERAGE_L
SHIFT_CNT
#$0A
SHIFTING
AVERAGE_L
; Take the average of the 128 samples
AN1611, Rev 3
8
Sensor Products
Freescale Semiconductor
STA
PTEMPLO
LDA
HOLD_CNT
; Check if the hold time of crash data
CMP
#$00
; is up
BNE
NON-CRASH
LDA
PTEMPLO
; If yes, display the current acceleration
STA
MAXACC
; value
JSR
ADTOLCD
BRA
NON-CRASH
CRASH
LDA
ZERO_ACC
ADD
#$0E
; If the crash is more than 7g
CMP
PTEMPLO
; 7g = 0E H * 0.5
BHS
NO_INFLATE
LDA
#$FF
; activate the LED
STA
PLMA
NO_INFLATE
JSR
MAXVALUE
; Display the peak acceleration
JSR
ADTOLCD
NON-CRASH
CLR
SHIFT_CNT
CLR
AVE_CNT1
CLR
AVE_CNT2
CLR
AVERAGE_L
CLR
AVERAGE_M
CLR
AVERAGE_H
BRA
REPEAT
; Repeat the whole process
******************************************
*
*
*
Delay Subroutine
*
*
(162 * 0.7725 ms = 0.125 sec)
*
*
*
******************************************
DLY20
STA
TEMP1
LDA
#!162
; 1 unit = 0.7725 ms
OUTLP
CLRX
INNRLP
DECX
BNE
INNRLP
DECA
BNE
OUTLP
LDA
TEMP1
RTS
******************************************
*
*
*
Reading the ADC data X times
*
*
and take the average
*
*
X is defined by DIV_HI and DIV_LO
*
*
*
******************************************
READAD
LDA
#$25
STA
ADSTAT
; AD status = 25H
CLR
PRESHI2
CLR
PRESHI
; Clear the memory
CLR
PRESLO
CLRX
CLR
ADCOUNTER
LOOP128
TXA
CMP
#$FF
BEQ
INC_COUNT
BRA
CONT
INC_COUNT
INC
ADCOUNTER
CONT
LDA
ADCOUNTER
; If ADCOUNTER = X
CMP
DIV_HI
; Clear bit = 0
BEQ
CHECK_X
; Branch to END100
BRA
ENDREAD
CHECK_X
TXA
CMP
DIV_LO
BEQ
END128
ENDREAD
BRCLR
7,ADSTAT,ENDREAD ; Halt here till AD read is finished
LDA
ADDATA
; Read the AD register
ADD
PRESLO
; PRES = PRES + ADDATA
STA
PRESLO
CLRA
ADC
PRESHI
STA
PRESHI
CLRA
ADC
PRESHI2
STA
PRESHI2
INCX
; Increase the AD counter by 1
BRA
LOOP128
; Branch to Loop128
END128
CLR
RSHIFT
; Reset the right shift counter
AN1611, Rev 3
Sensor Products
Freescale Semiconductor
9
DIVIDE
INC
RSHIFT
; Increase the right counter
LSR
PRESHI2
ROR
PRESHI
; Right shift the high byte
ROR
PRESLO
; Right shift the low byte
LDA
RSHIFT
CMP
NO_SHIFT
; If the right shift counter >= NO_SHIFT
BHS
ENDDIVIDE
; End the shifting
JMP
DIVIDE
; otherwise continue the shifting
ENDDIVIDE
LDA
PRESLO
STA
PTEMPLO
RTS
******************************************
*
*
*
Timer service interrupt
*
*
Alternates the Port data and
*
*
backplane of LCD
*
*
*
******************************************
TIMERCMP
STA
TEMP2
; Push Accumulator
COM
PORTC
; Port C = - (Port C)
COM
PORTB
; Port B = - (Port B)
COM
PORTA
; Port A = - (Port A)
LDA
START_TIME
; Start to count down the hold time
CMP
#$FF
; if START_TIME = FF
BNE
SKIP_TIME
JSR
CHECK_HOLD
SKIP_TIME
BSR
COMPRGT
; Branch to subroutine compare register
LDA
TEMP2
; Pop Accumulator
RTI
******************************************
*
*
*
Check whether the hold time
*
*
of crash impact is due
*
*
*
******************************************
CHECK_HOLD
DEC
HOLD_CNT
LDA
HOLD_CNT
CMP
#$00
; Is the hold time up?
BNE
NOT_YET
LDA
#$00
; If yes,
STA
PLMA
; stop buzzer
LDA
#$FF
; Set HOLD_DONE to FF indicate that the
STA
HOLD_DONE
; hold time is up
CLR
START_TIME
; Stop the counting down of hold time
NOT_YET
RTS
******************************************
*
*
*
Subroutine reset
*
*
the timer compare register
*
*
*
******************************************
COMPRGT
LDA
TCNTHI
; Read Timer count register
STA
TEMPTCNTHI
; and store it in the RAM
LDA
TCNTLO
STA
TEMPTCNTLO
ADD
#$4C
; Add 1D4C H = 7500 periods
STA
TEMPTCNTLO
; with the current timer count
LDA
TEMPTCNTHI
; 1 period = 2 us
ADC
#$1D
STA
TEMPTCNTHI
; Save the next count to the register
STA
OCMPHI1
LDA
TSTATUS
; Clear the output compare flag
LDA
TEMPTCNTLO
; by access the timer status register
STA
OCMPLO1
; and then access the output compare
RTS
; register
******************************************
*
*
*
Determine which is the next
*
*
acceleration value to be display
*
*
*
******************************************
MAXVALUE
LDA
PTEMPLO
CMP
MAXACC
; Compare the current acceleration with
BLS
OLDMAX
; the memory, branch if it is <= maxacc
BRA
NEWMAX1
OLDMAX
LDA
HOLD_DONE
; Decrease the Holdtime when
CMP
#$FF
; the maximum value remain unchanged
AN1611, Rev 3
10
Sensor Products
Freescale Semiconductor
BEQ
NEWMAX1
; Branch if the Holdtime is due
LDA
MAXACC
; otherwise use the current value
BRA
NEWMAX2
NEWMAX1
LDA
#$C8
; Hold time = 200 * 15 ms = 3 sec
STA
HOLD_CNT
; Reload the hold time for the next
CLR
HOLD_DONE
; maximum value
LDA
#$FF
STA
START_TIME
; Start to count down the hold time
LDA
PTEMPLO
; Take the current value as maximum
NEWMAX2
STA
MAXACC
RTS
******************************************
*
*
*
This subroutine is to convert
*
*
the AD data to the LCD
*
*
Save the data to be diaplayed
*
*
in MAXACC
*
*
*
******************************************
ADTOLCD
SEI
; Disable the Timer Interrupt !!
LDA
#$00
; Load 0000 into the memory
STA
DECHI
LDA
#$00
STA
DECLO
LDA
MAXACC
LDX
#5
MUL
; Acceleration = AD x 5
ADD
DECLO
; Acceleration is stored as DECHI
STA
DECLO
; and DECLO
STA
ACCLO
; Temporary storage
LDA
#$00
; Assume positive deceleration
STA
SIGN
; "00" positive ; "01" negative
CLRA
TXA
ADC
DECHI
STA
DECHI
STA
ACCHI
; Temporary storage
LDA
DECLO
SUB
DCOFFSETLO
; Deceleration = Dec - DC offset
STA
DECLO
LDA
DECHI
SBC
DCOFFSETHI
STA
DECHI
BCS
NEGATIVE
; Branch if the result is negative
BRA
SEARCH
NEGATIVE
LDA
DCOFFSETLO
; Acceleration = DC offset - Dec
SUB
ACCLO
STA
DECLO
LDA
DCOFFSETHI
SBC
ACCHI
STA
DECHI
LDA
#$01
; Assign a negative sign
STA
SIGN
SEARCH
CLRX
; Start the search for hundred digit
LOOP100
LDA
DECLO
; Acceleration = Acceleration - 100
SUB
HUNDREDLO
STA
DECLO
LDA
DECHI
SBC
HUNDREDHI
STA
DECHI
INCX
; X = X + 1
BCC
LOOP100
; if acceleration >= 100, continue the
DECX
; loop100, otherwise X = X - 1
LDA
DECLO
; Acceleration = Acceleration + 100
ADD
HUNDREDLO
STA
DECLO
LDA
DECHI
ADC
HUNDREDHI
STA
DECHI
TXA
; Check if the MSD is zero
AND
#$FF
BEQ
NOZERO
; If MSD is zero, branch to NOZERO
LDA
$0300,X
; Output the first second digit
STA
PORTC
BRA
STARTTEN
NOZERO
LDA
#$00
; Display blank if MSD is zero
STA
PORTC
AN1611, Rev 3
Sensor Products
Freescale Semiconductor
11
STARTTEN
LOOP10
CLRX
; Start to search for ten digit
LDA
DECLO
; acceleration = acceleration - 10
SUB
TENLO
STA
DECLO
LDA
DECHI
SBC
TENHI
STA
DECHI
INCX
BCC
LOOP10
; if acceleration >= 10 continue the
DECX
; loop, otherwise end
LDA
DECLO
; acceleration = acceleration + 10
ADD
TENLO
STA
DECLO
LDA
DECHI
ADC
TENHI
STA
DECHI
LDA
$0300,X
; Output the last second digit
EOR
SIGN
; Display the sign
STA
PORTB
CLRX
; Start to search for the last digit
LDA
DECLO
; declo = declo - 1
TAX
LDA
$0300,X
; Output the last digit
EOR
#$01
; Add a decimal point in the display
STA
PORTA
CLI
; Enable Interrupt again !
RTS
******************************************
*
*
*
This subroutine provides services
*
*
for those unintended interrupts
*
*
*
******************************************
SWI
RTI
; Software interrupt return
IRQ
RTI
; Hardware interrupt
TIMERCAP
RTI
; Timer input capture
TIMERROV
RTI
; Timer overflow
SCI
RTI
; Serial communication Interface
; Interrupt
ORG
$3FF2
; For 68HC05B16, the vector location
FDB
SCI
; starts at 3FF2
FDB
TIMERROV
; For 68HC05B5, the address starts
FDB
TIMERCMP
; 1FF2
FDB
TIMERCAP
FDB
IRQ
FDB
SWI
FDB
RESET
AN1611, Rev 3
12
Sensor Products
Freescale Semiconductor
NOTES
AN1611, Rev 3
Sensor Products
Freescale Semiconductor
13
NOTES
AN1611, Rev 3
14
Sensor Products
Freescale Semiconductor
NOTES
AN1611, Rev 3
Sensor Products
Freescale Semiconductor
15
How to Reach Us:
Home Page:
www.freescale.com
E-mail:
[email protected]
USA/Europe or Locations Not Listed:
Freescale Semiconductor
Technical Information Center, CH370
1300 N. Alma School Road
Chandler, Arizona 85224
+1-800-521-6274 or +1-480-768-2130
[email protected]
Europe, Middle East, and Africa:
Freescale Halbleiter Deutschland GmbH
Technical Information Center
Schatzbogen 7
81829 Muenchen, Germany
+44 1296 380 456 (English)
+46 8 52200080 (English)
+49 89 92103 559 (German)
+33 1 69 35 48 48 (French)
[email protected]
Japan:
Freescale Semiconductor Japan Ltd.
Headquarters
ARCO Tower 15F
1-8-1, Shimo-Meguro, Meguro-ku,
Tokyo 153-0064
Japan
0120 191014 or +81 3 5437 9125
[email protected]
Asia/Pacific:
Freescale Semiconductor Hong Kong Ltd.
Technical Information Center
2 Dai King Street
Tai Po Industrial Estate
Tai Po, N.T., Hong Kong
+800 2666 8080
[email protected]
For Literature Requests Only:
Freescale Semiconductor Literature Distribution Center
P.O. Box 5405
Denver, Colorado 80217
1-800-441-2447 or 303-675-2140
Fax: 303-675-2150
[email protected]
AN1611
Rev. 3
10/2004
Information in this document is provided solely to enable system and software
implementers to use Freescale Semiconductor products. There are no express or
implied copyright licenses granted hereunder to design or fabricate any integrated
circuits or integrated circuits based on the information in this document.
Freescale Semiconductor reserves the right to make changes without further notice to
any products herein. Freescale Semiconductor makes no warranty, representation or
guarantee regarding the suitability of its products for any particular purpose, nor does
Freescale Semiconductor assume any liability arising out of the application or use of any
product or circuit, and specifically disclaims any and all liability, including without
limitation consequential or incidental damages. “Typical” parameters that may be
provided in Freescale Semiconductor data sheets and/or specifications can and do vary
in different applications and actual performance may vary over time. All operating
parameters, including “Typicals”, must be validated for each customer application by
customer’s technical experts. Freescale Semiconductor does not convey any license
under its patent rights nor the rights of others. Freescale Semiconductor products are
not designed, intended, or authorized for use as components in systems intended for
surgical implant into the body, or other applications intended to support or sustain life,
or for any other application in which the failure of the Freescale Semiconductor product
could create a situation where personal injury or death may occur. Should Buyer
purchase or use Freescale Semiconductor products for any such unintended or
unauthorized application, Buyer shall indemnify and hold Freescale Semiconductor and
its officers, employees, subsidiaries, affiliates, and distributors harmless against all
claims, costs, damages, and expenses, and reasonable attorney fees arising out of,
directly or indirectly, any claim of personal injury or death associated with such
unintended or unauthorized use, even if such claim alleges that Freescale
Semiconductor was negligent regarding the design or manufacture of the part.
Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc.
All other product or service names are the property of their respective owners.
© Freescale Semiconductor, Inc. 2004. All rights reserved.