Mercurial > public > hwos_code
annotate src/testmode.asm @ 100:9c7d9e7198c0
1.30 release
author | heinrichsweikamp |
---|---|
date | Fri, 02 May 2014 19:38:14 +0200 |
parents | f2201aa374db |
children | e3ac5b2021bc |
rev | line source |
---|---|
0 | 1 ;============================================================================= |
2 ; | |
3 ; File tesmode.asm | |
4 ; | |
5 ; Test Mode for Hardware check | |
6 ; | |
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. | |
8 ;============================================================================= | |
9 ; HISTORY | |
10 ; 2012-10-31 : [mH] Creation | |
11 | |
12 #include "ostc3.inc" ; Mandatory header | |
13 #include "shared_definitions.h" ; Mailbox from/to p2_deco.c | |
14 #include "start.inc" | |
15 #include "tft.inc" | |
16 #include "tft_outputs.inc" | |
17 #include "isr.inc" | |
18 #include "adc_lightsensor.inc" | |
19 #include "strings.inc" | |
20 #include "sleepmode.inc" | |
21 #include "wait.inc" ; speed_* | |
22 #include "mcp.inc" ; RX | |
23 #include "i2c.inc" | |
24 #include "surfmode.inc" | |
25 #include "math.inc" | |
26 #include "eeprom_rs232.inc" | |
67 | 27 #include "ms5541.inc" |
0 | 28 |
29 extern compass | |
30 extern compass_filter | |
31 extern compass_filter_init | |
32 extern compass_reset_calibration | |
33 extern compass_add_calibration | |
34 extern compass_solve_calibration | |
35 | |
36 testmode CODE | |
37 | |
38 ;============================================================================= | |
39 ; Boot tasks for all modes | |
40 global testloop | |
67 | 41 testloop: ; Page1 |
0 | 42 call speed_normal |
43 bcf no_sensor_int ; Sensor ISR | |
44 | |
45 clrf CCP1CON ; stop PWM | |
46 bcf PORTC,2 ; Pull PWM output to GND | |
47 call TFT_boot ; Initialize TFT (includes clear screen) | |
48 call enable_ir ; Enable IR-Port | |
49 WIN_TOP .0 | |
50 WIN_LEFT .0 | |
51 WIN_FONT FT_SMALL | |
52 WIN_INVERT .0 ; Init new Wordprocessor | |
53 call TFT_standard_color | |
54 call TFT_Display_FadeIn | |
55 | |
56 call I2C_init_compass | |
57 call I2C_init_accelerometer | |
58 | |
59 ; Init compass/accel filtering value. | |
60 call I2C_RX_compass | |
61 call I2C_RX_accelerometer | |
62 call compass_filter_init | |
63 | |
64 clrf timeout_counter2 | |
65 clrf timeout_counter3 | |
66 bcf premenu ; clear premenu flag | |
67 bcf menubit ; clear menu flag | |
68 | |
69 bcf switch_left | |
70 bcf switch_right | |
71 | |
72 testloop_loop: | |
73 btfss onesecupdate ; do every second tasks? | |
74 bra testloop_loop2 ; no, loop | |
75 | |
76 ; One Second tasks | |
77 call speed_normal | |
78 call I2C_RX_compass ; Test Compass | |
79 call I2C_RX_accelerometer ; Test Accelerometer | |
80 call compass_filter ; Filter Raw compass + accel readings. | |
81 banksel common | |
82 | |
83 ; Make a second measure and filter, to show faster reactions. | |
84 call I2C_RX_compass ; Test Compass | |
85 call I2C_RX_accelerometer ; Test Accelerometer | |
86 call compass_filter ; Filter Raw compass + accel readings. | |
87 call compass ; Do compass corrections. | |
88 banksel common | |
89 | |
90 call TFT_update_raw_data | |
91 movlw .240 | |
92 call timeout_testmode ; check timeout | |
93 | |
94 bcf onesecupdate ; every second tasks done | |
95 | |
96 testloop_loop2: | |
97 ; Tasks approx. every 50ms for all modes | |
98 bcf LEDg | |
99 btfsc vusb_in | |
100 bsf LEDg | |
101 | |
102 ; Mode tasks | |
103 extern surfloop | |
104 btfsc switch_left | |
67 | 105 bra testloop2 ; Page 2 |
0 | 106 |
107 btfsc switch_right | |
108 goto compass_calibration_loop | |
109 | |
110 btfsc sleepmode ; Sleepmode active? | |
67 | 111 bra testloop2 ; Page 2 |
112 | |
113 bra testloop_loop ; loop testmode | |
114 | |
115 testloop2: ; Page2 | |
116 call speed_normal | |
117 bsf no_sensor_int ; disable sensor interrupt | |
118 call get_calibration_data ; Get calibration data from pressure sensor | |
119 banksel common ; get_calibration_data uses isr_backup | |
120 bcf no_sensor_int ; normal sensor interrupt mode | |
121 | |
122 clrf CCP1CON ; stop PWM | |
123 bcf PORTC,2 ; Pull PWM output to GND | |
124 call TFT_boot ; Initialize TFT (includes clear screen) | |
125 WIN_TOP .0 | |
126 WIN_LEFT .0 | |
127 WIN_FONT FT_SMALL | |
128 WIN_INVERT .0 ; Init new Wordprocessor | |
129 call TFT_standard_color | |
130 call TFT_Display_FadeIn | |
131 | |
132 clrf timeout_counter2 | |
133 clrf timeout_counter3 | |
134 bcf premenu ; clear premenu flag | |
135 bcf menubit ; clear menu flag | |
136 | |
137 bcf switch_left | |
138 bcf switch_right | |
139 | |
140 testloop2_loop: | |
141 btfss onesecupdate ; do every second tasks? | |
142 bra testloop2_loop2 ; no, loop | |
143 | |
144 ; One Second tasks | |
145 call TFT_update_raw_data2 | |
146 movlw .240 | |
147 call timeout_testmode ; check timeout | |
148 | |
149 bcf onesecupdate ; every second tasks done | |
150 | |
151 testloop2_loop2: | |
152 ; Tasks approx. every 50ms for all modes | |
153 bcf LEDg | |
154 btfsc vusb_in | |
155 bsf LEDg | |
156 | |
157 ; Mode tasks | |
158 btfsc switch_left | |
159 goto surfloop ; Exit | |
160 | |
161 btfsc sleepmode ; Sleepmode active? | |
0 | 162 goto sleeploop ; Yes, switch into sleepmode! |
163 | |
67 | 164 bra testloop2_loop ; loop testmode |
0 | 165 |
166 | |
167 global compass_calibration_loop | |
168 compass_calibration_loop: ; Compass calibration | |
169 bsf no_sensor_int ; No Sensor ISR | |
91
917393caf559
minor, always re-init compass in calibration loop
heinrichsweikamp
parents:
90
diff
changeset
|
170 call I2C_sleep_accelerometer ; Stop accelerometer |
917393caf559
minor, always re-init compass in calibration loop
heinrichsweikamp
parents:
90
diff
changeset
|
171 call I2C_sleep_compass ; Stop compass |
0 | 172 call TFT_ClearScreen |
173 ; Mask | |
174 WIN_COLOR color_greenish | |
175 WIN_SMALL .16,.0 | |
176 STRCPY_TEXT_PRINT tCompassMenu | |
90
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
177 btfss switch_right2 ; wait until button is released |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
178 bra $-4 |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
179 |
0 | 180 call TFT_standard_color |
94
f2201aa374db
BUGFIX: compass calibration does now timeout automatically after 60s
heinrichsweikamp
parents:
91
diff
changeset
|
181 ; WIN_SMALL .0,.215 |
f2201aa374db
BUGFIX: compass calibration does now timeout automatically after 60s
heinrichsweikamp
parents:
91
diff
changeset
|
182 ; STRCPY_TEXT_PRINT tExit |
90
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
183 WAITMS d'255' |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
184 WAITMS d'255' |
94
f2201aa374db
BUGFIX: compass calibration does now timeout automatically after 60s
heinrichsweikamp
parents:
91
diff
changeset
|
185 movlw .7 ; Gain init |
90
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
186 movff WREG,opt_compass_gain |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
187 compass_calibration_gainset: ; Reduce the gain, set bank here! |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
188 banksel opt_compass_gain |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
189 decf opt_compass_gain,F ; Reduce by one |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
190 btfsc STATUS,N ; <0? |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
191 clrf opt_compass_gain ; Yes, keep at zero |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
192 |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
193 banksel common |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
194 call I2C_init_accelerometer |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
195 call I2C_init_compass_fast |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
196 call TFT_compass_show_gain ; Show the current compass gain |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
197 |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
198 WAITMS d'100' |
0 | 199 |
200 clrf timeout_counter2 | |
201 clrf timeout_counter3 | |
202 | |
203 call speed_fastest | |
204 call I2C_RX_compass ; read compass | |
205 call I2C_RX_accelerometer ; read Accelerometer | |
90
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
206 |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
207 ; Test all axes for +4096 (Hi byte=16) |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
208 banksel compass_DX+1 |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
209 movlw .16 |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
210 cpfseq compass_DX+1 |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
211 bra $+4 |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
212 bra compass_calibration_gainset |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
213 cpfseq compass_DY+1 |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
214 bra $+4 |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
215 bra compass_calibration_gainset |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
216 cpfseq compass_DZ+1 |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
217 bra $+4 |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
218 bra compass_calibration_gainset |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
219 |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
220 ; Test all axes for -4096 (Hi byte=240) |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
221 movlw .240 |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
222 cpfseq compass_DX+1 |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
223 bra $+4 |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
224 bra compass_calibration_gainset |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
225 cpfseq compass_DY+1 |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
226 bra $+4 |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
227 bra compass_calibration_gainset |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
228 cpfseq compass_DZ+1 |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
229 bra $+4 |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
230 bra compass_calibration_gainset |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
231 banksel common |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
232 |
0 | 233 call compass_filter_init ; set DX_f values |
234 call compass_reset_calibration ; Reset CX_f values | |
235 banksel common | |
236 | |
237 compass_calibration_loop2: | |
238 call I2C_RX_compass ; read compass | |
239 call I2C_RX_accelerometer ; Test Accelerometer | |
240 call compass_filter ; Filter compass raw data | |
241 banksel common | |
242 | |
243 ; Twice | |
244 call I2C_RX_compass ; read compass | |
245 call I2C_RX_accelerometer ; Test Accelerometer | |
246 call compass_filter ; Filter compass raw data | |
247 banksel common | |
90
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
248 |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
249 ; Test all axes for +4096 (Hi byte=16) |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
250 banksel compass_DX+1 |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
251 movlw .16 |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
252 cpfseq compass_DX+1 |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
253 bra $+4 |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
254 bra compass_calibration_gainset |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
255 cpfseq compass_DY+1 |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
256 bra $+4 |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
257 bra compass_calibration_gainset |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
258 cpfseq compass_DZ+1 |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
259 bra $+4 |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
260 bra compass_calibration_gainset |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
261 |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
262 ; Test all axes for -4096 (Hi byte=240) |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
263 movlw .240 |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
264 cpfseq compass_DX+1 |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
265 bra $+4 |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
266 bra compass_calibration_gainset |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
267 cpfseq compass_DY+1 |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
268 bra $+4 |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
269 bra compass_calibration_gainset |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
270 cpfseq compass_DZ+1 |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
271 bra $+4 |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
272 bra compass_calibration_gainset |
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
273 banksel common |
0 | 274 ; |
275 ; ; Three | |
276 ; call I2C_RX_compass ; read compass | |
277 ; call I2C_RX_accelerometer ; Test Accelerometer | |
278 ; call compass_filter ; Filter compass raw data | |
279 ; banksel common | |
280 ; | |
281 ; ; Four times to get cleaner values | |
282 ; call I2C_RX_compass ; read compass | |
283 ; call I2C_RX_accelerometer ; Test Accelerometer | |
284 ; call compass_filter ; Filter compass raw data | |
285 | |
286 ; And register only one value out of four: | |
287 call compass_add_calibration ; check and store new max/min values | |
288 banksel common | |
289 | |
290 call TFT_compass_fast ; show values | |
291 | |
292 btfsc sleepmode ; Sleepmode active? | |
293 bra compass_calibration_exit ; Yes, exit | |
294 | |
94
f2201aa374db
BUGFIX: compass calibration does now timeout automatically after 60s
heinrichsweikamp
parents:
91
diff
changeset
|
295 ; btfsc switch_left ; Button pressed? |
f2201aa374db
BUGFIX: compass calibration does now timeout automatically after 60s
heinrichsweikamp
parents:
91
diff
changeset
|
296 ; bra compass_calibration_exit ; Yes, exit |
0 | 297 |
298 btfss onesecupdate ; do every second tasks? | |
299 bra compass_calibration_loop2 ; no, loop here | |
300 | |
94
f2201aa374db
BUGFIX: compass calibration does now timeout automatically after 60s
heinrichsweikamp
parents:
91
diff
changeset
|
301 movlw .60 |
0 | 302 call timeout_testmode ; check timeout |
94
f2201aa374db
BUGFIX: compass calibration does now timeout automatically after 60s
heinrichsweikamp
parents:
91
diff
changeset
|
303 movlw .60 |
f2201aa374db
BUGFIX: compass calibration does now timeout automatically after 60s
heinrichsweikamp
parents:
91
diff
changeset
|
304 call TFT_show_timeout_testmode ; Show the timeout |
f2201aa374db
BUGFIX: compass calibration does now timeout automatically after 60s
heinrichsweikamp
parents:
91
diff
changeset
|
305 |
0 | 306 bcf onesecupdate ; clear flag |
307 | |
308 bra compass_calibration_loop2 ; loop here | |
309 | |
310 compass_calibration_exit: | |
311 call compass_solve_calibration | |
312 banksel common | |
313 extern option_save_all | |
314 call option_save_all ; save all settings into EEPROM | |
315 bcf sleepmode ; Clear the flag before exiting to surfacemode | |
316 movlw .6 | |
90
3274e87fd027
NEW: automatic compass gain makes calibration quicker
heinrichsweikamp
parents:
67
diff
changeset
|
317 movwf customview_surfmode ; Set to compass view... |
0 | 318 goto surfloop ; ...and exit |
319 | |
320 END |