Index: firmware/App/Controllers/DialInFlow.c =================================================================== diff -u -rd523b848b4d88669fcf0ab27fc2842521dfc1ffd -r8a2d4170a3645d658bb3ef48552d5d4d6d7a37e2 --- firmware/App/Controllers/DialInFlow.c (.../DialInFlow.c) (revision d523b848b4d88669fcf0ab27fc2842521dfc1ffd) +++ firmware/App/Controllers/DialInFlow.c (.../DialInFlow.c) (revision 8a2d4170a3645d658bb3ef48552d5d4d6d7a37e2) @@ -182,9 +182,9 @@ static U32 errorDialInRotorSpeedPersistTimerCtr = 0; ///< Persistence timer counter for rotor speed error condition. static U32 errorDialInPumpDirectionPersistTimerCtr = 0; ///< Persistence timer counter for pump direction error condition. -static F32 flowReadings[ SIZE_OF_ROLLING_AVG ]; ///< Holds flow samples for a rolling average. +static F64 flowReadings[ SIZE_OF_ROLLING_AVG ]; ///< Holds flow samples for a rolling average. static U32 flowReadingsIdx = 0; ///< Index for next sample in rolling average array. -static F32 flowReadingsTotal = 0.0; ///< Rolling total - used to calc average. +static F64 flowReadingsTotal = 0.0; ///< Rolling total - used to calc average. static U32 flowReadingsCount = 0; ///< Number of samples in flow rolling average buffer. static U32 dipCurrErrorDurationCtr = 0; ///< Used for tracking persistence of dip current errors. @@ -201,7 +201,7 @@ static void setDialInPumpDirection( MOTOR_DIR_T dir ); static void publishDialInFlowData( void ); static void resetDialInFlowMovingAverage( void ); -static void filterDialInFlowReadings( F32 flow ); +static void filterDialInFlowReadings( F64 flow ); static void updateDialInPumpSpeedAndDirectionFromHallSensors( void ); static void checkDialInPumpRotor( void ); static void checkDialInPumpDirection( void ); @@ -240,7 +240,6 @@ // Initialize persistent alarm for flow sensor signal strength too low initPersistentAlarm( ALARM_ID_HD_DIAL_IN_FLOW_OUT_OF_RANGE, 0, DIP_MAX_FLOW_RATE_OUT_OF_RANGE_PERSIST ); - initPersistentAlarm( ALARM_ID_HD_DIALYSATE_FLOW_DATA_NOT_RECEIVE, 0, 0 ); } /*********************************************************************//** @@ -407,61 +406,17 @@ U08 spReadCtr = getFPGADialysateFlowSlowPacketReadCounter(); U08 flowErrorCtr = getFPGADialysateFlowErrorCounter(); U08 flowStatus = getFPGADialysateFlowMeterStatus(); - F32 dipFlow; -#ifdef USE_FMD_FLOW_SENSOR - F32 dpFlow = getFPGADialysateFlow(); + F64 dipFlow; - // Check if a new calibration is available - if ( TRUE == isNewCalibrationRecordAvailable() ) - { - // Get the new calibration data and check its validity - processCalibrationData(); - } - dipFlow = pow(dpFlow, 4) * dialysateFlowCalRecord.hdFlowSensors[ CAL_DATA_HD_DIALYSATE_FLOW_SENSOR ].fourthOrderCoeff + - pow(dpFlow, 3) * dialysateFlowCalRecord.hdFlowSensors[ CAL_DATA_HD_DIALYSATE_FLOW_SENSOR ].thirdOrderCoeff + - pow(dpFlow, 2) * dialysateFlowCalRecord.hdFlowSensors[ CAL_DATA_HD_DIALYSATE_FLOW_SENSOR ].secondOrderCoeff + - dpFlow * dialysateFlowCalRecord.hdFlowSensors[ CAL_DATA_HD_DIALYSATE_FLOW_SENSOR ].gain + - dialysateFlowCalRecord.hdFlowSensors[ CAL_DATA_HD_DIALYSATE_FLOW_SENSOR ].offset; - -#ifndef DISABLE_PUMP_FLOW_CHECKS - if ( TRUE == isPersistentAlarmTriggered( ALARM_ID_HD_DP_FLOW_SENSOR_ERROR, ( flowErrorCtr != lastDialysateFlowCommErrorCount ) ) ) - { - activateAlarmNoData( ALARM_ID_HD_DP_FLOW_SENSOR_ERROR ); - } - if ( flowStatus != DFM_SENSOR_CONNECTED_STATUS ) - { - SET_ALARM_WITH_1_U32_DATA( ALARM_ID_HD_DIALYSATE_FLOW_STATUS_SELF_TEST_FAILURE, (U32)flowStatus ); - } - lastDialysateFlowCommErrorCount = flowErrorCtr; -#endif - -#ifndef DISABLE_FPGA_COUNTER_CHECKS - // Check for stale flow reading - if ( TRUE == isPersistentAlarmTriggered( ALARM_ID_HD_DP_FLOW_READ_TIMEOUT_ERROR, ( fpReadCtr == lastDialysateFlowFastPacketReadCtr ) ) ) - { - activateAlarmNoData( ALARM_ID_HD_DP_FLOW_READ_TIMEOUT_ERROR ); - } - if ( TRUE == isPersistentAlarmTriggered( ALARM_ID_HD_DP_FLOW_SLOW_READ_TIMEOUT_ERROR, ( spReadCtr == lastDialysateFlowSlowPacketReadCtr ) ) ) - { - activateAlarmNoData( ALARM_ID_HD_DP_FLOW_SLOW_READ_TIMEOUT_ERROR ); - } -#endif - - // Record flow read counters for next time around - lastDialysateFlowFastPacketReadCtr = fpReadCtr; - lastDialysateFlowSlowPacketReadCtr = spReadCtr; - - dialInFlowSignalStrength.data = getFPGADialysateFlowSignalStrength(); -#else + // Process new dialysate flow readings if ( TRUE == getDialysateFlowDataFreshFlag() ) { - dialysateFlowDataFreshStatusCounter = 0; // reset counter - dipFlow = getDGDialysateFlowRateMlMin() * (F32)ML_PER_LITER; - filterDialInFlowReadings( dipFlow ); // process the fresh dialysate flow data - setDialysateFlowDataFreshFlag( FALSE ); + dipFlow = getDGDialysateFlowRateLMin() * (F64)ML_PER_LITER; // convert rate to mL/min + filterDialInFlowReadings( dipFlow ); // process the fresh dialysate flow data + dialysateFlowDataFreshStatusCounter = 0; // reset counter } else - { // dialysate flow data is a stale data + { // Alarm if not receiving new dialysate flow readings in timely manner if ( ++dialysateFlowDataFreshStatusCounter > DIP_DIALYSATE_FLOW_DATA_ALARM_THRESHOLD ) { filterDialInFlowReadings( 0.0 ); @@ -471,8 +426,8 @@ } } } -#endif - + + // Get latest pump speed and current from motor controller adcDialInPumpMCSpeedRPM.data = (F32)(SIGN_FROM_12_BIT_VALUE(dipRPM)) * DIP_SPEED_ADC_TO_RPM_FACTOR; adcDialInPumpMCCurrentmA.data = (F32)(SIGN_FROM_12_BIT_VALUE(dipmA)) * DIP_CURRENT_ADC_TO_MA_FACTOR; @@ -925,7 +880,7 @@ * @details Outputs: flowReadings[], flowReadingsIdx, flowReadingsCount, flowReadingsTotal * @return none *************************************************************************/ -void filterDialInFlowReadings( F32 flow ) +void filterDialInFlowReadings( F64 flow ) { if ( flowReadingsCount >= SIZE_OF_ROLLING_AVG ) { @@ -935,7 +890,7 @@ flowReadingsTotal += flow; flowReadingsIdx = INC_WRAP( flowReadingsIdx, 0, SIZE_OF_ROLLING_AVG - 1 ); flowReadingsCount = INC_CAP( flowReadingsCount, SIZE_OF_ROLLING_AVG ); - measuredDialInFlowRate.data = flowReadingsTotal / (F32)flowReadingsCount; + measuredDialInFlowRate.data = (F32)( flowReadingsTotal / (F64)flowReadingsCount ); } /*********************************************************************//**