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