Mercurial > public > mk2
comparison code_part1/OSTC_code_asm_part1/ms5535.asm @ 0:96a35aeda5f2
Initial setup
author | heinrichsweikamp |
---|---|
date | Tue, 12 Jan 2010 15:05:59 +0100 |
parents | |
children | 2b5c52ae3923 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:96a35aeda5f2 |
---|---|
1 ; OSTC - diving computer code | |
2 ; Copyright (C) 2008 HeinrichsWeikamp GbR | |
3 | |
4 ; This program is free software: you can redistribute it and/or modify | |
5 ; it under the terms of the GNU General Public License as published by | |
6 ; the Free Software Foundation, either version 3 of the License, or | |
7 ; (at your option) any later version. | |
8 | |
9 ; This program is distributed in the hope that it will be useful, | |
10 ; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 ; GNU General Public License for more details. | |
13 | |
14 ; You should have received a copy of the GNU General Public License | |
15 ; along with this program. If not, see <http://www.gnu.org/licenses/>. | |
16 | |
17 | |
18 ; routines for Intersema MS5535A, MS5541B and MS5541C | |
19 ; written by: Matthias Heinrichs, info@heinrichsweikamp.com | |
20 ; written: 9/26/05 | |
21 ; last updated: 08/08/31 | |
22 ; known bugs: | |
23 ; ToDo: | |
24 | |
25 ; with second order temperature compensation | |
26 | |
27 calculate_compensation: | |
28 ; calculate xdT | |
29 clrf isr_xA+1 | |
30 movlw d'8' | |
31 movwf isr_xA+0 | |
32 movff C5+0,isr_xB+0 | |
33 movff C5+1,isr_xB+1 | |
34 call isr_mult16x16 ;isr_xA*isr_xB=isr_xC | |
35 movlw LOW d'10000' | |
36 addwf isr_xC+0, f | |
37 movlw HIGH d'10000' | |
38 addwfc isr_xC+1, f ;isr_xC= 8*C5 + 10000 | |
39 movff D2+0,isr_sub_a+0 | |
40 movff D2+1,isr_sub_a+1 | |
41 movff isr_xC+0,isr_sub_b+0 | |
42 movff isr_xC+1,isr_sub_b+1 | |
43 call isr_sub16 ; isr_sub_c = isr_sub_a - isr_sub_b | |
44 movff isr_sub_c+0,xdT+0 | |
45 movff isr_sub_c+1,xdT+1 | |
46 | |
47 ; Second order temperature calculation | |
48 btfsc neg_flag_isr | |
49 bra dTzero_yes | |
50 ; dT>0 | |
51 bcf neg_flag_xdT | |
52 movff xdT+0,isr_xA+0 | |
53 movff xdT+1,isr_xA+1 | |
54 movff xdT+0,isr_xB+0 | |
55 movff xdT+1,isr_xB+1 | |
56 call isr_mult16x16 ;isr_xA*isr_xB=isr_xC | |
57 movlw d'17' ; 2^17=(128*128)*8 | |
58 movwf isr_divB | |
59 call isr_div32 ; isr_xC=isr_xC(32Bit)/2^isr_divB (isr_divB: 8Bit only!) | |
60 movff xdT+0,isr_sub_a+0 | |
61 movff xdT+1,isr_sub_a+1 | |
62 movff isr_xC+0,isr_sub_b+0 | |
63 movff isr_xC+1,isr_sub_b+1 | |
64 call isr_sub16 ; isr_sub_c = isr_sub_a - isr_sub_b | |
65 movff isr_sub_c+0,xdT2+0 | |
66 movff isr_sub_c+1,xdT2+1 | |
67 bra OFF_calc ; Done | |
68 | |
69 dTzero_yes: | |
70 ; dT<0 | |
71 bsf neg_flag_xdT | |
72 movff xdT+0,isr_xA+0 | |
73 movff xdT+1,isr_xA+1 | |
74 movff xdT+0,isr_xB+0 | |
75 movff xdT+1,isr_xB+1 | |
76 call isr_mult16x16 ;isr_xA*isr_xB=isr_xC | |
77 movlw d'15' ; 2^15=(128*128)*2 | |
78 movwf isr_divB | |
79 call isr_div32 ; isr_xC=isr_xC(32Bit)/2^isr_divB (isr_divB: 8Bit only!) | |
80 | |
81 movf xdT+0,W | |
82 addwf isr_xC+0,F | |
83 movf xdT+1,W | |
84 addwfc isr_xC+1,F | |
85 movff isr_xC+0,xdT2+0 | |
86 movff isr_xC+1,xdT2+1 | |
87 | |
88 OFF_calc: | |
89 ; calculate OFF | |
90 movff C4+0,isr_sub_a | |
91 movff C4+1,isr_sub_a+1 | |
92 movlw d'250' | |
93 movwf isr_sub_b | |
94 clrf isr_sub_b+1 | |
95 call isr_sub16 ; (C4-250) - Sets neg_flag_isr! | |
96 movff isr_sub_c,isr_xA | |
97 movff isr_sub_c+1,isr_xA+1 | |
98 movff xdT+0,isr_xB | |
99 movff xdT+0+1,isr_xB+1 | |
100 call isr_mult16x16 ; (C4-250)*dT | |
101 movff isr_xC+0,isr_divA | |
102 movff isr_xC+1,isr_divA+1 | |
103 movlw d'12' | |
104 movwf isr_divB | |
105 call isr_div16 ; [(C4-250)*dT]/2^12 | |
106 movff isr_divA+0,isr_xC+0 | |
107 movff isr_divA+1,isr_xC+1 ; isr_xC= {[(C4-250)*dT]/2^12} | |
108 btfss neg_flag_isr ; neg_flag_isr=1? | |
109 bra OFF_calc2 ; Yes, do C2 - isr_xC | |
110 ; no, so do C2 + isr_xC | |
111 movf C2+0,W | |
112 addwf isr_xC+0, f | |
113 movf C2+1,W | |
114 addwfc isr_xC+1, f ; isr_xC= C2 + {[(C4-250)*dT/2^12]} | |
115 OFF_calc3: | |
116 movlw LOW d'10000' | |
117 addwf isr_xC+0, f | |
118 movlw HIGH d'10000' | |
119 addwfc isr_xC+1, f ; isr_xC=[(C4-250)*dT/2^12] + 10000 | |
120 movff isr_xC+0,OFF+0 | |
121 movff isr_xC+1,OFF+1 | |
122 bra calculate_SENS ; Done with OFF | |
123 | |
124 OFF_calc2: | |
125 movff C2+0,isr_sub_a+0 | |
126 movff C2+1,isr_sub_a+1 | |
127 movff isr_xC+0,isr_sub_b+0 | |
128 movff isr_xC+1,isr_sub_b+1 | |
129 call isr_sub16 ; isr_sub_c = isr_sub_a - isr_sub_b | |
130 ; isr_xC= C2 - {[(C4-250)*dT/2^12]} | |
131 movff isr_sub_c+0,isr_xC+0 | |
132 movff isr_sub_c+1,isr_xC+1 ; Done with OFF | |
133 bra OFF_calc3 | |
134 | |
135 calculate_SENS: | |
136 movff C3+0, C3_temp+0 | |
137 movff C3+1, C3_temp+1 | |
138 movlw d'200' | |
139 addwf C3_temp+0, f | |
140 movlw d'0' | |
141 addwfc C3_temp+1, f ; C3 no longer valid! | |
142 movff C3_temp+0, isr_xA | |
143 movff C3_temp+1, isr_xA+1 | |
144 movff xdT+0, isr_xB | |
145 movff xdT+1, isr_xB+1 | |
146 call isr_mult16x16 | |
147 movff isr_xC+0,isr_divA | |
148 movff isr_xC+1,isr_divA+1 | |
149 movlw d'13' | |
150 movwf isr_divB | |
151 call isr_div16 | |
152 movff isr_divA,SENS+0 | |
153 movff isr_divA+1,SENS+1 | |
154 movff C1+0,isr_divA | |
155 movff C1+1,isr_divA+1 | |
156 movlw d'1' | |
157 movwf isr_divB | |
158 call isr_div16 | |
159 movf isr_divA,W | |
160 addwf SENS+0, f | |
161 movf isr_divA+1,W | |
162 addwfc SENS+1, f | |
163 movlw d'184' | |
164 addwf SENS+0, f | |
165 movlw d'11' | |
166 addwfc SENS+1, f | |
167 | |
168 ; calculate amb_pressure | |
169 movff D1+0,isr_sub_a | |
170 movff D1+1,isr_sub_a+1 | |
171 movff OFF+0,isr_sub_b | |
172 movff OFF+1,isr_sub_b+1 | |
173 call isr_sub16 | |
174 movff isr_sub_c,isr_xA | |
175 movff isr_sub_c+1,isr_xA+1 | |
176 movff SENS+0,isr_xB | |
177 movff SENS+1,isr_xB+1 | |
178 call isr_mult16x16 | |
179 movlw d'12' | |
180 movwf isr_divB | |
181 call isr_div32 | |
182 btfsc neg_flag_isr ; invert isr_xC+0 and isr_xC+1 | |
183 call isr_invert_xC | |
184 movlw LOW d'1000' | |
185 addwf isr_xC+0, f | |
186 movlw HIGH d'1000' | |
187 addwfc isr_xC+1, f | |
188 movff isr_xC+0,amb_pressure+0 | |
189 movff isr_xC+1,amb_pressure+1 | |
190 | |
191 btfss simulatormode_active ; are we in simulator mode? | |
192 bra calc_pressure_done ; no | |
193 | |
194 movff sim_pressure+0,amb_pressure+0 ; override readings with simulator values | |
195 movff sim_pressure+1,amb_pressure+1 | |
196 | |
197 calc_pressure_done: | |
198 | |
199 ; calculate temp | |
200 movff C6+0, C3_temp+0 | |
201 movff C6+1, C3_temp+1 | |
202 movlw d'100' | |
203 addwf C3_temp+0, f | |
204 movlw d'0' | |
205 addwfc C3_temp+1, f | |
206 movff C3_temp+0,isr_xA+0 | |
207 movff C3_temp+1,isr_xA+1 | |
208 movff xdT2+0,isr_xB+0 | |
209 movff xdT2+1,isr_xB+1 | |
210 call isr_mult16x16 | |
211 movlw d'11' | |
212 movwf isr_divB | |
213 call isr_div32 | |
214 bcf neg_temp ; Temperatur positive | |
215 | |
216 btfsc neg_flag_xdT ; was xdT negative? | |
217 bra neg_sub_temp ; yes, 200 - dT*(.... | |
218 ; No, 200 + dT*(.... | |
219 ; movf temperature_correction,W | |
220 ; addlw d'200' | |
221 ; btfsc STATUS,C | |
222 ; incf isr_xC+1,F | |
223 | |
224 movlw d'200' | |
225 addwf isr_xC+0, f | |
226 movlw d'0' | |
227 addwfc isr_xC+1, f | |
228 movff isr_xC+0,temperature+0 | |
229 movff isr_xC+1,temperature+1 | |
230 return ; done | |
231 | |
232 neg_sub_temp: ; 200 - dT*(.... | |
233 ; movf temperature_correction,W | |
234 ; addlw d'200' | |
235 ; btfsc STATUS,C | |
236 ; decf isr_xC+1,F | |
237 | |
238 movlw d'200' | |
239 neg_sub_temp3: | |
240 movwf isr_sub_a+0 | |
241 clrf isr_sub_a+1 | |
242 movff isr_xC+0, isr_sub_b+0 | |
243 movff isr_xC+1, isr_sub_b+1 | |
244 call isr_sub16 ; isr_sub_c = isr_sub_a - isr_sub_b | |
245 btfsc neg_flag_isr ; below zero? | |
246 bsf neg_temp ; temperature negative! | |
247 | |
248 movff isr_sub_c+0,temperature+0 | |
249 movff isr_sub_c+1,temperature+1 | |
250 return ; Fertig mit allem | |
251 | |
252 | |
253 get_pressure_start: | |
254 rcall reset_MS5535A | |
255 movlw b'10100000' ;+3*high as start and 1+low as stop! | |
256 get_pressure_start2: | |
257 movwf isr1_temp | |
258 movlw d'12' | |
259 movwf clock_count | |
260 rcall send_data_MS55535A | |
261 return | |
262 | |
263 get_pressure_value: | |
264 rcall get_2bytes_MS5535A | |
265 movff dMSB,D1+1 | |
266 movff dLSB,D1+0 | |
267 return | |
268 | |
269 get_temperature_start: | |
270 rcall reset_MS5535A | |
271 movlw b'10010000' ;+3*high as start and 1+low as stop! | |
272 bra get_pressure_start2 ; continue in "get_pressure" | |
273 | |
274 get_temperature_value: | |
275 rcall get_2bytes_MS5535A | |
276 movff dMSB,D2+1 | |
277 movff dLSB,D2+0 | |
278 return | |
279 | |
280 get_calibration_data: | |
281 ; read addional temperature correction from internal EEPROM 0x100 | |
282 bsf no_sensor_int ; No sensor interupt! | |
283 clrf temperature_correction ; clear compensation value | |
284 movlw LOW 0x100 | |
285 movwf EEADR | |
286 movlw HIGH 0x100 | |
287 movwf EEADRH | |
288 call read_eeprom | |
289 clrf EEADRH ; Only 256Bytes used in normal program | |
290 movlw d'200' ; limit value | |
291 cpfsgt EEDATA ; EEDATA>200? | |
292 movff EEDATA, temperature_correction ; No, Store for compensation | |
293 | |
294 rcall reset_MS5535A | |
295 movlw d'13' | |
296 movwf clock_count | |
297 movlw b'01010100' ;+3*high as start and 1+low as stop! | |
298 movwf isr1_temp | |
299 rcall send_data_MS55535A | |
300 rcall get_2bytes_MS5535A | |
301 movff dMSB,W1+1 | |
302 movff dLSB,W1+0 | |
303 | |
304 movlw d'13' | |
305 movwf clock_count | |
306 movlw b'01011000' ;+3*high as start and 1+low as stop! | |
307 movwf isr1_temp | |
308 rcall send_data_MS55535A | |
309 rcall get_2bytes_MS5535A | |
310 movff dMSB,W2+1 | |
311 movff dLSB,W2+0 | |
312 | |
313 movlw d'13' | |
314 movwf clock_count | |
315 movlw b'01100100' ;+3*high as start and 1+low as stop! | |
316 movwf isr1_temp | |
317 rcall send_data_MS55535A | |
318 rcall get_2bytes_MS5535A | |
319 movff dMSB,W3+1 | |
320 movff dLSB,W3+0 | |
321 | |
322 movlw d'13' | |
323 movwf clock_count | |
324 movlw b'01101000' ;+3*high as start and 1+low as stop! | |
325 movwf isr1_temp | |
326 rcall send_data_MS55535A | |
327 rcall get_2bytes_MS5535A | |
328 movff dMSB,W4+1 | |
329 movff dLSB,W4+0 | |
330 | |
331 ; calculate C1 (16Bit) | |
332 movff W1+1, C1+1 | |
333 bcf STATUS,C | |
334 rrcf C1+1 | |
335 bcf STATUS,C | |
336 rrcf C1+1 | |
337 bcf STATUS,C | |
338 rrcf C1+1 | |
339 movff W1+0, C1+0 | |
340 bsf STATUS,C | |
341 btfss W1+1,0 | |
342 bcf STATUS,C | |
343 rrcf C1+0 | |
344 bsf STATUS,C | |
345 btfss W1+1,1 | |
346 bcf STATUS,C | |
347 rrcf C1+0 | |
348 bsf STATUS,C | |
349 btfss W1+1,2 | |
350 bcf STATUS,C | |
351 rrcf C1+0 | |
352 | |
353 ; calculate C2 (16Bit) | |
354 movff W2+0, C2+0 | |
355 bsf STATUS,C | |
356 btfss W2+1,0 | |
357 bcf STATUS,C | |
358 rrcf C2+0 | |
359 bsf STATUS,C | |
360 btfss W2+1,1 | |
361 bcf STATUS,C | |
362 rrcf C2+0 | |
363 bsf STATUS,C | |
364 btfss W2+1,2 | |
365 bcf STATUS,C | |
366 rrcf C2+0 | |
367 bsf STATUS,C | |
368 btfss W2+1,3 | |
369 bcf STATUS,C | |
370 rrcf C2+0 | |
371 bsf STATUS,C | |
372 btfss W2+1,4 | |
373 bcf STATUS,C | |
374 rrcf C2+0 | |
375 bsf STATUS,C | |
376 btfss W2+1,5 | |
377 bcf STATUS,C | |
378 rrcf C2+0 | |
379 | |
380 movff W2+1, C2+1 | |
381 bsf STATUS,C | |
382 btfss W1+0,0 | |
383 bcf STATUS,C | |
384 rrcf C2+1 | |
385 bsf STATUS,C | |
386 btfss W1+0,1 | |
387 bcf STATUS,C | |
388 rrcf C2+1 | |
389 bsf STATUS,C | |
390 btfss W1+0,2 | |
391 bcf STATUS,C | |
392 rrcf C2+1 | |
393 bcf STATUS,C | |
394 rrcf C2+1 | |
395 bcf STATUS,C | |
396 rrcf C2+1 | |
397 bcf STATUS,C | |
398 rrcf C2+1 | |
399 | |
400 ; calculate C3 (16Bit) | |
401 movff W3+1,C3+0 | |
402 bsf STATUS,C | |
403 btfss W3+0,7 | |
404 bcf STATUS,C | |
405 rlcf C3+0 | |
406 bsf STATUS,C | |
407 btfss W3+0,6 | |
408 bcf STATUS,C | |
409 rlcf C3+0 | |
410 clrf C3+1 | |
411 btfsc W3+1,7 | |
412 bsf C3+1,1 | |
413 btfsc W3+1,6 | |
414 bsf C3+1,0 | |
415 | |
416 ; calculate C4 (16Bit) | |
417 movff W4+1,C4+0 | |
418 bsf STATUS,C | |
419 btfss W4+0,7 | |
420 bcf STATUS,C | |
421 rlcf C4+0 | |
422 clrf C4+1 | |
423 btfsc W4+1,7 | |
424 bsf C4+1,0 | |
425 | |
426 ; calculate C5 (16Bit) | |
427 movff W3+0,C5+0 | |
428 bcf C5+0,6 | |
429 btfsc W2+0,0 | |
430 bsf C5+0,6 | |
431 bcf C5+0,7 | |
432 btfsc W2+0,1 | |
433 bsf C5+0,7 | |
434 clrf C5+1 | |
435 btfsc W2+0,2 | |
436 bsf C5+1,0 | |
437 btfsc W2+0,3 | |
438 bsf C5+1,1 | |
439 btfsc W2+0,4 | |
440 bsf C5+1,2 | |
441 btfsc W2+0,5 | |
442 bsf C5+1,3 | |
443 | |
444 ; calculate C6 (16Bit) | |
445 clrf C6+1 | |
446 movff W4+0,C6+0 | |
447 bcf C6+0,7 | |
448 | |
449 bcf no_sensor_int ; enable sensor interrupts | |
450 return | |
451 | |
452 reset_MS5535A_one: | |
453 bsf sensor_SDO | |
454 nop | |
455 bsf sensor_CLK | |
456 nop | |
457 nop | |
458 nop | |
459 nop | |
460 nop | |
461 nop | |
462 bcf sensor_CLK | |
463 return | |
464 | |
465 reset_MS5535A_zero: | |
466 bcf sensor_SDO | |
467 nop | |
468 bsf sensor_CLK | |
469 nop | |
470 nop | |
471 nop | |
472 nop | |
473 nop | |
474 nop | |
475 bcf sensor_CLK | |
476 return | |
477 | |
478 reset_MS5535A: | |
479 rcall reset_MS5535A_one ;0 | |
480 rcall reset_MS5535A_zero | |
481 rcall reset_MS5535A_one | |
482 rcall reset_MS5535A_zero | |
483 rcall reset_MS5535A_one | |
484 rcall reset_MS5535A_zero | |
485 rcall reset_MS5535A_one | |
486 rcall reset_MS5535A_zero | |
487 rcall reset_MS5535A_one | |
488 rcall reset_MS5535A_zero | |
489 rcall reset_MS5535A_one | |
490 rcall reset_MS5535A_zero | |
491 rcall reset_MS5535A_one | |
492 rcall reset_MS5535A_zero | |
493 rcall reset_MS5535A_one | |
494 rcall reset_MS5535A_zero ;15 | |
495 rcall reset_MS5535A_zero | |
496 rcall reset_MS5535A_zero | |
497 rcall reset_MS5535A_zero | |
498 rcall reset_MS5535A_zero | |
499 rcall reset_MS5535A_zero ;20 | |
500 return | |
501 | |
502 get_2bytes_MS5535A: | |
503 movlw d'8' | |
504 movwf clock_count | |
505 rcall recieve_loop | |
506 movff isr1_temp,dMSB | |
507 | |
508 movlw d'8' | |
509 movwf clock_count | |
510 rcall recieve_loop | |
511 movff isr1_temp,dLSB | |
512 bsf sensor_CLK | |
513 nop | |
514 nop | |
515 nop | |
516 nop | |
517 nop | |
518 nop | |
519 bcf sensor_CLK | |
520 return | |
521 | |
522 recieve_loop: | |
523 bsf sensor_CLK | |
524 nop | |
525 nop | |
526 nop | |
527 nop | |
528 nop | |
529 nop | |
530 bcf sensor_CLK | |
531 btfss sensor_SDI ;MSB first | |
532 bcf STATUS,C | |
533 btfsc sensor_SDI ;MSB first | |
534 bsf STATUS,C | |
535 rlcf isr1_temp,F | |
536 decfsz clock_count,F | |
537 bra recieve_loop | |
538 return | |
539 | |
540 | |
541 send_data_MS55535A: | |
542 ; send three startbits first | |
543 bcf sensor_CLK | |
544 bsf sensor_SDO | |
545 movlw d'3' | |
546 subwf clock_count,F ; total bit counter | |
547 bsf sensor_CLK | |
548 nop | |
549 nop | |
550 nop | |
551 nop | |
552 nop | |
553 nop | |
554 bcf sensor_CLK | |
555 nop | |
556 nop | |
557 nop | |
558 nop | |
559 nop | |
560 nop | |
561 bsf sensor_CLK | |
562 nop | |
563 nop | |
564 nop | |
565 nop | |
566 nop | |
567 nop | |
568 bcf sensor_CLK | |
569 nop | |
570 nop | |
571 nop | |
572 nop | |
573 nop | |
574 nop | |
575 bsf sensor_CLK | |
576 nop | |
577 nop | |
578 nop | |
579 nop | |
580 nop | |
581 nop | |
582 bcf sensor_CLK | |
583 ; now send 8 bytes from isr_temp1 and fill-up with zeros | |
584 datenbits: | |
585 btfss isr1_temp,7 ;MSB first | |
586 bcf sensor_SDO | |
587 btfsc isr1_temp,7 ;MSB first | |
588 bsf sensor_SDO | |
589 bcf STATUS,C | |
590 rlcf isr1_temp | |
591 | |
592 bsf sensor_CLK | |
593 nop | |
594 nop | |
595 nop | |
596 nop | |
597 nop | |
598 nop | |
599 bcf sensor_CLK | |
600 | |
601 decfsz clock_count,F | |
602 bra datenbits | |
603 return |