Index: firmware/App/Modes/ModeChemicalDisinfect.c =================================================================== diff -u -r025612ad77fe630889a364586de54bffe5262d56 -r05019ca03114d75099dd3ae6e09f776bd8a2c46e --- firmware/App/Modes/ModeChemicalDisinfect.c (.../ModeChemicalDisinfect.c) (revision 025612ad77fe630889a364586de54bffe5262d56) +++ firmware/App/Modes/ModeChemicalDisinfect.c (.../ModeChemicalDisinfect.c) (revision 05019ca03114d75099dd3ae6e09f776bd8a2c46e) @@ -421,9 +421,6 @@ // Set all the actuators to reset and de-energized state deenergizeActuators(); - // Reset the load cells lowest weight prior to starting the run - resetReservoirsLowestWeight(); - F32 ppiPressure = getMeasuredDGPressure( PRESSURE_SENSOR_RO_PUMP_INLET ); F32 THdTemp = getTemperatureValue( TEMPSENSORS_HEAT_DISINFECT ); F32 TPoTemp = getTemperatureValue( TEMPSENSORS_OUTLET_PRIMARY_HEATER ); Index: firmware/App/Modes/ModeDrain.c =================================================================== diff -u -r025612ad77fe630889a364586de54bffe5262d56 -r05019ca03114d75099dd3ae6e09f776bd8a2c46e --- firmware/App/Modes/ModeDrain.c (.../ModeDrain.c) (revision 025612ad77fe630889a364586de54bffe5262d56) +++ firmware/App/Modes/ModeDrain.c (.../ModeDrain.c) (revision 05019ca03114d75099dd3ae6e09f776bd8a2c46e) @@ -50,11 +50,10 @@ #define DIALYSATE_DRAIN_TIME_OUT ( 2 * SEC_PER_MIN * MS_PER_SECOND ) ///< Dialysate drain time out. -/// Time period to wait for concentrate lines to rinse. -#define RINSE_CONCENTRATE_LINES_WAIT ( 25 * MS_PER_SECOND / TASK_GENERAL_INTERVAL ) -/// Reserver the concentrate speed to rinse out concentrate lines. -#define RINSE_SPEED ( ( CONCENTRATE_PUMP_MAX_SPEED - 3.0 ) * -1.0 ) +#define RINSE_CONCENTRATE_LINES_WAIT ( 25 * MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Time period to wait for concentrate lines to rinse. +#define RINSE_SPEED ( ( CONCENTRATE_PUMP_MAX_SPEED - 3.0 ) * -1.0 ) ///< Reserver the concentrate speed to rinse out concentrate lines. + // ********** private data ********** static DG_DRAIN_STATE_T drainState; ///< Currently active drain state. Index: firmware/App/Modes/ModeFill.c =================================================================== diff -u -r44222e803e04d057ab793ce6b72902b8bfe9b7d0 -r05019ca03114d75099dd3ae6e09f776bd8a2c46e --- firmware/App/Modes/ModeFill.c (.../ModeFill.c) (revision 44222e803e04d057ab793ce6b72902b8bfe9b7d0) +++ firmware/App/Modes/ModeFill.c (.../ModeFill.c) (revision 05019ca03114d75099dd3ae6e09f776bd8a2c46e) @@ -353,7 +353,6 @@ { result = DG_FILL_MODE_STATE_DIALYSATE_PRODUCTION; } - } if ( TRUE == didTimeout( waterQualityCheckStartTime, WATER_QUALITY_CHECK_TIME_OUT_MS ) ) @@ -501,13 +500,9 @@ #ifndef DISABLE_MIXING requestConcentratePumpOn( CONCENTRATEPUMPS_CP1_ACID ); requestConcentratePumpOn( CONCENTRATEPUMPS_CP2_BICARB ); - - if ( concentratePumpPrimeCount++ > CONCENTRATE_PUMP_PRIME_INTERVAL ) #endif - { - setValveState( VPO, VALVE_STATE_FILL_C_TO_NC ); - result = DG_FILL_MODE_STATE_DELIVER_DIALYSATE; - } + setValveState( VPO, VALVE_STATE_FILL_C_TO_NC ); + result = DG_FILL_MODE_STATE_DELIVER_DIALYSATE; } else { Index: firmware/App/Modes/ModeFlush.c =================================================================== diff -u -r025612ad77fe630889a364586de54bffe5262d56 -r05019ca03114d75099dd3ae6e09f776bd8a2c46e --- firmware/App/Modes/ModeFlush.c (.../ModeFlush.c) (revision 025612ad77fe630889a364586de54bffe5262d56) +++ firmware/App/Modes/ModeFlush.c (.../ModeFlush.c) (revision 05019ca03114d75099dd3ae6e09f776bd8a2c46e) @@ -295,9 +295,6 @@ { DG_FLUSH_STATE_T state = DG_FLUSH_STATE_START; - // Reset the load cells lowest weight prior to starting the run - resetReservoirsLowestWeight(); - // Start overall flush timer overallFlushElapsedTimeStart = getMSTimerCount(); Index: firmware/App/Modes/ModeHeatDisinfect.c =================================================================== diff -u -rcc8b9ddb9905161ddb0dc2af6bfbf863408669c8 -r05019ca03114d75099dd3ae6e09f776bd8a2c46e --- firmware/App/Modes/ModeHeatDisinfect.c (.../ModeHeatDisinfect.c) (revision cc8b9ddb9905161ddb0dc2af6bfbf863408669c8) +++ firmware/App/Modes/ModeHeatDisinfect.c (.../ModeHeatDisinfect.c) (revision 05019ca03114d75099dd3ae6e09f776bd8a2c46e) @@ -430,9 +430,6 @@ // Set all the actuators to reset and de-energized state deenergizeActuators(); - // Reset the load cells lowest weight prior to starting the run - resetReservoirsLowestWeight(); - F32 ppiPressure = getMeasuredDGPressure( PRESSURE_SENSOR_RO_PUMP_INLET ); F32 TDiTemp = getTemperatureValue( TEMPSENSORS_INLET_DIALYSATE ); F32 TRoTemp = getTemperatureValue( TEMPSENSORS_OUTLET_REDUNDANT ); Index: firmware/App/Services/Reservoirs.c =================================================================== diff -u -r44222e803e04d057ab793ce6b72902b8bfe9b7d0 -r05019ca03114d75099dd3ae6e09f776bd8a2c46e --- firmware/App/Services/Reservoirs.c (.../Reservoirs.c) (revision 44222e803e04d057ab793ce6b72902b8bfe9b7d0) +++ firmware/App/Services/Reservoirs.c (.../Reservoirs.c) (revision 05019ca03114d75099dd3ae6e09f776bd8a2c46e) @@ -44,13 +44,10 @@ #define DEFAULT_DRAIN_VOLUME_ML 0 ///< Default drain volume in mL. #define MAX_DRAIN_VOLUME_ML MAX_RESERVOIR_VOLUME_ML ///< Maximum drain volume in mL. -#define MAX_RESERVOIR_WEIGHT 10000 ///< Maximum reservoir weight in grams. - #define MIN_DRAIN_INLET_PSI_EMPTY -3.0 ///< Minimum drain inlet pressure (in PSI) to indicate reservoir is empty while drain pump on. - #define RESERVOIR_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< interval (ms/task time) at which the reservoir data is published on the CAN bus. - #define MAX_REDUNDANT_LOAD_CELL_DIFF 50.0 ///< Maximum difference in redundant load cells when determining if fill completed. +#define DRAIN_THRESHOLD_ML 30.0 ///< Drain threshold in milliliters. // ********** private data ********** @@ -67,13 +64,13 @@ F32 tempReservoirEndFill; ///< Temperature reservoir at the end of the fill in C. F32 tempTargetTrimmer; ///< Temperature target trimmer heater in C. F32 flowTargetDialysateLPM; ///< Dialysate target flow rate in L/min. -} HEATERS_TEMPERATURE_CALC_DATA_T; +} HEATERS_TEMPERATURE_CALC_DATA_T; static HEATERS_TEMPERATURE_CALC_DATA_T heatersTempCalc; ///< Heaters temperature calculations data structure. static U32 reservoirDataPublicationTimerCounter = 0; ///< used to schedule reservoir data publication to CAN bus. static OVERRIDE_U32_T activeReservoir = { 0, 0, 0, 0 }; ///< The active reservoir that the DG is filling/draining/etc. -static OVERRIDE_U32_T fillVolumeTargetMl = { 0, 0, 0, 0 }; // TODO is this needed with NV Data? ///< The target reservoir fill volume (in mL). +static OVERRIDE_U32_T fillVolumeTargetMl = { 0, 0, 0, 0 }; ///< The target reservoir fill volume (in mL). static OVERRIDE_U32_T drainVolumeTargetMl = { 0, 0, 0, 0 }; ///< The target reservoir drain volume (in mL). @@ -83,20 +80,21 @@ static LOAD_CELL_ID_T redundantLoadCell[ NUM_OF_DG_RESERVOIRS ] = { LOAD_CELL_RESERVOIR_1_BACKUP, LOAD_CELL_RESERVOIR_2_BACKUP }; /// The reservoirs' lowest weight during draining. -static F32 reservoirLowestWeight[ NUM_OF_DG_RESERVOIRS ] = { MAX_RESERVOIR_WEIGHT, MAX_RESERVOIR_WEIGHT }; static U32 reservoirWeightUnchangeStartTime[ NUM_OF_DG_RESERVOIRS ] = { 0, 0 }; ///< The reservoirs' weight start time when weight stop decreasing. static BOOL tareLoadCellRequest; ///< Flag indicates if load cell tare has been requested by HD. static DG_RESERVOIR_VOLUME_RECORD_T reservoirsCalRecord; ///< DG reservoirs non-volatile record. static DG_HEATING_CAL_RECORD_T heatingConstsCalRecord; ///< DG heating calibration record. static F32 targetFillFlowRateLPM; ///< Target fill flow rate in L/min. static BOOL isThisTheFirstCycle = TRUE; ///< Boolean flag to indicate whether this is the first cycle. +static F32 previousReservoiWeight[ NUM_OF_DG_RESERVOIRS ]; ///< Previous reservoir weight. /*********************************************************************//** * @brief * The initReservoirs function initializes the Reservoirs module. * @details Inputs: none * @details Outputs: activeReservoir.data, fillVolumeTargetMl.data, - * drainVolumeTargetMl.data, targetFillFlowRateLPM, isThisTheFirstCycle + * drainVolumeTargetMl.data, targetFillFlowRateLPM, isThisTheFirstCycle, + * previousReservoiWeight * @return none *************************************************************************/ void initReservoirs( void ) @@ -106,6 +104,8 @@ drainVolumeTargetMl.data = DEFAULT_DRAIN_VOLUME_ML; targetFillFlowRateLPM = 0.0; isThisTheFirstCycle = TRUE; + + memset( &previousReservoiWeight, 0.0, sizeof( F32 ) * NUM_OF_DG_RESERVOIRS ); } /*********************************************************************//** @@ -440,20 +440,6 @@ /*********************************************************************//** * @brief - * The resetReservoirsLowestWeight function resets the lowest load cell - * weight of the reservoirs. - * @details Inputs: reservoirLowestWeight - * @details Outputs: reservoirLowestWeight - * @return none - *************************************************************************/ -void resetReservoirsLowestWeight( void ) -{ - reservoirLowestWeight[ DG_RESERVOIR_1 ] = MAX_RESERVOIR_WEIGHT; - reservoirLowestWeight[ DG_RESERVOIR_2 ] = MAX_RESERVOIR_WEIGHT; -} - -/*********************************************************************//** - * @brief * The getInactiveReservoir function gets the inactive reservoir. * @details Inputs: activeReservoir * @details Outputs: none @@ -682,8 +668,9 @@ * @brief * The hasTargetDrainVolumeReached function checks if the target drain volume * for specific reservoir has been reached or exceed time limit. - * @details Inputs: drainVolumeTargetMl - * @details Outputs: none + * @details Inputs: reservoirWeightUnchangeStartTime, reservoirWeightUnchangeStartTime + * @details Outputs: reservoirWeightUnchangeStartTime, tareLoadCellRequest, + * reservoirWeightUnchangeStartTime * @param reservoirId reservoir id * @param timeout timeout period when weight remains the same * @return TRUE if target drain volume has been reached or exceeds time limit, FALSE if not. @@ -692,26 +679,27 @@ { BOOL result = FALSE; - F32 const loadcellWeight = getLoadCellSmallFilteredWeight( associatedLoadCell[ reservoirId ] ); - U32 const targetDrainVolume = getU32OverrideValue( &drainVolumeTargetMl ); + F32 loadcellWeightML = getLoadCellSmallFilteredWeight( associatedLoadCell[ reservoirId ] ); + U32 targetDrainVolML = getU32OverrideValue( &drainVolumeTargetMl ); + F32 drainFlowML = loadcellWeightML - previousReservoiWeight[ reservoirId ]; - if ( loadcellWeight < reservoirLowestWeight[ reservoirId ] ) + previousReservoiWeight[ reservoirId ] = getLoadCellSmallFilteredWeight( associatedLoadCell[ reservoirId ] ); + + if ( ( drainFlowML <= DRAIN_THRESHOLD_ML ) && ( 0 == reservoirWeightUnchangeStartTime[ reservoirId ] ) ) { - reservoirLowestWeight[ reservoirId ] = loadcellWeight; reservoirWeightUnchangeStartTime[ reservoirId ] = getMSTimerCount(); } - - BOOL const hasTimeOut = didTimeout( reservoirWeightUnchangeStartTime[ reservoirId ], timeout ); - BOOL const hasTargetReached = ( targetDrainVolume >= loadcellWeight ); - + else if ( drainFlowML > DRAIN_THRESHOLD_ML ) + { + reservoirWeightUnchangeStartTime[ reservoirId ] = 0; + } // If the goal is to tare the load cell, then the target drain should be reached and timing out on the // reservoir weight is not enough - if ( ( ( TRUE == hasTimeOut ) && ( getMeasuredDGPressure( PRESSURE_SENSOR_DRAIN_PUMP_INLET ) > MIN_DRAIN_INLET_PSI_EMPTY ) ) || - ( ( TRUE == hasTargetReached ) && ( FALSE == tareLoadCellRequest ) ) ) + else if ( ( TRUE == didTimeout( reservoirWeightUnchangeStartTime[ reservoirId ], timeout ) && + ( getMeasuredDGPressure( PRESSURE_SENSOR_DRAIN_PUMP_INLET ) > MIN_DRAIN_INLET_PSI_EMPTY ) ) || ( FALSE == tareLoadCellRequest ) ) { + reservoirWeightUnchangeStartTime[ reservoirId ] = 0; result = TRUE; - // Reset for next drain - reservoirLowestWeight[ reservoirId ] = MAX_RESERVOIR_WEIGHT; } return result; Index: firmware/App/Services/Reservoirs.h =================================================================== diff -u -r025612ad77fe630889a364586de54bffe5262d56 -r05019ca03114d75099dd3ae6e09f776bd8a2c46e --- firmware/App/Services/Reservoirs.h (.../Reservoirs.h) (revision 025612ad77fe630889a364586de54bffe5262d56) +++ firmware/App/Services/Reservoirs.h (.../Reservoirs.h) (revision 05019ca03114d75099dd3ae6e09f776bd8a2c46e) @@ -102,7 +102,6 @@ void stopDrainCmd( void ); // handle stop drain command from HD void tareReservoir( void ); -void resetReservoirsLowestWeight( void ); DG_RESERVOIR_ID_T getInactiveReservoir( void ); F32 getReservoirWeight( DG_RESERVOIR_ID_T reservoirId );