Index: firmware/App/Modes/FPModes/FlushPermeate.c =================================================================== diff -u -rd79faa7118db6d048ce3433224b3e5a478c97a98 -rf73c82e967797bb1db745ebffd71a49e523e651c --- firmware/App/Modes/FPModes/FlushPermeate.c (.../FlushPermeate.c) (revision d79faa7118db6d048ce3433224b3e5a478c97a98) +++ firmware/App/Modes/FPModes/FlushPermeate.c (.../FlushPermeate.c) (revision f73c82e967797bb1db745ebffd71a49e523e651c) @@ -19,9 +19,9 @@ #include "Conductivity.h" #include "FlushPermeate.h" #include "FPOperationModes.h" +#include "Level.h" #include "MessageSupport.h" #include "Messaging.h" -#include "PermeateTank.h" #include "Pressure.h" #include "ROPump.h" #include "TaskGeneral.h" @@ -35,13 +35,14 @@ // ********** private definitions ********** -#define PERMEATE_FLUSH_MAX_TIMEOUT ( 600 * MS_PER_SECOND ) ///< Max override timeout for 10 minutes +#define PERMEATE_FLUSH_MAX_TIMEOUT ( 10 * SEC_PER_MIN * MS_PER_SECOND ) ///< Max override timeout for 10 minutes #define PERMEATE_FLUSH_DATA_PUBLISH_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the gen water mode data published. -#define PERMEATE_FLUSH_TIMEOUT ( 120 * MS_PER_SECOND ) ///< Permeate flush timer (in ms) -#define PERMEATE_FLUSH_ALARM_TIMEOUT ( 180 * MS_PER_SECOND ) ///< Permeate flush alarm timer (in ms) +#define PERMEATE_FLUSH_TIMEOUT ( 2 * SEC_PER_MIN * MS_PER_SECOND ) ///< Permeate flush timer (in ms) timeout for 2 minutes +#define PERMEATE_FLUSH_ALARM_TIMEOUT ( 5 * SEC_PER_MIN * MS_PER_SECOND ) ///< Permeate flush alarm timer (in ms) timeout for 5 minutes #define PERMEATE_FLUSH_RO_PUMP_TGT_ML 700 ///< Pressure target in ml/min for the RO pump during permeate flush. #define PERMEATE_FLUSH_BOOST_PUMP_TGT_PSI 25 ///< Pressure target in PSI for the boost pump during permeate flush. #define PERMEATE_FLUSH_CONDUCTIVITY_THRESHOLD 200.0F ///< Conductivity alarm threshold for permeate flush. +#define MIN_BOOST_PUMP_DUTY_CYCLE_PCT 0.5F ///< Minimum duty cycle value for boost pump during open loop control // ********** private data ********** @@ -54,6 +55,7 @@ static U32 permeateFlushAlarmTimer; static BOOL pendingStartPermeateFlushRequest; ///< signal to start flushing. static BOOL isFlushComplete; ///< Permeate Flush complete BOOL +static BOOL isTankFilled; ///< Permeate tank filled in permeate flush state // ********** private function prototypes ********** @@ -92,6 +94,7 @@ permeateFlushAlarmTimer = 0; isFlushComplete = FALSE; pendingStartPermeateFlushRequest = FALSE; + isTankFilled = FALSE; } /*********************************************************************//** @@ -141,25 +144,51 @@ static FP_PERM_FLUSH_STATE_T handlePermeateFlushProgressState( void ) { FP_PERM_FLUSH_STATE_T state = PERM_FLUSH_IN_PROGRESS; + LEVEL_STATE_T level = getLevelStatus( P25_LEVL ); // if ( TRUE == 1 ))// TODO Alarm and Stop State Rework // { // state = PERM_FLUSH_PAUSED; // } - if( TRUE == didTimeout( permeateFlushTimer, getPermeateFlushTimeout() ) ) + // Manual control of Permeate tank while in Permeate Flush + // to prevent overfill. + if ( LEVEL_STATE_HIGH == level ) { + setValveState( M4_VALV, VALVE_STATE_CLOSED ); + if ( TRUE == isBoostPumpInstalled() ) + { + // TODO update the default min duty cycle value after testing + F32 currentDutyCyclePct = getCurrentBoostPumpDutyCyclePCT() > MIN_BOOST_PUMP_DUTY_CYCLE_PCT ? getCurrentBoostPumpDutyCyclePCT(): MIN_BOOST_PUMP_DUTY_CYCLE_PCT; + + setBoostPumpTargetDutyCycle( currentDutyCyclePct ); + isTankFilled = TRUE; + } + } + else if ( LEVEL_STATE_LOW == level ) + { + setValveState( M4_VALV, VALVE_STATE_OPEN ); + // set boost pump to closed loop when M4 closed. Added Tank fill check to avoid reset during initial transition + if ( ( TRUE == isBoostPumpInstalled() ) && ( TRUE == isTankFilled ) ) + { + setBoostPumpTargetPressure( PERMEATE_FLUSH_BOOST_PUMP_TGT_PSI ); + isTankFilled = FALSE; + } + } + + if ( TRUE == didTimeout( permeateFlushTimer, getPermeateFlushTimeout() ) ) + { F32 p18conductivity = getFilteredConductivity( P18_COND ); - if( PERMEATE_FLUSH_CONDUCTIVITY_THRESHOLD > p18conductivity ) + if ( ( PERMEATE_FLUSH_CONDUCTIVITY_THRESHOLD > p18conductivity ) && ( LEVEL_STATE_HIGH == level ) ) { isFlushComplete = TRUE; state = PERM_FLUSH_PAUSED; } - // If conductivity is not in range, continue to monitor until timeout + // If conductivity is not in range, continue to monitor until timeout, TODO if conductivity fluctuates for another 3 minutes else { - if( TRUE == didTimeout( permeateFlushAlarmTimer, getPermeateFlushAlarmTimeout() ) ) + if ( TRUE == didTimeout( permeateFlushAlarmTimer, getPermeateFlushAlarmTimeout() ) ) { SET_ALARM_WITH_2_U32_DATA( ALARM_ID_FP_PERMEATE_FLUSH_CONDUCTIVITY_TIMEOUT, PERMEATE_FLUSH_CONDUCTIVITY_THRESHOLD, p18conductivity) state = PERM_FLUSH_PAUSED; @@ -215,7 +244,6 @@ setValveState( P34_VALV, VALVE_STATE_CLOSED ); setValveState( P37_VALV, VALVE_STATE_CLOSED ); setValveState( P39_VALV, VALVE_STATE_OPEN ); - startPermeateTankControl(); if ( TRUE == isBoostPumpInstalled() ) { setBoostPumpTargetPressure( PERMEATE_FLUSH_BOOST_PUMP_TGT_PSI ); @@ -239,7 +267,6 @@ setValveState( P34_VALV, VALVE_STATE_CLOSED ); setValveState( P37_VALV, VALVE_STATE_CLOSED ); setValveState( P39_VALV, VALVE_STATE_CLOSED ); - if ( TRUE == isBoostPumpInstalled() ) { signalBoostPumpHardStop();