Index: firmware/App/Modes/ModeGenPermeate.c =================================================================== diff -u -r5ad3da2cfc5014e6beebf3b67ef394a3a65426a0 -r764e0e8c7a889f72a9b6bdced9ef08a09d72b36e --- firmware/App/Modes/ModeGenPermeate.c (.../ModeGenPermeate.c) (revision 5ad3da2cfc5014e6beebf3b67ef394a3a65426a0) +++ firmware/App/Modes/ModeGenPermeate.c (.../ModeGenPermeate.c) (revision 764e0e8c7a889f72a9b6bdced9ef08a09d72b36e) @@ -16,6 +16,7 @@ ***************************************************************************/ #include "BoostPump.h" +#include "Conductivity.h" #include "DDInterface.h" #include "FPModeStandby.h" #include "FPOperationModes.h" @@ -41,7 +42,9 @@ #define PRE_GEN_PERMEATE_DATA_PUBLISH_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the gen permeate mode data published. #define GEN_PERMEATE_BOOST_PUMP_TGT_PSI 25.0F ///< Pressure target in PSI for the boost pump during generate permeate mode. #define GEN_PERMEATE_RO_PUMP_TGT_ML 750 ///< Flow target in ml/min for the ro pump during generate permeate mode. -#define PUMP_REST_TIMEOUT_MS ( 3 * MS_PER_SECOND ) ///< Verify Water timer ( in ms ) +#define PUMP_REST_TIMEOUT_MS ( 3 * MS_PER_SECOND ) ///< Verify Water timer ( in ms ) +#define RO_REJECTION_WAIT_TIME_MS ( 8 * MS_PER_SECOND ) ///< Verify Water timer ( in ms ) +#define MIN_RO_REJECTION_RATIO_PCT 90.0F ///< Minimum RO rejection ration in percentage // ********** private data ********** @@ -56,8 +59,8 @@ static U32 fullDutyCount; ///< Sample counts for one full cycle. static F32 prevFullAvgDutyCycle; ///< Average vale of duty cycle during previous full state. static BOOL isFullAvgValid; ///< Flag to check if the average full duty cycle value is valid or not. -static U32 waitTimeAfterReset; ///< Time to wait after reset before starting close loop control (temporary) -static BOOL stateTransitioned; ///< +static U32 timeInState; ///< Time to wait after reset before starting close loop control (temporary) +static BOOL stateTransitioned; ///< Flag to check if permeate tank state transitioned // ********** private function prototypes ********** @@ -92,7 +95,7 @@ fullDutyCount = 0; prevFullAvgDutyCycle = 0.0F; isFullAvgValid = FALSE; - waitTimeAfterReset = 0; + timeInState = 0; stateTransitioned = FALSE; } @@ -176,9 +179,9 @@ switch( state ) { case FP_GENP_TANK_FILL_STATE: - initDutyCycle = isFillAvgValid ? prevFillAvgDutyCycle : 0.70F; + initDutyCycle = isFillAvgValid ? prevFillAvgDutyCycle : getCurrentROPumpDutyCyclePCT(); setROPumpTargetDutyCycle( initDutyCycle, TRUE ); - waitTimeAfterReset = getMSTimerCount(); + timeInState = getMSTimerCount(); if ( TRUE == isBoostPumpInstalled() ) { setBoostPumpTargetPressure( GEN_PERMEATE_BOOST_PUMP_TGT_PSI ); @@ -188,7 +191,7 @@ case FP_GENP_TANK_FULL_STATE: initDutyCycle = isFullAvgValid ? prevFullAvgDutyCycle : getCurrentROPumpDutyCyclePCT(); setROPumpTargetDutyCycle( initDutyCycle, TRUE ); - waitTimeAfterReset = getMSTimerCount(); + timeInState = getMSTimerCount(); if ( TRUE == isBoostPumpInstalled() ) { signalBoostPumpHardStop(); @@ -212,13 +215,23 @@ { FP_GENP_MODE_STATE_T state = FP_GENP_TANK_FILL_STATE; PERMEATE_TANK_STATE_T permemeateTankState = getPermeateTankState(); - F32 initDutyCycle = isFillAvgValid ? prevFillAvgDutyCycle : 0.70F; // TODO - what value to start in initial cycle - if ( TRUE == didTimeout( waitTimeAfterReset, PUMP_REST_TIMEOUT_MS ) && stateTransitioned == TRUE ) + F32 initDutyCycle = isFillAvgValid ? prevFillAvgDutyCycle : getCurrentROPumpDutyCyclePCT(); + if ( TRUE == didTimeout( timeInState, PUMP_REST_TIMEOUT_MS ) && stateTransitioned == TRUE ) { stateTransitioned = FALSE; resetPIController( PI_CONTROLLER_ID_RO_PUMP_FLOW, initDutyCycle, 0.0F ); setROPumpTargetFlowRateMLPM( GEN_PERMEATE_RO_PUMP_TGT_ML, TRUE ); } + // Wait for RO rejection to stabilize after transition from full to fill + RO Rejection moving average duration + if ( TRUE == didTimeout( timeInState, RO_REJECTION_WAIT_TIME_MS ) ) + { + F32 avgRORR = getRORRAverage(); + // Alarm if the filtered average is less than allowed RO rejection limit + if ( avgRORR < MIN_RO_REJECTION_RATIO_PCT ) + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_FP_REJECTION_RATIO_LOW_RANGE, avgRORR, MIN_RO_REJECTION_RATIO_PCT) + } + } if ( permemeateTankState == PERMEATE_TANK_FULL_STATE ) { state = FP_GENP_TANK_FULL_STATE; @@ -238,7 +251,7 @@ { FP_GENP_MODE_STATE_T state = FP_GENP_TANK_FULL_STATE; F32 initDutyCycle = isFullAvgValid ? prevFullAvgDutyCycle : getCurrentROPumpDutyCyclePCT(); - if ( TRUE == didTimeout( waitTimeAfterReset, PUMP_REST_TIMEOUT_MS ) && stateTransitioned == TRUE ) + if ( TRUE == didTimeout( timeInState, PUMP_REST_TIMEOUT_MS ) && stateTransitioned == TRUE ) { stateTransitioned = FALSE; resetPIController( PI_CONTROLLER_ID_RO_PUMP_FLOW, initDutyCycle, 0.0F );