Index: firmware/App/Controllers/ROPump.c =================================================================== diff -u -r81dc975f13b9308e40aa0e33e0eca2d407276d44 -r19d00df76fc906db9e514b10f259c39958ff25bb --- firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision 81dc975f13b9308e40aa0e33e0eca2d407276d44) +++ firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision 19d00df76fc906db9e514b10f259c39958ff25bb) @@ -324,12 +324,8 @@ { U16 roFlowReading = getFPGAROPumpFlowRate(); - // If the flow is less than a certain value, FPGA will return 0xFFFF meaning that the flow is 0. - if ( FLOW_SENSOR_ZERO_READING != roFlowReading ) - { - // Update sum for flow average calculation - measuredFlowReadingsSum += (S32)roFlowReading; - } + // Update sum for flow average calculation + measuredFlowReadingsSum += (S32)roFlowReading; // Read the pressure at the sensor. The pump cannot be more that the maximum allowed pressure // to make sure the hardware (especially the ROF) is not damaged. If it is the case, we need to stop immediately @@ -347,30 +343,21 @@ // Read flow at the control set if ( ++flowFilterCounter >= FLOW_SAMPLES_TO_AVERAGE ) { - U32 sensor; - F32 flow = RO_FLOW_ADC_TO_LPM_FACTOR / ( (F32)measuredFlowReadingsSum * FLOW_AVERAGE_MULTIPLIER ); - // If the flow is less than a certain value, FPGA will return 0xFFFF meaning that - // the flow is 0. Otherwise, convert the count to flow rate in mL/min - if ( ( FLOW_SENSOR_ZERO_READING == roFlowReading ) || ( 0 == roFlowReading ) ) - { - measuredROFlowRateLPM.data = 0.0; - } - else - { - // Right now there is only one flow sensor but a for loop is used here to be able to automatically accommodate - // the future flow sensors - for( sensor = 0; sensor < NUM_OF_CAL_DATA_FLOW_SENSORS; sensor++ ) - { - measuredROFlowRateLPM.data = pow(flow, 4) * flowSensorsCalRecord.flowSensors[ sensor ].fourthOrderCoeff + - pow(flow, 3) * flowSensorsCalRecord.flowSensors[ sensor ].thirdOrderCoeff + - pow(flow, 2) * flowSensorsCalRecord.flowSensors[ sensor ].secondOrderCoeff + - flow * flowSensorsCalRecord.flowSensors[ sensor ].gain + - flowSensorsCalRecord.flowSensors[ sensor ].offset; - } - } + measuredROFlowRateLPM.data = pow(flow, 4) * flowSensorsCalRecord.flowSensors[ CAL_DATA_RO_PUMP_FLOW_SENSOR ].fourthOrderCoeff + + pow(flow, 3) * flowSensorsCalRecord.flowSensors[ CAL_DATA_RO_PUMP_FLOW_SENSOR ].thirdOrderCoeff + + pow(flow, 2) * flowSensorsCalRecord.flowSensors[ CAL_DATA_RO_PUMP_FLOW_SENSOR ].secondOrderCoeff + + flow * flowSensorsCalRecord.flowSensors[ CAL_DATA_RO_PUMP_FLOW_SENSOR ].gain + + flowSensorsCalRecord.flowSensors[ CAL_DATA_RO_PUMP_FLOW_SENSOR ].offset; + // If the flow is less than a certain value, FPGA will return 0xFFFF meaning that + // the flow is 0. + if ( FLOW_SENSOR_ZERO_READING == roFlowReading ) + { + measuredROFlowRateLPM.data = 0.0; + } + measuredFlowReadingsSum = 0; flowFilterCounter = 0; }