Started a gui menuflow

Dependencies:   LCD_DISCO_F429ZI mbed TS_DISCO_F429ZI BSP_DISCO_F429ZI

Committer:
ahaas92
Date:
Thu Jun 11 22:55:06 2020 +0000
Revision:
3:b029a3f73a9e
Init of gui structure ;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ahaas92 3:b029a3f73a9e 1 /*********************************************************************/
ahaas92 3:b029a3f73a9e 2
ahaas92 3:b029a3f73a9e 3 /* Includes ------------------------------------------------------------------*/
ahaas92 3:b029a3f73a9e 4 #define EXTERN extern
ahaas92 3:b029a3f73a9e 5 #include "SS.h"
ahaas92 3:b029a3f73a9e 6 #include "main.h"
ahaas92 3:b029a3f73a9e 7 #include "_ss_pwm.h"
ahaas92 3:b029a3f73a9e 8 #include "_SS_I2CX_Drivers.h"
ahaas92 3:b029a3f73a9e 9 #include "_SS_I2CX_SDP600.h"
ahaas92 3:b029a3f73a9e 10 #include "_SS_I2CX_X201641.h"
ahaas92 3:b029a3f73a9e 11 #include "Ventilation.h"
ahaas92 3:b029a3f73a9e 12 #include "MotorTempTable.h"
ahaas92 3:b029a3f73a9e 13 #include "_SS_FlowComputer.h"
ahaas92 3:b029a3f73a9e 14 #include "_SS_TSI_4040.h"
ahaas92 3:b029a3f73a9e 15 #include "_SS_Data_Logging.h"
ahaas92 3:b029a3f73a9e 16 #include "_SS_OnOffActioner.h"
ahaas92 3:b029a3f73a9e 17 #undef EXTERN
ahaas92 3:b029a3f73a9e 18
ahaas92 3:b029a3f73a9e 19 #define INIT_VARIABLES
ahaas92 3:b029a3f73a9e 20 #define EXTERN
ahaas92 3:b029a3f73a9e 21 #include "Monitoring.h"
ahaas92 3:b029a3f73a9e 22 #undef EXTERN
ahaas92 3:b029a3f73a9e 23 #undef INIT_VARIABLES
ahaas92 3:b029a3f73a9e 24
ahaas92 3:b029a3f73a9e 25
ahaas92 3:b029a3f73a9e 26 // *********************** Register locations **********************************
ahaas92 3:b029a3f73a9e 27 #define DMA_IFCR1 (*(volatile uint32_t *)0x40020004)
ahaas92 3:b029a3f73a9e 28 #define DMA_CCR1 (*(volatile uint32_t *)0x40020008)
ahaas92 3:b029a3f73a9e 29 #define DMA_CNTDR1 (*(volatile uint32_t *)0x4002000c)
ahaas92 3:b029a3f73a9e 30 #define DMA_CPAR1 (*(volatile uint32_t *)0x40020010)
ahaas92 3:b029a3f73a9e 31 #define DMA_CMAR1 (*(volatile uint32_t *)0x40020014)
ahaas92 3:b029a3f73a9e 32
ahaas92 3:b029a3f73a9e 33 #define ADC1_SR (*(volatile uint32_t *)0x40012400)
ahaas92 3:b029a3f73a9e 34 #define ADC1_SQR1 (*(volatile uint32_t *)0x4001242C)
ahaas92 3:b029a3f73a9e 35 #define ADC1_SQR2 (*(volatile uint32_t *)0x40012430)
ahaas92 3:b029a3f73a9e 36 #define ADC1_SQR3 (*(volatile uint32_t *)0x40012434)
ahaas92 3:b029a3f73a9e 37 #define ADC1_LTR (*(volatile uint32_t *)0x40012428)
ahaas92 3:b029a3f73a9e 38 #define ADC1_HTR (*(volatile uint32_t *)0x40012424)
ahaas92 3:b029a3f73a9e 39 #define ADC1_CR1 (*(volatile uint32_t *)0x40012404)
ahaas92 3:b029a3f73a9e 40 #define ADC1_CR2 (*(volatile uint32_t *)0x40012408)
ahaas92 3:b029a3f73a9e 41
ahaas92 3:b029a3f73a9e 42
ahaas92 3:b029a3f73a9e 43 // ************************* ADC CONFIGURATION CHANNELS ************************
ahaas92 3:b029a3f73a9e 44 #define FREE_MEAS_CHANNEL 0
ahaas92 3:b029a3f73a9e 45 #define PPROX_MEAS_CHANNEL 1
ahaas92 3:b029a3f73a9e 46 #define CURRENT_MEAS_CHANNEL 2
ahaas92 3:b029a3f73a9e 47 #define ALIM_24V_MEAS_CHANNEL 6
ahaas92 3:b029a3f73a9e 48 #define TEMP_PHASE_A 5
ahaas92 3:b029a3f73a9e 49 #define TEMP_PHASE_B 4
ahaas92 3:b029a3f73a9e 50 #define TEMP_PHASE_C 3
ahaas92 3:b029a3f73a9e 51
ahaas92 3:b029a3f73a9e 52 // ********************* 24V ALARM MANAGEMENT **********************************
ahaas92 3:b029a3f73a9e 53 #ifndef C_M3_DEVICETEST_TARGET
ahaas92 3:b029a3f73a9e 54
ahaas92 3:b029a3f73a9e 55 #endif
ahaas92 3:b029a3f73a9e 56
ahaas92 3:b029a3f73a9e 57
ahaas92 3:b029a3f73a9e 58
ahaas92 3:b029a3f73a9e 59 // ************************ I2C SENSORS MANAGEMENT *****************************
ahaas92 3:b029a3f73a9e 60 #ifndef C_M3_DEVICETEST_TARGET
ahaas92 3:b029a3f73a9e 61 #define READING_NO_SENSOR 0
ahaas92 3:b029a3f73a9e 62 #define READING_FLOW_SENSORS 1
ahaas92 3:b029a3f73a9e 63 //#define READING_PRESSURE_SENSORS 2
ahaas92 3:b029a3f73a9e 64 #define STOP_READING_FLOW_SENSORS 3
ahaas92 3:b029a3f73a9e 65 #define START_READING_FLOW_SENSORS 4
ahaas92 3:b029a3f73a9e 66 #define NUMBER_I2C_REBOOT 3
ahaas92 3:b029a3f73a9e 67
ahaas92 3:b029a3f73a9e 68 #define FLOW_SENSOR_READING 0
ahaas92 3:b029a3f73a9e 69 #define FLOW_SENSOR_OK 1
ahaas92 3:b029a3f73a9e 70 #define FLOW_SENSOR_FAIL 2
ahaas92 3:b029a3f73a9e 71 static u8 ucStatusSDP600=FLOW_SENSOR_READING;
ahaas92 3:b029a3f73a9e 72 static u8 ucStatusX201641=FLOW_SENSOR_READING;
ahaas92 3:b029a3f73a9e 73
ahaas92 3:b029a3f73a9e 74 static volatile u8 ucReadingFlowSensor=START_READING_FLOW_SENSORS; // I2Cx sensor managment
ahaas92 3:b029a3f73a9e 75 static u8 ucCounterFlowErrorMeasurement=0;
ahaas92 3:b029a3f73a9e 76 static u16 uiTotalCounterFlowErrorMeasurement=0;
ahaas92 3:b029a3f73a9e 77
ahaas92 3:b029a3f73a9e 78 #if defined(SDP600_USED_I2C1_BUS) || defined(X201641_USED_I2C1_BUS)
ahaas92 3:b029a3f73a9e 79 #ifdef DISPLAY_AVERAGE_BLOWER_RAW_FLOW
ahaas92 3:b029a3f73a9e 80 #define SMOOTH_BLOWER_RAW_FLOW_COUNTER 50
ahaas92 3:b029a3f73a9e 81 static u16 uiBlowerRAWFlowTemp[SMOOTH_BLOWER_RAW_FLOW_COUNTER];
ahaas92 3:b029a3f73a9e 82 static u8 ucIndexBlowerRAWFlowSmooth=0;
ahaas92 3:b029a3f73a9e 83
ahaas92 3:b029a3f73a9e 84 #define BLOWER_RAW_FLOW_SAMPLES_NUMBER 200
ahaas92 3:b029a3f73a9e 85 static u32 ulSumBlowerFlowRAWMes=0;
ahaas92 3:b029a3f73a9e 86 static u16 uiBlowerRAWFlowSamplesCounter=BLOWER_RAW_FLOW_SAMPLES_NUMBER;
ahaas92 3:b029a3f73a9e 87 #endif
ahaas92 3:b029a3f73a9e 88
ahaas92 3:b029a3f73a9e 89 #define SMOOTH_BLOWER_FLOW_LARGE_COUNTER 75//100 // MUST BE HIGHER THAN SMOOTH_BLOWER_FLOW_SMALL_COUNTER
ahaas92 3:b029a3f73a9e 90 #define SMOOTH_BLOWER_FLOW_SMALL_COUNTER 15 // MUST BE LOWER THAN SMOOTH_BLOWER_FLOW_LARGE_COUNTER
ahaas92 3:b029a3f73a9e 91 static int16_t iTempBlowerFlowForSmallSmooth[SMOOTH_BLOWER_FLOW_SMALL_COUNTER];
ahaas92 3:b029a3f73a9e 92 static int16_t iTempBlowerFlowForLargeSmooth[SMOOTH_BLOWER_FLOW_LARGE_COUNTER];
ahaas92 3:b029a3f73a9e 93 static u8 ucIndexSmallBlowerFlowSmooth=0;
ahaas92 3:b029a3f73a9e 94 static u8 ucIndexLargeBlowerFlowSmooth=0;
ahaas92 3:b029a3f73a9e 95
ahaas92 3:b029a3f73a9e 96 static int16_t idConductancedtSmooth[SMOOTH_BLOWER_FLOW_SMALL_COUNTER];
ahaas92 3:b029a3f73a9e 97 #endif // (SDP600_USED_I2C1_BUS) || (X201641_USED_I2C1_BUS)
ahaas92 3:b029a3f73a9e 98 #endif // C_M3_DEVICETEST_TARGET
ahaas92 3:b029a3f73a9e 99
ahaas92 3:b029a3f73a9e 100
ahaas92 3:b029a3f73a9e 101
ahaas92 3:b029a3f73a9e 102 // ****************** PROXIMAL PRESSURE SENSOR MANAGEMENT **********************
ahaas92 3:b029a3f73a9e 103 #ifndef C_M3_DEVICETEST_TARGET
ahaas92 3:b029a3f73a9e 104 #define SMOOTH_PPROX_PRESSURE_COUNTER 40
ahaas92 3:b029a3f73a9e 105 static u8 ucIndexPproxPressureSmooth=0;
ahaas92 3:b029a3f73a9e 106 static u16 uiProximalPressureTemp[SMOOTH_PPROX_PRESSURE_COUNTER];
ahaas92 3:b029a3f73a9e 107 #endif // C_M3_DEVICETEST_TARGET
ahaas92 3:b029a3f73a9e 108
ahaas92 3:b029a3f73a9e 109
ahaas92 3:b029a3f73a9e 110
ahaas92 3:b029a3f73a9e 111 // ********************* MEASURES MANAGEMENT **********************************
ahaas92 3:b029a3f73a9e 112 #ifndef C_M3_DEVICETEST_TARGET
ahaas92 3:b029a3f73a9e 113 // ---- Current measurement
ahaas92 3:b029a3f73a9e 114 static u32 ulSumCurrentADCMesFiltered=0;
ahaas92 3:b029a3f73a9e 115 static u32 ulCounterADC_FilteredBlowerCurrentMes=0;
ahaas92 3:b029a3f73a9e 116
ahaas92 3:b029a3f73a9e 117 // ---- Temperature measurement
ahaas92 3:b029a3f73a9e 118 static u32 ulADCSumBlowerTemperature=0;
ahaas92 3:b029a3f73a9e 119 static u16 uiTemperatureSamplesCounter=0;
ahaas92 3:b029a3f73a9e 120
ahaas92 3:b029a3f73a9e 121 #ifdef TEMPERATURE_TRENDS
ahaas92 3:b029a3f73a9e 122 #ifdef USE_FLOW_COMPUTER
ahaas92 3:b029a3f73a9e 123 #define FLOW_COMPUTER_CYCLE_DETECTION_TIMER 10 // 100ms
ahaas92 3:b029a3f73a9e 124 static u8 ucFlowComputerCycle=EXPIRATION_CYCLE;
ahaas92 3:b029a3f73a9e 125 static u16 uiFlowComputerCycleModificationTimer=FLOW_COMPUTER_CYCLE_DETECTION_TIMER;
ahaas92 3:b029a3f73a9e 126 #else
ahaas92 3:b029a3f73a9e 127 #define TIME_OUT_TEMPERATURE_MEASUREMENT 6000 // 60s
ahaas92 3:b029a3f73a9e 128 static u16 uiTimeOutTemperatureMeasurement=0;
ahaas92 3:b029a3f73a9e 129 #endif // #ifdef USE_FLOW_COMPUTER
ahaas92 3:b029a3f73a9e 130 static u32 ulADCSumTemperaturePhaseA=0;
ahaas92 3:b029a3f73a9e 131 static u16 uiADCTemperaturePhaseA;
ahaas92 3:b029a3f73a9e 132 static u32 ulADCSumTemperaturePhaseB=0;
ahaas92 3:b029a3f73a9e 133 static u16 uiADCTemperaturePhaseB;
ahaas92 3:b029a3f73a9e 134 static u32 ulADCSumTemperaturePhaseC=0;
ahaas92 3:b029a3f73a9e 135 static u16 uiADCTemperaturePhaseC;
ahaas92 3:b029a3f73a9e 136 #endif
ahaas92 3:b029a3f73a9e 137
ahaas92 3:b029a3f73a9e 138 // ---- Blower Speed measurment
ahaas92 3:b029a3f73a9e 139 static u32 ulSumTachoTicks=0;
ahaas92 3:b029a3f73a9e 140 static u32 ulCounterAverageMotorSpeed=0;
ahaas92 3:b029a3f73a9e 141
ahaas92 3:b029a3f73a9e 142 // --- Blower current Bessel filter
ahaas92 3:b029a3f73a9e 143 /*static u16 uiCurrentADCMesFilteredPrev2;
ahaas92 3:b029a3f73a9e 144 static u16 uiCurrentADCMesFilteredPrev1;
ahaas92 3:b029a3f73a9e 145 static u16 uiCurrentADCMesPrev2;
ahaas92 3:b029a3f73a9e 146 static u16 uiCurrentADCMesPrev1;
ahaas92 3:b029a3f73a9e 147 static u16 uiCurrentADCMesFiltered;*/
ahaas92 3:b029a3f73a9e 148
ahaas92 3:b029a3f73a9e 149 // --- Motor voltage
ahaas92 3:b029a3f73a9e 150 static u32 ulSumADC_MotorVoltage;
ahaas92 3:b029a3f73a9e 151 static u32 ulCounterADC_MotorVoltage;
ahaas92 3:b029a3f73a9e 152
ahaas92 3:b029a3f73a9e 153 // --- Temporary measurements
ahaas92 3:b029a3f73a9e 154 static u16 uiPproxMax;
ahaas92 3:b029a3f73a9e 155 static u16 uiVtiTemp;
ahaas92 3:b029a3f73a9e 156 static u16 uiVteTemp;
ahaas92 3:b029a3f73a9e 157 static u16 uiTiMesTemp;
ahaas92 3:b029a3f73a9e 158 static u16 uiTeMesTemp;
ahaas92 3:b029a3f73a9e 159 #endif // #ifndef C_M3_DEVICETEST_TARGET
ahaas92 3:b029a3f73a9e 160
ahaas92 3:b029a3f73a9e 161
ahaas92 3:b029a3f73a9e 162 #ifndef C_M3_DEVICETEST_TARGET
ahaas92 3:b029a3f73a9e 163 static u8 ucVentilationCycleCopy=INSPIRATION_CYCLE;
ahaas92 3:b029a3f73a9e 164 static int32_t lSumVti=0;
ahaas92 3:b029a3f73a9e 165 static int32_t lSumVte=0;
ahaas92 3:b029a3f73a9e 166 static u8 ucCounterAlarmVteMin=0;
ahaas92 3:b029a3f73a9e 167 static u8 ucCounterLPAlarm=0;
ahaas92 3:b029a3f73a9e 168 #endif // C_M3_DEVICETEST_TARGET
ahaas92 3:b029a3f73a9e 169
ahaas92 3:b029a3f73a9e 170
ahaas92 3:b029a3f73a9e 171 #define RCC_APB2RSTR (*(volatile uint32_t *)0x4002100c)
ahaas92 3:b029a3f73a9e 172
ahaas92 3:b029a3f73a9e 173
ahaas92 3:b029a3f73a9e 174 // ***************** Functions **********************************************
ahaas92 3:b029a3f73a9e 175 int16_t ComputeFlowInLitersPerMin(u16 uFlowRAW, bool bPositiveFlow);
ahaas92 3:b029a3f73a9e 176 void ComputeBlowerPower(void);
ahaas92 3:b029a3f73a9e 177 u16 ComputeTemperature(u16 uiADCMotorTemp, u16 *puiTempLUT, u16 uiTemperatureGain);
ahaas92 3:b029a3f73a9e 178
ahaas92 3:b029a3f73a9e 179
ahaas92 3:b029a3f73a9e 180 /*******************************************************************************
ahaas92 3:b029a3f73a9e 181 * Function Name : ADC1_init
ahaas92 3:b029a3f73a9e 182 * Description : Init ADC1
ahaas92 3:b029a3f73a9e 183 * Input : None
ahaas92 3:b029a3f73a9e 184 * Output : None
ahaas92 3:b029a3f73a9e 185 * Return : None
ahaas92 3:b029a3f73a9e 186 *******************************************************************************/
ahaas92 3:b029a3f73a9e 187 void ADC1_init(void)
ahaas92 3:b029a3f73a9e 188 {
ahaas92 3:b029a3f73a9e 189 // First perform De_init
ahaas92 3:b029a3f73a9e 190 DMA_CCR1 &= (uint32_t)(~0x1); // channel 1 disable
ahaas92 3:b029a3f73a9e 191 DMA_CCR1 = 0; // Reset Channelx control register
ahaas92 3:b029a3f73a9e 192 DMA_CNTDR1 = 0; // Reset Channelx remaining bytes register
ahaas92 3:b029a3f73a9e 193 DMA_CPAR1 = 0; // Reset Channelx peripheral address register
ahaas92 3:b029a3f73a9e 194 DMA_CMAR1 = 0; // Reset Channelx memory address register
ahaas92 3:b029a3f73a9e 195 DMA_IFCR1 |= DMA_Channel1_IT_Mask; // Reset interrupt pending bits
ahaas92 3:b029a3f73a9e 196 // end de-init
ahaas92 3:b029a3f73a9e 197
ahaas92 3:b029a3f73a9e 198 // Initialise DMA #1
ahaas92 3:b029a3f73a9e 199 DMA_CPAR1 = (uint32_t)(ADC1_BASE + 0x4c); // base adress of ADC1 ADC_DR register
ahaas92 3:b029a3f73a9e 200
ahaas92 3:b029a3f73a9e 201 DMA_CMAR1 = (unsigned long)(&uiADC_Value[0]);
ahaas92 3:b029a3f73a9e 202 DMA_CNTDR1 = NUMBER_ADC_CONVERSION; // numbers of data to be transfered
ahaas92 3:b029a3f73a9e 203
ahaas92 3:b029a3f73a9e 204 DMA_CCR1 = (3<<12) + (1<<10) + (1<<8) + (1<<7) + (1<<5) /*+ (1<<1)*/; // very high priority, mem size 16 bits, periph size 16 bits, mem increase,/* circular enabled*/, /*transfer complete IT*/
ahaas92 3:b029a3f73a9e 205 DMA_CCR1 |= 1; // channel 1 enable
ahaas92 3:b029a3f73a9e 206
ahaas92 3:b029a3f73a9e 207
ahaas92 3:b029a3f73a9e 208
ahaas92 3:b029a3f73a9e 209 // De-init of the ADC 1
ahaas92 3:b029a3f73a9e 210 RCC_APB2RSTR |= RCC_APB2Periph_ADC1; // enable
ahaas92 3:b029a3f73a9e 211 RCC_APB2RSTR &= ~RCC_APB2Periph_ADC1; // disable
ahaas92 3:b029a3f73a9e 212 // end De-init of the ADC 1
ahaas92 3:b029a3f73a9e 213
ahaas92 3:b029a3f73a9e 214 // Select channels of the regular group
ahaas92 3:b029a3f73a9e 215 #ifdef TEMPERATURE_TRENDS
ahaas92 3:b029a3f73a9e 216 ADC1_SQR1 = ((NUMBER_ADC_CONVERSION-1)<<20) + (FREE_MEAS_CHANNEL<<15) + (FREE_MEAS_CHANNEL<<10) + (FREE_MEAS_CHANNEL<<5) + FREE_MEAS_CHANNEL;
ahaas92 3:b029a3f73a9e 217 ADC1_SQR2 = (FREE_MEAS_CHANNEL<<25) + (FREE_MEAS_CHANNEL<<20) + (FREE_MEAS_CHANNEL<<15) + (FREE_MEAS_CHANNEL<<10) + (FREE_MEAS_CHANNEL<<5) + TEMP_PHASE_C;
ahaas92 3:b029a3f73a9e 218 ADC1_SQR3 = (TEMP_PHASE_B<<25) + (TEMP_PHASE_A<<20) + (FREE_MEAS_CHANNEL<<15) + (CURRENT_MEAS_CHANNEL<<10) + (ALIM_24V_MEAS_CHANNEL<<5) + PPROX_MEAS_CHANNEL;
ahaas92 3:b029a3f73a9e 219 #else
ahaas92 3:b029a3f73a9e 220 ADC1_SQR1 = ((NUMBER_ADC_CONVERSION-1)<<20) + (FREE_MEAS_CHANNEL<<15) + (FREE_MEAS_CHANNEL<<10) + (FREE_MEAS_CHANNEL<<5) + FREE_MEAS_CHANNEL;
ahaas92 3:b029a3f73a9e 221 ADC1_SQR2 = (FREE_MEAS_CHANNEL<<25) + (FREE_MEAS_CHANNEL<<20) + (FREE_MEAS_CHANNEL<<15) + (FREE_MEAS_CHANNEL<<10) + (FREE_MEAS_CHANNEL<<5) + FREE_MEAS_CHANNEL;
ahaas92 3:b029a3f73a9e 222 ADC1_SQR3 = (FREE_MEAS_CHANNEL<<25) + (FREE_MEAS_CHANNEL<<20) + (FREE_MEAS_CHANNEL<<15) + (CURRENT_MEAS_CHANNEL<<10) + (ALIM_24V_MEAS_CHANNEL<<5) + PPROX_MEAS_CHANNEL;
ahaas92 3:b029a3f73a9e 223 #endif
ahaas92 3:b029a3f73a9e 224
ahaas92 3:b029a3f73a9e 225 // 21 micros ADC conversion time
ahaas92 3:b029a3f73a9e 226 ADC1->SMPR2= (7<<27) + (7<<24) + (7<<21) + (7<<18) + (7<<15) + (7<<12) + (7<<9) + (7<<6) + (7<<3) + 7;
ahaas92 3:b029a3f73a9e 227 ADC1->SMPR1= (7<<21) + (7<<18) + (7<<15) + (7<<12) + (7<<9) + (7<<6) + (7<<3) + 7;
ahaas92 3:b029a3f73a9e 228
ahaas92 3:b029a3f73a9e 229 ADC1_CR1 = (1<<8); // Scan mode enabled
ahaas92 3:b029a3f73a9e 230 ADC1_CR2 = (1<<8); // DMA mode enabled
ahaas92 3:b029a3f73a9e 231
ahaas92 3:b029a3f73a9e 232 ADC1_CR2 |= 1; // start ADC1 - power-on
ahaas92 3:b029a3f73a9e 233
ahaas92 3:b029a3f73a9e 234 // Delay at least 1uSec for ADC calibration/stabilisation. See ADC documentation
ahaas92 3:b029a3f73a9e 235 // Stabilization time > 1uS for ADC, between power-on and start of conversion
ahaas92 3:b029a3f73a9e 236 // Give it 10uSecs just to be sure.
ahaas92 3:b029a3f73a9e 237 Delay100NS(100);
ahaas92 3:b029a3f73a9e 238
ahaas92 3:b029a3f73a9e 239 // Calibration of ADC1
ahaas92 3:b029a3f73a9e 240 ADC1_CR2 |= (1<<3); // reset calibration registers
ahaas92 3:b029a3f73a9e 241 ADC1_CR2 |= (1<<2); // Enable calibration
ahaas92 3:b029a3f73a9e 242 while ((ADC1_CR2 & (1<<2)) == (1<<2)); // Wait end of calibration
ahaas92 3:b029a3f73a9e 243
ahaas92 3:b029a3f73a9e 244 ADC1_CR2 |= 1; // start ADC1 - start conversions
ahaas92 3:b029a3f73a9e 245 }
ahaas92 3:b029a3f73a9e 246
ahaas92 3:b029a3f73a9e 247
ahaas92 3:b029a3f73a9e 248 /*******************************************************************************
ahaas92 3:b029a3f73a9e 249 * Function Name : CheckAlimMotorVoltage
ahaas92 3:b029a3f73a9e 250 * Description : Check the voltage range of the 24V power supply
ahaas92 3:b029a3f73a9e 251 * Input : None
ahaas92 3:b029a3f73a9e 252 * Output : None
ahaas92 3:b029a3f73a9e 253 * Return : OPSTATUS_OK or OPSTATUS_FAIL
ahaas92 3:b029a3f73a9e 254 *******************************************************************************/
ahaas92 3:b029a3f73a9e 255 opstatus_t CheckAlimMotorVoltage(void)
ahaas92 3:b029a3f73a9e 256 {
ahaas92 3:b029a3f73a9e 257 if (uiDCinADCMeas<271 || uiDCinADCMeas>2090)
ahaas92 3:b029a3f73a9e 258 return(OPSTATUS_FAIL); // <12V or >24V
ahaas92 3:b029a3f73a9e 259 return(OPSTATUS_OK);
ahaas92 3:b029a3f73a9e 260 }
ahaas92 3:b029a3f73a9e 261
ahaas92 3:b029a3f73a9e 262
ahaas92 3:b029a3f73a9e 263 /*******************************************************************************
ahaas92 3:b029a3f73a9e 264 * Function Name : Compute24VMeasure
ahaas92 3:b029a3f73a9e 265 * Description : Compute the 24V measure
ahaas92 3:b029a3f73a9e 266 * Input : None
ahaas92 3:b029a3f73a9e 267 * Output : None
ahaas92 3:b029a3f73a9e 268 * Return : OPSTATUS_OK or OPSTATUS_FAIL
ahaas92 3:b029a3f73a9e 269 *******************************************************************************/
ahaas92 3:b029a3f73a9e 270 #ifndef C_M3_DEVICETEST_TARGET
ahaas92 3:b029a3f73a9e 271 void Compute24VMeasure(void)
ahaas92 3:b029a3f73a9e 272 {
ahaas92 3:b029a3f73a9e 273 u32 ulTemp;
ahaas92 3:b029a3f73a9e 274 u16 uiADC_BlowerVoltage;
ahaas92 3:b029a3f73a9e 275
ahaas92 3:b029a3f73a9e 276 if (bMemoStartVentilation==TRUE)
ahaas92 3:b029a3f73a9e 277 uiADC_BlowerVoltage=uiAverageADC_MotorVoltage;
ahaas92 3:b029a3f73a9e 278 else
ahaas92 3:b029a3f73a9e 279 uiADC_BlowerVoltage=uiDCinADCMeas;
ahaas92 3:b029a3f73a9e 280
ahaas92 3:b029a3f73a9e 281 ulTemp=((u32)uiADC_BlowerVoltage*100)/1452;
ahaas92 3:b029a3f73a9e 282 ulTemp+=100;
ahaas92 3:b029a3f73a9e 283 uiTechnicalDataMes[MOTOR_VOLTAGE_TEC_MES]=(u16)ulTemp;
ahaas92 3:b029a3f73a9e 284 uiMotorVoltageMes=(u16)ulTemp;
ahaas92 3:b029a3f73a9e 285 }
ahaas92 3:b029a3f73a9e 286 #endif
ahaas92 3:b029a3f73a9e 287
ahaas92 3:b029a3f73a9e 288 void GetFirstMotorVoltageReading(void)
ahaas92 3:b029a3f73a9e 289 {
ahaas92 3:b029a3f73a9e 290 uiAverageADC_MotorVoltage=uiDCinADCMeas;
ahaas92 3:b029a3f73a9e 291 }
ahaas92 3:b029a3f73a9e 292 /*******************************************************************************
ahaas92 3:b029a3f73a9e 293 * Function Name : ComputeBlowerPower
ahaas92 3:b029a3f73a9e 294 * Description : Compute the power of the blower
ahaas92 3:b029a3f73a9e 295 * Input : None
ahaas92 3:b029a3f73a9e 296 * Output : None
ahaas92 3:b029a3f73a9e 297 * Return : OPSTATUS_OK or OPSTATUS_FAIL
ahaas92 3:b029a3f73a9e 298 *******************************************************************************/
ahaas92 3:b029a3f73a9e 299 void ComputeBlowerPower(void)
ahaas92 3:b029a3f73a9e 300 {
ahaas92 3:b029a3f73a9e 301 uiTechnicalDataMes[MOTOR_POWER_TEC_MES]=((u32)uiMotorVoltageMes*uiBlowerCurrentMes)/10;
ahaas92 3:b029a3f73a9e 302 }
ahaas92 3:b029a3f73a9e 303
ahaas92 3:b029a3f73a9e 304 /*******************************************************************************
ahaas92 3:b029a3f73a9e 305 * Function Name : SpeedMeasurement
ahaas92 3:b029a3f73a9e 306 * Description : Return blower speed
ahaas92 3:b029a3f73a9e 307 * Input : Tacho counter
ahaas92 3:b029a3f73a9e 308 * Output : None
ahaas92 3:b029a3f73a9e 309 * Return : Blower speed in RPM
ahaas92 3:b029a3f73a9e 310 *******************************************************************************/
ahaas92 3:b029a3f73a9e 311 u16 SpeedMeasurement(u16 uiTachoCounter)
ahaas92 3:b029a3f73a9e 312 {
ahaas92 3:b029a3f73a9e 313 u16 uiSpeedTemp=65500;
ahaas92 3:b029a3f73a9e 314
ahaas92 3:b029a3f73a9e 315 if (uiTachoCounter>915)
ahaas92 3:b029a3f73a9e 316 uiSpeedTemp=(u16)(60000000UL/uiTachoCounter);
ahaas92 3:b029a3f73a9e 317
ahaas92 3:b029a3f73a9e 318 return(uiSpeedTemp);
ahaas92 3:b029a3f73a9e 319 }
ahaas92 3:b029a3f73a9e 320
ahaas92 3:b029a3f73a9e 321
ahaas92 3:b029a3f73a9e 322 /*******************************************************************************
ahaas92 3:b029a3f73a9e 323 * Function Name : ReadADCInputs
ahaas92 3:b029a3f73a9e 324 * Description : Read all ADC input (function calls every 1ms)
ahaas92 3:b029a3f73a9e 325 * Input : None
ahaas92 3:b029a3f73a9e 326 * Output : None
ahaas92 3:b029a3f73a9e 327 * Return : None
ahaas92 3:b029a3f73a9e 328 *******************************************************************************/
ahaas92 3:b029a3f73a9e 329 void ReadADCInputs(void)
ahaas92 3:b029a3f73a9e 330 {
ahaas92 3:b029a3f73a9e 331 //u32 ulTerm1, ulTerm2, ulTerm3, ulTerm4, ulTerm5;
ahaas92 3:b029a3f73a9e 332
ahaas92 3:b029a3f73a9e 333 // ADC Pprox measurement
ahaas92 3:b029a3f73a9e 334 uiProximalPressureADCMes=uiADC_Value[ADC_PPROX_MES];
ahaas92 3:b029a3f73a9e 335
ahaas92 3:b029a3f73a9e 336 // ADC DCin measurement
ahaas92 3:b029a3f73a9e 337 uiDCinADCMeas=uiADC_Value[ADC_DCIN_MES];
ahaas92 3:b029a3f73a9e 338
ahaas92 3:b029a3f73a9e 339 // ADC Blower current measurement
ahaas92 3:b029a3f73a9e 340 ComputeADCBlowerCurrent(FALSE);
ahaas92 3:b029a3f73a9e 341
ahaas92 3:b029a3f73a9e 342 // ADC Free measurement
ahaas92 3:b029a3f73a9e 343 uiADCBlowerTemperatureMeas=uiADC_Value[ADC_FREE_MES];
ahaas92 3:b029a3f73a9e 344
ahaas92 3:b029a3f73a9e 345 #ifdef TEMPERATURE_TRENDS
ahaas92 3:b029a3f73a9e 346 uiADCTemperaturePhaseA=uiADC_Value[ADC_TEMP_PHASE_A];
ahaas92 3:b029a3f73a9e 347 uiADCTemperaturePhaseB=uiADC_Value[ADC_TEMP_PHASE_B];
ahaas92 3:b029a3f73a9e 348 uiADCTemperaturePhaseC=uiADC_Value[ADC_TEMP_PHASE_C];
ahaas92 3:b029a3f73a9e 349 #endif
ahaas92 3:b029a3f73a9e 350
ahaas92 3:b029a3f73a9e 351 // 2nd order Bessel Filter (Fcut-out=36Hz, sample rate=1KHz)
ahaas92 3:b029a3f73a9e 352 /*ulTerm1=(919UL*uiADCBlowerCurrent)>>6;
ahaas92 3:b029a3f73a9e 353 ulTerm2=(919UL*uiCurrentADCMesPrev1)>>5;
ahaas92 3:b029a3f73a9e 354 ulTerm3=(919UL*uiCurrentADCMesPrev2)>>6;
ahaas92 3:b029a3f73a9e 355 ulTerm4=(1427UL*uiCurrentADCMesFilteredPrev1)>>1;
ahaas92 3:b029a3f73a9e 356 ulTerm5=259UL*uiCurrentADCMesFilteredPrev2;
ahaas92 3:b029a3f73a9e 357
ahaas92 3:b029a3f73a9e 358 uiCurrentADCMesFiltered=(ulTerm1+ulTerm2+ulTerm3+ulTerm4-ulTerm5)>>9;
ahaas92 3:b029a3f73a9e 359 uiCurrentADCMesFilteredPrev2=uiCurrentADCMesFilteredPrev1;
ahaas92 3:b029a3f73a9e 360 uiCurrentADCMesFilteredPrev1=uiCurrentADCMesFiltered;
ahaas92 3:b029a3f73a9e 361 uiCurrentADCMesPrev2=uiCurrentADCMesPrev1;
ahaas92 3:b029a3f73a9e 362 uiCurrentADCMesPrev1=uiADCBlowerCurrent;*/
ahaas92 3:b029a3f73a9e 363
ahaas92 3:b029a3f73a9e 364
ahaas92 3:b029a3f73a9e 365 // 2nd order Bessel Filter (Fcut-out=150Hz, sample rate=1KHz)
ahaas92 3:b029a3f73a9e 366 /*ulTerm1=(1929UL*uiADCBlowerCurrent)>>1;
ahaas92 3:b029a3f73a9e 367 ulTerm2=(1929UL*uiCurrentADCMesPrev1);
ahaas92 3:b029a3f73a9e 368 ulTerm3=(1929UL*uiCurrentADCMesPrev2)>>1;
ahaas92 3:b029a3f73a9e 369 ulTerm4=(1095UL*uiCurrentADCMesFilteredPrev1)>>1;
ahaas92 3:b029a3f73a9e 370 ulTerm5=(2479UL*uiCurrentADCMesFilteredPrev2)>>3;
ahaas92 3:b029a3f73a9e 371
ahaas92 3:b029a3f73a9e 372 uiCurrentADCMesFiltered=(ulTerm1+ulTerm2+ulTerm3+ulTerm4-ulTerm5)>>12;
ahaas92 3:b029a3f73a9e 373 uiCurrentADCMesFilteredPrev2=uiCurrentADCMesFilteredPrev1;
ahaas92 3:b029a3f73a9e 374 uiCurrentADCMesFilteredPrev1=uiCurrentADCMesFiltered;
ahaas92 3:b029a3f73a9e 375 uiCurrentADCMesPrev2=uiCurrentADCMesPrev1;
ahaas92 3:b029a3f73a9e 376 uiCurrentADCMesPrev1=uiADCBlowerCurrent;*/
ahaas92 3:b029a3f73a9e 377
ahaas92 3:b029a3f73a9e 378 // --- Start new conversions
ahaas92 3:b029a3f73a9e 379 ADC1->CR2 |= 1;
ahaas92 3:b029a3f73a9e 380 }
ahaas92 3:b029a3f73a9e 381
ahaas92 3:b029a3f73a9e 382 #ifndef C_M3_DEVICETEST_TARGET
ahaas92 3:b029a3f73a9e 383 /*******************************************************************************
ahaas92 3:b029a3f73a9e 384 * Function Name : ComputeMeasurements
ahaas92 3:b029a3f73a9e 385 * Description : Compute different measures
ahaas92 3:b029a3f73a9e 386 * Input : None
ahaas92 3:b029a3f73a9e 387 * Output : None
ahaas92 3:b029a3f73a9e 388 * Return : None
ahaas92 3:b029a3f73a9e 389 *******************************************************************************/
ahaas92 3:b029a3f73a9e 390 void ComputeMeasurements(void)
ahaas92 3:b029a3f73a9e 391 {
ahaas92 3:b029a3f73a9e 392 // ---------------------- Measure Current (A) ----------------------------
ahaas92 3:b029a3f73a9e 393 uiBlowerCurrentMes=ComputeBlowerCurrentInAmper(uiADCBlowerCurrent);
ahaas92 3:b029a3f73a9e 394
ahaas92 3:b029a3f73a9e 395 // -------------------- Compute motor voltage (V) ------------------------
ahaas92 3:b029a3f73a9e 396 Compute24VMeasure();
ahaas92 3:b029a3f73a9e 397 ComputeBlowerPower();
ahaas92 3:b029a3f73a9e 398
ahaas92 3:b029a3f73a9e 399 // ---------------------- Others measurements ----------------------------
ahaas92 3:b029a3f73a9e 400 if (bMemoStartVentilation==TRUE)
ahaas92 3:b029a3f73a9e 401 {
ahaas92 3:b029a3f73a9e 402 // --- Motor speed (RPM) (every 10ms)
ahaas92 3:b029a3f73a9e 403 uiBlowerSpeedMes=SpeedMeasurement(uiTachoTimeTicks);
ahaas92 3:b029a3f73a9e 404 }
ahaas92 3:b029a3f73a9e 405 }
ahaas92 3:b029a3f73a9e 406 #endif // #ifndef C_M3_DEVICETEST_TARGET
ahaas92 3:b029a3f73a9e 407
ahaas92 3:b029a3f73a9e 408
ahaas92 3:b029a3f73a9e 409 #ifndef C_M3_DEVICETEST_TARGET
ahaas92 3:b029a3f73a9e 410 #ifdef TEMPERATURE_TRENDS
ahaas92 3:b029a3f73a9e 411 /*******************************************************************************
ahaas92 3:b029a3f73a9e 412 * Function Name : ComputeAverageOnMeasurements
ahaas92 3:b029a3f73a9e 413 * Description : Average differents mesures : MUST BE CALLED EVERY 10ms
ahaas92 3:b029a3f73a9e 414 * Input : None
ahaas92 3:b029a3f73a9e 415 * Output : None
ahaas92 3:b029a3f73a9e 416 * Return : None
ahaas92 3:b029a3f73a9e 417 *******************************************************************************/
ahaas92 3:b029a3f73a9e 418 void ComputeAverageOnMeasurements(void)
ahaas92 3:b029a3f73a9e 419 {
ahaas92 3:b029a3f73a9e 420 #ifdef USE_FLOW_COMPUTER
ahaas92 3:b029a3f73a9e 421 // ----------- USE THE FLOW COMPUTER TO DETECT CYCLE ----------------
ahaas92 3:b029a3f73a9e 422 u16 uiDummy;
ahaas92 3:b029a3f73a9e 423 opstatus_t opstatus;
ahaas92 3:b029a3f73a9e 424
ahaas92 3:b029a3f73a9e 425 // Read new flow from flow computer every 10ms
ahaas92 3:b029a3f73a9e 426 opstatus=SS_Xgetw(flc, &uiDummy);
ahaas92 3:b029a3f73a9e 427 if (opstatus==OPSTATUS_OK)
ahaas92 3:b029a3f73a9e 428 {
ahaas92 3:b029a3f73a9e 429 // Update flow/pressure displayed
ahaas92 3:b029a3f73a9e 430 uiBlowerFlow=iFlowFromFlowComputer*10;
ahaas92 3:b029a3f73a9e 431 uiPoutPressureMes=uiPressureFromFlowComputer;
ahaas92 3:b029a3f73a9e 432
ahaas92 3:b029a3f73a9e 433 // Comm with flow computer OK !!
ahaas92 3:b029a3f73a9e 434 #ifdef DATA_LOGGING
ahaas92 3:b029a3f73a9e 435 if (bRecordTemperatureTrendsAllowed==FALSE)
ahaas92 3:b029a3f73a9e 436 {
ahaas92 3:b029a3f73a9e 437 bRecordTemperatureTrendsAllowed=TRUE;
ahaas92 3:b029a3f73a9e 438 uiTrendsSampleTime=RECORD_TRENDS_SAMPLE_TIME;
ahaas92 3:b029a3f73a9e 439 }
ahaas92 3:b029a3f73a9e 440 #endif // DATA_LOGGING
ahaas92 3:b029a3f73a9e 441
ahaas92 3:b029a3f73a9e 442 // inspiration/expiration cycle detection
ahaas92 3:b029a3f73a9e 443 if (ucFlowComputerCycle==EXPIRATION_CYCLE)
ahaas92 3:b029a3f73a9e 444 {
ahaas92 3:b029a3f73a9e 445 // Inspiration detection
ahaas92 3:b029a3f73a9e 446 if (iFlowFromFlowComputer>50) // 5l/min
ahaas92 3:b029a3f73a9e 447 {
ahaas92 3:b029a3f73a9e 448 uiFlowComputerCycleModificationTimer--;
ahaas92 3:b029a3f73a9e 449 if (uiFlowComputerCycleModificationTimer==0)
ahaas92 3:b029a3f73a9e 450 {
ahaas92 3:b029a3f73a9e 451 ucFlowComputerCycle=INSPIRATION_CYCLE;
ahaas92 3:b029a3f73a9e 452
ahaas92 3:b029a3f73a9e 453 // Compute temperature of the previous inspiratory cycle
ahaas92 3:b029a3f73a9e 454 if (uiTemperatureSamplesCounter!=0)
ahaas92 3:b029a3f73a9e 455 {
ahaas92 3:b029a3f73a9e 456 uiTechnicalDataMes[MOTOR_TEMPERATURE_TEC_MES]=ComputeMotorTemperature(ulADCSumBlowerTemperature/uiTemperatureSamplesCounter);
ahaas92 3:b029a3f73a9e 457 uiADCAverageTemperaturePhaseA=ulADCSumTemperaturePhaseA/uiTemperatureSamplesCounter;
ahaas92 3:b029a3f73a9e 458 uiADCAverageTemperaturePhaseB=ulADCSumTemperaturePhaseB/uiTemperatureSamplesCounter;
ahaas92 3:b029a3f73a9e 459 uiADCAverageTemperaturePhaseC=ulADCSumTemperaturePhaseC/uiTemperatureSamplesCounter;
ahaas92 3:b029a3f73a9e 460 }
ahaas92 3:b029a3f73a9e 461 ulADCSumBlowerTemperature=0;
ahaas92 3:b029a3f73a9e 462 ulADCSumTemperaturePhaseA=0;
ahaas92 3:b029a3f73a9e 463 ulADCSumTemperaturePhaseB=0;
ahaas92 3:b029a3f73a9e 464 ulADCSumTemperaturePhaseC=0;
ahaas92 3:b029a3f73a9e 465 uiTemperatureSamplesCounter=0;
ahaas92 3:b029a3f73a9e 466 }
ahaas92 3:b029a3f73a9e 467 }
ahaas92 3:b029a3f73a9e 468 else
ahaas92 3:b029a3f73a9e 469 uiFlowComputerCycleModificationTimer=FLOW_COMPUTER_CYCLE_DETECTION_TIMER;
ahaas92 3:b029a3f73a9e 470 }
ahaas92 3:b029a3f73a9e 471 else
ahaas92 3:b029a3f73a9e 472 {
ahaas92 3:b029a3f73a9e 473 // Record temperature as long as the flow is positive
ahaas92 3:b029a3f73a9e 474 if (iFlowFromFlowComputer>(-10)) // >-1l/min
ahaas92 3:b029a3f73a9e 475 {
ahaas92 3:b029a3f73a9e 476 ulADCSumBlowerTemperature+=uiADCBlowerTemperatureMeas;
ahaas92 3:b029a3f73a9e 477 ulADCSumTemperaturePhaseA+=uiADCTemperaturePhaseA;
ahaas92 3:b029a3f73a9e 478 ulADCSumTemperaturePhaseB+=uiADCTemperaturePhaseB;
ahaas92 3:b029a3f73a9e 479 ulADCSumTemperaturePhaseC+=uiADCTemperaturePhaseC;
ahaas92 3:b029a3f73a9e 480 uiTemperatureSamplesCounter++;
ahaas92 3:b029a3f73a9e 481 }
ahaas92 3:b029a3f73a9e 482
ahaas92 3:b029a3f73a9e 483 // Expiration detection
ahaas92 3:b029a3f73a9e 484 if (iFlowFromFlowComputer<(-50)) // <-5l/min
ahaas92 3:b029a3f73a9e 485 {
ahaas92 3:b029a3f73a9e 486 uiFlowComputerCycleModificationTimer--;
ahaas92 3:b029a3f73a9e 487 if (uiFlowComputerCycleModificationTimer==0)
ahaas92 3:b029a3f73a9e 488 ucFlowComputerCycle=EXPIRATION_CYCLE;
ahaas92 3:b029a3f73a9e 489 }
ahaas92 3:b029a3f73a9e 490 else
ahaas92 3:b029a3f73a9e 491 uiFlowComputerCycleModificationTimer=FLOW_COMPUTER_CYCLE_DETECTION_TIMER;
ahaas92 3:b029a3f73a9e 492 }
ahaas92 3:b029a3f73a9e 493 }
ahaas92 3:b029a3f73a9e 494 else if (opstatus==OPSTATUS_FAIL)
ahaas92 3:b029a3f73a9e 495 {
ahaas92 3:b029a3f73a9e 496 // Comm Failure with flow computer => no data recorded
ahaas92 3:b029a3f73a9e 497 uiBlowerFlow=0;
ahaas92 3:b029a3f73a9e 498 uiPoutPressureMes=0;
ahaas92 3:b029a3f73a9e 499
ahaas92 3:b029a3f73a9e 500 #ifdef DATA_LOGGING
ahaas92 3:b029a3f73a9e 501 bRecordTemperatureTrendsAllowed=FALSE;
ahaas92 3:b029a3f73a9e 502 #endif
ahaas92 3:b029a3f73a9e 503 uiTechnicalDataMes[MOTOR_TEMPERATURE_TEC_MES]=0;
ahaas92 3:b029a3f73a9e 504 }
ahaas92 3:b029a3f73a9e 505 #else
ahaas92 3:b029a3f73a9e 506 // ----------- USE THE 24V MEASURE TO DETECT CYCLE ----------------
ahaas92 3:b029a3f73a9e 507 if (uiDCinADCMeas>500)
ahaas92 3:b029a3f73a9e 508 {
ahaas92 3:b029a3f73a9e 509 // Inspiration
ahaas92 3:b029a3f73a9e 510 ulADCSumBlowerTemperature+=uiADCBlowerTemperatureMeas;
ahaas92 3:b029a3f73a9e 511 ulADCSumTemperaturePhaseA+=uiADCTemperaturePhaseA;
ahaas92 3:b029a3f73a9e 512 ulADCSumTemperaturePhaseB+=uiADCTemperaturePhaseB;
ahaas92 3:b029a3f73a9e 513 ulADCSumTemperaturePhaseC+=uiADCTemperaturePhaseC;
ahaas92 3:b029a3f73a9e 514 uiTemperatureSamplesCounter++;
ahaas92 3:b029a3f73a9e 515 uiTimeOutTemperatureMeasurement=TIME_OUT_TEMPERATURE_MEASUREMENT;
ahaas92 3:b029a3f73a9e 516 #ifdef DATA_LOGGING
ahaas92 3:b029a3f73a9e 517 bRecordTemperatureTrendsAllowed=TRUE;
ahaas92 3:b029a3f73a9e 518 #endif
ahaas92 3:b029a3f73a9e 519 }
ahaas92 3:b029a3f73a9e 520 else if (uiTimeOutTemperatureMeasurement!=0)
ahaas92 3:b029a3f73a9e 521 {
ahaas92 3:b029a3f73a9e 522 // Expiration
ahaas92 3:b029a3f73a9e 523 uiTimeOutTemperatureMeasurement--;
ahaas92 3:b029a3f73a9e 524 if (uiTemperatureSamplesCounter!=0)
ahaas92 3:b029a3f73a9e 525 {
ahaas92 3:b029a3f73a9e 526 uiTechnicalDataMes[MOTOR_TEMPERATURE_TEC_MES]=ComputeMotorTemperature(ulADCSumBlowerTemperature/uiTemperatureSamplesCounter);
ahaas92 3:b029a3f73a9e 527 uiADCAverageTemperaturePhaseA=ulADCSumTemperaturePhaseA/uiTemperatureSamplesCounter;
ahaas92 3:b029a3f73a9e 528 uiADCAverageTemperaturePhaseB=ulADCSumTemperaturePhaseB/uiTemperatureSamplesCounter;
ahaas92 3:b029a3f73a9e 529 uiADCAverageTemperaturePhaseC=ulADCSumTemperaturePhaseC/uiTemperatureSamplesCounter;
ahaas92 3:b029a3f73a9e 530 }
ahaas92 3:b029a3f73a9e 531 ulADCSumBlowerTemperature=0;
ahaas92 3:b029a3f73a9e 532 ulADCSumTemperaturePhaseA=0;
ahaas92 3:b029a3f73a9e 533 ulADCSumTemperaturePhaseB=0;
ahaas92 3:b029a3f73a9e 534 ulADCSumTemperaturePhaseC=0;
ahaas92 3:b029a3f73a9e 535 uiTemperatureSamplesCounter=0;
ahaas92 3:b029a3f73a9e 536 }
ahaas92 3:b029a3f73a9e 537 else
ahaas92 3:b029a3f73a9e 538 {
ahaas92 3:b029a3f73a9e 539 uiTechnicalDataMes[MOTOR_TEMPERATURE_TEC_MES]=0;
ahaas92 3:b029a3f73a9e 540
ahaas92 3:b029a3f73a9e 541 ulADCSumBlowerTemperature=0;
ahaas92 3:b029a3f73a9e 542 ulADCSumTemperaturePhaseA=0;
ahaas92 3:b029a3f73a9e 543 ulADCSumTemperaturePhaseB=0;
ahaas92 3:b029a3f73a9e 544 ulADCSumTemperaturePhaseC=0;
ahaas92 3:b029a3f73a9e 545 uiTemperatureSamplesCounter=0;
ahaas92 3:b029a3f73a9e 546
ahaas92 3:b029a3f73a9e 547 #ifdef DATA_LOGGING
ahaas92 3:b029a3f73a9e 548 bRecordTemperatureTrendsAllowed=FALSE;
ahaas92 3:b029a3f73a9e 549 #endif
ahaas92 3:b029a3f73a9e 550 }
ahaas92 3:b029a3f73a9e 551 #endif // #ifdef USE_FLOW_COMPUTER
ahaas92 3:b029a3f73a9e 552 }
ahaas92 3:b029a3f73a9e 553 #endif // #ifdef TEMPERATURE_TRENDS
ahaas92 3:b029a3f73a9e 554 #endif // #ifndef C_M3_DEVICETEST_TARGET
ahaas92 3:b029a3f73a9e 555
ahaas92 3:b029a3f73a9e 556
ahaas92 3:b029a3f73a9e 557 /*******************************************************************************
ahaas92 3:b029a3f73a9e 558 * Function Name : ComputeADCBlowerCurrent
ahaas92 3:b029a3f73a9e 559 * Description : Compute the average current during a PWM cycle (20micros)
ahaas92 3:b029a3f73a9e 560 * Input : bRecordCurrentOffset
ahaas92 3:b029a3f73a9e 561 * Output : None
ahaas92 3:b029a3f73a9e 562 * Return : None
ahaas92 3:b029a3f73a9e 563 *******************************************************************************/
ahaas92 3:b029a3f73a9e 564 void ComputeADCBlowerCurrent(bool bRecordCurrentOffset)
ahaas92 3:b029a3f73a9e 565 {
ahaas92 3:b029a3f73a9e 566 if (bRecordCurrentOffset==TRUE)
ahaas92 3:b029a3f73a9e 567 {
ahaas92 3:b029a3f73a9e 568 uiADCOffsetBlowerCurrent=uiADCBlowerCurrent=uiADC_Value[ADC_CURRENT_MES];
ahaas92 3:b029a3f73a9e 569 }
ahaas92 3:b029a3f73a9e 570 else
ahaas92 3:b029a3f73a9e 571 {
ahaas92 3:b029a3f73a9e 572 uiADCBlowerCurrent=uiADC_Value[ADC_CURRENT_MES];
ahaas92 3:b029a3f73a9e 573 }
ahaas92 3:b029a3f73a9e 574 }
ahaas92 3:b029a3f73a9e 575
ahaas92 3:b029a3f73a9e 576
ahaas92 3:b029a3f73a9e 577 /*******************************************************************************
ahaas92 3:b029a3f73a9e 578 * Function Name : ComputeBlowerCurrentInAmper
ahaas92 3:b029a3f73a9e 579 * Description : Return blower current value in cAmper (ex: 100=1.00A)
ahaas92 3:b029a3f73a9e 580 * Input : ADC value
ahaas92 3:b029a3f73a9e 581 * Output : None
ahaas92 3:b029a3f73a9e 582 * Return : Blower current in cAmper (ex: 100=1.00A)
ahaas92 3:b029a3f73a9e 583 *******************************************************************************/
ahaas92 3:b029a3f73a9e 584 int16_t ComputeBlowerCurrentInAmper(u16 uiADCBlowerCurrentLocal)
ahaas92 3:b029a3f73a9e 585 {
ahaas92 3:b029a3f73a9e 586 int32_t lTempValue;
ahaas92 3:b029a3f73a9e 587
ahaas92 3:b029a3f73a9e 588 // Computation using MOT_CUR_MEAS2
ahaas92 3:b029a3f73a9e 589 lTempValue=(int32_t)uiADCBlowerCurrentLocal-(int32_t)uiADCOffsetBlowerCurrent;
ahaas92 3:b029a3f73a9e 590 lTempValue*=1000;
ahaas92 3:b029a3f73a9e 591 lTempValue/=uiTechnicalDataSet[GAIN_BLOWER_CURRENT_TEC];
ahaas92 3:b029a3f73a9e 592 return(lTempValue);
ahaas92 3:b029a3f73a9e 593 }
ahaas92 3:b029a3f73a9e 594
ahaas92 3:b029a3f73a9e 595
ahaas92 3:b029a3f73a9e 596 #ifndef C_M3_DEVICETEST_TARGET
ahaas92 3:b029a3f73a9e 597 /*******************************************************************************
ahaas92 3:b029a3f73a9e 598 * Function Name : LaunchFlowReadingOnI2CBus
ahaas92 3:b029a3f73a9e 599 * Description : Open and Read the flow sensor(s) on the I2C bus
ahaas92 3:b029a3f73a9e 600 * Input : None
ahaas92 3:b029a3f73a9e 601 * Output : None
ahaas92 3:b029a3f73a9e 602 * Return : None
ahaas92 3:b029a3f73a9e 603 *******************************************************************************/
ahaas92 3:b029a3f73a9e 604 void LaunchFlowReadingOnI2CBus(void)
ahaas92 3:b029a3f73a9e 605 {
ahaas92 3:b029a3f73a9e 606 opstatus_t byOpStatus;
ahaas92 3:b029a3f73a9e 607 u16 uiSensorErr;
ahaas92 3:b029a3f73a9e 608
ahaas92 3:b029a3f73a9e 609 if (fOpenI2C1SDP600Sensors==FALSE || fOpenI2C2SDP600Sensors==FALSE ||
ahaas92 3:b029a3f73a9e 610 fOpenI2C1X201641Sensors==FALSE || fOpenI2C2X201641Sensors==FALSE)
ahaas92 3:b029a3f73a9e 611 {
ahaas92 3:b029a3f73a9e 612 byOpStatus=SS_Xopen(I2C_SDP600);
ahaas92 3:b029a3f73a9e 613 if (byOpStatus==OPSTATUS_FAIL)
ahaas92 3:b029a3f73a9e 614 uiFlagsAlarm[ALARM_FLAGS2]|=FLOW_SENSOR_FAILURE_ALARM_MASK;
ahaas92 3:b029a3f73a9e 615
ahaas92 3:b029a3f73a9e 616 byOpStatus=SS_Xopen(I2C_X201641);
ahaas92 3:b029a3f73a9e 617 if (byOpStatus==OPSTATUS_FAIL)
ahaas92 3:b029a3f73a9e 618 uiFlagsAlarm[ALARM_FLAGS2]|=FLOW_SENSOR_FAILURE_ALARM_MASK;
ahaas92 3:b029a3f73a9e 619
ahaas92 3:b029a3f73a9e 620 ucReadingFlowSensor=STOP_READING_FLOW_SENSORS;
ahaas92 3:b029a3f73a9e 621 }
ahaas92 3:b029a3f73a9e 622 else if (ucReadingFlowSensor==STOP_READING_FLOW_SENSORS)
ahaas92 3:b029a3f73a9e 623 {
ahaas92 3:b029a3f73a9e 624 ucReadingFlowSensor=START_READING_FLOW_SENSORS;
ahaas92 3:b029a3f73a9e 625 }
ahaas92 3:b029a3f73a9e 626 else if (ucReadingFlowSensor==READING_FLOW_SENSORS)
ahaas92 3:b029a3f73a9e 627 {
ahaas92 3:b029a3f73a9e 628 // Reading SDP600 Flow sensors
ahaas92 3:b029a3f73a9e 629 if (ucStatusSDP600==FLOW_SENSOR_READING)
ahaas92 3:b029a3f73a9e 630 {
ahaas92 3:b029a3f73a9e 631 byOpStatus=SS_Xgetw(I2C_SDP600, &uiSensorErr);
ahaas92 3:b029a3f73a9e 632 if (byOpStatus==OPSTATUS_OK)
ahaas92 3:b029a3f73a9e 633 ucStatusSDP600=FLOW_SENSOR_OK;
ahaas92 3:b029a3f73a9e 634 else if (byOpStatus==OPSTATUS_FAIL)
ahaas92 3:b029a3f73a9e 635 ucStatusSDP600=FLOW_SENSOR_FAIL;
ahaas92 3:b029a3f73a9e 636 }
ahaas92 3:b029a3f73a9e 637
ahaas92 3:b029a3f73a9e 638 // Reading X201641 Flow sensors
ahaas92 3:b029a3f73a9e 639 if (ucStatusX201641==FLOW_SENSOR_READING)
ahaas92 3:b029a3f73a9e 640 {
ahaas92 3:b029a3f73a9e 641 byOpStatus=SS_Xgetw(I2C_X201641, &uiSensorErr);
ahaas92 3:b029a3f73a9e 642 if (byOpStatus==OPSTATUS_OK)
ahaas92 3:b029a3f73a9e 643 ucStatusX201641=FLOW_SENSOR_OK;
ahaas92 3:b029a3f73a9e 644 else if (byOpStatus==OPSTATUS_FAIL)
ahaas92 3:b029a3f73a9e 645 ucStatusX201641=FLOW_SENSOR_FAIL;
ahaas92 3:b029a3f73a9e 646 }
ahaas92 3:b029a3f73a9e 647
ahaas92 3:b029a3f73a9e 648 // End of flow measurement?
ahaas92 3:b029a3f73a9e 649 if (ucStatusSDP600!=FLOW_SENSOR_READING && ucStatusX201641!=FLOW_SENSOR_READING)
ahaas92 3:b029a3f73a9e 650 {
ahaas92 3:b029a3f73a9e 651 if (ucStatusSDP600==FLOW_SENSOR_OK && ucStatusX201641==FLOW_SENSOR_OK)
ahaas92 3:b029a3f73a9e 652 {
ahaas92 3:b029a3f73a9e 653 ucCounterFlowErrorMeasurement=0;
ahaas92 3:b029a3f73a9e 654 #ifdef TIME_MEASUREMENT
ahaas92 3:b029a3f73a9e 655 GPIOB->BRR = GPIO_Pin_5;
ahaas92 3:b029a3f73a9e 656 #endif
ahaas92 3:b029a3f73a9e 657 }
ahaas92 3:b029a3f73a9e 658 else
ahaas92 3:b029a3f73a9e 659 {
ahaas92 3:b029a3f73a9e 660 // Error counters
ahaas92 3:b029a3f73a9e 661 uiTotalCounterFlowErrorMeasurement++;
ahaas92 3:b029a3f73a9e 662 ucCounterFlowErrorMeasurement++;
ahaas92 3:b029a3f73a9e 663 if (ucCounterFlowErrorMeasurement>=NUMBER_I2C_REBOOT)
ahaas92 3:b029a3f73a9e 664 {
ahaas92 3:b029a3f73a9e 665 //ulErrorCounter|=uiSensorErr;
ahaas92 3:b029a3f73a9e 666 uiFlagsAlarm[ALARM_FLAGS2]|=FLOW_SENSOR_FAILURE_ALARM_MASK;
ahaas92 3:b029a3f73a9e 667 }
ahaas92 3:b029a3f73a9e 668 }
ahaas92 3:b029a3f73a9e 669
ahaas92 3:b029a3f73a9e 670 // Next Sensors to measure
ahaas92 3:b029a3f73a9e 671 ucReadingFlowSensor=READING_NO_SENSOR;
ahaas92 3:b029a3f73a9e 672 ucStatusSDP600=FLOW_SENSOR_READING;
ahaas92 3:b029a3f73a9e 673 ucStatusX201641=FLOW_SENSOR_READING;
ahaas92 3:b029a3f73a9e 674 }
ahaas92 3:b029a3f73a9e 675 }
ahaas92 3:b029a3f73a9e 676 }
ahaas92 3:b029a3f73a9e 677 #endif // #ifndef C_M3_DEVICETEST_TARGET
ahaas92 3:b029a3f73a9e 678
ahaas92 3:b029a3f73a9e 679
ahaas92 3:b029a3f73a9e 680
ahaas92 3:b029a3f73a9e 681 #ifndef C_M3_DEVICETEST_TARGET
ahaas92 3:b029a3f73a9e 682 /*******************************************************************************
ahaas92 3:b029a3f73a9e 683 * Function Name : ComputeFlowMeasurement
ahaas92 3:b029a3f73a9e 684 * Description : Conpute inspiratory and erxpiratory flow measurements
ahaas92 3:b029a3f73a9e 685 * Input : None
ahaas92 3:b029a3f73a9e 686 * Output : None
ahaas92 3:b029a3f73a9e 687 * Return : None
ahaas92 3:b029a3f73a9e 688 *******************************************************************************/
ahaas92 3:b029a3f73a9e 689 void ComputeFlowMeasurement(void)
ahaas92 3:b029a3f73a9e 690 {
ahaas92 3:b029a3f73a9e 691 #if defined(SDP600_USED_I2C1_BUS) || defined(X201641_USED_I2C1_BUS)
ahaas92 3:b029a3f73a9e 692 int32_t lValue;
ahaas92 3:b029a3f73a9e 693 u16 uiValue;
ahaas92 3:b029a3f73a9e 694 #ifdef DISPLAY_AVERAGE_BLOWER_RAW_FLOW
ahaas92 3:b029a3f73a9e 695 u32 ulValue;
ahaas92 3:b029a3f73a9e 696 #endif
ahaas92 3:b029a3f73a9e 697 #endif
ahaas92 3:b029a3f73a9e 698
ahaas92 3:b029a3f73a9e 699 if (ucReadingFlowSensor==START_READING_FLOW_SENSORS)
ahaas92 3:b029a3f73a9e 700 {
ahaas92 3:b029a3f73a9e 701 ucReadingFlowSensor=READING_FLOW_SENSORS;
ahaas92 3:b029a3f73a9e 702 }
ahaas92 3:b029a3f73a9e 703 else if (ucReadingFlowSensor==READING_NO_SENSOR)
ahaas92 3:b029a3f73a9e 704 {
ahaas92 3:b029a3f73a9e 705 ucReadingFlowSensor=READING_FLOW_SENSORS;
ahaas92 3:b029a3f73a9e 706
ahaas92 3:b029a3f73a9e 707 // **** Reading of the Inspiratory RAW Flow
ahaas92 3:b029a3f73a9e 708 #if defined(SDP600_USED_I2C1_BUS) || defined(X201641_USED_I2C1_BUS)
ahaas92 3:b029a3f73a9e 709 #ifdef SDP600_USED_I2C1_BUS
ahaas92 3:b029a3f73a9e 710 SDP600_ReadADCFlowValue(I2C1, SDP600_BLOWER_FLOW_SENSOR, &uiValue);
ahaas92 3:b029a3f73a9e 711 #endif
ahaas92 3:b029a3f73a9e 712 #ifdef X201641_USED_I2C1_BUS
ahaas92 3:b029a3f73a9e 713 X201641_ReadADCFlowValue(I2C1, X201641_BLOWER_FLOW_SENSOR, &uiValue);
ahaas92 3:b029a3f73a9e 714 #endif
ahaas92 3:b029a3f73a9e 715 if (uiValue==uiTechnicalDataSet[FLOWI_OFFSET_TEC])
ahaas92 3:b029a3f73a9e 716 {
ahaas92 3:b029a3f73a9e 717 uiBlowerFlowRAWMes=0;
ahaas92 3:b029a3f73a9e 718 iBlowerFlowMes=0;
ahaas92 3:b029a3f73a9e 719 }
ahaas92 3:b029a3f73a9e 720 else if (uiValue>uiTechnicalDataSet[FLOWI_OFFSET_TEC])
ahaas92 3:b029a3f73a9e 721 {
ahaas92 3:b029a3f73a9e 722 uiBlowerFlowRAWMes=uiValue-uiTechnicalDataSet[FLOWI_OFFSET_TEC];
ahaas92 3:b029a3f73a9e 723 iBlowerFlowMes=ComputeFlowInLitersPerMin(uiBlowerFlowRAWMes, FALSE);
ahaas92 3:b029a3f73a9e 724 }
ahaas92 3:b029a3f73a9e 725 else
ahaas92 3:b029a3f73a9e 726 {
ahaas92 3:b029a3f73a9e 727 uiBlowerFlowRAWMes=uiTechnicalDataSet[FLOWI_OFFSET_TEC]-uiValue;
ahaas92 3:b029a3f73a9e 728 iBlowerFlowMes=ComputeFlowInLitersPerMin(uiBlowerFlowRAWMes, TRUE);
ahaas92 3:b029a3f73a9e 729 }
ahaas92 3:b029a3f73a9e 730
ahaas92 3:b029a3f73a9e 731 // Smoothing RWA data signals
ahaas92 3:b029a3f73a9e 732 #ifdef DISPLAY_AVERAGE_BLOWER_RAW_FLOW
ahaas92 3:b029a3f73a9e 733 uiBlowerRAWFlowTemp[ucIndexBlowerRAWFlowSmooth]=uiBlowerFlowRAWMes;
ahaas92 3:b029a3f73a9e 734 ulValue=0;
ahaas92 3:b029a3f73a9e 735 for (uiValue=0; uiValue<SMOOTH_BLOWER_RAW_FLOW_COUNTER; uiValue++)
ahaas92 3:b029a3f73a9e 736 ulValue+=uiBlowerRAWFlowTemp[uiValue];
ahaas92 3:b029a3f73a9e 737 uiBlowerFlowRAWSmoothingMes=ulValue/SMOOTH_BLOWER_RAW_FLOW_COUNTER;
ahaas92 3:b029a3f73a9e 738 ucIndexBlowerRAWFlowSmooth++;
ahaas92 3:b029a3f73a9e 739 if (ucIndexBlowerRAWFlowSmooth>=SMOOTH_BLOWER_RAW_FLOW_COUNTER)
ahaas92 3:b029a3f73a9e 740 ucIndexBlowerRAWFlowSmooth=0;
ahaas92 3:b029a3f73a9e 741
ahaas92 3:b029a3f73a9e 742 // Average of the RAW data signal
ahaas92 3:b029a3f73a9e 743 ulSumBlowerFlowRAWMes+=uiBlowerFlowRAWSmoothingMes;
ahaas92 3:b029a3f73a9e 744 uiBlowerRAWFlowSamplesCounter--;
ahaas92 3:b029a3f73a9e 745 if (uiBlowerRAWFlowSamplesCounter==0)
ahaas92 3:b029a3f73a9e 746 {
ahaas92 3:b029a3f73a9e 747 uiAverageBlowerFlowRAWMes=ulSumBlowerFlowRAWMes/BLOWER_RAW_FLOW_SAMPLES_NUMBER;
ahaas92 3:b029a3f73a9e 748 ulSumBlowerFlowRAWMes=0;
ahaas92 3:b029a3f73a9e 749 uiBlowerRAWFlowSamplesCounter=BLOWER_RAW_FLOW_SAMPLES_NUMBER;
ahaas92 3:b029a3f73a9e 750 }
ahaas92 3:b029a3f73a9e 751 #endif // DISPLAY_AVERAGE_BLOWER_RAW_FLOW
ahaas92 3:b029a3f73a9e 752
ahaas92 3:b029a3f73a9e 753
ahaas92 3:b029a3f73a9e 754 // **** Reading of the Inspiratory Flow in l/min
ahaas92 3:b029a3f73a9e 755 /*#ifdef SDP600_USED_I2C1_BUS
ahaas92 3:b029a3f73a9e 756 SDP600_CalculFlowValue(I2C1, SDP600_BLOWER_FLOW_SENSOR, &iBlowerFlowMes);
ahaas92 3:b029a3f73a9e 757 #endif
ahaas92 3:b029a3f73a9e 758 #ifdef X201641_USED_I2C1_BUS
ahaas92 3:b029a3f73a9e 759 X201641_CalculFlowValue(I2C1, X201641_BLOWER_FLOW_SENSOR, &iBlowerFlowMes);
ahaas92 3:b029a3f73a9e 760 #endif*/
ahaas92 3:b029a3f73a9e 761 iTempBlowerFlowForSmallSmooth[ucIndexSmallBlowerFlowSmooth]=iBlowerFlowMes;
ahaas92 3:b029a3f73a9e 762 iTempBlowerFlowForLargeSmooth[ucIndexLargeBlowerFlowSmooth]=iBlowerFlowMes;
ahaas92 3:b029a3f73a9e 763
ahaas92 3:b029a3f73a9e 764 // Small Smoothing of the inspiratory flow signal
ahaas92 3:b029a3f73a9e 765 lValue=0;
ahaas92 3:b029a3f73a9e 766 for (uiValue=0; uiValue<SMOOTH_BLOWER_FLOW_SMALL_COUNTER; uiValue++)
ahaas92 3:b029a3f73a9e 767 lValue+=iTempBlowerFlowForSmallSmooth[uiValue];
ahaas92 3:b029a3f73a9e 768 iBlowerFlowSmoothingMes=lValue/(int16_t)SMOOTH_BLOWER_FLOW_SMALL_COUNTER;
ahaas92 3:b029a3f73a9e 769 ucIndexSmallBlowerFlowSmooth++;
ahaas92 3:b029a3f73a9e 770 if (ucIndexSmallBlowerFlowSmooth>=SMOOTH_BLOWER_FLOW_SMALL_COUNTER)
ahaas92 3:b029a3f73a9e 771 ucIndexSmallBlowerFlowSmooth=0;
ahaas92 3:b029a3f73a9e 772
ahaas92 3:b029a3f73a9e 773 // Large Smoothing of the inspiratory flow signal
ahaas92 3:b029a3f73a9e 774 lValue=0;
ahaas92 3:b029a3f73a9e 775 for (uiValue=0; uiValue<SMOOTH_BLOWER_FLOW_LARGE_COUNTER; uiValue++)
ahaas92 3:b029a3f73a9e 776 lValue+=iTempBlowerFlowForLargeSmooth[uiValue];
ahaas92 3:b029a3f73a9e 777 iBlowerFlowSmoothingMesForTrigger=lValue/(int16_t)SMOOTH_BLOWER_FLOW_LARGE_COUNTER;
ahaas92 3:b029a3f73a9e 778 ucIndexLargeBlowerFlowSmooth++;
ahaas92 3:b029a3f73a9e 779 if (ucIndexLargeBlowerFlowSmooth>=SMOOTH_BLOWER_FLOW_LARGE_COUNTER)
ahaas92 3:b029a3f73a9e 780 ucIndexLargeBlowerFlowSmooth=0;
ahaas92 3:b029a3f73a9e 781
ahaas92 3:b029a3f73a9e 782 // Flow for Optima Comm
ahaas92 3:b029a3f73a9e 783 uiBlowerFlow=iBlowerFlowMes;
ahaas92 3:b029a3f73a9e 784 uiBlowerFlowSmoothingMes=iBlowerFlowSmoothingMes;
ahaas92 3:b029a3f73a9e 785 uiBlowerFlowTriggerMes=iBlowerFlowSmoothingMesForTrigger;
ahaas92 3:b029a3f73a9e 786 #endif // (SDP600_USED_I2C1_BUS) || (X201641_USED_I2C1_BUS)
ahaas92 3:b029a3f73a9e 787 }
ahaas92 3:b029a3f73a9e 788
ahaas92 3:b029a3f73a9e 789 }
ahaas92 3:b029a3f73a9e 790 #endif // #ifndef C_M3_DEVICETEST_TARGET
ahaas92 3:b029a3f73a9e 791
ahaas92 3:b029a3f73a9e 792
ahaas92 3:b029a3f73a9e 793
ahaas92 3:b029a3f73a9e 794 #ifndef C_M3_DEVICETEST_TARGET
ahaas92 3:b029a3f73a9e 795 double powApprox(double a, double x)
ahaas92 3:b029a3f73a9e 796 {
ahaas92 3:b029a3f73a9e 797 union
ahaas92 3:b029a3f73a9e 798 {
ahaas92 3:b029a3f73a9e 799 double d;
ahaas92 3:b029a3f73a9e 800 int A[2];
ahaas92 3:b029a3f73a9e 801 } Z = { a };
ahaas92 3:b029a3f73a9e 802 Z.A[1] = (int)(x * (Z.A[1] - 1072632447) + 1072632447);
ahaas92 3:b029a3f73a9e 803 Z.A[0] = 0;
ahaas92 3:b029a3f73a9e 804 return Z.d;
ahaas92 3:b029a3f73a9e 805 }
ahaas92 3:b029a3f73a9e 806 /*******************************************************************************
ahaas92 3:b029a3f73a9e 807 * Function Name : ComputeConductance
ahaas92 3:b029a3f73a9e 808 * Description : Compute Conductance
ahaas92 3:b029a3f73a9e 809 * Input : Pressure, Flow
ahaas92 3:b029a3f73a9e 810 * Output : Conductance
ahaas92 3:b029a3f73a9e 811 * Return : None
ahaas92 3:b029a3f73a9e 812 *******************************************************************************/
ahaas92 3:b029a3f73a9e 813 float prevConductance = 0.0f;
ahaas92 3:b029a3f73a9e 814 u8 bufferIndex = 0;
ahaas92 3:b029a3f73a9e 815 bool filled = FALSE;
ahaas92 3:b029a3f73a9e 816 int16_t littleSum = 0;
ahaas92 3:b029a3f73a9e 817
ahaas92 3:b029a3f73a9e 818 void ComputeConductance(void)
ahaas92 3:b029a3f73a9e 819 {
ahaas92 3:b029a3f73a9e 820 float pressure = iProximalPressureMes/10.0f;
ahaas92 3:b029a3f73a9e 821 float flow = iBlowerFlowSmoothingMes/100.0f/60.0f;
ahaas92 3:b029a3f73a9e 822 float density = 1.225f;
ahaas92 3:b029a3f73a9e 823 float viscosity = 0.00018f;
ahaas92 3:b029a3f73a9e 824 float calcConductance = 0.0f;
ahaas92 3:b029a3f73a9e 825
ahaas92 3:b029a3f73a9e 826 if(pressure != 0)
ahaas92 3:b029a3f73a9e 827 {
ahaas92 3:b029a3f73a9e 828 calcConductance = (100000)*((powApprox((flow*0.001f),1.75)*powApprox(density,0.75)*powApprox(viscosity,0.25)/(pressure / 10.0f)* 98.0638f));
ahaas92 3:b029a3f73a9e 829 calcConductance = calcConductance * 1000.0f;
ahaas92 3:b029a3f73a9e 830 if(calcConductance < 60000 && calcConductance > -60000)
ahaas92 3:b029a3f73a9e 831 {
ahaas92 3:b029a3f73a9e 832 uiConductanceCalc = (int16_t)calcConductance;
ahaas92 3:b029a3f73a9e 833 }
ahaas92 3:b029a3f73a9e 834 }
ahaas92 3:b029a3f73a9e 835 // int16_t tempValue = idConductancedtSmooth[bufferIndex];
ahaas92 3:b029a3f73a9e 836 // idConductancedtSmooth[bufferIndex]= (int16_t)(calcConductance - prevConductance);//1000;
ahaas92 3:b029a3f73a9e 837 // littleSum += idConductancedtSmooth[bufferIndex];
ahaas92 3:b029a3f73a9e 838 // bufferIndex++;
ahaas92 3:b029a3f73a9e 839 // if(bufferIndex > SMOOTH_BLOWER_FLOW_LARGE_COUNTER)
ahaas92 3:b029a3f73a9e 840 // {
ahaas92 3:b029a3f73a9e 841 // bufferIndex = 0;
ahaas92 3:b029a3f73a9e 842 // if(!filled)
ahaas92 3:b029a3f73a9e 843 // {
ahaas92 3:b029a3f73a9e 844 // filled = TRUE;
ahaas92 3:b029a3f73a9e 845 // }
ahaas92 3:b029a3f73a9e 846 // }
ahaas92 3:b029a3f73a9e 847 //
ahaas92 3:b029a3f73a9e 848 // if(filled)
ahaas92 3:b029a3f73a9e 849 // {
ahaas92 3:b029a3f73a9e 850 // littleSum -= tempValue;
ahaas92 3:b029a3f73a9e 851 // uidConductanceCalcdt = littleSum/SMOOTH_BLOWER_FLOW_LARGE_COUNTER;
ahaas92 3:b029a3f73a9e 852 // }
ahaas92 3:b029a3f73a9e 853 uidConductanceCalcdt = (int16_t)(calcConductance - prevConductance);
ahaas92 3:b029a3f73a9e 854 prevConductance = calcConductance;
ahaas92 3:b029a3f73a9e 855 }
ahaas92 3:b029a3f73a9e 856 /*******************************************************************************
ahaas92 3:b029a3f73a9e 857 * Function Name : ComputeProximalPressureMeasurements
ahaas92 3:b029a3f73a9e 858 * Description : Compute Proximal pressure measurements
ahaas92 3:b029a3f73a9e 859 * Input : None
ahaas92 3:b029a3f73a9e 860 * Output : None
ahaas92 3:b029a3f73a9e 861 * Return : None
ahaas92 3:b029a3f73a9e 862 *******************************************************************************/
ahaas92 3:b029a3f73a9e 863 void ComputeProximalPressureMeasurements(void)
ahaas92 3:b029a3f73a9e 864 {
ahaas92 3:b029a3f73a9e 865 u32 ulValue;
ahaas92 3:b029a3f73a9e 866 u16 uiValue;
ahaas92 3:b029a3f73a9e 867
ahaas92 3:b029a3f73a9e 868 iProximalPressureMes=((100L*((int16_t)uiProximalPressureADCMes-(int16_t)uiTechnicalDataSet[PPROX_OFFSET_TEC]))/(int16_t)uiTechnicalDataSet[PPROX_GAIN_TEC]);
ahaas92 3:b029a3f73a9e 869 if (iProximalPressureMes>0)
ahaas92 3:b029a3f73a9e 870 uiProximalPressureMes=(u16)iProximalPressureMes;
ahaas92 3:b029a3f73a9e 871 else
ahaas92 3:b029a3f73a9e 872 uiProximalPressureMes=0;
ahaas92 3:b029a3f73a9e 873 uiNegativeProximalPressureMes=iProximalPressureMes;
ahaas92 3:b029a3f73a9e 874
ahaas92 3:b029a3f73a9e 875 // Smoothing proximal pressure
ahaas92 3:b029a3f73a9e 876 uiProximalPressureTemp[ucIndexPproxPressureSmooth]=uiProximalPressureMes;
ahaas92 3:b029a3f73a9e 877 ulValue=0;
ahaas92 3:b029a3f73a9e 878 for (uiValue=0; uiValue<SMOOTH_PPROX_PRESSURE_COUNTER; uiValue++)
ahaas92 3:b029a3f73a9e 879 ulValue+=uiProximalPressureTemp[uiValue];
ahaas92 3:b029a3f73a9e 880 uiProximalPressureSmoothingMes=ulValue/SMOOTH_PPROX_PRESSURE_COUNTER;
ahaas92 3:b029a3f73a9e 881
ahaas92 3:b029a3f73a9e 882 ucIndexPproxPressureSmooth++;
ahaas92 3:b029a3f73a9e 883 if (ucIndexPproxPressureSmooth>=SMOOTH_PPROX_PRESSURE_COUNTER)
ahaas92 3:b029a3f73a9e 884 ucIndexPproxPressureSmooth=0;
ahaas92 3:b029a3f73a9e 885 }
ahaas92 3:b029a3f73a9e 886 #endif // #ifndef C_M3_DEVICETEST_TARGET
ahaas92 3:b029a3f73a9e 887
ahaas92 3:b029a3f73a9e 888
ahaas92 3:b029a3f73a9e 889 #ifndef C_M3_DEVICETEST_TARGET
ahaas92 3:b029a3f73a9e 890 /*******************************************************************************
ahaas92 3:b029a3f73a9e 891 * Function Name : ComputeOffsetProximalPressureSensor
ahaas92 3:b029a3f73a9e 892 * Description : Compute offset of the proximal pressure sensor
ahaas92 3:b029a3f73a9e 893 * Input : None
ahaas92 3:b029a3f73a9e 894 * Output : None
ahaas92 3:b029a3f73a9e 895 * Return : None
ahaas92 3:b029a3f73a9e 896 *******************************************************************************/
ahaas92 3:b029a3f73a9e 897 void ComputeOffsetProximalPressureSensor(void)
ahaas92 3:b029a3f73a9e 898 {
ahaas92 3:b029a3f73a9e 899 u32 ulOffsetSum=0;
ahaas92 3:b029a3f73a9e 900 u16 i;
ahaas92 3:b029a3f73a9e 901
ahaas92 3:b029a3f73a9e 902 for (i=0; i<64; i++)
ahaas92 3:b029a3f73a9e 903 {
ahaas92 3:b029a3f73a9e 904 ulOffsetSum+=uiADC_Value[ADC_PPROX_MES];
ahaas92 3:b029a3f73a9e 905 uiTempoSysTick=5;
ahaas92 3:b029a3f73a9e 906 while (uiTempoSysTick!=0){}
ahaas92 3:b029a3f73a9e 907 }
ahaas92 3:b029a3f73a9e 908 uiTechnicalDataSet[PPROX_OFFSET_TEC]=ulOffsetSum>>6;
ahaas92 3:b029a3f73a9e 909 }
ahaas92 3:b029a3f73a9e 910 #endif // #ifndef C_M3_DEVICETEST_TARGET
ahaas92 3:b029a3f73a9e 911
ahaas92 3:b029a3f73a9e 912
ahaas92 3:b029a3f73a9e 913
ahaas92 3:b029a3f73a9e 914 #ifndef C_M3_DEVICETEST_TARGET
ahaas92 3:b029a3f73a9e 915 /*******************************************************************************
ahaas92 3:b029a3f73a9e 916 * Function Name : VentilationMonitoringAndAlarms
ahaas92 3:b029a3f73a9e 917 * Description : Compute measurements and alarms during ventilation
ahaas92 3:b029a3f73a9e 918 * Input : None
ahaas92 3:b029a3f73a9e 919 * Output : None
ahaas92 3:b029a3f73a9e 920 * Return : None
ahaas92 3:b029a3f73a9e 921 *******************************************************************************/
ahaas92 3:b029a3f73a9e 922 void VentilationMonitoringAndAlarms(void)
ahaas92 3:b029a3f73a9e 923 {
ahaas92 3:b029a3f73a9e 924 u16 uiTotalTimeMes;
ahaas92 3:b029a3f73a9e 925
ahaas92 3:b029a3f73a9e 926 if (bMemoStartVentilation==TRUE && uiTechnicalDataSet[DEVICE_MODE_TEC]==VENTILATION_MODE)
ahaas92 3:b029a3f73a9e 927 {
ahaas92 3:b029a3f73a9e 928 if (ucVentilationCycle==INSPIRATION_CYCLE)
ahaas92 3:b029a3f73a9e 929 {
ahaas92 3:b029a3f73a9e 930 // ***************** INSPIRATION ******************
ahaas92 3:b029a3f73a9e 931 if (ucVentilationCycleCopy==EXPIRATION_CYCLE)
ahaas92 3:b029a3f73a9e 932 {
ahaas92 3:b029a3f73a9e 933 // --- Beginning of inspiration
ahaas92 3:b029a3f73a9e 934 ucVentilationCycleCopy=INSPIRATION_CYCLE;
ahaas92 3:b029a3f73a9e 935 SS_Xputdw(act, EV_CTL|FLAG_ACTIONER_ON);
ahaas92 3:b029a3f73a9e 936
ahaas92 3:b029a3f73a9e 937 // Update Vte measurement
ahaas92 3:b029a3f73a9e 938 uiVentilationMeasures[VTE_MES]=uiVteTemp;
ahaas92 3:b029a3f73a9e 939
ahaas92 3:b029a3f73a9e 940 // Update Te measurement
ahaas92 3:b029a3f73a9e 941 uiVentilationMeasures[TE_MES]=uiTeMesTemp;
ahaas92 3:b029a3f73a9e 942
ahaas92 3:b029a3f73a9e 943 // Update Average ADC Motor Voltage
ahaas92 3:b029a3f73a9e 944 if (ulCounterADC_MotorVoltage!=0)
ahaas92 3:b029a3f73a9e 945 uiAverageADC_MotorVoltage=ulSumADC_MotorVoltage/ulCounterADC_MotorVoltage;
ahaas92 3:b029a3f73a9e 946
ahaas92 3:b029a3f73a9e 947 // Update Current measurement
ahaas92 3:b029a3f73a9e 948 if (ulCounterADC_FilteredBlowerCurrentMes!=0)
ahaas92 3:b029a3f73a9e 949 uiBreathBlowerCurrentMes=ComputeBlowerCurrentInAmper(ulSumCurrentADCMesFiltered/ulCounterADC_FilteredBlowerCurrentMes);
ahaas92 3:b029a3f73a9e 950 ulSumCurrentADCMesFiltered=0; ulCounterADC_FilteredBlowerCurrentMes=0;
ahaas92 3:b029a3f73a9e 951
ahaas92 3:b029a3f73a9e 952 // Update average blower speed
ahaas92 3:b029a3f73a9e 953 if (ulCounterAverageMotorSpeed!=0)
ahaas92 3:b029a3f73a9e 954 uiAverageBlowerSpeedMes=SpeedMeasurement(ulSumTachoTicks/ulCounterAverageMotorSpeed);
ahaas92 3:b029a3f73a9e 955 ulSumTachoTicks=0;
ahaas92 3:b029a3f73a9e 956 ulCounterAverageMotorSpeed=0;
ahaas92 3:b029a3f73a9e 957
ahaas92 3:b029a3f73a9e 958 // Update average motor temperature during inspiration
ahaas92 3:b029a3f73a9e 959 if (uiTemperatureSamplesCounter!=0)
ahaas92 3:b029a3f73a9e 960 {
ahaas92 3:b029a3f73a9e 961 uiTechnicalDataMes[MOTOR_TEMPERATURE_TEC_MES]=ComputeMotorTemperature(ulADCSumBlowerTemperature/uiTemperatureSamplesCounter);
ahaas92 3:b029a3f73a9e 962 if (uiTechnicalDataMes[MOTOR_TEMPERATURE_TEC_MES]>890)
ahaas92 3:b029a3f73a9e 963 uiFlagsAlarm[ALARM_FLAGS2]|=MOTOR_TEMPERATURE_ALARM_MASK;
ahaas92 3:b029a3f73a9e 964 else if (uiTechnicalDataMes[MOTOR_TEMPERATURE_TEC_MES]<810)
ahaas92 3:b029a3f73a9e 965 uiFlagsAlarm[ALARM_FLAGS2]&=(~MOTOR_TEMPERATURE_ALARM_MASK);
ahaas92 3:b029a3f73a9e 966 }
ahaas92 3:b029a3f73a9e 967 ulADCSumBlowerTemperature=0; uiTemperatureSamplesCounter=0;
ahaas92 3:b029a3f73a9e 968
ahaas92 3:b029a3f73a9e 969 // --- Pmax=0
ahaas92 3:b029a3f73a9e 970 uiPproxMax=0;
ahaas92 3:b029a3f73a9e 971
ahaas92 3:b029a3f73a9e 972 // --- Vti=0
ahaas92 3:b029a3f73a9e 973 lSumVti=0;
ahaas92 3:b029a3f73a9e 974 uiRecordVtiMes=uiVentilationMeasures[VTI_MES];
ahaas92 3:b029a3f73a9e 975
ahaas92 3:b029a3f73a9e 976 // --- Dislay Breath rate
ahaas92 3:b029a3f73a9e 977 uiTotalTimeMes=uiVentilationMeasures[TI_MES]+uiVentilationMeasures[TE_MES];
ahaas92 3:b029a3f73a9e 978 if (uiTotalTimeMes>0)
ahaas92 3:b029a3f73a9e 979 uiVentilationMeasures[BREATH_RATE_MES]=600000/uiTotalTimeMes;
ahaas92 3:b029a3f73a9e 980
ahaas92 3:b029a3f73a9e 981 // --- Ti=0
ahaas92 3:b029a3f73a9e 982 uiTiMesTemp=0;
ahaas92 3:b029a3f73a9e 983
ahaas92 3:b029a3f73a9e 984 // --- Max flow
ahaas92 3:b029a3f73a9e 985 iBlowerFlowSmoothingMaxMes=0;
ahaas92 3:b029a3f73a9e 986
ahaas92 3:b029a3f73a9e 987 // --- Alarm Vte Min
ahaas92 3:b029a3f73a9e 988 if (uiVentilationMeasures[VTE_MES]<uiVentilationSet[VTE_MIN_ALARM_SET] && enVentilationMode!=CPAP_MODE)
ahaas92 3:b029a3f73a9e 989 {
ahaas92 3:b029a3f73a9e 990 ucCounterAlarmVteMin++;
ahaas92 3:b029a3f73a9e 991 if (ucCounterAlarmVteMin>=5)
ahaas92 3:b029a3f73a9e 992 {
ahaas92 3:b029a3f73a9e 993 ucCounterAlarmVteMin=5;
ahaas92 3:b029a3f73a9e 994 uiFlagsAlarm[ALARM_FLAGS1]|=LOW_VTE_ALARM_MASK;
ahaas92 3:b029a3f73a9e 995 }
ahaas92 3:b029a3f73a9e 996 }
ahaas92 3:b029a3f73a9e 997 else
ahaas92 3:b029a3f73a9e 998 {
ahaas92 3:b029a3f73a9e 999 ucCounterAlarmVteMin=0;
ahaas92 3:b029a3f73a9e 1000 uiFlagsAlarm[ALARM_FLAGS1]&=(~LOW_VTE_ALARM_MASK);
ahaas92 3:b029a3f73a9e 1001 }
ahaas92 3:b029a3f73a9e 1002 }
ahaas92 3:b029a3f73a9e 1003 else //if (ucVentilationCycle==EXPIRATION_CYCLE)
ahaas92 3:b029a3f73a9e 1004 {
ahaas92 3:b029a3f73a9e 1005 // --- During inspiration
ahaas92 3:b029a3f73a9e 1006
ahaas92 3:b029a3f73a9e 1007 // --- Motor Speed
ahaas92 3:b029a3f73a9e 1008 ulSumTachoTicks+=uiTachoTimeTicks;
ahaas92 3:b029a3f73a9e 1009 ulCounterAverageMotorSpeed++;
ahaas92 3:b029a3f73a9e 1010
ahaas92 3:b029a3f73a9e 1011 // --- Blower Current
ahaas92 3:b029a3f73a9e 1012 ulSumCurrentADCMesFiltered+=uiADCBlowerCurrent;
ahaas92 3:b029a3f73a9e 1013 ulCounterADC_FilteredBlowerCurrentMes++;
ahaas92 3:b029a3f73a9e 1014
ahaas92 3:b029a3f73a9e 1015 // --- Inc Pmax
ahaas92 3:b029a3f73a9e 1016 if (uiProximalPressureMes>uiPproxMax)
ahaas92 3:b029a3f73a9e 1017 uiPproxMax=uiProximalPressureMes;
ahaas92 3:b029a3f73a9e 1018
ahaas92 3:b029a3f73a9e 1019 // --- Inc max flow
ahaas92 3:b029a3f73a9e 1020 if (iBlowerFlowSmoothingMes>iBlowerFlowSmoothingMaxMes)
ahaas92 3:b029a3f73a9e 1021 iBlowerFlowSmoothingMaxMes=iBlowerFlowSmoothingMes;
ahaas92 3:b029a3f73a9e 1022
ahaas92 3:b029a3f73a9e 1023 // --- Inc Vti
ahaas92 3:b029a3f73a9e 1024 if (iBlowerFlowMes>30)
ahaas92 3:b029a3f73a9e 1025 lSumVti+=iBlowerFlowMes;
ahaas92 3:b029a3f73a9e 1026 uiVtiTemp=(u32)lSumVti/6000;
ahaas92 3:b029a3f73a9e 1027
ahaas92 3:b029a3f73a9e 1028 // --- Inc Ti
ahaas92 3:b029a3f73a9e 1029 uiTiMesTemp++;
ahaas92 3:b029a3f73a9e 1030
ahaas92 3:b029a3f73a9e 1031 // --- Motor temperature
ahaas92 3:b029a3f73a9e 1032 ulADCSumBlowerTemperature+=uiADCBlowerTemperatureMeas;
ahaas92 3:b029a3f73a9e 1033 uiTemperatureSamplesCounter++;
ahaas92 3:b029a3f73a9e 1034
ahaas92 3:b029a3f73a9e 1035 // --- Alarm Pmax
ahaas92 3:b029a3f73a9e 1036 if (uiProximalPressureMes>uiVentilationSet[HIGH_PRESSURE_ALARM_SET] && enVentilationMode!=CPAP_MODE)
ahaas92 3:b029a3f73a9e 1037 {
ahaas92 3:b029a3f73a9e 1038 uiFlagsAlarm[ALARM_FLAGS1]|=HIGH_PRESSURE_ALARM_MASK;
ahaas92 3:b029a3f73a9e 1039 fAlarmPmax=TRUE;
ahaas92 3:b029a3f73a9e 1040 }
ahaas92 3:b029a3f73a9e 1041
ahaas92 3:b029a3f73a9e 1042 // --- Alarm Vti Max
ahaas92 3:b029a3f73a9e 1043 if ((uiVtiTemp>uiVentilationSet[VTI_MAX_ALARM_SET] && enVentilationMode==PS_MODE) ||
ahaas92 3:b029a3f73a9e 1044 (uiVtiTemp>uiVentilationSet[VTI_MAX_ALARM_SET] && enVentilationMode==APCV_MODE))
ahaas92 3:b029a3f73a9e 1045 {
ahaas92 3:b029a3f73a9e 1046 uiFlagsAlarm[ALARM_FLAGS1]|=HIGH_VTI_ALARM_MASK;
ahaas92 3:b029a3f73a9e 1047 fAlarmVtiMax=TRUE;
ahaas92 3:b029a3f73a9e 1048 }
ahaas92 3:b029a3f73a9e 1049 }
ahaas92 3:b029a3f73a9e 1050 }
ahaas92 3:b029a3f73a9e 1051 else
ahaas92 3:b029a3f73a9e 1052 {
ahaas92 3:b029a3f73a9e 1053 // ***************** EXPIRATION ******************
ahaas92 3:b029a3f73a9e 1054 if (ucVentilationCycleCopy==INSPIRATION_CYCLE)
ahaas92 3:b029a3f73a9e 1055 {
ahaas92 3:b029a3f73a9e 1056 // --- Beginning of Expiration
ahaas92 3:b029a3f73a9e 1057 ucVentilationCycleCopy=EXPIRATION_CYCLE;
ahaas92 3:b029a3f73a9e 1058 SS_Xputdw(act, EV_CTL|FLAG_ACTIONER_OFF);
ahaas92 3:b029a3f73a9e 1059
ahaas92 3:b029a3f73a9e 1060 // Update Pprox max measurement
ahaas92 3:b029a3f73a9e 1061 uiVentilationMeasures[PPROX_MAX_MES]=uiPproxMax;
ahaas92 3:b029a3f73a9e 1062
ahaas92 3:b029a3f73a9e 1063 // Update Vti measurement
ahaas92 3:b029a3f73a9e 1064 uiVentilationMeasures[VTI_MES]=uiVtiTemp;
ahaas92 3:b029a3f73a9e 1065
ahaas92 3:b029a3f73a9e 1066 // Update Ti measurement
ahaas92 3:b029a3f73a9e 1067 uiVentilationMeasures[TI_MES]=uiTiMesTemp;
ahaas92 3:b029a3f73a9e 1068
ahaas92 3:b029a3f73a9e 1069 // --- Motor Speed
ahaas92 3:b029a3f73a9e 1070 ulSumTachoTicks+=uiTachoTimeTicks;
ahaas92 3:b029a3f73a9e 1071 ulCounterAverageMotorSpeed++;
ahaas92 3:b029a3f73a9e 1072
ahaas92 3:b029a3f73a9e 1073 // --- Blower Current
ahaas92 3:b029a3f73a9e 1074 ulSumCurrentADCMesFiltered+=uiADCBlowerCurrent;
ahaas92 3:b029a3f73a9e 1075 ulCounterADC_FilteredBlowerCurrentMes++;
ahaas92 3:b029a3f73a9e 1076
ahaas92 3:b029a3f73a9e 1077 // --- Vte=0
ahaas92 3:b029a3f73a9e 1078 lSumVte=0;
ahaas92 3:b029a3f73a9e 1079
ahaas92 3:b029a3f73a9e 1080 // --- Te=0
ahaas92 3:b029a3f73a9e 1081 uiTeMesTemp=0;
ahaas92 3:b029a3f73a9e 1082
ahaas92 3:b029a3f73a9e 1083 // --- Alarm Low Pressure
ahaas92 3:b029a3f73a9e 1084 if ((uiVentilationMeasures[PPROX_MAX_MES]<(uiVentilationSet[PS_SET]-5) && enVentilationMode==PS_MODE) ||
ahaas92 3:b029a3f73a9e 1085 (uiVentilationMeasures[PPROX_MAX_MES]<(uiVentilationSet[PI_SET]-5) && enVentilationMode==APCV_MODE) ||
ahaas92 3:b029a3f73a9e 1086 (uiVentilationMeasures[PPROX_MAX_MES]<uiVentilationSet[LOW_PRESSURE_ALARM_SET] && enVentilationMode==AVC_MODE))
ahaas92 3:b029a3f73a9e 1087 {
ahaas92 3:b029a3f73a9e 1088 ucCounterLPAlarm++;
ahaas92 3:b029a3f73a9e 1089 if (ucCounterLPAlarm>=4)
ahaas92 3:b029a3f73a9e 1090 {
ahaas92 3:b029a3f73a9e 1091 ucCounterLPAlarm=4;
ahaas92 3:b029a3f73a9e 1092 uiFlagsAlarm[ALARM_FLAGS1]|=LOW_PRESSURE_ALARM_MASK;
ahaas92 3:b029a3f73a9e 1093 }
ahaas92 3:b029a3f73a9e 1094 }
ahaas92 3:b029a3f73a9e 1095 else
ahaas92 3:b029a3f73a9e 1096 {
ahaas92 3:b029a3f73a9e 1097 ucCounterLPAlarm=0;
ahaas92 3:b029a3f73a9e 1098 uiFlagsAlarm[ALARM_FLAGS1]&=(~LOW_PRESSURE_ALARM_MASK);
ahaas92 3:b029a3f73a9e 1099 }
ahaas92 3:b029a3f73a9e 1100
ahaas92 3:b029a3f73a9e 1101 // --- Clear Alarm High pressure
ahaas92 3:b029a3f73a9e 1102 if (fAlarmPmax==FALSE)
ahaas92 3:b029a3f73a9e 1103 uiFlagsAlarm[ALARM_FLAGS1]&=(~HIGH_PRESSURE_ALARM_MASK);
ahaas92 3:b029a3f73a9e 1104 fAlarmPmax=FALSE;
ahaas92 3:b029a3f73a9e 1105
ahaas92 3:b029a3f73a9e 1106 // --- Clear Alarm Vti Max
ahaas92 3:b029a3f73a9e 1107 if (fAlarmVtiMax==FALSE)
ahaas92 3:b029a3f73a9e 1108 uiFlagsAlarm[ALARM_FLAGS1]&=(~HIGH_VTI_ALARM_MASK);
ahaas92 3:b029a3f73a9e 1109 fAlarmVtiMax=FALSE;
ahaas92 3:b029a3f73a9e 1110 }
ahaas92 3:b029a3f73a9e 1111 else
ahaas92 3:b029a3f73a9e 1112 {
ahaas92 3:b029a3f73a9e 1113 // --- During Expiration
ahaas92 3:b029a3f73a9e 1114
ahaas92 3:b029a3f73a9e 1115 // --- Motor Speed
ahaas92 3:b029a3f73a9e 1116 ulSumTachoTicks+=uiTachoTimeTicks;
ahaas92 3:b029a3f73a9e 1117 ulCounterAverageMotorSpeed++;
ahaas92 3:b029a3f73a9e 1118
ahaas92 3:b029a3f73a9e 1119 // --- Blower Current
ahaas92 3:b029a3f73a9e 1120 ulSumCurrentADCMesFiltered+=uiADCBlowerCurrent;
ahaas92 3:b029a3f73a9e 1121 ulCounterADC_FilteredBlowerCurrentMes++;
ahaas92 3:b029a3f73a9e 1122
ahaas92 3:b029a3f73a9e 1123 // --- Inc Vte
ahaas92 3:b029a3f73a9e 1124 if (iBlowerFlowMes<(-30))
ahaas92 3:b029a3f73a9e 1125 lSumVte+=iBlowerFlowMes;
ahaas92 3:b029a3f73a9e 1126 if (lSumVte<0)
ahaas92 3:b029a3f73a9e 1127 uiVteTemp=(u32)(lSumVte/(-6000));
ahaas92 3:b029a3f73a9e 1128 else
ahaas92 3:b029a3f73a9e 1129 uiVteTemp=0;
ahaas92 3:b029a3f73a9e 1130
ahaas92 3:b029a3f73a9e 1131 // --- Inc Te
ahaas92 3:b029a3f73a9e 1132 uiTeMesTemp++;
ahaas92 3:b029a3f73a9e 1133 if (uiTeMesTemp>60000) uiTeMesTemp=60000;
ahaas92 3:b029a3f73a9e 1134
ahaas92 3:b029a3f73a9e 1135 // --- Average motor voltage
ahaas92 3:b029a3f73a9e 1136 if (uiTeMesTemp==100)
ahaas92 3:b029a3f73a9e 1137 {
ahaas92 3:b029a3f73a9e 1138 ulSumADC_MotorVoltage=0;
ahaas92 3:b029a3f73a9e 1139 ulCounterADC_MotorVoltage=0;
ahaas92 3:b029a3f73a9e 1140 }
ahaas92 3:b029a3f73a9e 1141 else if (uiTeMesTemp>100)
ahaas92 3:b029a3f73a9e 1142 {
ahaas92 3:b029a3f73a9e 1143 ulSumADC_MotorVoltage+=uiDCinADCMeas;
ahaas92 3:b029a3f73a9e 1144 ulCounterADC_MotorVoltage++;
ahaas92 3:b029a3f73a9e 1145 }
ahaas92 3:b029a3f73a9e 1146 }
ahaas92 3:b029a3f73a9e 1147 }
ahaas92 3:b029a3f73a9e 1148 }
ahaas92 3:b029a3f73a9e 1149 else // if (bMemoStartVentilation==TRUE && uiTechnicalDataSet[DEVICE_MODE_TEC]==VENTILATION_MODE)
ahaas92 3:b029a3f73a9e 1150 {
ahaas92 3:b029a3f73a9e 1151 #ifndef TEMPERATURE_TRENDS
ahaas92 3:b029a3f73a9e 1152 uiTechnicalDataMes[MOTOR_TEMPERATURE_TEC_MES]=ComputeMotorTemperature(uiADCBlowerTemperatureMeas);
ahaas92 3:b029a3f73a9e 1153 #endif
ahaas92 3:b029a3f73a9e 1154 }
ahaas92 3:b029a3f73a9e 1155 }
ahaas92 3:b029a3f73a9e 1156 #endif // #ifndef C_M3_DEVICETEST_TARGET
ahaas92 3:b029a3f73a9e 1157
ahaas92 3:b029a3f73a9e 1158
ahaas92 3:b029a3f73a9e 1159 #ifndef C_M3_DEVICETEST_TARGET
ahaas92 3:b029a3f73a9e 1160 /*******************************************************************************
ahaas92 3:b029a3f73a9e 1161 * Function Name : ClearVentilationAlarm
ahaas92 3:b029a3f73a9e 1162 * Description : Clear all ventilation Alarms
ahaas92 3:b029a3f73a9e 1163 * Input : None
ahaas92 3:b029a3f73a9e 1164 * Output : None
ahaas92 3:b029a3f73a9e 1165 * Return : None
ahaas92 3:b029a3f73a9e 1166 *******************************************************************************/
ahaas92 3:b029a3f73a9e 1167 void ClearAllVentilationAlarms(void)
ahaas92 3:b029a3f73a9e 1168 {
ahaas92 3:b029a3f73a9e 1169 u8 i;
ahaas92 3:b029a3f73a9e 1170 u8 ucAlarmFlag;
ahaas92 3:b029a3f73a9e 1171
ahaas92 3:b029a3f73a9e 1172 for (i=0; i<SIZE_BLOWER_ALARM; i++)
ahaas92 3:b029a3f73a9e 1173 {
ahaas92 3:b029a3f73a9e 1174 ucAlarmFlag=stBlowerAlarmStatus[i].ucAlarmFlag;
ahaas92 3:b029a3f73a9e 1175 if (stBlowerAlarmStatus[i].bVentilationAlarm==TRUE && (ucAlarmFlag==ALARM_FLAGS1 || ucAlarmFlag==ALARM_FLAGS2))
ahaas92 3:b029a3f73a9e 1176 uiFlagsAlarm[ucAlarmFlag]&=(~stBlowerAlarmStatus[i].uiAlarmMask);
ahaas92 3:b029a3f73a9e 1177 }
ahaas92 3:b029a3f73a9e 1178 }
ahaas92 3:b029a3f73a9e 1179
ahaas92 3:b029a3f73a9e 1180
ahaas92 3:b029a3f73a9e 1181 /*******************************************************************************
ahaas92 3:b029a3f73a9e 1182 * Function Name : ClearAlarm
ahaas92 3:b029a3f73a9e 1183 * Description : Clear a specific alarm
ahaas92 3:b029a3f73a9e 1184 * Input : Mask of the alarm
ahaas92 3:b029a3f73a9e 1185 * Output : None
ahaas92 3:b029a3f73a9e 1186 * Return : None
ahaas92 3:b029a3f73a9e 1187 *******************************************************************************/
ahaas92 3:b029a3f73a9e 1188 void ClearAlarm(u8 ucAlarmFlag, u16 uiMask)
ahaas92 3:b029a3f73a9e 1189 {
ahaas92 3:b029a3f73a9e 1190 uiFlagsAlarm[ucAlarmFlag]&=(~uiMask);
ahaas92 3:b029a3f73a9e 1191 }
ahaas92 3:b029a3f73a9e 1192
ahaas92 3:b029a3f73a9e 1193
ahaas92 3:b029a3f73a9e 1194 /*******************************************************************************
ahaas92 3:b029a3f73a9e 1195 * Function Name : ClearAllMeasures
ahaas92 3:b029a3f73a9e 1196 * Description : Clear all ventilation measures
ahaas92 3:b029a3f73a9e 1197 * Input : None
ahaas92 3:b029a3f73a9e 1198 * Output : None
ahaas92 3:b029a3f73a9e 1199 * Return : None
ahaas92 3:b029a3f73a9e 1200 *******************************************************************************/
ahaas92 3:b029a3f73a9e 1201 void ClearAllMeasures(void)
ahaas92 3:b029a3f73a9e 1202 {
ahaas92 3:b029a3f73a9e 1203 u8 i;
ahaas92 3:b029a3f73a9e 1204
ahaas92 3:b029a3f73a9e 1205 // Reset measures except alarms
ahaas92 3:b029a3f73a9e 1206 for (i=0; i<SIZE_LRM_GROUP; i++)
ahaas92 3:b029a3f73a9e 1207 {
ahaas92 3:b029a3f73a9e 1208 if (i!=ALARM_ID1_MES && i!=ALARM_ID2_MES)// && i!=ALARM_ID3_MES && i!=ALARM_ID4_MES)
ahaas92 3:b029a3f73a9e 1209 uiVentilationMeasures[i]=0;
ahaas92 3:b029a3f73a9e 1210 }
ahaas92 3:b029a3f73a9e 1211
ahaas92 3:b029a3f73a9e 1212 // Reset others measures
ahaas92 3:b029a3f73a9e 1213 uiBlowerSpeedMes=0; uiAverageBlowerSpeedMes=0; // Speed=0 RPM
ahaas92 3:b029a3f73a9e 1214 ulSumTachoTicks=0; ulCounterAverageMotorSpeed=0;
ahaas92 3:b029a3f73a9e 1215 uiBreathBlowerCurrentMes=0; // Blower current=0 A
ahaas92 3:b029a3f73a9e 1216 ulSumCurrentADCMesFiltered=0; ulCounterADC_FilteredBlowerCurrentMes=0;
ahaas92 3:b029a3f73a9e 1217 bDisplayInspiratoryTrigger=FALSE;
ahaas92 3:b029a3f73a9e 1218 #ifdef MOTOR_LIFE_TESTING
ahaas92 3:b029a3f73a9e 1219 uiAverateMotorTempMes=0;
ahaas92 3:b029a3f73a9e 1220 #endif // #ifdef MOTOR_LIFE_TESTING
ahaas92 3:b029a3f73a9e 1221
ahaas92 3:b029a3f73a9e 1222 // Init temporary variables
ahaas92 3:b029a3f73a9e 1223 ucVentilationCycleCopy=INSPIRATION_CYCLE;
ahaas92 3:b029a3f73a9e 1224 uiPproxMax=0;
ahaas92 3:b029a3f73a9e 1225 uiVtiTemp=0;
ahaas92 3:b029a3f73a9e 1226 uiTiMesTemp=0;
ahaas92 3:b029a3f73a9e 1227 ucCounterLPAlarm=0;
ahaas92 3:b029a3f73a9e 1228 fAlarmPmax=FALSE;
ahaas92 3:b029a3f73a9e 1229 fAlarmVtiMax=FALSE;
ahaas92 3:b029a3f73a9e 1230 ucCounterAlarmVteMin=0;
ahaas92 3:b029a3f73a9e 1231 }
ahaas92 3:b029a3f73a9e 1232
ahaas92 3:b029a3f73a9e 1233
ahaas92 3:b029a3f73a9e 1234 /*******************************************************************************
ahaas92 3:b029a3f73a9e 1235 * Function Name : ReadStopVentilationAlarmNumber
ahaas92 3:b029a3f73a9e 1236 * Description : Read the alarm number which stops the ventilation
ahaas92 3:b029a3f73a9e 1237 * Input : None
ahaas92 3:b029a3f73a9e 1238 * Output : None
ahaas92 3:b029a3f73a9e 1239 * Return : alarm number
ahaas92 3:b029a3f73a9e 1240 *******************************************************************************/
ahaas92 3:b029a3f73a9e 1241 u8 ReadStopVentilationAlarmNumber(void)
ahaas92 3:b029a3f73a9e 1242 {
ahaas92 3:b029a3f73a9e 1243 u16 uiMask;
ahaas92 3:b029a3f73a9e 1244 u8 i;
ahaas92 3:b029a3f73a9e 1245 u8 ucAlarmNumber=SIZE_BLOWER_ALARM;
ahaas92 3:b029a3f73a9e 1246
ahaas92 3:b029a3f73a9e 1247 // Check Alarm which stops ventilation
ahaas92 3:b029a3f73a9e 1248 if (uiFlagsAlarm[ALARM_FLAGS1]!=0 ||
ahaas92 3:b029a3f73a9e 1249 uiFlagsAlarm[ALARM_FLAGS2]!=0)
ahaas92 3:b029a3f73a9e 1250 /*uiFlagsAlarm[ALARM_FLAGS3]!=0 ||
ahaas92 3:b029a3f73a9e 1251 uiFlagsAlarm[ALARM_FLAGS4]!=0)*/
ahaas92 3:b029a3f73a9e 1252 {
ahaas92 3:b029a3f73a9e 1253 for (i=0; i<SIZE_BLOWER_ALARM; i++)
ahaas92 3:b029a3f73a9e 1254 {
ahaas92 3:b029a3f73a9e 1255 if (stBlowerAlarmStatus[i].bForceVentilToStop==TRUE)
ahaas92 3:b029a3f73a9e 1256 {
ahaas92 3:b029a3f73a9e 1257 uiMask=stBlowerAlarmStatus[i].uiAlarmMask;
ahaas92 3:b029a3f73a9e 1258 if ((uiFlagsAlarm[stBlowerAlarmStatus[i].ucAlarmFlag]&uiMask)==uiMask)
ahaas92 3:b029a3f73a9e 1259 {
ahaas92 3:b029a3f73a9e 1260 ucAlarmNumber=i;
ahaas92 3:b029a3f73a9e 1261 break;
ahaas92 3:b029a3f73a9e 1262 }
ahaas92 3:b029a3f73a9e 1263 }
ahaas92 3:b029a3f73a9e 1264 }
ahaas92 3:b029a3f73a9e 1265 }
ahaas92 3:b029a3f73a9e 1266 return(ucAlarmNumber);
ahaas92 3:b029a3f73a9e 1267 }
ahaas92 3:b029a3f73a9e 1268
ahaas92 3:b029a3f73a9e 1269
ahaas92 3:b029a3f73a9e 1270 /*******************************************************************************
ahaas92 3:b029a3f73a9e 1271 * Function Name : UpdateAlarmsMeasureID
ahaas92 3:b029a3f73a9e 1272 * Description : Update the alarms ventilation measure variables
ahaas92 3:b029a3f73a9e 1273 * Input : None
ahaas92 3:b029a3f73a9e 1274 * Output : None
ahaas92 3:b029a3f73a9e 1275 * Return : alarm number
ahaas92 3:b029a3f73a9e 1276 *******************************************************************************/
ahaas92 3:b029a3f73a9e 1277 #ifdef USE_OPTIMACOMM
ahaas92 3:b029a3f73a9e 1278 void UpdateAlarmsMeasureID(void)
ahaas92 3:b029a3f73a9e 1279 {
ahaas92 3:b029a3f73a9e 1280 uiVentilationMeasures[ALARM_ID1_MES]=uiFlagsAlarm[ALARM_FLAGS1];
ahaas92 3:b029a3f73a9e 1281 uiVentilationMeasures[ALARM_ID2_MES]=uiFlagsAlarm[ALARM_FLAGS2];
ahaas92 3:b029a3f73a9e 1282 }
ahaas92 3:b029a3f73a9e 1283 #endif // #ifdef USE_OPTIMACOMM
ahaas92 3:b029a3f73a9e 1284 #endif // #ifndef C_M3_DEVICETEST_TARGET
ahaas92 3:b029a3f73a9e 1285
ahaas92 3:b029a3f73a9e 1286
ahaas92 3:b029a3f73a9e 1287 /*******************************************************************************
ahaas92 3:b029a3f73a9e 1288 * Function Name : ComputeMotorTemperature
ahaas92 3:b029a3f73a9e 1289 * Description : Return temperature (in degres C)
ahaas92 3:b029a3f73a9e 1290 * Input : uiADCMotorTemp : ADC value
ahaas92 3:b029a3f73a9e 1291 * Output : None
ahaas92 3:b029a3f73a9e 1292 * Return : None
ahaas92 3:b029a3f73a9e 1293 *******************************************************************************/
ahaas92 3:b029a3f73a9e 1294 u16 ComputeMotorTemperature(u16 uiADCMotorTemp)
ahaas92 3:b029a3f73a9e 1295 {
ahaas92 3:b029a3f73a9e 1296 u16 uiTemp, uiTempDec;
ahaas92 3:b029a3f73a9e 1297 u32 ulTemp;
ahaas92 3:b029a3f73a9e 1298
ahaas92 3:b029a3f73a9e 1299 for (uiTemp=0; uiTemp<121; uiTemp++)
ahaas92 3:b029a3f73a9e 1300 {
ahaas92 3:b029a3f73a9e 1301 if (uiADCMotorTemp>=uiADCMotorTempTable[uiTemp])
ahaas92 3:b029a3f73a9e 1302 break;
ahaas92 3:b029a3f73a9e 1303 }
ahaas92 3:b029a3f73a9e 1304
ahaas92 3:b029a3f73a9e 1305 if (uiADCMotorTemp<uiADCMotorTempTable[120])
ahaas92 3:b029a3f73a9e 1306 return(1200);
ahaas92 3:b029a3f73a9e 1307 else if (uiADCMotorTemp>=uiADCMotorTempTable[0])
ahaas92 3:b029a3f73a9e 1308 return(0);
ahaas92 3:b029a3f73a9e 1309 else if (uiADCMotorTemp==uiADCMotorTempTable[uiTemp])
ahaas92 3:b029a3f73a9e 1310 ulTemp=uiTemp*10;
ahaas92 3:b029a3f73a9e 1311 else
ahaas92 3:b029a3f73a9e 1312 {
ahaas92 3:b029a3f73a9e 1313 uiTempDec=((uiADCMotorTempTable[uiTemp-1]-uiADCMotorTemp)*10)/(uiADCMotorTempTable[uiTemp-1]-uiADCMotorTempTable[uiTemp]);
ahaas92 3:b029a3f73a9e 1314 ulTemp=((uiTemp-1)*10)+uiTempDec;
ahaas92 3:b029a3f73a9e 1315 }
ahaas92 3:b029a3f73a9e 1316
ahaas92 3:b029a3f73a9e 1317 ulTemp*=1000;
ahaas92 3:b029a3f73a9e 1318 ulTemp/=uiTechnicalDataSet[GAIN_BLOWER_TEMP_TEC];
ahaas92 3:b029a3f73a9e 1319 return((u16)ulTemp);
ahaas92 3:b029a3f73a9e 1320 }
ahaas92 3:b029a3f73a9e 1321
ahaas92 3:b029a3f73a9e 1322
ahaas92 3:b029a3f73a9e 1323 /*******************************************************************************
ahaas92 3:b029a3f73a9e 1324 * Function Name : ComputeFlowInLitersPerMin
ahaas92 3:b029a3f73a9e 1325 * Description : Compute the flow in l/min
ahaas92 3:b029a3f73a9e 1326 * Input : uFlowRAW : flow digital value, bPositiveFlow= TRUE if positive flow
ahaas92 3:b029a3f73a9e 1327 * Output : None
ahaas92 3:b029a3f73a9e 1328 * Return : signed Flow in l/min
ahaas92 3:b029a3f73a9e 1329 *******************************************************************************/
ahaas92 3:b029a3f73a9e 1330 int16_t ComputeFlowInLitersPerMin(u16 uiFlowRAW, bool bPositiveFlow)
ahaas92 3:b029a3f73a9e 1331 {
ahaas92 3:b029a3f73a9e 1332 u16 uiIndex;
ahaas92 3:b029a3f73a9e 1333 int16_t iFlow;
ahaas92 3:b029a3f73a9e 1334 u32 a;
ahaas92 3:b029a3f73a9e 1335 int32_t b;
ahaas92 3:b029a3f73a9e 1336 int32_t y;
ahaas92 3:b029a3f73a9e 1337
ahaas92 3:b029a3f73a9e 1338 for (uiIndex=0; uiIndex<stLUTFlowSensor.uiLUT_TableSize; uiIndex++)
ahaas92 3:b029a3f73a9e 1339 {
ahaas92 3:b029a3f73a9e 1340 if (uiFlowRAW==stLUTFlowSensor.uiFlowSensorTicks[uiIndex])
ahaas92 3:b029a3f73a9e 1341 {
ahaas92 3:b029a3f73a9e 1342 iFlow=(int16_t)stLUTFlowSensor.uiFlowValue[uiIndex];
ahaas92 3:b029a3f73a9e 1343 break;
ahaas92 3:b029a3f73a9e 1344 }
ahaas92 3:b029a3f73a9e 1345 else if (uiFlowRAW<stLUTFlowSensor.uiFlowSensorTicks[uiIndex])
ahaas92 3:b029a3f73a9e 1346 {
ahaas92 3:b029a3f73a9e 1347 if (uiIndex==0)
ahaas92 3:b029a3f73a9e 1348 {
ahaas92 3:b029a3f73a9e 1349 iFlow=(int16_t)(((u32)uiFlowRAW*stLUTFlowSensor.uiFlowValue[uiIndex])/stLUTFlowSensor.uiFlowSensorTicks[uiIndex]);
ahaas92 3:b029a3f73a9e 1350 }
ahaas92 3:b029a3f73a9e 1351 else
ahaas92 3:b029a3f73a9e 1352 {
ahaas92 3:b029a3f73a9e 1353 a=(100UL*(stLUTFlowSensor.uiFlowValue[uiIndex]-stLUTFlowSensor.uiFlowValue[uiIndex-1]))/(stLUTFlowSensor.uiFlowSensorTicks[uiIndex]-stLUTFlowSensor.uiFlowSensorTicks[uiIndex-1]);
ahaas92 3:b029a3f73a9e 1354 b=((int32_t)stLUTFlowSensor.uiFlowValue[uiIndex-1]*100)-((int32_t)stLUTFlowSensor.uiFlowSensorTicks[uiIndex-1]*a);
ahaas92 3:b029a3f73a9e 1355 y=((int32_t)a*(int32_t)uiFlowRAW)+b;
ahaas92 3:b029a3f73a9e 1356 iFlow=(int16_t)(y/100);
ahaas92 3:b029a3f73a9e 1357 }
ahaas92 3:b029a3f73a9e 1358 break;
ahaas92 3:b029a3f73a9e 1359 }
ahaas92 3:b029a3f73a9e 1360 else
ahaas92 3:b029a3f73a9e 1361 {
ahaas92 3:b029a3f73a9e 1362 iFlow=(int16_t)stLUTFlowSensor.uiFlowValue[uiIndex];
ahaas92 3:b029a3f73a9e 1363 }
ahaas92 3:b029a3f73a9e 1364 }
ahaas92 3:b029a3f73a9e 1365
ahaas92 3:b029a3f73a9e 1366 if (bPositiveFlow==FALSE)
ahaas92 3:b029a3f73a9e 1367 iFlow*=(-1);
ahaas92 3:b029a3f73a9e 1368
ahaas92 3:b029a3f73a9e 1369 return(iFlow);
ahaas92 3:b029a3f73a9e 1370 }
ahaas92 3:b029a3f73a9e 1371
ahaas92 3:b029a3f73a9e 1372 /******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/
ahaas92 3:b029a3f73a9e 1373
ahaas92 3:b029a3f73a9e 1374
ahaas92 3:b029a3f73a9e 1375