Index: firmware/App/Modes/ModeHeatDisinfect.c =================================================================== diff -u -r9ce06772b2f651c57144327e6cbf886e2bc22dee -r9047c6e1db73ac20849a63b8cbec33041c28b0d5 --- firmware/App/Modes/ModeHeatDisinfect.c (.../ModeHeatDisinfect.c) (revision 9ce06772b2f651c57144327e6cbf886e2bc22dee) +++ firmware/App/Modes/ModeHeatDisinfect.c (.../ModeHeatDisinfect.c) (revision 9047c6e1db73ac20849a63b8cbec33041c28b0d5) @@ -54,19 +54,19 @@ #define DRAIN_WEIGH_UNCHANGE_TIMEOUT ( 2 * MS_PER_SECOND ) ///< Time period of unchanged weight during draining before timeout. // Flush drain path state defines -#define FLUSH_DRAIN_WAIT_TIME_MS ( 60 * MS_PER_SECOND ) ///< Flush Drain path wait time in milliseconds. +#define FLUSH_DRAIN_WAIT_TIME_MS ( 1 * MS_PER_SECOND ) ///< Flush Drain path wait time in milliseconds. TODo original time was 60 seconds #define MIN_INLET_TEMPERATURE_C 25.0 ///< Minimum water inlet temperature in C. #define MIN_INLET_CONDUCTIVITY_US_PER_CM 0.0 ///< Minimum water inlet conductivity in uS/cm #define MAX_INLET_CONDUCTIVITY_US_PER_CM 2000.0 ///< Maximum water inlet conductivity in us/cm // Flush circulation path state defines -#define RO_PUMP_TARGET_FLUSH_FILL_FLOW_RATE_LPM 0.8 ///< RO pump target flow rate during flush/fill in L/min. +#define RO_PUMP_TARGET_FLUSH_FILL_FLOW_RATE_LPM 0.6 ///< RO pump target flow rate during flush/fill in L/min. TODO original flow was 0.8 #define MAX_RO_PUMP_FLUSH_FILL_PRESSURE_PSI 130 ///< Maximum RO pump pressure during flush/fill states in psi. -#define FLUSH_CICRCULATION_WAIT_TIME_MS ( 30 * MS_PER_SECOND ) ///< Flush/rinse circulation path wait time in milliseconds. +#define FLUSH_CICRCULATION_WAIT_TIME_MS ( 30 * MS_PER_SECOND ) ///< Flush/rinse circulation path wait time in milliseconds. TODO original time was 30 seconds #define MAX_FLUSH_CIRC_TEMP_SENSOR_DIFF_C 3.0 ///< Maximum flush circulation temperature difference tolerance in C. // Flush and drain R1 and R2 -#define RSRVRS_FULL_VOL_ML 2200.0 ///< Reservoirs 1 & 2 full volume in mL. +#define RSRVRS_FULL_VOL_ML 1900.0 ///< Reservoirs 1 & 2 full volume in mL. #define RSRVRS_PARTIAL_FILL_VOL_ML 500.0 ///< Reservoirs 1 & 2 partial volume in mL. #define RSRVRS_FILL_UP_TIMEOUT_MS ( 5 * 60 * MS_PER_SECOND ) ///< Reservoirs 1 & 2 full fill up timeout in ms. #define RSRVRS_500ML_FILL_UP_TIMEOUT_MS ( 2 * 60 * MS_PER_SECOND ) ///< Reservoirs 1 & 2 partial fill up timeout in ms. @@ -88,14 +88,6 @@ // Rinse R1 to R2 #define ROF_MIN_LOW_PRESSURE_TEMPERATURE_C 45.0 ///< RO filter minimum temperature that the pressure must be no more than 30psi in C. -/// Name of reservoirs -typedef enum rsrvrs -{ - R1 = 0, ///< Reservoir 1 - R2, ///< Reservoir 2 - NUM_OF_RSRVRS ///< Number of reservoirs -} RSRVRS_T; //TODO remove - /// TODO remove? typedef enum rsvrs_status { @@ -151,7 +143,7 @@ static void resetActuators( void ); static void setModeToFailed( DG_HEAT_DISINFECT_STATE_T state ); -static BOOL isRsrvrFull( RSRVRS_T r, F32 targetVol, U32 timeout, DG_HEAT_DISINFECT_STATE_T state ); +static BOOL isRsrvrFull( DG_RESERVOIR_ID_T r, F32 targetVol, U32 timeout, DG_HEAT_DISINFECT_STATE_T state ); static BOOL isRsrvrEmpty( DG_RESERVOIR_ID_T r, U32 drainSteadyStateTimeout, U32 timeout, DG_HEAT_DISINFECT_STATE_T failedState ); static BOOL isStateHeatDisinfectComplete( DG_HEAT_DISINFECT_STATE_T state ); static void publishHeatDisinfectData( void ); @@ -364,7 +356,8 @@ { // Close VPi to prevent wasting water setValveState( VPI, VALVE_STATE_CLOSED ); - + // Request a tare for reservoir 1 + tareReservoir(); // Set the actuators to drain R1 setValveState( VRD, VALVE_STATE_R1_C_TO_NC ); setDrainPumpTargetRPM( DRAIN_PUMP_TARGET_RPM ); @@ -408,6 +401,8 @@ else { // Set the actuators to drain R2. + // Request a tare for reservoir 2 + tareReservoir(); // NOTE: Drain pump is already on and VDr is already on drain state setValveState( VRD, VALVE_STATE_R2_C_TO_NO ); stateTimer = getMSTimerCount(); @@ -442,6 +437,7 @@ else { stateTrialCounter = 0; + signalDrainPumpHardStop(); setValveState( VPI, VALVE_STATE_OPEN ); stateTimer = getMSTimerCount(); state = DG_HEAT_DISINFECT_STATE_FLUSH_DRAIN; @@ -467,10 +463,10 @@ if ( didTimeout( stateTimer, FLUSH_DRAIN_WAIT_TIME_MS ) ) { // If the inlet temperature and conductivity are in range, move onto the next state - if ( getTemperatureValue( TEMPSENSORS_INLET_PRIMARY_HEATER ) > MIN_INLET_TEMPERATURE_C /*&& + if ( getTemperatureValue( TEMPSENSORS_INLET_PRIMARY_HEATER ) > 15 /*MIN_INLET_TEMPERATURE_C && TODO bring the code back getConductivityValue( CONDUCTIVITYSENSORS_CPI_SENSOR ) > MIN_INLET_CONDUCTIVITY_US_PER_CM*/ ) { - setValveState( VPD, VALVE_STATE_DRAIN_C_TO_NC ); + setValveState( VPD, VALVE_STATE_OPEN_C_TO_NO ); setROPumpTargetFlowRate( RO_PUMP_TARGET_FLUSH_FILL_FLOW_RATE_LPM, MAX_RO_PUMP_FLUSH_FILL_PRESSURE_PSI ); stateTimer = getMSTimerCount(); stateTrialCounter = 0; @@ -511,9 +507,9 @@ F32 TPoTemp = getTemperatureValue( TEMPSENSORS_OUTLET_PRIMARY_HEATER ); F32 TD1Temp = getTemperatureValue( TEMPSENSORS_CONDUCTIVITY_SENSOR_1 ); F32 TD2Temp = getTemperatureValue( TEMPSENSORS_CONDUCTIVITY_SENSOR_2 ); - F32 avgTemp = ( TPmTemp + TPoTemp + TD1Temp + TD2Temp ) / 4.0; + F32 avgTemp = ( /*TPmTemp +*/ TPoTemp + TD1Temp + TD2Temp ) / 3.0; //TODO add TPm once we have the sensor in change the average count to 4.0 - BOOL isTPmOut = fabs( TPmTemp - avgTemp ) > MAX_FLUSH_CIRC_TEMP_SENSOR_DIFF_C; + BOOL isTPmOut = FALSE; //fabs( TPmTemp - avgTemp ) > MAX_FLUSH_CIRC_TEMP_SENSOR_DIFF_C; TODO uncomment this when BOOL isTPoOut = fabs( TPoTemp - avgTemp ) > MAX_FLUSH_CIRC_TEMP_SENSOR_DIFF_C; BOOL isTD1Out = fabs( TD1Temp - avgTemp ) > MAX_FLUSH_CIRC_TEMP_SENSOR_DIFF_C; BOOL isTD2Out = fabs( TD2Temp - avgTemp ) > MAX_FLUSH_CIRC_TEMP_SENSOR_DIFF_C; @@ -568,17 +564,17 @@ *************************************************************************/ static DG_HEAT_DISINFECT_STATE_T handleHeatDisinfectFlushR1AndR2State( void ) { - DG_HEAT_DISINFECT_STATE_T state = DG_HEAT_DISINFECT_STATE_FLUSH_CIRCULATION; + DG_HEAT_DISINFECT_STATE_T state = DG_HEAT_DISINFECT_STATE_FLUSH_R1_AND_R2; // If R1 is not full, keep monitoring for R1 level and timeout - if ( FALSE == isR1Full ) + if ( isR1Full != TRUE ) { - isR1Full = isRsrvrFull( R1, RSRVRS_FULL_VOL_ML, RSRVRS_FILL_UP_TIMEOUT_MS, state ); + isR1Full = isRsrvrFull( DG_RESERVOIR_1, RSRVRS_FULL_VOL_ML, RSRVRS_FILL_UP_TIMEOUT_MS, state ); } // Once R1 is full, keep monitoring for R2 level and timeout if( isR1Full ) { - isR2Full = isRsrvrFull( R2, RSRVRS_PARTIAL_FILL_VOL_ML, RSRVRS_500ML_FILL_UP_TIMEOUT_MS, state ); + isR2Full = isRsrvrFull( DG_RESERVOIR_2, RSRVRS_PARTIAL_FILL_VOL_ML, RSRVRS_500ML_FILL_UP_TIMEOUT_MS, state ); // Once R2 is full (to 500mL in this case), transition to the next state if ( isR2Full ) @@ -590,6 +586,9 @@ setValveState( VRD, VALVE_STATE_R1_C_TO_NC ); setDrainPumpTargetRPM( DRAIN_PUMP_TARGET_RPM ); stateTimer = getMSTimerCount(); + // Set both reservoirs to full status to FALSE + isR2Full = FALSE; + isR1Full = FALSE; state = DG_HEAT_DISINFECT_STATE_FLUSH_R2_AND_DRAIN_R1; } } @@ -607,26 +606,24 @@ *************************************************************************/ static DG_HEAT_DISINFECT_STATE_T handleHeatDisinfectFlushR2AndDrainR1State( void ) { - DG_HEAT_DISINFECT_STATE_T state = DG_HEAT_DISINFECT_STATE_FLUSH_CIRCULATION; + DG_HEAT_DISINFECT_STATE_T state = DG_HEAT_DISINFECT_STATE_FLUSH_R2_AND_DRAIN_R1; // If reservoir 1 is empty, turn off the drain pump - if ( FALSE == isR1Full ) + if ( isRsrvrEmpty( DG_RESERVOIR_1, DRAIN_WEIGH_UNCHANGE_TIMEOUT, RSRVRS_INITIAL_DRAIN_TIME_OUT_MS, state ) ) { - isR1Full = isRsrvrEmpty( DG_RESERVOIR_1, DRAIN_WEIGH_UNCHANGE_TIMEOUT, RSRVRS_INITIAL_DRAIN_TIME_OUT_MS, state ); - // Done with draining R1 signalDrainPumpHardStop(); } // First reservoir 2 must be completely full - if ( FALSE == isR2Full ) + if ( isR2Full != TRUE ) { - isR2Full = isRsrvrFull( R2, RSRVRS_FULL_VOL_ML, RSRVRS_FILL_UP_TIMEOUT_MS, state ); + isR2Full = isRsrvrFull( DG_RESERVOIR_2, RSRVRS_FULL_VOL_ML, RSRVRS_FILL_UP_TIMEOUT_MS, state ); } // Once R2 is full, R1 must be partially full - else + if( isR2Full ) { - isR1Full = isRsrvrFull( R1, RSRVRS_PARTIAL_FILL_VOL_ML, RSRVRS_500ML_FILL_UP_TIMEOUT_MS, state ); + isR1Full = isRsrvrFull( DG_RESERVOIR_1, RSRVRS_PARTIAL_FILL_VOL_ML, RSRVRS_500ML_FILL_UP_TIMEOUT_MS, state ); // Once R1 is partially full, transition to the next state if ( isR1Full ) @@ -663,7 +660,7 @@ DG_HEAT_DISINFECT_STATE_T state = DG_HEAT_DISINFECT_STATE_FLUSH_DRAIN_R2; // If reservoir 2 is empty, set the drain valve to drain R1 - if (isRsrvrEmpty( DG_RESERVOIR_2, DRAIN_WEIGH_UNCHANGE_TIMEOUT, RSRVRS_INITIAL_DRAIN_TIME_OUT_MS, state ) ) + if ( isRsrvrEmpty( DG_RESERVOIR_2, DRAIN_WEIGH_UNCHANGE_TIMEOUT, RSRVRS_INITIAL_DRAIN_TIME_OUT_MS, state ) ) { setValveState( VRD, VALVE_STATE_R1_C_TO_NC ); // Start the timer for drain timeout @@ -689,10 +686,16 @@ // If reservoir 1 is empty, set the state to fill water state if ( isRsrvrEmpty( DG_RESERVOIR_1, DRAIN_WEIGH_UNCHANGE_TIMEOUT, RSRVRS_INITIAL_DRAIN_TIME_OUT_MS, state ) ) { + // Done with draining the reservoirs + signalDrainPumpHardStop(); + + // Prepare for filling the reservoirs and heating the water setValveState( VPI, VALVE_STATE_OPEN ); setValveState( VPD, VALVE_STATE_OPEN_C_TO_NO ); setValveState( VPO, VALVE_STATE_FILL_C_TO_NC ); + setValveState( VRO, VALVE_STATE_R1_C_TO_NO ); setValveState( VRI, VALVE_STATE_R2_C_TO_NC ); + setValveState( VRF, VALVE_STATE_R1_C_TO_NC ); // Turn on the RO pump setROPumpTargetFlowRate( RO_PUMP_TARGET_FLUSH_FILL_FLOW_RATE_LPM, MAX_RO_PUMP_FLUSH_FILL_PRESSURE_PSI ); @@ -722,14 +725,14 @@ DG_HEAT_DISINFECT_STATE_T state = DG_HEAT_DISINFECT_STATE_FILL_WITH_WATER; // First reservoir 1 must be full - if ( FALSE == isR1Full ) + if ( isRsrvrFull( DG_RESERVOIR_1, RSRVRS_FULL_VOL_ML, RSRVRS_FILL_UP_TIMEOUT_MS, state ) ) { - isR1Full = isRsrvrFull( R1, RSRVRS_FULL_VOL_ML, RSRVRS_FILL_UP_TIMEOUT_MS, state ); + isR1Full = TRUE; } // Once reservoir 1 is full, check the status of reservoir 2 since the water overflows to reservoir 2 - else + if ( isR1Full ) { - isR2Full = isRsrvrFull( R2, RSRVRS_PARTIAL_FILL_VOL_ML, RSRVRS_500ML_FILL_UP_TIMEOUT_MS, state ); + isR2Full = isRsrvrFull( DG_RESERVOIR_2, RSRVRS_PARTIAL_FILL_VOL_ML, RSRVRS_500ML_FILL_UP_TIMEOUT_MS, state ); // Once reservoir 2 is full, set the actuators for recirculation if ( isR2Full ) @@ -811,7 +814,7 @@ // So waiting for R1 to get to the level of defined partially full BOOL isR1PartiallyFull = fabs( getLoadCellFilteredWeight( LOAD_CELL_RESERVOIR_1_PRIMARY ) - RSRVRS_PARTIAL_FILL_VOL_ML ) < RSRVRS_MAX_TARGET_VOL_CHANGE_ML; - if ( isRsrvrFull( R2, RSRVRS_FULL_VOL_ML, RSRVRS_FILL_UP_TIMEOUT_MS, state ) && isR1PartiallyFull ) + if ( isRsrvrFull( DG_RESERVOIR_2, RSRVRS_FULL_VOL_ML, RSRVRS_FILL_UP_TIMEOUT_MS, state ) && isR1PartiallyFull ) { // Get the current volumes to be monitored during R2 to R1 heat disinfect state R1HeatDisinfectVol = getLoadCellFilteredWeight( LOAD_CELL_RESERVOIR_1_PRIMARY ); @@ -953,12 +956,12 @@ if ( FALSE == isR1Full ) { // Since reservoir 1 is being filled up at a lower flow rate, the timeout is twice as long as a normal fill up - isR1Full = isRsrvrFull( R1, RSRVRS_FULL_VOL_ML, 2 * RSRVRS_FILL_UP_TIMEOUT_MS, state ); + isR1Full = isRsrvrFull( DG_RESERVOIR_1, RSRVRS_FULL_VOL_ML, 2 * RSRVRS_FILL_UP_TIMEOUT_MS, state ); } else { // Since reservoir 2 is being filled up at a lower flow rate, the timeout is longer than a normal fill up - isR2Full = isRsrvrFull( R2, RSRVRS_PARTIAL_FILL_VOL_ML, RSRVRS_FILL_UP_TIMEOUT_MS, state ); + isR2Full = isRsrvrFull( DG_RESERVOIR_2, RSRVRS_PARTIAL_FILL_VOL_ML, RSRVRS_FILL_UP_TIMEOUT_MS, state ); if ( isR2Full ) { @@ -1002,11 +1005,11 @@ { if ( FALSE == isR2Full ) { - isR2Full = isRsrvrFull( R2, RSRVRS_FULL_VOL_ML, RSRVRS_FILL_UP_TIMEOUT_MS, state ); + isR2Full = isRsrvrFull( DG_RESERVOIR_2, RSRVRS_FULL_VOL_ML, RSRVRS_FILL_UP_TIMEOUT_MS, state ); } else { - isR1Full = isRsrvrFull( R1, RSRVRS_PARTIAL_FILL_VOL_ML, RSRVRS_500ML_FILL_UP_TIMEOUT_MS, state ); + isR1Full = isRsrvrFull( DG_RESERVOIR_1, RSRVRS_PARTIAL_FILL_VOL_ML, RSRVRS_500ML_FILL_UP_TIMEOUT_MS, state ); if ( isR1Full ) { @@ -1123,16 +1126,16 @@ * @param state is the state that called this function * @return none *************************************************************************/ -static BOOL isRsrvrFull( RSRVRS_T r, F32 targetVol, U32 timeout, DG_HEAT_DISINFECT_STATE_T state ) +static BOOL isRsrvrFull( DG_RESERVOIR_ID_T r, F32 targetVol, U32 timeout, DG_HEAT_DISINFECT_STATE_T state ) { BOOL rsrvrStatus = FALSE; F32 volume = 0.0; - if ( r == R1 ) + if ( r == DG_RESERVOIR_1 ) { volume = getLoadCellFilteredWeight( LOAD_CELL_RESERVOIR_1_PRIMARY ); } - else if ( r == R2 ) + else if ( r == DG_RESERVOIR_2 ) { volume = getLoadCellFilteredWeight( LOAD_CELL_RESERVOIR_2_PRIMARY ); } @@ -1147,7 +1150,7 @@ else if ( didTimeout( stateTimer, timeout ) ) { // Fill timed out - setModeToFailed( state ); + //setModeToFailed( state ); //TODO un-comment } return rsrvrStatus;