annotate src/compass_ops.asm @ 152:19ad15f04f60

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