Mercurial > public > hwos_code
annotate src/ms5541.asm @ 642:a9a0188091e4
fix rare upgrade issue with OSTC sport 2019 hardware
author | heinrichsweikamp |
---|---|
date | Thu, 14 Jan 2021 16:24:07 +0100 |
parents | 4050675965ea |
children | 7d8a4c60ec1a 5b7fe7777425 |
rev | line source |
---|---|
0 | 1 ;============================================================================= |
2 ; | |
634 | 3 ; File ms5541.asm * combined next generation V3.9.4f |
0 | 4 ; |
634 | 5 ; Sensor Subroutines |
0 | 6 ; |
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. | |
8 ;============================================================================= | |
9 ; HISTORY | |
10 ; 2011-08-03 : [mH] moving from OSTC code | |
11 | |
623 | 12 #include "hwos.inc" ; Mandatory header |
13 #include "math.inc" ; Math routines | |
0 | 14 |
623 | 15 |
16 ms5541 CODE | |
0 | 17 |
634 | 18 |
623 | 19 ; Expose internal variables to ease debug |
604 | 20 global D1, D2 |
21 global C1, C2, C3, C4, C5, C6 | |
623 | 22 global xdT, xdT2, OFF, SENS, pressure_abs_avg, temperature_avg |
0 | 23 |
623 | 24 |
634 | 25 ;----------------------------------------------------------------------------- |
26 ; Convert Temperature & Pressure raw Values to compensated Values | |
27 ; | |
28 ; called from ISR and from sleep mode, returns in bank isr_data | |
29 ; | |
30 global calculate_compensation | |
0 | 31 calculate_compensation: |
623 | 32 banksel isr_backup ; select bank ISR data |
33 | |
34 ;---- pressure sensor compensation | |
35 | |
36 ; xdT = D2 - C5 (s16 range -11.400 .. +12.350) | |
37 movf C5+0,W ; get value to be subtracted | |
38 subwf D2+0,W ; do the low byte | |
604 | 39 movwf xdT+0 |
623 | 40 movf C5+1,W ; do the high byte |
604 | 41 subwfb D2+1,W |
42 movwf xdT+1 | |
0 | 43 |
623 | 44 ; second order temperature calculation |
45 | |
46 ; xdT/128 is in range -89..+96, hence signed 8 bit. dT/128 = (2*dT)/256 | |
47 rlcf xdT+0,W ; put hit bit in carry | |
48 rlcf xdT+1,W ; inject in high byte | |
49 movwf isr_xA+0 ; and put result in low byte | |
604 | 50 clrf isr_xA+1 |
623 | 51 btfsc xdT+1,7 ; dT < 0 ? |
52 setf isr_xA+1 ; YES - sign extend to -1 | |
53 MOVII isr_xA,isr_xB ; copy A to B | |
604 | 54 call isr_signed_mult16x16 ; dT*dT --> xC (32 bits) |
0 | 55 |
623 | 56 ; dT >= 0: divide by 8, i.e. 3 shifts rights |
57 ; dT < 0: divide by 2, i.e. 1 shifts rights | |
634 | 58 movlw .3 ; 3 shifts by default |
59 btfss xdT+1,7 ; was dT negative ? | |
60 movlw .1 ; YES - replace by 1 shift | |
0 | 61 calc_loop_1: |
634 | 62 bcf STATUS,C ; dT^2 is positive, so injecte zeros |
63 rrcf isr_xC+1,F ; shift right high byte | |
64 rrcf isr_xC+0,F ; shift right low byte | |
65 decfsz WREG ; decrement loop counter, all shifts done? | |
66 bra calc_loop_1 ; NO - loop | |
0 | 67 |
604 | 68 movf isr_xC+0,W ; dT2 = dT - (dT/128)*(dT/128)/(2 ...or... 8) |
634 | 69 subwf xdT+0,W ; ... |
70 movwf xdT2+0 ; ... | |
71 movf isr_xC+1,W ; ... | |
72 subwfb xdT+1,W ; ... | |
73 movwf xdT2+1 ; ... | |
604 | 74 |
623 | 75 ; calculate OFF = C2 + ((C4-250)*dT2)/2^12 + 10000 (range +9.246 .. +18.887) |
76 MOVII C4, isr_xA ; C4 - 250 --> A | |
77 MOVII xdT2,isr_xB ; dT2 --> B | |
634 | 78 call isr_signed_mult16x16 ; C = A*B |
0 | 79 |
623 | 80 movlw .12-.8 ; a 12 bit shift = 1 byte + 4 bits |
634 | 81 call isr_shift_C31 ; special shift |
368
57e349960ef4
Additional temperature calibration via PC interface
heinrichsweikamp
parents:
353
diff
changeset
|
82 |
623 | 83 movlw LOW(.10000) ; add 10000 |
634 | 84 addwf isr_xC+1,F ; ... |
85 movlw HIGH(.10000) ; ... | |
86 addwfc isr_xC+2,F ; ... | |
0 | 87 |
623 | 88 movf C2+0,W ; add C2 and store result in OFF |
634 | 89 addwf isr_xC+1,W ; ... |
90 movwf OFF+0 ; ... | |
91 movf C2+1,W ; ... | |
92 addwfc isr_xC+2,W ; ... | |
93 movwf OFF+1 ; ... | |
604 | 94 |
623 | 95 ; calculate SENS = C1/2 + ((C3+200)*dT)/2^13 + 3000 |
604 | 96 movlw LOW(.200) ; C3+200 --> A |
634 | 97 addwf C3+0,W ; ... |
98 movwf isr_xA+0 ; ... | |
99 movlw HIGH(.200) ; ... | |
100 addwfc C3+1,W ; ... | |
101 movwf isr_xA+1 ; ... | |
604 | 102 ; B still contains dT2 |
634 | 103 call isr_signed_mult16x16 ; C = A*B |
623 | 104 movlw .13-.8 ; A 13 bit shift = 1 byte + 5 bits |
634 | 105 call isr_shift_C31 ; special shift |
0 | 106 |
604 | 107 bcf STATUS,C ; SENS = C1 / 2 |
634 | 108 rrcf C1+1,W ; ... |
109 movwf SENS+1 ; ... | |
110 rrcf C1+0,W ; ... | |
111 movwf SENS+0 ; ... | |
604 | 112 |
623 | 113 movlw LOW(.3000) ; add 3000 |
634 | 114 addwf isr_xC+1,F ; ... |
115 movlw HIGH(.3000) ; ... | |
116 addwfc isr_xC+2,F ; ... | |
0 | 117 |
623 | 118 movf isr_xC+1,W ; and sum into SENS |
634 | 119 addwf SENS+0,F ; ... |
120 movf isr_xC+2,W ; ... | |
121 addwfc SENS+1,F ; ... | |
0 | 122 |
631 | 123 ; calculate absolute pressure = (sens * (d1-off))/2^12 + 1000 (for MS5541C) |
124 ; calculate absolute pressure = (sens * (d1-off))/2^11 + 1000 (for MS5541C-30) | |
604 | 125 movf OFF+0,W ; d1-off --> a |
634 | 126 subwf D1+0,W ; ... |
127 movwf isr_xA+0 ; ... | |
128 movf OFF+1,W ; ... | |
129 subwfb D1+1,W ; ... | |
130 movwf isr_xA+1 ; ... | |
0 | 131 |
634 | 132 MOVII SENS,isr_xB ; sens --> B |
133 call isr_signed_mult16x16 ; C = A*B | |
134 movlw .13 ; 12 * 256 = 3328 | |
631 | 135 cpfslt C1+1 ; C1 > 3328 ? |
136 bra isr_shift_ms5541_30 ; YES - MS5541-30 | |
137 movlw .12-.8 ; NO - MS5541: 12 bit shift = 1 byte + 4 bits | |
634 | 138 bra isr_shift_ms5541_common ; - continue |
631 | 139 isr_shift_ms5541_30: |
140 movlw .11-.8 ; MS5541-30: 11 bit shift = 1 byte + 3 bits | |
141 isr_shift_ms5541_common: | |
634 | 142 call isr_shift_C31 ; special shift |
623 | 143 movlw LOW .1000 ; add 1000 |
634 | 144 addwf isr_xC+1,F ; ... |
145 movlw HIGH .1000 ; ... | |
146 addwfc isr_xC+2,F ; ... | |
0 | 147 |
623 | 148 ; add opt_pressure_adjust to result (SIGNED!) |
634 | 149 clrf isr_xC+0 ; prepare high byte for adjustment |
150 movff opt_pressure_adjust,WREG ; get low byte for adjustment (signed) | |
151 movf WREG,W ; excite flags | |
152 bz calc_compensation_1 ; opt_pressure_adjust = 0 -> skip adjustment | |
153 btfss STATUS,N ; opt_pressure_adjust < 0 ? | |
154 bra calc_compensation_adjust ; NO - positive | |
155 negf WREG ; YES - negate opt_pressure_adjust for limit check | |
156 setf isr_xC+0 ; - adopt high byte for adjustment | |
157 calc_compensation_adjust: | |
158 addlw -.21 ; limit is 20 mbar, subtract 21 | |
159 bnn calc_compensation_1 ; result not negative -> skip adjustment | |
160 movff opt_pressure_adjust,WREG ; get opt_pressure_adjust, low byte | |
623 | 161 addwf isr_xC+1,F ; pressure value += opt_pressure_adjust, low byte |
634 | 162 movf isr_xC+0,W ; get adjustment, high byte |
163 addwfc isr_xC+2,F ; pressure value += opt_pressure_adjust, high byte | |
623 | 164 |
165 calc_compensation_1: | |
166 bcf sensor_override_active ; clear sensor override active flag by default | |
167 btfss sensor_override_request ; sensor override requested? | |
168 bra calc_compensation_add_avg ; NO - keep taking absolute pressure from sensor | |
169 btfsc quit_simulatormode ; YES - shall quit simulator mode (the fast way)? | |
170 bra calc_compensation_sim_quit ; YES - force pressure_rel_sim to zero | |
171 ;bra calc_compensation_sim ; NO - calculate pressure_rel_sim from simulated depth | |
172 | |
173 calc_compensation_sim: ; check if OSTC got submerged | |
174 movlw .5 ; coding in high byte for 1280 | |
175 cpfsgt isr_xC+2 ; absolute pressure > 1280 mbar, i.e. OSTC submerged? | |
176 bra calc_compensation_sim_slave ; NO - slave pressure_rel_sim to target depth | |
177 ;bra calc_compensation_sim_quit ; YES - force pressure_rel_sim to zero | |
92
7ca1105751c7
add sensor calibration option (PC only), some cleanup
heinrichsweikamp
parents:
29
diff
changeset
|
178 |
623 | 179 calc_compensation_sim_quit: |
180 CLRI pressure_rel_sim ; set pressure_rel_sim to zero, this paves a restart into surface/dive mode | |
181 bra calc_compensation_sim_com ; continue with common part | |
182 | |
183 calc_compensation_sim_slave: | |
184 movf simulatormode_depth,W ; copy simulated depth to WREG | |
185 mullw .100 ; multiply with 100 to turn depth from meters to relative target pressure in mbar | |
186 ; check if shall go up | |
187 movf pressure_rel_sim+0,W ; get relative pressure, low byte | |
188 subwf PRODL,W ; WREG = relative target pressure - pressure_rel_sim (low byte) | |
189 movf pressure_rel_sim+1,W ; get relative pressure, high byte | |
190 subwfb PRODH,W ; WREG = relative target pressure - pressure_rel_sim (high byte) | |
191 btfsc STATUS,N ; result < 0, i.e. pressure_rel_sim > relative target pressure ? | |
192 bra calc_compensation_sim_up ; YES - decrease pressure_rel_sim | |
193 ; check if shall go down | |
194 movf PRODL,W ; get relative target pressure, low byte | |
195 subwf pressure_rel_sim+0,W ; WREG = pressure_rel_sim - relative target pressure (low byte) | |
196 movf PRODH,W ; get relative target pressure, high byte | |
197 subwfb pressure_rel_sim+1,W ; WREG = pressure_rel_sim - relative target pressure (high byte) | |
198 btfsc STATUS,N ; result < 0, i.e. relative target pressure > pressure_rel_sim ? | |
199 bra calc_compensation_sim_down ; YES - increase pressure_rel_sim | |
200 ; both pressures are equal | |
201 bra calc_compensation_sim_com ; NO to both - keep pressure_rel_sim as it is | |
0 | 202 |
623 | 203 calc_compensation_sim_up: |
204 movf PRODL,W ; get relative target pressure, low byte | |
205 subwf pressure_rel_sim+0,W ; WREG = pressure_rel_sim - relative target pressure (low byte) | |
206 movwf PRODL ; PRODL = pressure_rel_sim - relative target pressure (low byte) | |
207 movf PRODH,W ; get relative target pressure, high byte | |
208 subwfb pressure_rel_sim+1,W ; WREG = pressure_rel_sim - relative target pressure (high byte) | |
209 tstfsz WREG ; more than 255 mbar off from target? | |
210 bra calc_compensation_sim_up_norm ; YES - go up with normal speed | |
211 movlw simulator_ascent_threshold ; NO - get remaining difference for slowing down ascent | |
212 cpfslt PRODL ; - remaining difference to target < decrement? | |
213 bra calc_compensation_sim_up_norm ; NO - go up with normal speed | |
214 ;bra calc_compensation_sim_up_slow ; YES - go up with slow speed | |
215 | |
216 calc_compensation_sim_up_slow: | |
217 DECI pressure_rel_sim ; subtract slow decrement (1 mbar) from pressure_rel_sim | |
218 bra calc_compensation_sim_com ; continue with common part | |
219 | |
220 calc_compensation_sim_up_norm: | |
221 SUBLI simulator_ascent_rate,pressure_rel_sim ; subtract normal decrement from pressure_rel_sim | |
222 bra calc_compensation_sim_com ; continue with common part | |
353
573f2251cf49
NEW: Quit Simulator automatically when starting a real dive
heinrichsweikamp
parents:
275
diff
changeset
|
223 |
623 | 224 calc_compensation_sim_down: |
225 movf pressure_rel_sim+0,W ; get relative pressure, low byte | |
226 subwf PRODL,F ; PRODL = relative target pressure - pressure_rel_sim (low byte) | |
227 movf pressure_rel_sim+1,W ; get relative pressure, high byte | |
228 subwfb PRODH,W ; WREG = relative target pressure - pressure_rel_sim (high byte) | |
229 tstfsz WREG ; more than 255 mbar off from target? | |
230 bra calc_compensation_sim_down_norm ; YES - go down with normal speed | |
231 movlw simulator_descent_threshold ; NO - get remaining difference for slowing down descent | |
232 cpfslt PRODL ; - remaining difference to target < increment? | |
233 bra calc_compensation_sim_down_norm ; NO - go down with normal speed | |
234 ;bra calc_compensation_sim_down_slow ; YES - go down with slow speed | |
235 | |
236 calc_compensation_sim_down_slow: | |
237 INCI pressure_rel_sim ; add slow increment (1 mbar) to pressure_rel_sim | |
238 bra calc_compensation_sim_com ; continue with common part | |
604 | 239 |
623 | 240 calc_compensation_sim_down_norm: |
241 ADDLI simulator_descent_rate,pressure_rel_sim ; add normal increment to pressure_rel_sim | |
242 ;bra calc_compensation_sim_com ; continue with common part | |
243 | |
244 calc_compensation_sim_com: | |
245 movf pressure_surf+0,W ; copy surface pressure to WREG, low byte | |
246 addwf pressure_rel_sim+0,W ; add surface pressure to relative pressure to gain simulated absolute pressure, low byte | |
247 movwf isr_xC+1 ; override sensor pressure with simulated pressure, low byte | |
248 movf pressure_surf+1,W ; copy surface pressure to WREG, high byte | |
249 addwfc pressure_rel_sim+1,W ; add surface pressure to relative pressure to gain simulated absolute pressure, high byte | |
250 movwf isr_xC+2 ; override sensor pressure with simulated pressure, high byte | |
251 bsf sensor_override_active ; confirm sensor override is active | |
252 | |
253 calc_compensation_add_avg: | |
254 ; add current absolute pressure to averaging buffer | |
255 movf isr_xC+1,W ; copy current absolute pressure to WREG, low byte | |
256 addwf pressure_abs_avg+0,F ; pressure_abs_avg += current pressure, low byte | |
257 movf isr_xC+2,W ; copy current absolute pressure to WREG, high byte | |
258 addwfc pressure_abs_avg+1,F ; pressure_abs_avg += current pressure, high byte | |
259 | |
260 ;---- temperature sensor compensation | |
0 | 261 |
604 | 262 ; calculate temp = 200 + dT*(C6+100)/2^11 |
263 movlw LOW(.100) ; C6 + 100 --> A | |
634 | 264 addwf C6+0,W ; ... |
265 movwf isr_xA+0 ; ... | |
266 movlw HIGH(.100) ; ... | |
267 addwfc C6+1,W ; ... | |
268 movwf isr_xA+1 ; ... | |
0 | 269 |
623 | 270 MOVII xdT2,isr_xB ; dT2 --> B |
604 | 271 call isr_signed_mult16x16 ; A*B |
623 | 272 movlw .11-.8 ; a 12 bit shift = 1 byte + 3 bits |
634 | 273 call isr_shift_C31 ; special shift |
0 | 274 |
623 | 275 movlw LOW(.200) ; add 200 |
634 | 276 addwf isr_xC+1,F ; ... |
277 movlw HIGH(.200) ; ... | |
278 addwfc isr_xC+2,F ; ... | |
0 | 279 |
623 | 280 ; add opt_temperature_adjust to result (SIGNED!) |
634 | 281 clrf isr_xC+0 ; prepare high byte for adjustment |
282 movff opt_temperature_adjust,WREG ; get low byte for adjustment (signed) | |
283 movf WREG,W ; excite flags | |
284 bz calc_temperature_add_avg ; opt_temperature_adjust = 0 -> skip adjustment | |
285 btfss STATUS,N ; opt_temperature_adjust < 0 ? | |
286 bra calc_temperature_adjust ; NO - positive | |
287 negf WREG ; YES - negate opt_temperature_adjust for limit check | |
288 setf isr_xC+0 ; - adopt high byte for adjustment | |
289 calc_temperature_adjust: | |
290 addlw -.21 ; limit is 2.0°C, subtract 21 (scaling is 0.1°C) | |
291 bnn calc_temperature_add_avg ; result not negative -> skip adjustment | |
292 movff opt_temperature_adjust,WREG ; get opt_temperature_adjust, low byte | |
293 addwf isr_xC+1,F ; temperature value += opt_temperature_adjust, low byte | |
294 movf isr_xC+0,W ; get adjustment high byte | |
295 addwfc isr_xC+2,F ; temperature value += opt_temperature_adjust, high byte | |
368
57e349960ef4
Additional temperature calibration via PC interface
heinrichsweikamp
parents:
353
diff
changeset
|
296 |
634 | 297 calc_temperature_add_avg: |
298 movf isr_xC+1,W ; copy current temperature to WREG, low byte | |
299 addwf temperature_avg+0,F ; temperature_avg += current temperature, low byte | |
300 movf isr_xC+2,W ; copy current temperature to WREG, high byte | |
301 addwfc temperature_avg+1,F ; temperature_avg += current temperature, high byte | |
302 return ; done | |
303 | |
623 | 304 |
634 | 305 ;----------------------------------------------------------------------------- |
306 ; Start Pressure Measurement | |
307 ; | |
308 ; called from ISR and sleep mode, needs to be called in bank isr_backup | |
309 ; | |
310 global get_pressure_start | |
311 get_pressure_start: | |
312 rcall reset_MS5541 ; reset the chip | |
313 movlw b'10100000' ; +3*high as start and 1+low as stop | |
314 movwf dbuffer ; .... | |
315 movlw d'12' ; send start command | |
316 rcall send_data_MS5541 ; ... | |
623 | 317 return ; done |
0 | 318 |
623 | 319 |
634 | 320 ;----------------------------------------------------------------------------- |
321 ; Read Pressure Measurement Result | |
322 ; | |
323 ; called from ISR and sleep mode, needs to be called in bank isr_backup | |
324 ; | |
325 global get_pressure_value | |
0 | 326 get_pressure_value: |
623 | 327 btfsc MS5541_miso ; conversion done? |
634 | 328 return ; NO - abort |
329 rcall get_2bytes_MS5541 ; YES - read result | |
330 movff dMSB,D1+1 ; copy result to D1, high byte first | |
331 movff dLSB,D1+0 ; ... low byte second | |
332 return ; done | |
0 | 333 |
623 | 334 |
634 | 335 ;----------------------------------------------------------------------------- |
336 ; Start Temperature Measurement | |
337 ; | |
338 ; called from ISR and sleep mode, needs to be called in bank isr_backup | |
339 ; | |
340 global get_temperature_start | |
341 get_temperature_start: | |
342 rcall reset_MS5541 ; reset chip | |
343 movlw b'10010000' ; +3*high as start and 1+low as stop | |
344 movwf dbuffer ; ... | |
345 movlw d'12' ; send start command | |
346 rcall send_data_MS5541 ; ... | |
347 return ; done | |
348 | |
349 | |
350 ;----------------------------------------------------------------------------- | |
351 ; Read Pressure Measurement Result | |
352 ; | |
353 ; called from ISR and sleep mode, needs to be called in bank isr_backup | |
354 ; | |
355 global get_temperature_value | |
0 | 356 get_temperature_value: |
623 | 357 btfsc MS5541_miso ; conversion done? |
358 return ; NO - done | |
634 | 359 rcall get_2bytes_MS5541 ; YES - read result |
360 movff dMSB,D2+1 ; copy result to D2, high byte first | |
361 movff dLSB,D2+0 ; ... low byte second | |
362 return ; done | |
363 | |
0 | 364 |
634 | 365 ;----------------------------------------------------------------------------- |
366 ; Retrieve Calibration Data | |
367 ; | |
368 ; called by start, returns in bank common | |
369 ; | |
370 global get_calibration_data | |
0 | 371 get_calibration_data: |
623 | 372 banksel isr_backup ; select bank ISR data |
373 bsf block_sensor_interrupt ; disable sensor interrupts | |
0 | 374 |
634 | 375 rcall reset_MS5541 ; reset chip |
376 | |
623 | 377 movlw b'01010100' ; +3*high as start and 1+low as stop |
634 | 378 movwf dbuffer ; ... |
379 movlw d'13' ; send command | |
380 rcall send_data_MS5541 ; ... | |
381 rcall get_2bytes_MS5541 ; read result | |
382 movff dMSB,ir_s8_buffer+1 ; copy result, high byte first | |
383 movff dLSB,ir_s8_buffer+0 ; copy result, low byte second | |
0 | 384 |
623 | 385 movlw b'01011000' ; +3*high as start and 1+low as stop |
634 | 386 movwf dbuffer ; ... |
387 movlw d'13' ; send command | |
388 rcall send_data_MS5541 ; ... | |
389 rcall get_2bytes_MS5541 ; read result | |
390 movff dMSB,ir_s8_buffer+3 ; copy result, high byte first | |
391 movff dLSB,ir_s8_buffer+2 ; copy result, low byte second | |
0 | 392 |
623 | 393 movlw b'01100100' ; +3*high as start and 1+low as stop |
634 | 394 movwf dbuffer ; ... |
395 movlw d'13' ; send command | |
396 rcall send_data_MS5541 ; ... | |
397 rcall get_2bytes_MS5541 ; read result | |
398 movff dMSB,ir_s8_buffer+5 ; copy result, high byte first | |
399 movff dLSB,ir_s8_buffer+4 ; copy result, low byte second | |
0 | 400 |
623 | 401 movlw b'01101000' ; +3*high as start and 1+low as stop |
634 | 402 movwf dbuffer ; ... |
403 movlw d'13' ; send command | |
404 rcall send_data_MS5541 ; ... | |
405 rcall get_2bytes_MS5541 ; read result | |
406 movff dMSB,ir_s8_buffer+7 ; copy result, high byte first | |
407 movff dLSB,ir_s8_buffer+6 ; copy result, low byte second | |
0 | 408 |
634 | 409 ; calculate C1 (16 Bit) |
410 movff ir_s8_buffer+1,C1+1 | |
0 | 411 bcf STATUS,C |
412 rrcf C1+1 | |
413 bcf STATUS,C | |
414 rrcf C1+1 | |
415 bcf STATUS,C | |
416 rrcf C1+1 | |
634 | 417 movff ir_s8_buffer+0,C1+0 |
0 | 418 bsf STATUS,C |
255 | 419 btfss ir_s8_buffer+1,0 |
0 | 420 bcf STATUS,C |
421 rrcf C1+0 | |
422 bsf STATUS,C | |
255 | 423 btfss ir_s8_buffer+1,1 |
0 | 424 bcf STATUS,C |
425 rrcf C1+0 | |
426 bsf STATUS,C | |
255 | 427 btfss ir_s8_buffer+1,2 |
0 | 428 bcf STATUS,C |
429 rrcf C1+0 | |
430 | |
634 | 431 ; calculate C2 (16 Bit) |
255 | 432 movff ir_s8_buffer+2, C2+0 |
0 | 433 bsf STATUS,C |
255 | 434 btfss ir_s8_buffer+3,0 |
0 | 435 bcf STATUS,C |
436 rrcf C2+0 | |
437 bsf STATUS,C | |
255 | 438 btfss ir_s8_buffer+3,1 |
0 | 439 bcf STATUS,C |
440 rrcf C2+0 | |
441 bsf STATUS,C | |
255 | 442 btfss ir_s8_buffer+3,2 |
0 | 443 bcf STATUS,C |
444 rrcf C2+0 | |
445 bsf STATUS,C | |
255 | 446 btfss ir_s8_buffer+3,3 |
0 | 447 bcf STATUS,C |
448 rrcf C2+0 | |
449 bsf STATUS,C | |
255 | 450 btfss ir_s8_buffer+3,4 |
0 | 451 bcf STATUS,C |
452 rrcf C2+0 | |
453 bsf STATUS,C | |
255 | 454 btfss ir_s8_buffer+3,5 |
0 | 455 bcf STATUS,C |
456 rrcf C2+0 | |
457 | |
255 | 458 movff ir_s8_buffer+3, C2+1 |
0 | 459 bsf STATUS,C |
255 | 460 btfss ir_s8_buffer+0,0 |
0 | 461 bcf STATUS,C |
462 rrcf C2+1 | |
463 bsf STATUS,C | |
255 | 464 btfss ir_s8_buffer+0,1 |
0 | 465 bcf STATUS,C |
466 rrcf C2+1 | |
467 bsf STATUS,C | |
255 | 468 btfss ir_s8_buffer+0,2 |
0 | 469 bcf STATUS,C |
470 rrcf C2+1 | |
471 bcf STATUS,C | |
472 rrcf C2+1 | |
473 bcf STATUS,C | |
474 rrcf C2+1 | |
475 bcf STATUS,C | |
476 rrcf C2+1 | |
477 | |
634 | 478 ; calculate C3 (16 Bit) |
255 | 479 movff ir_s8_buffer+5,C3+0 |
0 | 480 bsf STATUS,C |
255 | 481 btfss ir_s8_buffer+4,7 |
0 | 482 bcf STATUS,C |
483 rlcf C3+0 | |
484 bsf STATUS,C | |
255 | 485 btfss ir_s8_buffer+4,6 |
0 | 486 bcf STATUS,C |
487 rlcf C3+0 | |
488 clrf C3+1 | |
255 | 489 btfsc ir_s8_buffer+5,7 |
0 | 490 bsf C3+1,1 |
255 | 491 btfsc ir_s8_buffer+5,6 |
0 | 492 bsf C3+1,0 |
604 | 493 |
634 | 494 ; calculate C4 (16 Bit) |
255 | 495 movff ir_s8_buffer+7,C4+0 |
0 | 496 bsf STATUS,C |
255 | 497 btfss ir_s8_buffer+6,7 |
0 | 498 bcf STATUS,C |
499 rlcf C4+0 | |
500 clrf C4+1 | |
255 | 501 btfsc ir_s8_buffer+7,7 |
0 | 502 bsf C4+1,0 |
503 | |
623 | 504 ; C4=C4-250 |
604 | 505 movlw LOW(-.250) ; C4 - 250 --> C4 |
0 | 506 addwf C4+0,W |
604 | 507 movwf C4+0 |
508 movlw -1 ; HIGH(- .250) is not understood... | |
509 addwfc C4+1,W | |
510 movwf C4+1 | |
511 | |
634 | 512 ; calculate C5 (16 Bit) |
255 | 513 movff ir_s8_buffer+4,C5+0 |
0 | 514 bcf C5+0,6 |
255 | 515 btfsc ir_s8_buffer+2,0 |
0 | 516 bsf C5+0,6 |
517 bcf C5+0,7 | |
255 | 518 btfsc ir_s8_buffer+2,1 |
0 | 519 bsf C5+0,7 |
520 clrf C5+1 | |
255 | 521 btfsc ir_s8_buffer+2,2 |
0 | 522 bsf C5+1,0 |
255 | 523 btfsc ir_s8_buffer+2,3 |
0 | 524 bsf C5+1,1 |
255 | 525 btfsc ir_s8_buffer+2,4 |
0 | 526 bsf C5+1,2 |
255 | 527 btfsc ir_s8_buffer+2,5 |
0 | 528 bsf C5+1,3 |
529 | |
604 | 530 ; calculate C5 = UT1 |
531 ; C5 = 8*C5 + 10000 (u16 range 10.000 .. +42.760) | |
0 | 532 clrf isr_xA+1 |
533 movlw d'8' | |
534 movwf isr_xA+0 | |
623 | 535 MOVII C5,isr_xB |
536 call isr_unsigned_mult16x16 ; isr_xA*isr_xB=isr_xC | |
537 MOVII isr_xC,C5 | |
604 | 538 movlw LOW d'10000' |
539 addwf C5+0,F | |
540 movlw HIGH d'10000' | |
623 | 541 addwfc C5+1,F ; = 8*C5 + 10000 |
0 | 542 |
623 | 543 ; calculate C6 (16Bit) |
0 | 544 clrf C6+1 |
255 | 545 movff ir_s8_buffer+6,C6+0 |
0 | 546 bcf C6+0,7 |
547 | |
623 | 548 clrf sensor_state_counter ; reset state counter |
549 bcf block_sensor_interrupt ; re-enable sensor interrupts | |
550 banksel common ; back to bank common | |
551 return ; done | |
0 | 552 |
634 | 553 |
554 ;----------------------------------------------------------------------------- | |
555 ; Helper Function - Reset Chip | |
556 ; | |
0 | 557 reset_MS5541_one: |
634 | 558 bsf MS5541_mosi ; set MOSI |
623 | 559 bra send_clk_pulse ; send one high-low sequence on MS5541_clk and return |
0 | 560 |
561 reset_MS5541_zero: | |
634 | 562 bcf MS5541_mosi ; clear MOSI |
623 | 563 bra send_clk_pulse ; send one high-low sequence on MS5541_clk and return |
0 | 564 |
565 reset_MS5541: | |
604 | 566 rcall reset_MS5541_one ; 0 |
0 | 567 rcall reset_MS5541_zero |
568 rcall reset_MS5541_one | |
569 rcall reset_MS5541_zero | |
570 rcall reset_MS5541_one | |
571 rcall reset_MS5541_zero | |
572 rcall reset_MS5541_one | |
573 rcall reset_MS5541_zero | |
574 rcall reset_MS5541_one | |
575 rcall reset_MS5541_zero | |
576 rcall reset_MS5541_one | |
577 rcall reset_MS5541_zero | |
578 rcall reset_MS5541_one | |
579 rcall reset_MS5541_zero | |
580 rcall reset_MS5541_one | |
604 | 581 rcall reset_MS5541_zero ; 15 |
582 rcall reset_MS5541_zero | |
583 rcall reset_MS5541_zero | |
584 rcall reset_MS5541_zero | |
585 rcall reset_MS5541_zero | |
586 rcall reset_MS5541_zero ; 20 | |
0 | 587 return |
588 | |
623 | 589 |
634 | 590 ;----------------------------------------------------------------------------- |
591 ; Helper Function - read 2 Byte from Chip | |
592 ; | |
0 | 593 get_2bytes_MS5541: |
634 | 594 movlw d'8' ; load counter for 8 bit |
595 movwf clock_count ; ... | |
596 rcall recieve_loop ; receive 8 bits | |
597 movff dbuffer,dMSB ; store result | |
598 movlw d'8' ; load counter for 8 bit | |
599 movwf clock_count ; ... | |
600 rcall recieve_loop ; receive 8 bits | |
601 movff dbuffer,dLSB ; store result | |
623 | 602 bra send_clk_pulse ; send one high-low sequence on MS5541_clk and return |
0 | 603 |
634 | 604 |
605 ;----------------------------------------------------------------------------- | |
606 ; Helper Function - read 1 Bit from Chip | |
607 ; | |
0 | 608 recieve_loop: |
623 | 609 rcall send_clk_pulse ; send one high-low sequence on MS5541_clk |
634 | 610 btfss MS5541_miso ; read bit = 1 ? (MSB first) |
611 bcf STATUS,C ; NO - clear carry bit | |
612 btfsc MS5541_miso ; read bit = 0 ? (MSB first) | |
613 bsf STATUS,C ; NO - set carry bit | |
614 rlcf dbuffer,F ; shift buffer | |
615 decfsz clock_count,F ; decrement counter, became zero? | |
616 bra recieve_loop ; NO - loop | |
617 return ; YES - done | |
0 | 618 |
634 | 619 |
620 ;----------------------------------------------------------------------------- | |
621 ; Helper Function - send a Clock Pulse | |
622 ; | |
0 | 623 send_clk_pulse: |
634 | 624 bsf MS5541_clk ; set clock |
0 | 625 nop |
626 nop | |
627 nop | |
628 nop | |
29
50c3e2c7ba7a
adding cardinal (and ordinal) directions for the compass
heinrichsweikamp
parents:
0
diff
changeset
|
629 nop |
50c3e2c7ba7a
adding cardinal (and ordinal) directions for the compass
heinrichsweikamp
parents:
0
diff
changeset
|
630 nop |
634 | 631 bcf MS5541_clk ; release clock |
0 | 632 nop |
633 nop | |
29
50c3e2c7ba7a
adding cardinal (and ordinal) directions for the compass
heinrichsweikamp
parents:
0
diff
changeset
|
634 nop |
50c3e2c7ba7a
adding cardinal (and ordinal) directions for the compass
heinrichsweikamp
parents:
0
diff
changeset
|
635 nop |
634 | 636 return ; done |
0 | 637 |
623 | 638 |
634 | 639 ;----------------------------------------------------------------------------- |
640 ; Helper Function - send a Command | |
641 ; | |
0 | 642 send_data_MS5541: |
623 | 643 movwf clock_count ; from WREG |
644 ; send three start bits first | |
634 | 645 bcf MS5541_clk ; revoke clock |
646 nop ; wait | |
647 nop ; wait | |
648 bsf MS5541_mosi ; set MOSI | |
649 movlw d'3' ; compute total bit counter | |
650 subwf clock_count,F ; ... | |
623 | 651 rcall send_clk_pulse ; send one high-low sequence on MS5541_clk |
652 rcall send_clk_pulse ; send one high-low sequence on MS5541_clk | |
653 rcall send_clk_pulse ; send one high-low sequence on MS5541_clk | |
634 | 654 |
655 send_data_MS5541_loop: | |
656 ; now send 8 bits from dbuffer and fill-up with zeros | |
657 bcf MS5541_clk ; revoke clock | |
658 nop ; wait | |
659 nop ; wait | |
660 btfss dbuffer,7 ; bit = 1 ? (MSB first) | |
661 bcf MS5541_mosi ; NO - clear MOSI | |
662 btfsc dbuffer,7 ; bit = 0 ? (MSB first) | |
663 bsf MS5541_mosi ; NO - set MOSI | |
664 bsf MS5541_clk ; set clock | |
665 bcf STATUS,C ; clear carry bit | |
666 rlcf dbuffer,F ; shift data byte | |
667 nop ; wait | |
668 nop ; wait | |
0 | 669 ; nop |
670 ; nop | |
671 ; nop | |
672 ; nop | |
673 ; bcf MS5541_clk | |
634 | 674 decfsz clock_count,F ; decrement bit counter, became zero? |
675 bra send_data_MS5541_loop ; NO - loop | |
676 bcf MS5541_clk ; YES - revoke clock | |
677 return ; - done | |
0 | 678 |
634 | 679 ;----------------------------------------------------------------------------- |
680 | |
681 END |