comparison Discovery/Src/data_exchange_main.c @ 747:df0d43da1614

Added pressure compensation to CO2 detection: A pressure compensation is needed if the ExplorIR shall be used under extended pressure conditions. The procedure recommended by the application note has been integrated. To keep things simple the focus of the CO2 measurement is not the precision, as it is needed for the decompression calculation, but the indication of a critical increase of CO2 in the breathing loop. That's why only a lookup table with 1000ppm steps has been implemented instead of calculating the polynom for every measurement.
author Ideenmodellierer
date Sun, 05 Mar 2023 22:06:47 +0100
parents 190e5814b2f5
children aa6006975e76
comparison
equal deleted inserted replaced
746:7e84ae1513b6 747:df0d43da1614
55 */ 55 */
56 56
57 /* Includes ------------------------------------------------------------------*/ 57 /* Includes ------------------------------------------------------------------*/
58 #include <stdlib.h> 58 #include <stdlib.h>
59 #include <string.h> // for memcpy 59 #include <string.h> // for memcpy
60 #include <math.h>
60 #include "stm32f4xx_hal.h" 61 #include "stm32f4xx_hal.h"
61 #include "stdio.h" 62 #include "stdio.h"
62 #include "ostc.h" 63 #include "ostc.h"
63 #include "settings.h" 64 #include "settings.h"
64 #include "data_central.h" 65 #include "data_central.h"
407 break; 408 break;
408 case SENSOR_DIGO2: SensorActive[SENSOR_DIGO2] = 1; 409 case SENSOR_DIGO2: SensorActive[SENSOR_DIGO2] = 1;
409 break; 410 break;
410 case SENSOR_CO2: SensorActive[SENSOR_CO2] = 1; 411 case SENSOR_CO2: SensorActive[SENSOR_CO2] = 1;
411 break; 412 break;
413 #ifdef ENABLE_SENTINEL_MODE
414 case SENSOR_SENTINEL: SensorActive[SENSOR_SENTINEL] = 1;
415 break;
416 #endif
412 default: 417 default:
413 break; 418 break;
414 } 419 }
415 } 420 }
416 421
426 { 431 {
427 externalInterface_Cmd |= EXT_INTERFACE_33V_ON | EXT_INTERFACE_UART_CO2; /* CO2 sensor has to be activated via auto detection */ 432 externalInterface_Cmd |= EXT_INTERFACE_33V_ON | EXT_INTERFACE_UART_CO2; /* CO2 sensor has to be activated via auto detection */
428 } 433 }
429 434
430 #ifdef ENABLE_SENTINEL_MODE 435 #ifdef ENABLE_SENTINEL_MODE
431 if(settings->ppo2sensors_source == O2_SENSOR_SOURCE_SENTINEL) 436 if(SensorActive[SENSOR_SENTINEL])
432 { 437 {
433 externalInterface_Cmd |= EXT_INTERFACE_33V_ON | EXT_INTERFACE_UART_SENTINEL; 438 externalInterface_Cmd |= EXT_INTERFACE_33V_ON | EXT_INTERFACE_UART_SENTINEL;
434 externalInterface_Cmd &= (~EXT_INTERFACE_ADC_ON); 439 externalInterface_Cmd &= (~EXT_INTERFACE_ADC_ON);
435 } 440 }
436 #endif 441 #endif
827 832
828 SDiveState *pStateReal = stateRealGetPointerWrite(); 833 SDiveState *pStateReal = stateRealGetPointerWrite();
829 uint8_t idx; 834 uint8_t idx;
830 float meter = 0; 835 float meter = 0;
831 SSettings *pSettings; 836 SSettings *pSettings;
832 837
833 838 #ifdef ENABLE_EXTERNAL_PRESSURE
834 839 float CO2Corr = 0.0;
840 #endif
841
835 // wireless - �ltere daten aufr�umen 842 // wireless - �ltere daten aufr�umen
836 #if 0 843 #if 0
837 for(int i=0;i<(2*NUM_GASES+1);i++) 844 for(int i=0;i<(2*NUM_GASES+1);i++)
838 { 845 {
839 if(pStateReal->lifeData.bottle_bar[i]) 846 if(pStateReal->lifeData.bottle_bar[i])
1137 /* sensorErrors 1144 /* sensorErrors
1138 */ 1145 */
1139 pStateReal->sensorErrorsRTE = dataIn.sensorErrors; 1146 pStateReal->sensorErrorsRTE = dataIn.sensorErrors;
1140 1147
1141 /* data from CO2 sensor */ 1148 /* data from CO2 sensor */
1142 pStateReal->lifeData.CO2_data.CO2_ppm = dataIn.data[(dataIn.boolADCO2Data && DATA_BUFFER_CO2)].CO2_ppm; 1149 pStateReal->lifeData.CO2_data.CO2_ppm = dataIn.data[(dataIn.boolADCO2Data && DATA_BUFFER_CO2)].CO2_ppm * 10; /* Scale factor depends on sensor */
1143 pStateReal->lifeData.CO2_data.signalStrength = dataIn.data[(dataIn.boolADCO2Data && DATA_BUFFER_CO2)].CO2_signalStrength; 1150 pStateReal->lifeData.CO2_data.signalStrength = dataIn.data[(dataIn.boolADCO2Data && DATA_BUFFER_CO2)].CO2_signalStrength;
1151
1152 #ifdef ENABLE_EXTERNAL_PRESSURE
1153 CO2Corr = 2.811*pow(10,-38)*pow(pStateReal->lifeData.CO2_data.CO2_ppm,6)- 9.817*pow(10,-32)*pow(pStateReal->lifeData.CO2_data.CO2_ppm,5)+1.304*pow(10,-25)*pow(pStateReal->lifeData.CO2_data.CO2_ppm,4)
1154 -8.216*pow(10,-20)*pow(pStateReal->lifeData.CO2_data.CO2_ppm,3)+2.311*pow(10,-14)*pow(pStateReal->lifeData.CO2_data.CO2_ppm,2) - 2.195*pow(10,-9)*pStateReal->lifeData.CO2_data.CO2_ppm - 1.471*pow(10,-3);
1155 pStateReal->lifeData.CO2_data.CO2_ppm = pStateReal->lifeData.CO2_data.CO2_ppm / (1.0 + (CO2Corr * ((stateRealGetPointer()->lifeData.pressure_surface_bar * 1000) - ((stateRealGetPointer()->lifeData.ppO2Sensor_bar[2] *1000)))));
1156 #endif
1144 } 1157 }
1145 1158
1146 /* apnea specials 1159 /* apnea specials
1147 */ 1160 */
1148 if(pStateReal->diveSettings.diveMode == DIVEMODE_Apnea) 1161 if(pStateReal->diveSettings.diveMode == DIVEMODE_Apnea)