comparison src/ms5541.asm @ 604:ca4556fb60b9

bump to 2.99beta, work on 3.00 stable
author heinrichsweikamp
date Thu, 22 Nov 2018 19:47:26 +0100
parents 57e349960ef4
children c40025d8e750
comparison
equal deleted inserted replaced
603:00b24fb4324d 604:ca4556fb60b9
1 ;============================================================================= 1 ;=============================================================================
2 ; 2 ;
3 ; File ms5541.asm 3 ; File ms5541.asm V2.98c
4 ; 4 ;
5 ; Sensor subroutines 5 ; Sensor subroutines
6 ; 6 ;
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. 7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved.
8 ;============================================================================= 8 ;=============================================================================
9 ; HISTORY 9 ; HISTORY
10 ; 2011-08-03 : [mH] moving from OSTC code 10 ; 2011-08-03 : [mH] moving from OSTC code
11 11
12 #include "hwos.inc" ; Mandatory header 12 #include "hwos.inc" ; Mandatory header
13 #include "math.inc" ; Math routines 13 #include "math.inc" ; Math routines
14 14
15 sensors CODE 15 ms5541 CODE
16 16
17 ;============================================================================= 17 ;=============================================================================
18 ; Expose internal variables, to ease debug: 18 ; Expose internal variables, to ease debug:
19 global D1, D2 19 global D1, D2
20 global C1, C2, C3, C4, C5, C6 20 global C1, C2, C3, C4, C5, C6
21 global xdT, xdT2, OFF, SENS, amb_pressure_avg, temperature_avg 21 global xdT, xdT2, OFF, SENS, amb_pressure_avg, temperature_avg
22 22
23 ;============================================================================= 23 ;=============================================================================
24 global calculate_compensation 24 global calculate_compensation
25 calculate_compensation: 25 calculate_compensation:
26 ; xdT = D2 - C5 (s16 range -11.400 .. +12.350) 26 ; xdT = D2 - C5 (s16 range -11.400 .. +12.350)
27 movf C5+0,W ; Get Value to be subtracted 27 movf C5+0,W ; Get Value to be subtracted
28 subwf D2+0,W ; Do the Low Byte 28 subwf D2+0,W ; Do the Low Byte
29 movwf xdT+0 29 movwf xdT+0
30 movf C5+1,W ; Then the high byte. 30 movf C5+1,W ; Then the high byte.
31 subwfb D2+1,W 31 subwfb D2+1,W
32 movwf xdT+1 32 movwf xdT+1
33 33
34 ; Second order temperature calculation 34 ; Second order temperature calculation
35 ; xdT/128 is in range -89..+96, hence signed 8bit. dT/128 = (2*dT)/256 35 ; xdT/128 is in range -89..+96, hence signed 8bit. dT/128 = (2*dT)/256
36 rlcf xdT+0,W ; put hit bit in carry. 36 rlcf xdT+0,W ; put hit bit in carry.
37 rlcf xdT+1,W ; inject in high byte. 37 rlcf xdT+1,W ; inject in high byte.
38 movwf isr_xA+0 ; and put result in low byte. 38 movwf isr_xA+0 ; and put result in low byte.
39 clrf isr_xA+1 39 clrf isr_xA+1
40 btfsc xdT+1,7 ; If dT < 0 40 btfsc xdT+1,7 ; If dT < 0
41 setf isr_xA+1 ; then signextend to -1 41 setf isr_xA+1 ; then signextend to -1
42 movff isr_xA+0,isr_xB+0 ; copy A to B 42 movff isr_xA+0,isr_xB+0 ; copy A to B
43 movff isr_xA+1,isr_xB+1 43 movff isr_xA+1,isr_xB+1
44 call isr_signed_mult16x16 ; dT*dT --> xC (32 bits) 44 call isr_signed_mult16x16 ; dT*dT --> xC (32 bits)
45 45
46 ; dT >= 0: divide by 8, ie. 3 shifts rights. 46 ; dT >= 0: divide by 8, ie. 3 shifts rights.
47 ; dT < 0: divide by 2, ie. 1 shifts rights. 47 ; dT < 0: divide by 2, ie. 1 shifts rights.
48 movlw .3 48 movlw .3
49 btfss xdT+1,7 ; Was dT negative ? 49 btfss xdT+1,7 ; Was dT negative ?
50 movlw .1 50 movlw .1
51 calc_loop_1: 51 calc_loop_1:
52 bcf STATUS,C ;dT^2 is positive, so injected zeros. 52 bcf STATUS,C ; dT^2 is positive, so injected zeros.
53 rrcf isr_xC+1,F 53 rrcf isr_xC+1,F
54 rrcf isr_xC+0,F 54 rrcf isr_xC+0,F
55 decfsz WREG 55 decfsz WREG
56 bra calc_loop_1 56 bra calc_loop_1
57 57
58 movf isr_xC+0,W ; dT2 = dT - (dT/128)*(dT/128)/(2 ...or... 8) 58 movf isr_xC+0,W ; dT2 = dT - (dT/128)*(dT/128)/(2 ...or... 8)
59 subwf xdT+0,W 59 subwf xdT+0,W
60 movwf xdT2+0 60 movwf xdT2+0
61 movf isr_xC+1,W 61 movf isr_xC+1,W
62 subwfb xdT+1,W 62 subwfb xdT+1,W
63 movwf xdT2+1 63 movwf xdT2+1
64 64
65 ; Calculate OFF = C2 + ((C4-250)*dT2)/2^12 + 10000 65 ; Calculate OFF = C2 + ((C4-250)*dT2)/2^12 + 10000
66 ; (range +9.246 .. +18.887) 66 ; (range +9.246 .. +18.887)
67 movff C4+0,isr_xA+0 ; C4 - 250 --> A 67 movff C4+0,isr_xA+0 ; C4 - 250 --> A
68 movff C4+1,isr_xA+1 68 movff C4+1,isr_xA+1
69 movff xdT2+0,isr_xB+0 ; dT2 --> B 69 movff xdT2+0,isr_xB+0 ; dT2 --> B
70 movff xdT2+1,isr_xB+1 70 movff xdT2+1,isr_xB+1
71 call isr_signed_mult16x16 71 call isr_signed_mult16x16
72 72
73 movlw .12-.8 ; A 12bit shift = 1 byte + 4 bits. 73 movlw .12-.8 ; A 12bit shift = 1 byte + 4 bits.
74 call isr_shift_C31 74 call isr_shift_C31
75 75
76 movlw LOW(.10000) ; Add 10000 76 movlw LOW(.10000) ; Add 10000
77 addwf isr_xC+1,F 77 addwf isr_xC+1,F
78 movlw HIGH(.10000) 78 movlw HIGH(.10000)
79 addwfc isr_xC+2,F 79 addwfc isr_xC+2,F
80 80
81 movf C2+0,W ; Add C2, and save into OFF 81 movf C2+0,W ; Add C2, and save into OFF
82 addwf isr_xC+1,W 82 addwf isr_xC+1,W
83 movwf OFF+0 83 movwf OFF+0
84 movf C2+1,W 84 movf C2+1,W
85 addwfc isr_xC+2,W 85 addwfc isr_xC+2,W
86 movwf OFF+1 86 movwf OFF+1
87 87
88 ; Calculate SENS = C1/2 + ((C3+200)*dT)/2^13 + 3000 88 ; Calculate SENS = C1/2 + ((C3+200)*dT)/2^13 + 3000
89 movlw LOW(.200) ; C3+200 --> A 89 movlw LOW(.200) ; C3+200 --> A
90 addwf C3+0,W 90 addwf C3+0,W
91 movwf isr_xA+0 91 movwf isr_xA+0
92 movlw HIGH(.200) 92 movlw HIGH(.200)
93 addwfc C3+1,W 93 addwfc C3+1,W
94 movwf isr_xA+1 94 movwf isr_xA+1
95 ; B still contains dT2 95 ; B still contains dT2
96 call isr_signed_mult16x16 ; A*B --> C 96 call isr_signed_mult16x16 ; A*B --> C
97 movlw .13-.8 ; A 13bit shift = 1 byte + 5 bits. 97 movlw .13-.8 ; A 13bit shift = 1 byte + 5 bits.
98 call isr_shift_C31 98 call isr_shift_C31
99 99
100 bcf STATUS,C ; SENS = C1 / 2 100 bcf STATUS,C ; SENS = C1 / 2
101 rrcf C1+1,W 101 rrcf C1+1,W
102 movwf SENS+1 102 movwf SENS+1
103 rrcf C1+0,W 103 rrcf C1+0,W
104 movwf SENS+0 104 movwf SENS+0
105 105
106 movlw LOW(.3000) ; Add 3000 106 movlw LOW(.3000) ; Add 3000
107 addwf isr_xC+1,F 107 addwf isr_xC+1,F
108 movlw HIGH(.3000) 108 movlw HIGH(.3000)
109 addwfc isr_xC+2,F 109 addwfc isr_xC+2,F
110 110
111 movf isr_xC+1,W ; And sum into SENS 111 movf isr_xC+1,W ; And sum into SENS
112 addwf SENS+0,F 112 addwf SENS+0,F
113 movf isr_xC+2,W 113 movf isr_xC+2,W
114 addwfc SENS+1,F 114 addwfc SENS+1,F
115 115
116 ; calculate amb_pressure = (sens * (d1-off))/2^12 + 1000 116 ; calculate amb_pressure = (sens * (d1-off))/2^12 + 1000
117 movf OFF+0,W ; d1-off --> a 117 movf OFF+0,W ; d1-off --> a
118 subwf D1+0,W 118 subwf D1+0,W
119 movwf isr_xA+0 119 movwf isr_xA+0
120 movf OFF+1,W 120 movf OFF+1,W
121 subwfb D1+1,W 121 subwfb D1+1,W
122 movwf isr_xA+1 122 movwf isr_xA+1
123 123
124 movff SENS+0,isr_xB+0 ; sens --> b 124 movff SENS+0,isr_xB+0 ; sens --> b
125 movff SENS+1,isr_xB+1 125 movff SENS+1,isr_xB+1
126 call isr_signed_mult16x16 126 call isr_signed_mult16x16
127 movlw .12-.8 ; a 12bit shift = 1 byte + 4 bits. 127 movlw .12-.8 ; a 12bit shift = 1 byte + 4 bits.
128 call isr_shift_C31 128 call isr_shift_C31
129 129
130 movlw LOW(.1000) ; add 1000 130 movlw LOW(.1000) ; add 1000
131 addwf isr_xC+1,F 131 addwf isr_xC+1,F
132 movlw HIGH(.1000) 132 movlw HIGH(.1000)
133 addwfc isr_xC+2,F 133 addwfc isr_xC+2,F
134 134
135 ; Add opt_pressure_adjust to result (SIGNED!) 135 ; Add opt_pressure_adjust to result (SIGNED!)
136 movff opt_pressure_adjust,isr_xC+0 136 movff opt_pressure_adjust,isr_xC+0
137 137
138 btfss isr_xC+0,7 ; <0? 138 btfss isr_xC+0,7 ; < 0 ?
139 bra pressure_extra_add ; No 139 bra pressure_extra_add ; No
140 ; Yes 140 ; Yes
141 comf isr_xC+0,F 141 comf isr_xC+0,F
142 incf isr_xC+0,F 142 incf isr_xC+0,F
143 ; Check for max. of 20mbar 143 ; Check for max. of 20mbar
144 movlw .22 144 movlw .22
145 cpfslt isr_xC+0 145 cpfslt isr_xC+0
146 clrf isr_xC+0 146 clrf isr_xC+0
147 ; Subtract 147 ; Subtract
148 movf isr_xC+0,W 148 movf isr_xC+0,W
149 subwf isr_xC+1,F 149 subwf isr_xC+1,F
150 movlw .0 150 movlw .0
151 subwfb isr_xC+2,F 151 subwfb isr_xC+2,F
152 bra pressure_extra_common 152 bra pressure_extra_common
153 153
154 pressure_extra_add: 154 pressure_extra_add:
155 ; Check for max. of 20mbar 155 ; Check for max. of 20mbar
156 movlw .21 156 movlw .21
157 cpfslt isr_xC+0 157 cpfslt isr_xC+0
158 clrf isr_xC+0 158 clrf isr_xC+0
159 ; Add 159 ; Add
160 movf isr_xC+0,W 160 movf isr_xC+0,W
161 addwf isr_xC+1,F 161 addwf isr_xC+1,F
162 movlw .0 162 movlw .0
163 addwfc isr_xC+2,F 163 addwfc isr_xC+2,F
164 164
165 pressure_extra_common: 165 pressure_extra_common:
166 banksel common ; flag2 is in bank 1 166 banksel common ; flag2 is in bank 1
167 btfss simulatormode_active ; are we in simulator mode? 167 btfss simulatormode_active ; are we in simulator mode?
168 bra calc_compensation_2 ; no 168 bra calc_compensation_2 ; no
169 169
170 banksel isr_xC+2 170 banksel isr_xC+2
171 movlw .5 171 movlw .5
172 cpfsgt isr_xC+2 ; >1280mbar ? 172 cpfsgt isr_xC+2 ; > 1280 mbar ?
173 bra pressure_extra_common2 ; No 173 bra pressure_extra_common2 ; No
174 ; Yes, reset sim_pressure:2 to 1000mbar (End of sim) 174 ; Yes, reset sim_pressure:2 to 1000mbar (End of sim)
175 movlw LOW .1000 175 movlw LOW .1000
176 movwf sim_pressure+0 176 movwf sim_pressure+0
177 movlw HIGH .1000 177 movlw HIGH .1000
178 movwf sim_pressure+1 178 movwf sim_pressure+1
179 179
180 pressure_extra_common2: 180 pressure_extra_common2:
181 movff sim_pressure+0,isr_xC+1 ; override readings with simulator values 181 movff sim_pressure+0,isr_xC+1 ; override readings with simulator values
182 movff sim_pressure+1,isr_xC+2 182 movff sim_pressure+1,isr_xC+2
183 183
184 calc_compensation_2: 184 calc_compensation_2:
185 banksel isr_backup 185 banksel isr_backup
186 movf isr_xC+1,W ; Then sum_up to pressure averaging buffer. 186 movf isr_xC+1,W ; Then sum_up to pressure averaging buffer.
187 addwf amb_pressure_avg+0,F 187 addwf amb_pressure_avg+0,F
188 movf isr_xC+2,W 188 movf isr_xC+2,W
189 addwfc amb_pressure_avg+1,F 189 addwfc amb_pressure_avg+1,F
190 190
191 ; calculate temp = 200 + dT*(C6+100)/2^11 191 ; calculate temp = 200 + dT*(C6+100)/2^11
192 movlw LOW(.100) ; C6 + 100 --> A 192 movlw LOW(.100) ; C6 + 100 --> A
193 addwf C6+0,W 193 addwf C6+0,W
194 movwf isr_xA+0 194 movwf isr_xA+0
195 movlw HIGH(.100) 195 movlw HIGH(.100)
196 addwfc C6+1,W 196 addwfc C6+1,W
197 movwf isr_xA+1 197 movwf isr_xA+1
198 198
199 movff xdT2+0,isr_xB+0 ; dT2 --> B 199 movff xdT2+0,isr_xB+0 ; dT2 --> B
200 movff xdT2+1,isr_xB+1 200 movff xdT2+1,isr_xB+1
201 call isr_signed_mult16x16 ; A*B 201 call isr_signed_mult16x16 ; A*B
202 movlw .11-.8 ; A 12bit shift = 1 byte + 3 bits. 202 movlw .11-.8 ; A 12 bit shift = 1 byte + 3 bits
203 call isr_shift_C31 203 call isr_shift_C31
204 204
205 movlw LOW(.200) ; Add 200 205 movlw LOW(.200) ; Add 200
206 addwf isr_xC+1,F 206 addwf isr_xC+1,F
207 movlw HIGH(.200) 207 movlw HIGH(.200)
208 addwfc isr_xC+2,F 208 addwfc isr_xC+2,F
209 209
210 ; Add opt_temperature_adjust to result (SIGNED!) 210 ; Add opt_temperature_adjust to result (SIGNED!)
211 movff opt_temperature_adjust,isr_xC+0 211 movff opt_temperature_adjust,isr_xC+0
212 212
213 btfss isr_xC+0,7 ; <0? 213 btfss isr_xC+0,7 ; < 0 ?
214 bra temperature_extra_add ; No 214 bra temperature_extra_add ; No
215 ; Yes 215 ; Yes
216 comf isr_xC+0,F 216 comf isr_xC+0,F
217 incf isr_xC+0,F 217 incf isr_xC+0,F
218 ; Check for max. of 2.0°C 218 ; Check for max. of 2.0°C
219 movlw .22 219 movlw .22
220 cpfslt isr_xC+0 220 cpfslt isr_xC+0
221 clrf isr_xC+0 221 clrf isr_xC+0
222 ; Subtract 222 ; Subtract
223 movf isr_xC+0,W 223 movf isr_xC+0,W
224 subwf isr_xC+1,F 224 subwf isr_xC+1,F
225 movlw .0 225 movlw .0
226 subwfb isr_xC+2,F 226 subwfb isr_xC+2,F
227 bra temperature_extra_common 227 bra temperature_extra_common
228 228
229 temperature_extra_add: 229 temperature_extra_add:
230 ; Check for max. of 2.0°C 230 ; Check for max. of 2.0°C
231 movlw .21 231 movlw .21
232 cpfslt isr_xC+0 232 cpfslt isr_xC+0
233 clrf isr_xC+0 233 clrf isr_xC+0
234 ; Add 234 ; Add
235 movf isr_xC+0,W 235 movf isr_xC+0,W
236 addwf isr_xC+1,F 236 addwf isr_xC+1,F
237 movlw .0 237 movlw .0
238 addwfc isr_xC+2,F 238 addwfc isr_xC+2,F
239 temperature_extra_common: 239 temperature_extra_common:
240 240
241 movf isr_xC+1,W 241 movf isr_xC+1,W
242 addwf temperature_avg+0,F 242 addwf temperature_avg+0,F
243 movf isr_xC+2,W 243 movf isr_xC+2,W
244 addwfc temperature_avg+1,F 244 addwfc temperature_avg+1,F
245 245
246 return ; Done. 246 return ; Done.
247 247
248 ;============================================================================= 248 ;=============================================================================
249 global get_pressure_start 249 global get_pressure_start
250 get_pressure_start: 250 get_pressure_start:
251 rcall reset_MS5541 251 rcall reset_MS5541
256 rcall send_data_MS5541 256 rcall send_data_MS5541
257 return 257 return
258 258
259 global get_pressure_value 259 global get_pressure_value
260 get_pressure_value: 260 get_pressure_value:
261 btfsc MS5541_miso ; Conversion done? 261 btfsc MS5541_miso ; Conversion done?
262 return ; No, Return 262 return ; No, Return
263 rcall get_2bytes_MS5541 263 rcall get_2bytes_MS5541
264 movff dMSB,D1+1 264 movff dMSB,D1+1
265 movff dLSB,D1+0 265 movff dLSB,D1+0
266 return 266 return
267 267
272 movlw b'10010000' ;+3*high as start and 1+low as stop! 272 movlw b'10010000' ;+3*high as start and 1+low as stop!
273 bra get_pressure_start2 ; continue in "get_pressure" 273 bra get_pressure_start2 ; continue in "get_pressure"
274 274
275 global get_temperature_value 275 global get_temperature_value
276 get_temperature_value: 276 get_temperature_value:
277 btfsc MS5541_miso ; Conversion done? 277 btfsc MS5541_miso ; Conversion done?
278 return ; No, Return 278 return ; No, Return
279 rcall get_2bytes_MS5541 279 rcall get_2bytes_MS5541
280 movff dMSB,D2+1 280 movff dMSB,D2+1
281 movff dLSB,D2+0 281 movff dLSB,D2+0
282 return 282 return
283 283
284 ;============================================================================= 284 ;=============================================================================
285 global get_calibration_data 285 global get_calibration_data
286 get_calibration_data: 286 get_calibration_data:
287 banksel common 287 banksel common
288 bsf no_sensor_int ; disable sensor interrupts 288 bsf no_sensor_int ; disable sensor interrupts
289 banksel isr_backup ; Back to Bank0 ISR data 289 banksel isr_backup ; Back to Bank0 ISR data
290 290
291 rcall reset_MS5541 291 rcall reset_MS5541
292 movlw b'01010100' ;+3*high as start and 1+low as stop! 292 movlw b'01010100' ;+3*high as start and 1+low as stop!
293 movwf isr1_temp 293 movwf isr1_temp
294 movlw d'13' 294 movlw d'13'
295 rcall send_data_MS5541 295 rcall send_data_MS5541
296 rcall get_2bytes_MS5541 296 rcall get_2bytes_MS5541
297 movff dMSB,ir_s8_buffer+1 297 movff dMSB,ir_s8_buffer+1
298 movff dLSB,ir_s8_buffer+0 298 movff dLSB,ir_s8_buffer+0
299 299
300 movlw b'01011000' ;+3*high as start and 1+low as stop! 300 movlw b'01011000' ;+3*high as start and 1+low as stop!
301 movwf isr1_temp 301 movwf isr1_temp
302 movlw d'13' 302 movlw d'13'
303 rcall send_data_MS5541 303 rcall send_data_MS5541
304 rcall get_2bytes_MS5541 304 rcall get_2bytes_MS5541
305 movff dMSB,ir_s8_buffer+3 305 movff dMSB,ir_s8_buffer+3
306 movff dLSB,ir_s8_buffer+2 306 movff dLSB,ir_s8_buffer+2
307 307
308 movlw b'01100100' ;+3*high as start and 1+low as stop! 308 movlw b'01100100' ;+3*high as start and 1+low as stop!
309 movwf isr1_temp 309 movwf isr1_temp
310 movlw d'13' 310 movlw d'13'
311 rcall send_data_MS5541 311 rcall send_data_MS5541
312 rcall get_2bytes_MS5541 312 rcall get_2bytes_MS5541
313 movff dMSB,ir_s8_buffer+5 313 movff dMSB,ir_s8_buffer+5
314 movff dLSB,ir_s8_buffer+4 314 movff dLSB,ir_s8_buffer+4
315 315
316 movlw b'01101000' ;+3*high as start and 1+low as stop! 316 movlw b'01101000' ;+3*high as start and 1+low as stop!
317 movwf isr1_temp 317 movwf isr1_temp
318 movlw d'13' 318 movlw d'13'
319 rcall send_data_MS5541 319 rcall send_data_MS5541
320 rcall get_2bytes_MS5541 320 rcall get_2bytes_MS5541
321 movff dMSB,ir_s8_buffer+7 321 movff dMSB,ir_s8_buffer+7
403 clrf C3+1 403 clrf C3+1
404 btfsc ir_s8_buffer+5,7 404 btfsc ir_s8_buffer+5,7
405 bsf C3+1,1 405 bsf C3+1,1
406 btfsc ir_s8_buffer+5,6 406 btfsc ir_s8_buffer+5,6
407 bsf C3+1,0 407 bsf C3+1,0
408 408
409 ; calculate C4 (16Bit) 409 ; calculate C4 (16Bit)
410 movff ir_s8_buffer+7,C4+0 410 movff ir_s8_buffer+7,C4+0
411 bsf STATUS,C 411 bsf STATUS,C
412 btfss ir_s8_buffer+6,7 412 btfss ir_s8_buffer+6,7
413 bcf STATUS,C 413 bcf STATUS,C
415 clrf C4+1 415 clrf C4+1
416 btfsc ir_s8_buffer+7,7 416 btfsc ir_s8_buffer+7,7
417 bsf C4+1,0 417 bsf C4+1,0
418 418
419 ; C4=C4-250 419 ; C4=C4-250
420 movlw LOW(-.250) ; C4 - 250 --> C4 420 movlw LOW(-.250) ; C4 - 250 --> C4
421 addwf C4+0,W 421 addwf C4+0,W
422 movwf C4+0 422 movwf C4+0
423 movlw -1 ; HIGH(- .250) is not understood... 423 movlw -1 ; HIGH(- .250) is not understood...
424 addwfc C4+1,W 424 addwfc C4+1,W
425 movwf C4+1 425 movwf C4+1
426 426
427 ; calculate C5 (16Bit) 427 ; calculate C5 (16Bit)
428 movff ir_s8_buffer+4,C5+0 428 movff ir_s8_buffer+4,C5+0
429 bcf C5+0,6 429 bcf C5+0,6
430 btfsc ir_s8_buffer+2,0 430 btfsc ir_s8_buffer+2,0
431 bsf C5+0,6 431 bsf C5+0,6
432 bcf C5+0,7 432 bcf C5+0,7
440 btfsc ir_s8_buffer+2,4 440 btfsc ir_s8_buffer+2,4
441 bsf C5+1,2 441 bsf C5+1,2
442 btfsc ir_s8_buffer+2,5 442 btfsc ir_s8_buffer+2,5
443 bsf C5+1,3 443 bsf C5+1,3
444 444
445 ; calculate C5 = UT1 445 ; calculate C5 = UT1
446 ; C5 = 8*C5 + 10000 (u16 range 10.000 .. +42.760) 446 ; C5 = 8*C5 + 10000 (u16 range 10.000 .. +42.760)
447 clrf isr_xA+1 447 clrf isr_xA+1
448 movlw d'8' 448 movlw d'8'
449 movwf isr_xA+0 449 movwf isr_xA+0
450 movff C5+0,isr_xB+0 450 movff C5+0,isr_xB+0
451 movff C5+1,isr_xB+1 451 movff C5+1,isr_xB+1
452 call isr_unsigned_mult16x16 ;isr_xA*isr_xB=isr_xC 452 call isr_unsigned_mult16x16 ;isr_xA*isr_xB=isr_xC
453 movff isr_xC+0,C5+0 453 movff isr_xC+0,C5+0
454 movff isr_xC+1,C5+1 454 movff isr_xC+1,C5+1
455 movlw LOW d'10000' 455 movlw LOW d'10000'
456 addwf C5+0,F 456 addwf C5+0,F
457 movlw HIGH d'10000' 457 movlw HIGH d'10000'
458 addwfc C5+1,F ; = 8*C5 + 10000 458 addwfc C5+1,F ; = 8*C5 + 10000
459 459
460 ; calculate C6 (16Bit) 460 ; calculate C6 (16Bit)
461 clrf C6+1 461 clrf C6+1
462 movff ir_s8_buffer+6,C6+0 462 movff ir_s8_buffer+6,C6+0
463 bcf C6+0,7 463 bcf C6+0,7
464 464
465 banksel common 465 banksel common
466 bcf no_sensor_int ; enable sensor interrupts 466 bcf no_sensor_int ; enable sensor interrupts
467 bcf pressure_refresh ; Clear flag 467 bcf pressure_refresh ; Clear flag
468 banksel isr_backup ; Back to Bank0 ISR data 468 banksel isr_backup ; Back to Bank0 ISR data
469 469
470 clrf sensor_state_counter ; Then reset State counter 470 clrf sensor_state_counter ; Then reset State counter
471 471
472 return 472 return
473 473
474 ;============================================================================= 474 ;=============================================================================
475 reset_MS5541_one: 475 reset_MS5541_one:
476 bsf MS5541_mosi 476 bsf MS5541_mosi
477 bra send_clk_pulse ; Send one high-low sequence on MS5541_clk -> and return 477 bra send_clk_pulse ; Send one high-low sequence on MS5541_clk -> and return
478 478
479 reset_MS5541_zero: 479 reset_MS5541_zero:
480 bcf MS5541_mosi 480 bcf MS5541_mosi
481 bra send_clk_pulse ; Send one high-low sequence on MS5541_clk -> and return 481 bra send_clk_pulse ; Send one high-low sequence on MS5541_clk -> and return
482 482
483 reset_MS5541: 483 reset_MS5541:
484 rcall reset_MS5541_one ;0 484 rcall reset_MS5541_one ; 0
485 rcall reset_MS5541_zero 485 rcall reset_MS5541_zero
486 rcall reset_MS5541_one 486 rcall reset_MS5541_one
487 rcall reset_MS5541_zero 487 rcall reset_MS5541_zero
488 rcall reset_MS5541_one 488 rcall reset_MS5541_one
489 rcall reset_MS5541_zero 489 rcall reset_MS5541_zero
490 rcall reset_MS5541_one 490 rcall reset_MS5541_one
491 rcall reset_MS5541_zero 491 rcall reset_MS5541_zero
492 rcall reset_MS5541_one 492 rcall reset_MS5541_one
493 rcall reset_MS5541_zero 493 rcall reset_MS5541_zero
494 rcall reset_MS5541_one 494 rcall reset_MS5541_one
495 rcall reset_MS5541_zero 495 rcall reset_MS5541_zero
496 rcall reset_MS5541_one 496 rcall reset_MS5541_one
497 rcall reset_MS5541_zero 497 rcall reset_MS5541_zero
498 rcall reset_MS5541_one 498 rcall reset_MS5541_one
499 rcall reset_MS5541_zero ;15 499 rcall reset_MS5541_zero ; 15
500 rcall reset_MS5541_zero 500 rcall reset_MS5541_zero
501 rcall reset_MS5541_zero 501 rcall reset_MS5541_zero
502 rcall reset_MS5541_zero 502 rcall reset_MS5541_zero
503 rcall reset_MS5541_zero 503 rcall reset_MS5541_zero
504 rcall reset_MS5541_zero ;20 504 rcall reset_MS5541_zero ; 20
505 return 505 return
506 506
507 get_2bytes_MS5541: 507 get_2bytes_MS5541:
508 movlw d'8' 508 movlw d'8'
509 movwf clock_count 509 movwf clock_count
512 512
513 movlw d'8' 513 movlw d'8'
514 movwf clock_count 514 movwf clock_count
515 rcall recieve_loop 515 rcall recieve_loop
516 movff isr1_temp,dLSB 516 movff isr1_temp,dLSB
517 bra send_clk_pulse ; Send one high-low sequence on MS5541_clk -> and return 517 bra send_clk_pulse ; Send one high-low sequence on MS5541_clk -> and return
518 ;return 518 ;return
519 519
520 recieve_loop: 520 recieve_loop:
521 rcall send_clk_pulse ; Send one high-low sequence on MS5541_clk 521 rcall send_clk_pulse ; Send one high-low sequence on MS5541_clk
522 btfss MS5541_miso ;MSB first 522 btfss MS5541_miso ;MSB first
523 bcf STATUS,C 523 bcf STATUS,C
524 btfsc MS5541_miso ;MSB first 524 btfsc MS5541_miso ;MSB first
525 bsf STATUS,C 525 bsf STATUS,C
526 rlcf isr1_temp,F 526 rlcf isr1_temp,F
539 bcf MS5541_clk 539 bcf MS5541_clk
540 nop 540 nop
541 nop 541 nop
542 nop 542 nop
543 nop 543 nop
544 return 544 return
545 545
546 send_data_MS5541: 546 send_data_MS5541:
547 movwf clock_count ; From WREG 547 movwf clock_count ; From WREG
548 ; send three startbits first 548 ; send three startbits first
549 bcf MS5541_clk 549 bcf MS5541_clk
550 nop 550 nop
551 nop 551 nop
552 bsf MS5541_mosi 552 bsf MS5541_mosi
553 movlw d'3' 553 movlw d'3'
554 subwf clock_count,F ; total bit counter 554 subwf clock_count,F ; total bit counter
555 rcall send_clk_pulse ; Send one high-low sequence on MS5541_clk 555 rcall send_clk_pulse ; Send one high-low sequence on MS5541_clk
556 rcall send_clk_pulse ; Send one high-low sequence on MS5541_clk 556 rcall send_clk_pulse ; Send one high-low sequence on MS5541_clk
557 rcall send_clk_pulse ; Send one high-low sequence on MS5541_clk 557 rcall send_clk_pulse ; Send one high-low sequence on MS5541_clk
558 ; now send 8 bytes from isr_temp1 and fill-up with zeros 558 ; now send 8 bytes from isr_temp1 and fill-up with zeros
559 send_data_MS5541_2: 559 send_data_MS5541_2:
560 bcf MS5541_clk 560 bcf MS5541_clk
561 nop 561 nop
562 nop 562 nop
563 563
564 btfss isr1_temp,7 ;MSB first 564 btfss isr1_temp,7 ; MSB first
565 bcf MS5541_mosi 565 bcf MS5541_mosi
566 btfsc isr1_temp,7 ;MSB first 566 btfsc isr1_temp,7 ; MSB first
567 bsf MS5541_mosi 567 bsf MS5541_mosi
568 568
569 bsf MS5541_clk 569 bsf MS5541_clk
570 570
571 bcf STATUS,C 571 bcf STATUS,C
581 decfsz clock_count,F 581 decfsz clock_count,F
582 bra send_data_MS5541_2 582 bra send_data_MS5541_2
583 bcf MS5541_clk 583 bcf MS5541_clk
584 return 584 return
585 585
586 END 586 END