Mercurial > public > hwos_code
annotate src/ms5541.asm @ 656:8af5aefbcdaf default tip
Update to 3.31 beta
| author | heinrichsweikamp |
|---|---|
| date | Thu, 27 Nov 2025 18:32:58 +0100 |
| parents | 75e90cd0c2c3 |
| children |
| 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 ; |
| 654 | 7 ; Copyright (c) 2011, JD Gascuel, heinrichs weikamp gmbh, all right reserved. |
| 0 | 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 | |
| 643 | 14 #include "i2c.inc" |
| 15 #include "shared_definitions.h" ; mailbox from/to p2_deco.c | |
| 623 | 16 |
| 17 ms5541 CODE | |
| 0 | 18 |
| 634 | 19 |
| 623 | 20 ; Expose internal variables to ease debug |
| 604 | 21 global D1, D2 |
| 22 global C1, C2, C3, C4, C5, C6 | |
| 623 | 23 global xdT, xdT2, OFF, SENS, pressure_abs_avg, temperature_avg |
| 0 | 24 |
| 623 | 25 |
| 634 | 26 ;----------------------------------------------------------------------------- |
| 27 ; Convert Temperature & Pressure raw Values to compensated Values | |
| 28 ; | |
| 29 ; called from ISR and from sleep mode, returns in bank isr_data | |
| 30 ; | |
| 31 global calculate_compensation | |
| 0 | 32 calculate_compensation: |
| 623 | 33 banksel isr_backup ; select bank ISR data |
| 34 | |
| 643 | 35 btfsc press_sensor_type ; New sensor found? |
| 36 bra press_comp_ms5837 ; Yes, use MS5837 | |
| 37 | |
| 623 | 38 ;---- pressure sensor compensation |
| 39 | |
| 40 ; xdT = D2 - C5 (s16 range -11.400 .. +12.350) | |
| 41 movf C5+0,W ; get value to be subtracted | |
| 42 subwf D2+0,W ; do the low byte | |
| 604 | 43 movwf xdT+0 |
| 623 | 44 movf C5+1,W ; do the high byte |
| 604 | 45 subwfb D2+1,W |
| 46 movwf xdT+1 | |
| 0 | 47 |
| 623 | 48 ; second order temperature calculation |
| 49 | |
| 50 ; xdT/128 is in range -89..+96, hence signed 8 bit. dT/128 = (2*dT)/256 | |
| 51 rlcf xdT+0,W ; put hit bit in carry | |
| 52 rlcf xdT+1,W ; inject in high byte | |
| 53 movwf isr_xA+0 ; and put result in low byte | |
| 604 | 54 clrf isr_xA+1 |
| 623 | 55 btfsc xdT+1,7 ; dT < 0 ? |
| 56 setf isr_xA+1 ; YES - sign extend to -1 | |
| 57 MOVII isr_xA,isr_xB ; copy A to B | |
| 604 | 58 call isr_signed_mult16x16 ; dT*dT --> xC (32 bits) |
| 0 | 59 |
| 623 | 60 ; dT >= 0: divide by 8, i.e. 3 shifts rights |
| 61 ; dT < 0: divide by 2, i.e. 1 shifts rights | |
| 634 | 62 movlw .3 ; 3 shifts by default |
| 63 btfss xdT+1,7 ; was dT negative ? | |
| 64 movlw .1 ; YES - replace by 1 shift | |
| 0 | 65 calc_loop_1: |
| 634 | 66 bcf STATUS,C ; dT^2 is positive, so injecte zeros |
| 67 rrcf isr_xC+1,F ; shift right high byte | |
| 68 rrcf isr_xC+0,F ; shift right low byte | |
| 69 decfsz WREG ; decrement loop counter, all shifts done? | |
| 70 bra calc_loop_1 ; NO - loop | |
| 0 | 71 |
| 604 | 72 movf isr_xC+0,W ; dT2 = dT - (dT/128)*(dT/128)/(2 ...or... 8) |
| 634 | 73 subwf xdT+0,W ; ... |
| 74 movwf xdT2+0 ; ... | |
| 75 movf isr_xC+1,W ; ... | |
| 76 subwfb xdT+1,W ; ... | |
| 77 movwf xdT2+1 ; ... | |
| 604 | 78 |
| 623 | 79 ; calculate OFF = C2 + ((C4-250)*dT2)/2^12 + 10000 (range +9.246 .. +18.887) |
| 80 MOVII C4, isr_xA ; C4 - 250 --> A | |
| 81 MOVII xdT2,isr_xB ; dT2 --> B | |
| 634 | 82 call isr_signed_mult16x16 ; C = A*B |
| 0 | 83 |
| 623 | 84 movlw .12-.8 ; a 12 bit shift = 1 byte + 4 bits |
| 634 | 85 call isr_shift_C31 ; special shift |
|
368
57e349960ef4
Additional temperature calibration via PC interface
heinrichsweikamp
parents:
353
diff
changeset
|
86 |
| 623 | 87 movlw LOW(.10000) ; add 10000 |
| 634 | 88 addwf isr_xC+1,F ; ... |
| 89 movlw HIGH(.10000) ; ... | |
| 90 addwfc isr_xC+2,F ; ... | |
| 0 | 91 |
| 623 | 92 movf C2+0,W ; add C2 and store result in OFF |
| 634 | 93 addwf isr_xC+1,W ; ... |
| 94 movwf OFF+0 ; ... | |
| 95 movf C2+1,W ; ... | |
| 96 addwfc isr_xC+2,W ; ... | |
| 97 movwf OFF+1 ; ... | |
| 604 | 98 |
| 623 | 99 ; calculate SENS = C1/2 + ((C3+200)*dT)/2^13 + 3000 |
| 604 | 100 movlw LOW(.200) ; C3+200 --> A |
| 634 | 101 addwf C3+0,W ; ... |
| 102 movwf isr_xA+0 ; ... | |
| 103 movlw HIGH(.200) ; ... | |
| 104 addwfc C3+1,W ; ... | |
| 105 movwf isr_xA+1 ; ... | |
| 604 | 106 ; B still contains dT2 |
| 634 | 107 call isr_signed_mult16x16 ; C = A*B |
| 623 | 108 movlw .13-.8 ; A 13 bit shift = 1 byte + 5 bits |
| 634 | 109 call isr_shift_C31 ; special shift |
| 0 | 110 |
| 604 | 111 bcf STATUS,C ; SENS = C1 / 2 |
| 634 | 112 rrcf C1+1,W ; ... |
| 113 movwf SENS+1 ; ... | |
| 114 rrcf C1+0,W ; ... | |
| 115 movwf SENS+0 ; ... | |
| 604 | 116 |
| 623 | 117 movlw LOW(.3000) ; add 3000 |
| 634 | 118 addwf isr_xC+1,F ; ... |
| 119 movlw HIGH(.3000) ; ... | |
| 120 addwfc isr_xC+2,F ; ... | |
| 0 | 121 |
| 623 | 122 movf isr_xC+1,W ; and sum into SENS |
| 634 | 123 addwf SENS+0,F ; ... |
| 124 movf isr_xC+2,W ; ... | |
| 125 addwfc SENS+1,F ; ... | |
| 0 | 126 |
| 631 | 127 ; calculate absolute pressure = (sens * (d1-off))/2^12 + 1000 (for MS5541C) |
| 128 ; calculate absolute pressure = (sens * (d1-off))/2^11 + 1000 (for MS5541C-30) | |
| 604 | 129 movf OFF+0,W ; d1-off --> a |
| 634 | 130 subwf D1+0,W ; ... |
| 131 movwf isr_xA+0 ; ... | |
| 132 movf OFF+1,W ; ... | |
| 133 subwfb D1+1,W ; ... | |
| 134 movwf isr_xA+1 ; ... | |
| 0 | 135 |
| 634 | 136 MOVII SENS,isr_xB ; sens --> B |
| 137 call isr_signed_mult16x16 ; C = A*B | |
| 643 | 138 movlw .15 ; 15 * 256 = 3840 |
| 631 | 139 cpfslt C1+1 ; C1 > 3328 ? |
| 140 bra isr_shift_ms5541_30 ; YES - MS5541-30 | |
| 141 movlw .12-.8 ; NO - MS5541: 12 bit shift = 1 byte + 4 bits | |
| 634 | 142 bra isr_shift_ms5541_common ; - continue |
| 631 | 143 isr_shift_ms5541_30: |
| 144 movlw .11-.8 ; MS5541-30: 11 bit shift = 1 byte + 3 bits | |
| 145 isr_shift_ms5541_common: | |
| 634 | 146 call isr_shift_C31 ; special shift |
| 623 | 147 movlw LOW .1000 ; add 1000 |
| 634 | 148 addwf isr_xC+1,F ; ... |
| 149 movlw HIGH .1000 ; ... | |
| 150 addwfc isr_xC+2,F ; ... | |
| 643 | 151 bra press_comp_done_common |
| 0 | 152 |
| 643 | 153 press_comp_ms5837: |
| 154 ; xdT = D2 - C5*2^8 | |
| 155 movlw .0 ; Low | |
| 156 subwf D2+0,W | |
| 157 movwf xdT+0 | |
| 158 movf C5+0,W ; High | |
| 159 subwfb D2+1,W | |
| 160 movwf xdT+1 | |
| 161 movf C5+1,W ; Upper | |
| 162 subwfb D2+2,W | |
| 163 movwf xdT+2 | |
| 164 ; xdT equals D2 - (C5*2^8) | |
| 165 | |
| 166 ; Calculate OFF = C2*2^16+(C4*xdT)/2^7 | |
| 167 movff C4+0,isr_xA+0 | |
| 168 movff C4+1,isr_xA+1 | |
| 169 clrf isr_xA+2 | |
| 170 movff xdT+0,isr_xB+0 | |
| 171 movff xdT+1,isr_xB+1 | |
| 172 movff xdT+2,isr_xB+2 | |
| 173 call isr_signed_mult24x24 ; C = A*B | |
| 174 ; isr_xC:6 equals (C4*xdT) | |
| 175 rlcf isr_xC+0,F | |
| 176 rlcf isr_xC+1,F | |
| 177 rlcf isr_xC+2,F | |
| 178 rlcf isr_xC+3,F | |
| 179 rlcf isr_xC+4,F | |
| 180 rlcf isr_xC+5,F | |
| 181 movff isr_xC+1,OFF+0 | |
| 182 movff isr_xC+2,OFF+1 | |
| 183 movff isr_xC+3,OFF+2 | |
| 184 movff isr_xC+4,OFF+3 | |
| 185 ; OFF equals (C4*xdT)/2^7 | |
| 186 movf C2+0,W | |
| 187 addwf OFF+2,F | |
| 188 movf C2+1,W | |
| 189 addwfc OFF+3,F | |
| 190 ; OFF equals C2*2^16+((C4*xdT)/2^7) | |
| 191 | |
| 192 ; Calculate SENS = C1*2^15 + (C3*xdT)/2^8 | |
| 193 MOVII C1,isr_xA | |
| 194 movlw LOW (.32768) | |
| 195 movwf isr_xB+0 | |
| 196 movlw HIGH (.32768) | |
| 197 movwf isr_xB+1 | |
| 198 call isr_unsigned_mult16x16 ; C = A*B | |
| 199 movff isr_xC+0,SENS+0 | |
| 200 movff isr_xC+1,SENS+1 | |
| 201 movff isr_xC+2,SENS+2 | |
| 202 movff isr_xC+3,SENS+3 ; 32bit copy | |
| 203 ; SENS equals C1*2^15 | |
| 204 movff C3+0,isr_xA+0 | |
| 205 movff C3+1,isr_xA+1 | |
| 206 clrf isr_xA+2 | |
| 207 movff xdT+0,isr_xB+0 | |
| 208 movff xdT+1,isr_xB+1 | |
| 209 movff xdT+2,isr_xB+2 | |
| 210 call isr_signed_mult24x24 ; C = A*B | |
| 211 ; isr_xC:6 equals (C3*xdT) | |
| 212 movf isr_xC+1,W | |
| 213 addwf SENS+0,F | |
| 214 movf isr_xC+2,W | |
| 215 addwfc SENS+1,F | |
| 216 movf isr_xC+3,W | |
| 217 addwfc SENS+2,F | |
| 218 movf isr_xC+4,W | |
| 219 addwfc SENS+3,F | |
| 220 ; SENS equals C1*2^15 + (C3*xdT)/2^8 | |
| 221 | |
| 222 ; Calculate PRESSURE = ((D1 * SENS) / 2^21) - OFF) / 2^13 | |
| 223 movff SENS+0,isr_xA+0 | |
| 224 movff SENS+1,isr_xA+1 | |
| 225 movff SENS+2,isr_xA+2 | |
| 226 movff SENS+3,isr_xA+3 | |
| 227 movff D1+0,isr_xB+0 | |
| 228 movff D1+1,isr_xB+1 | |
| 229 movff D1+2,isr_xB+2 | |
| 230 call isr_unsigned_mult32x24 ; C = A*B | |
| 231 ; isr_xC:7 equals D1*SENS | |
| 232 | |
| 233 ; devide isr_xC:7 / 2^21 -> shift right 21 times | |
| 234 movlw .21 | |
| 235 press_comp_ms5837_2: | |
| 236 bcf STATUS,C ; clear carry, needed for MS5837 use | |
| 237 rrcf isr_xC+6,F | |
| 238 rrcf isr_xC+5,F | |
| 239 rrcf isr_xC+4,F | |
| 240 rrcf isr_xC+3,F | |
| 241 rrcf isr_xC+2,F | |
| 242 rrcf isr_xC+1,F | |
| 243 rrcf isr_xC+0,F | |
| 244 decfsz WREG ; decrement loop counter, done? | |
| 245 bra press_comp_ms5837_2 ; NO - loop | |
| 246 ; isr_xC:6 equals (D1*SENS)/2^21 | |
| 247 | |
| 248 ; Calculate isr_xC:6-OFF | |
| 249 movf OFF+0,W ; Low | |
| 250 subwf isr_xC+0,F | |
| 251 movf OFF+1,W ; High | |
| 252 subwfb isr_xC+1,F | |
| 253 movf OFF+2,W ; Upper | |
| 254 subwfb isr_xC+2,F | |
| 255 movf OFF+3,W ; Extra | |
| 256 subwfb isr_xC+3,F | |
| 257 movlw .0 ; ultra | |
| 258 subwfb isr_xC+4,F | |
| 259 movlw .0 ; Hyper | |
| 260 subwfb isr_xC+5,F | |
| 261 ; isr_xC:5 is now isr_xC:4-OFF | |
| 262 | |
| 263 ; devide by 2^13 | |
| 264 ; devide isr_xC:6 / 2^13 -> shift right 13 times | |
| 265 movlw .13 | |
| 266 press_comp_ms5837_3: | |
| 267 bcf STATUS,C ; clear carry | |
| 268 rrcf isr_xC+5,F | |
| 269 rrcf isr_xC+4,F | |
| 270 rrcf isr_xC+3,F | |
| 271 rrcf isr_xC+2,F | |
| 272 rrcf isr_xC+1,F | |
| 273 rrcf isr_xC+0,F | |
| 274 decfsz WREG ; decrement loop counter, done? | |
| 275 bra press_comp_ms5837_3 ; NO - loop | |
| 276 ; isr_xC:4 equals pressure in .1 mbar | |
| 277 | |
| 278 movlw .10 | |
| 279 movwf isr_xB+0 | |
| 280 clrf isr_xB+1 | |
| 281 call isr_div32x16 ; isr_xC:4 = isr_xC:4 / isr_xB:2 with isr_xA as remainder | |
| 282 ; isr_xC:2 equals pressure in 1mbar | |
| 283 | |
| 284 ; copy for compatibility of the next routines | |
| 285 movff isr_xC+1,isr_xC+2 | |
| 286 movff isr_xC+0,isr_xC+1 | |
| 287 | |
| 288 press_comp_done_common: ; continue here even with MS5837 | |
| 623 | 289 ; add opt_pressure_adjust to result (SIGNED!) |
| 634 | 290 clrf isr_xC+0 ; prepare high byte for adjustment |
| 291 movff opt_pressure_adjust,WREG ; get low byte for adjustment (signed) | |
| 292 movf WREG,W ; excite flags | |
| 293 bz calc_compensation_1 ; opt_pressure_adjust = 0 -> skip adjustment | |
| 294 btfss STATUS,N ; opt_pressure_adjust < 0 ? | |
| 295 bra calc_compensation_adjust ; NO - positive | |
| 296 negf WREG ; YES - negate opt_pressure_adjust for limit check | |
| 297 setf isr_xC+0 ; - adopt high byte for adjustment | |
| 298 calc_compensation_adjust: | |
| 299 addlw -.21 ; limit is 20 mbar, subtract 21 | |
| 300 bnn calc_compensation_1 ; result not negative -> skip adjustment | |
| 301 movff opt_pressure_adjust,WREG ; get opt_pressure_adjust, low byte | |
| 623 | 302 addwf isr_xC+1,F ; pressure value += opt_pressure_adjust, low byte |
| 634 | 303 movf isr_xC+0,W ; get adjustment, high byte |
| 304 addwfc isr_xC+2,F ; pressure value += opt_pressure_adjust, high byte | |
| 623 | 305 |
| 306 calc_compensation_1: | |
| 307 bcf sensor_override_active ; clear sensor override active flag by default | |
| 308 btfss sensor_override_request ; sensor override requested? | |
| 309 bra calc_compensation_add_avg ; NO - keep taking absolute pressure from sensor | |
| 310 btfsc quit_simulatormode ; YES - shall quit simulator mode (the fast way)? | |
| 311 bra calc_compensation_sim_quit ; YES - force pressure_rel_sim to zero | |
| 312 ;bra calc_compensation_sim ; NO - calculate pressure_rel_sim from simulated depth | |
| 313 | |
| 314 calc_compensation_sim: ; check if OSTC got submerged | |
| 315 movlw .5 ; coding in high byte for 1280 | |
| 316 cpfsgt isr_xC+2 ; absolute pressure > 1280 mbar, i.e. OSTC submerged? | |
| 317 bra calc_compensation_sim_slave ; NO - slave pressure_rel_sim to target depth | |
| 318 ;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
|
319 |
| 623 | 320 calc_compensation_sim_quit: |
| 321 CLRI pressure_rel_sim ; set pressure_rel_sim to zero, this paves a restart into surface/dive mode | |
| 322 bra calc_compensation_sim_com ; continue with common part | |
| 323 | |
| 324 calc_compensation_sim_slave: | |
| 325 movf simulatormode_depth,W ; copy simulated depth to WREG | |
| 326 mullw .100 ; multiply with 100 to turn depth from meters to relative target pressure in mbar | |
| 327 ; check if shall go up | |
| 328 movf pressure_rel_sim+0,W ; get relative pressure, low byte | |
| 329 subwf PRODL,W ; WREG = relative target pressure - pressure_rel_sim (low byte) | |
| 330 movf pressure_rel_sim+1,W ; get relative pressure, high byte | |
| 331 subwfb PRODH,W ; WREG = relative target pressure - pressure_rel_sim (high byte) | |
| 332 btfsc STATUS,N ; result < 0, i.e. pressure_rel_sim > relative target pressure ? | |
| 333 bra calc_compensation_sim_up ; YES - decrease pressure_rel_sim | |
| 334 ; check if shall go down | |
| 335 movf PRODL,W ; get relative target pressure, low byte | |
| 336 subwf pressure_rel_sim+0,W ; WREG = pressure_rel_sim - relative target pressure (low byte) | |
| 337 movf PRODH,W ; get relative target pressure, high byte | |
| 338 subwfb pressure_rel_sim+1,W ; WREG = pressure_rel_sim - relative target pressure (high byte) | |
| 339 btfsc STATUS,N ; result < 0, i.e. relative target pressure > pressure_rel_sim ? | |
| 340 bra calc_compensation_sim_down ; YES - increase pressure_rel_sim | |
| 341 ; both pressures are equal | |
| 342 bra calc_compensation_sim_com ; NO to both - keep pressure_rel_sim as it is | |
| 0 | 343 |
| 623 | 344 calc_compensation_sim_up: |
| 345 movf PRODL,W ; get relative target pressure, low byte | |
| 346 subwf pressure_rel_sim+0,W ; WREG = pressure_rel_sim - relative target pressure (low byte) | |
| 347 movwf PRODL ; PRODL = pressure_rel_sim - relative target pressure (low byte) | |
| 348 movf PRODH,W ; get relative target pressure, high byte | |
| 349 subwfb pressure_rel_sim+1,W ; WREG = pressure_rel_sim - relative target pressure (high byte) | |
| 350 tstfsz WREG ; more than 255 mbar off from target? | |
| 351 bra calc_compensation_sim_up_norm ; YES - go up with normal speed | |
| 352 movlw simulator_ascent_threshold ; NO - get remaining difference for slowing down ascent | |
| 353 cpfslt PRODL ; - remaining difference to target < decrement? | |
| 354 bra calc_compensation_sim_up_norm ; NO - go up with normal speed | |
| 355 ;bra calc_compensation_sim_up_slow ; YES - go up with slow speed | |
| 356 | |
| 357 calc_compensation_sim_up_slow: | |
| 358 DECI pressure_rel_sim ; subtract slow decrement (1 mbar) from pressure_rel_sim | |
| 359 bra calc_compensation_sim_com ; continue with common part | |
| 360 | |
| 361 calc_compensation_sim_up_norm: | |
| 362 SUBLI simulator_ascent_rate,pressure_rel_sim ; subtract normal decrement from pressure_rel_sim | |
| 363 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
|
364 |
| 623 | 365 calc_compensation_sim_down: |
| 366 movf pressure_rel_sim+0,W ; get relative pressure, low byte | |
| 367 subwf PRODL,F ; PRODL = relative target pressure - pressure_rel_sim (low byte) | |
| 368 movf pressure_rel_sim+1,W ; get relative pressure, high byte | |
| 369 subwfb PRODH,W ; WREG = relative target pressure - pressure_rel_sim (high byte) | |
| 370 tstfsz WREG ; more than 255 mbar off from target? | |
| 371 bra calc_compensation_sim_down_norm ; YES - go down with normal speed | |
| 372 movlw simulator_descent_threshold ; NO - get remaining difference for slowing down descent | |
| 373 cpfslt PRODL ; - remaining difference to target < increment? | |
| 374 bra calc_compensation_sim_down_norm ; NO - go down with normal speed | |
| 375 ;bra calc_compensation_sim_down_slow ; YES - go down with slow speed | |
| 376 | |
| 377 calc_compensation_sim_down_slow: | |
| 378 INCI pressure_rel_sim ; add slow increment (1 mbar) to pressure_rel_sim | |
| 379 bra calc_compensation_sim_com ; continue with common part | |
| 604 | 380 |
| 623 | 381 calc_compensation_sim_down_norm: |
| 382 ADDLI simulator_descent_rate,pressure_rel_sim ; add normal increment to pressure_rel_sim | |
| 383 ;bra calc_compensation_sim_com ; continue with common part | |
| 384 | |
| 385 calc_compensation_sim_com: | |
| 386 movf pressure_surf+0,W ; copy surface pressure to WREG, low byte | |
| 387 addwf pressure_rel_sim+0,W ; add surface pressure to relative pressure to gain simulated absolute pressure, low byte | |
| 388 movwf isr_xC+1 ; override sensor pressure with simulated pressure, low byte | |
| 389 movf pressure_surf+1,W ; copy surface pressure to WREG, high byte | |
| 390 addwfc pressure_rel_sim+1,W ; add surface pressure to relative pressure to gain simulated absolute pressure, high byte | |
| 391 movwf isr_xC+2 ; override sensor pressure with simulated pressure, high byte | |
| 392 bsf sensor_override_active ; confirm sensor override is active | |
| 393 | |
| 394 calc_compensation_add_avg: | |
| 395 ; add current absolute pressure to averaging buffer | |
| 396 movf isr_xC+1,W ; copy current absolute pressure to WREG, low byte | |
| 397 addwf pressure_abs_avg+0,F ; pressure_abs_avg += current pressure, low byte | |
| 398 movf isr_xC+2,W ; copy current absolute pressure to WREG, high byte | |
| 399 addwfc pressure_abs_avg+1,F ; pressure_abs_avg += current pressure, high byte | |
| 643 | 400 movlw .0 |
| 401 addwfc pressure_abs_avg+2,F ; pressure_abs_avg += current pressure, upper byte | |
| 623 | 402 |
| 403 ;---- temperature sensor compensation | |
| 0 | 404 |
| 643 | 405 btfsc press_sensor_type ; New sensor found? |
| 406 bra temp_comp_ms5837 ; Yes, use MS5837 | |
| 407 | |
| 604 | 408 ; calculate temp = 200 + dT*(C6+100)/2^11 |
| 409 movlw LOW(.100) ; C6 + 100 --> A | |
| 634 | 410 addwf C6+0,W ; ... |
| 411 movwf isr_xA+0 ; ... | |
| 412 movlw HIGH(.100) ; ... | |
| 413 addwfc C6+1,W ; ... | |
| 414 movwf isr_xA+1 ; ... | |
| 0 | 415 |
| 623 | 416 MOVII xdT2,isr_xB ; dT2 --> B |
| 604 | 417 call isr_signed_mult16x16 ; A*B |
| 623 | 418 movlw .11-.8 ; a 12 bit shift = 1 byte + 3 bits |
| 634 | 419 call isr_shift_C31 ; special shift |
| 0 | 420 |
| 623 | 421 movlw LOW(.200) ; add 200 |
| 634 | 422 addwf isr_xC+1,F ; ... |
| 423 movlw HIGH(.200) ; ... | |
| 424 addwfc isr_xC+2,F ; ... | |
| 643 | 425 bra temp_comp_done_common |
| 0 | 426 |
| 643 | 427 temp_comp_ms5837: |
| 428 ; TEMP = 2000+((xdT * C6) / 2^23) | |
| 429 | |
| 430 ; xdT * C6 -> isr_xC:6 | |
| 431 movff C6+0,isr_xA+0 | |
| 432 movff C6+1,isr_xA+1 | |
| 433 clrf isr_xA+2 | |
| 434 movff xdT+0,isr_xB+0 | |
| 435 movff xdT+1,isr_xB+1 | |
| 436 movff xdT+2,isr_xB+2 | |
| 437 call isr_signed_mult24x24 ; A*B | |
| 438 | |
| 439 ; devide isr_xC:6 / 2^23 -> shift right 23 times | |
| 440 ; a special variant (again): We loose isr_xC+0 and isr_xC+1 anyway | |
| 441 ; and do not care about the inserted carry since we won't use isr_xC+5 | |
| 442 ; and we shift less then 8 bytes | |
| 443 movlw .23-.16 | |
| 444 temp_comp_ms5837_2: | |
| 445 rrcf isr_xC+5,F ; | |
| 446 rrcf isr_xC+4,F ; | |
| 447 rrcf isr_xC+3,F ; | |
| 448 rrcf isr_xC+2,F ; ... | |
| 449 decfsz WREG ; decrement loop counter, done? | |
| 450 bra temp_comp_ms5837_2 ; NO - loop | |
| 451 | |
| 452 ; only use +2 and +3 | |
| 453 movlw LOW(.2000) ; add 2000 | |
| 454 addwf isr_xC+2,F ; ... | |
| 455 movlw HIGH(.2000) ; ... | |
| 456 addwfc isr_xC+3,F ; ... | |
| 457 | |
| 458 ; devide by 10 for .1°C resolution | |
| 459 movlw .10 | |
| 460 movwf isr_xB+0 | |
| 461 clrf isr_xB+1 | |
| 462 movff isr_xC+2,isr_xA+0 | |
| 463 movff isr_xC+3,isr_xA+1 | |
| 464 | |
| 465 btfss isr_xC+3,7 ; check sign bit | |
| 466 bra temp_comp_ms5837_3 ; not negative... | |
| 467 ; negate isr_xA:2 to make it positive | |
| 468 comf isr_xA+1 ; 16 bit sign change | |
| 469 negf isr_xA+0 | |
| 470 btfsc STATUS,C ; - carry to propagate? | |
| 471 incf isr_xA+1,F ; YES - do it | |
| 472 | |
| 473 temp_comp_ms5837_3: | |
| 474 call isr_div16x16 ; isr_xC:2 = isr_xA:2 / isr_xB:2 | |
| 475 | |
| 476 btfss isr_xC+3,7 ; check sign bit again | |
| 477 bra temp_comp_ms5837_4 ; not negative... | |
| 478 ; negate result isr_xC:2 to make it negative again | |
| 479 comf isr_xC+1 ; 16 bit sign change | |
| 480 negf isr_xC+0 | |
| 481 btfsc STATUS,C ;- carry to propagate? | |
| 482 incf isr_xC+1,F ; YES - do it | |
| 483 | |
| 484 temp_comp_ms5837_4: | |
| 485 ; copy for compatibility of the next routines | |
| 486 movff isr_xC+1,isr_xC+2 | |
| 487 movff isr_xC+0,isr_xC+1 | |
| 488 | |
| 489 temp_comp_done_common: ; continue here even with MS5837 | |
| 623 | 490 ; add opt_temperature_adjust to result (SIGNED!) |
| 634 | 491 clrf isr_xC+0 ; prepare high byte for adjustment |
| 492 movff opt_temperature_adjust,WREG ; get low byte for adjustment (signed) | |
| 493 movf WREG,W ; excite flags | |
| 494 bz calc_temperature_add_avg ; opt_temperature_adjust = 0 -> skip adjustment | |
| 495 btfss STATUS,N ; opt_temperature_adjust < 0 ? | |
| 496 bra calc_temperature_adjust ; NO - positive | |
| 497 negf WREG ; YES - negate opt_temperature_adjust for limit check | |
| 498 setf isr_xC+0 ; - adopt high byte for adjustment | |
| 499 calc_temperature_adjust: | |
| 500 addlw -.21 ; limit is 2.0°C, subtract 21 (scaling is 0.1°C) | |
| 501 bnn calc_temperature_add_avg ; result not negative -> skip adjustment | |
| 502 movff opt_temperature_adjust,WREG ; get opt_temperature_adjust, low byte | |
| 503 addwf isr_xC+1,F ; temperature value += opt_temperature_adjust, low byte | |
| 504 movf isr_xC+0,W ; get adjustment high byte | |
| 505 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
|
506 |
| 634 | 507 calc_temperature_add_avg: |
| 508 movf isr_xC+1,W ; copy current temperature to WREG, low byte | |
| 509 addwf temperature_avg+0,F ; temperature_avg += current temperature, low byte | |
| 510 movf isr_xC+2,W ; copy current temperature to WREG, high byte | |
| 511 addwfc temperature_avg+1,F ; temperature_avg += current temperature, high byte | |
| 512 return ; done | |
| 513 | |
| 623 | 514 |
| 634 | 515 ;----------------------------------------------------------------------------- |
| 516 ; Start Pressure Measurement | |
| 517 ; | |
| 518 ; called from ISR and sleep mode, needs to be called in bank isr_backup | |
| 519 ; | |
| 520 global get_pressure_start | |
| 521 get_pressure_start: | |
| 643 | 522 btfsc press_sensor_type ; New sensor found? |
| 523 return ; Yes, ignore routine | |
| 634 | 524 rcall reset_MS5541 ; reset the chip |
| 525 movlw b'10100000' ; +3*high as start and 1+low as stop | |
| 526 movwf dbuffer ; .... | |
| 527 movlw d'12' ; send start command | |
| 643 | 528 bra send_data_MS5541 ; ... (And return) |
| 0 | 529 |
| 623 | 530 |
| 634 | 531 ;----------------------------------------------------------------------------- |
| 532 ; Read Pressure Measurement Result | |
| 533 ; | |
| 534 ; called from ISR and sleep mode, needs to be called in bank isr_backup | |
| 535 ; | |
| 536 global get_pressure_value | |
| 0 | 537 get_pressure_value: |
| 643 | 538 btfsc press_sensor_type ; New sensor found? |
| 539 bra get_pressure_value2 | |
| 623 | 540 btfsc MS5541_miso ; conversion done? |
| 634 | 541 return ; NO - abort |
| 542 rcall get_2bytes_MS5541 ; YES - read result | |
| 543 movff dMSB,D1+1 ; copy result to D1, high byte first | |
| 544 movff dLSB,D1+0 ; ... low byte second | |
| 545 return ; done | |
| 0 | 546 |
| 643 | 547 get_pressure_value2: |
| 548 btfsc i2c_busy_pressure ; currently updating pressure? | |
| 549 return ; Yes, skip update... | |
| 550 movff D1_buffer+0,D1+0 | |
| 551 movff D1_buffer+1,D1+1 | |
| 552 movff D1_buffer+2,D1+2 | |
| 553 return | |
| 554 | |
| 623 | 555 |
| 634 | 556 ;----------------------------------------------------------------------------- |
| 557 ; Start Temperature Measurement | |
| 558 ; | |
| 559 ; called from ISR and sleep mode, needs to be called in bank isr_backup | |
| 560 ; | |
| 561 global get_temperature_start | |
| 562 get_temperature_start: | |
| 643 | 563 btfsc press_sensor_type ; New sensor found? |
| 564 return ; Yes, ignore routine | |
| 634 | 565 rcall reset_MS5541 ; reset chip |
| 566 movlw b'10010000' ; +3*high as start and 1+low as stop | |
| 567 movwf dbuffer ; ... | |
| 568 movlw d'12' ; send start command | |
| 643 | 569 bra send_data_MS5541 ; ... (And return) |
| 634 | 570 |
| 571 | |
| 572 ;----------------------------------------------------------------------------- | |
| 573 ; Read Pressure Measurement Result | |
| 574 ; | |
| 575 ; called from ISR and sleep mode, needs to be called in bank isr_backup | |
| 576 ; | |
| 577 global get_temperature_value | |
| 0 | 578 get_temperature_value: |
| 643 | 579 btfsc press_sensor_type ; New sensor found? |
| 580 bra get_temperature_value2 | |
| 623 | 581 btfsc MS5541_miso ; conversion done? |
| 582 return ; NO - done | |
| 634 | 583 rcall get_2bytes_MS5541 ; YES - read result |
| 584 movff dMSB,D2+1 ; copy result to D2, high byte first | |
| 585 movff dLSB,D2+0 ; ... low byte second | |
| 586 return ; done | |
| 587 | |
| 643 | 588 get_temperature_value2: |
| 589 btfsc i2c_busy_temperature ; currently updating temperature? | |
| 590 return ; Yes, skip update... | |
| 591 movff D2_buffer+0,D2+0 | |
| 592 movff D2_buffer+1,D2+1 | |
| 593 movff D2_buffer+2,D2+2 | |
| 594 return | |
| 595 | |
| 0 | 596 |
| 634 | 597 ;----------------------------------------------------------------------------- |
| 598 ; Retrieve Calibration Data | |
| 599 ; | |
| 600 ; called by start, returns in bank common | |
| 601 ; | |
| 602 global get_calibration_data | |
| 0 | 603 get_calibration_data: |
| 623 | 604 banksel isr_backup ; select bank ISR data |
| 643 | 605 bsf block_sensor_interrupt ; disable sensor interrupts |
| 0 | 606 |
| 643 | 607 btfsc press_sensor_type ; New sensor found? |
| 608 call I2C_get_calib_MS5837 ; Yes, read C1 to C6 | |
| 609 banksel isr_backup ; select bank ISR data | |
| 645 | 610 ; double-check sensor type |
| 611 movlw 0xED | |
| 612 cpfseq C1+0 | |
| 613 bra get_calibration_data1 ; Not 0xED (I2C address false reading) | |
| 614 movlw 0xED | |
| 615 cpfseq C1+1 | |
| 616 bra get_calibration_data1 ; Not 0xED (I2C address false reading) | |
| 617 movlw 0xED | |
| 618 cpfseq C5+0 | |
| 619 bra get_calibration_data1 ; Not 0xED (I2C address false reading) | |
| 620 movlw 0xED | |
| 621 cpfseq C5+1 | |
| 622 bra get_calibration_data1 ; Not 0xED (I2C address false reading) | |
| 643 | 623 |
| 645 | 624 ; C1 and C5 are 0xEDED -> NOT Sensor 1 |
| 625 bcf press_sensor_type | |
| 626 | |
| 627 get_calibration_data1: | |
| 643 | 628 btfsc press_sensor_type ; New sensor found? |
| 629 bra get_calibration_data2 ; Yes, skip to the end | |
| 630 | |
| 634 | 631 rcall reset_MS5541 ; reset chip |
| 632 | |
| 623 | 633 movlw b'01010100' ; +3*high as start and 1+low as stop |
| 634 | 634 movwf dbuffer ; ... |
| 635 movlw d'13' ; send command | |
| 636 rcall send_data_MS5541 ; ... | |
| 637 rcall get_2bytes_MS5541 ; read result | |
| 656 | 638 movff dMSB,ms5541_rawdata+1 ; copy result, high byte first |
| 639 movff dLSB,ms5541_rawdata+0 ; copy result, low byte second | |
| 0 | 640 |
| 623 | 641 movlw b'01011000' ; +3*high as start and 1+low as stop |
| 634 | 642 movwf dbuffer ; ... |
| 643 movlw d'13' ; send command | |
| 644 rcall send_data_MS5541 ; ... | |
| 645 rcall get_2bytes_MS5541 ; read result | |
| 656 | 646 movff dMSB,ms5541_rawdata+3 ; copy result, high byte first |
| 647 movff dLSB,ms5541_rawdata+2 ; copy result, low byte second | |
| 0 | 648 |
| 623 | 649 movlw b'01100100' ; +3*high as start and 1+low as stop |
| 634 | 650 movwf dbuffer ; ... |
| 651 movlw d'13' ; send command | |
| 652 rcall send_data_MS5541 ; ... | |
| 653 rcall get_2bytes_MS5541 ; read result | |
| 656 | 654 movff dMSB,ms5541_rawdata+5 ; copy result, high byte first |
| 655 movff dLSB,ms5541_rawdata+4 ; copy result, low byte second | |
| 0 | 656 |
| 623 | 657 movlw b'01101000' ; +3*high as start and 1+low as stop |
| 634 | 658 movwf dbuffer ; ... |
| 659 movlw d'13' ; send command | |
| 660 rcall send_data_MS5541 ; ... | |
| 661 rcall get_2bytes_MS5541 ; read result | |
| 656 | 662 movff dMSB,ms5541_rawdata+7 ; copy result, high byte first |
| 663 movff dLSB,ms5541_rawdata+6 ; copy result, low byte second | |
| 0 | 664 |
| 634 | 665 ; calculate C1 (16 Bit) |
| 656 | 666 movff ms5541_rawdata+1,C1+1 |
| 0 | 667 bcf STATUS,C |
| 668 rrcf C1+1 | |
| 669 bcf STATUS,C | |
| 670 rrcf C1+1 | |
| 671 bcf STATUS,C | |
| 672 rrcf C1+1 | |
| 656 | 673 movff ms5541_rawdata+0,C1+0 |
| 0 | 674 bsf STATUS,C |
| 656 | 675 btfss ms5541_rawdata+1,0 |
| 0 | 676 bcf STATUS,C |
| 677 rrcf C1+0 | |
| 678 bsf STATUS,C | |
| 656 | 679 btfss ms5541_rawdata+1,1 |
| 0 | 680 bcf STATUS,C |
| 681 rrcf C1+0 | |
| 682 bsf STATUS,C | |
| 656 | 683 btfss ms5541_rawdata+1,2 |
| 0 | 684 bcf STATUS,C |
| 685 rrcf C1+0 | |
| 686 | |
| 634 | 687 ; calculate C2 (16 Bit) |
| 656 | 688 movff ms5541_rawdata+2, C2+0 |
| 0 | 689 bsf STATUS,C |
| 656 | 690 btfss ms5541_rawdata+3,0 |
| 0 | 691 bcf STATUS,C |
| 692 rrcf C2+0 | |
| 693 bsf STATUS,C | |
| 656 | 694 btfss ms5541_rawdata+3,1 |
| 0 | 695 bcf STATUS,C |
| 696 rrcf C2+0 | |
| 697 bsf STATUS,C | |
| 656 | 698 btfss ms5541_rawdata+3,2 |
| 0 | 699 bcf STATUS,C |
| 700 rrcf C2+0 | |
| 701 bsf STATUS,C | |
| 656 | 702 btfss ms5541_rawdata+3,3 |
| 0 | 703 bcf STATUS,C |
| 704 rrcf C2+0 | |
| 705 bsf STATUS,C | |
| 656 | 706 btfss ms5541_rawdata+3,4 |
| 0 | 707 bcf STATUS,C |
| 708 rrcf C2+0 | |
| 709 bsf STATUS,C | |
| 656 | 710 btfss ms5541_rawdata+3,5 |
| 0 | 711 bcf STATUS,C |
| 712 rrcf C2+0 | |
| 713 | |
| 656 | 714 movff ms5541_rawdata+3, C2+1 |
| 0 | 715 bsf STATUS,C |
| 656 | 716 btfss ms5541_rawdata+0,0 |
| 0 | 717 bcf STATUS,C |
| 718 rrcf C2+1 | |
| 719 bsf STATUS,C | |
| 656 | 720 btfss ms5541_rawdata+0,1 |
| 0 | 721 bcf STATUS,C |
| 722 rrcf C2+1 | |
| 723 bsf STATUS,C | |
| 656 | 724 btfss ms5541_rawdata+0,2 |
| 0 | 725 bcf STATUS,C |
| 726 rrcf C2+1 | |
| 727 bcf STATUS,C | |
| 728 rrcf C2+1 | |
| 729 bcf STATUS,C | |
| 730 rrcf C2+1 | |
| 731 bcf STATUS,C | |
| 732 rrcf C2+1 | |
| 733 | |
| 634 | 734 ; calculate C3 (16 Bit) |
| 656 | 735 movff ms5541_rawdata+5,C3+0 |
| 0 | 736 bsf STATUS,C |
| 656 | 737 btfss ms5541_rawdata+4,7 |
| 0 | 738 bcf STATUS,C |
| 739 rlcf C3+0 | |
| 740 bsf STATUS,C | |
| 656 | 741 btfss ms5541_rawdata+4,6 |
| 0 | 742 bcf STATUS,C |
| 743 rlcf C3+0 | |
| 744 clrf C3+1 | |
| 656 | 745 btfsc ms5541_rawdata+5,7 |
| 0 | 746 bsf C3+1,1 |
| 656 | 747 btfsc ms5541_rawdata+5,6 |
| 0 | 748 bsf C3+1,0 |
| 604 | 749 |
| 634 | 750 ; calculate C4 (16 Bit) |
| 656 | 751 movff ms5541_rawdata+7,C4+0 |
| 0 | 752 bsf STATUS,C |
| 656 | 753 btfss ms5541_rawdata+6,7 |
| 0 | 754 bcf STATUS,C |
| 755 rlcf C4+0 | |
| 756 clrf C4+1 | |
| 656 | 757 btfsc ms5541_rawdata+7,7 |
| 0 | 758 bsf C4+1,0 |
| 759 | |
| 623 | 760 ; C4=C4-250 |
| 604 | 761 movlw LOW(-.250) ; C4 - 250 --> C4 |
| 0 | 762 addwf C4+0,W |
| 604 | 763 movwf C4+0 |
| 764 movlw -1 ; HIGH(- .250) is not understood... | |
| 765 addwfc C4+1,W | |
| 766 movwf C4+1 | |
| 767 | |
| 634 | 768 ; calculate C5 (16 Bit) |
| 656 | 769 movff ms5541_rawdata+4,C5+0 |
| 0 | 770 bcf C5+0,6 |
| 656 | 771 btfsc ms5541_rawdata+2,0 |
| 0 | 772 bsf C5+0,6 |
| 773 bcf C5+0,7 | |
| 656 | 774 btfsc ms5541_rawdata+2,1 |
| 0 | 775 bsf C5+0,7 |
| 776 clrf C5+1 | |
| 656 | 777 btfsc ms5541_rawdata+2,2 |
| 0 | 778 bsf C5+1,0 |
| 656 | 779 btfsc ms5541_rawdata+2,3 |
| 0 | 780 bsf C5+1,1 |
| 656 | 781 btfsc ms5541_rawdata+2,4 |
| 0 | 782 bsf C5+1,2 |
| 656 | 783 btfsc ms5541_rawdata+2,5 |
| 0 | 784 bsf C5+1,3 |
| 785 | |
| 604 | 786 ; calculate C5 = UT1 |
| 787 ; C5 = 8*C5 + 10000 (u16 range 10.000 .. +42.760) | |
| 0 | 788 clrf isr_xA+1 |
| 789 movlw d'8' | |
| 790 movwf isr_xA+0 | |
| 623 | 791 MOVII C5,isr_xB |
| 792 call isr_unsigned_mult16x16 ; isr_xA*isr_xB=isr_xC | |
| 793 MOVII isr_xC,C5 | |
| 604 | 794 movlw LOW d'10000' |
| 795 addwf C5+0,F | |
| 796 movlw HIGH d'10000' | |
| 623 | 797 addwfc C5+1,F ; = 8*C5 + 10000 |
| 0 | 798 |
| 623 | 799 ; calculate C6 (16Bit) |
| 0 | 800 clrf C6+1 |
| 656 | 801 movff ms5541_rawdata+6,C6+0 |
| 0 | 802 bcf C6+0,7 |
| 803 | |
| 643 | 804 get_calibration_data2: |
| 623 | 805 clrf sensor_state_counter ; reset state counter |
| 806 bcf block_sensor_interrupt ; re-enable sensor interrupts | |
| 807 banksel common ; back to bank common | |
| 808 return ; done | |
| 0 | 809 |
| 634 | 810 |
| 811 ;----------------------------------------------------------------------------- | |
| 812 ; Helper Function - Reset Chip | |
| 813 ; | |
| 0 | 814 reset_MS5541_one: |
| 634 | 815 bsf MS5541_mosi ; set MOSI |
| 623 | 816 bra send_clk_pulse ; send one high-low sequence on MS5541_clk and return |
| 0 | 817 |
| 818 reset_MS5541_zero: | |
| 634 | 819 bcf MS5541_mosi ; clear MOSI |
| 623 | 820 bra send_clk_pulse ; send one high-low sequence on MS5541_clk and return |
| 0 | 821 |
| 822 reset_MS5541: | |
| 604 | 823 rcall reset_MS5541_one ; 0 |
| 0 | 824 rcall reset_MS5541_zero |
| 825 rcall reset_MS5541_one | |
| 826 rcall reset_MS5541_zero | |
| 827 rcall reset_MS5541_one | |
| 828 rcall reset_MS5541_zero | |
| 829 rcall reset_MS5541_one | |
| 830 rcall reset_MS5541_zero | |
| 831 rcall reset_MS5541_one | |
| 832 rcall reset_MS5541_zero | |
| 833 rcall reset_MS5541_one | |
| 834 rcall reset_MS5541_zero | |
| 835 rcall reset_MS5541_one | |
| 836 rcall reset_MS5541_zero | |
| 837 rcall reset_MS5541_one | |
| 604 | 838 rcall reset_MS5541_zero ; 15 |
| 839 rcall reset_MS5541_zero | |
| 840 rcall reset_MS5541_zero | |
| 841 rcall reset_MS5541_zero | |
| 842 rcall reset_MS5541_zero | |
| 843 rcall reset_MS5541_zero ; 20 | |
| 0 | 844 return |
| 845 | |
| 623 | 846 |
| 634 | 847 ;----------------------------------------------------------------------------- |
| 848 ; Helper Function - read 2 Byte from Chip | |
| 849 ; | |
| 0 | 850 get_2bytes_MS5541: |
| 634 | 851 movlw d'8' ; load counter for 8 bit |
| 852 movwf clock_count ; ... | |
| 853 rcall recieve_loop ; receive 8 bits | |
| 854 movff dbuffer,dMSB ; store result | |
| 855 movlw d'8' ; load counter for 8 bit | |
| 856 movwf clock_count ; ... | |
| 857 rcall recieve_loop ; receive 8 bits | |
| 858 movff dbuffer,dLSB ; store result | |
| 623 | 859 bra send_clk_pulse ; send one high-low sequence on MS5541_clk and return |
| 0 | 860 |
| 634 | 861 |
| 862 ;----------------------------------------------------------------------------- | |
| 863 ; Helper Function - read 1 Bit from Chip | |
| 864 ; | |
| 0 | 865 recieve_loop: |
| 623 | 866 rcall send_clk_pulse ; send one high-low sequence on MS5541_clk |
| 634 | 867 btfss MS5541_miso ; read bit = 1 ? (MSB first) |
| 868 bcf STATUS,C ; NO - clear carry bit | |
| 869 btfsc MS5541_miso ; read bit = 0 ? (MSB first) | |
| 870 bsf STATUS,C ; NO - set carry bit | |
| 871 rlcf dbuffer,F ; shift buffer | |
| 872 decfsz clock_count,F ; decrement counter, became zero? | |
| 873 bra recieve_loop ; NO - loop | |
| 874 return ; YES - done | |
| 0 | 875 |
| 634 | 876 |
| 877 ;----------------------------------------------------------------------------- | |
| 878 ; Helper Function - send a Clock Pulse | |
| 879 ; | |
| 0 | 880 send_clk_pulse: |
| 634 | 881 bsf MS5541_clk ; set clock |
| 0 | 882 nop |
| 883 nop | |
| 884 nop | |
| 885 nop | |
|
29
50c3e2c7ba7a
adding cardinal (and ordinal) directions for the compass
heinrichsweikamp
parents:
0
diff
changeset
|
886 nop |
|
50c3e2c7ba7a
adding cardinal (and ordinal) directions for the compass
heinrichsweikamp
parents:
0
diff
changeset
|
887 nop |
| 634 | 888 bcf MS5541_clk ; release clock |
| 0 | 889 nop |
| 890 nop | |
|
29
50c3e2c7ba7a
adding cardinal (and ordinal) directions for the compass
heinrichsweikamp
parents:
0
diff
changeset
|
891 nop |
|
50c3e2c7ba7a
adding cardinal (and ordinal) directions for the compass
heinrichsweikamp
parents:
0
diff
changeset
|
892 nop |
| 634 | 893 return ; done |
| 0 | 894 |
| 623 | 895 |
| 634 | 896 ;----------------------------------------------------------------------------- |
| 897 ; Helper Function - send a Command | |
| 898 ; | |
| 0 | 899 send_data_MS5541: |
| 623 | 900 movwf clock_count ; from WREG |
| 901 ; send three start bits first | |
| 634 | 902 bcf MS5541_clk ; revoke clock |
| 903 nop ; wait | |
| 904 nop ; wait | |
| 905 bsf MS5541_mosi ; set MOSI | |
| 906 movlw d'3' ; compute total bit counter | |
| 907 subwf clock_count,F ; ... | |
| 623 | 908 rcall send_clk_pulse ; send one high-low sequence on MS5541_clk |
| 909 rcall send_clk_pulse ; send one high-low sequence on MS5541_clk | |
| 910 rcall send_clk_pulse ; send one high-low sequence on MS5541_clk | |
| 634 | 911 |
| 912 send_data_MS5541_loop: | |
| 913 ; now send 8 bits from dbuffer and fill-up with zeros | |
| 914 bcf MS5541_clk ; revoke clock | |
| 915 nop ; wait | |
| 916 nop ; wait | |
| 917 btfss dbuffer,7 ; bit = 1 ? (MSB first) | |
| 918 bcf MS5541_mosi ; NO - clear MOSI | |
| 919 btfsc dbuffer,7 ; bit = 0 ? (MSB first) | |
| 920 bsf MS5541_mosi ; NO - set MOSI | |
| 921 bsf MS5541_clk ; set clock | |
| 922 bcf STATUS,C ; clear carry bit | |
| 923 rlcf dbuffer,F ; shift data byte | |
| 924 nop ; wait | |
| 925 nop ; wait | |
| 0 | 926 ; nop |
| 927 ; nop | |
| 928 ; nop | |
| 929 ; nop | |
| 930 ; bcf MS5541_clk | |
| 634 | 931 decfsz clock_count,F ; decrement bit counter, became zero? |
| 932 bra send_data_MS5541_loop ; NO - loop | |
| 933 bcf MS5541_clk ; YES - revoke clock | |
| 934 return ; - done | |
| 0 | 935 |
| 634 | 936 ;----------------------------------------------------------------------------- |
| 937 | |
| 938 END |
