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