Mercurial > public > hwos_code
comparison src/testmode.asm @ 90:3274e87fd027
NEW: automatic compass gain makes calibration quicker
author | heinrichsweikamp |
---|---|
date | Tue, 15 Apr 2014 14:40:49 +0200 |
parents | 7815bf21d353 |
children | 917393caf559 |
comparison
equal
deleted
inserted
replaced
89:c34516c99ca8 | 90:3274e87fd027 |
---|---|
165 | 165 |
166 | 166 |
167 global compass_calibration_loop | 167 global compass_calibration_loop |
168 compass_calibration_loop: ; Compass calibration | 168 compass_calibration_loop: ; Compass calibration |
169 bsf no_sensor_int ; No Sensor ISR | 169 bsf no_sensor_int ; No Sensor ISR |
170 call I2C_init_accelerometer | |
171 call I2C_init_compass_fast | |
172 call TFT_ClearScreen | 170 call TFT_ClearScreen |
173 | 171 |
174 ; Mask | 172 ; Mask |
175 WIN_COLOR color_greenish | 173 WIN_COLOR color_greenish |
176 WIN_SMALL .16,.0 | 174 WIN_SMALL .16,.0 |
177 STRCPY_TEXT_PRINT tCompassMenu | 175 STRCPY_TEXT_PRINT tCompassMenu |
176 btfss switch_right2 ; wait until button is released | |
177 bra $-4 | |
178 | |
178 call TFT_standard_color | 179 call TFT_standard_color |
179 WIN_SMALL .0,.215 | 180 WIN_SMALL .0,.215 |
180 STRCPY_TEXT_PRINT tExit | 181 STRCPY_TEXT_PRINT tExit |
182 WAITMS d'255' | |
183 WAITMS d'255' | |
184 movlw .8 ; Gain init | |
185 movff WREG,opt_compass_gain | |
186 compass_calibration_gainset: ; Reduce the gain, set bank here! | |
187 banksel opt_compass_gain | |
188 decf opt_compass_gain,F ; Reduce by one | |
189 btfsc STATUS,N ; <0? | |
190 clrf opt_compass_gain ; Yes, keep at zero | |
191 | |
192 banksel common | |
193 call I2C_init_accelerometer | |
194 call I2C_init_compass_fast | |
195 call TFT_compass_show_gain ; Show the current compass gain | |
196 | |
197 WAITMS d'100' | |
181 | 198 |
182 clrf timeout_counter2 | 199 clrf timeout_counter2 |
183 clrf timeout_counter3 | 200 clrf timeout_counter3 |
184 | 201 |
185 call speed_fastest | 202 call speed_fastest |
186 call I2C_RX_compass ; read compass | 203 call I2C_RX_compass ; read compass |
187 call I2C_RX_accelerometer ; read Accelerometer | 204 call I2C_RX_accelerometer ; read Accelerometer |
205 | |
206 ; Test all axes for +4096 (Hi byte=16) | |
207 banksel compass_DX+1 | |
208 movlw .16 | |
209 cpfseq compass_DX+1 | |
210 bra $+4 | |
211 bra compass_calibration_gainset | |
212 cpfseq compass_DY+1 | |
213 bra $+4 | |
214 bra compass_calibration_gainset | |
215 cpfseq compass_DZ+1 | |
216 bra $+4 | |
217 bra compass_calibration_gainset | |
218 | |
219 ; Test all axes for -4096 (Hi byte=240) | |
220 movlw .240 | |
221 cpfseq compass_DX+1 | |
222 bra $+4 | |
223 bra compass_calibration_gainset | |
224 cpfseq compass_DY+1 | |
225 bra $+4 | |
226 bra compass_calibration_gainset | |
227 cpfseq compass_DZ+1 | |
228 bra $+4 | |
229 bra compass_calibration_gainset | |
230 banksel common | |
231 | |
188 call compass_filter_init ; set DX_f values | 232 call compass_filter_init ; set DX_f values |
189 call compass_reset_calibration ; Reset CX_f values | 233 call compass_reset_calibration ; Reset CX_f values |
190 banksel common | 234 banksel common |
191 | 235 |
192 compass_calibration_loop2: | 236 compass_calibration_loop2: |
197 | 241 |
198 ; Twice | 242 ; Twice |
199 call I2C_RX_compass ; read compass | 243 call I2C_RX_compass ; read compass |
200 call I2C_RX_accelerometer ; Test Accelerometer | 244 call I2C_RX_accelerometer ; Test Accelerometer |
201 call compass_filter ; Filter compass raw data | 245 call compass_filter ; Filter compass raw data |
246 banksel common | |
247 | |
248 ; Test all axes for +4096 (Hi byte=16) | |
249 banksel compass_DX+1 | |
250 movlw .16 | |
251 cpfseq compass_DX+1 | |
252 bra $+4 | |
253 bra compass_calibration_gainset | |
254 cpfseq compass_DY+1 | |
255 bra $+4 | |
256 bra compass_calibration_gainset | |
257 cpfseq compass_DZ+1 | |
258 bra $+4 | |
259 bra compass_calibration_gainset | |
260 | |
261 ; Test all axes for -4096 (Hi byte=240) | |
262 movlw .240 | |
263 cpfseq compass_DX+1 | |
264 bra $+4 | |
265 bra compass_calibration_gainset | |
266 cpfseq compass_DY+1 | |
267 bra $+4 | |
268 bra compass_calibration_gainset | |
269 cpfseq compass_DZ+1 | |
270 bra $+4 | |
271 bra compass_calibration_gainset | |
202 banksel common | 272 banksel common |
203 ; | 273 ; |
204 ; ; Three | 274 ; ; Three |
205 ; call I2C_RX_compass ; read compass | 275 ; call I2C_RX_compass ; read compass |
206 ; call I2C_RX_accelerometer ; Test Accelerometer | 276 ; call I2C_RX_accelerometer ; Test Accelerometer |
215 ; And register only one value out of four: | 285 ; And register only one value out of four: |
216 call compass_add_calibration ; check and store new max/min values | 286 call compass_add_calibration ; check and store new max/min values |
217 banksel common | 287 banksel common |
218 | 288 |
219 call TFT_compass_fast ; show values | 289 call TFT_compass_fast ; show values |
220 ; btg LEDg ; Show read-out interval | |
221 | 290 |
222 btfsc sleepmode ; Sleepmode active? | 291 btfsc sleepmode ; Sleepmode active? |
223 bra compass_calibration_exit ; Yes, exit | 292 bra compass_calibration_exit ; Yes, exit |
224 | 293 |
225 btfsc switch_left ; Button pressed? | 294 btfsc switch_left ; Button pressed? |
239 banksel common | 308 banksel common |
240 extern option_save_all | 309 extern option_save_all |
241 call option_save_all ; save all settings into EEPROM | 310 call option_save_all ; save all settings into EEPROM |
242 bcf sleepmode ; Clear the flag before exiting to surfacemode | 311 bcf sleepmode ; Clear the flag before exiting to surfacemode |
243 movlw .6 | 312 movlw .6 |
244 movwf menupos3 ; Set to compass view... | 313 movwf customview_surfmode ; Set to compass view... |
245 goto surfloop ; ...and exit | 314 goto surfloop ; ...and exit |
246 | 315 |
247 END | 316 END |