Index: firmware/App/Controllers/SpentChamberFill.c =================================================================== diff -u -r173453569b2eb31b3f19572bf5386440667b0162 -r0a1d4f769464407084d39843244af74911bbdfa5 --- firmware/App/Controllers/SpentChamberFill.c (.../SpentChamberFill.c) (revision 173453569b2eb31b3f19572bf5386440667b0162) +++ firmware/App/Controllers/SpentChamberFill.c (.../SpentChamberFill.c) (revision 0a1d4f769464407084d39843244af74911bbdfa5) @@ -39,6 +39,7 @@ // ********** private definitions ********** #define SPENT_CHAMBER_FILL_DATA_PUBLISH_INTERVAL ( 250 / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the balancing chamber data published. +#define SPENT_CHAMBER_SWITCHING_PERIOD 59 ///< Spent Chamber Fill Switching Period // ********** private data ********** @@ -97,7 +98,7 @@ initSpentChamberFill(); updateBalChamberSwitchingPeriod(); // Follow the same cycle for spent chamber fill - spentChamberFillSwitchingPeriod = getBalChamberSwitchingPeriod(); + spentChamberFillSwitchingPeriod = SPENT_CHAMBER_SWITCHING_PERIOD; } /*********************************************************************//** @@ -188,8 +189,7 @@ /*********************************************************************//** * @brief * The handleSpentChamberFillWaitPressureStabilizeState function introduces the pressure - * stabilization period before starting the spent chamber fill - * for state 2 fill process. + * stabilization period before starting the spent chamber fill. * @details \b Inputs: none * @details \b Outputs: valve states * @return none. @@ -201,8 +201,8 @@ F32 freshDialPressure = getFilteredPressure( D18_PRES ); F32 spentDialPressure = getFilteredPressure( D51_PRES ); - BOOL spentInRange = ( ( spentDialPressure >= SPENT_DIAL_FILL_PRESSURE_MIN_PSIG ) && ( spentDialPressure <= SPENT_DIAL_FILL_PRESSURE_MAX_PSIG ) ); - BOOL freshInRange = ( ( freshDialPressure >= FRESH_DIAL_FILL_PRESSURE_MIN_PSIG ) && ( freshDialPressure <= FRESH_DIAL_FILL_PRESSURE_MAX_PSIG ) ); + BOOL spentInRange = ( ( spentDialPressure >= SPENT_DIAL_FILL_PRESSURE_MIN_PSIG ) && ( spentDialPressure <= SPENT_DIAL_FILL_PRESSURE_MAX_PSIG ) ); + BOOL freshInRange = ( ( freshDialPressure >= FRESH_DIAL_FILL_PRESSURE_MIN_PSIG ) && ( freshDialPressure <= FRESH_DIAL_FILL_PRESSURE_MAX_PSIG ) ); if ( ( TRUE == spentInRange ) && ( TRUE == freshInRange ) ) { Index: firmware/App/Modes/ModeGenDialysate.c =================================================================== diff -u -r173453569b2eb31b3f19572bf5386440667b0162 -r0a1d4f769464407084d39843244af74911bbdfa5 --- firmware/App/Modes/ModeGenDialysate.c (.../ModeGenDialysate.c) (revision 173453569b2eb31b3f19572bf5386440667b0162) +++ firmware/App/Modes/ModeGenDialysate.c (.../ModeGenDialysate.c) (revision 0a1d4f769464407084d39843244af74911bbdfa5) @@ -59,15 +59,19 @@ #define DIALYSATE_TEMP_LOWER_SAFETY_LIMIT_C 33.0F ///< Dialysate lower bound safety temperature limit in C. #define DIALYSATE_TEMP_CLEAR_TIMEOUT_MS ( 10 * MS_PER_SECOND ) ///< Dialysate temperature clear persistence timeout. #define ZERO_DIAL_FLOW_RATE 0.0F ///< Zero dialysate flow rate -#define SPENT_CHAMBER_FILL_MAX_COUNT 10 ///< Total number of spent chamber fill allowed. +#define SPENT_CHAMBER_FILL_MAX_COUNT 12 ///< Total number of spent chamber fill allowed. #define BICARB_CHAMBER_FILL_TIMEOUT ( 1 * MS_PER_SECOND ) ///< Bicarb chamber fill timeout. #define PUMP_SPEED_SLOPE_FACTOR_DIENER_2000 1.24F ///< D48 Diener 2000 pump speed slope (y = 1.24x + 30). #define PUMP_SPEED_INTERCEPT_FACTOR_DIENER_2000 30.0F ///< D48 Diener 2000 pump speed intercept. #define PUMP_SPEED_SLOPE_FACTOR_DIENER_1000 2.869F ///< D48 Diener 1000 pump speed slope (y = 2.869x + 25.956). #define PUMP_SPEED_INTERCEPT_FACTOR_DIENER_1000 25.956F ///< D48 Diener 1000 pump speed intercept. #define BICARB_CHAMBER_FILL_TIMEOUT ( 1 * MS_PER_SECOND ) ///< Bicarb chamber fill timeout. +#define SPENT_CHAMBER_FILL_WAIT_COUNT 3 ///< Number of totalSpentChamberFill increments to wait after level HIGH before transitioning. +// ********** private data ********** + + //Testing #define DELAY_BC_SWITCHING_AT_START_UP ( 10 * MS_PER_SECOND ) ///< Provide a balancing chamber switching start up delay to stabilize pump speed etc., /// Payload record structure for Gen dialysate execution state set request @@ -94,7 +98,8 @@ static BOOL delayBypassStateFlag; ///< To indicate change in treatment parameters static F32 dialysateToDialyzerFlowRate; ///< Current dialysate to dialyzer flow rate (ml/min) static U32 d48PumpSpeed; ///< Initial D48 pump speed based on the Qd. - +static U32 scFillWaitStart; ///< totalSpentChamberFill count latched when level first went HIGH. +static BOOL scFillWaitActive ; ///< TRUE while waiting out the confirm cycles after level HIGH. // ********** private function prototypes ********** static void setModeGenDStateTransition( DD_GEND_MODE_STATE_T state ); @@ -144,6 +149,8 @@ pendingSpentChamberFill = FALSE; pendingBicarbChamberFill = FALSE; d48PumpSpeed = getDialysatePumpMinRPM( D48_PUMP ); + scFillWaitStart = 0; + scFillWaitActive = FALSE; //Testing bypassStateDelayStartTimeMS = 0; delayBypassStateFlag = TRUE; @@ -461,10 +468,12 @@ setValveState( D65_VALV, VALVE_STATE_CLOSED ); setValveState( D81_VALV, VALVE_STATE_CLOSED ); setValveState( D8_VALV, VALVE_STATE_CLOSED ); + setValveState( D88_79_VALV, VALVE_STATE_CLOSED ); + setValveState( D34_VALV, VALVE_STATE_CLOSED ); //Close all balancing chamber valves valveControlForBCClosedState(); - setValveState( D34_VALV, VALVE_STATE_OPEN ); + setValveState( D91_VALV, VALVE_STATE_OPEN ); setValveState( D53_VALV, VALVE_STATE_OPEN ); if ( TRUE == getTestConfigStatus( TEST_CONFIG_DD_DISABLE_DRY_BICARB ) ) @@ -644,6 +653,10 @@ { pendingSpentChamberFill = TRUE; } + else + { + pendingSpentChamberFill = FALSE; + } if ( LEVEL_STATE_LOW == bicarbChamberLevel ) { @@ -758,12 +771,13 @@ if ( getTestConfigStatus( TEST_CONFIG_DD_ENABLE_SPENT_CHAMBER_H_FILL ) == TRUE ) { - if ( ( TRUE == pendingSpentChamberFill ) && ( FALSE == balancingChambFillInProgress ) ) + if ( ( TRUE == pendingSpentChamberFill ) ) { // Deactivate Balancing Chamber Switching requestBalChamberSwitching( FALSE ); - if ( getBalancingChamberStatus()== FALSE ) + // Wait for the Balancing Chamber to complete the current cycle before transition into spent chamber fill state + if ( getBalancingChamberStatus() == FALSE ) { setModeGenDStateTransition( DD_GEND_SPENT_CHAMBER_FILL_STATE ); pendingSpentChamberFill = FALSE; @@ -861,18 +875,24 @@ static DD_GEND_MODE_STATE_T handleGenDSpentChamberFillState( void ) { DD_GEND_MODE_STATE_T state = DD_GEND_SPENT_CHAMBER_FILL_STATE; - LEVEL_STATE_T spentChamberLevel = getLevelStatus( D46_LEVL ); U32 totalSpentChamberFill = getTotalSpentChamberFillCounts(); - // High level is met or total fill count exceeded - if ( ( LEVEL_STATE_HIGH == spentChamberLevel ) || + // Latch the fill count once, at the moment level first goes HIGH + if ( ( LEVEL_STATE_HIGH == getLevelStatus( D46_LEVL ) ) && ( FALSE == scFillWaitActive ) ) + { + scFillWaitStart = totalSpentChamberFill; + scFillWaitActive = TRUE; + } + + // High level confirmed after wait count, or total fill count exceeded + if ( ( ( LEVEL_STATE_HIGH == getLevelStatus( D46_LEVL ) ) && ( ( scFillWaitStart + SPENT_CHAMBER_FILL_WAIT_COUNT ) == totalSpentChamberFill ) ) || ( totalSpentChamberFill >= SPENT_CHAMBER_FILL_MAX_COUNT ) ) { setModeGenDStateTransition( DD_GEND_DIALYSATE_BYPASS_STATE ); isDialDeliveryInProgress.data = FALSE; - //delayBypassStateFlag = TRUE; state = DD_GEND_DIALYSATE_BYPASS_STATE; + scFillWaitActive = FALSE; //Trigger alarm if count exceeded if ( totalSpentChamberFill >= SPENT_CHAMBER_FILL_MAX_COUNT )