Index: firmware/App/Controllers/Fans.c =================================================================== diff -u -r986abcfcf047822cad1a10c1ee0924a80dd5f512 -r9490539a39d2bfd8d40558f3c05b09b48f041e6c --- firmware/App/Controllers/Fans.c (.../Fans.c) (revision 986abcfcf047822cad1a10c1ee0924a80dd5f512) +++ firmware/App/Controllers/Fans.c (.../Fans.c) (revision 9490539a39d2bfd8d40558f3c05b09b48f041e6c) @@ -479,7 +479,7 @@ for ( fan = FAN_INLET_1; fan < NUM_OF_FANS_NAMES; fan++ ) { rpm = getMeasuredFanRPM( fan ); - isFanRPMOutOfRange |= ( ( fabs( rpm - fansMinAllowedRPM ) < NEARLY_ZERO ) || ( fabs( rpm - fansMaxAllowedRPM ) > NEARLY_ZERO ) ? TRUE : FALSE ); + isFanRPMOutOfRange |= ( ( fabs( rpm - fansMinAllowedRPM ) < NEARLY_ZERO ) || ( fabs( rpm - fansMaxAllowedRPM ) < NEARLY_ZERO ) ? TRUE : FALSE ); } // If the fans alarm has been raised already, do not raise again Index: firmware/App/Modes/ModeChemicalDisinfect.c =================================================================== diff -u -r05019ca03114d75099dd3ae6e09f776bd8a2c46e -r9490539a39d2bfd8d40558f3c05b09b48f041e6c --- firmware/App/Modes/ModeChemicalDisinfect.c (.../ModeChemicalDisinfect.c) (revision 05019ca03114d75099dd3ae6e09f776bd8a2c46e) +++ firmware/App/Modes/ModeChemicalDisinfect.c (.../ModeChemicalDisinfect.c) (revision 9490539a39d2bfd8d40558f3c05b09b48f041e6c) @@ -438,7 +438,7 @@ setValveState( VPI, VALVE_STATE_CLOSED ); // Request a tare for reservoir 1 - tareReservoir(); + //tareReservoir(); // TODO update the drain here // Set the actuators to drain R1 setValveState( VRD1, VALVE_STATE_OPEN ); @@ -510,7 +510,7 @@ rsrvr2Status = DG_RESERVOIR_ABOVE_TARGET; // Request a tare for reservoir 2 - tareReservoir(); + //tareReservoir(); // TODO update the reservoir drain // Done with draining R1 setValveState( VRD1, VALVE_STATE_CLOSED ); Index: firmware/App/Modes/ModeDrain.c =================================================================== diff -u -r05019ca03114d75099dd3ae6e09f776bd8a2c46e -r9490539a39d2bfd8d40558f3c05b09b48f041e6c --- firmware/App/Modes/ModeDrain.c (.../ModeDrain.c) (revision 05019ca03114d75099dd3ae6e09f776bd8a2c46e) +++ firmware/App/Modes/ModeDrain.c (.../ModeDrain.c) (revision 9490539a39d2bfd8d40558f3c05b09b48f041e6c) @@ -107,6 +107,9 @@ { setValveStateDelayed( VRD2, VALVE_STATE_OPEN, DELAY_RES_DRAIN_VALVE_MS ); } + + initDrainParameters( inactiveReservoir ); + // set initial actuator states setValveState( VDR, VALVE_STATE_DRAIN_C_TO_NO ); setDrainPumpTargetRPMDelayed( TARGET_DRAIN_PUMP_RPM, DELAY_DRAIN_PUMP_MS ); Index: firmware/App/Modes/ModeHeatDisinfect.c =================================================================== diff -u -r05019ca03114d75099dd3ae6e09f776bd8a2c46e -r9490539a39d2bfd8d40558f3c05b09b48f041e6c --- firmware/App/Modes/ModeHeatDisinfect.c (.../ModeHeatDisinfect.c) (revision 05019ca03114d75099dd3ae6e09f776bd8a2c46e) +++ firmware/App/Modes/ModeHeatDisinfect.c (.../ModeHeatDisinfect.c) (revision 9490539a39d2bfd8d40558f3c05b09b48f041e6c) @@ -162,6 +162,7 @@ static U32 ROFCoolingTimer = 0; ///< RO filter cooling timer. static BOOL hasROFCirculationBeenStarted = FALSE; ///< Flag to indicate the water in RO filter has been recirculated. static U32 targetDisinfectTime = 0; ///< Target disinfect time. +static BOOL haveDrainParamsBeenInit; ///< Boolean flag to indicate whether the drain parameters have been reset or not. // ********** private function prototypes ********** @@ -207,6 +208,7 @@ * isPartialDisinfectInProgress, isDrainPumpOnInMixDrain, * hasROFCirculationBeenStarted, ROFCirculationTimer, targetDisinfectTime * ROFCirculationCoolingCounter, concentratePumpsPrimeTimer, + * haveDrainParamsBeenInit * @return none *************************************************************************/ void initHeatDisinfectMode( void ) @@ -232,6 +234,7 @@ hasROFCirculationBeenStarted = FALSE; concentratePumpsPrimeTimer = 0; targetDisinfectTime = 0; + haveDrainParamsBeenInit = FALSE; } /*********************************************************************//** @@ -1852,20 +1855,29 @@ { DG_RESERVOIR_STATUS_T status = DG_RESERVOIR_ABOVE_TARGET; + // If the drain parameters of the reservoir is not initialized, initialize them + if ( FALSE == haveDrainParamsBeenInit ) + { + initDrainParameters( r ); + haveDrainParamsBeenInit = TRUE; + } + BOOL isDrainComplete = hasTargetDrainVolumeBeenReached( r, drainSteadyStateTimeout ); if ( TRUE == isDrainComplete ) { // Set the state timer in case it needs to be used for another timeout check - stateTimer = getMSTimerCount(); - status = DG_RESERVOIR_REACHED_TARGET; + stateTimer = getMSTimerCount(); + haveDrainParamsBeenInit = FALSE; + status = DG_RESERVOIR_REACHED_TARGET; } else if ( TRUE == didTimeout( stateTimer, timeout ) ) { // Failed to drain on time. Update the previous heat disinfect state and transition to basic cancellation - prevHeatDisinfectState = heatDisinfectState; + prevHeatDisinfectState = heatDisinfectState; alarmDetectedPendingTrigger = ALARM_ID_DG_RESERVOIR_DRAIN_TIMEOUT; - status = DG_RESERVOIR_NOT_REACHED_TARGET; + haveDrainParamsBeenInit = FALSE; + status = DG_RESERVOIR_NOT_REACHED_TARGET; } return status; Index: firmware/App/Modes/OperationModes.c =================================================================== diff -u -r986abcfcf047822cad1a10c1ee0924a80dd5f512 -r9490539a39d2bfd8d40558f3c05b09b48f041e6c --- firmware/App/Modes/OperationModes.c (.../OperationModes.c) (revision 986abcfcf047822cad1a10c1ee0924a80dd5f512) +++ firmware/App/Modes/OperationModes.c (.../OperationModes.c) (revision 9490539a39d2bfd8d40558f3c05b09b48f041e6c) @@ -41,7 +41,8 @@ // ********** private definitions ********** #define BROADCAST_DG_OP_MODE_INTERVAL ( 250 / TASK_GENERAL_INTERVAL ) ///< interval (ms/task time) at which the operation mode is published on the CAN bus. -#define DATA_PUBLISH_COUNTER_START_COUNT 11 ///< Data publish counter start count. +// The data publish counter offset is a lower number to make sure DG is sending its status to the HD from the beginning and alarm 140 is not raised +#define DATA_PUBLISH_COUNTER_START_COUNT 2 ///< Data publish counter start count. // ********** private data ********** Index: firmware/App/Services/Reservoirs.c =================================================================== diff -u -r986abcfcf047822cad1a10c1ee0924a80dd5f512 -r9490539a39d2bfd8d40558f3c05b09b48f041e6c --- firmware/App/Services/Reservoirs.c (.../Reservoirs.c) (revision 986abcfcf047822cad1a10c1ee0924a80dd5f512) +++ firmware/App/Services/Reservoirs.c (.../Reservoirs.c) (revision 9490539a39d2bfd8d40558f3c05b09b48f041e6c) @@ -47,7 +47,7 @@ #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. +#define DRAIN_THRESHOLD_ML 1.0 ///< Drain threshold in milliliters. #define DATA_PUBLISH_COUNTER_START_COUNT 5 ///< Data publish counter start count. // ********** private data ********** @@ -87,7 +87,7 @@ 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. +static F32 previousReservoirWeight[ NUM_OF_DG_RESERVOIRS ]; ///< Previous reservoir weight. /*********************************************************************//** * @brief @@ -107,7 +107,7 @@ isThisTheFirstCycle = TRUE; dataPublishCounter = DATA_PUBLISH_COUNTER_START_COUNT; - memset( &previousReservoiWeight, 0.0, sizeof( F32 ) * NUM_OF_DG_RESERVOIRS ); + memset( &previousReservoirWeight, 0.0, sizeof( F32 ) * NUM_OF_DG_RESERVOIRS ); } /*********************************************************************//** @@ -430,18 +430,6 @@ /*********************************************************************//** * @brief - * The tareReservoir function sets the tare load cell variable to TRUE. - * @details Inputs: none - * @details Outputs: none - * @return none - *************************************************************************/ -void tareReservoir( void ) -{ - tareLoadCellRequest = TRUE; -} - -/*********************************************************************//** - * @brief * The getInactiveReservoir function gets the inactive reservoir. * @details Inputs: activeReservoir * @details Outputs: none @@ -683,10 +671,16 @@ F32 loadcellWeightML = getLoadCellSmallFilteredWeight( associatedLoadCell[ reservoirId ] ); U32 targetDrainVolML = getU32OverrideValue( &drainVolumeTargetMl ); - F32 drainFlowML = loadcellWeightML - previousReservoiWeight[ reservoirId ]; + F32 drainFlowML = loadcellWeightML - previousReservoirWeight[ reservoirId ]; - previousReservoiWeight[ reservoirId ] = getLoadCellSmallFilteredWeight( associatedLoadCell[ reservoirId ] ); + // Update the structure with the current weight as the previous + previousReservoirWeight[ reservoirId ] = getLoadCellSmallFilteredWeight( associatedLoadCell[ reservoirId ] ); + // If the flow is less than the threshold and the time has not been set, set the timer + // If the flow is greater than the threshold and timer has been set, 0 it because the flow is out of range and we are not + // ready to consider this the end of the reservoir flow + // If the wait for drain to steady has elapsed and the drain pump inlet pressure sensor is indicating and increased vacuum, + // signal the drain is complete if ( ( drainFlowML <= DRAIN_THRESHOLD_ML ) && ( 0 == reservoirWeightUnchangeStartTime[ reservoirId ] ) ) { reservoirWeightUnchangeStartTime[ reservoirId ] = getMSTimerCount(); @@ -695,12 +689,9 @@ { 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 else if ( ( TRUE == didTimeout( reservoirWeightUnchangeStartTime[ reservoirId ], timeout ) && - ( getMeasuredDGPressure( PRESSURE_SENSOR_DRAIN_PUMP_INLET ) > MIN_DRAIN_INLET_PSI_EMPTY ) ) || ( FALSE == tareLoadCellRequest ) ) + ( getMeasuredDGPressure( PRESSURE_SENSOR_DRAIN_PUMP_INLET ) > MIN_DRAIN_INLET_PSI_EMPTY ) ) ) { - reservoirWeightUnchangeStartTime[ reservoirId ] = 0; result = TRUE; } @@ -745,7 +736,25 @@ return tareLoadCellRequest; } +/*********************************************************************//** + * @brief + * The initDrainParameters function initializes the drain parameters. + * @details Inputs: none + * @details Outputs: reservoirWeightUnchangeStartTime, previousReservoirWeight + * associatedLoadCell + * @param reservoirId the ID of the reservoir that it drain parameters have + * to be initialized + * @return none + *************************************************************************/ +void initDrainParameters( DG_RESERVOIR_ID_T reservoirId ) +{ + // Set the start time to 0 for the next drain and update the current load cell reading to the previous value + reservoirWeightUnchangeStartTime[ reservoirId ] = 0; + previousReservoirWeight[ reservoirId ] = getLoadCellSmallFilteredWeight( associatedLoadCell[ reservoirId ] ); +} + + /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/ Index: firmware/App/Services/Reservoirs.h =================================================================== diff -u -r05019ca03114d75099dd3ae6e09f776bd8a2c46e -r9490539a39d2bfd8d40558f3c05b09b48f041e6c --- firmware/App/Services/Reservoirs.h (.../Reservoirs.h) (revision 05019ca03114d75099dd3ae6e09f776bd8a2c46e) +++ firmware/App/Services/Reservoirs.h (.../Reservoirs.h) (revision 9490539a39d2bfd8d40558f3c05b09b48f041e6c) @@ -101,8 +101,6 @@ void startDrainCmd( DRAIN_CMD_T drainCmd ); // handle drain command from HD void stopDrainCmd( void ); // handle stop drain command from HD -void tareReservoir( void ); - DG_RESERVOIR_ID_T getInactiveReservoir( void ); F32 getReservoirWeight( DG_RESERVOIR_ID_T reservoirId ); @@ -119,6 +117,7 @@ BOOL hasTargetDrainVolumeBeenReached( DG_RESERVOIR_ID_T reservoirId, U32 timeout ); void tareLoadCellsAtEmpty( DG_RESERVOIR_ID_T reservoirId ); BOOL isReservoirTarePending( void ); +void initDrainParameters( DG_RESERVOIR_ID_T reservoirId ); BOOL testSetDGActiveReservoirOverride( DG_RESERVOIR_ID_T value ); BOOL testResetDGActiveReservoirOverride( void );