comparison 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
comparison
equal deleted inserted replaced
339:cb77d1fa4535 340:ecbbbd423e86
25 25
26 ;============================================================================= 26 ;=============================================================================
27 ; Expose internal variables, to ease debug: 27 ; Expose internal variables, to ease debug:
28 global D1, D2 28 global D1, D2
29 global C1, C2, C3, C4, C5, C6 29 global C1, C2, C3, C4, C5, C6
30 global xdT, xdT2, OFF, SENS, amb_pressure, temperature 30 global xdT, xdT2, OFF, SENS, amb_pressure_avg, temperature_avg
31 31
32 ;============================================================================= 32 ;=============================================================================
33 calculate_compensation: 33 calculate_compensation:
34 ; calculate UT1 = 8*C5 + 10000 (u16 range 10.000 .. +42.760) 34 ; calculate UT1 = 8*C5 + 10000 (u16 range 10.000 .. +42.760)
35 clrf isr_xA+1 35 clrf isr_xA+1
149 movff SENS+1,isr_xB+1 149 movff SENS+1,isr_xB+1
150 call isr_signed_mult16x16 150 call isr_signed_mult16x16
151 movlw .12-.8 ; a 12bit shift = 1 byte + 4 bits. 151 movlw .12-.8 ; a 12bit shift = 1 byte + 4 bits.
152 call isr_shift_C31 152 call isr_shift_C31
153 153
154 movlw LOW(.1000) ; add 1000, and save into amb_pressure 154 movlw LOW(.1000) ; add 1000
155 addwf isr_xC+1,W 155 addwf isr_xC+1,F
156 movwf amb_pressure+0
157 movlw HIGH(.1000) 156 movlw HIGH(.1000)
158 addwfc isr_xC+2,W 157 addwfc isr_xC+2,F
159 movwf amb_pressure+1
160 158
161 btfss simulatormode_active ; are we in simulator mode? 159 btfss simulatormode_active ; are we in simulator mode?
162 bra calc_pressure_done ; no 160 bra calc_compensation_2 ; no
163 161
164 movff sim_pressure+0,amb_pressure+0 ; override readings with simulator values 162 movff sim_pressure+0,isr_xC+1 ; override readings with simulator values
165 movff sim_pressure+1,amb_pressure+1 163 movff sim_pressure+1,isr_xC+2
166 164
167 calc_pressure_done: 165 calc_compensation_2:
166 movf isr_xC+1,W ; Then sum_up to pressure averaging buffer.
167 addwf amb_pressure_avg+0,F
168 movf isr_xC+2,W
169 addwfc amb_pressure_avg+1,F
170
168 ; calculate temp = 200 + dT*(C6+100)/2^11 171 ; calculate temp = 200 + dT*(C6+100)/2^11
169 movlw LOW(.100) ; C6 + 100 --> A 172 movlw LOW(.100) ; C6 + 100 --> A
170 addwf C6+0,W 173 addwf C6+0,W
171 movwf isr_xA+0 174 movwf isr_xA+0
172 movlw HIGH(.100) 175 movlw HIGH(.100)
177 movff xdT2+1,isr_xB+1 180 movff xdT2+1,isr_xB+1
178 call isr_signed_mult16x16 ; A*B 181 call isr_signed_mult16x16 ; A*B
179 movlw .11-.8 ; A 12bit shift = 1 byte + 3 bits. 182 movlw .11-.8 ; A 12bit shift = 1 byte + 3 bits.
180 call isr_shift_C31 183 call isr_shift_C31
181 184
182 movlw LOW(.200) ; Add 200, and save into temperature 185 movlw LOW(.200) ; Add 200
183 addwf isr_xC+1,W 186 addwf isr_xC+1,F
184 movwf temperature+0
185 movlw HIGH(.200) 187 movlw HIGH(.200)
186 addwfc isr_xC+2,W 188 addwfc isr_xC+2,F
187 movwf temperature+1 189
188 190 movf isr_xC+1,W
189 bcf neg_temp 191 addwf temperature_avg+0,F
190 bnn calc_pos_temp ; Is Temp° negativ ? 192 movf isr_xC+2,W
191 193 addwfc temperature_avg+1,F
192 bsf neg_temp ; Yes: set flag and store -temp 194
193 comf temperature+1
194 negf temperature+0
195 btfsc STATUS,C
196 incf temperature+1
197
198 calc_pos_temp:
199 return ; Fertig mit allem 195 return ; Fertig mit allem
200 196
201 ;============================================================================= 197 ;=============================================================================
202 get_pressure_start: 198 get_pressure_start:
203 rcall reset_MS5535A 199 rcall reset_MS5535A