Index: firmware/App/Controllers/ConductivitySensors.c =================================================================== diff -u -r7cc6fbb41e6b460fedff71581f6205ef36d5deb6 -r16cd633e1d18224face6f977120ccab3846e7671 --- firmware/App/Controllers/ConductivitySensors.c (.../ConductivitySensors.c) (revision 7cc6fbb41e6b460fedff71581f6205ef36d5deb6) +++ firmware/App/Controllers/ConductivitySensors.c (.../ConductivitySensors.c) (revision 16cd633e1d18224face6f977120ccab3846e7671) @@ -103,7 +103,6 @@ // ********** private function prototypes ********** -static F32 getConductivityValue( U32 sensorId ); static F32 calcCompensatedConductivity( F32 conductivity, F32 temperature); static void calcRORejectionRatio( void ); static void processCPiCPoSensorRead( U32 sensorId, U32 fgpaRead, U08 fpgaReadCount, U08 fpgaErrorCount, U08 fpgaSensorFault ); @@ -240,7 +239,7 @@ * @param sensorId conductivity sensor id * @return compensated conductivity *************************************************************************/ -static F32 getConductivityValue( U32 sensorId ) +F32 getConductivityValue( U32 sensorId ) { F32 result = 0.0; Index: firmware/App/Controllers/ConductivitySensors.h =================================================================== diff -u -r7cc6fbb41e6b460fedff71581f6205ef36d5deb6 -r16cd633e1d18224face6f977120ccab3846e7671 --- firmware/App/Controllers/ConductivitySensors.h (.../ConductivitySensors.h) (revision 7cc6fbb41e6b460fedff71581f6205ef36d5deb6) +++ firmware/App/Controllers/ConductivitySensors.h (.../ConductivitySensors.h) (revision 16cd633e1d18224face6f977120ccab3846e7671) @@ -59,6 +59,8 @@ void checkRORejectionRatio( void ); void checkConcentrateConductivity( void ); +F32 getConductivityValue( U32 sensorId ); + BOOL testSetConductivityOverride( U32 sensorId, F32 value ); BOOL testResetConductivityOverride( U32 sensorId ); Index: firmware/App/DGCommon.h =================================================================== diff -u -r7cc6fbb41e6b460fedff71581f6205ef36d5deb6 -r16cd633e1d18224face6f977120ccab3846e7671 --- firmware/App/DGCommon.h (.../DGCommon.h) (revision 7cc6fbb41e6b460fedff71581f6205ef36d5deb6) +++ firmware/App/DGCommon.h (.../DGCommon.h) (revision 16cd633e1d18224face6f977120ccab3846e7671) @@ -42,6 +42,7 @@ #define ALARMS_DEBUG 1 // #define HEATERS_DEBUG 1 // #define PRESSURES_DEBUG 1 +// #define DISABLE_DIALYSATE_CHECK 1 #include #include #endif Index: firmware/App/Modes/ModeFill.c =================================================================== diff -u -ra726311564521affd46cbbaf129bdffb22e1d58f -r16cd633e1d18224face6f977120ccab3846e7671 --- firmware/App/Modes/ModeFill.c (.../ModeFill.c) (revision a726311564521affd46cbbaf129bdffb22e1d58f) +++ firmware/App/Modes/ModeFill.c (.../ModeFill.c) (revision 16cd633e1d18224face6f977120ccab3846e7671) @@ -21,8 +21,10 @@ #include "LoadCell.h" #include "ModeFill.h" #include "OperationModes.h" +#include "PersistentAlarm.h" #include "Pressures.h" #include "Reservoirs.h" +#include "ROPump.h" #include "TemperatureSensors.h" #include "Timers.h" #include "Valves.h" @@ -34,15 +36,27 @@ // ********** private definitions ********** +#define FILL_MIN_RO_FLOW_RATE 0.6 ///< Minimum RO flow rate in fill mode. +#define FILL_MAX_RO_FLOW_RATE 1.0 ///< Maximum RO flow rate in fill mode. +#define FILL_TARGET_RO_FLOW_RATE 0.8 ///< Target RO flow rate in fill mode. +#define FILL_TARGET_RO_PRESSURE_PSI 120 ///< Target RO pressure in fill mode. +#define RO_FLOW_RATE_OUT_OF_RANGE_PERSISTENCE_PERIOD ( 5 * MS_PER_SECOND ) ///< Persistence period for RO flow rate out of range. + +#define DIALYSATE_ACID_CONCENTRATE_RATIO ( 2.35618 / 100 ) ///< Ratio between RO water and acid concentrate. +#define DIALYSATE_BICARB_CONCENTRATE_RATIO ( 4.06812 / 100 ) ///< Ratio between RO water and bicarbonate concentrate. + // ********** private data ********** -static DG_FILL_MODE_STATE_T fillState; ///< Currently active fill state. +static DG_FILL_MODE_STATE_T fillState; ///< Currently active fill state. // ********** private function prototypes ********** +static DG_FILL_MODE_STATE_T handleCheckInletWaterState( void ); static DG_FILL_MODE_STATE_T handleDialysateProductionState( void ); static DG_FILL_MODE_STATE_T handleDeliverDialysateState( void ); +static void handleDialysateMixing( void ); + /*********************************************************************//** * @brief * The initFillMode function initializes the fill mode module. @@ -53,6 +67,9 @@ void initFillMode( void ) { fillState = DG_FILL_MODE_STATE_START; + + initPersistentAlarm( PERSISTENT_ALARM_RO_PUMP_FLOW_RATE_OUT_OF_RANGE, ALARM_ID_RO_PUMP_FLOW_RATE_OUT_OF_RANGE, + FALSE, RO_FLOW_RATE_OUT_OF_RANGE_PERSISTENCE_PERIOD, RO_FLOW_RATE_OUT_OF_RANGE_PERSISTENCE_PERIOD ); } /*********************************************************************//** @@ -64,14 +81,11 @@ *************************************************************************/ void transitionToFillMode( void ) { - // re-initialize fill mode each time we transition to fill mode - initFillMode(); + fillState = DG_FILL_MODE_STATE_START; // set initial actuator states setValveState( VDR, VALVE_STATE_DRAIN_C_TO_NO ); setValveState( VPO, VALVE_STATE_NOFILL_C_TO_NO ); - // Conc. pumps on - requestConcentratePumpOn(); } /*********************************************************************//** @@ -93,9 +107,13 @@ switch ( fillState ) { case DG_FILL_MODE_STATE_START: - fillState = DG_FILL_MODE_STATE_DIALYSATE_PRODUCTION; + fillState = DG_FILL_MODE_STATE_CHECK_INLET_WATER; break; + case DG_FILL_MODE_STATE_CHECK_INLET_WATER: + fillState = handleCheckInletWaterState(); + break; + case DG_FILL_MODE_STATE_DIALYSATE_PRODUCTION: fillState = handleDialysateProductionState(); break; @@ -113,9 +131,38 @@ return fillState; } + +static DG_FILL_MODE_STATE_T handleCheckInletWaterState( void ) +{ + DG_FILL_MODE_STATE_T result = DG_FILL_MODE_STATE_CHECK_INLET_WATER; + + BOOL const isWaterTemperatureGood = !isAlarmActive( ALARM_ID_INLET_WATER_HIGH_TEMPERATURE ) && !isAlarmActive( ALARM_ID_INLET_WATER_LOW_TEMPERATURE ); + BOOL const isWaterConductivityGood = !isAlarmActive( ALARM_ID_INLET_WATER_HIGH_CONDUCTIVITY ) && !isAlarmActive( ALARM_ID_INLET_WATER_LOW_CONDUCTIVITY ) && + !isAlarmActive( ALARM_ID_RO_REJECTION_RATIO_OUT_OF_RANGE ); + + BOOL isInletWaterReady = isWaterTemperatureGood && isWaterConductivityGood; + +#ifdef DISABLE_DIALYSATE_CHECK + isInletWaterReady = TRUE; +#endif + + if ( isInletWaterReady ) + { + // Concentrate pumps on request and set RO pump to flow rate 800 mL/min + requestConcentratePumpOn(); + // TODO: Change to set flow rate once RO pump driver is updated + // setROPumpFlowRate( FILL_TARGET_RO_FLOW_RATE ); + setROPumpTargetPressure( FILL_TARGET_RO_PRESSURE_PSI, PUMP_CONTROL_MODE_CLOSED_LOOP ); + + result = DG_FILL_MODE_STATE_DIALYSATE_PRODUCTION; + } + + return result; +} + /*********************************************************************//** * @brief - * The handleDialysateProductionState function executes the Dialysate production + * The handleDialysateProductionState function executes the dialysate production * state of the fill mode state machine. * @details Inputs: none * @details Outputs: none @@ -125,8 +172,17 @@ { DG_FILL_MODE_STATE_T result = DG_FILL_MODE_STATE_DIALYSATE_PRODUCTION; + handleDialysateMixing(); + checkConcentrateConductivity(); + + BOOL isDialysateProductionGood = ( !isAlarmActive( ALARM_ID_POST_ACID_CONDUCTIVITY_OUT_OF_RANGE ) && !isAlarmActive( ALARM_ID_POST_BICARB_CONDUCTIVITY_OUT_OF_RANGE ) ); + +#ifdef DISABLE_DIALYSATE_CHECK + isDialysateProductionGood = TRUE; +#endif + // TODO - transition when temperature and mix is in range - if ( 1 ) + if ( isDialysateProductionGood ) { setValveState( VPO, VALVE_STATE_FILL_C_TO_NC ); result = DG_FILL_MODE_STATE_DELIVER_DIALYSATE; @@ -137,19 +193,28 @@ /*********************************************************************//** * @brief - * The handleDeliverDialysateState function executes the deliver Dialysate + * The handleDeliverDialysateState function executes the deliver dialysate * state of the fill mode state machine. * @details Inputs: none - * @details Outputs: Deliver Dialysate + * @details Outputs: Deliver dialysate * @return the next state *************************************************************************/ static DG_FILL_MODE_STATE_T handleDeliverDialysateState( void ) { DG_FILL_MODE_STATE_T result = DG_FILL_MODE_STATE_DELIVER_DIALYSATE; LOAD_CELL_ID_T fillWeightLoadCell = LOAD_CELL_A1; + handleDialysateMixing(); + checkConcentrateConductivity(); + + BOOL isDialysateConductivityBad = ( isAlarmActive( ALARM_ID_POST_ACID_CONDUCTIVITY_OUT_OF_RANGE ) || isAlarmActive( ALARM_ID_POST_BICARB_CONDUCTIVITY_OUT_OF_RANGE ) ); + +#ifdef DISABLE_DIALYSATE_CHECK + isInletWaterReady = TRUE; +#endif + // TODO - transition back when temperature or mix out of range - if ( 0 ) + if ( isDialysateConductivityBad ) { setValveState( VPO, VALVE_STATE_NOFILL_C_TO_NO ); result = DG_FILL_MODE_STATE_DIALYSATE_PRODUCTION; @@ -171,16 +236,18 @@ return result; } -/*********************************************************************//** - * @brief - * The getCurrentFillState function returns the current state of the fill mode. - * @details Inputs: fillState - * @details Outputs: none - * @return current state of fill mode - *************************************************************************/ -DG_FILL_MODE_STATE_T getCurrentFillState( void ) +static void handleDialysateMixing( void ) { - return fillState; + // Set concentrate pumps speed based off RO pump flow rate + F32 const measuredROFlowRate = getMeasuredROFlowRate(); + F32 const acidCP1PumpFlowRate = DIALYSATE_ACID_CONCENTRATE_RATIO * measuredROFlowRate * ML_PER_LITER; + F32 const bicarbCP2PumpFlowRate = DIALYSATE_BICARB_CONCENTRATE_RATIO * measuredROFlowRate * ML_PER_LITER; + + setConcentratePumpTargetSpeed( CONCENTRATEPUMPS_CP1, acidCP1PumpFlowRate ); + setConcentratePumpTargetSpeed( CONCENTRATEPUMPS_CP2, bicarbCP2PumpFlowRate ); + + BOOL const isROPumpFlowRateOutOfRange = ( measuredROFlowRate <= FILL_MIN_RO_FLOW_RATE ) || ( measuredROFlowRate >= FILL_MAX_RO_FLOW_RATE ) ; + checkPersistentAlarm( PERSISTENT_ALARM_RO_PUMP_FLOW_RATE_OUT_OF_RANGE, isROPumpFlowRateOutOfRange, measuredROFlowRate ); } /**@}*/ Index: firmware/App/Modes/ModeFill.h =================================================================== diff -u -rc1ef106ed0f97dc998230c6e154aa2362aa476d8 -r16cd633e1d18224face6f977120ccab3846e7671 --- firmware/App/Modes/ModeFill.h (.../ModeFill.h) (revision c1ef106ed0f97dc998230c6e154aa2362aa476d8) +++ firmware/App/Modes/ModeFill.h (.../ModeFill.h) (revision 16cd633e1d18224face6f977120ccab3846e7671) @@ -37,8 +37,6 @@ void transitionToFillMode( void ); // prepares for transition to fill mode U32 execFillMode( void ); // execute the fill mode state machine (call from OperationModes) -DG_FILL_MODE_STATE_T getCurrentFillState( void ); // get the current state of the fill mode. - /**@}*/ #endif