Index: firmware/App/Modes/ModeDrain.c =================================================================== diff -u -rf656b17f3d8d93b4fca49c9725e096e7eb55acc7 -r1a5efe97f5f39594b45797fded52cafce92afe80 --- firmware/App/Modes/ModeDrain.c (.../ModeDrain.c) (revision f656b17f3d8d93b4fca49c9725e096e7eb55acc7) +++ firmware/App/Modes/ModeDrain.c (.../ModeDrain.c) (revision 1a5efe97f5f39594b45797fded52cafce92afe80) @@ -34,20 +34,27 @@ // ********** private definitions ********** #define TARGET_DRAIN_PUMP_RPM 2100 ///< Target drain pump speed (in RPM). -#define DRAIN_WEIGHT_UNCHANGE_TIMEOUT ( 15 * 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. +/// Time period to wait after drain complete and before taring load cells. +#define DRAIN_EMPTY_TARE_WAIT ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) #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. +#define DELAY_RES_DRAIN_VALVE_MS 1000 ///< Delay reservoir drain valve open by 1 second. +#define DELAY_DRAIN_PUMP_MS 2000 ///< Delay drain pump on by 2 seconds. + // ********** 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. static U32 tempTrans = 0; // ********** private function prototypes ********** static DG_DRAIN_STATE_T handleDrainState( void ); +static DG_DRAIN_STATE_T handleTareState( void ); /*********************************************************************//** * @brief @@ -59,6 +66,7 @@ void initDrainMode( void ) { drainState = DG_DRAIN_STATE_START; + drainEmptyTareTimerCtr = 0; } /*********************************************************************//** @@ -73,30 +81,22 @@ // re-initialize each time we transition to drain mode initDrainMode(); -/*#ifndef V_2_SYSTEM +#ifndef V_2_SYSTEM DG_RESERVOIR_ID_T inactiveReservoir = getInactiveReservoir(); if ( DG_RESERVOIR_1 == inactiveReservoir ) { - setValveState( VRD1, VALVE_STATE_OPEN ); + setValveStateDelayed( VRD1, VALVE_STATE_OPEN, DELAY_RES_DRAIN_VALVE_MS ); } else if ( DG_RESERVOIR_2 == inactiveReservoir ) { - setValveState( VRD2, VALVE_STATE_OPEN ); + setValveStateDelayed( VRD2, VALVE_STATE_OPEN, DELAY_RES_DRAIN_VALVE_MS ); } -#endif*/ - - // TODO test code remove - DG_RESERVOIR_ID_T inactiveReservoir = getInactiveReservoir(); - tempTrans = 0; +#endif + // set initial actuator states setValveState( VDR, VALVE_STATE_DRAIN_C_TO_NO ); - // TODO test code remove + setDrainPumpTargetRPMDelayed( TARGET_DRAIN_PUMP_RPM, DELAY_DRAIN_PUMP_MS ); - // set initial actuator states - //setValveState( VDR, VALVE_STATE_DRAIN_C_TO_NO ); TODO uncomment - - //setDrainPumpTargetRPM( TARGET_DRAIN_PUMP_RPM ); //TODO comment this for testing - // NOTE: The target flow rate should be set prior to setting the start primary heater // because the initial guess in the heaters driver needs the target flow to calculate // the new PWMs for the main and small primary heaters @@ -123,13 +123,20 @@ switch ( drainState ) { case DG_DRAIN_STATE_START: - drainState = DG_DRAIN_STATE_DRAIN; + if ( TRUE == isDrainPumpOn() ) + { + drainState = DG_DRAIN_STATE_DRAIN; + } break; case DG_DRAIN_STATE_DRAIN: 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; @@ -141,9 +148,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 ) @@ -174,6 +182,48 @@ if ( TRUE == hasTargetDrainVolumeBeenReached( inactiveReservoir, DRAIN_WEIGHT_UNCHANGE_TIMEOUT ) ) { setDrainPumpTargetRPM( 0 ); + +#ifndef V_2_SYSTEM + if ( DG_RESERVOIR_1 == inactiveReservoir ) + { + setValveState( VRD1, VALVE_STATE_CLOSED ); + } + else if ( DG_RESERVOIR_2 == inactiveReservoir ) + { + 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 ); #ifndef V_2_SYSTEM