Index: firmware/App/Modes/FPModes/ModeGenPermeate.c =================================================================== diff -u -r2475e55c224cbd841d61b76f1618451efe6be1f5 -r61b54ff1d0ff5120a8f3654ff1acf4628f442ffd --- firmware/App/Modes/FPModes/ModeGenPermeate.c (.../ModeGenPermeate.c) (revision 2475e55c224cbd841d61b76f1618451efe6be1f5) +++ firmware/App/Modes/FPModes/ModeGenPermeate.c (.../ModeGenPermeate.c) (revision 61b54ff1d0ff5120a8f3654ff1acf4628f442ffd) @@ -47,6 +47,11 @@ #define RO_REJECTION_WAIT_TIME_MS ( 8 * MS_PER_SECOND ) ///< RO rejection alarm wait time. 5 seconds for RR to stabilize and 3 seconds for calculating rolling average ( in ms ) #define MIN_SAMPLES_NEEDED_FOR_DUTY_CYCLE_AVG 10 ///< Minimum number for samples needed for calculating the average duty cycle #define PERMEATE_FLOW_OUT_OF_RANGE_TIMEOUT_MS ( 12 * MS_PER_SECOND ) ///< Permeate flow low tolerance out of range timeout +#define PERMEATE_TANK_EMPTY_LEVEL_VOL_ML 0 ///< Permeate tank volume in empty level ( in ml ) +#define PERMEATE_TANK_LOW_LEVEL_VOL_ML 957 ///< Permeate tank volume in low level ( in ml ) +#define PERMEATE_TANK_HIGH_LEVEL_VOL_ML 1345 ///< Permeate tank volume in high level ( in ml ) +#define PERMEATE_TANK_FULL_LEVEL_VOL_ML 1532 ///< Permeate tank volume in full level ( in ml ) +#define RINSE_PUMP_TARGET_FLOW 228.89 ///< Rinse pump rate // ********** private data ********** @@ -63,6 +68,10 @@ static BOOL isFullAvgValid; ///< Flag to check if the average full duty cycle value is valid or not. 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 +static U32 tankFullAlarmTimer; ///< Time stamp to track alarm timeout during tank full. +static U32 tankFillAlarmTimer; ///< Time stamp to track alarm timeout during tank fill. +static F32 tankFullAlarmTimeout; ///< Permeate tank full alarm timeout +static F32 tankFillAlarmTimeout; ///< Permeate tank fill alarm timeout // ********** private function prototypes ********** @@ -73,6 +82,8 @@ static U32 getGenPermeateDataPublishInterval( void ); static void updateDutyCycleAvg( FP_GENP_MODE_STATE_T state ); static void calculateDutyCycleAvg( FP_GENP_MODE_STATE_T state ); +static F32 getTankFullAlarmTimeout( void ); +static F32 getTankFillAlarmTimeout( void ); /*********************************************************************//** * @brief @@ -99,6 +110,10 @@ isFullAvgValid = FALSE; timeInState = 0; stateTransitioned = FALSE; + tankFullAlarmTimer = 0; + tankFillAlarmTimer = 0; + tankFullAlarmTimeout = 0.0F; + tankFillAlarmTimeout = 0.0F; } /*********************************************************************//** @@ -224,6 +239,46 @@ /*********************************************************************//** * @brief + * The getTankFullAlarmTimeout function returns the tank full alarm timeout + * @details \b Inputs: none + * @details \b Outputs: tankFullAlarmTimeout + * @return the alarm timeout for tank full + *************************************************************************/ +static F32 getTankFullAlarmTimeout( void ) +{ + F32 expectedDeprimeTime = 0.0F; + F32 expectedTankFullTime = 0.0F; + F32 ddConsumptionRate = getTDDialysateFlowrate() + RINSE_PUMP_TARGET_FLOW; + + expectedTankFullTime = ( ( PERMEATE_TANK_HIGH_LEVEL_VOL_ML - PERMEATE_TANK_LOW_LEVEL_VOL_ML ) / ddConsumptionRate ) * SEC_PER_MIN; + expectedDeprimeTime = ( ( PERMEATE_TANK_LOW_LEVEL_VOL_ML - PERMEATE_TANK_EMPTY_LEVEL_VOL_ML ) / ddConsumptionRate ) * SEC_PER_MIN; + tankFullAlarmTimeout = expectedTankFullTime + expectedDeprimeTime; + + return tankFullAlarmTimeout; +} + +/*********************************************************************//** + * @brief + * The getTankFillAlarmTimeout function returns the tank fill alarm timeout + * @details \b Inputs: none + * @details \b Outputs: tankFillAlarmTimeout + * @return the alarm timeout for tank fill + *************************************************************************/ +static F32 getTankFillAlarmTimeout( void ) +{ + F32 expectedOverfillTime = 0.0F; + F32 expectedTankFillTime = 0.0F; + F32 ddConsumptionRate = getTDDialysateFlowrate() + RINSE_PUMP_TARGET_FLOW; + + expectedTankFillTime = ( ( PERMEATE_TANK_HIGH_LEVEL_VOL_ML - PERMEATE_TANK_LOW_LEVEL_VOL_ML ) / ddConsumptionRate ) * SEC_PER_MIN; + expectedOverfillTime = ( ( PERMEATE_TANK_FULL_LEVEL_VOL_ML - PERMEATE_TANK_HIGH_LEVEL_VOL_ML ) / ddConsumptionRate ) * SEC_PER_MIN; + tankFillAlarmTimeout = ( expectedTankFillTime + ( expectedOverfillTime / 2 ) ); + + return tankFillAlarmTimeout; +} + +/*********************************************************************//** + * @brief * The setModeGenPTransition function sets the actuators and variables * for the state transition in generate permeate mode. * @details Inputs: none @@ -242,6 +297,7 @@ initDutyCycle = isFillAvgValid ? prevFillAvgDutyCycle : getCurrentROPumpDutyCyclePCT(); setROPumpTargetDutyCycle( initDutyCycle, TRUE ); timeInState = getMSTimerCount(); + tankFillAlarmTimer = getMSTimerCount(); if ( TRUE == isBoostPumpInstalled() ) { setBoostPumpTargetPressure( GEN_PERMEATE_BOOST_PUMP_TGT_PSI ); @@ -252,6 +308,7 @@ initDutyCycle = isFullAvgValid ? prevFullAvgDutyCycle : getCurrentROPumpDutyCyclePCT(); setROPumpTargetDutyCycle( initDutyCycle, TRUE ); timeInState = getMSTimerCount(); + tankFullAlarmTimer = getMSTimerCount(); if ( TRUE == isBoostPumpInstalled() ) { F32 currentDutyCyclePct = getCurrentBoostPumpDutyCyclePCT(); @@ -278,6 +335,10 @@ FP_GENP_MODE_STATE_T state = FP_GENP_TANK_FILL_STATE; PERMEATE_TANK_STATE_T permemeateTankState = getPermeateTankState(); + if ( TRUE == didTimeout( tankFillAlarmTimer, getTankFillAlarmTimeout() ) ) + { + SET_ALARM_WITH_1_U32_DATA( ALARM_ID_FP_GEN_PERMEATE_TANK_FILL_TIMEOUT, permemeateTankState ) + } // Wait for set timeout before transition to closed loop control if ( TRUE == didTimeout( timeInState, PUMP_REST_TIMEOUT_MS ) && stateTransitioned == TRUE ) { @@ -309,6 +370,11 @@ FP_GENP_MODE_STATE_T state = FP_GENP_TANK_FULL_STATE; PERMEATE_TANK_STATE_T permemeateTankState = getPermeateTankState(); + if ( TRUE == didTimeout( tankFullAlarmTimer, getTankFullAlarmTimeout() ) ) + { + SET_ALARM_WITH_1_U32_DATA( ALARM_ID_FP_GEN_PERMEATE_TANK_FULL_TIMEOUT, permemeateTankState ) + } + // Wait for set timeout before transition to closed loop control if ( TRUE == didTimeout( timeInState, PUMP_REST_TIMEOUT_MS ) && stateTransitioned == TRUE ) {