Index: firmware/App/Modes/ModeGenPermeate.c =================================================================== diff -u -rf79d3737907fd08293d56f60f9f439ac68c81855 -r6dd382e3988fac2f9ee041b4738d67305e17a6a2 --- firmware/App/Modes/ModeGenPermeate.c (.../ModeGenPermeate.c) (revision f79d3737907fd08293d56f60f9f439ac68c81855) +++ firmware/App/Modes/ModeGenPermeate.c (.../ModeGenPermeate.c) (revision 6dd382e3988fac2f9ee041b4738d67305e17a6a2) @@ -24,6 +24,7 @@ #include "Messaging.h" #include "ModeGenPermeate.h" #include "ModePreGenPermeate.h" +#include "PermeateTank.h" #include "ROPump.h" #include "TaskGeneral.h" #include "Timers.h" @@ -37,21 +38,16 @@ // ********** private definitions ********** #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_TANK_FULL_SWITCH_MS ( 6 * MS_PER_SECOND ) ///< state switch timeout (in ms) -#define GEN_PERMEATE_TANK_FULL_TIMEOUT_MS ( 60 * MS_PER_SECOND ) -#define GEN_PERMEATE_BOOST_PUMP_TGT_PSI 25 -#define GEN_PERMEATE_PWM_DEFAULT 0.22F +#define GEN_PERMEATE_BOOST_PUMP_TGT_PSI 25 ///< Pressure target in PSI for the boost pump during generate permeate mode. +#define GEN_PERMEATE_RO_PUMP_TGT_ML 700 ///< Flow target in ml/min for the ro pump during generate permeate mode. + // ********** private data ********** static FP_GENP_MODE_STATE_T genPermeateState; ///< Currently active generate Permeate state. static U32 genPermeateDataPublicationTimerCounter; ///< Used to schedule generate Permeate data publication to CAN bus. static OVERRIDE_U32_T genPermeateDataPublishInterval; ///< Generate permeate mode data publish interval. -static U32 tankFullDelayTime; ///< Time stamp to track delay before valve switch. -static BOOL pendingStartGenRequest; ///< Flag indicating DD has requested FP start the generate permeate. -static F32 genPermeateRODutyCycle; -static F32 genPermeateBoostDutyCycle; -static U32 tankFullAlarmTimeout; +static BOOL pendingStartGenRequest; ///< Flag indicating DD has requested FP start the generate permeate. // ********** private function prototypes ********** @@ -76,11 +72,7 @@ genPermeateDataPublishInterval.ovInitData = 0; genPermeateDataPublishInterval.override = OVERRIDE_RESET; genPermeateDataPublicationTimerCounter = 0; - tankFullDelayTime = 0; - tankFullAlarmTimeout = 0; pendingStartGenRequest = 0; - genPermeateRODutyCycle = 0.0F; - genPermeateBoostDutyCycle = 0.0F; } /*********************************************************************//** @@ -96,18 +88,8 @@ initGenPermeateMode(); setCurrentSubState( genPermeateState ); setModeGenPTransition( genPermeateState ); - - // Setting RO pump pwm at the start instead of - // each transition to allow testing of different target control - // while in Gen Permeate - if ( 0.0F == getGenPermeateRODutyCycle() ) // we skipped verify water via dialin - { - setROPumpTargetDutyCycle( GEN_PERMEATE_PWM_DEFAULT ); - } - else - { - setROPumpTargetDutyCycle( getGenPermeateRODutyCycle() ); - } + startPermeateTankControl(); + setROPumpTargetFlowRateMLPM( GEN_PERMEATE_RO_PUMP_TGT_ML ); return genPermeateState; } @@ -166,41 +148,17 @@ switch( state ) { case FP_GENP_TANK_FILL_STATE: - setValveState( M4_VALV,VALVE_STATE_OPEN ); - setValveState( M7_VALV, VALVE_STATE_CLOSED ); - setValveState( P6_VALV, VALVE_STATE_CLOSED ); - setValveState( P11_VALV, VALVE_STATE_OPEN ); - setValveState( P33_VALV, VALVE_STATE_OPEN ); // TODO - Change valves to handle RO rejection config - setValveState( P34_VALV, VALVE_STATE_CLOSED ); // Current set to Medium recovery for alpha HW - setValveState( P37_VALV, VALVE_STATE_CLOSED ); - setValveState( P39_VALV, VALVE_STATE_OPEN ); - setValveState( P20_VALV, VALVE_STATE_CLOSED ); - setValveState( P43_VALV, VALVE_STATE_CLOSED ); - if ( TRUE == isBoostPumpInstalled() ) { setBoostPumpTargetPressure( GEN_PERMEATE_BOOST_PUMP_TGT_PSI ); } break; case FP_GENP_TANK_FULL_STATE: - setValveState( M4_VALV, VALVE_STATE_CLOSED ); - setValveState( M7_VALV, VALVE_STATE_CLOSED ); - setValveState( P6_VALV, VALVE_STATE_CLOSED ); - setValveState( P11_VALV, VALVE_STATE_CLOSED ); - setValveState( P33_VALV, VALVE_STATE_OPEN ); - setValveState( P34_VALV, VALVE_STATE_CLOSED ); - setValveState( P37_VALV, VALVE_STATE_CLOSED ); - setValveState( P39_VALV, VALVE_STATE_OPEN ); - setValveState( P20_VALV, VALVE_STATE_CLOSED ); - setValveState( P43_VALV, VALVE_STATE_CLOSED ); - if ( TRUE == isBoostPumpInstalled() ) { signalBoostPumpHardStop(); } - tankFullDelayTime = getMSTimerCount(); - tankFullAlarmTimeout = getMSTimerCount(); break; default: @@ -219,25 +177,13 @@ static FP_GENP_MODE_STATE_T handleGenPTankFillState( void ) { FP_GENP_MODE_STATE_T state = FP_GENP_TANK_FILL_STATE; - LEVEL_STATE_T level = getLevelStatus(); + PERMEATE_TANK_STATE_T permemeateTankState = getPermeateTankState(); - if ( LEVEL_STATE_HIGH == level ) + if ( permemeateTankState == PERMEATE_TANK_FULL_STATE ) { state = FP_GENP_TANK_FULL_STATE; - // save boost pump - if ( TRUE == isBoostPumpInstalled() ) - { - setGenPermeateBoostDutyCycle( getCurrentBoostPumpDutyCyclePCT() ); - SEND_EVENT_WITH_2_U32_DATA( FP_EVENT_GENP_BOOST_SET_PWM, getCurrentBoostPumpDutyCyclePCT(), getFluidPumpReadPWMDutyCycle( P40_PUMP ) ) - } } - else if ( level <= LEVEL_STATE_MEDIUM ) - { - // expected state. No action required. - // If level is low we still want to fill. - } - return state; } @@ -251,16 +197,10 @@ static FP_GENP_MODE_STATE_T handleGenPTankFullState( void ) { FP_GENP_MODE_STATE_T state = FP_GENP_TANK_FULL_STATE; - LEVEL_STATE_T level = getLevelStatus(); + PERMEATE_TANK_STATE_T permemeateTankState = getPermeateTankState(); - if ( TRUE == didTimeout( tankFullAlarmTimeout, GEN_PERMEATE_TANK_FULL_TIMEOUT_MS ) ) + if ( permemeateTankState == PERMEATE_TANK_FILL_STATE ) { - SET_ALARM_WITH_1_U32_DATA( ALARM_ID_FP_GEN_PERMEATE_TANK_FULL_TIMEOUT, level ) - } - - if ( ( ( level == LEVEL_STATE_MEDIUM ) && ( TRUE == didTimeout( tankFullDelayTime, GEN_PERMEATE_TANK_FULL_SWITCH_MS ) ) ) || - ( level == LEVEL_STATE_LOW ) ) - { state = FP_GENP_TANK_FILL_STATE; } @@ -269,58 +209,6 @@ /*********************************************************************//** * @brief - * The getGenPermeateBoostDutyCycle function returns the current Boost pump pwm setting - * in gen permeate mode. - * @details \b Inputs: genPermeateBoostDutyCycle - * @details \b Outputs: genPermeateBoostDutyCycle - * @return the current pwm setting for the RO Pump - *************************************************************************/ -F32 getGenPermeateBoostDutyCycle( void ) -{ - return genPermeateBoostDutyCycle; -} - -/*********************************************************************//** - * @brief - * The setGenPermeateBoostDutyCycle function sets the Boost pump pwm in gen permeate - * mode - * @details \b Inputs: none - * @details \b Outputs: genPermeateBoostDutyCycle - * @return none - *************************************************************************/ -void setGenPermeateBoostDutyCycle( F32 duty) -{ - genPermeateBoostDutyCycle = duty; -} - -/*********************************************************************//** - * @brief - * The getGenPermeateRODutyCycle function returns the current pwm setting - * for the RO pump in gen permeate mode. - * @details \b Inputs: genPermeateRODutyCycle - * @details \b Outputs: genPermeateRODutyCycle - * @return the current pwm setting for the RO Pump - *************************************************************************/ -F32 getGenPermeateRODutyCycle( void ) -{ - return genPermeateRODutyCycle; -} - -/*********************************************************************//** - * @brief - * The setGenPermeateRODutyCycle function sets the RO PWM pump in gen permeate - * mode - * @details \b Inputs: none - * @details \b Outputs: genPermeateRODutyCycle - * @return none - *************************************************************************/ -void setGenPermeateRODutyCycle( F32 duty) -{ - genPermeateRODutyCycle = duty; -} - -/*********************************************************************//** - * @brief * The getCurrentGenPermeateState function returns the current state of the * gen permeate mode. * @details \b Inputs: genPermeateState