Index: firmware/App/Modes/FPModes/ModeGenPermeate.c =================================================================== diff -u -r9b06dafd96aca26795e2aeb05c21a5824b3db97a -r846073b88a25474464d43b4c0e8f300b52021f96 --- firmware/App/Modes/FPModes/ModeGenPermeate.c (.../ModeGenPermeate.c) (revision 9b06dafd96aca26795e2aeb05c21a5824b3db97a) +++ firmware/App/Modes/FPModes/ModeGenPermeate.c (.../ModeGenPermeate.c) (revision 846073b88a25474464d43b4c0e8f300b52021f96) @@ -29,6 +29,7 @@ #include "PIControllers.h" #include "ROPump.h" #include "TaskGeneral.h" +#include "TDInterface.h" #include "Timers.h" #include "Valves.h" #include "WaterQualityMonitor.h" @@ -46,6 +47,7 @@ #define PUMP_REST_TIMEOUT_MS ( 3 * MS_PER_SECOND ) ///< Duraion for open loop control at the start of tank fill/full state ( in ms ) #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 MIN_RO_PUMP_DUTY_CYCLE 0.5 ///< Minimum RO pump duty cycle to start in fill/full state #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 ) @@ -248,14 +250,11 @@ *************************************************************************/ static F32 getTankFullAlarmTimeout( void ) { - F32 expectedDeprimeTime = 0.0F; - F32 expectedTankFullTime = 0.0F; - F32 ddConsumptionRate = getTDDialysateFlowrate() + RINSE_PUMP_TARGET_FLOW; + F32 ddConsumptionRate = getTDDialysateFlowrate() + RINSE_PUMP_TARGET_FLOW; + F32 expectedTankFullTime = ( ( PERMEATE_TANK_HIGH_LEVEL_VOL_ML - PERMEATE_TANK_LOW_LEVEL_VOL_ML ) / ddConsumptionRate ) * SEC_PER_MIN; + F32 expectedDeprimeTime = ( ( PERMEATE_TANK_LOW_LEVEL_VOL_ML - PERMEATE_TANK_EMPTY_LEVEL_VOL_ML ) / ddConsumptionRate ) * SEC_PER_MIN; + tankFullAlarmTimeout = expectedTankFullTime + expectedDeprimeTime; - 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; } @@ -268,14 +267,11 @@ *************************************************************************/ static F32 getTankFillAlarmTimeout( void ) { - F32 expectedOverfillTime = 0.0F; - F32 expectedTankFillTime = 0.0F; - F32 ddConsumptionRate = getTDDialysateFlowrate() + RINSE_PUMP_TARGET_FLOW; + F32 ddConsumptionRate = getTDDialysateFlowrate() + RINSE_PUMP_TARGET_FLOW; + F32 expectedTankFillTime = ( ( PERMEATE_TANK_HIGH_LEVEL_VOL_ML - PERMEATE_TANK_LOW_LEVEL_VOL_ML ) / ddConsumptionRate ) * SEC_PER_MIN; + F32 expectedOverfillTime = ( ( PERMEATE_TANK_FULL_LEVEL_VOL_ML - PERMEATE_TANK_HIGH_LEVEL_VOL_ML ) / ddConsumptionRate ) * SEC_PER_MIN; + tankFillAlarmTimeout = ( expectedTankFillTime + ( expectedOverfillTime / 2 ) ); - 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; } @@ -297,6 +293,8 @@ { case FP_GENP_TANK_FILL_STATE: initDutyCycle = isFillAvgValid ? prevFillAvgDutyCycle : getCurrentROPumpDutyCyclePCT(); + // set the duty cycle to minimum of 0.5 if the value is zero + initDutyCycle = initDutyCycle == 0.0F ? MIN_RO_PUMP_DUTY_CYCLE : initDutyCycle; setROPumpTargetDutyCycle( initDutyCycle, TRUE ); timeInState = getMSTimerCount(); tankFillAlarmTimer = getMSTimerCount(); @@ -308,6 +306,8 @@ case FP_GENP_TANK_FULL_STATE: initDutyCycle = isFullAvgValid ? prevFullAvgDutyCycle : getCurrentROPumpDutyCyclePCT(); + // set the duty cycle to minimum of 0.5 if the value is zero + initDutyCycle = initDutyCycle == 0.0F ? MIN_RO_PUMP_DUTY_CYCLE : initDutyCycle; setROPumpTargetDutyCycle( initDutyCycle, TRUE ); timeInState = getMSTimerCount(); tankFullAlarmTimer = getMSTimerCount();