annotate src/ms5541.asm @ 647:357341239438

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