Index: firmware/App/Modes/ModeDrain.c =================================================================== diff -u -r2e3b3b2034ee5afb52a8630568145c9705afff9f -r78a138b18328bce8312abac79d76aad9dfe8ea3a --- firmware/App/Modes/ModeDrain.c (.../ModeDrain.c) (revision 2e3b3b2034ee5afb52a8630568145c9705afff9f) +++ firmware/App/Modes/ModeDrain.c (.../ModeDrain.c) (revision 78a138b18328bce8312abac79d76aad9dfe8ea3a) @@ -34,7 +34,8 @@ // ********** private definitions ********** #define TARGET_DRAIN_PUMP_RPM 1800 ///< Target drain pump speed (in RPM). -#define DRAIN_WEIGHT_UNCHANGE_TIMEOUT ( 2 * MS_PER_SECOND ) ///< Time period of unchanged weight during draining before timeout. +#define DRAIN_WEIGHT_UNCHANGE_TIMEOUT ( 2 * MS_PER_SECOND ) ///< Time period of unchanged weight during draining before timeout. +#define DRAIN_EMPTY_TARE_WAIT ( MS_PER_SECOND ) ///< Time period to wait after drain complete and before taring load cells. #define TARGET_RO_PRESSURE_PSI 130 ///< Target pressure for RO pump. #define TARGET_RO_FLOW_RATE_L 0.3 ///< Target flow rate for RO pump. @@ -44,11 +45,13 @@ // ********** private data ********** -static DG_DRAIN_STATE_T drainState = DG_DRAIN_STATE_START; ///< Currently active drain state. +static DG_DRAIN_STATE_T drainState; ///< Currently active drain state. +static U32 drainEmptyTareTimerCtr; ///< Timer counter for delay between drain complete and load cell tare. // ********** private function prototypes ********** static DG_DRAIN_STATE_T handleDrainState( void ); +static DG_DRAIN_STATE_T handleTareState( void ); /*********************************************************************//** * @brief @@ -60,6 +63,7 @@ void initDrainMode( void ) { drainState = DG_DRAIN_STATE_START; + drainEmptyTareTimerCtr = 0; } /*********************************************************************//** @@ -121,6 +125,10 @@ drainState = handleDrainState(); break; + case DG_DRAIN_STATE_TARE: + drainState = handleTareState(); + break; + default: SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_DRAIN_MODE_INVALID_EXEC_STATE, drainState ) drainState = DG_DRAIN_STATE_START; @@ -132,9 +140,10 @@ /*********************************************************************//** * @brief - * The handleDrainState function handles the drain state of the drain mode state machine. + * The handleDrainState function handles the drain state of the drain mode + * state machine. * @details Inputs: none - * @details Outputs: Drain out from reservoir + * @details Outputs: none * @return the next state *************************************************************************/ static DG_DRAIN_STATE_T handleDrainState( void ) @@ -146,7 +155,6 @@ if ( hasTargetDrainVolumeBeenReached( inactiveReservoir, DRAIN_WEIGHT_UNCHANGE_TIMEOUT ) ) { setDrainPumpTargetRPM( 0 ); - requestNewOperationMode( DG_MODE_CIRC ); #ifndef V_2_SYSTEM if ( DG_RESERVOIR_1 == inactiveReservoir ) @@ -158,13 +166,45 @@ setValveState( VRD2, VALVE_STATE_CLOSED ); } #endif + + if ( TRUE == isReservoirTarePending() ) + { // Tare reservoir load cells at empty if requested + result = DG_DRAIN_STATE_TARE; + } + else + { + requestNewOperationMode( DG_MODE_CIRC ); + } } return result; } /*********************************************************************//** * @brief + * The handleTareState function handles the tare state of the drain mode + * state machine. + * @details Inputs: drainEmptyTareTimerCtr + * @details Outputs: drainEmptyTareTimerCtr + * @return the next state + *************************************************************************/ +static DG_DRAIN_STATE_T handleTareState( void ) +{ + DG_DRAIN_STATE_T result = DG_DRAIN_STATE_TARE; + DG_RESERVOIR_ID_T inactiveReservoir = getInactiveReservoir(); + + if ( ++drainEmptyTareTimerCtr > DRAIN_EMPTY_TARE_WAIT ) + { + drainEmptyTareTimerCtr = 0; + tareLoadCellsAtEmpty( inactiveReservoir ); + requestNewOperationMode( DG_MODE_CIRC ); + } + + return result; +} + +/*********************************************************************//** + * @brief * The getCurrentDrainState function returns the current state of the drain mode. * @details Inputs: drainState * @details Outputs: none Index: firmware/App/Services/Reservoirs.c =================================================================== diff -u -r847478dd75aac2edfe27df454ac5a644b6f30040 -r78a138b18328bce8312abac79d76aad9dfe8ea3a --- firmware/App/Services/Reservoirs.c (.../Reservoirs.c) (revision 847478dd75aac2edfe27df454ac5a644b6f30040) +++ firmware/App/Services/Reservoirs.c (.../Reservoirs.c) (revision 78a138b18328bce8312abac79d76aad9dfe8ea3a) @@ -472,21 +472,47 @@ if ( hasTimeOut || hasTargetReached ) { result = TRUE; + // Reset for next drain reservoirLowestWeight[ reservoirId ] = MAX_RESERVOIR_WEIGHT; - - if ( tareLoadCellRequest ) - { - tareLoadCellRequest = FALSE; - tareLoadCell( associatedLoadCell[ reservoirId ] ); - tareLoadCell( redundantLoadCell[ reservoirId ] ); - } } return result; } /*********************************************************************//** * @brief + * The tareLoadCellsAtEmpty function tares the load cells for the inactive + * reservoir when ModeDrain empties it and tare request is pending. + * @details Inputs: tareLoadCellRequest + * @details Outputs: tareLoadCellRequest + * @param reservoirId ID of reservoir to tare + * @return none + *************************************************************************/ +void tareLoadCellsAtEmpty( DG_RESERVOIR_ID_T reservoirId ) +{ + if ( TRUE == tareLoadCellRequest ) + { + tareLoadCellRequest = FALSE; + tareLoadCell( associatedLoadCell[ reservoirId ] ); + tareLoadCell( redundantLoadCell[ reservoirId ] ); + } +} + +/*********************************************************************//** + * @brief + * The isReservoirTarePending function determines whether a reservoir tare + * request is currently pending. + * @details Inputs: tareLoadCellRequest + * @details Outputs: none + * @return tareLoadCellRequest + *************************************************************************/ +BOOL isReservoirTarePending( void ) +{ + return tareLoadCellRequest; +} + +/*********************************************************************//** + * @brief * The getActiveReservoir function gets the active reservoir. * @details Inputs: activeReservoir * @details Outputs: none Index: firmware/App/Services/Reservoirs.h =================================================================== diff -u -rebbb1f85550a1f9b8f946655f7b2b63f76fbf67d -r78a138b18328bce8312abac79d76aad9dfe8ea3a --- firmware/App/Services/Reservoirs.h (.../Reservoirs.h) (revision ebbb1f85550a1f9b8f946655f7b2b63f76fbf67d) +++ firmware/App/Services/Reservoirs.h (.../Reservoirs.h) (revision 78a138b18328bce8312abac79d76aad9dfe8ea3a) @@ -85,7 +85,9 @@ F32 getReservoirWeight( DG_RESERVOIR_ID_T reservoirId ); BOOL hasTargetFillVolumeBeenReached( DG_RESERVOIR_ID_T reservoirId ); -BOOL hasTargetDrainVolumeBeenReached( DG_RESERVOIR_ID_T reservoirId , U32 timeout ); +BOOL hasTargetDrainVolumeBeenReached( DG_RESERVOIR_ID_T reservoirId, U32 timeout ); +void tareLoadCellsAtEmpty( DG_RESERVOIR_ID_T reservoirId ); +BOOL isReservoirTarePending( void ); BOOL testSetDGActiveReservoirOverride( DG_RESERVOIR_ID_T value ); BOOL testResetDGActiveReservoirOverride( void );