annotate src/ms5541.asm @ 632:0347acdf6d8e

changelog updates
author heinrichsweikamp
date Sat, 29 Feb 2020 16:57:45 +0100
parents 185ba2f91f59
children 4050675965ea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
heinrichsweikamp
parents:
diff changeset
1 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
2 ;
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
3 ; File ms5541.asm combined next generation V3.8.6
0
heinrichsweikamp
parents:
diff changeset
4 ;
heinrichsweikamp
parents:
diff changeset
5 ; Sensor subroutines
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
0
heinrichsweikamp
parents:
diff changeset
14
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
15
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
16 ms5541 CODE
0
heinrichsweikamp
parents:
diff changeset
17
heinrichsweikamp
parents:
diff changeset
18 ;=============================================================================
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
19 ; Expose internal variables to ease debug
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
20 global D1, D2
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
21 global C1, C2, C3, C4, C5, C6
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
22 global xdT, xdT2, OFF, SENS, pressure_abs_avg, temperature_avg
0
heinrichsweikamp
parents:
diff changeset
23
heinrichsweikamp
parents:
diff changeset
24 ;=============================================================================
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
25
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
26 global calculate_compensation ; called from ISR and from sleep mode, returns in bank isr_data
0
heinrichsweikamp
parents:
diff changeset
27 calculate_compensation:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
28 banksel isr_backup ; select bank ISR data
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
29
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
30 ;---- pressure sensor compensation
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
31
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
32 ; xdT = D2 - C5 (s16 range -11.400 .. +12.350)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
33 movf C5+0,W ; get value to be subtracted
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
34 subwf D2+0,W ; do the low byte
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
35 movwf xdT+0
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
36 movf C5+1,W ; do the high byte
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
37 subwfb D2+1,W
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
38 movwf xdT+1
0
heinrichsweikamp
parents:
diff changeset
39
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
40 ; second order temperature calculation
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
41
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
42 ; 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
43 rlcf xdT+0,W ; put hit bit in carry
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
44 rlcf xdT+1,W ; inject in high byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
45 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
46 clrf isr_xA+1
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
47 btfsc xdT+1,7 ; dT < 0 ?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
48 setf isr_xA+1 ; YES - sign extend to -1
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
49 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
50 call isr_signed_mult16x16 ; dT*dT --> xC (32 bits)
0
heinrichsweikamp
parents:
diff changeset
51
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
52 ; dT >= 0: divide by 8, i.e. 3 shifts rights
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
53 ; dT < 0: divide by 2, i.e. 1 shifts rights
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
54 movlw .3
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
55 btfss xdT+1,7 ; was dT negative ?
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
56 movlw .1
0
heinrichsweikamp
parents:
diff changeset
57 calc_loop_1:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
58 bcf STATUS,C ; dT^2 is positive, so injected zeros
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
59 rrcf isr_xC+1,F
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
60 rrcf isr_xC+0,F
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
61 decfsz WREG
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
62 bra calc_loop_1
0
heinrichsweikamp
parents:
diff changeset
63
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
64 movf isr_xC+0,W ; dT2 = dT - (dT/128)*(dT/128)/(2 ...or... 8)
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
65 subwf xdT+0,W
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
66 movwf xdT2+0
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
67 movf isr_xC+1,W
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
68 subwfb xdT+1,W
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
69 movwf xdT2+1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
70
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
71 ; calculate OFF = C2 + ((C4-250)*dT2)/2^12 + 10000 (range +9.246 .. +18.887)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
72 MOVII C4, isr_xA ; C4 - 250 --> A
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
73 MOVII xdT2,isr_xB ; dT2 --> B
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
74 call isr_signed_mult16x16
0
heinrichsweikamp
parents:
diff changeset
75
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
76 movlw .12-.8 ; a 12 bit shift = 1 byte + 4 bits
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
77 call isr_shift_C31
368
57e349960ef4 Additional temperature calibration via PC interface
heinrichsweikamp
parents: 353
diff changeset
78
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
79 movlw LOW(.10000) ; add 10000
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
80 addwf isr_xC+1,F
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
81 movlw HIGH(.10000)
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
82 addwfc isr_xC+2,F
0
heinrichsweikamp
parents:
diff changeset
83
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
84 movf C2+0,W ; add C2 and store result in OFF
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
85 addwf isr_xC+1,W
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
86 movwf OFF+0
0
heinrichsweikamp
parents:
diff changeset
87 movf C2+1,W
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
88 addwfc isr_xC+2,W
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
89 movwf OFF+1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
90
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
91 ; 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
92 movlw LOW(.200) ; C3+200 --> A
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
93 addwf C3+0,W
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
94 movwf isr_xA+0
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
95 movlw HIGH(.200)
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
96 addwfc C3+1,W
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
97 movwf isr_xA+1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
98 ; B still contains dT2
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
99 call isr_signed_mult16x16 ; A*B --> C
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
100 movlw .13-.8 ; A 13 bit shift = 1 byte + 5 bits
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
101 call isr_shift_C31
0
heinrichsweikamp
parents:
diff changeset
102
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
103 bcf STATUS,C ; SENS = C1 / 2
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
104 rrcf C1+1,W
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
105 movwf SENS+1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
106 rrcf C1+0,W
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
107 movwf SENS+0
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
108
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
109 movlw LOW(.3000) ; add 3000
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
110 addwf isr_xC+1,F
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
111 movlw HIGH(.3000)
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
112 addwfc isr_xC+2,F
0
heinrichsweikamp
parents:
diff changeset
113
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
114 movf isr_xC+1,W ; and sum into SENS
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
115 addwf SENS+0,F
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
116 movf isr_xC+2,W
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
117 addwfc SENS+1,F
0
heinrichsweikamp
parents:
diff changeset
118
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
119 ; calculate absolute pressure = (sens * (d1-off))/2^12 + 1000 (for MS5541C)
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
120 ; 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
121 movf OFF+0,W ; d1-off --> a
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
122 subwf D1+0,W
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
123 movwf isr_xA+0
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
124 movf OFF+1,W
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
125 subwfb D1+1,W
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
126 movwf isr_xA+1
0
heinrichsweikamp
parents:
diff changeset
127
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
128 MOVII SENS,isr_xB ; sens --> b
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
129 call isr_signed_mult16x16
630
4cd81bdbf15c 3.08 stable release
heinrichsweikamp
parents: 623
diff changeset
130 movlw .13
631
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
131 cpfslt C1+1 ; C1 > 3328 ?
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
132 bra isr_shift_ms5541_30 ; YES - MS5541-30
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
133 movlw .12-.8 ; NO - MS5541: 12 bit shift = 1 byte + 4 bits
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
134 bra isr_shift_ms5541_common
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
135 isr_shift_ms5541_30:
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
136 movlw .11-.8 ; MS5541-30: 11 bit shift = 1 byte + 3 bits
185ba2f91f59 3.09 beta 1 release
heinrichsweikamp
parents: 630
diff changeset
137 isr_shift_ms5541_common:
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
138 call isr_shift_C31
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
139 movlw LOW .1000 ; add 1000
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
140 addwf isr_xC+1,F
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
141 movlw HIGH .1000
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
142 addwfc isr_xC+2,F
0
heinrichsweikamp
parents:
diff changeset
143
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
144 ; add opt_pressure_adjust to result (SIGNED!)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
145 movff opt_pressure_adjust,isr_xC+0; get adjustment value (signed)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
146 movf isr_xC+0,F ; excite flags, opt_pressure_adjust = 0 ?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
147 bz calc_compensation_1 ; YES - skip pressure adjustment
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
148 btfss isr_xC+0,7 ; NO - opt_pressure_adjust < 0 ?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
149 bra pressure_extra_add ; NO - add offset
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
150 ;bra pressure_extra_sub ; YES - subtract offset
0
heinrichsweikamp
parents:
diff changeset
151
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
152 pressure_extra_sub:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
153 comf isr_xC+0,F ; complement opt_pressure_adjust
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
154 incf isr_xC+0,F ; ...
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
155 movlw .22 ; check for max. of 20 mbar
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
156 cpfslt isr_xC+0 ; opt_pressure_adjust < 21 mbar ?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
157 clrf isr_xC+0 ; NO - reset opt_pressure_adjust to zero
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
158 movf isr_xC+0,W ; get opt_pressure_adjust to WREG
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
159 subwf isr_xC+1,F ; pressure value -= opt_pressure_adjust, low byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
160 movlw .0 ; pressure value -= opt_pressure_adjust, high byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
161 subwfb isr_xC+2,F ; ...
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
162 bra calc_compensation_1 ; continue with checking for simulator mode
92
7ca1105751c7 add sensor calibration option (PC only), some cleanup
heinrichsweikamp
parents: 29
diff changeset
163
7ca1105751c7 add sensor calibration option (PC only), some cleanup
heinrichsweikamp
parents: 29
diff changeset
164 pressure_extra_add:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
165 movlw .21 ; check for max. of 20 mbar
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
166 cpfslt isr_xC+0 ; opt_pressure_adjust < 21 mbar ?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
167 clrf isr_xC+0 ; NO - reset opt_pressure_adjust to zero
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
168 movf isr_xC+0,W ; get opt_pressure_adjust to WREG
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
169 addwf isr_xC+1,F ; pressure value += opt_pressure_adjust, low byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
170 movlw .0 ; pressure value += opt_pressure_adjust, high byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
171 addwfc isr_xC+2,F ; ...
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
172 ;bra calc_compensation_1 ; continue with checking for simulator mode
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
173
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
174 calc_compensation_1:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
175 bcf sensor_override_active ; clear sensor override active flag by default
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
176 btfss sensor_override_request ; sensor override requested?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
177 bra calc_compensation_add_avg ; NO - keep taking absolute pressure from sensor
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
178 btfsc quit_simulatormode ; YES - shall quit simulator mode (the fast way)?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
179 bra calc_compensation_sim_quit ; YES - force pressure_rel_sim to zero
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
180 ;bra calc_compensation_sim ; NO - calculate pressure_rel_sim from simulated depth
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
181
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
182 calc_compensation_sim: ; check if OSTC got submerged
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
183 movlw .5 ; coding in high byte for 1280
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
184 cpfsgt isr_xC+2 ; absolute pressure > 1280 mbar, i.e. OSTC submerged?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
185 bra calc_compensation_sim_slave ; NO - slave pressure_rel_sim to target depth
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
186 ;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
187
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
188 calc_compensation_sim_quit:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
189 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
190 bra calc_compensation_sim_com ; continue with common part
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
191
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
192 calc_compensation_sim_slave:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
193 movf simulatormode_depth,W ; copy simulated depth to WREG
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
194 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
195 ; check if shall go up
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
196 movf pressure_rel_sim+0,W ; get relative pressure, low byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
197 subwf PRODL,W ; WREG = relative target pressure - pressure_rel_sim (low byte)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
198 movf pressure_rel_sim+1,W ; get relative pressure, high byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
199 subwfb PRODH,W ; WREG = relative target pressure - pressure_rel_sim (high byte)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
200 btfsc STATUS,N ; result < 0, i.e. pressure_rel_sim > relative target pressure ?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
201 bra calc_compensation_sim_up ; YES - decrease pressure_rel_sim
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
202 ; check if shall go down
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
203 movf PRODL,W ; get relative target pressure, low byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
204 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
205 movf PRODH,W ; get relative target pressure, high byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
206 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
207 btfsc STATUS,N ; result < 0, i.e. relative target pressure > pressure_rel_sim ?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
208 bra calc_compensation_sim_down ; YES - increase pressure_rel_sim
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
209 ; both pressures are equal
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
210 bra calc_compensation_sim_com ; NO to both - keep pressure_rel_sim as it is
0
heinrichsweikamp
parents:
diff changeset
211
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
212 calc_compensation_sim_up:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
213 movf PRODL,W ; get relative target pressure, low byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
214 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
215 movwf PRODL ; PRODL = pressure_rel_sim - relative target pressure (low byte)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
216 movf PRODH,W ; get relative target pressure, high byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
217 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
218 tstfsz WREG ; more than 255 mbar off from target?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
219 bra calc_compensation_sim_up_norm ; YES - go up with normal speed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
220 movlw simulator_ascent_threshold ; NO - get remaining difference for slowing down ascent
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
221 cpfslt PRODL ; - remaining difference to target < decrement?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
222 bra calc_compensation_sim_up_norm ; NO - go up with normal speed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
223 ;bra calc_compensation_sim_up_slow ; YES - go up with slow speed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
224
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
225 calc_compensation_sim_up_slow:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
226 DECI pressure_rel_sim ; subtract slow decrement (1 mbar) from pressure_rel_sim
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
227 bra calc_compensation_sim_com ; continue with common part
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
228
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
229 calc_compensation_sim_up_norm:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
230 SUBLI simulator_ascent_rate,pressure_rel_sim ; subtract normal decrement from pressure_rel_sim
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
231 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
232
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
233 calc_compensation_sim_down:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
234 movf pressure_rel_sim+0,W ; get relative pressure, low byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
235 subwf PRODL,F ; PRODL = relative target pressure - pressure_rel_sim (low byte)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
236 movf pressure_rel_sim+1,W ; get relative pressure, high byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
237 subwfb PRODH,W ; WREG = relative target pressure - pressure_rel_sim (high byte)
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
238 tstfsz WREG ; more than 255 mbar off from target?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
239 bra calc_compensation_sim_down_norm ; YES - go down with normal speed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
240 movlw simulator_descent_threshold ; NO - get remaining difference for slowing down descent
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
241 cpfslt PRODL ; - remaining difference to target < increment?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
242 bra calc_compensation_sim_down_norm ; NO - go down with normal speed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
243 ;bra calc_compensation_sim_down_slow ; YES - go down with slow speed
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
244
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
245 calc_compensation_sim_down_slow:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
246 INCI pressure_rel_sim ; add slow increment (1 mbar) to pressure_rel_sim
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
247 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
248
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
249 calc_compensation_sim_down_norm:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
250 ADDLI simulator_descent_rate,pressure_rel_sim ; add normal increment to pressure_rel_sim
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
251 ;bra calc_compensation_sim_com ; continue with common part
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
252
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
253 calc_compensation_sim_com:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
254 movf pressure_surf+0,W ; copy surface pressure to WREG, low byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
255 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
256 movwf isr_xC+1 ; override sensor pressure with simulated pressure, low byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
257 movf pressure_surf+1,W ; copy surface pressure to WREG, high byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
258 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
259 movwf isr_xC+2 ; override sensor pressure with simulated pressure, high byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
260 bsf sensor_override_active ; confirm sensor override is active
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
261
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
262 calc_compensation_add_avg:
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
263 ; add current absolute pressure to averaging buffer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
264 movf isr_xC+1,W ; copy current absolute pressure to WREG, low byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
265 addwf pressure_abs_avg+0,F ; pressure_abs_avg += current pressure, low byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
266 movf isr_xC+2,W ; copy current absolute pressure to WREG, high byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
267 addwfc pressure_abs_avg+1,F ; pressure_abs_avg += current pressure, high byte
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
268
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
269 ;---- temperature sensor compensation
0
heinrichsweikamp
parents:
diff changeset
270
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
271 ; calculate temp = 200 + dT*(C6+100)/2^11
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
272 movlw LOW(.100) ; C6 + 100 --> A
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
273 addwf C6+0,W
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
274 movwf isr_xA+0
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
275 movlw HIGH(.100)
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
276 addwfc C6+1,W
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
277 movwf isr_xA+1
0
heinrichsweikamp
parents:
diff changeset
278
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
279 MOVII xdT2,isr_xB ; dT2 --> B
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
280 call isr_signed_mult16x16 ; A*B
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
281 movlw .11-.8 ; a 12 bit shift = 1 byte + 3 bits
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
282 call isr_shift_C31
0
heinrichsweikamp
parents:
diff changeset
283
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
284 movlw LOW(.200) ; add 200
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
285 addwf isr_xC+1,F
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
286 movlw HIGH(.200)
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
287 addwfc isr_xC+2,F
0
heinrichsweikamp
parents:
diff changeset
288
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
289 ; add opt_temperature_adjust to result (SIGNED!)
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
290 movff opt_temperature_adjust,isr_xC+0
368
57e349960ef4 Additional temperature calibration via PC interface
heinrichsweikamp
parents: 353
diff changeset
291
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
292 btfss isr_xC+0,7 ; < 0 ?
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
293 bra temperature_extra_add ; NO
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
294 comf isr_xC+0,F ; YES
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
295 incf isr_xC+0,F
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
296 movlw .22 ; check for max. of 2.0°C
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
297 cpfslt isr_xC+0
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
298 clrf isr_xC+0
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
299 movf isr_xC+0,W ; subtract
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
300 subwf isr_xC+1,F
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
301 movlw .0
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
302 subwfb isr_xC+2,F
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
303 bra temperature_extra_common
368
57e349960ef4 Additional temperature calibration via PC interface
heinrichsweikamp
parents: 353
diff changeset
304
57e349960ef4 Additional temperature calibration via PC interface
heinrichsweikamp
parents: 353
diff changeset
305 temperature_extra_add:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
306 movlw .21 ; check for max. of 2.0°C
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
307 cpfslt isr_xC+0
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
308 clrf isr_xC+0
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
309 movf isr_xC+0,W ; add
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
310 addwf isr_xC+1,F
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
311 movlw .0
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
312 addwfc isr_xC+2,F
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
313
368
57e349960ef4 Additional temperature calibration via PC interface
heinrichsweikamp
parents: 353
diff changeset
314 temperature_extra_common:
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
315 movf isr_xC+1,W
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
316 addwf temperature_avg+0,F
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
317 movf isr_xC+2,W
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
318 addwfc temperature_avg+1,F
0
heinrichsweikamp
parents:
diff changeset
319
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
320 return ; done
0
heinrichsweikamp
parents:
diff changeset
321
heinrichsweikamp
parents:
diff changeset
322 ;=============================================================================
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
323
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
324 global get_pressure_start ; called from ISR and sleep mode, needs to be called bank isr_backup
0
heinrichsweikamp
parents:
diff changeset
325 get_pressure_start:
heinrichsweikamp
parents:
diff changeset
326 rcall reset_MS5541
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
327 movlw b'10100000' ; +3*high as start and 1+low as stop
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
328 movwf dbuffer
0
heinrichsweikamp
parents:
diff changeset
329 movlw d'12'
heinrichsweikamp
parents:
diff changeset
330 rcall send_data_MS5541
heinrichsweikamp
parents:
diff changeset
331 return
heinrichsweikamp
parents:
diff changeset
332
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
333 global get_pressure_value ; called from ISR and sleep mode, needs to be called bank isr_backup
0
heinrichsweikamp
parents:
diff changeset
334 get_pressure_value:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
335 btfsc MS5541_miso ; conversion done?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
336 return ; NO - done
0
heinrichsweikamp
parents:
diff changeset
337 rcall get_2bytes_MS5541
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
338 movff dMSB,D1+1
0
heinrichsweikamp
parents:
diff changeset
339 movff dLSB,D1+0
heinrichsweikamp
parents:
diff changeset
340 return
heinrichsweikamp
parents:
diff changeset
341
heinrichsweikamp
parents:
diff changeset
342 ;=============================================================================
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
343
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
344 global get_temperature_start ; called from ISR and sleep mode, needs to be called in bank isr_backup
0
heinrichsweikamp
parents:
diff changeset
345 get_temperature_start:
heinrichsweikamp
parents:
diff changeset
346 rcall reset_MS5541
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
347 movlw b'10010000' ; +3*high as start and 1+low as stop
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
348 movwf dbuffer
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
349 movlw d'12'
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
350 rcall send_data_MS5541
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
351 return
0
heinrichsweikamp
parents:
diff changeset
352
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
353
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
354 global get_temperature_value ; called from ISR and sleep mode, needs to be called in bank isr_backup
0
heinrichsweikamp
parents:
diff changeset
355 get_temperature_value:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
356 btfsc MS5541_miso ; conversion done?
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
357 return ; NO - done
0
heinrichsweikamp
parents:
diff changeset
358 rcall get_2bytes_MS5541
heinrichsweikamp
parents:
diff changeset
359 movff dMSB,D2+1
heinrichsweikamp
parents:
diff changeset
360 movff dLSB,D2+0
heinrichsweikamp
parents:
diff changeset
361 return
heinrichsweikamp
parents:
diff changeset
362
heinrichsweikamp
parents:
diff changeset
363 ;=============================================================================
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
364
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
365 global get_calibration_data ; called by start, returns in bank common
0
heinrichsweikamp
parents:
diff changeset
366 get_calibration_data:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
367 banksel isr_backup ; select bank ISR data
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
368 bsf block_sensor_interrupt ; disable sensor interrupts
0
heinrichsweikamp
parents:
diff changeset
369
heinrichsweikamp
parents:
diff changeset
370 rcall reset_MS5541
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
371 movlw b'01010100' ; +3*high as start and 1+low as stop
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
372 movwf dbuffer
0
heinrichsweikamp
parents:
diff changeset
373 movlw d'13'
heinrichsweikamp
parents:
diff changeset
374 rcall send_data_MS5541
heinrichsweikamp
parents:
diff changeset
375 rcall get_2bytes_MS5541
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
376 movff dMSB,ir_s8_buffer+1
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
377 movff dLSB,ir_s8_buffer+0
0
heinrichsweikamp
parents:
diff changeset
378
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
379 movlw b'01011000' ; +3*high as start and 1+low as stop
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
380 movwf dbuffer
0
heinrichsweikamp
parents:
diff changeset
381 movlw d'13'
heinrichsweikamp
parents:
diff changeset
382 rcall send_data_MS5541
heinrichsweikamp
parents:
diff changeset
383 rcall get_2bytes_MS5541
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
384 movff dMSB,ir_s8_buffer+3
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
385 movff dLSB,ir_s8_buffer+2
0
heinrichsweikamp
parents:
diff changeset
386
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
387 movlw b'01100100' ; +3*high as start and 1+low as stop
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
388 movwf dbuffer
0
heinrichsweikamp
parents:
diff changeset
389 movlw d'13'
heinrichsweikamp
parents:
diff changeset
390 rcall send_data_MS5541
heinrichsweikamp
parents:
diff changeset
391 rcall get_2bytes_MS5541
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
392 movff dMSB,ir_s8_buffer+5
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
393 movff dLSB,ir_s8_buffer+4
0
heinrichsweikamp
parents:
diff changeset
394
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
395 movlw b'01101000' ; +3*high as start and 1+low as stop
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
396 movwf dbuffer
0
heinrichsweikamp
parents:
diff changeset
397 movlw d'13'
heinrichsweikamp
parents:
diff changeset
398 rcall send_data_MS5541
heinrichsweikamp
parents:
diff changeset
399 rcall get_2bytes_MS5541
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
400 movff dMSB,ir_s8_buffer+7
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
401 movff dLSB,ir_s8_buffer+6
0
heinrichsweikamp
parents:
diff changeset
402
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
403 ; calculate C1 (16Bit)
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
404 movff ir_s8_buffer+1, C1+1
0
heinrichsweikamp
parents:
diff changeset
405 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
406 rrcf C1+1
heinrichsweikamp
parents:
diff changeset
407 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
408 rrcf C1+1
heinrichsweikamp
parents:
diff changeset
409 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
410 rrcf C1+1
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
411 movff ir_s8_buffer+0, C1+0
0
heinrichsweikamp
parents:
diff changeset
412 bsf STATUS,C
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
413 btfss ir_s8_buffer+1,0
0
heinrichsweikamp
parents:
diff changeset
414 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
415 rrcf C1+0
heinrichsweikamp
parents:
diff changeset
416 bsf STATUS,C
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
417 btfss ir_s8_buffer+1,1
0
heinrichsweikamp
parents:
diff changeset
418 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
419 rrcf C1+0
heinrichsweikamp
parents:
diff changeset
420 bsf STATUS,C
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
421 btfss ir_s8_buffer+1,2
0
heinrichsweikamp
parents:
diff changeset
422 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
423 rrcf C1+0
heinrichsweikamp
parents:
diff changeset
424
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
425 ; calculate C2 (16Bit)
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
426 movff ir_s8_buffer+2, C2+0
0
heinrichsweikamp
parents:
diff changeset
427 bsf STATUS,C
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
428 btfss ir_s8_buffer+3,0
0
heinrichsweikamp
parents:
diff changeset
429 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
430 rrcf C2+0
heinrichsweikamp
parents:
diff changeset
431 bsf STATUS,C
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
432 btfss ir_s8_buffer+3,1
0
heinrichsweikamp
parents:
diff changeset
433 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
434 rrcf C2+0
heinrichsweikamp
parents:
diff changeset
435 bsf STATUS,C
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
436 btfss ir_s8_buffer+3,2
0
heinrichsweikamp
parents:
diff changeset
437 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
438 rrcf C2+0
heinrichsweikamp
parents:
diff changeset
439 bsf STATUS,C
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
440 btfss ir_s8_buffer+3,3
0
heinrichsweikamp
parents:
diff changeset
441 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
442 rrcf C2+0
heinrichsweikamp
parents:
diff changeset
443 bsf STATUS,C
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
444 btfss ir_s8_buffer+3,4
0
heinrichsweikamp
parents:
diff changeset
445 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
446 rrcf C2+0
heinrichsweikamp
parents:
diff changeset
447 bsf STATUS,C
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
448 btfss ir_s8_buffer+3,5
0
heinrichsweikamp
parents:
diff changeset
449 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
450 rrcf C2+0
heinrichsweikamp
parents:
diff changeset
451
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
452 movff ir_s8_buffer+3, C2+1
0
heinrichsweikamp
parents:
diff changeset
453 bsf STATUS,C
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
454 btfss ir_s8_buffer+0,0
0
heinrichsweikamp
parents:
diff changeset
455 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
456 rrcf C2+1
heinrichsweikamp
parents:
diff changeset
457 bsf STATUS,C
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
458 btfss ir_s8_buffer+0,1
0
heinrichsweikamp
parents:
diff changeset
459 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
460 rrcf C2+1
heinrichsweikamp
parents:
diff changeset
461 bsf STATUS,C
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
462 btfss ir_s8_buffer+0,2
0
heinrichsweikamp
parents:
diff changeset
463 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
464 rrcf C2+1
heinrichsweikamp
parents:
diff changeset
465 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
466 rrcf C2+1
heinrichsweikamp
parents:
diff changeset
467 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
468 rrcf C2+1
heinrichsweikamp
parents:
diff changeset
469 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
470 rrcf C2+1
heinrichsweikamp
parents:
diff changeset
471
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
472 ; calculate C3 (16Bit)
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
473 movff ir_s8_buffer+5,C3+0
0
heinrichsweikamp
parents:
diff changeset
474 bsf STATUS,C
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
475 btfss ir_s8_buffer+4,7
0
heinrichsweikamp
parents:
diff changeset
476 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
477 rlcf C3+0
heinrichsweikamp
parents:
diff changeset
478 bsf STATUS,C
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
479 btfss ir_s8_buffer+4,6
0
heinrichsweikamp
parents:
diff changeset
480 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
481 rlcf C3+0
heinrichsweikamp
parents:
diff changeset
482 clrf C3+1
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
483 btfsc ir_s8_buffer+5,7
0
heinrichsweikamp
parents:
diff changeset
484 bsf C3+1,1
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
485 btfsc ir_s8_buffer+5,6
0
heinrichsweikamp
parents:
diff changeset
486 bsf C3+1,0
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
487
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
488 ; calculate C4 (16Bit)
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
489 movff ir_s8_buffer+7,C4+0
0
heinrichsweikamp
parents:
diff changeset
490 bsf STATUS,C
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
491 btfss ir_s8_buffer+6,7
0
heinrichsweikamp
parents:
diff changeset
492 bcf STATUS,C
heinrichsweikamp
parents:
diff changeset
493 rlcf C4+0
heinrichsweikamp
parents:
diff changeset
494 clrf C4+1
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
495 btfsc ir_s8_buffer+7,7
0
heinrichsweikamp
parents:
diff changeset
496 bsf C4+1,0
heinrichsweikamp
parents:
diff changeset
497
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
498 ; C4=C4-250
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
499 movlw LOW(-.250) ; C4 - 250 --> C4
0
heinrichsweikamp
parents:
diff changeset
500 addwf C4+0,W
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
501 movwf C4+0
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
502 movlw -1 ; HIGH(- .250) is not understood...
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
503 addwfc C4+1,W
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
504 movwf C4+1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
505
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
506 ; calculate C5 (16Bit)
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
507 movff ir_s8_buffer+4,C5+0
0
heinrichsweikamp
parents:
diff changeset
508 bcf C5+0,6
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
509 btfsc ir_s8_buffer+2,0
0
heinrichsweikamp
parents:
diff changeset
510 bsf C5+0,6
heinrichsweikamp
parents:
diff changeset
511 bcf C5+0,7
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
512 btfsc ir_s8_buffer+2,1
0
heinrichsweikamp
parents:
diff changeset
513 bsf C5+0,7
heinrichsweikamp
parents:
diff changeset
514 clrf C5+1
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
515 btfsc ir_s8_buffer+2,2
0
heinrichsweikamp
parents:
diff changeset
516 bsf C5+1,0
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
517 btfsc ir_s8_buffer+2,3
0
heinrichsweikamp
parents:
diff changeset
518 bsf C5+1,1
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
519 btfsc ir_s8_buffer+2,4
0
heinrichsweikamp
parents:
diff changeset
520 bsf C5+1,2
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
521 btfsc ir_s8_buffer+2,5
0
heinrichsweikamp
parents:
diff changeset
522 bsf C5+1,3
heinrichsweikamp
parents:
diff changeset
523
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
524 ; calculate C5 = UT1
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
525 ; C5 = 8*C5 + 10000 (u16 range 10.000 .. +42.760)
0
heinrichsweikamp
parents:
diff changeset
526 clrf isr_xA+1
heinrichsweikamp
parents:
diff changeset
527 movlw d'8'
heinrichsweikamp
parents:
diff changeset
528 movwf isr_xA+0
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
529 MOVII C5,isr_xB
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
530 call isr_unsigned_mult16x16 ; isr_xA*isr_xB=isr_xC
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
531 MOVII isr_xC,C5
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
532 movlw LOW d'10000'
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
533 addwf C5+0,F
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
534 movlw HIGH d'10000'
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
535 addwfc C5+1,F ; = 8*C5 + 10000
0
heinrichsweikamp
parents:
diff changeset
536
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
537 ; calculate C6 (16Bit)
0
heinrichsweikamp
parents:
diff changeset
538 clrf C6+1
255
ad62dff7739a add bearing option to compass
heinrichsweikamp
parents: 178
diff changeset
539 movff ir_s8_buffer+6,C6+0
0
heinrichsweikamp
parents:
diff changeset
540 bcf C6+0,7
heinrichsweikamp
parents:
diff changeset
541
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
542 clrf sensor_state_counter ; reset state counter
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
543 bcf block_sensor_interrupt ; re-enable sensor interrupts
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
544 banksel common ; back to bank common
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
545 return ; done
0
heinrichsweikamp
parents:
diff changeset
546
heinrichsweikamp
parents:
diff changeset
547 ;=============================================================================
heinrichsweikamp
parents:
diff changeset
548 reset_MS5541_one:
heinrichsweikamp
parents:
diff changeset
549 bsf MS5541_mosi
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
550 bra send_clk_pulse ; send one high-low sequence on MS5541_clk and return
0
heinrichsweikamp
parents:
diff changeset
551
heinrichsweikamp
parents:
diff changeset
552 reset_MS5541_zero:
heinrichsweikamp
parents:
diff changeset
553 bcf MS5541_mosi
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
554 bra send_clk_pulse ; send one high-low sequence on MS5541_clk and return
0
heinrichsweikamp
parents:
diff changeset
555
heinrichsweikamp
parents:
diff changeset
556 reset_MS5541:
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
557 rcall reset_MS5541_one ; 0
0
heinrichsweikamp
parents:
diff changeset
558 rcall reset_MS5541_zero
heinrichsweikamp
parents:
diff changeset
559 rcall reset_MS5541_one
heinrichsweikamp
parents:
diff changeset
560 rcall reset_MS5541_zero
heinrichsweikamp
parents:
diff changeset
561 rcall reset_MS5541_one
heinrichsweikamp
parents:
diff changeset
562 rcall reset_MS5541_zero
heinrichsweikamp
parents:
diff changeset
563 rcall reset_MS5541_one
heinrichsweikamp
parents:
diff changeset
564 rcall reset_MS5541_zero
heinrichsweikamp
parents:
diff changeset
565 rcall reset_MS5541_one
heinrichsweikamp
parents:
diff changeset
566 rcall reset_MS5541_zero
heinrichsweikamp
parents:
diff changeset
567 rcall reset_MS5541_one
heinrichsweikamp
parents:
diff changeset
568 rcall reset_MS5541_zero
heinrichsweikamp
parents:
diff changeset
569 rcall reset_MS5541_one
heinrichsweikamp
parents:
diff changeset
570 rcall reset_MS5541_zero
heinrichsweikamp
parents:
diff changeset
571 rcall reset_MS5541_one
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
572 rcall reset_MS5541_zero ; 15
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
573 rcall reset_MS5541_zero
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
574 rcall reset_MS5541_zero
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
575 rcall reset_MS5541_zero
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
576 rcall reset_MS5541_zero
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
577 rcall reset_MS5541_zero ; 20
0
heinrichsweikamp
parents:
diff changeset
578 return
heinrichsweikamp
parents:
diff changeset
579
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
580
0
heinrichsweikamp
parents:
diff changeset
581 get_2bytes_MS5541:
heinrichsweikamp
parents:
diff changeset
582 movlw d'8'
heinrichsweikamp
parents:
diff changeset
583 movwf clock_count
heinrichsweikamp
parents:
diff changeset
584 rcall recieve_loop
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
585 movff dbuffer,dMSB
0
heinrichsweikamp
parents:
diff changeset
586 movlw d'8'
heinrichsweikamp
parents:
diff changeset
587 movwf clock_count
heinrichsweikamp
parents:
diff changeset
588 rcall recieve_loop
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
589 movff dbuffer,dLSB
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
590 bra send_clk_pulse ; send one high-low sequence on MS5541_clk and return
0
heinrichsweikamp
parents:
diff changeset
591
heinrichsweikamp
parents:
diff changeset
592 recieve_loop:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
593 rcall send_clk_pulse ; send one high-low sequence on MS5541_clk
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
594 btfss MS5541_miso ; MSB first
0
heinrichsweikamp
parents:
diff changeset
595 bcf STATUS,C
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
596 btfsc MS5541_miso ; MSB first
0
heinrichsweikamp
parents:
diff changeset
597 bsf STATUS,C
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
598 rlcf dbuffer,F
0
heinrichsweikamp
parents:
diff changeset
599 decfsz clock_count,F
heinrichsweikamp
parents:
diff changeset
600 bra recieve_loop
heinrichsweikamp
parents:
diff changeset
601 return
heinrichsweikamp
parents:
diff changeset
602
heinrichsweikamp
parents:
diff changeset
603 send_clk_pulse:
heinrichsweikamp
parents:
diff changeset
604 bsf MS5541_clk
heinrichsweikamp
parents:
diff changeset
605 nop
heinrichsweikamp
parents:
diff changeset
606 nop
heinrichsweikamp
parents:
diff changeset
607 nop
heinrichsweikamp
parents:
diff changeset
608 nop
29
50c3e2c7ba7a adding cardinal (and ordinal) directions for the compass
heinrichsweikamp
parents: 0
diff changeset
609 nop
50c3e2c7ba7a adding cardinal (and ordinal) directions for the compass
heinrichsweikamp
parents: 0
diff changeset
610 nop
0
heinrichsweikamp
parents:
diff changeset
611 bcf MS5541_clk
heinrichsweikamp
parents:
diff changeset
612 nop
heinrichsweikamp
parents:
diff changeset
613 nop
29
50c3e2c7ba7a adding cardinal (and ordinal) directions for the compass
heinrichsweikamp
parents: 0
diff changeset
614 nop
50c3e2c7ba7a adding cardinal (and ordinal) directions for the compass
heinrichsweikamp
parents: 0
diff changeset
615 nop
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
616 return
0
heinrichsweikamp
parents:
diff changeset
617
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
618
0
heinrichsweikamp
parents:
diff changeset
619 send_data_MS5541:
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
620 movwf clock_count ; from WREG
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
621 ; send three start bits first
0
heinrichsweikamp
parents:
diff changeset
622 bcf MS5541_clk
29
50c3e2c7ba7a adding cardinal (and ordinal) directions for the compass
heinrichsweikamp
parents: 0
diff changeset
623 nop
50c3e2c7ba7a adding cardinal (and ordinal) directions for the compass
heinrichsweikamp
parents: 0
diff changeset
624 nop
0
heinrichsweikamp
parents:
diff changeset
625 bsf MS5541_mosi
heinrichsweikamp
parents:
diff changeset
626 movlw d'3'
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
627 subwf clock_count,F ; total bit counter
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
628 rcall send_clk_pulse ; send one high-low sequence on MS5541_clk
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
629 rcall send_clk_pulse ; send one high-low sequence on MS5541_clk
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
630 rcall send_clk_pulse ; send one high-low sequence on MS5541_clk
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
631 send_data_MS5541_loop: ; now send 8 bits from dbuffer and fill-up with zeros
0
heinrichsweikamp
parents:
diff changeset
632 bcf MS5541_clk
29
50c3e2c7ba7a adding cardinal (and ordinal) directions for the compass
heinrichsweikamp
parents: 0
diff changeset
633 nop
50c3e2c7ba7a adding cardinal (and ordinal) directions for the compass
heinrichsweikamp
parents: 0
diff changeset
634 nop
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
635 btfss dbuffer,7 ; MSB first
0
heinrichsweikamp
parents:
diff changeset
636 bcf MS5541_mosi
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
637 btfsc dbuffer,7 ; MSB first
0
heinrichsweikamp
parents:
diff changeset
638 bsf MS5541_mosi
heinrichsweikamp
parents:
diff changeset
639 bsf MS5541_clk
heinrichsweikamp
parents:
diff changeset
640 bcf STATUS,C
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
641 rlcf dbuffer,F
29
50c3e2c7ba7a adding cardinal (and ordinal) directions for the compass
heinrichsweikamp
parents: 0
diff changeset
642 nop
50c3e2c7ba7a adding cardinal (and ordinal) directions for the compass
heinrichsweikamp
parents: 0
diff changeset
643 nop
0
heinrichsweikamp
parents:
diff changeset
644 ; nop
heinrichsweikamp
parents:
diff changeset
645 ; nop
heinrichsweikamp
parents:
diff changeset
646 ; nop
heinrichsweikamp
parents:
diff changeset
647 ; nop
heinrichsweikamp
parents:
diff changeset
648 ; bcf MS5541_clk
heinrichsweikamp
parents:
diff changeset
649 decfsz clock_count,F
623
c40025d8e750 3.03 beta released
heinrichsweikamp
parents: 604
diff changeset
650 bra send_data_MS5541_loop
0
heinrichsweikamp
parents:
diff changeset
651 bcf MS5541_clk
heinrichsweikamp
parents:
diff changeset
652 return
heinrichsweikamp
parents:
diff changeset
653
604
ca4556fb60b9 bump to 2.99beta, work on 3.00 stable
heinrichsweikamp
parents: 368
diff changeset
654 END