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