Mercurial > public > ostc4
annotate Small_CPU/Src/pressure.c @ 334:143fe85f82a2 v1.5.0 release
building a 1.5
author | heinrichsweikamp |
---|---|
date | Sun, 04 Aug 2019 11:01:06 +0200 |
parents | b4c578caaafb |
children | c11ce8c885d3 |
rev | line source |
---|---|
38 | 1 /** |
2 ****************************************************************************** | |
3 * @file pressure.c | |
4 * @author heinrichs weikamp gmbh | |
5 * @date 2014 | |
6 * @version V0.0.2 | |
7 * @since 20-Oct-2016 | |
8 * @brief | |
9 * | |
10 @verbatim | |
11 ============================================================================== | |
12 ##### How to use ##### | |
13 ============================================================================== | |
14 V0.0.2 18-Oct-2016 pressure_calculation_AN520_004_mod_MS5803_30BA__09_2015 | |
15 | |
16 @endverbatim | |
17 ****************************************************************************** | |
18 * @attention | |
19 * | |
20 * <h2><center>© COPYRIGHT(c) 2016 heinrichs weikamp</center></h2> | |
21 * | |
22 ****************************************************************************** | |
23 */ | |
24 | |
25 | |
26 | |
27 /* surface time | |
28 the last 30 minutes will be saved once per minute in a endless loop | |
29 at the beginning of a dive the oldest value will be used | |
30 */ | |
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
31 #include "math.h" |
241
2b9775f71e30
cleanup: factor out I2C1_Status() and cleanup type
Jan Mulder <jlmulder@xs4all.nl>
parents:
186
diff
changeset
|
32 #include "scheduler.h" |
38 | 33 #include "pressure.h" |
34 #include "i2c.h" | |
35 #include "rtc.h" | |
36 | |
37 #define CMD_RESET 0x1E // ADC reset command | |
38 #define CMD_ADC_READ 0x00 // ADC read command | |
39 #define CMD_ADC_CONV 0x40 // ADC conversion command | |
40 #define CMD_ADC_D1 0x00 // ADC D1 conversion | |
41 #define CMD_ADC_D2 0x10 // ADC D2 conversion | |
42 #define CMD_ADC_256 0x00 // ADC OSR=256 | |
43 #define CMD_ADC_512 0x02 // ADC OSR=512 | |
44 #define CMD_ADC_1024 0x04 // ADC OSR=1024 | |
45 #define CMD_ADC_2048 0x06 // ADC OSR=2056 | |
46 #define CMD_ADC_4096 0x08 // ADC OSR=4096 | |
47 #define CMD_PROM_RD 0xA0 // Prom read command | |
48 | |
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
49 #define PRESSURE_HISTORY_SIZE (8u) |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
50 #define PRESSURE_JUMP_VALID_MBAR (500.0f) /* values are measure several times a second => jumps > 5m very unlikely */ |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
51 |
186
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
52 static uint16_t get_ci_by_coef_num(uint8_t coef_num); |
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
53 //void pressure_calculation_new(void); |
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
54 //void pressure_calculation_old(void); |
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
55 static void pressure_calculation_AN520_004_mod_MS5803_30BA__09_2015(void); |
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
56 static uint8_t crc4(uint16_t n_prom[]); |
38 | 57 |
186
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
58 static HAL_StatusTypeDef pressure_sensor_get_data(void); |
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
59 static uint32_t get_adc(void); |
38 | 60 uint8_t pressureSensorInitSuccess = 0; |
61 | |
186
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
62 static uint16_t C[8] = { 1 }; |
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
63 static uint32_t D1 = 1; |
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
64 static uint32_t D2 = 1; |
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
65 static uint8_t n_crc; |
38 | 66 |
186
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
67 static int64_t C5_x_2p8 = 1; |
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
68 static int64_t C2_x_2p16 = 1; |
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
69 static int64_t C1_x_2p15 = 1; |
38 | 70 |
71 /* | |
72 short C2plus10000 = -1; | |
73 short C3plus200 = -1; | |
74 short C4minus250 = -1; | |
75 short UT1 = -1; | |
76 short C6plus100 = -1; | |
77 */ | |
78 | |
186
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
79 static float ambient_temperature = 0; |
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
80 static float ambient_pressure_mbar = 1000.0; |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
81 static float surface_pressure_mbar = 1000.0; |
186
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
82 static float surface_ring_mbar[31] = { 0 }; |
38 | 83 |
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
84 static float pressure_history_mbar[PRESSURE_HISTORY_SIZE]; |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
85 |
38 | 86 uint8_t secondCounterSurfaceRing = 0; |
87 | |
88 float get_temperature(void) | |
89 { | |
90 return ambient_temperature; | |
91 } | |
92 | |
93 float get_pressure_mbar(void) | |
94 { | |
95 return ambient_pressure_mbar; | |
96 } | |
97 | |
98 float get_surface_mbar(void) | |
99 { | |
100 return surface_pressure_mbar; | |
101 } | |
102 | |
103 | |
104 void init_surface_ring(void) | |
105 { | |
106 surface_ring_mbar[0] = 0; | |
107 for(int i=1; i<31; i++) | |
108 surface_ring_mbar[i] = ambient_pressure_mbar; | |
109 surface_pressure_mbar = ambient_pressure_mbar; | |
110 } | |
111 | |
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
112 void init_pressure_history(void) |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
113 { |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
114 for(int i=0; i<PRESSURE_HISTORY_SIZE; i++) |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
115 { |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
116 pressure_history_mbar[i] = 1000.0; |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
117 } |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
118 } |
38 | 119 |
120 /* the ring has one place with 0 | |
121 * after that comes the oldest value | |
122 * the new pressure is written in this hole | |
123 * the oldest value is read and then the new hole | |
124 */ | |
125 void update_surface_pressure(uint8_t call_rhythm_seconds) | |
126 { | |
127 secondCounterSurfaceRing += call_rhythm_seconds; | |
128 | |
129 if(secondCounterSurfaceRing < 60) | |
130 return; | |
131 | |
132 secondCounterSurfaceRing = 0; | |
133 | |
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
134 if(is_init_pressure_done()) |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
135 { |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
136 int hole; |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
137 for(hole=30;hole>0;hole--) |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
138 if(surface_ring_mbar[hole] == 0) { break; } |
38 | 139 |
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
140 surface_ring_mbar[hole] = ambient_pressure_mbar; |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
141 |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
142 hole++; |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
143 if(hole > 30) |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
144 hole = 0; |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
145 surface_pressure_mbar = surface_ring_mbar[hole]; |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
146 surface_ring_mbar[hole] = 0; |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
147 } |
38 | 148 } |
149 | |
186
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
150 #ifdef DEMOMODE |
38 | 151 float demo_modify_temperature_helper(float bottom_mbar_diff_to_surface) |
152 { | |
153 const float temperature_surface = 31.0; | |
154 const float temperature_bottom = 14.0; | |
155 | |
156 const float temperature_difference = temperature_bottom - temperature_surface; | |
157 | |
158 // range 0.0 - 1.0 | |
159 float position_now = (ambient_pressure_mbar - surface_pressure_mbar) / bottom_mbar_diff_to_surface; | |
160 | |
161 if(position_now <= 0) | |
162 return temperature_surface; | |
163 | |
164 if(position_now >= 1) | |
165 return temperature_bottom; | |
166 | |
167 return temperature_surface + (temperature_difference * position_now); | |
168 } | |
169 | |
170 | |
171 uint32_t demo_modify_temperature_and_pressure(int32_t divetime_in_seconds, uint8_t subseconds, float ceiling_mbar) | |
172 { | |
173 | |
174 const float descent_rate = 4000/60; | |
175 const float ascent_rate = 1000/60; | |
176 const uint32_t seconds_descend = (1 * 60) + 30; | |
177 const uint32_t turbo_seconds_at_bottom_start = (0 * 60) + 0; | |
178 const uint32_t seconds_descend_and_bottomtime = seconds_descend + turbo_seconds_at_bottom_start + (2 * 60) + 0; | |
179 uint32_t time_elapsed_in_seconds; | |
180 static float ambient_pressure_mbar_memory = 0; | |
181 static uint32_t time_last_call = 0; | |
182 | |
183 if(divetime_in_seconds <= seconds_descend) | |
184 { | |
185 ambient_pressure_mbar = (divetime_in_seconds * descent_rate) + ((float)(subseconds) * descent_rate) + surface_pressure_mbar; | |
186 ambient_temperature = demo_modify_temperature_helper(descent_rate * seconds_descend); | |
187 | |
188 time_last_call = divetime_in_seconds; | |
189 return 0; | |
190 } | |
191 else | |
192 if(divetime_in_seconds <= seconds_descend + turbo_seconds_at_bottom_start) | |
193 { | |
194 ambient_pressure_mbar = (seconds_descend * descent_rate) + surface_pressure_mbar; | |
195 ambient_temperature = demo_modify_temperature_helper(descent_rate * seconds_descend); | |
196 ambient_pressure_mbar_memory = ambient_pressure_mbar; | |
197 time_last_call = divetime_in_seconds; | |
198 return turbo_seconds_at_bottom_start; | |
199 } | |
200 else | |
201 if(divetime_in_seconds <= seconds_descend_and_bottomtime) | |
202 { | |
203 ambient_pressure_mbar = (seconds_descend * descent_rate) + surface_pressure_mbar; | |
204 ambient_temperature = demo_modify_temperature_helper(descent_rate * seconds_descend); | |
205 ambient_pressure_mbar_memory = ambient_pressure_mbar; | |
206 time_last_call = divetime_in_seconds; | |
207 return 0; | |
208 } | |
209 else | |
210 { | |
211 time_elapsed_in_seconds = divetime_in_seconds - time_last_call; | |
212 ambient_pressure_mbar = ambient_pressure_mbar_memory - time_elapsed_in_seconds * ascent_rate; | |
213 | |
214 if(ambient_pressure_mbar < surface_pressure_mbar) | |
215 ambient_pressure_mbar = surface_pressure_mbar; | |
216 else if(ambient_pressure_mbar < ceiling_mbar) | |
217 ambient_pressure_mbar = ceiling_mbar; | |
218 | |
219 ambient_temperature = demo_modify_temperature_helper(descent_rate * seconds_descend); | |
220 ambient_pressure_mbar_memory = ambient_pressure_mbar; | |
221 time_last_call = divetime_in_seconds; | |
222 return 0; | |
223 } | |
224 } | |
186
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
225 #endif |
38 | 226 |
227 uint8_t is_init_pressure_done(void) | |
228 { | |
229 return pressureSensorInitSuccess; | |
230 } | |
231 | |
232 uint8_t init_pressure(void) | |
233 { | |
234 uint8_t buffer[1]; | |
235 buffer[0] = 0x1e; | |
236 uint8_t retValue = 0xFF; | |
237 | |
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
238 pressureSensorInitSuccess = false; |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
239 init_pressure_history(); |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
240 |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
241 /* Send reset request to pressure sensor */ |
38 | 242 retValue = I2C_Master_Transmit( DEVICE_PRESSURE, buffer, 1); |
243 if(retValue != HAL_OK) | |
244 { | |
245 return (HAL_StatusTypeDef)retValue; | |
246 } | |
247 HAL_Delay(3); | |
248 | |
249 for(uint8_t i=0;i<8;i++) | |
250 { | |
251 C[i] = get_ci_by_coef_num(i); | |
252 } | |
253 n_crc = crc4(C); // no evaluation at the moment hw 151026 | |
254 | |
255 C5_x_2p8 = C[5] * 256; | |
256 C2_x_2p16 = C[2] * 65536; | |
257 C1_x_2p15 = C[1] * 32768; | |
258 | |
241
2b9775f71e30
cleanup: factor out I2C1_Status() and cleanup type
Jan Mulder <jlmulder@xs4all.nl>
parents:
186
diff
changeset
|
259 if(global.I2C_SystemStatus == HAL_OK) |
38 | 260 { |
261 pressureSensorInitSuccess = 1; | |
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
262 retValue = pressure_update(); |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
263 |
38 | 264 } |
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
265 return retValue; |
38 | 266 } |
267 | |
268 | |
186
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
269 static uint32_t get_adc(void) |
38 | 270 { |
271 uint8_t buffer[1]; | |
272 uint8_t resivebuf[4]; | |
273 uint32_t answer = 0; | |
186
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
274 |
38 | 275 buffer[0] = 0x00; // Get ADC |
276 I2C_Master_Transmit( DEVICE_PRESSURE, buffer, 1); | |
277 I2C_Master_Receive( DEVICE_PRESSURE, resivebuf, 4); | |
278 resivebuf[3] = 0; | |
279 answer = 256*256 *(uint32_t)resivebuf[0] + 256 * (uint32_t)resivebuf[1] + (uint32_t)resivebuf[2]; | |
280 | |
281 return answer; | |
282 } | |
283 | |
284 | |
186
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
285 static uint16_t get_ci_by_coef_num(uint8_t coef_num) |
38 | 286 { |
287 uint8_t resivebuf[2]; | |
288 | |
289 uint8_t cmd = CMD_PROM_RD+coef_num*2; | |
290 I2C_Master_Transmit( DEVICE_PRESSURE, &cmd, 1); | |
291 I2C_Master_Receive( DEVICE_PRESSURE, resivebuf, 2); | |
292 return (256*(uint16_t)resivebuf[0]) + (uint16_t)resivebuf[1]; | |
293 } | |
294 | |
295 | |
296 | |
297 uint8_t pressure_update(void) | |
298 { | |
299 HAL_StatusTypeDef statusReturn = HAL_TIMEOUT; | |
300 | |
301 statusReturn = pressure_sensor_get_data(); | |
302 pressure_calculation(); | |
303 return (uint8_t)statusReturn; | |
304 } | |
305 | |
276
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
306 /* Switch between pressure and temperature measurement with every successful read operation */ |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
307 void pressure_update_alternating(void) |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
308 { |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
309 static uint8_t getTemperature= 0; |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
310 |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
311 if(getTemperature) |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
312 { |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
313 if(pressure_sensor_get_temperature_raw() == HAL_OK) |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
314 { |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
315 getTemperature = 0; |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
316 } |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
317 } |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
318 else |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
319 { |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
320 if(pressure_sensor_get_pressure_raw() == HAL_OK) |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
321 { |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
322 getTemperature = 1; |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
323 } |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
324 } |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
325 pressure_calculation(); |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
326 return; |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
327 } |
38 | 328 |
186
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
329 static uint32_t pressure_sensor_get_one_value(uint8_t cmd, HAL_StatusTypeDef *statusReturn) |
38 | 330 { |
331 uint8_t command = CMD_ADC_CONV + cmd; | |
332 HAL_StatusTypeDef statusReturnTemp = HAL_TIMEOUT; | |
333 | |
334 statusReturnTemp = I2C_Master_Transmit( DEVICE_PRESSURE, &command, 1); | |
335 | |
336 if(statusReturn) | |
337 { | |
338 *statusReturn = statusReturnTemp; | |
339 } | |
340 | |
341 switch (cmd & 0x0f) // wait necessary conversion time | |
342 { | |
343 case CMD_ADC_256 : HAL_Delay(1); break; | |
344 case CMD_ADC_512 : HAL_Delay(3); break; | |
345 case CMD_ADC_1024: HAL_Delay(4); break; | |
346 case CMD_ADC_2048: HAL_Delay(6); break; | |
347 case CMD_ADC_4096: HAL_Delay(10); break; | |
348 } | |
349 return get_adc(); | |
350 } | |
351 | |
352 | |
186
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
353 static HAL_StatusTypeDef pressure_sensor_get_data(void) |
38 | 354 { |
276
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
355 uint32_t requestedValue = 0; |
38 | 356 HAL_StatusTypeDef statusReturn1 = HAL_TIMEOUT; |
357 HAL_StatusTypeDef statusReturn2 = HAL_TIMEOUT; | |
358 | |
276
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
359 |
38 | 360 |
276
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
361 requestedValue = pressure_sensor_get_one_value(CMD_ADC_D2 + CMD_ADC_1024, &statusReturn2); |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
362 if (statusReturn2 == HAL_OK) |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
363 { |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
364 D2 = requestedValue; |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
365 } |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
366 |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
367 requestedValue = pressure_sensor_get_one_value(CMD_ADC_D1 + CMD_ADC_1024, &statusReturn1); |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
368 if (statusReturn1 == HAL_OK) |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
369 { |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
370 D1 = requestedValue; |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
371 } |
38 | 372 if(statusReturn2 > statusReturn1) // if anything is not HAL_OK (0x00) or worse |
373 return statusReturn2; | |
374 else | |
375 return statusReturn1; | |
376 } | |
377 | |
378 | |
276
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
379 HAL_StatusTypeDef pressure_sensor_get_pressure_raw(void) |
38 | 380 { |
276
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
381 uint32_t requestedValue = 0; |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
382 HAL_StatusTypeDef statusReturn = HAL_TIMEOUT; |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
383 |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
384 requestedValue = pressure_sensor_get_one_value(CMD_ADC_D1 + CMD_ADC_1024, &statusReturn); |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
385 if (statusReturn == HAL_OK) |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
386 { |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
387 D1 = requestedValue; |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
388 } |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
389 |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
390 return statusReturn; |
38 | 391 } |
392 | |
393 | |
276
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
394 HAL_StatusTypeDef pressure_sensor_get_temperature_raw(void) |
38 | 395 { |
276
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
396 uint32_t requestedValue = 0; |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
397 HAL_StatusTypeDef statusReturn = HAL_TIMEOUT; |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
398 |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
399 requestedValue = pressure_sensor_get_one_value(CMD_ADC_D2 + CMD_ADC_1024, &statusReturn); |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
400 if (statusReturn == HAL_OK) |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
401 { |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
402 D2 = requestedValue; |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
403 } |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
404 return statusReturn; |
38 | 405 } |
406 | |
407 | |
408 void pressure_calculation(void) | |
409 { | |
241
2b9775f71e30
cleanup: factor out I2C1_Status() and cleanup type
Jan Mulder <jlmulder@xs4all.nl>
parents:
186
diff
changeset
|
410 if(global.I2C_SystemStatus != HAL_OK) |
38 | 411 return; |
412 | |
413 pressure_calculation_AN520_004_mod_MS5803_30BA__09_2015(); | |
414 } | |
415 | |
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
416 static uint8_t pressure_plausible(float pressurevalue) |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
417 { |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
418 static uint8_t pressurewriteindex = 0; |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
419 uint8_t retval = 0; |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
420 uint8_t index; |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
421 float pressure_average = 0; |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
422 |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
423 for(index = 0; index < PRESSURE_HISTORY_SIZE; index++) |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
424 { |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
425 pressure_average += pressure_history_mbar[index]; |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
426 } |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
427 pressure_average /= PRESSURE_HISTORY_SIZE; |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
428 if(pressure_average == 1000.0) /* first pressure calculation */ |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
429 { |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
430 if(fabs(pressurevalue - pressure_average) < 11000.0) /* just in case a reset occure during dive assume value equal < 100m as valid */ |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
431 { |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
432 for(index = 0; index < PRESSURE_HISTORY_SIZE; index++) |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
433 { |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
434 pressure_history_mbar[index] = pressurevalue; /* set history to current value */ |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
435 retval = 1; |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
436 } |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
437 } |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
438 } |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
439 else |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
440 { |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
441 if(fabs(pressurevalue - pressure_average) < PRESSURE_JUMP_VALID_MBAR) |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
442 pressure_history_mbar[pressurewriteindex++] = pressurevalue; |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
443 pressurewriteindex &= 0x7; /* wrap around if necessary */ |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
444 retval = 1; |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
445 } |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
446 |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
447 return retval; |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
448 } |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
449 |
186
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
450 static void pressure_calculation_AN520_004_mod_MS5803_30BA__09_2015(void) |
38 | 451 { |
452 uint32_t local_D1; // ADC value of the pressure conversion | |
453 uint32_t local_D2; // ADC value of the temperature conversion | |
454 int32_t local_Px10; // compensated pressure value | |
455 int32_t local_Tx100; // compensated temperature value | |
456 int64_t local_dT; // int32_t, difference between actual and measured temperature | |
457 int64_t local_OFF; // offset at actual temperature | |
458 int64_t local_SENS; // sensitivity at actual temperature | |
459 | |
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
460 float calc_pressure; |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
461 |
38 | 462 int64_t T2; |
463 int64_t OFF2; | |
464 int64_t SENS2; | |
465 | |
466 local_D1 = D1; | |
467 local_D2 = D2; | |
468 | |
469 local_dT = ((int64_t)local_D2) - ((int64_t)C[5]) * 256; //pow(2,8); | |
470 local_OFF = ((int64_t)C[2]) * 65536 + local_dT * ((int64_t)C[4]) / 128; // pow(2,16), pow(2,7) | |
471 local_SENS = ((int64_t)C[1]) * 32768 + local_dT * ((int64_t)C[3]) / 256; // pow(2,15), pow(2,8) | |
472 | |
473 local_Tx100 = (int32_t)(2000 + (local_dT * ((int64_t)C[6])) / 8388608);// pow(2,23) | |
474 | |
475 | |
476 if(local_Tx100 < 2000) // low temperature | |
477 { | |
478 T2 = 3 * local_dT; | |
479 T2 *= local_dT; | |
480 T2 /= 8589934592; | |
481 | |
482 OFF2 = ((int64_t)local_Tx100) - 2000; | |
483 OFF2 *= OFF2; | |
484 OFF2 *= 3; | |
485 OFF2 /= 2; | |
486 | |
487 SENS2 = ((int64_t)local_Tx100) - 2000; | |
488 SENS2 *= SENS2; | |
489 SENS2 *= 5; | |
490 SENS2 /= 8; | |
491 | |
492 local_Tx100 -= (int32_t)T2; | |
493 local_OFF -= OFF2; | |
494 local_SENS -= SENS2; | |
495 } | |
496 else | |
497 { | |
498 T2 = 7 * local_dT; | |
499 T2 *= local_dT; | |
500 T2 /= 137438953472; | |
501 | |
502 OFF2 = ((int64_t)local_Tx100) - 2000; | |
503 OFF2 *= OFF2; | |
504 OFF2 /= 16; | |
505 | |
506 local_Tx100 -= (int32_t)T2; | |
507 local_OFF -= OFF2; | |
508 } | |
509 | |
510 local_Px10 = (int32_t)( | |
511 (((int64_t)((local_D1 * local_SENS) / 2097152)) - local_OFF) | |
512 / 8192 );// )) / 10; // pow(2,21), pow(2,13) | |
513 | |
514 ambient_temperature = ((float)local_Tx100) / 100; | |
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
515 |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
516 calc_pressure = ((float)local_Px10) / 10; |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
517 if(pressure_plausible(calc_pressure)) |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
518 { |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
519 ambient_pressure_mbar = calc_pressure; |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
520 } |
38 | 521 } |
522 | |
523 | |
186
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
524 /* |
38 | 525 void pressure_calculation_new(void) |
526 { | |
527 #define POW2_8 (256) | |
528 #define POW2_17 (131072) | |
529 #define POW2_6 (64) | |
530 #define POW2_16 (65536) | |
531 #define POW2_7 (128) | |
532 #define POW2_23 (8388608) | |
533 #define POW2_21 (2097152) | |
534 #define POW2_15 (32768) | |
535 #define POW2_13 (8192) | |
536 #define POW2_37 (137438953472) | |
537 #define POW2_4 (16) | |
538 #define POW2_33 (8589934592) | |
539 #define POW2_3 (8) | |
540 | |
541 int32_t P; // compensated pressure value | |
542 int32_t T; // compensated temperature value | |
543 int32_t dT; // difference between actual and measured temperature | |
544 int64_t OFF; // offset at actual temperature | |
545 int64_t SENS; | |
546 | |
547 int32_t T2; | |
548 int64_t OFF2; | |
549 int64_t SENS2; | |
550 | |
551 dT = ((int32_t)D2) - ((int32_t)C[5]) * POW2_8; | |
552 OFF = ((int64_t)C[2]) * POW2_16 + ((int64_t)dT) * ((int64_t)C[4]) / POW2_7; | |
553 SENS = ((int64_t)C[1]) * POW2_15 + ((int64_t)dT) * ((int64_t)C[3]) / POW2_8; | |
554 | |
555 T = 2000 + (dT * ((int32_t)C[6])) / POW2_23; | |
556 | |
557 | |
558 if(T < 2000) // low temperature | |
559 { | |
560 T2 = 3 * dT * dT; | |
561 T2 /= POW2_33; | |
562 OFF2 = ((int64_t)T) - 2000; | |
563 OFF2 *= OFF2; | |
564 OFF2 *= 3; | |
565 OFF2 /= 2; | |
566 SENS2 = ((int64_t)T) - 2000; | |
567 SENS2 *= SENS2; | |
568 SENS2 *= 5; | |
569 SENS2 /= POW2_3; | |
570 } | |
571 else // high temperature | |
572 { | |
573 T2 = 7 * dT * dT; | |
574 T2 /= POW2_37; | |
575 OFF2 = ((int64_t)T) - 2000; | |
576 OFF2 *= OFF2; | |
577 OFF2 /= POW2_4; | |
578 SENS2 = 0; | |
579 } | |
580 | |
581 T = T - T2; | |
582 OFF = OFF - OFF2; | |
583 SENS = SENS - SENS2; | |
584 | |
585 P = (int32_t)(((((int64_t)D1) * SENS) / POW2_21 - OFF) / POW2_13); | |
586 | |
587 ambient_temperature = ((float)T) / 100; | |
588 ambient_pressure_mbar = ((float)P) / 10; | |
589 } | |
186
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
590 */ |
38 | 591 |
186
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
592 /* |
38 | 593 void pressure_calculation_old(void) { |
594 // | |
595 double ambient_temperature_centigrad = 0; | |
596 double ambient_pressure_decimbar = 0; | |
597 | |
598 // static for debug | |
599 static int64_t dt = 0; | |
600 static int64_t temp = 0; | |
601 static int64_t ms_off = 0; | |
602 static int64_t sens = 0; | |
603 // | |
604 static int64_t ms_off2 = 0; | |
605 static int64_t sens2 = 0; | |
606 static int64_t t2 = 0; | |
607 | |
608 if((D2 == 0) || (D1 == 0)) | |
609 return; | |
610 // | |
611 | |
612 // dT = D2 - C[5] * POW2_8; | |
613 // T = 2000 + (dT * C[6]) / POW2_23; | |
614 dt = (int64_t)D2 - C5_x_2p8; | |
615 //temp ; // in 10 milliGrad Celcius | |
616 ambient_temperature_centigrad = 2000 + dt * C[6] / 8388608; | |
617 | |
618 | |
619 if(ambient_temperature_centigrad < 2000) // low temperature | |
620 { | |
621 t2 = 3 * dt; | |
622 t2 *= dt; | |
623 t2 /= 8589934592; | |
624 ms_off2 = ambient_temperature_centigrad - 2000; | |
625 ms_off2 *= ms_off2; | |
626 sens2 = ms_off2; | |
627 ms_off2 *= 3; | |
628 ms_off2 /= 2; | |
629 sens2 *= 5; | |
630 sens2 /= 8; | |
631 } | |
632 else // high temperature | |
633 { | |
634 t2 = 7 * dt; | |
635 t2 *= dt; | |
636 t2 /= 137438953472; | |
637 ms_off2 = ambient_temperature_centigrad - 2000; | |
638 ms_off2 *= ms_off2; | |
639 ms_off2 /= 16; | |
640 sens2 = 0; | |
641 } | |
642 | |
643 | |
644 // | |
645 | |
646 // pressure | |
647 // OFF = C[2] * POW2_16 + dT * C[4] / POW2_7; | |
648 // SENS = C[1] * POW2_15 + dT * C[3] / POW2_8; | |
649 ms_off = C[4] * dt; | |
650 ms_off /= 128; | |
651 ms_off += C2_x_2p16; | |
652 // | |
653 sens = C[3] * dt; | |
654 sens /= 256; | |
655 sens += C1_x_2p15; | |
656 | |
657 // 2nd order correction | |
658 ambient_temperature_centigrad -= t2; | |
659 ms_off -= ms_off2; | |
660 sens -= sens2; | |
661 | |
662 ambient_temperature = ambient_temperature_centigrad / 100; | |
663 // P = (D1 * SENS / POW2_21 - OFF) / POW2_13; | |
664 temp = D1 * sens; | |
665 temp /= 2097152; | |
666 temp -= ms_off; | |
667 temp /= 8192; | |
668 ambient_pressure_decimbar = temp; // to float/double | |
669 ambient_pressure_mbar = ambient_pressure_decimbar / 10; | |
670 } | |
186
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
671 */ |
38 | 672 |
673 | |
674 /* taken from AN520 by meas-spec.com dated 9. Aug. 2011 | |
675 * short and int are both 16bit according to AVR/GCC google results | |
676 */ | |
186
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
677 static uint8_t crc4(uint16_t n_prom[]) |
38 | 678 { |
679 uint16_t cnt; // simple counter | |
680 uint16_t n_rem; // crc reminder | |
681 uint16_t crc_read; // original value of the crc | |
682 uint8_t n_bit; | |
683 n_rem = 0x00; | |
684 crc_read=n_prom[7]; //save read CRC | |
685 n_prom[7]=(0xFF00 & (n_prom[7])); //CRC byte is replaced by 0 | |
686 for (cnt = 0; cnt < 16; cnt++) // operation is performed on bytes | |
687 { // choose LSB or MSB | |
688 if (cnt%2==1) n_rem ^= (uint16_t) ((n_prom[cnt>>1]) & 0x00FF); | |
689 else n_rem ^= (uint16_t) (n_prom[cnt>>1]>>8); | |
690 for (n_bit = 8; n_bit > 0; n_bit--) | |
691 { | |
692 if (n_rem & (0x8000)) | |
693 { | |
694 n_rem = (n_rem << 1) ^ 0x3000; | |
695 } | |
696 else | |
697 { | |
698 n_rem = (n_rem << 1); | |
699 } | |
700 } | |
701 } | |
702 n_rem= (0x000F & (n_rem >> 12)); // // final 4-bit reminder is CRC code | |
703 n_prom[7]=crc_read; // restore the crc_read to its original place | |
704 return (n_rem ^ 0x00); | |
705 } | |
706 /* | |
707 void test_calculation(void) | |
708 { | |
709 C1 = 29112; | |
710 C2 = 26814; | |
711 C3 = 19125; | |
712 C4 = 17865; | |
713 C5 = 32057; | |
714 C6 = 31305; | |
715 | |
716 C2_x_2p16 = C2 * 65536; | |
717 C1_x_2p15 = C1 * 32768; | |
718 | |
719 D1 = 4944364; | |
720 D2 = 8198974; | |
721 pressure_calculation() ; | |
722 }; | |
723 */ | |
724 |