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