annotate src/ms5541.asm @ 643:7d8a4c60ec1a

3.15 release
author heinrichsweikamp
date Mon, 24 May 2021 18:40:53 +0200
parents 4050675965ea
children 070528a88715 357341239438
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
heinrichsweikamp
parents:
diff changeset
1 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
2 ;
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
3 ; File ms5541.asm * combined next generation V3.9.4f
0
heinrichsweikamp
parents:
diff changeset
4 ;
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
5 ; Sensor Subroutines
0
heinrichsweikamp
parents:
diff changeset
6 ;
heinrichsweikamp
parents:
diff changeset
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved.
heinrichsweikamp
parents:
diff changeset
8 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
9 ; HISTORY
heinrichsweikamp
parents:
diff changeset
10 ; 2011-08-03 : [mH] moving from OSTC code
heinrichsweikamp
parents:
diff changeset
11
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
12 #include "hwos.inc" ; Mandatory header
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
13 #include "math.inc" ; Math routines
643
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
14 #include "i2c.inc"
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
15 #include "shared_definitions.h" ; mailbox from/to p2_deco.c
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
16
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
17 ms5541 CODE
0
heinrichsweikamp
parents:
diff changeset
18
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
19
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
20 ; Expose internal variables to ease debug
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
21 global D1, D2
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
22 global C1, C2, C3, C4, C5, C6
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
23 global xdT, xdT2, OFF, SENS, pressure_abs_avg, temperature_avg
0
heinrichsweikamp
parents:
diff changeset
24
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
25
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
26 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
27 ; Convert Temperature & Pressure raw Values to compensated Values
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
28 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
29 ; called from ISR and from sleep mode, returns in bank isr_data
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
30 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
31 global calculate_compensation
0
heinrichsweikamp
parents:
diff changeset
32 calculate_compensation:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
33 banksel isr_backup ; select bank ISR data
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
34
643
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
35 btfsc press_sensor_type ; New sensor found?
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
36 bra press_comp_ms5837 ; Yes, use MS5837
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
37
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
38 ;---- pressure sensor compensation
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
39
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
40 ; xdT = D2 - C5 (s16 range -11.400 .. +12.350)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
41 movf C5+0,W ; get value to be subtracted
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
42 subwf D2+0,W ; do the low byte
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
43 movwf xdT+0
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
44 movf C5+1,W ; do the high byte
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
45 subwfb D2+1,W
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
46 movwf xdT+1
0
heinrichsweikamp
parents:
diff changeset
47
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
48 ; second order temperature calculation
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
49
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
50 ; xdT/128 is in range -89..+96, hence signed 8 bit. dT/128 = (2*dT)/256
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
51 rlcf xdT+0,W ; put hit bit in carry
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
52 rlcf xdT+1,W ; inject in high byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
53 movwf isr_xA+0 ; and put result in low byte
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
54 clrf isr_xA+1
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
55 btfsc xdT+1,7 ; dT < 0 ?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
56 setf isr_xA+1 ; YES - sign extend to -1
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
57 MOVII isr_xA,isr_xB ; copy A to B
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
58 call isr_signed_mult16x16 ; dT*dT --> xC (32 bits)
0
heinrichsweikamp
parents:
diff changeset
59
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
60 ; dT >= 0: divide by 8, i.e. 3 shifts rights
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
61 ; dT < 0: divide by 2, i.e. 1 shifts rights
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
62 movlw .3 ; 3 shifts by default
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
63 btfss xdT+1,7 ; was dT negative ?
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
64 movlw .1 ; YES - replace by 1 shift
0
heinrichsweikamp
parents:
diff changeset
65 calc_loop_1:
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
66 bcf STATUS,C ; dT^2 is positive, so injecte zeros
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
67 rrcf isr_xC+1,F ; shift right high byte
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
68 rrcf isr_xC+0,F ; shift right low byte
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
69 decfsz WREG ; decrement loop counter, all shifts done?
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
70 bra calc_loop_1 ; NO - loop
0
heinrichsweikamp
parents:
diff changeset
71
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
72 movf isr_xC+0,W ; dT2 = dT - (dT/128)*(dT/128)/(2 ...or... 8)
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
73 subwf xdT+0,W ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
74 movwf xdT2+0 ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
75 movf isr_xC+1,W ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
76 subwfb xdT+1,W ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
77 movwf xdT2+1 ; ...
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
78
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
79 ; calculate OFF = C2 + ((C4-250)*dT2)/2^12 + 10000 (range +9.246 .. +18.887)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
80 MOVII C4, isr_xA ; C4 - 250 --> A
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
81 MOVII xdT2,isr_xB ; dT2 --> B
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
82 call isr_signed_mult16x16 ; C = A*B
0
heinrichsweikamp
parents:
diff changeset
83
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
84 movlw .12-.8 ; a 12 bit shift = 1 byte + 4 bits
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
85 call isr_shift_C31 ; special shift
368
57e349960ef4 Additional temperature calibration via PC interface
heinrichsweikamp
parents: 353
diff changeset
86
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
87 movlw LOW(.10000) ; add 10000
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
88 addwf isr_xC+1,F ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
89 movlw HIGH(.10000) ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
90 addwfc isr_xC+2,F ; ...
0
heinrichsweikamp
parents:
diff changeset
91
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
92 movf C2+0,W ; add C2 and store result in OFF
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
93 addwf isr_xC+1,W ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
94 movwf OFF+0 ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
95 movf C2+1,W ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
96 addwfc isr_xC+2,W ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
97 movwf OFF+1 ; ...
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
98
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
99 ; calculate SENS = C1/2 + ((C3+200)*dT)/2^13 + 3000
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
100 movlw LOW(.200) ; C3+200 --> A
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
101 addwf C3+0,W ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
102 movwf isr_xA+0 ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
103 movlw HIGH(.200) ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
104 addwfc C3+1,W ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
105 movwf isr_xA+1 ; ...
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
106 ; B still contains dT2
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
107 call isr_signed_mult16x16 ; C = A*B
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
108 movlw .13-.8 ; A 13 bit shift = 1 byte + 5 bits
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
109 call isr_shift_C31 ; special shift
0
heinrichsweikamp
parents:
diff changeset
110
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
111 bcf STATUS,C ; SENS = C1 / 2
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
112 rrcf C1+1,W ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
113 movwf SENS+1 ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
114 rrcf C1+0,W ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
115 movwf SENS+0 ; ...
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
116
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
117 movlw LOW(.3000) ; add 3000
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
118 addwf isr_xC+1,F ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
119 movlw HIGH(.3000) ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
120 addwfc isr_xC+2,F ; ...
0
heinrichsweikamp
parents:
diff changeset
121
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
122 movf isr_xC+1,W ; and sum into SENS
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
123 addwf SENS+0,F ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
124 movf isr_xC+2,W ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
125 addwfc SENS+1,F ; ...
0
heinrichsweikamp
parents:
diff changeset
126
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
127 ; calculate absolute pressure = (sens * (d1-off))/2^12 + 1000 (for MS5541C)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
128 ; calculate absolute pressure = (sens * (d1-off))/2^11 + 1000 (for MS5541C-30)
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
129 movf OFF+0,W ; d1-off --> a
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
130 subwf D1+0,W ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
131 movwf isr_xA+0 ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
132 movf OFF+1,W ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
133 subwfb D1+1,W ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
134 movwf isr_xA+1 ; ...
0
heinrichsweikamp
parents:
diff changeset
135
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
136 MOVII SENS,isr_xB ; sens --> B
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
137 call isr_signed_mult16x16 ; C = A*B
643
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
138 movlw .15 ; 15 * 256 = 3840
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
139 cpfslt C1+1 ; C1 > 3328 ?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
140 bra isr_shift_ms5541_30 ; YES - MS5541-30
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
141 movlw .12-.8 ; NO - MS5541: 12 bit shift = 1 byte + 4 bits
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
142 bra isr_shift_ms5541_common ; - continue
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
143 isr_shift_ms5541_30:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
144 movlw .11-.8 ; MS5541-30: 11 bit shift = 1 byte + 3 bits
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
145 isr_shift_ms5541_common:
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
146 call isr_shift_C31 ; special shift
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
147 movlw LOW .1000 ; add 1000
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
148 addwf isr_xC+1,F ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
149 movlw HIGH .1000 ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
150 addwfc isr_xC+2,F ; ...
643
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
151 bra press_comp_done_common
0
heinrichsweikamp
parents:
diff changeset
152
643
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
153 press_comp_ms5837:
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
154 ; xdT = D2 - C5*2^8
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
155 movlw .0 ; Low
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
156 subwf D2+0,W
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
157 movwf xdT+0
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
158 movf C5+0,W ; High
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
159 subwfb D2+1,W
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
160 movwf xdT+1
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
161 movf C5+1,W ; Upper
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
162 subwfb D2+2,W
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
163 movwf xdT+2
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
164 ; xdT equals D2 - (C5*2^8)
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
165
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
166 ; Calculate OFF = C2*2^16+(C4*xdT)/2^7
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
167 movff C4+0,isr_xA+0
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
168 movff C4+1,isr_xA+1
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
169 clrf isr_xA+2
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
170 movff xdT+0,isr_xB+0
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
171 movff xdT+1,isr_xB+1
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
172 movff xdT+2,isr_xB+2
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
173 call isr_signed_mult24x24 ; C = A*B
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
174 ; isr_xC:6 equals (C4*xdT)
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
175 rlcf isr_xC+0,F
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
176 rlcf isr_xC+1,F
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
177 rlcf isr_xC+2,F
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
178 rlcf isr_xC+3,F
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
179 rlcf isr_xC+4,F
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
180 rlcf isr_xC+5,F
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
181 movff isr_xC+1,OFF+0
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
182 movff isr_xC+2,OFF+1
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
183 movff isr_xC+3,OFF+2
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
184 movff isr_xC+4,OFF+3
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
185 ; OFF equals (C4*xdT)/2^7
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
186 movf C2+0,W
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
187 addwf OFF+2,F
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
188 movf C2+1,W
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
189 addwfc OFF+3,F
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
190 ; OFF equals C2*2^16+((C4*xdT)/2^7)
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
191
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
192 ; Calculate SENS = C1*2^15 + (C3*xdT)/2^8
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
193 MOVII C1,isr_xA
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
194 movlw LOW (.32768)
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
195 movwf isr_xB+0
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
196 movlw HIGH (.32768)
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
197 movwf isr_xB+1
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
198 call isr_unsigned_mult16x16 ; C = A*B
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
199 movff isr_xC+0,SENS+0
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
200 movff isr_xC+1,SENS+1
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
201 movff isr_xC+2,SENS+2
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
202 movff isr_xC+3,SENS+3 ; 32bit copy
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
203 ; SENS equals C1*2^15
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
204 movff C3+0,isr_xA+0
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
205 movff C3+1,isr_xA+1
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
206 clrf isr_xA+2
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
207 movff xdT+0,isr_xB+0
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
208 movff xdT+1,isr_xB+1
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
209 movff xdT+2,isr_xB+2
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
210 call isr_signed_mult24x24 ; C = A*B
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
211 ; isr_xC:6 equals (C3*xdT)
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
212 movf isr_xC+1,W
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
213 addwf SENS+0,F
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
214 movf isr_xC+2,W
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
215 addwfc SENS+1,F
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
216 movf isr_xC+3,W
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
217 addwfc SENS+2,F
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
218 movf isr_xC+4,W
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
219 addwfc SENS+3,F
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
220 ; SENS equals C1*2^15 + (C3*xdT)/2^8
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
221
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
222 ; Calculate PRESSURE = ((D1 * SENS) / 2^21) - OFF) / 2^13
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
223 movff SENS+0,isr_xA+0
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
224 movff SENS+1,isr_xA+1
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
225 movff SENS+2,isr_xA+2
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
226 movff SENS+3,isr_xA+3
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
227 movff D1+0,isr_xB+0
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
228 movff D1+1,isr_xB+1
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
229 movff D1+2,isr_xB+2
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
230 call isr_unsigned_mult32x24 ; C = A*B
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
231 ; isr_xC:7 equals D1*SENS
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
232
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
233 ; devide isr_xC:7 / 2^21 -> shift right 21 times
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
234 movlw .21
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
235 press_comp_ms5837_2:
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
236 bcf STATUS,C ; clear carry, needed for MS5837 use
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
237 rrcf isr_xC+6,F
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
238 rrcf isr_xC+5,F
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
239 rrcf isr_xC+4,F
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
240 rrcf isr_xC+3,F
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
241 rrcf isr_xC+2,F
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
242 rrcf isr_xC+1,F
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
243 rrcf isr_xC+0,F
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
244 decfsz WREG ; decrement loop counter, done?
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
245 bra press_comp_ms5837_2 ; NO - loop
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
246 ; isr_xC:6 equals (D1*SENS)/2^21
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
247
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
248 ; Calculate isr_xC:6-OFF
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
249 movf OFF+0,W ; Low
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
250 subwf isr_xC+0,F
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
251 movf OFF+1,W ; High
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
252 subwfb isr_xC+1,F
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
253 movf OFF+2,W ; Upper
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
254 subwfb isr_xC+2,F
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
255 movf OFF+3,W ; Extra
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
256 subwfb isr_xC+3,F
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
257 movlw .0 ; ultra
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
258 subwfb isr_xC+4,F
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
259 movlw .0 ; Hyper
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
260 subwfb isr_xC+5,F
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
261 ; isr_xC:5 is now isr_xC:4-OFF
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
262
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
263 ; devide by 2^13
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
264 ; devide isr_xC:6 / 2^13 -> shift right 13 times
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
265 movlw .13
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
266 press_comp_ms5837_3:
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
267 bcf STATUS,C ; clear carry
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
268 rrcf isr_xC+5,F
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
269 rrcf isr_xC+4,F
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
270 rrcf isr_xC+3,F
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
271 rrcf isr_xC+2,F
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
272 rrcf isr_xC+1,F
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
273 rrcf isr_xC+0,F
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
274 decfsz WREG ; decrement loop counter, done?
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
275 bra press_comp_ms5837_3 ; NO - loop
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
276 ; isr_xC:4 equals pressure in .1 mbar
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
277
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
278 movlw .10
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
279 movwf isr_xB+0
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
280 clrf isr_xB+1
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
281 call isr_div32x16 ; isr_xC:4 = isr_xC:4 / isr_xB:2 with isr_xA as remainder
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
282 ; isr_xC:2 equals pressure in 1mbar
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
283
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
284 ; subtract 20mbar from the final result
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
285 movlw .20
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
286 subwf isr_xC+0,F
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
287 movlw .0
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
288 subwfb isr_xC+1,F
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
289
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
290 ; copy for compatibility of the next routines
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
291 movff isr_xC+1,isr_xC+2
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
292 movff isr_xC+0,isr_xC+1
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
293
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
294 press_comp_done_common: ; continue here even with MS5837
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
295 ; add opt_pressure_adjust to result (SIGNED!)
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
296 clrf isr_xC+0 ; prepare high byte for adjustment
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
297 movff opt_pressure_adjust,WREG ; get low byte for adjustment (signed)
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
298 movf WREG,W ; excite flags
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
299 bz calc_compensation_1 ; opt_pressure_adjust = 0 -> skip adjustment
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
300 btfss STATUS,N ; opt_pressure_adjust < 0 ?
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
301 bra calc_compensation_adjust ; NO - positive
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
302 negf WREG ; YES - negate opt_pressure_adjust for limit check
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
303 setf isr_xC+0 ; - adopt high byte for adjustment
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
304 calc_compensation_adjust:
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
305 addlw -.21 ; limit is 20 mbar, subtract 21
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
306 bnn calc_compensation_1 ; result not negative -> skip adjustment
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
307 movff opt_pressure_adjust,WREG ; get opt_pressure_adjust, low byte
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
308 addwf isr_xC+1,F ; pressure value += opt_pressure_adjust, low byte
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
309 movf isr_xC+0,W ; get adjustment, high byte
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
310 addwfc isr_xC+2,F ; pressure value += opt_pressure_adjust, high byte
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
311
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
312 calc_compensation_1:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
313 bcf sensor_override_active ; clear sensor override active flag by default
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
314 btfss sensor_override_request ; sensor override requested?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
315 bra calc_compensation_add_avg ; NO - keep taking absolute pressure from sensor
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
316 btfsc quit_simulatormode ; YES - shall quit simulator mode (the fast way)?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
317 bra calc_compensation_sim_quit ; YES - force pressure_rel_sim to zero
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
318 ;bra calc_compensation_sim ; NO - calculate pressure_rel_sim from simulated depth
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
319
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
320 calc_compensation_sim: ; check if OSTC got submerged
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
321 movlw .5 ; coding in high byte for 1280
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
322 cpfsgt isr_xC+2 ; absolute pressure > 1280 mbar, i.e. OSTC submerged?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
323 bra calc_compensation_sim_slave ; NO - slave pressure_rel_sim to target depth
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
324 ;bra calc_compensation_sim_quit ; YES - force pressure_rel_sim to zero
92
7ca1105751c7 add sensor calibration option (PC only), some cleanup
heinrichsweikamp
parents: 29
diff changeset
325
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
326 calc_compensation_sim_quit:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
327 CLRI pressure_rel_sim ; set pressure_rel_sim to zero, this paves a restart into surface/dive mode
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
328 bra calc_compensation_sim_com ; continue with common part
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
329
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
330 calc_compensation_sim_slave:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
331 movf simulatormode_depth,W ; copy simulated depth to WREG
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
332 mullw .100 ; multiply with 100 to turn depth from meters to relative target pressure in mbar
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
333 ; check if shall go up
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
334 movf pressure_rel_sim+0,W ; get relative pressure, low byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
335 subwf PRODL,W ; WREG = relative target pressure - pressure_rel_sim (low byte)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
336 movf pressure_rel_sim+1,W ; get relative pressure, high byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
337 subwfb PRODH,W ; WREG = relative target pressure - pressure_rel_sim (high byte)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
338 btfsc STATUS,N ; result < 0, i.e. pressure_rel_sim > relative target pressure ?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
339 bra calc_compensation_sim_up ; YES - decrease pressure_rel_sim
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
340 ; check if shall go down
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
341 movf PRODL,W ; get relative target pressure, low byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
342 subwf pressure_rel_sim+0,W ; WREG = pressure_rel_sim - relative target pressure (low byte)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
343 movf PRODH,W ; get relative target pressure, high byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
344 subwfb pressure_rel_sim+1,W ; WREG = pressure_rel_sim - relative target pressure (high byte)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
345 btfsc STATUS,N ; result < 0, i.e. relative target pressure > pressure_rel_sim ?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
346 bra calc_compensation_sim_down ; YES - increase pressure_rel_sim
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
347 ; both pressures are equal
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
348 bra calc_compensation_sim_com ; NO to both - keep pressure_rel_sim as it is
0
heinrichsweikamp
parents:
diff changeset
349
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
350 calc_compensation_sim_up:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
351 movf PRODL,W ; get relative target pressure, low byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
352 subwf pressure_rel_sim+0,W ; WREG = pressure_rel_sim - relative target pressure (low byte)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
353 movwf PRODL ; PRODL = pressure_rel_sim - relative target pressure (low byte)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
354 movf PRODH,W ; get relative target pressure, high byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
355 subwfb pressure_rel_sim+1,W ; WREG = pressure_rel_sim - relative target pressure (high byte)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
356 tstfsz WREG ; more than 255 mbar off from target?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
357 bra calc_compensation_sim_up_norm ; YES - go up with normal speed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
358 movlw simulator_ascent_threshold ; NO - get remaining difference for slowing down ascent
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
359 cpfslt PRODL ; - remaining difference to target < decrement?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
360 bra calc_compensation_sim_up_norm ; NO - go up with normal speed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
361 ;bra calc_compensation_sim_up_slow ; YES - go up with slow speed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
362
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
363 calc_compensation_sim_up_slow:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
364 DECI pressure_rel_sim ; subtract slow decrement (1 mbar) from pressure_rel_sim
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
365 bra calc_compensation_sim_com ; continue with common part
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
366
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
367 calc_compensation_sim_up_norm:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
368 SUBLI simulator_ascent_rate,pressure_rel_sim ; subtract normal decrement from pressure_rel_sim
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
369 bra calc_compensation_sim_com ; continue with common part
353
573f2251cf49 NEW: Quit Simulator automatically when starting a real dive
heinrichsweikamp
parents: 275
diff changeset
370
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
371 calc_compensation_sim_down:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
372 movf pressure_rel_sim+0,W ; get relative pressure, low byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
373 subwf PRODL,F ; PRODL = relative target pressure - pressure_rel_sim (low byte)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
374 movf pressure_rel_sim+1,W ; get relative pressure, high byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
375 subwfb PRODH,W ; WREG = relative target pressure - pressure_rel_sim (high byte)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
376 tstfsz WREG ; more than 255 mbar off from target?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
377 bra calc_compensation_sim_down_norm ; YES - go down with normal speed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
378 movlw simulator_descent_threshold ; NO - get remaining difference for slowing down descent
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
379 cpfslt PRODL ; - remaining difference to target < increment?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
380 bra calc_compensation_sim_down_norm ; NO - go down with normal speed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
381 ;bra calc_compensation_sim_down_slow ; YES - go down with slow speed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
382
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
383 calc_compensation_sim_down_slow:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
384 INCI pressure_rel_sim ; add slow increment (1 mbar) to pressure_rel_sim
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
385 bra calc_compensation_sim_com ; continue with common part
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
386
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
387 calc_compensation_sim_down_norm:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
388 ADDLI simulator_descent_rate,pressure_rel_sim ; add normal increment to pressure_rel_sim
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
389 ;bra calc_compensation_sim_com ; continue with common part
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
390
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
391 calc_compensation_sim_com:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
392 movf pressure_surf+0,W ; copy surface pressure to WREG, low byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
393 addwf pressure_rel_sim+0,W ; add surface pressure to relative pressure to gain simulated absolute pressure, low byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
394 movwf isr_xC+1 ; override sensor pressure with simulated pressure, low byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
395 movf pressure_surf+1,W ; copy surface pressure to WREG, high byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
396 addwfc pressure_rel_sim+1,W ; add surface pressure to relative pressure to gain simulated absolute pressure, high byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
397 movwf isr_xC+2 ; override sensor pressure with simulated pressure, high byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
398 bsf sensor_override_active ; confirm sensor override is active
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
399
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
400 calc_compensation_add_avg:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
401 ; add current absolute pressure to averaging buffer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
402 movf isr_xC+1,W ; copy current absolute pressure to WREG, low byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
403 addwf pressure_abs_avg+0,F ; pressure_abs_avg += current pressure, low byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
404 movf isr_xC+2,W ; copy current absolute pressure to WREG, high byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
405 addwfc pressure_abs_avg+1,F ; pressure_abs_avg += current pressure, high byte
643
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
406 movlw .0
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
407 addwfc pressure_abs_avg+2,F ; pressure_abs_avg += current pressure, upper byte
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
408
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
409 ;---- temperature sensor compensation
0
heinrichsweikamp
parents:
diff changeset
410
643
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
411 btfsc press_sensor_type ; New sensor found?
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
412 bra temp_comp_ms5837 ; Yes, use MS5837
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
413
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
414 ; calculate temp = 200 + dT*(C6+100)/2^11
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
415 movlw LOW(.100) ; C6 + 100 --> A
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
416 addwf C6+0,W ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
417 movwf isr_xA+0 ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
418 movlw HIGH(.100) ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
419 addwfc C6+1,W ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
420 movwf isr_xA+1 ; ...
0
heinrichsweikamp
parents:
diff changeset
421
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
422 MOVII xdT2,isr_xB ; dT2 --> B
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
423 call isr_signed_mult16x16 ; A*B
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
424 movlw .11-.8 ; a 12 bit shift = 1 byte + 3 bits
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
425 call isr_shift_C31 ; special shift
0
heinrichsweikamp
parents:
diff changeset
426
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
427 movlw LOW(.200) ; add 200
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
428 addwf isr_xC+1,F ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
429 movlw HIGH(.200) ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
430 addwfc isr_xC+2,F ; ...
643
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
431 bra temp_comp_done_common
0
heinrichsweikamp
parents:
diff changeset
432
643
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
433 temp_comp_ms5837:
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
434 ; TEMP = 2000+((xdT * C6) / 2^23)
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
435
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
436 ; xdT * C6 -> isr_xC:6
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
437 movff C6+0,isr_xA+0
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
438 movff C6+1,isr_xA+1
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
439 clrf isr_xA+2
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
440 movff xdT+0,isr_xB+0
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
441 movff xdT+1,isr_xB+1
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
442 movff xdT+2,isr_xB+2
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
443 call isr_signed_mult24x24 ; A*B
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
444
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
445 ; devide isr_xC:6 / 2^23 -> shift right 23 times
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
446 ; a special variant (again): We loose isr_xC+0 and isr_xC+1 anyway
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
447 ; and do not care about the inserted carry since we won't use isr_xC+5
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
448 ; and we shift less then 8 bytes
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
449 movlw .23-.16
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
450 temp_comp_ms5837_2:
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
451 rrcf isr_xC+5,F ;
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
452 rrcf isr_xC+4,F ;
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
453 rrcf isr_xC+3,F ;
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
454 rrcf isr_xC+2,F ; ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
455 decfsz WREG ; decrement loop counter, done?
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
456 bra temp_comp_ms5837_2 ; NO - loop
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
457
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
458 ; only use +2 and +3
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
459 movlw LOW(.2000) ; add 2000
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
460 addwf isr_xC+2,F ; ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
461 movlw HIGH(.2000) ; ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
462 addwfc isr_xC+3,F ; ...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
463
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
464 ; devide by 10 for .1°C resolution
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
465 movlw .10
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
466 movwf isr_xB+0
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
467 clrf isr_xB+1
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
468 movff isr_xC+2,isr_xA+0
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
469 movff isr_xC+3,isr_xA+1
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
470
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
471 btfss isr_xC+3,7 ; check sign bit
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
472 bra temp_comp_ms5837_3 ; not negative...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
473 ; negate isr_xA:2 to make it positive
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
474 comf isr_xA+1 ; 16 bit sign change
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
475 negf isr_xA+0
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
476 btfsc STATUS,C ; - carry to propagate?
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
477 incf isr_xA+1,F ; YES - do it
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
478
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
479 temp_comp_ms5837_3:
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
480 call isr_div16x16 ; isr_xC:2 = isr_xA:2 / isr_xB:2
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
481
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
482 btfss isr_xC+3,7 ; check sign bit again
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
483 bra temp_comp_ms5837_4 ; not negative...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
484 ; negate result isr_xC:2 to make it negative again
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
485 comf isr_xC+1 ; 16 bit sign change
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
486 negf isr_xC+0
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
487 btfsc STATUS,C ;- carry to propagate?
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
488 incf isr_xC+1,F ; YES - do it
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
489
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
490 temp_comp_ms5837_4:
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
491 ; copy for compatibility of the next routines
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
492 movff isr_xC+1,isr_xC+2
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
493 movff isr_xC+0,isr_xC+1
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
494
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
495 temp_comp_done_common: ; continue here even with MS5837
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
496 ; add opt_temperature_adjust to result (SIGNED!)
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
497 clrf isr_xC+0 ; prepare high byte for adjustment
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
498 movff opt_temperature_adjust,WREG ; get low byte for adjustment (signed)
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
499 movf WREG,W ; excite flags
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
500 bz calc_temperature_add_avg ; opt_temperature_adjust = 0 -> skip adjustment
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
501 btfss STATUS,N ; opt_temperature_adjust < 0 ?
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
502 bra calc_temperature_adjust ; NO - positive
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
503 negf WREG ; YES - negate opt_temperature_adjust for limit check
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
504 setf isr_xC+0 ; - adopt high byte for adjustment
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
505 calc_temperature_adjust:
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
506 addlw -.21 ; limit is 2.0°C, subtract 21 (scaling is 0.1°C)
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
507 bnn calc_temperature_add_avg ; result not negative -> skip adjustment
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
508 movff opt_temperature_adjust,WREG ; get opt_temperature_adjust, low byte
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
509 addwf isr_xC+1,F ; temperature value += opt_temperature_adjust, low byte
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
510 movf isr_xC+0,W ; get adjustment high byte
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
511 addwfc isr_xC+2,F ; temperature value += opt_temperature_adjust, high byte
368
57e349960ef4 Additional temperature calibration via PC interface
heinrichsweikamp
parents: 353
diff changeset
512
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
513 calc_temperature_add_avg:
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
514 movf isr_xC+1,W ; copy current temperature to WREG, low byte
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
515 addwf temperature_avg+0,F ; temperature_avg += current temperature, low byte
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
516 movf isr_xC+2,W ; copy current temperature to WREG, high byte
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
517 addwfc temperature_avg+1,F ; temperature_avg += current temperature, high byte
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
518 return ; done
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
519
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
520
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
521 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
522 ; Start Pressure Measurement
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
523 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
524 ; called from ISR and sleep mode, needs to be called in bank isr_backup
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
525 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
526 global get_pressure_start
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
527 get_pressure_start:
643
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
528 btfsc press_sensor_type ; New sensor found?
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
529 return ; Yes, ignore routine
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
530 rcall reset_MS5541 ; reset the chip
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
531 movlw b'10100000' ; +3*high as start and 1+low as stop
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
532 movwf dbuffer ; ....
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
533 movlw d'12' ; send start command
643
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
534 bra send_data_MS5541 ; ... (And return)
0
heinrichsweikamp
parents:
diff changeset
535
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
536
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
537 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
538 ; Read Pressure Measurement Result
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
539 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
540 ; called from ISR and sleep mode, needs to be called in bank isr_backup
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
541 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
542 global get_pressure_value
0
heinrichsweikamp
parents:
diff changeset
543 get_pressure_value:
643
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
544 btfsc press_sensor_type ; New sensor found?
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
545 bra get_pressure_value2
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
546 btfsc MS5541_miso ; conversion done?
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
547 return ; NO - abort
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
548 rcall get_2bytes_MS5541 ; YES - read result
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
549 movff dMSB,D1+1 ; copy result to D1, high byte first
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
550 movff dLSB,D1+0 ; ... low byte second
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
551 return ; done
0
heinrichsweikamp
parents:
diff changeset
552
643
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
553 get_pressure_value2:
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
554 btfsc i2c_busy_pressure ; currently updating pressure?
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
555 return ; Yes, skip update...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
556 movff D1_buffer+0,D1+0
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
557 movff D1_buffer+1,D1+1
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
558 movff D1_buffer+2,D1+2
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
559 return
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
560
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
561
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
562 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
563 ; Start Temperature Measurement
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
564 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
565 ; called from ISR and sleep mode, needs to be called in bank isr_backup
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
566 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
567 global get_temperature_start
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
568 get_temperature_start:
643
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
569 btfsc press_sensor_type ; New sensor found?
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
570 return ; Yes, ignore routine
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
571 rcall reset_MS5541 ; reset chip
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
572 movlw b'10010000' ; +3*high as start and 1+low as stop
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
573 movwf dbuffer ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
574 movlw d'12' ; send start command
643
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
575 bra send_data_MS5541 ; ... (And return)
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
576
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
577
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
578 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
579 ; Read Pressure Measurement Result
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
580 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
581 ; called from ISR and sleep mode, needs to be called in bank isr_backup
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
582 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
583 global get_temperature_value
0
heinrichsweikamp
parents:
diff changeset
584 get_temperature_value:
643
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
585 btfsc press_sensor_type ; New sensor found?
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
586 bra get_temperature_value2
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
587 btfsc MS5541_miso ; conversion done?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
588 return ; NO - done
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
589 rcall get_2bytes_MS5541 ; YES - read result
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
590 movff dMSB,D2+1 ; copy result to D2, high byte first
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
591 movff dLSB,D2+0 ; ... low byte second
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
592 return ; done
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
593
643
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
594 get_temperature_value2:
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
595 btfsc i2c_busy_temperature ; currently updating temperature?
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
596 return ; Yes, skip update...
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
597 movff D2_buffer+0,D2+0
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
598 movff D2_buffer+1,D2+1
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
599 movff D2_buffer+2,D2+2
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
600 return
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
601
0
heinrichsweikamp
parents:
diff changeset
602
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
603 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
604 ; Retrieve Calibration Data
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
605 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
606 ; called by start, returns in bank common
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
607 ;
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
608 global get_calibration_data
0
heinrichsweikamp
parents:
diff changeset
609 get_calibration_data:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
610 banksel isr_backup ; select bank ISR data
643
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
611 bsf block_sensor_interrupt ; disable sensor interrupts
0
heinrichsweikamp
parents:
diff changeset
612
643
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
613 btfsc press_sensor_type ; New sensor found?
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
614 call I2C_get_calib_MS5837 ; Yes, read C1 to C6
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
615 banksel isr_backup ; select bank ISR data
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
616
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
617 btfsc press_sensor_type ; New sensor found?
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
618 bra get_calibration_data2 ; Yes, skip to the end
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
619
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
620 rcall reset_MS5541 ; reset chip
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
621
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
622 movlw b'01010100' ; +3*high as start and 1+low as stop
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
623 movwf dbuffer ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
624 movlw d'13' ; send command
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
625 rcall send_data_MS5541 ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
626 rcall get_2bytes_MS5541 ; read result
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
627 movff dMSB,ir_s8_buffer+1 ; copy result, high byte first
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
628 movff dLSB,ir_s8_buffer+0 ; copy result, low byte second
0
heinrichsweikamp
parents:
diff changeset
629
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
630 movlw b'01011000' ; +3*high as start and 1+low as stop
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
631 movwf dbuffer ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
632 movlw d'13' ; send command
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
633 rcall send_data_MS5541 ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
634 rcall get_2bytes_MS5541 ; read result
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
635 movff dMSB,ir_s8_buffer+3 ; copy result, high byte first
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
636 movff dLSB,ir_s8_buffer+2 ; copy result, low byte second
0
heinrichsweikamp
parents:
diff changeset
637
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
638 movlw b'01100100' ; +3*high as start and 1+low as stop
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
639 movwf dbuffer ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
640 movlw d'13' ; send command
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
641 rcall send_data_MS5541 ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
642 rcall get_2bytes_MS5541 ; read result
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
643 movff dMSB,ir_s8_buffer+5 ; copy result, high byte first
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
644 movff dLSB,ir_s8_buffer+4 ; copy result, low byte second
0
heinrichsweikamp
parents:
diff changeset
645
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
646 movlw b'01101000' ; +3*high as start and 1+low as stop
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
647 movwf dbuffer ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
648 movlw d'13' ; send command
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
649 rcall send_data_MS5541 ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
650 rcall get_2bytes_MS5541 ; read result
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
651 movff dMSB,ir_s8_buffer+7 ; copy result, high byte first
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
652 movff dLSB,ir_s8_buffer+6 ; copy result, low byte second
0
heinrichsweikamp
parents:
diff changeset
653
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
654 ; calculate C1 (16 Bit)
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
655 movff ir_s8_buffer+1,C1+1
0
heinrichsweikamp
parents:
diff changeset
656 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
657 rrcf C1+1
heinrichsweikamp
parents:
diff changeset
658 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
659 rrcf C1+1
heinrichsweikamp
parents:
diff changeset
660 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
661 rrcf C1+1
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
662 movff ir_s8_buffer+0,C1+0
0
heinrichsweikamp
parents:
diff changeset
663 bsf STATUS,C
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
664 btfss ir_s8_buffer+1,0
0
heinrichsweikamp
parents:
diff changeset
665 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
666 rrcf C1+0
heinrichsweikamp
parents:
diff changeset
667 bsf STATUS,C
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
668 btfss ir_s8_buffer+1,1
0
heinrichsweikamp
parents:
diff changeset
669 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
670 rrcf C1+0
heinrichsweikamp
parents:
diff changeset
671 bsf STATUS,C
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
672 btfss ir_s8_buffer+1,2
0
heinrichsweikamp
parents:
diff changeset
673 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
674 rrcf C1+0
heinrichsweikamp
parents:
diff changeset
675
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
676 ; calculate C2 (16 Bit)
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
677 movff ir_s8_buffer+2, C2+0
0
heinrichsweikamp
parents:
diff changeset
678 bsf STATUS,C
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
679 btfss ir_s8_buffer+3,0
0
heinrichsweikamp
parents:
diff changeset
680 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
681 rrcf C2+0
heinrichsweikamp
parents:
diff changeset
682 bsf STATUS,C
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
683 btfss ir_s8_buffer+3,1
0
heinrichsweikamp
parents:
diff changeset
684 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
685 rrcf C2+0
heinrichsweikamp
parents:
diff changeset
686 bsf STATUS,C
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
687 btfss ir_s8_buffer+3,2
0
heinrichsweikamp
parents:
diff changeset
688 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
689 rrcf C2+0
heinrichsweikamp
parents:
diff changeset
690 bsf STATUS,C
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
691 btfss ir_s8_buffer+3,3
0
heinrichsweikamp
parents:
diff changeset
692 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
693 rrcf C2+0
heinrichsweikamp
parents:
diff changeset
694 bsf STATUS,C
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
695 btfss ir_s8_buffer+3,4
0
heinrichsweikamp
parents:
diff changeset
696 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
697 rrcf C2+0
heinrichsweikamp
parents:
diff changeset
698 bsf STATUS,C
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
699 btfss ir_s8_buffer+3,5
0
heinrichsweikamp
parents:
diff changeset
700 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
701 rrcf C2+0
heinrichsweikamp
parents:
diff changeset
702
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
703 movff ir_s8_buffer+3, C2+1
0
heinrichsweikamp
parents:
diff changeset
704 bsf STATUS,C
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
705 btfss ir_s8_buffer+0,0
0
heinrichsweikamp
parents:
diff changeset
706 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
707 rrcf C2+1
heinrichsweikamp
parents:
diff changeset
708 bsf STATUS,C
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
709 btfss ir_s8_buffer+0,1
0
heinrichsweikamp
parents:
diff changeset
710 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
711 rrcf C2+1
heinrichsweikamp
parents:
diff changeset
712 bsf STATUS,C
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
713 btfss ir_s8_buffer+0,2
0
heinrichsweikamp
parents:
diff changeset
714 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
715 rrcf C2+1
heinrichsweikamp
parents:
diff changeset
716 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
717 rrcf C2+1
heinrichsweikamp
parents:
diff changeset
718 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
719 rrcf C2+1
heinrichsweikamp
parents:
diff changeset
720 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
721 rrcf C2+1
heinrichsweikamp
parents:
diff changeset
722
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
723 ; calculate C3 (16 Bit)
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
724 movff ir_s8_buffer+5,C3+0
0
heinrichsweikamp
parents:
diff changeset
725 bsf STATUS,C
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
726 btfss ir_s8_buffer+4,7
0
heinrichsweikamp
parents:
diff changeset
727 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
728 rlcf C3+0
heinrichsweikamp
parents:
diff changeset
729 bsf STATUS,C
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
730 btfss ir_s8_buffer+4,6
0
heinrichsweikamp
parents:
diff changeset
731 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
732 rlcf C3+0
heinrichsweikamp
parents:
diff changeset
733 clrf C3+1
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
734 btfsc ir_s8_buffer+5,7
0
heinrichsweikamp
parents:
diff changeset
735 bsf C3+1,1
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
736 btfsc ir_s8_buffer+5,6
0
heinrichsweikamp
parents:
diff changeset
737 bsf C3+1,0
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
738
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
739 ; calculate C4 (16 Bit)
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
740 movff ir_s8_buffer+7,C4+0
0
heinrichsweikamp
parents:
diff changeset
741 bsf STATUS,C
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
742 btfss ir_s8_buffer+6,7
0
heinrichsweikamp
parents:
diff changeset
743 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
744 rlcf C4+0
heinrichsweikamp
parents:
diff changeset
745 clrf C4+1
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
746 btfsc ir_s8_buffer+7,7
0
heinrichsweikamp
parents:
diff changeset
747 bsf C4+1,0
heinrichsweikamp
parents:
diff changeset
748
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
749 ; C4=C4-250
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
750 movlw LOW(-.250) ; C4 - 250 --> C4
0
heinrichsweikamp
parents:
diff changeset
751 addwf C4+0,W
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
752 movwf C4+0
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
753 movlw -1 ; HIGH(- .250) is not understood...
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
754 addwfc C4+1,W
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
755 movwf C4+1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
756
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
757 ; calculate C5 (16 Bit)
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
758 movff ir_s8_buffer+4,C5+0
0
heinrichsweikamp
parents:
diff changeset
759 bcf C5+0,6
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
760 btfsc ir_s8_buffer+2,0
0
heinrichsweikamp
parents:
diff changeset
761 bsf C5+0,6
heinrichsweikamp
parents:
diff changeset
762 bcf C5+0,7
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
763 btfsc ir_s8_buffer+2,1
0
heinrichsweikamp
parents:
diff changeset
764 bsf C5+0,7
heinrichsweikamp
parents:
diff changeset
765 clrf C5+1
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
766 btfsc ir_s8_buffer+2,2
0
heinrichsweikamp
parents:
diff changeset
767 bsf C5+1,0
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
768 btfsc ir_s8_buffer+2,3
0
heinrichsweikamp
parents:
diff changeset
769 bsf C5+1,1
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
770 btfsc ir_s8_buffer+2,4
0
heinrichsweikamp
parents:
diff changeset
771 bsf C5+1,2
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
772 btfsc ir_s8_buffer+2,5
0
heinrichsweikamp
parents:
diff changeset
773 bsf C5+1,3
heinrichsweikamp
parents:
diff changeset
774
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
775 ; calculate C5 = UT1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
776 ; C5 = 8*C5 + 10000 (u16 range 10.000 .. +42.760)
0
heinrichsweikamp
parents:
diff changeset
777 clrf isr_xA+1
heinrichsweikamp
parents:
diff changeset
778 movlw d'8'
heinrichsweikamp
parents:
diff changeset
779 movwf isr_xA+0
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
780 MOVII C5,isr_xB
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
781 call isr_unsigned_mult16x16 ; isr_xA*isr_xB=isr_xC
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
782 MOVII isr_xC,C5
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
783 movlw LOW d'10000'
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
784 addwf C5+0,F
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
785 movlw HIGH d'10000'
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
786 addwfc C5+1,F ; = 8*C5 + 10000
0
heinrichsweikamp
parents:
diff changeset
787
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
788 ; calculate C6 (16Bit)
0
heinrichsweikamp
parents:
diff changeset
789 clrf C6+1
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
790 movff ir_s8_buffer+6,C6+0
0
heinrichsweikamp
parents:
diff changeset
791 bcf C6+0,7
heinrichsweikamp
parents:
diff changeset
792
643
7d8a4c60ec1a 3.15 release
heinrichsweikamp
parents: 634
diff changeset
793 get_calibration_data2:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
794 clrf sensor_state_counter ; reset state counter
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
795 bcf block_sensor_interrupt ; re-enable sensor interrupts
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
796 banksel common ; back to bank common
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
797 return ; done
0
heinrichsweikamp
parents:
diff changeset
798
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
799
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
800 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
801 ; Helper Function - Reset Chip
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
802 ;
0
heinrichsweikamp
parents:
diff changeset
803 reset_MS5541_one:
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
804 bsf MS5541_mosi ; set MOSI
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
805 bra send_clk_pulse ; send one high-low sequence on MS5541_clk and return
0
heinrichsweikamp
parents:
diff changeset
806
heinrichsweikamp
parents:
diff changeset
807 reset_MS5541_zero:
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
808 bcf MS5541_mosi ; clear MOSI
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
809 bra send_clk_pulse ; send one high-low sequence on MS5541_clk and return
0
heinrichsweikamp
parents:
diff changeset
810
heinrichsweikamp
parents:
diff changeset
811 reset_MS5541:
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
812 rcall reset_MS5541_one ; 0
0
heinrichsweikamp
parents:
diff changeset
813 rcall reset_MS5541_zero
heinrichsweikamp
parents:
diff changeset
814 rcall reset_MS5541_one
heinrichsweikamp
parents:
diff changeset
815 rcall reset_MS5541_zero
heinrichsweikamp
parents:
diff changeset
816 rcall reset_MS5541_one
heinrichsweikamp
parents:
diff changeset
817 rcall reset_MS5541_zero
heinrichsweikamp
parents:
diff changeset
818 rcall reset_MS5541_one
heinrichsweikamp
parents:
diff changeset
819 rcall reset_MS5541_zero
heinrichsweikamp
parents:
diff changeset
820 rcall reset_MS5541_one
heinrichsweikamp
parents:
diff changeset
821 rcall reset_MS5541_zero
heinrichsweikamp
parents:
diff changeset
822 rcall reset_MS5541_one
heinrichsweikamp
parents:
diff changeset
823 rcall reset_MS5541_zero
heinrichsweikamp
parents:
diff changeset
824 rcall reset_MS5541_one
heinrichsweikamp
parents:
diff changeset
825 rcall reset_MS5541_zero
heinrichsweikamp
parents:
diff changeset
826 rcall reset_MS5541_one
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
827 rcall reset_MS5541_zero ; 15
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
828 rcall reset_MS5541_zero
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
829 rcall reset_MS5541_zero
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
830 rcall reset_MS5541_zero
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
831 rcall reset_MS5541_zero
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
832 rcall reset_MS5541_zero ; 20
0
heinrichsweikamp
parents:
diff changeset
833 return
heinrichsweikamp
parents:
diff changeset
834
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
835
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
836 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
837 ; Helper Function - read 2 Byte from Chip
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
838 ;
0
heinrichsweikamp
parents:
diff changeset
839 get_2bytes_MS5541:
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
840 movlw d'8' ; load counter for 8 bit
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
841 movwf clock_count ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
842 rcall recieve_loop ; receive 8 bits
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
843 movff dbuffer,dMSB ; store result
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
844 movlw d'8' ; load counter for 8 bit
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
845 movwf clock_count ; ...
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
846 rcall recieve_loop ; receive 8 bits
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
847 movff dbuffer,dLSB ; store result
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
848 bra send_clk_pulse ; send one high-low sequence on MS5541_clk and return
0
heinrichsweikamp
parents:
diff changeset
849
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
850
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
851 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
852 ; Helper Function - read 1 Bit from Chip
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
853 ;
0
heinrichsweikamp
parents:
diff changeset
854 recieve_loop:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
855 rcall send_clk_pulse ; send one high-low sequence on MS5541_clk
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
856 btfss MS5541_miso ; read bit = 1 ? (MSB first)
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
857 bcf STATUS,C ; NO - clear carry bit
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
858 btfsc MS5541_miso ; read bit = 0 ? (MSB first)
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
859 bsf STATUS,C ; NO - set carry bit
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
860 rlcf dbuffer,F ; shift buffer
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
861 decfsz clock_count,F ; decrement counter, became zero?
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
862 bra recieve_loop ; NO - loop
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
863 return ; YES - done
0
heinrichsweikamp
parents:
diff changeset
864
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
865
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
866 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
867 ; Helper Function - send a Clock Pulse
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
868 ;
0
heinrichsweikamp
parents:
diff changeset
869 send_clk_pulse:
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
870 bsf MS5541_clk ; set clock
0
heinrichsweikamp
parents:
diff changeset
871 nop
heinrichsweikamp
parents:
diff changeset
872 nop
heinrichsweikamp
parents:
diff changeset
873 nop
heinrichsweikamp
parents:
diff changeset
874 nop
29
50c3e2c7ba7a adding cardinal (and ordinal) directions for the compass
heinrichsweikamp
parents: 0
diff changeset
875 nop
50c3e2c7ba7a adding cardinal (and ordinal) directions for the compass
heinrichsweikamp
parents: 0
diff changeset
876 nop
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
877 bcf MS5541_clk ; release clock
0
heinrichsweikamp
parents:
diff changeset
878 nop
heinrichsweikamp
parents:
diff changeset
879 nop
29
50c3e2c7ba7a adding cardinal (and ordinal) directions for the compass
heinrichsweikamp
parents: 0
diff changeset
880 nop
50c3e2c7ba7a adding cardinal (and ordinal) directions for the compass
heinrichsweikamp
parents: 0
diff changeset
881 nop
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
882 return ; done
0
heinrichsweikamp
parents:
diff changeset
883
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
884
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
885 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
886 ; Helper Function - send a Command
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
887 ;
0
heinrichsweikamp
parents:
diff changeset
888 send_data_MS5541:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
889 movwf clock_count ; from WREG
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
890 ; send three start bits first
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
891 bcf MS5541_clk ; revoke clock
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
892 nop ; wait
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
893 nop ; wait
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
894 bsf MS5541_mosi ; set MOSI
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
895 movlw d'3' ; compute total bit counter
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
896 subwf clock_count,F ; ...
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
897 rcall send_clk_pulse ; send one high-low sequence on MS5541_clk
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
898 rcall send_clk_pulse ; send one high-low sequence on MS5541_clk
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
899 rcall send_clk_pulse ; send one high-low sequence on MS5541_clk
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
900
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
901 send_data_MS5541_loop:
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
902 ; now send 8 bits from dbuffer and fill-up with zeros
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
903 bcf MS5541_clk ; revoke clock
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
904 nop ; wait
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
905 nop ; wait
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
906 btfss dbuffer,7 ; bit = 1 ? (MSB first)
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
907 bcf MS5541_mosi ; NO - clear MOSI
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
908 btfsc dbuffer,7 ; bit = 0 ? (MSB first)
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
909 bsf MS5541_mosi ; NO - set MOSI
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
910 bsf MS5541_clk ; set clock
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
911 bcf STATUS,C ; clear carry bit
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
912 rlcf dbuffer,F ; shift data byte
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
913 nop ; wait
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
914 nop ; wait
0
heinrichsweikamp
parents:
diff changeset
915 ; nop
heinrichsweikamp
parents:
diff changeset
916 ; nop
heinrichsweikamp
parents:
diff changeset
917 ; nop
heinrichsweikamp
parents:
diff changeset
918 ; nop
heinrichsweikamp
parents:
diff changeset
919 ; bcf MS5541_clk
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
920 decfsz clock_count,F ; decrement bit counter, became zero?
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
921 bra send_data_MS5541_loop ; NO - loop
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
922 bcf MS5541_clk ; YES - revoke clock
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
923 return ; - done
0
heinrichsweikamp
parents:
diff changeset
924
634
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
925 ;-----------------------------------------------------------------------------
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
926
4050675965ea 3.10 stable release
heinrichsweikamp
parents: 631
diff changeset
927 END