Index: firmware/App/Controllers/DGInterface.c =================================================================== diff -u -r954107454f4c5d4cfbdfaefda5cc1cd15b1e18ac -r46c538cc5b7b40ddc8227e2ad1c77bab93716571 --- firmware/App/Controllers/DGInterface.c (.../DGInterface.c) (revision 954107454f4c5d4cfbdfaefda5cc1cd15b1e18ac) +++ firmware/App/Controllers/DGInterface.c (.../DGInterface.c) (revision 46c538cc5b7b40ddc8227e2ad1c77bab93716571) @@ -91,6 +91,7 @@ // DG Dialysate flow rate static F32 dgDialysateFlowRateMlMin = 0.0; ///< Latest dialysate flow rate reported by the DG. +static BOOL dgDialysateFlowDataFreshFlag = FALSE; ///< Flag to signal the execDialInFlowMonitor() to process fresh flow rate data // Reservoir data static DG_RESERVOIR_ID_T dgActiveReservoir = DG_RESERVOIR_2; ///< Latest active reservoir reported by the DG. @@ -127,7 +128,7 @@ dgTrimmerTempSet = 0.0; dgActiveReservoirSet = DG_RESERVOIR_2; dgReservoirFillVolumeTargetSet = 0; - dgReservoirDrainVolumeTargetSet = 0; + dgReservoirDrainVolumeTargetSet = 0; // initialize load cell weights for ( i = 0; i < NUM_OF_LOAD_CELLS; i++ ) @@ -430,6 +431,19 @@ return result; } + +/*********************************************************************//** + * @brief + * The getDialysateFlowDataFreshFlag function returns a flag to indicate + * if the dialysate flow rate data reported by the DG is fresh or stale data. + * @details Inputs: dgDialysateFlowDataFreshFlag + * @details Outputs: none + * @return T/F flag to indicate fresh/stale status of dialysate flow data. + *************************************************************************/ +BOOL getDialysateFlowDataFreshFlag( void ) +{ + return dgDialysateFlowDataFreshFlag; +} /*********************************************************************//** * @brief @@ -605,18 +619,32 @@ /*********************************************************************//** * @brief - * The setDialysateFlowData function sets the latest dialysate flow data - * reported by the DG. + * The setDialysateFlowData function sets the latest dialysate flow rate + * and its freshness status. The dialysate flow data is reported by the DG. * @details Inputs: none * @details Outputs: dgDialysateFlowRateMlMin - * @param flowRate latest dialysate flow rate (LPM) reported by DG + * @param flowRate latest dialysate flow rate (mL/min) reported by DG * @return none *************************************************************************/ void setDialysateFlowData( F32 flowRate ) { dgDialysateFlowRateMlMin = flowRate; - filterDialInFlowReadings( flowRate * (F32)ML_PER_LITER ); + setDialysateFlowDataFreshFlag( TRUE ); // sets freshness status } + +/*********************************************************************//** + * @brief + * The setDialysateFlowDataFreshFlag function sets the dialysate flow + * data freshness flag. + * @details Inputs: none + * @details Outputs: dgDialysateFlowDataFreshFlag + * @param flowRateFreshFlag to set + * @return none + *************************************************************************/ +void setDialysateFlowDataFreshFlag( BOOL flowRateFreshFlag ) +{ + dgDialysateFlowDataFreshFlag = flowRateFreshFlag; +} /*********************************************************************//** * @brief Index: firmware/App/Controllers/DGInterface.h =================================================================== diff -u -r954107454f4c5d4cfbdfaefda5cc1cd15b1e18ac -r46c538cc5b7b40ddc8227e2ad1c77bab93716571 --- firmware/App/Controllers/DGInterface.h (.../DGInterface.h) (revision 954107454f4c5d4cfbdfaefda5cc1cd15b1e18ac) +++ firmware/App/Controllers/DGInterface.h (.../DGInterface.h) (revision 46c538cc5b7b40ddc8227e2ad1c77bab93716571) @@ -120,6 +120,7 @@ DG_RESERVOIR_ID_T getDGActiveReservoir( void ); DG_RESERVOIR_ID_T getDGInactiveReservoir( void ); BOOL hasDGCompletedReservoirSwitch( void ); +BOOL getDialysateFlowDataFreshFlag( void ); F32 getDGDialysateFlowRateMlMin( void ); F32 getLoadCellWeight( LOAD_CELL_ID_T loadCellID ); F32 getReservoirWeight( DG_RESERVOIR_ID_T resID ); @@ -132,6 +133,7 @@ void setDGDialysateTemperatures( F32 primaryHtrTemp, F32 trimmerHtrTemp ); void setDGReservoirsData( DG_RESERVOIR_ID_T resID, U32 fillVol, U32 drainVol ); void setDialysateFlowData( F32 flowRate ); +void setDialysateFlowDataFreshFlag( BOOL flowRateFreshFlag ); void setNewLoadCellReadings( F32 res1Primary, F32 res1Backup, F32 res2Primary, F32 res2Backup ); void setDGDisinfectsStates( DG_DISINFECT_UI_STATES_T states ); Index: firmware/App/Controllers/DialInFlow.c =================================================================== diff -u -re45524455c005d4fa1734efcbaf7ed0499302670 -r46c538cc5b7b40ddc8227e2ad1c77bab93716571 --- firmware/App/Controllers/DialInFlow.c (.../DialInFlow.c) (revision e45524455c005d4fa1734efcbaf7ed0499302670) +++ firmware/App/Controllers/DialInFlow.c (.../DialInFlow.c) (revision 46c538cc5b7b40ddc8227e2ad1c77bab93716571) @@ -29,7 +29,8 @@ #include "PersistentAlarm.h" #include "PIControllers.h" #include "SafetyShutdown.h" -#include "SystemCommMessages.h" +#include "SystemCommMessages.h" +#include "SystemComm.h" #include "TaskGeneral.h" #include "TaskPriority.h" #include "Timers.h" @@ -82,6 +83,8 @@ static const U32 DIP_DIRECTION_ERROR_PERSIST = (250 / TASK_PRIORITY_INTERVAL); /// Persist time (task intervals) dialysate flow rate out of range error condition. static const U32 DIP_MAX_FLOW_RATE_OUT_OF_RANGE_PERSIST = ((1 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL); +/// Time threshold to trigger an alarm if Dialysate flow data has not arrived within 3 seconds +static const U32 DIP_DIALYSATE_FLOW_DATA_ALARM_THRESHOLD = ((3 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL); #define DIP_MAX_CURR_WHEN_STOPPED_MA 150.0 ///< Motor controller current should not exceed this when pump should be stopped. #define DIP_MAX_CURR_WHEN_RUNNING_MA 2000.0 ///< Motor controller current should not exceed this when pump should be running. @@ -152,7 +155,8 @@ static PUMP_CONTROL_MODE_T dialInPumpControlModeSet = PUMP_CONTROL_MODE_CLOSED_LOOP;///< Currently set dialIn pump control mode. /// Interval (in ms) at which to publish dialIn flow data to CAN bus -static OVERRIDE_U32_T dialInFlowDataPublishInterval = { DIAL_IN_FLOW_DATA_PUB_INTERVAL, DIAL_IN_FLOW_DATA_PUB_INTERVAL, DIAL_IN_FLOW_DATA_PUB_INTERVAL, 0 }; +static OVERRIDE_U32_T dialInFlowDataPublishInterval = { DIAL_IN_FLOW_DATA_PUB_INTERVAL, DIAL_IN_FLOW_DATA_PUB_INTERVAL, DIAL_IN_FLOW_DATA_PUB_INTERVAL, 0 }; +static U32 dialysateFlowDataFreshStatusCounter = 0; ///< Counter use to trigger alarm if no fresh dialysate flow data is received static S32 targetDialInFlowRate = 0; ///< Requested dialIn flow rate static OVERRIDE_F32_T measuredDialInFlowRate = { 0.0, 0.0, 0.0, 0 }; ///< Measured dialysate inlet flow rate static OVERRIDE_F32_T dialInPumpRotorSpeedRPM = { 0.0, 0.0, 0.0, 0 }; ///< Measured dialysate inlet pump rotor speed @@ -196,7 +200,8 @@ static void releaseDialInPumpStop( void ); static void setDialInPumpDirection( MOTOR_DIR_T dir ); static void publishDialInFlowData( void ); -static void resetDialInFlowMovingAverage( void ); +static void resetDialInFlowMovingAverage( void ); +static void filterDialInFlowReadings( F32 flow ); static void updateDialInPumpSpeedAndDirectionFromHallSensors( void ); static void checkDialInPumpRotor( void ); static void checkDialInPumpDirection( void ); @@ -235,6 +240,7 @@ // 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 ); } /*********************************************************************//** @@ -401,10 +407,78 @@ U08 spReadCtr = getFPGADialysateFlowSlowPacketReadCounter(); U08 flowErrorCtr = getFPGADialysateFlowErrorCounter(); U08 flowStatus = getFPGADialysateFlowMeterStatus(); +<<<<<<< HEAD + F32 dipFlow; +#ifdef USE_FMD_FLOW_SENSOR + F32 dpFlow = getFPGADialysateFlow(); + + // 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 + if ( TRUE == getDialysateFlowDataFreshFlag() ) + { + dialysateFlowDataFreshStatusCounter = 0; // reset counter + dipFlow = getDGDialysateFlowRateMlMin() * (F32)ML_PER_LITER; + filterDialInFlowReadings( dipFlow ); // process the fresh dialysate flow data + setDialysateFlowDataFreshFlag( FALSE ); + } + else + { // dialysate flow data is a stale data + if ( ++dialysateFlowDataFreshStatusCounter > DIP_DIALYSATE_FLOW_DATA_ALARM_THRESHOLD ) + { + filterDialInFlowReadings( 0.0 ); + if ( TRUE == isDGCommunicating() ) + { + activateAlarmNoData( ALARM_ID_HD_DIALYSATE_FLOW_DATA_NOT_RECEIVE ); + } + } + } +#endif +======= +>>>>>>> 954107454f4c5d4cfbdfaefda5cc1cd15b1e18ac 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; - + // Calculate dialysate inlet pump motor speed/direction from hall sensor count updateDialInPumpSpeedAndDirectionFromHallSensors(); Index: firmware/App/Controllers/DialInFlow.h =================================================================== diff -u -re45524455c005d4fa1734efcbaf7ed0499302670 -r46c538cc5b7b40ddc8227e2ad1c77bab93716571 --- firmware/App/Controllers/DialInFlow.h (.../DialInFlow.h) (revision e45524455c005d4fa1734efcbaf7ed0499302670) +++ firmware/App/Controllers/DialInFlow.h (.../DialInFlow.h) (revision 46c538cc5b7b40ddc8227e2ad1c77bab93716571) @@ -56,8 +56,7 @@ BOOL setDialInPumpTargetFlowRate( U32 flowRate, MOTOR_DIR_T dir, PUMP_CONTROL_MODE_T mode ); void signalDialInPumpHardStop( void ); -void signalDialInPumpRotorHallSensor( void ); -void filterDialInFlowReadings( F32 flow ); +void signalDialInPumpRotorHallSensor( void ); BOOL homeDialInPump( void ); BOOL isDialInPumpRunning( void );