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