Index: firmware/App/Controllers/ROPump.c =================================================================== diff -u -rd3819286869611f9c02add72a0f8e321598fdf42 -r012ee7b4f72e47aa351eb723abca0e3104ea677b --- firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision d3819286869611f9c02add72a0f8e321598fdf42) +++ firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision 012ee7b4f72e47aa351eb723abca0e3104ea677b) @@ -324,8 +324,12 @@ { U16 roFlowReading = getFPGAROPumpFlowRate(); - // Update sum for flow average calculation - measuredFlowReadingsSum += (S32)roFlowReading; + // 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; + } // 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,25 +351,16 @@ 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 ) ) + // Right now there is only one flow sensor but a for loop is used here to be able to automatically accommodate + // any future flow sensors TODO - this loop works with the flowSensorsCalRecord, but not with the measuredROFlowRateLPM structure. + for( sensor = 0; sensor < NUM_OF_CAL_DATA_FLOW_SENSORS; sensor++ ) { - measuredROFlowRateLPM.data = 0.0; + 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; } - 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; - } - } measuredFlowReadingsSum = 0; flowFilterCounter = 0;