Mercurial > public > mk2
annotate code_part1/OSTC_code_asm_part1/ms5535.asm @ 715:de413161f00c
256ms switch debounce timer
author | heinrichsweikamp |
---|---|
date | Tue, 21 May 2013 12:17:49 +0200 |
parents | b7f7184d800d |
children | c50296c3059e |
rev | line source |
---|---|
0 | 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 | |
161
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
19 ; history: |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
20 ; 2005-09-26: Written by Matthias Heinrichs, info@heinrichsweikamp.com |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
161
diff
changeset
|
21 ; 2008-08-21: MH last updated, with second order compensation. |
161
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
22 ; 2011-01-19: jDG Clean up using true signed arithmetics. |
341
2144f19fa1eb
BUGFIX protect against ISR changing pressure/temperature while reading it.
JeanDo
parents:
340
diff
changeset
|
23 ; 2011-05-19: jDG Avegaring temperature and amb_pressure in private variable, |
2144f19fa1eb
BUGFIX protect against ISR changing pressure/temperature while reading it.
JeanDo
parents:
340
diff
changeset
|
24 ; Use signed 16bit value for temperature (compat with avg !). |
2144f19fa1eb
BUGFIX protect against ISR changing pressure/temperature while reading it.
JeanDo
parents:
340
diff
changeset
|
25 ; |
0 | 26 ; known bugs: |
27 ; ToDo: | |
28 | |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
161
diff
changeset
|
29 ;============================================================================= |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
161
diff
changeset
|
30 ; Expose internal variables, to ease debug: |
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
161
diff
changeset
|
31 global D1, D2 |
289 | 32 global C1, C2, C3, C4, C5, C6 |
340
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
289
diff
changeset
|
33 global xdT, xdT2, OFF, SENS, amb_pressure_avg, temperature_avg |
0 | 34 |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
161
diff
changeset
|
35 ;============================================================================= |
0 | 36 calculate_compensation: |
704 | 37 ; xdT = D2 - C5 (s16 range -11.400 .. +12.350) |
38 movf C5+0,W ; Get Value to be subtracted | |
161
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
39 subwf D2+0,W ; Do the Low Byte |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
40 movwf xdT+0 |
704 | 41 movf C5+1,W ; Then the high byte. |
161
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
42 subwfb D2+1,W |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
43 movwf xdT+1 |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
44 |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
45 ; Second order temperature calculation |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
46 ; xdT/128 is in range -89..+96, hence signed 8bit. dT/128 = (2*dT)/256 |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
47 rlcf xdT+0,W ; put hit bit in carry. |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
48 rlcf xdT+1,W ; inject in high byte. |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
49 movwf isr_xA+0 ; and put result in low byte. |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
50 clrf isr_xA+1 |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
51 btfsc xdT+1,7 ; If dT < 0 |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
52 setf isr_xA+1 ; then signextend to -1 |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
53 movff isr_xA+0,isr_xB+0 ; copy A to B |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
54 movff isr_xA+1,isr_xB+1 |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
55 call isr_signed_mult16x16 ; dT*dT --> xC (32 bits) |
0 | 56 |
161
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
57 ; dT >= 0: divide by 8, ie. 3 shifts rights. |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
58 ; dT < 0: divide by 2, ie. 1 shifts rights. |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
59 movlw .3 |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
60 btfss xdT+1,7 ; Was dT negatif ? |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
61 movlw .1 |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
62 calc_loop_1: |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
63 bcf STATUS,C ;dT^2 is positiv, so injected zeros. |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
64 rrcf isr_xC+1,F |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
65 rrcf isr_xC+0,F |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
66 decfsz WREG |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
67 bra calc_loop_1 |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
68 |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
69 movf isr_xC+0,W ; dT2 = dT - (dT/128)*(dT/128)/(2 ...or... 8) |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
70 subwf xdT+0,W |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
71 movwf xdT2+0 |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
72 movf isr_xC+1,W |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
73 subwfb xdT+1,W |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
74 movwf xdT2+1 |
0 | 75 |
161
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
76 ; Calculate OFF = C2 + ((C4-250)*dT2)/2^12 + 10000 |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
77 ; (range +9.246 .. +18.887) |
704 | 78 movff C4+0,isr_xA+0 |
79 movff C4+1,isr_xA+1 | |
161
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
80 |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
81 movff xdT2+0,isr_xB+0 ; dT2 --> B |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
82 movff xdT2+1,isr_xB+1 |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
83 call isr_signed_mult16x16 |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
84 movlw .12-.8 ; A 12bit shift = 1 byte + 4 bits. |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
85 call isr_shift_C31 |
0 | 86 |
161
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
87 movlw LOW(.10000) ; Add 10000 |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
88 addwf isr_xC+1,F |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
89 movlw HIGH(.10000) |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
90 addwfc isr_xC+2,F |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
91 |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
92 movf C2+0,W ; Add C2, and save into OFF |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
93 addwf isr_xC+1,W |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
94 movwf OFF+0 |
0 | 95 movf C2+1,W |
161
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
96 addwfc isr_xC+2,W |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
97 movwf OFF+1 |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
98 |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
99 ; Calculate SENS = C1/2 + ((C3+200)*dT)/2^13 + 3000 |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
100 movlw LOW(.200) ; C3+200 --> A |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
101 addwf C3+0,W |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
102 movwf isr_xA+0 |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
103 movlw HIGH(.200) |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
104 addwfc C3+1,W |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
105 movwf isr_xA+1 |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
106 ; B still contains dT2 |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
107 call isr_signed_mult16x16 ; A*B --> C |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
108 movlw .13-.8 ; A 13bit shift = 1 byte + 5 bits. |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
109 call isr_shift_C31 |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
110 |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
111 bcf STATUS,C ; SENS = C1 / 2 |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
112 rrcf C1+1,W |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
113 movwf SENS+1 |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
114 rrcf C1+0,W |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
115 movwf SENS+0 |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
116 |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
117 movlw LOW(.3000) ; Add 3000 |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
118 addwf isr_xC+1,F |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
119 movlw HIGH(.3000) |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
120 addwfc isr_xC+2,F |
0 | 121 |
161
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
122 movf isr_xC+1,W ; And sum into SENS |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
123 addwf SENS+0,F |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
124 movf isr_xC+2,W |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
125 addwfc SENS+1,F |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
126 |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
127 ; calculate amb_pressure = (sens * (d1-off))/2^12 + 1000 |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
128 movf OFF+0,W ; d1-off --> a |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
129 subwf D1+0,W |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
130 movwf isr_xA+0 |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
131 movf OFF+1,W |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
132 subwfb D1+1,W |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
133 movwf isr_xA+1 |
0 | 134 |
161
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
135 movff SENS+0,isr_xB+0 ; sens --> b |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
136 movff SENS+1,isr_xB+1 |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
137 call isr_signed_mult16x16 |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
138 movlw .12-.8 ; a 12bit shift = 1 byte + 4 bits. |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
139 call isr_shift_C31 |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
140 |
340
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
289
diff
changeset
|
141 movlw LOW(.1000) ; add 1000 |
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
289
diff
changeset
|
142 addwf isr_xC+1,F |
161
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
143 movlw HIGH(.1000) |
340
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
289
diff
changeset
|
144 addwfc isr_xC+2,F |
0 | 145 |
146 btfss simulatormode_active ; are we in simulator mode? | |
340
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
289
diff
changeset
|
147 bra calc_compensation_2 ; no |
0 | 148 |
340
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
289
diff
changeset
|
149 movff sim_pressure+0,isr_xC+1 ; override readings with simulator values |
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
289
diff
changeset
|
150 movff sim_pressure+1,isr_xC+2 |
0 | 151 |
340
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
289
diff
changeset
|
152 calc_compensation_2: |
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
289
diff
changeset
|
153 movf isr_xC+1,W ; Then sum_up to pressure averaging buffer. |
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
289
diff
changeset
|
154 addwf amb_pressure_avg+0,F |
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
289
diff
changeset
|
155 movf isr_xC+2,W |
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
289
diff
changeset
|
156 addwfc amb_pressure_avg+1,F |
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
289
diff
changeset
|
157 |
161
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
158 ; calculate temp = 200 + dT*(C6+100)/2^11 |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
159 movlw LOW(.100) ; C6 + 100 --> A |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
160 addwf C6+0,W |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
161 movwf isr_xA+0 |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
162 movlw HIGH(.100) |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
163 addwfc C6+1,W |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
164 movwf isr_xA+1 |
0 | 165 |
161
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
166 movff xdT2+0,isr_xB+0 ; dT2 --> B |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
167 movff xdT2+1,isr_xB+1 |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
168 call isr_signed_mult16x16 ; A*B |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
169 movlw .11-.8 ; A 12bit shift = 1 byte + 3 bits. |
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
170 call isr_shift_C31 |
0 | 171 |
340
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
289
diff
changeset
|
172 movlw LOW(.200) ; Add 200 |
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
289
diff
changeset
|
173 addwf isr_xC+1,F |
161
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
174 movlw HIGH(.200) |
340
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
289
diff
changeset
|
175 addwfc isr_xC+2,F |
0 | 176 |
340
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
289
diff
changeset
|
177 movf isr_xC+1,W |
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
289
diff
changeset
|
178 addwf temperature_avg+0,F |
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
289
diff
changeset
|
179 movf isr_xC+2,W |
ecbbbd423e86
BUGFIX save negativ temperatures in logbook (bbbug #6)
JeanDo
parents:
289
diff
changeset
|
180 addwfc temperature_avg+1,F |
0 | 181 |
161
8d6aca08f66b
Use signed arithmetic for pressure/temperature compensation.
JeanDo
parents:
83
diff
changeset
|
182 return ; Fertig mit allem |
0 | 183 |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
161
diff
changeset
|
184 ;============================================================================= |
0 | 185 get_pressure_start: |
186 rcall reset_MS5535A | |
187 movlw b'10100000' ;+3*high as start and 1+low as stop! | |
188 get_pressure_start2: | |
189 movwf isr1_temp | |
190 movlw d'12' | |
191 movwf clock_count | |
192 rcall send_data_MS55535A | |
193 return | |
194 | |
195 get_pressure_value: | |
81
31fa973a70fd
Kludges to emulate inexisting devices when debugged with the MPLAB software SIMulator.
JeanDo
parents:
4
diff
changeset
|
196 #ifndef TESTING |
31fa973a70fd
Kludges to emulate inexisting devices when debugged with the MPLAB software SIMulator.
JeanDo
parents:
4
diff
changeset
|
197 ; Use register injection instead when in MPLab Sim emulation... |
0 | 198 rcall get_2bytes_MS5535A |
199 movff dMSB,D1+1 | |
200 movff dLSB,D1+0 | |
81
31fa973a70fd
Kludges to emulate inexisting devices when debugged with the MPLAB software SIMulator.
JeanDo
parents:
4
diff
changeset
|
201 #endif |
0 | 202 return |
203 | |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
161
diff
changeset
|
204 ;============================================================================= |
0 | 205 get_temperature_start: |
206 rcall reset_MS5535A | |
207 movlw b'10010000' ;+3*high as start and 1+low as stop! | |
208 bra get_pressure_start2 ; continue in "get_pressure" | |
209 | |
210 get_temperature_value: | |
81
31fa973a70fd
Kludges to emulate inexisting devices when debugged with the MPLAB software SIMulator.
JeanDo
parents:
4
diff
changeset
|
211 #ifndef TESTING |
31fa973a70fd
Kludges to emulate inexisting devices when debugged with the MPLAB software SIMulator.
JeanDo
parents:
4
diff
changeset
|
212 ; Use register injection instead... |
0 | 213 rcall get_2bytes_MS5535A |
214 movff dMSB,D2+1 | |
215 movff dLSB,D2+0 | |
81
31fa973a70fd
Kludges to emulate inexisting devices when debugged with the MPLAB software SIMulator.
JeanDo
parents:
4
diff
changeset
|
216 #endif |
0 | 217 return |
218 | |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
161
diff
changeset
|
219 ;============================================================================= |
0 | 220 get_calibration_data: |
714 | 221 banksel flag5 |
222 bsf no_sensor_int ; disable sensor interrupts | |
0 | 223 rcall reset_MS5535A |
224 movlw d'13' | |
225 movwf clock_count | |
226 movlw b'01010100' ;+3*high as start and 1+low as stop! | |
227 movwf isr1_temp | |
228 rcall send_data_MS55535A | |
229 rcall get_2bytes_MS5535A | |
289 | 230 |
231 #ifdef TESTING | |
232 movlw LOW(.18556) | |
233 movff WREG,W1+0 | |
234 movlw HIGH(.18556) | |
235 movff WREG,W1+1 | |
236 #else | |
0 | 237 movff dMSB,W1+1 |
238 movff dLSB,W1+0 | |
289 | 239 #endif |
0 | 240 |
241 movlw d'13' | |
242 movwf clock_count | |
243 movlw b'01011000' ;+3*high as start and 1+low as stop! | |
244 movwf isr1_temp | |
245 rcall send_data_MS55535A | |
246 rcall get_2bytes_MS5535A | |
289 | 247 #ifdef TESTING |
248 movlw LOW(.49183) | |
249 movff WREG,W2+0 | |
250 movlw HIGH(.49183) | |
251 movff WREG,W2+1 | |
252 #else | |
0 | 253 movff dMSB,W2+1 |
254 movff dLSB,W2+0 | |
289 | 255 #endif |
0 | 256 |
257 movlw d'13' | |
258 movwf clock_count | |
259 movlw b'01100100' ;+3*high as start and 1+low as stop! | |
260 movwf isr1_temp | |
261 rcall send_data_MS55535A | |
262 rcall get_2bytes_MS5535A | |
289 | 263 #ifdef TESTING |
264 movlw LOW(.22354) | |
265 movff WREG,W3+0 | |
266 movlw HIGH(.22354) | |
267 movff WREG,W3+1 | |
268 #else | |
0 | 269 movff dMSB,W3+1 |
270 movff dLSB,W3+0 | |
289 | 271 #endif |
0 | 272 |
273 movlw d'13' | |
274 movwf clock_count | |
275 movlw b'01101000' ;+3*high as start and 1+low as stop! | |
276 movwf isr1_temp | |
277 rcall send_data_MS55535A | |
278 rcall get_2bytes_MS5535A | |
289 | 279 #ifdef TESTING |
280 movlw LOW(.28083) | |
281 movff WREG,W4+0 | |
282 movlw HIGH(.28083) | |
283 movff WREG,W4+1 | |
284 #else | |
0 | 285 movff dMSB,W4+1 |
286 movff dLSB,W4+0 | |
289 | 287 #endif |
0 | 288 |
289 ; calculate C1 (16Bit) | |
290 movff W1+1, C1+1 | |
291 bcf STATUS,C | |
292 rrcf C1+1 | |
293 bcf STATUS,C | |
294 rrcf C1+1 | |
295 bcf STATUS,C | |
296 rrcf C1+1 | |
297 movff W1+0, C1+0 | |
298 bsf STATUS,C | |
299 btfss W1+1,0 | |
300 bcf STATUS,C | |
301 rrcf C1+0 | |
302 bsf STATUS,C | |
303 btfss W1+1,1 | |
304 bcf STATUS,C | |
305 rrcf C1+0 | |
306 bsf STATUS,C | |
307 btfss W1+1,2 | |
308 bcf STATUS,C | |
309 rrcf C1+0 | |
310 | |
311 ; calculate C2 (16Bit) | |
312 movff W2+0, C2+0 | |
313 bsf STATUS,C | |
314 btfss W2+1,0 | |
315 bcf STATUS,C | |
316 rrcf C2+0 | |
317 bsf STATUS,C | |
318 btfss W2+1,1 | |
319 bcf STATUS,C | |
320 rrcf C2+0 | |
321 bsf STATUS,C | |
322 btfss W2+1,2 | |
323 bcf STATUS,C | |
324 rrcf C2+0 | |
325 bsf STATUS,C | |
326 btfss W2+1,3 | |
327 bcf STATUS,C | |
328 rrcf C2+0 | |
329 bsf STATUS,C | |
330 btfss W2+1,4 | |
331 bcf STATUS,C | |
332 rrcf C2+0 | |
333 bsf STATUS,C | |
334 btfss W2+1,5 | |
335 bcf STATUS,C | |
336 rrcf C2+0 | |
337 | |
338 movff W2+1, C2+1 | |
339 bsf STATUS,C | |
340 btfss W1+0,0 | |
341 bcf STATUS,C | |
342 rrcf C2+1 | |
343 bsf STATUS,C | |
344 btfss W1+0,1 | |
345 bcf STATUS,C | |
346 rrcf C2+1 | |
347 bsf STATUS,C | |
348 btfss W1+0,2 | |
349 bcf STATUS,C | |
350 rrcf C2+1 | |
351 bcf STATUS,C | |
352 rrcf C2+1 | |
353 bcf STATUS,C | |
354 rrcf C2+1 | |
355 bcf STATUS,C | |
356 rrcf C2+1 | |
357 | |
358 ; calculate C3 (16Bit) | |
359 movff W3+1,C3+0 | |
360 bsf STATUS,C | |
361 btfss W3+0,7 | |
362 bcf STATUS,C | |
363 rlcf C3+0 | |
364 bsf STATUS,C | |
365 btfss W3+0,6 | |
366 bcf STATUS,C | |
367 rlcf C3+0 | |
368 clrf C3+1 | |
369 btfsc W3+1,7 | |
370 bsf C3+1,1 | |
371 btfsc W3+1,6 | |
372 bsf C3+1,0 | |
373 | |
374 ; calculate C4 (16Bit) | |
375 movff W4+1,C4+0 | |
376 bsf STATUS,C | |
377 btfss W4+0,7 | |
378 bcf STATUS,C | |
379 rlcf C4+0 | |
380 clrf C4+1 | |
381 btfsc W4+1,7 | |
382 bsf C4+1,0 | |
704 | 383 |
384 ; C4=C4-250 | |
385 movlw LOW(-.250) ; C4 - 250 --> C4 | |
386 addwf C4+0,W | |
387 movwf C4+0 | |
388 movlw -1 ; HIGH(- .250) is not understood... | |
389 addwfc C4+1,W | |
390 movwf C4+1 | |
0 | 391 |
392 ; calculate C5 (16Bit) | |
393 movff W3+0,C5+0 | |
394 bcf C5+0,6 | |
395 btfsc W2+0,0 | |
396 bsf C5+0,6 | |
397 bcf C5+0,7 | |
398 btfsc W2+0,1 | |
399 bsf C5+0,7 | |
400 clrf C5+1 | |
401 btfsc W2+0,2 | |
402 bsf C5+1,0 | |
403 btfsc W2+0,3 | |
404 bsf C5+1,1 | |
405 btfsc W2+0,4 | |
406 bsf C5+1,2 | |
407 btfsc W2+0,5 | |
408 bsf C5+1,3 | |
409 | |
704 | 410 ; calculate C5 = UT1 |
411 ; C5 = 8*C5 + 10000 (u16 range 10.000 .. +42.760) | |
412 clrf isr_xA+1 | |
413 movlw d'8' | |
414 movwf isr_xA+0 | |
415 movff C5+0,isr_xB+0 | |
416 movff C5+1,isr_xB+1 | |
417 call isr_unsigned_mult16x16 ;isr_xA*isr_xB=isr_xC | |
418 movff isr_xC+0,C5+0 | |
419 movff isr_xC+1,C5+1 | |
420 movlw LOW d'10000' | |
421 addwf C5+0,F | |
422 movlw HIGH d'10000' | |
423 addwfc C5+1,F ; = 8*C5 + 10000 | |
424 | |
0 | 425 ; calculate C6 (16Bit) |
426 clrf C6+1 | |
427 movff W4+0,C6+0 | |
428 bcf C6+0,7 | |
429 | |
430 bcf no_sensor_int ; enable sensor interrupts | |
431 return | |
432 | |
169
e26f49674956
Merge decoplan display for both GF and Buhlmann models.
JeanDo
parents:
161
diff
changeset
|
433 ;============================================================================= |
0 | 434 reset_MS5535A_one: |
435 bsf sensor_SDO | |
436 nop | |
437 bsf sensor_CLK | |
438 nop | |
439 nop | |
440 nop | |
441 nop | |
469 | 442 btfsc OSCCON,4 ; 32MHz Mode? |
443 rcall MS5535A_extra_wait ; Yes | |
0 | 444 bcf sensor_CLK |
445 return | |
446 | |
447 reset_MS5535A_zero: | |
448 bcf sensor_SDO | |
449 nop | |
450 bsf sensor_CLK | |
451 nop | |
452 nop | |
453 nop | |
454 nop | |
469 | 455 btfsc OSCCON,4 ; 32MHz Mode? |
456 rcall MS5535A_extra_wait ; Yes | |
0 | 457 bcf sensor_CLK |
458 return | |
459 | |
469 | 460 MS5535A_extra_wait: |
461 nop | |
462 nop | |
463 nop | |
464 nop | |
465 nop | |
466 return | |
467 | |
0 | 468 reset_MS5535A: |
469 rcall reset_MS5535A_one ;0 | |
470 rcall reset_MS5535A_zero | |
471 rcall reset_MS5535A_one | |
472 rcall reset_MS5535A_zero | |
473 rcall reset_MS5535A_one | |
474 rcall reset_MS5535A_zero | |
475 rcall reset_MS5535A_one | |
476 rcall reset_MS5535A_zero | |
477 rcall reset_MS5535A_one | |
478 rcall reset_MS5535A_zero | |
479 rcall reset_MS5535A_one | |
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 ;15 | |
485 rcall reset_MS5535A_zero | |
486 rcall reset_MS5535A_zero | |
487 rcall reset_MS5535A_zero | |
488 rcall reset_MS5535A_zero | |
489 rcall reset_MS5535A_zero ;20 | |
490 return | |
491 | |
492 get_2bytes_MS5535A: | |
493 movlw d'8' | |
494 movwf clock_count | |
495 rcall recieve_loop | |
496 movff isr1_temp,dMSB | |
497 | |
498 movlw d'8' | |
499 movwf clock_count | |
500 rcall recieve_loop | |
501 movff isr1_temp,dLSB | |
502 bsf sensor_CLK | |
503 nop | |
504 nop | |
505 nop | |
506 nop | |
469 | 507 btfsc OSCCON,4 ; 32MHz Mode? |
508 rcall MS5535A_extra_wait ; Yes | |
0 | 509 bcf sensor_CLK |
510 return | |
511 | |
512 recieve_loop: | |
513 bsf sensor_CLK | |
514 nop | |
515 nop | |
516 nop | |
517 nop | |
469 | 518 btfsc OSCCON,4 ; 32MHz Mode? |
519 rcall MS5535A_extra_wait ; Yes | |
0 | 520 bcf sensor_CLK |
521 btfss sensor_SDI ;MSB first | |
522 bcf STATUS,C | |
523 btfsc sensor_SDI ;MSB first | |
524 bsf STATUS,C | |
525 rlcf isr1_temp,F | |
526 decfsz clock_count,F | |
527 bra recieve_loop | |
528 return | |
529 | |
530 send_data_MS55535A: | |
531 ; send three startbits first | |
532 bcf sensor_CLK | |
533 bsf sensor_SDO | |
534 movlw d'3' | |
535 subwf clock_count,F ; total bit counter | |
536 bsf sensor_CLK | |
537 nop | |
538 nop | |
539 nop | |
540 nop | |
469 | 541 btfsc OSCCON,4 ; 32MHz Mode? |
542 rcall MS5535A_extra_wait ; Yes | |
0 | 543 bcf sensor_CLK |
544 nop | |
545 nop | |
546 nop | |
547 nop | |
469 | 548 btfsc OSCCON,4 ; 32MHz Mode? |
549 rcall MS5535A_extra_wait ; Yes | |
0 | 550 bsf sensor_CLK |
551 nop | |
552 nop | |
553 nop | |
554 nop | |
469 | 555 btfsc OSCCON,4 ; 32MHz Mode? |
556 rcall MS5535A_extra_wait ; Yes | |
0 | 557 bcf sensor_CLK |
558 nop | |
559 nop | |
560 nop | |
561 nop | |
469 | 562 btfsc OSCCON,4 ; 32MHz Mode? |
563 rcall MS5535A_extra_wait ; Yes | |
0 | 564 bsf sensor_CLK |
565 nop | |
566 nop | |
567 nop | |
568 nop | |
469 | 569 btfsc OSCCON,4 ; 32MHz Mode? |
570 rcall MS5535A_extra_wait ; Yes | |
0 | 571 bcf sensor_CLK |
572 ; now send 8 bytes from isr_temp1 and fill-up with zeros | |
469 | 573 databits: |
0 | 574 btfss isr1_temp,7 ;MSB first |
575 bcf sensor_SDO | |
576 btfsc isr1_temp,7 ;MSB first | |
577 bsf sensor_SDO | |
578 bcf STATUS,C | |
579 rlcf isr1_temp | |
580 | |
581 bsf sensor_CLK | |
582 nop | |
583 nop | |
584 nop | |
585 nop | |
469 | 586 btfsc OSCCON,4 ; 32MHz Mode? |
587 rcall MS5535A_extra_wait ; Yes | |
0 | 588 bcf sensor_CLK |
589 | |
590 decfsz clock_count,F | |
469 | 591 bra databits |
0 | 592 return |