Mercurial > public > ostc4
annotate Small_CPU/Src/pressure.c @ 474:4be72d55b09a Improve_Button_Sleep
Added error detection for reading of ADC values in sleep mode:
ADC value were used for pressure calculation without making sure that the I2C operations used for reading the values were called successfully. As result a invalid pressure could be calculated causing the OSTC to wakeup or (worstcase) to enter dive mode. To avoid this the return values are now evaluated and pressure calculation is only done if I2C signaled no error during transmission
author | ideenmodellierer |
---|---|
date | Tue, 12 May 2020 22:42:52 +0200 |
parents | 6f30f2011667 |
children | 4b9427ae0a65 |
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 | |
352 | 49 /* remove comment to use a predefined profile for pressure changes instead of real world data */ |
50 /* #define SIMULATE_PRESSURE */ | |
51 | |
52 #define PRESSURE_SURFACE_MAX_MBAR (1030.0f) /* It is unlikely that pressure at surface is greater than this value => clip to it */ | |
53 #define PRESSURE_HISTORY_SIZE (8u) | |
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
54 |
352 | 55 #define PRESSURE_SURFACE_QUE (30u) /* history buffer [minutes] for past pressure measurements */ |
56 #define PRESSURE_SURFACE_EVA_WINDOW (15u) /* Number of entries evaluated during instability test. Used to avoid detection while dive enters water */ | |
57 #define PRESSURE_SURFACE_STABLE_LIMIT (10u) /* Define pressure as stable if delta (mBar) is below this value */ | |
58 #define PRESSURE_SURFACE_DETECT_STABLE_CNT (5u) /* Event count to detect stable condition */ | |
59 #define PRESSURE_SURFACE_UNSTABLE_LIMIT (50u) /* Define pressure as not stable if delta (mBar) is larger than this value */ | |
60 #define PRESSURE_SURFACE_DETECT_UNSTABLE_CNT (3u) /* Event count to detect unstable condition */ | |
61 | |
335
c11ce8c885d3
Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents:
331
diff
changeset
|
62 |
356 | 63 static uint8_t PRESSURE_ADDRESS = DEVICE_PRESSURE_MS5803; /* Default Address */ |
64 | |
186
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
65 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
|
66 //void pressure_calculation_new(void); |
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
67 //void pressure_calculation_old(void); |
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
68 static void pressure_calculation_AN520_004_mod_MS5803_30BA__09_2015(void); |
356 | 69 //static uint8_t crc4(uint16_t n_prom[]); |
38 | 70 |
186
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
71 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
|
72 static uint32_t get_adc(void); |
38 | 73 uint8_t pressureSensorInitSuccess = 0; |
74 | |
186
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
75 static uint16_t C[8] = { 1 }; |
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
76 static uint32_t D1 = 1; |
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
77 static uint32_t D2 = 1; |
356 | 78 //static uint8_t n_crc; |
38 | 79 |
186
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
80 static int64_t C5_x_2p8 = 1; |
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
81 static int64_t C2_x_2p16 = 1; |
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
82 static int64_t C1_x_2p15 = 1; |
38 | 83 |
84 /* | |
85 short C2plus10000 = -1; | |
86 short C3plus200 = -1; | |
87 short C4minus250 = -1; | |
88 short UT1 = -1; | |
89 short C6plus100 = -1; | |
90 */ | |
339
37f45300bc2e
Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents:
335
diff
changeset
|
91 static float pressure_offset = 0.0; /* Offset value which may be specified by the user via PC Software */ |
37f45300bc2e
Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents:
335
diff
changeset
|
92 static float temperature_offset = 0.0; /* Offset value which may be specified by the user via PC Software */ |
38 | 93 |
186
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
94 static float ambient_temperature = 0; |
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
95 static float ambient_pressure_mbar = 1000.0; |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
96 static float surface_pressure_mbar = 1000.0; |
335
c11ce8c885d3
Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents:
331
diff
changeset
|
97 static float surface_ring_mbar[PRESSURE_SURFACE_QUE] = { 0 }; |
38 | 98 |
352 | 99 static uint8_t surface_pressure_writeIndex = 0; |
100 static float surface_pressure_stable_value = 0; | |
101 static uint8_t surface_pressure_stable = 0; | |
102 | |
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
103 static float pressure_history_mbar[PRESSURE_HISTORY_SIZE]; |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
104 |
339
37f45300bc2e
Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents:
335
diff
changeset
|
105 static uint8_t secondCounterSurfaceRing = 0; |
37f45300bc2e
Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents:
335
diff
changeset
|
106 static uint8_t avgCount = 0; |
37f45300bc2e
Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents:
335
diff
changeset
|
107 static float runningAvg = 0; |
38 | 108 |
109 float get_temperature(void) | |
110 { | |
111 return ambient_temperature; | |
112 } | |
113 | |
114 float get_pressure_mbar(void) | |
115 { | |
116 return ambient_pressure_mbar; | |
117 } | |
118 | |
119 float get_surface_mbar(void) | |
120 { | |
121 return surface_pressure_mbar; | |
122 } | |
123 | |
124 | |
339
37f45300bc2e
Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents:
335
diff
changeset
|
125 void init_surface_ring(uint8_t force) |
38 | 126 { |
339
37f45300bc2e
Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents:
335
diff
changeset
|
127 if((surface_ring_mbar[0] == 0) || (force)) /* only initialize once. Keep value in place in case of an i2c recovery */ |
335
c11ce8c885d3
Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents:
331
diff
changeset
|
128 { |
339
37f45300bc2e
Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents:
335
diff
changeset
|
129 secondCounterSurfaceRing = 0; /* restart calculation */ |
37f45300bc2e
Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents:
335
diff
changeset
|
130 avgCount = 0; |
37f45300bc2e
Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents:
335
diff
changeset
|
131 runningAvg = 0; |
37f45300bc2e
Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents:
335
diff
changeset
|
132 |
335
c11ce8c885d3
Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents:
331
diff
changeset
|
133 for(int i=0; i<PRESSURE_SURFACE_QUE; i++) |
c11ce8c885d3
Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents:
331
diff
changeset
|
134 surface_ring_mbar[i] = ambient_pressure_mbar; |
c11ce8c885d3
Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents:
331
diff
changeset
|
135 surface_pressure_mbar = ambient_pressure_mbar; |
352 | 136 surface_pressure_writeIndex = 0; /* index of the oldest value in the ring buffer */ |
335
c11ce8c885d3
Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents:
331
diff
changeset
|
137 } |
38 | 138 } |
139 | |
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
140 void init_pressure_history(void) |
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 for(int i=0; i<PRESSURE_HISTORY_SIZE; i++) |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
143 { |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
144 pressure_history_mbar[i] = 1000.0; |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
145 } |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
146 } |
38 | 147 |
352 | 148 uint8_t is_surface_pressure_stable(void) |
149 { | |
150 return surface_pressure_stable; | |
151 } | |
335
c11ce8c885d3
Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents:
331
diff
changeset
|
152 |
352 | 153 float set_last_surface_pressure_stable(void) |
154 { | |
155 surface_pressure_mbar = surface_pressure_stable_value; | |
156 return surface_pressure_stable_value; | |
157 } | |
158 | |
159 /* iterate backward through the history memory and evaluate the changes pressure changes during the last 30 minutes */ | |
160 void evaluate_surface_pressure() | |
161 { | |
162 uint8_t index; | |
163 float lastvalue; | |
164 uint8_t stablecnt = 0; | |
165 uint8_t unstablecnt = 0; | |
166 uint8_t EvaluationWindow = PRESSURE_SURFACE_QUE - PRESSURE_SURFACE_EVA_WINDOW; /* do not use the latest 15 values to avoid unstable condition due to something like fin handling */ | |
167 uint8_t EvaluatedValues = 0; | |
168 | |
169 lastvalue = surface_ring_mbar[surface_pressure_writeIndex]; | |
170 surface_pressure_stable_value = surface_ring_mbar[surface_pressure_writeIndex]; /* default: if no stable value is found return the oldest value */ | |
171 index = surface_pressure_writeIndex; | |
172 surface_pressure_stable = 1; | |
173 | |
174 if(index == 0) | |
175 { | |
176 index = PRESSURE_SURFACE_QUE - 1; | |
177 } | |
178 else | |
179 { | |
180 index = index - 1; | |
181 } | |
182 do | |
183 { | |
184 if((EvaluatedValues < EvaluationWindow) && | |
185 (fabs(surface_pressure_stable_value - surface_ring_mbar[index]) > PRESSURE_SURFACE_UNSTABLE_LIMIT)) /* unusual change during last 30 minutes */ | |
186 { | |
187 unstablecnt++; | |
188 if(unstablecnt > PRESSURE_SURFACE_DETECT_UNSTABLE_CNT) | |
189 { | |
190 surface_pressure_stable = 0; | |
191 } | |
192 } | |
193 /* search for a value which does not change for several iterations */ | |
194 if (fabs(lastvalue - surface_ring_mbar[index]) < PRESSURE_SURFACE_STABLE_LIMIT) | |
195 { | |
196 stablecnt++; | |
197 } | |
198 else | |
199 { | |
200 stablecnt = 0; | |
201 } | |
202 if ((stablecnt >= PRESSURE_SURFACE_DETECT_STABLE_CNT) && (surface_pressure_stable == 0)&&(surface_pressure_stable_value == surface_ring_mbar[surface_pressure_writeIndex])) /* pressure is unstable => search for new stable value */ | |
203 { | |
204 surface_pressure_stable_value = surface_ring_mbar[index]; | |
205 unstablecnt = 0; | |
206 } | |
207 | |
208 lastvalue = surface_ring_mbar[index]; | |
209 | |
210 if(index == 0) | |
211 { | |
212 index = PRESSURE_SURFACE_QUE - 1; | |
213 } | |
214 else | |
215 { | |
216 index = index - 1; | |
217 } | |
218 EvaluatedValues++; | |
219 } while (index != surface_pressure_writeIndex); | |
220 } | |
38 | 221 void update_surface_pressure(uint8_t call_rhythm_seconds) |
222 { | |
339
37f45300bc2e
Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents:
335
diff
changeset
|
223 |
335
c11ce8c885d3
Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents:
331
diff
changeset
|
224 |
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
225 if(is_init_pressure_done()) |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
226 { |
335
c11ce8c885d3
Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents:
331
diff
changeset
|
227 runningAvg = (runningAvg * avgCount + ambient_pressure_mbar) / (avgCount +1); |
c11ce8c885d3
Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents:
331
diff
changeset
|
228 avgCount++; |
c11ce8c885d3
Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents:
331
diff
changeset
|
229 secondCounterSurfaceRing += call_rhythm_seconds; |
38 | 230 |
335
c11ce8c885d3
Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents:
331
diff
changeset
|
231 if(secondCounterSurfaceRing >= 60) |
c11ce8c885d3
Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents:
331
diff
changeset
|
232 { |
339
37f45300bc2e
Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents:
335
diff
changeset
|
233 if(runningAvg < PRESSURE_SURFACE_MAX_MBAR) |
37f45300bc2e
Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents:
335
diff
changeset
|
234 { |
352 | 235 surface_ring_mbar[surface_pressure_writeIndex] = runningAvg; |
339
37f45300bc2e
Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents:
335
diff
changeset
|
236 } |
37f45300bc2e
Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents:
335
diff
changeset
|
237 else |
37f45300bc2e
Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents:
335
diff
changeset
|
238 { |
352 | 239 surface_ring_mbar[surface_pressure_writeIndex] = PRESSURE_SURFACE_MAX_MBAR; |
339
37f45300bc2e
Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents:
335
diff
changeset
|
240 } |
352 | 241 surface_pressure_writeIndex++; /* the write index is now pointing to the oldest value in the buffer which will be overwritten next time */ |
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
242 |
352 | 243 if(surface_pressure_writeIndex == PRESSURE_SURFACE_QUE) |
335
c11ce8c885d3
Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents:
331
diff
changeset
|
244 { |
352 | 245 surface_pressure_writeIndex = 0; |
335
c11ce8c885d3
Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents:
331
diff
changeset
|
246 } |
c11ce8c885d3
Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents:
331
diff
changeset
|
247 |
352 | 248 surface_pressure_mbar = surface_ring_mbar[surface_pressure_writeIndex]; /* 30 minutes old measurement */ |
335
c11ce8c885d3
Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents:
331
diff
changeset
|
249 |
c11ce8c885d3
Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents:
331
diff
changeset
|
250 secondCounterSurfaceRing = 0; |
c11ce8c885d3
Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents:
331
diff
changeset
|
251 avgCount = 1; /* use the current value as starting point but restart the weight decrement of the measurements */ |
c11ce8c885d3
Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents:
331
diff
changeset
|
252 } |
352 | 253 evaluate_surface_pressure(); |
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
254 } |
38 | 255 } |
256 | |
186
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
257 #ifdef DEMOMODE |
38 | 258 float demo_modify_temperature_helper(float bottom_mbar_diff_to_surface) |
259 { | |
260 const float temperature_surface = 31.0; | |
261 const float temperature_bottom = 14.0; | |
262 | |
263 const float temperature_difference = temperature_bottom - temperature_surface; | |
264 | |
265 // range 0.0 - 1.0 | |
266 float position_now = (ambient_pressure_mbar - surface_pressure_mbar) / bottom_mbar_diff_to_surface; | |
267 | |
268 if(position_now <= 0) | |
269 return temperature_surface; | |
270 | |
271 if(position_now >= 1) | |
272 return temperature_bottom; | |
273 | |
274 return temperature_surface + (temperature_difference * position_now); | |
275 } | |
276 | |
277 | |
278 uint32_t demo_modify_temperature_and_pressure(int32_t divetime_in_seconds, uint8_t subseconds, float ceiling_mbar) | |
279 { | |
280 | |
281 const float descent_rate = 4000/60; | |
282 const float ascent_rate = 1000/60; | |
283 const uint32_t seconds_descend = (1 * 60) + 30; | |
284 const uint32_t turbo_seconds_at_bottom_start = (0 * 60) + 0; | |
285 const uint32_t seconds_descend_and_bottomtime = seconds_descend + turbo_seconds_at_bottom_start + (2 * 60) + 0; | |
286 uint32_t time_elapsed_in_seconds; | |
287 static float ambient_pressure_mbar_memory = 0; | |
288 static uint32_t time_last_call = 0; | |
289 | |
290 if(divetime_in_seconds <= seconds_descend) | |
291 { | |
292 ambient_pressure_mbar = (divetime_in_seconds * descent_rate) + ((float)(subseconds) * descent_rate) + surface_pressure_mbar; | |
293 ambient_temperature = demo_modify_temperature_helper(descent_rate * seconds_descend); | |
294 | |
295 time_last_call = divetime_in_seconds; | |
296 return 0; | |
297 } | |
298 else | |
299 if(divetime_in_seconds <= seconds_descend + turbo_seconds_at_bottom_start) | |
300 { | |
301 ambient_pressure_mbar = (seconds_descend * descent_rate) + surface_pressure_mbar; | |
302 ambient_temperature = demo_modify_temperature_helper(descent_rate * seconds_descend); | |
303 ambient_pressure_mbar_memory = ambient_pressure_mbar; | |
304 time_last_call = divetime_in_seconds; | |
305 return turbo_seconds_at_bottom_start; | |
306 } | |
307 else | |
308 if(divetime_in_seconds <= seconds_descend_and_bottomtime) | |
309 { | |
310 ambient_pressure_mbar = (seconds_descend * descent_rate) + surface_pressure_mbar; | |
311 ambient_temperature = demo_modify_temperature_helper(descent_rate * seconds_descend); | |
312 ambient_pressure_mbar_memory = ambient_pressure_mbar; | |
313 time_last_call = divetime_in_seconds; | |
314 return 0; | |
315 } | |
316 else | |
317 { | |
318 time_elapsed_in_seconds = divetime_in_seconds - time_last_call; | |
319 ambient_pressure_mbar = ambient_pressure_mbar_memory - time_elapsed_in_seconds * ascent_rate; | |
320 | |
321 if(ambient_pressure_mbar < surface_pressure_mbar) | |
322 ambient_pressure_mbar = surface_pressure_mbar; | |
323 else if(ambient_pressure_mbar < ceiling_mbar) | |
324 ambient_pressure_mbar = ceiling_mbar; | |
325 | |
326 ambient_temperature = demo_modify_temperature_helper(descent_rate * seconds_descend); | |
327 ambient_pressure_mbar_memory = ambient_pressure_mbar; | |
328 time_last_call = divetime_in_seconds; | |
329 return 0; | |
330 } | |
331 } | |
186
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
332 #endif |
38 | 333 |
334 uint8_t is_init_pressure_done(void) | |
335 { | |
336 return pressureSensorInitSuccess; | |
337 } | |
338 | |
339 uint8_t init_pressure(void) | |
340 { | |
341 uint8_t buffer[1]; | |
356 | 342 buffer[0] = 0x1E; // Reset Command |
38 | 343 uint8_t retValue = 0xFF; |
344 | |
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
345 pressureSensorInitSuccess = false; |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
346 init_pressure_history(); |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
347 |
356 | 348 /* Probe new sensor first */ |
349 retValue = I2C_Master_Transmit( DEVICE_PRESSURE_MS5837, buffer, 1); | |
350 if(retValue != HAL_OK) | |
351 { | |
352 PRESSURE_ADDRESS = DEVICE_PRESSURE_MS5803; // use old sensor | |
353 HAL_Delay(100); | |
354 MX_I2C1_Init(); | |
355 if (global.I2C_SystemStatus != HAL_OK) | |
356 { | |
357 if (MX_I2C1_TestAndClear() == GPIO_PIN_RESET) { | |
358 MX_I2C1_TestAndClear(); // do it a second time | |
359 } | |
360 MX_I2C1_Init(); | |
361 } | |
362 } | |
363 else | |
364 { | |
365 PRESSURE_ADDRESS = DEVICE_PRESSURE_MS5837; // Success, use new sensor | |
366 } | |
367 HAL_Delay(3); //2.8ms according to datasheet | |
368 | |
369 buffer[0] = 0x1E; // Reset Command | |
370 retValue = 0xFF; | |
371 | |
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
372 /* Send reset request to pressure sensor */ |
356 | 373 retValue = I2C_Master_Transmit( PRESSURE_ADDRESS, buffer, 1); |
38 | 374 if(retValue != HAL_OK) |
375 { | |
376 return (HAL_StatusTypeDef)retValue; | |
377 } | |
356 | 378 HAL_Delay(3); //2.8ms according to datasheet |
38 | 379 |
356 | 380 for(uint8_t i=0;i<7;i++) |
38 | 381 { |
382 C[i] = get_ci_by_coef_num(i); | |
383 } | |
356 | 384 // n_crc = crc4(C); // no evaluation at the moment hw 151026 |
38 | 385 |
386 C5_x_2p8 = C[5] * 256; | |
387 C2_x_2p16 = C[2] * 65536; | |
388 C1_x_2p15 = C[1] * 32768; | |
389 | |
241
2b9775f71e30
cleanup: factor out I2C1_Status() and cleanup type
Jan Mulder <jlmulder@xs4all.nl>
parents:
186
diff
changeset
|
390 if(global.I2C_SystemStatus == HAL_OK) |
38 | 391 { |
392 pressureSensorInitSuccess = 1; | |
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
393 retValue = pressure_update(); |
38 | 394 } |
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
395 return retValue; |
38 | 396 } |
397 | |
398 | |
186
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
399 static uint32_t get_adc(void) |
38 | 400 { |
401 uint8_t buffer[1]; | |
402 uint8_t resivebuf[4]; | |
474
4be72d55b09a
Added error detection for reading of ADC values in sleep mode:
ideenmodellierer
parents:
403
diff
changeset
|
403 uint32_t answer = 0xFFFFFFFF; |
186
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
404 |
38 | 405 buffer[0] = 0x00; // Get ADC |
474
4be72d55b09a
Added error detection for reading of ADC values in sleep mode:
ideenmodellierer
parents:
403
diff
changeset
|
406 if(I2C_Master_Transmit( PRESSURE_ADDRESS, buffer, 1) == HAL_OK) |
4be72d55b09a
Added error detection for reading of ADC values in sleep mode:
ideenmodellierer
parents:
403
diff
changeset
|
407 { |
4be72d55b09a
Added error detection for reading of ADC values in sleep mode:
ideenmodellierer
parents:
403
diff
changeset
|
408 if(I2C_Master_Receive( PRESSURE_ADDRESS, resivebuf, 4) == HAL_OK) |
4be72d55b09a
Added error detection for reading of ADC values in sleep mode:
ideenmodellierer
parents:
403
diff
changeset
|
409 { |
4be72d55b09a
Added error detection for reading of ADC values in sleep mode:
ideenmodellierer
parents:
403
diff
changeset
|
410 resivebuf[3] = 0; |
4be72d55b09a
Added error detection for reading of ADC values in sleep mode:
ideenmodellierer
parents:
403
diff
changeset
|
411 answer = 256*256 *(uint32_t)resivebuf[0] + 256 * (uint32_t)resivebuf[1] + (uint32_t)resivebuf[2]; |
4be72d55b09a
Added error detection for reading of ADC values in sleep mode:
ideenmodellierer
parents:
403
diff
changeset
|
412 } |
4be72d55b09a
Added error detection for reading of ADC values in sleep mode:
ideenmodellierer
parents:
403
diff
changeset
|
413 } |
38 | 414 return answer; |
415 } | |
416 | |
417 | |
186
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
418 static uint16_t get_ci_by_coef_num(uint8_t coef_num) |
38 | 419 { |
420 uint8_t resivebuf[2]; | |
421 | |
422 uint8_t cmd = CMD_PROM_RD+coef_num*2; | |
356 | 423 I2C_Master_Transmit( PRESSURE_ADDRESS, &cmd, 1); |
424 I2C_Master_Receive( PRESSURE_ADDRESS, resivebuf, 2); | |
38 | 425 return (256*(uint16_t)resivebuf[0]) + (uint16_t)resivebuf[1]; |
426 } | |
427 | |
428 | |
429 | |
430 uint8_t pressure_update(void) | |
431 { | |
432 HAL_StatusTypeDef statusReturn = HAL_TIMEOUT; | |
433 | |
434 statusReturn = pressure_sensor_get_data(); | |
435 pressure_calculation(); | |
436 return (uint8_t)statusReturn; | |
437 } | |
438 | |
276
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
439 /* Switch between pressure and temperature measurement with every successful read operation */ |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
440 void pressure_update_alternating(void) |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
441 { |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
442 static uint8_t getTemperature= 0; |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
443 |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
444 if(getTemperature) |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
445 { |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
446 if(pressure_sensor_get_temperature_raw() == HAL_OK) |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
447 { |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
448 getTemperature = 0; |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
449 } |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
450 } |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
451 else |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
452 { |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
453 if(pressure_sensor_get_pressure_raw() == HAL_OK) |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
454 { |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
455 getTemperature = 1; |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
456 } |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
457 } |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
458 pressure_calculation(); |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
459 return; |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
460 } |
38 | 461 |
186
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
462 static uint32_t pressure_sensor_get_one_value(uint8_t cmd, HAL_StatusTypeDef *statusReturn) |
38 | 463 { |
464 uint8_t command = CMD_ADC_CONV + cmd; | |
474
4be72d55b09a
Added error detection for reading of ADC values in sleep mode:
ideenmodellierer
parents:
403
diff
changeset
|
465 uint32_t adcValue = 0; |
38 | 466 HAL_StatusTypeDef statusReturnTemp = HAL_TIMEOUT; |
467 | |
356 | 468 statusReturnTemp = I2C_Master_Transmit( PRESSURE_ADDRESS, &command, 1); |
38 | 469 |
470 if(statusReturn) | |
471 { | |
472 *statusReturn = statusReturnTemp; | |
473 } | |
474
4be72d55b09a
Added error detection for reading of ADC values in sleep mode:
ideenmodellierer
parents:
403
diff
changeset
|
474 else |
38 | 475 { |
474
4be72d55b09a
Added error detection for reading of ADC values in sleep mode:
ideenmodellierer
parents:
403
diff
changeset
|
476 switch (cmd & 0x0f) // wait necessary conversion time |
4be72d55b09a
Added error detection for reading of ADC values in sleep mode:
ideenmodellierer
parents:
403
diff
changeset
|
477 { |
4be72d55b09a
Added error detection for reading of ADC values in sleep mode:
ideenmodellierer
parents:
403
diff
changeset
|
478 case CMD_ADC_256 : HAL_Delay(1); break; |
4be72d55b09a
Added error detection for reading of ADC values in sleep mode:
ideenmodellierer
parents:
403
diff
changeset
|
479 case CMD_ADC_512 : HAL_Delay(3); break; |
4be72d55b09a
Added error detection for reading of ADC values in sleep mode:
ideenmodellierer
parents:
403
diff
changeset
|
480 case CMD_ADC_1024: HAL_Delay(4); break; |
4be72d55b09a
Added error detection for reading of ADC values in sleep mode:
ideenmodellierer
parents:
403
diff
changeset
|
481 case CMD_ADC_2048: HAL_Delay(6); break; |
4be72d55b09a
Added error detection for reading of ADC values in sleep mode:
ideenmodellierer
parents:
403
diff
changeset
|
482 case CMD_ADC_4096: HAL_Delay(10); break; |
4be72d55b09a
Added error detection for reading of ADC values in sleep mode:
ideenmodellierer
parents:
403
diff
changeset
|
483 default: |
4be72d55b09a
Added error detection for reading of ADC values in sleep mode:
ideenmodellierer
parents:
403
diff
changeset
|
484 break; |
4be72d55b09a
Added error detection for reading of ADC values in sleep mode:
ideenmodellierer
parents:
403
diff
changeset
|
485 } |
4be72d55b09a
Added error detection for reading of ADC values in sleep mode:
ideenmodellierer
parents:
403
diff
changeset
|
486 adcValue = get_adc(); |
4be72d55b09a
Added error detection for reading of ADC values in sleep mode:
ideenmodellierer
parents:
403
diff
changeset
|
487 if(adcValue == 0xFFFFFFFF) |
4be72d55b09a
Added error detection for reading of ADC values in sleep mode:
ideenmodellierer
parents:
403
diff
changeset
|
488 { |
4be72d55b09a
Added error detection for reading of ADC values in sleep mode:
ideenmodellierer
parents:
403
diff
changeset
|
489 *statusReturn = HAL_ERROR; |
4be72d55b09a
Added error detection for reading of ADC values in sleep mode:
ideenmodellierer
parents:
403
diff
changeset
|
490 } |
4be72d55b09a
Added error detection for reading of ADC values in sleep mode:
ideenmodellierer
parents:
403
diff
changeset
|
491 } |
4be72d55b09a
Added error detection for reading of ADC values in sleep mode:
ideenmodellierer
parents:
403
diff
changeset
|
492 return adcValue; |
38 | 493 } |
494 | |
495 | |
186
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
496 static HAL_StatusTypeDef pressure_sensor_get_data(void) |
38 | 497 { |
276
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
498 uint32_t requestedValue = 0; |
38 | 499 HAL_StatusTypeDef statusReturn1 = HAL_TIMEOUT; |
500 HAL_StatusTypeDef statusReturn2 = HAL_TIMEOUT; | |
501 | |
276
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
502 |
38 | 503 |
276
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
504 requestedValue = pressure_sensor_get_one_value(CMD_ADC_D2 + CMD_ADC_1024, &statusReturn2); |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
505 if (statusReturn2 == HAL_OK) |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
506 { |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
507 D2 = requestedValue; |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
508 } |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
509 |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
510 requestedValue = pressure_sensor_get_one_value(CMD_ADC_D1 + CMD_ADC_1024, &statusReturn1); |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
511 if (statusReturn1 == HAL_OK) |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
512 { |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
513 D1 = requestedValue; |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
514 } |
38 | 515 if(statusReturn2 > statusReturn1) // if anything is not HAL_OK (0x00) or worse |
516 return statusReturn2; | |
517 else | |
518 return statusReturn1; | |
519 } | |
520 | |
521 | |
276
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
522 HAL_StatusTypeDef pressure_sensor_get_pressure_raw(void) |
38 | 523 { |
276
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
524 uint32_t requestedValue = 0; |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
525 HAL_StatusTypeDef statusReturn = HAL_TIMEOUT; |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
526 |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
527 requestedValue = pressure_sensor_get_one_value(CMD_ADC_D1 + CMD_ADC_1024, &statusReturn); |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
528 if (statusReturn == HAL_OK) |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
529 { |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
530 D1 = requestedValue; |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
531 } |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
532 |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
533 return statusReturn; |
38 | 534 } |
535 | |
536 | |
276
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
537 HAL_StatusTypeDef pressure_sensor_get_temperature_raw(void) |
38 | 538 { |
276
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
539 uint32_t requestedValue = 0; |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
540 HAL_StatusTypeDef statusReturn = HAL_TIMEOUT; |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
541 |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
542 requestedValue = pressure_sensor_get_one_value(CMD_ADC_D2 + CMD_ADC_1024, &statusReturn); |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
543 if (statusReturn == HAL_OK) |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
544 { |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
545 D2 = requestedValue; |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
546 } |
8e9c502c0b06
Rework pressure/ temperature data aquisition
ideenmodellierer
parents:
241
diff
changeset
|
547 return statusReturn; |
38 | 548 } |
549 | |
550 | |
352 | 551 #ifdef SIMULATE_PRESSURE |
552 void pressure_simulation() | |
553 { | |
554 static uint32_t tickstart = 0; | |
555 static float pressure_sim_mbar = 0; | |
556 static uint32_t passedSecond = 0; | |
557 static uint32_t secondtick = 0; | |
558 | |
559 uint32_t lasttick = 0; | |
560 | |
561 | |
562 | |
563 if( tickstart == 0) | |
564 { | |
565 tickstart = HAL_GetTick(); /* init time stamp */ | |
566 secondtick = tickstart; | |
567 pressure_sim_mbar = 1000; | |
568 } | |
569 | |
570 lasttick = HAL_GetTick(); | |
571 if(time_elapsed_ms(secondtick,lasttick) > 1000) /* one second passed since last tick */ | |
572 { | |
573 secondtick = lasttick; | |
574 passedSecond++; | |
575 | |
576 #ifdef DIVE_AFTER_LANDING | |
577 if(passedSecond < 10) pressure_sim_mbar = 1000.0; /* stay stable for 10 seconds */ | |
578 else if(passedSecond < 300) pressure_sim_mbar -= 1.0; /* decrease pressure in 5 minutes target 770mbar => delta 330 */ | |
579 else if(passedSecond < 900) pressure_sim_mbar += 0.0; /*stay stable 10 minutes*/ | |
580 else if(passedSecond < 1500) pressure_sim_mbar += 0.5; /* return to 1 bar in 10 Minutes*/ | |
581 else if(passedSecond < 1800) pressure_sim_mbar += 0.0; /* 5 minutes break */ | |
582 else if(passedSecond < 2000) pressure_sim_mbar += 10.0; /* start dive */ | |
583 else if(passedSecond < 2300) pressure_sim_mbar += 0.0; /* stay on depth */ | |
584 else if(passedSecond < 2500) pressure_sim_mbar -= 10.0; /* return to surface */ | |
585 else pressure_sim_mbar = 1000.0; /* final state */ | |
586 #else /* short dive */ | |
587 if(passedSecond < 10) pressure_sim_mbar = 1000.0; /* stay stable for 10 seconds */ | |
588 else if(passedSecond < 180) pressure_sim_mbar += 10.0; /* Start dive */ | |
589 else if(passedSecond < 300) pressure_sim_mbar += 0.0; /*stay on depth*/ | |
590 else if(passedSecond < 460) pressure_sim_mbar -= 10.0; /* return to surface */ | |
591 else if(passedSecond < 600) pressure_sim_mbar += 0.0; /* stay */ | |
592 else if(passedSecond < 610) pressure_sim_mbar = 1000.0; /* get ready for second dive */ | |
593 else if(passedSecond < 780) pressure_sim_mbar += 10.0; /* Start dive */ | |
594 else if(passedSecond < 900) pressure_sim_mbar += 0.0; /*stay on depth*/ | |
595 else if(passedSecond < 1060) pressure_sim_mbar -= 10.0; /* return to surface */ | |
596 else if(passedSecond < 1200) pressure_sim_mbar += 0.0; /* stay */ | |
597 else pressure_sim_mbar = 1000.0; /* final state */ | |
598 #endif | |
599 } | |
600 | |
601 | |
602 ambient_pressure_mbar = pressure_sim_mbar; | |
603 ambient_temperature = 25.0; | |
604 return; | |
605 } | |
606 | |
607 #endif | |
608 | |
38 | 609 void pressure_calculation(void) |
610 { | |
241
2b9775f71e30
cleanup: factor out I2C1_Status() and cleanup type
Jan Mulder <jlmulder@xs4all.nl>
parents:
186
diff
changeset
|
611 if(global.I2C_SystemStatus != HAL_OK) |
38 | 612 return; |
352 | 613 |
614 #ifdef SIMULATE_PRESSURE | |
615 pressure_simulation(); | |
616 #else | |
38 | 617 pressure_calculation_AN520_004_mod_MS5803_30BA__09_2015(); |
352 | 618 #endif |
38 | 619 } |
620 | |
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
621 static uint8_t pressure_plausible(float pressurevalue) |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
622 { |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
623 static uint8_t pressurewriteindex = 0; |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
624 uint8_t retval = 0; |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
625 uint8_t index; |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
626 float pressure_average = 0; |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
627 |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
628 for(index = 0; index < PRESSURE_HISTORY_SIZE; index++) |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
629 { |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
630 pressure_average += pressure_history_mbar[index]; |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
631 } |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
632 pressure_average /= PRESSURE_HISTORY_SIZE; |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
633 if(pressure_average == 1000.0) /* first pressure calculation */ |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
634 { |
339
37f45300bc2e
Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents:
335
diff
changeset
|
635 if(fabs(pressurevalue - pressure_average) < 11000.0) /* just in case a reset occur during dive assume value equal < 100m as valid */ |
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
636 { |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
637 for(index = 0; index < PRESSURE_HISTORY_SIZE; index++) |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
638 { |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
639 pressure_history_mbar[index] = pressurevalue; /* set history to current value */ |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
640 retval = 1; |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
641 } |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
642 } |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
643 } |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
644 else |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
645 { |
339
37f45300bc2e
Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents:
335
diff
changeset
|
646 pressure_history_mbar[pressurewriteindex++] = pressurevalue; |
37f45300bc2e
Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents:
335
diff
changeset
|
647 pressurewriteindex &= 0x7; /* wrap around if necessary */ |
37f45300bc2e
Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents:
335
diff
changeset
|
648 retval = 1; |
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
649 } |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
650 |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
651 return retval; |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
652 } |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
653 |
186
f11f0bf6ef2d
cleanup: remove obsolete code, make static, etc.
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
654 static void pressure_calculation_AN520_004_mod_MS5803_30BA__09_2015(void) |
38 | 655 { |
335
c11ce8c885d3
Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents:
331
diff
changeset
|
656 static float runningAvg = 0; |
c11ce8c885d3
Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents:
331
diff
changeset
|
657 static uint8_t avgCnt = 0; |
c11ce8c885d3
Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents:
331
diff
changeset
|
658 |
38 | 659 uint32_t local_D1; // ADC value of the pressure conversion |
660 uint32_t local_D2; // ADC value of the temperature conversion | |
661 int32_t local_Px10; // compensated pressure value | |
662 int32_t local_Tx100; // compensated temperature value | |
663 int64_t local_dT; // int32_t, difference between actual and measured temperature | |
664 int64_t local_OFF; // offset at actual temperature | |
665 int64_t local_SENS; // sensitivity at actual temperature | |
666 | |
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
667 float calc_pressure; |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
668 |
38 | 669 int64_t T2; |
670 int64_t OFF2; | |
671 int64_t SENS2; | |
672 | |
673 local_D1 = D1; | |
674 local_D2 = D2; | |
675 | |
676 local_dT = ((int64_t)local_D2) - ((int64_t)C[5]) * 256; //pow(2,8); | |
677 local_OFF = ((int64_t)C[2]) * 65536 + local_dT * ((int64_t)C[4]) / 128; // pow(2,16), pow(2,7) | |
678 local_SENS = ((int64_t)C[1]) * 32768 + local_dT * ((int64_t)C[3]) / 256; // pow(2,15), pow(2,8) | |
679 | |
680 local_Tx100 = (int32_t)(2000 + (local_dT * ((int64_t)C[6])) / 8388608);// pow(2,23) | |
681 | |
682 | |
683 if(local_Tx100 < 2000) // low temperature | |
684 { | |
685 T2 = 3 * local_dT; | |
686 T2 *= local_dT; | |
687 T2 /= 8589934592; | |
688 | |
689 OFF2 = ((int64_t)local_Tx100) - 2000; | |
690 OFF2 *= OFF2; | |
691 OFF2 *= 3; | |
692 OFF2 /= 2; | |
693 | |
694 SENS2 = ((int64_t)local_Tx100) - 2000; | |
695 SENS2 *= SENS2; | |
696 SENS2 *= 5; | |
697 SENS2 /= 8; | |
698 | |
699 local_Tx100 -= (int32_t)T2; | |
700 local_OFF -= OFF2; | |
701 local_SENS -= SENS2; | |
702 } | |
703 else | |
704 { | |
705 T2 = 7 * local_dT; | |
706 T2 *= local_dT; | |
707 T2 /= 137438953472; | |
708 | |
709 OFF2 = ((int64_t)local_Tx100) - 2000; | |
710 OFF2 *= OFF2; | |
711 OFF2 /= 16; | |
712 | |
713 local_Tx100 -= (int32_t)T2; | |
714 local_OFF -= OFF2; | |
715 } | |
716 | |
717 local_Px10 = (int32_t)( | |
718 (((int64_t)((local_D1 * local_SENS) / 2097152)) - local_OFF) | |
719 / 8192 );// )) / 10; // pow(2,21), pow(2,13) | |
720 | |
339
37f45300bc2e
Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents:
335
diff
changeset
|
721 ambient_temperature = ((float)local_Tx100) / 100; |
37f45300bc2e
Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents:
335
diff
changeset
|
722 ambient_temperature += temperature_offset; |
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
723 |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
724 calc_pressure = ((float)local_Px10) / 10; |
339
37f45300bc2e
Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents:
335
diff
changeset
|
725 calc_pressure += pressure_offset; |
37f45300bc2e
Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents:
335
diff
changeset
|
726 |
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
727 if(pressure_plausible(calc_pressure)) |
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
728 { |
335
c11ce8c885d3
Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents:
331
diff
changeset
|
729 runningAvg = (avgCnt * runningAvg + calc_pressure) / (avgCnt + 1); |
339
37f45300bc2e
Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents:
335
diff
changeset
|
730 if (avgCnt < 10) /* build an average considering the last measurements to have a weight "1 of 10" */ |
335
c11ce8c885d3
Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents:
331
diff
changeset
|
731 { /* Main reason for this is the jitter of up to +-10 HPa in surface mode which is caused */ |
c11ce8c885d3
Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents:
331
diff
changeset
|
732 avgCnt++; /* by the measurement range of the sensor which is focused on under water pressure measurement */ |
c11ce8c885d3
Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents:
331
diff
changeset
|
733 } |
c11ce8c885d3
Use average calculation for pressure: precondition was that pressure values jittered +- 10 HPa from one capture (once a second) to the other. Basically pressure is measured several times a second => using these values in an additional history calculation reduces the jitter down to +-1 per second
ideenmodellierer
parents:
331
diff
changeset
|
734 ambient_pressure_mbar = runningAvg; |
331
b4c578caaafb
Added plausibility check for pressure values
ideenmodellierer
parents:
276
diff
changeset
|
735 } |
38 | 736 } |
737 | |
738 | |
739 /* taken from AN520 by meas-spec.com dated 9. Aug. 2011 | |
740 * short and int are both 16bit according to AVR/GCC google results | |
741 */ | |
356 | 742 /*static uint8_t crc4(uint16_t n_prom[]) |
38 | 743 { |
744 uint16_t cnt; // simple counter | |
745 uint16_t n_rem; // crc reminder | |
746 uint16_t crc_read; // original value of the crc | |
747 uint8_t n_bit; | |
748 n_rem = 0x00; | |
749 crc_read=n_prom[7]; //save read CRC | |
750 n_prom[7]=(0xFF00 & (n_prom[7])); //CRC byte is replaced by 0 | |
751 for (cnt = 0; cnt < 16; cnt++) // operation is performed on bytes | |
752 { // choose LSB or MSB | |
753 if (cnt%2==1) n_rem ^= (uint16_t) ((n_prom[cnt>>1]) & 0x00FF); | |
754 else n_rem ^= (uint16_t) (n_prom[cnt>>1]>>8); | |
755 for (n_bit = 8; n_bit > 0; n_bit--) | |
756 { | |
757 if (n_rem & (0x8000)) | |
758 { | |
759 n_rem = (n_rem << 1) ^ 0x3000; | |
760 } | |
761 else | |
762 { | |
763 n_rem = (n_rem << 1); | |
764 } | |
765 } | |
766 } | |
767 n_rem= (0x000F & (n_rem >> 12)); // // final 4-bit reminder is CRC code | |
768 n_prom[7]=crc_read; // restore the crc_read to its original place | |
769 return (n_rem ^ 0x00); | |
770 } | |
356 | 771 |
38 | 772 void test_calculation(void) |
773 { | |
774 C1 = 29112; | |
775 C2 = 26814; | |
776 C3 = 19125; | |
777 C4 = 17865; | |
778 C5 = 32057; | |
779 C6 = 31305; | |
780 | |
781 C2_x_2p16 = C2 * 65536; | |
782 C1_x_2p15 = C1 * 32768; | |
783 | |
784 D1 = 4944364; | |
785 D2 = 8198974; | |
786 pressure_calculation() ; | |
787 }; | |
788 */ | |
339
37f45300bc2e
Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents:
335
diff
changeset
|
789 void pressure_set_offset (float pressureOffset, float temperatureOffset) |
37f45300bc2e
Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents:
335
diff
changeset
|
790 { |
37f45300bc2e
Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents:
335
diff
changeset
|
791 if(pressure_offset != pressureOffset) /* we received a new value => reinit surface que */ |
37f45300bc2e
Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents:
335
diff
changeset
|
792 { |
37f45300bc2e
Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents:
335
diff
changeset
|
793 ambient_pressure_mbar -= pressure_offset; /* revert old value */ |
37f45300bc2e
Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents:
335
diff
changeset
|
794 ambient_pressure_mbar += pressureOffset; /* apply new offset */ |
37f45300bc2e
Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents:
335
diff
changeset
|
795 init_surface_ring(1); |
37f45300bc2e
Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents:
335
diff
changeset
|
796 } |
38 | 797 |
339
37f45300bc2e
Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents:
335
diff
changeset
|
798 pressure_offset = pressureOffset; |
37f45300bc2e
Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents:
335
diff
changeset
|
799 temperature_offset = temperatureOffset; |
37f45300bc2e
Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents:
335
diff
changeset
|
800 } |
37f45300bc2e
Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents:
335
diff
changeset
|
801 |
37f45300bc2e
Apply averaging to pressure measurement: In pre versions calculated pressure value jittered +/-10hPa. Since we measure the pressure several time a second but only use one value a second, calc average including not used values
ideenmodellierer
parents:
335
diff
changeset
|
802 |