Index: firmware/App/Modes/ModeDrain.c =================================================================== diff -u -rf308cc4c35eab630ebbbde405cfe47d049afeafb -ra1b8dbb69c4bd2f0cc22e62bede7015c9307d378 --- firmware/App/Modes/ModeDrain.c (.../ModeDrain.c) (revision f308cc4c35eab630ebbbde405cfe47d049afeafb) +++ firmware/App/Modes/ModeDrain.c (.../ModeDrain.c) (revision a1b8dbb69c4bd2f0cc22e62bede7015c9307d378) @@ -8,7 +8,7 @@ * @file ModeDrain.c * * @author (last) Quang Nguyen -* @date (last) 13-Aug-2020 +* @date (last) 24-Aug-2020 * * @author (original) Leonardo Baloa * @date (original) 20-Dec-2019 @@ -17,13 +17,14 @@ #include "ConductivitySensors.h" #include "DrainPump.h" -#include "LoadCell.h" #include "ModeDrain.h" #include "OperationModes.h" #include "Pressures.h" #include "Reservoirs.h" -#include "Valves.h" +#include "ROPump.h" +#include "TaskGeneral.h" #include "TemperatureSensors.h" +#include "Valves.h" /** * @addtogroup DGDrainMode @@ -32,22 +33,25 @@ // ********** private definitions ********** -#define TARGET_DRAIN_PUMP_RPM 2800 ///< Target drain pump speed (in RPM). +#define TARGET_DRAIN_PUMP_RPM 1800 ///< Target drain pump speed (in RPM). +#define DRAIN_WEIGH_UNCHANGE_TIMEOUT ( 2 * MS_PER_SECOND ) ///< Time period of unchanged weight during draining before timeout. +#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. + // ********** private data ********** -static DG_DRAIN_STATE_T drainState = DG_DRAIN_STATE_START; ///< Currently active drain state. +static DG_DRAIN_STATE_T drainState = DG_DRAIN_STATE_START; ///< Currently active drain state. // ********** private function prototypes ********** static DG_DRAIN_STATE_T handleDrainState( void ); /*********************************************************************//** * @brief - * The initOpParamsMode function initializes the Drain Mode module. - * @details - * Inputs : none - * Outputs : Operating Parameters Mode module initialized. + * The initDrainMode function initializes the drain mode module. + * @details Inputs: none + * @details Outputs: drainState * @return none *************************************************************************/ void initDrainMode( void ) @@ -57,11 +61,9 @@ /*********************************************************************//** * @brief - * The transitionToDrainMode function prepares for transition to drain \n - * mode. - * @details - * Inputs : none - * Outputs : + * The transitionToDrainMode function prepares for transition to drain mode. + * @details Inputs: none + * @details Outputs: Drain mode initialized * @return none *************************************************************************/ void transitionToDrainMode( void ) @@ -71,23 +73,24 @@ // set initial actuator states setValveState( VDR, VALVE_STATE_DRAIN_C_TO_NO ); - setDrainPumpTargetSpeed( TARGET_DRAIN_PUMP_RPM ); + setDrainPumpTargetRPM( TARGET_DRAIN_PUMP_RPM ); + setROPumpTargetFlowRate( TARGET_RO_FLOW_RATE_L, TARGET_RO_PRESSURE_PSI ); } /*********************************************************************//** * @brief - * The execDrainMode function executes the Drain Mode state machine. - * @details - * Inputs : none - * Outputs : + * The execDrainMode function executes the drain mode state machine. + * @details Inputs: drainState + * @details Outputs: Check water quality, drain mode state machine executed * @return current state. *************************************************************************/ U32 execDrainMode( void ) { - // check inlet water conductivity, temperature, and pressure - checkInletWaterConductivity( drainState ); + // check inlet water conductivity, temperature, pressure, and RO rejection ratio + checkInletWaterConductivity(); checkInletWaterTemperature(); checkInletPressure(); + checkRORejectionRatio(); // execute current drain state switch ( drainState ) @@ -101,7 +104,7 @@ break; default: - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, 0, drainState ) // TODO - add s/w fault enum to 1st data param + 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; break; } @@ -111,28 +114,20 @@ /*********************************************************************//** * @brief - * The handleDrainState function handles the drain state of the Drain Mode \n - * state machine. - * @details - * Inputs : none - * Outputs : + * The handleDrainState function handles the drain state of the drain mode state machine. + * @details Inputs: none + * @details Outputs: Drain out from reservoir * @return the next state *************************************************************************/ static DG_DRAIN_STATE_T handleDrainState( void ) { DG_DRAIN_STATE_T result = DG_DRAIN_STATE_DRAIN; - LOAD_CELL_ID_T drainWeightLoadCell = LOAD_CELL_A1; + DG_RESERVOIR_ID_T inactiveReservoir = getInactiveReservoir(); - // determine which load cell to use for drain volume - we want weight of inactive reservoir - if ( RESERVOIR_1 == getActiveReservoir() ) + // if we have reached our target drain to volume (by weight) or cannot drain anymore, we are done draining - go back to re-circ mode + if ( hasTargetDrainVolumeBeenReached( inactiveReservoir, DRAIN_WEIGH_UNCHANGE_TIMEOUT ) ) { - drainWeightLoadCell = LOAD_CELL_B1; - } - - // if we've reached our target drain to volume (by weight), we're done draining - go back to re-circ mode - if ( getReservoirDrainVolumeTargetMl() >= getLoadCellFilteredWeight( drainWeightLoadCell ) ) - { - setDrainPumpTargetSpeed( 0 ); + setDrainPumpTargetRPM( 0 ); requestNewOperationMode( DG_MODE_CIRC ); } @@ -141,11 +136,9 @@ /*********************************************************************//** * @brief - * The getCurrentDrainState function returns the current state of the \n - * drain mode. - * @details - * Inputs : drainState - * Outputs : none + * The getCurrentDrainState function returns the current state of the drain mode. + * @details Inputs: drainState + * @details Outputs: none * @return the current state of drain mode. *************************************************************************/ DG_DRAIN_STATE_T getCurrentDrainState( void )