annotate src/compass_ops.asm @ 147:fdd4e30846ae

some cleanup
author heinrichsweikamp
date Wed, 06 Aug 2014 11:59:04 +0200
parents 11d4fc797f74
children 022b886eddaf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
147
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
1 #include "ostc3.inc"
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
2 #include "i2c.inc"
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
3 #include "tft_outputs.inc"
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
4 #include "isr.inc"
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
5 #include "tft.inc"
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
6 #include "strings.inc"
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
7 #include "wait.inc" ; speed_*
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
8 #include "surfmode.inc"
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
9
0
heinrichsweikamp
parents:
diff changeset
10
heinrichsweikamp
parents:
diff changeset
11 ; Make sure symbols from the .inc are available to the C code:
heinrichsweikamp
parents:
diff changeset
12 ; Filtered data
heinrichsweikamp
parents:
diff changeset
13 global compass_DX_f, compass_DY_f, compass_DZ_f
heinrichsweikamp
parents:
diff changeset
14 global accel_DX_f, accel_DY_f, accel_DZ_f
heinrichsweikamp
parents:
diff changeset
15
heinrichsweikamp
parents:
diff changeset
16 ; Calibration data
heinrichsweikamp
parents:
diff changeset
17 global compass_CX_f
heinrichsweikamp
parents:
diff changeset
18 global compass_CY_f
heinrichsweikamp
parents:
diff changeset
19 global compass_CZ_f
heinrichsweikamp
parents:
diff changeset
20
heinrichsweikamp
parents:
diff changeset
21 ; Tmp values to pass Q15 arithmetics around
heinrichsweikamp
parents:
diff changeset
22 global compass_a
heinrichsweikamp
parents:
diff changeset
23 global compass_b
heinrichsweikamp
parents:
diff changeset
24
heinrichsweikamp
parents:
diff changeset
25 ; Result
heinrichsweikamp
parents:
diff changeset
26 global compass_heading, compass_roll, compass_pitch
heinrichsweikamp
parents:
diff changeset
27
147
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
28 extern compass
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
29 extern compass_reset_calibration
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
30 extern compass_add_calibration
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
31 extern compass_solve_calibration
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
32
0
heinrichsweikamp
parents:
diff changeset
33 compass code
heinrichsweikamp
parents:
diff changeset
34 ;-----------------------------------------------------------------------------
heinrichsweikamp
parents:
diff changeset
35 ; Filter compass values
heinrichsweikamp
parents:
diff changeset
36 ;
heinrichsweikamp
parents:
diff changeset
37 ; Apply linear filtering to input parameters.
heinrichsweikamp
parents:
diff changeset
38
heinrichsweikamp
parents:
diff changeset
39 ; Apply filtering formula:
heinrichsweikamp
parents:
diff changeset
40 ; reg_f += (reg - reg_f) / 4
heinrichsweikamp
parents:
diff changeset
41 FILTER16 MACRO reg, reg_f
heinrichsweikamp
parents:
diff changeset
42 movf reg_f+0,W
heinrichsweikamp
parents:
diff changeset
43 subwf reg+0,W
heinrichsweikamp
parents:
diff changeset
44 movwf PRODL
heinrichsweikamp
parents:
diff changeset
45 movf reg_f+1,W
heinrichsweikamp
parents:
diff changeset
46 subwfb reg+1,W
heinrichsweikamp
parents:
diff changeset
47 movwf PRODH
heinrichsweikamp
parents:
diff changeset
48
heinrichsweikamp
parents:
diff changeset
49 bcf STATUS,C ; Copy sign bit into carry
heinrichsweikamp
parents:
diff changeset
50 btfsc PRODH,7
heinrichsweikamp
parents:
diff changeset
51 bsf STATUS,C
heinrichsweikamp
parents:
diff changeset
52 rrcf PRODH,F ; 16bit shift right
heinrichsweikamp
parents:
diff changeset
53 rrcf PRODL,F
heinrichsweikamp
parents:
diff changeset
54
heinrichsweikamp
parents:
diff changeset
55 bcf STATUS,C ; Copy sign bit into carry
heinrichsweikamp
parents:
diff changeset
56 btfsc PRODH,7
heinrichsweikamp
parents:
diff changeset
57 bsf STATUS,C
heinrichsweikamp
parents:
diff changeset
58 rrcf PRODH,F ; 16bit shift right
heinrichsweikamp
parents:
diff changeset
59 rrcf PRODL,W
heinrichsweikamp
parents:
diff changeset
60
heinrichsweikamp
parents:
diff changeset
61 addwf reg_f+0,F
heinrichsweikamp
parents:
diff changeset
62 movf PRODH,W
heinrichsweikamp
parents:
diff changeset
63 addwfc reg_f+1,F
heinrichsweikamp
parents:
diff changeset
64 ENDM
heinrichsweikamp
parents:
diff changeset
65
147
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
66 global compass_filter
0
heinrichsweikamp
parents:
diff changeset
67 compass_filter:
heinrichsweikamp
parents:
diff changeset
68 banksel compass_DX
heinrichsweikamp
parents:
diff changeset
69
heinrichsweikamp
parents:
diff changeset
70 FILTER16 compass_DX, compass_DX_f
heinrichsweikamp
parents:
diff changeset
71 FILTER16 compass_DY, compass_DY_f
heinrichsweikamp
parents:
diff changeset
72 FILTER16 compass_DZ, compass_DZ_f
heinrichsweikamp
parents:
diff changeset
73 FILTER16 accel_DX, accel_DX_f
heinrichsweikamp
parents:
diff changeset
74 FILTER16 accel_DY, accel_DY_f
heinrichsweikamp
parents:
diff changeset
75 FILTER16 accel_DZ, accel_DZ_f
heinrichsweikamp
parents:
diff changeset
76 banksel common
heinrichsweikamp
parents:
diff changeset
77 return
heinrichsweikamp
parents:
diff changeset
78
heinrichsweikamp
parents:
diff changeset
79 ;-----------------------------------------------------------------------------
heinrichsweikamp
parents:
diff changeset
80
heinrichsweikamp
parents:
diff changeset
81 compass_filter_init:
heinrichsweikamp
parents:
diff changeset
82 movff compass_DX+0, compass_DX_f+0
heinrichsweikamp
parents:
diff changeset
83 movff compass_DX+1, compass_DX_f+1
heinrichsweikamp
parents:
diff changeset
84 movff compass_DY+0, compass_DY_f+0
heinrichsweikamp
parents:
diff changeset
85 movff compass_DY+1, compass_DY_f+1
heinrichsweikamp
parents:
diff changeset
86 movff compass_DZ+0, compass_DZ_f+0
heinrichsweikamp
parents:
diff changeset
87 movff compass_DZ+1, compass_DZ_f+1
heinrichsweikamp
parents:
diff changeset
88 movff accel_DX+0, accel_DX_f+0
heinrichsweikamp
parents:
diff changeset
89 movff accel_DX+1, accel_DX_f+1
heinrichsweikamp
parents:
diff changeset
90 movff accel_DY+0, accel_DY_f+0
heinrichsweikamp
parents:
diff changeset
91 movff accel_DY+1, accel_DY_f+1
heinrichsweikamp
parents:
diff changeset
92 movff accel_DZ+0, accel_DZ_f+0
heinrichsweikamp
parents:
diff changeset
93 movff accel_DZ+1, accel_DZ_f+1
heinrichsweikamp
parents:
diff changeset
94 return
heinrichsweikamp
parents:
diff changeset
95
heinrichsweikamp
parents:
diff changeset
96 ;-----------------------------------------------------------------------------
heinrichsweikamp
parents:
diff changeset
97 ; Q15 fractional numbers: a * b / 2**16 (UNSIGNED)
heinrichsweikamp
parents:
diff changeset
98 ;
heinrichsweikamp
parents:
diff changeset
99 ; Uses 16x16->16 multiply, for positiv integers, keeping only the most
heinrichsweikamp
parents:
diff changeset
100 ; revelant bits.
heinrichsweikamp
parents:
diff changeset
101 ;
heinrichsweikamp
parents:
diff changeset
102 ; Used to multiply two Q15 numbers, in the range 0..1,
heinrichsweikamp
parents:
diff changeset
103 ; represented as 0..32767, that is a / 2**15.
heinrichsweikamp
parents:
diff changeset
104 ;
heinrichsweikamp
parents:
diff changeset
105 ; (a/2**15) * (b/2**15) = a*b / 2**30 = (a*b/2**16) / 2**14.
heinrichsweikamp
parents:
diff changeset
106 ; So to get back a Q15 number, we need a shift-left...
heinrichsweikamp
parents:
diff changeset
107 global compass_umul
heinrichsweikamp
parents:
diff changeset
108 compass_umul:
heinrichsweikamp
parents:
diff changeset
109 rcall compass_mul_16
heinrichsweikamp
parents:
diff changeset
110
heinrichsweikamp
parents:
diff changeset
111 ; The 2x time, by left-shifting inserting the missing bit:
heinrichsweikamp
parents:
diff changeset
112 compass_mul_2:
heinrichsweikamp
parents:
diff changeset
113 rlcf compass_r+2,F ; Missing bit into carry
heinrichsweikamp
parents:
diff changeset
114 rlcf compass_r+0,F
heinrichsweikamp
parents:
diff changeset
115 rlcf compass_r+1,F
heinrichsweikamp
parents:
diff changeset
116 movff compass_r+0,PRODL ; return value into ProdH:L
heinrichsweikamp
parents:
diff changeset
117 movff compass_r+1,PRODH
heinrichsweikamp
parents:
diff changeset
118 return
heinrichsweikamp
parents:
diff changeset
119
heinrichsweikamp
parents:
diff changeset
120 ; The 16x16-> multiply:
heinrichsweikamp
parents:
diff changeset
121 compass_mul_16:
heinrichsweikamp
parents:
diff changeset
122 banksel compass_a
heinrichsweikamp
parents:
diff changeset
123
heinrichsweikamp
parents:
diff changeset
124 movf compass_a+1,W ; Block ah*bh
heinrichsweikamp
parents:
diff changeset
125 mulwf compass_b+1
heinrichsweikamp
parents:
diff changeset
126 movff PRODL,compass_r+0 ; and copy
heinrichsweikamp
parents:
diff changeset
127 movff PRODH,compass_r+1
heinrichsweikamp
parents:
diff changeset
128
heinrichsweikamp
parents:
diff changeset
129 movf compass_a+0,W ; Block al*bl
heinrichsweikamp
parents:
diff changeset
130 mulwf compass_b+0
heinrichsweikamp
parents:
diff changeset
131 movff PRODH,compass_r+2 ; Into fraction byte
heinrichsweikamp
parents:
diff changeset
132
heinrichsweikamp
parents:
diff changeset
133 movf compass_a+1,W ; Block ah*bl
heinrichsweikamp
parents:
diff changeset
134 mulwf compass_b+0
heinrichsweikamp
parents:
diff changeset
135 movf PRODL,W
heinrichsweikamp
parents:
diff changeset
136 addwf compass_r+2,F ; Fraction part to carry.
heinrichsweikamp
parents:
diff changeset
137 movf PRODH,W ; and add16
heinrichsweikamp
parents:
diff changeset
138 addwfc compass_r+0,F
heinrichsweikamp
parents:
diff changeset
139 movlw 0
heinrichsweikamp
parents:
diff changeset
140 addwfc compass_r+1,F
heinrichsweikamp
parents:
diff changeset
141
heinrichsweikamp
parents:
diff changeset
142 movf compass_a+0,W ; Block al*bh
heinrichsweikamp
parents:
diff changeset
143 mulwf compass_b+1
heinrichsweikamp
parents:
diff changeset
144 movf PRODL,W
heinrichsweikamp
parents:
diff changeset
145 addwf compass_r+2,F ; Fraction part to carry.
heinrichsweikamp
parents:
diff changeset
146 movf PRODH,W ; and add16
heinrichsweikamp
parents:
diff changeset
147 addwfc compass_r+0,F
heinrichsweikamp
parents:
diff changeset
148 movlw 0
heinrichsweikamp
parents:
diff changeset
149 addwfc compass_r+1,F
heinrichsweikamp
parents:
diff changeset
150
heinrichsweikamp
parents:
diff changeset
151 return
heinrichsweikamp
parents:
diff changeset
152
heinrichsweikamp
parents:
diff changeset
153 ;-----------------------------------------------------------------------------
heinrichsweikamp
parents:
diff changeset
154 ; Q15 fractional numbers: a * b / 2**16 (SIGNED)
heinrichsweikamp
parents:
diff changeset
155
heinrichsweikamp
parents:
diff changeset
156 global compass_imul
heinrichsweikamp
parents:
diff changeset
157 compass_imul:
heinrichsweikamp
parents:
diff changeset
158 rcall compass_mul_16
heinrichsweikamp
parents:
diff changeset
159
heinrichsweikamp
parents:
diff changeset
160 btfss compass_b+1,7
heinrichsweikamp
parents:
diff changeset
161 bra compass_mul_3
heinrichsweikamp
parents:
diff changeset
162
heinrichsweikamp
parents:
diff changeset
163 movf compass_a+0,W
heinrichsweikamp
parents:
diff changeset
164 subwf compass_r+0,F
heinrichsweikamp
parents:
diff changeset
165 movf compass_a+1,W
heinrichsweikamp
parents:
diff changeset
166 subwfb compass_r+1,F
heinrichsweikamp
parents:
diff changeset
167
heinrichsweikamp
parents:
diff changeset
168 compass_mul_3:
heinrichsweikamp
parents:
diff changeset
169 btfss compass_a+1,7
heinrichsweikamp
parents:
diff changeset
170 bra compass_mul_4
heinrichsweikamp
parents:
diff changeset
171
heinrichsweikamp
parents:
diff changeset
172 movf compass_b+0,W
heinrichsweikamp
parents:
diff changeset
173 subwf compass_r+0,F
heinrichsweikamp
parents:
diff changeset
174 movf compass_b+1,W
heinrichsweikamp
parents:
diff changeset
175 subwfb compass_r+1,F
heinrichsweikamp
parents:
diff changeset
176
heinrichsweikamp
parents:
diff changeset
177 compass_mul_4:
heinrichsweikamp
parents:
diff changeset
178 bcf compass_r+1,6 ; Copy bit 7 to 6, so keep it after 2x
heinrichsweikamp
parents:
diff changeset
179 btfsc compass_r+1,7
heinrichsweikamp
parents:
diff changeset
180 bsf compass_r+1,6
heinrichsweikamp
parents:
diff changeset
181 bra compass_mul_2
heinrichsweikamp
parents:
diff changeset
182
147
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
183 global compass_calibration_loop
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
184 compass_calibration_loop: ; Compass calibration
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
185 bsf no_sensor_int ; No Sensor ISR
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
186 call I2C_sleep_accelerometer ; Stop accelerometer
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
187 call I2C_sleep_compass ; Stop compass
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
188 call TFT_ClearScreen
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
189 ; Mask
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
190 WIN_COLOR color_greenish
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
191 WIN_SMALL .16,.0
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
192 STRCPY_TEXT_PRINT tCompassMenu
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
193 btfss switch_right2 ; wait until button is released
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
194 bra $-4
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
195
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
196 call TFT_standard_color
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
197 ; WIN_SMALL .0,.215
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
198 ; STRCPY_TEXT_PRINT tExit
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
199 WAITMS d'255'
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
200 WAITMS d'255'
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
201 movlw .7 ; Gain init
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
202 movff WREG,opt_compass_gain
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
203 compass_calibration_gainset: ; Reduce the gain, set bank here!
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
204 banksel opt_compass_gain
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
205 decf opt_compass_gain,F ; Reduce by one
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
206 btfsc STATUS,N ; <0?
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
207 clrf opt_compass_gain ; Yes, keep at zero
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
208
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
209 banksel common
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
210 call I2C_init_accelerometer
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
211 call I2C_init_compass_fast
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
212 call TFT_compass_show_gain ; Show the current compass gain
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
213
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
214 WAITMS d'100'
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
215
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
216 clrf timeout_counter2
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
217 clrf timeout_counter3
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
218
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
219 call speed_fastest
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
220 call I2C_RX_compass ; read compass
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
221 call I2C_RX_accelerometer ; read Accelerometer
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
222
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
223 ; Test all axes for +4096 (Hi byte=16)
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
224 banksel compass_DX+1
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
225 movlw .16
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
226 cpfseq compass_DX+1
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
227 bra $+4
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
228 bra compass_calibration_gainset
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
229 cpfseq compass_DY+1
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
230 bra $+4
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
231 bra compass_calibration_gainset
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
232 cpfseq compass_DZ+1
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
233 bra $+4
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
234 bra compass_calibration_gainset
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
235
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
236 ; Test all axes for -4096 (Hi byte=240)
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
237 movlw .240
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
238 cpfseq compass_DX+1
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
239 bra $+4
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
240 bra compass_calibration_gainset
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
241 cpfseq compass_DY+1
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
242 bra $+4
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
243 bra compass_calibration_gainset
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
244 cpfseq compass_DZ+1
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
245 bra $+4
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
246 bra compass_calibration_gainset
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
247 banksel common
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
248
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
249 rcall compass_filter_init ; set DX_f values
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
250 call compass_reset_calibration ; Reset CX_f values
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
251 banksel common
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
252
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
253 compass_calibration_loop2:
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
254 call I2C_RX_compass ; read compass
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
255 call I2C_RX_accelerometer ; Test Accelerometer
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
256 rcall compass_filter ; Filter compass raw data
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
257 banksel common
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
258
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
259 ; Twice
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
260 call I2C_RX_compass ; read compass
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
261 call I2C_RX_accelerometer ; Test Accelerometer
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
262 rcall compass_filter ; Filter compass raw data
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
263 banksel common
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
264
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
265 ; Test all axes for +4096 (Hi byte=16)
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
266 banksel compass_DX+1
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
267 movlw .16
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
268 cpfseq compass_DX+1
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
269 bra $+4
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
270 bra compass_calibration_gainset
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
271 cpfseq compass_DY+1
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
272 bra $+4
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
273 bra compass_calibration_gainset
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
274 cpfseq compass_DZ+1
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
275 bra $+4
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
276 bra compass_calibration_gainset
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
277
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
278 ; Test all axes for -4096 (Hi byte=240)
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
279 movlw .240
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
280 cpfseq compass_DX+1
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
281 bra $+4
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
282 bra compass_calibration_gainset
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
283 cpfseq compass_DY+1
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
284 bra $+4
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
285 bra compass_calibration_gainset
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
286 cpfseq compass_DZ+1
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
287 bra $+4
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
288 bra compass_calibration_gainset
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
289 banksel common
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
290 ;
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
291 ; ; Three
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
292 ; call I2C_RX_compass ; read compass
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
293 ; call I2C_RX_accelerometer ; Test Accelerometer
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
294 ; call compass_filter ; Filter compass raw data
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
295 ; banksel common
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
296 ;
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
297 ; ; Four times to get cleaner values
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
298 ; call I2C_RX_compass ; read compass
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
299 ; call I2C_RX_accelerometer ; Test Accelerometer
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
300 ; call compass_filter ; Filter compass raw data
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
301
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
302 ; And register only one value out of four:
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
303 call compass_add_calibration ; check and store new max/min values
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
304 banksel common
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
305
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
306 call TFT_compass_fast ; show values
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
307
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
308 btfsc sleepmode ; Sleepmode active?
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
309 bra compass_calibration_exit ; Yes, exit
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
310
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
311 ; btfsc switch_left ; Button pressed?
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
312 ; bra compass_calibration_exit ; Yes, exit
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
313
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
314 btfss onesecupdate ; do every second tasks?
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
315 bra compass_calibration_loop2 ; no, loop here
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
316
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
317 movlw .60
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
318 call timeout_testmode ; check timeout
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
319 movlw .60
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
320 call TFT_show_timeout_testmode ; Show the timeout
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
321
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
322 bcf onesecupdate ; clear flag
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
323
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
324 bra compass_calibration_loop2 ; loop here
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
325
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
326 compass_calibration_exit:
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
327 call compass_solve_calibration
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
328 banksel common
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
329 extern option_save_all
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
330 call option_save_all ; save all settings into EEPROM
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
331 bcf sleepmode ; Clear the flag before exiting to surfacemode
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
332 movlw .6
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
333 movwf customview_surfmode ; Set to compass view...
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
334 goto surfloop ; ...and exit
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
335
fdd4e30846ae some cleanup
heinrichsweikamp
parents: 0
diff changeset
336
0
heinrichsweikamp
parents:
diff changeset
337 END