Index: firmware/App/Controllers/BalancingChamber.c =================================================================== diff -u -rae31b4c999dccae70fb40fb9d98a4380ce2c7415 -r16c5398fed27670d52609b19ad870a5f99111534 --- firmware/App/Controllers/BalancingChamber.c (.../BalancingChamber.c) (revision ae31b4c999dccae70fb40fb9d98a4380ce2c7415) +++ firmware/App/Controllers/BalancingChamber.c (.../BalancingChamber.c) (revision 16c5398fed27670d52609b19ad870a5f99111534) @@ -84,14 +84,13 @@ static F32 lastTdDialysateFlowrate; ///< Previous TD dialysate flow rate static F32 freshDialPressure; ///< Fresh side dialysate pressure static F32 spentDialPressure; ///< Spent side dialysate pressure -static BOOL isBalChamberSwitchingActive; ///< Flag indicating balancing chamber switching is active or not. -static BOOL isBalChamberSwitchingOnRequested; ///< Flag indicating that a request was made to activate balancing chamber switching. -static BOOL isBalChamberSwitchingOffRequested; ///< Flag indicating that a request was made to deactivate balancing chamber switching. - static U32 currentBalChamberFillCounter; ///< Counter (in task interval) to monitor the timing spent for the spent side fill operation. static U32 balChamberFillTimeoutCount; ///< Timeout count (in task interval) to detect BC fill timeout. static S32 diffSpentFillCompleteCount; ///< Difference between spent target fill to actual fill count static BOOL isSpentFillComplete; ///< Flag indicating spent side fill complete. +static BOOL isBalChamberSwitchingActive; ///< Flag indicating balancing chamber switching is active or not. +static BOOL isBalChamberSwitchingOnRequested; ///< Flag indicating that a request was made to activate balancing chamber switching. +static BOOL isBalChamberSwitchingOffRequested; ///< Flag indicating that a request was made to deactivate balancing chamber switching. //TODO: remove later once level sensor working static U32 bicarbChamberPeriodicFillCounter; @@ -150,17 +149,15 @@ isPressureDroppedDuringFill = FALSE; freshDialPressure = 0.0F; spentDialPressure = 0.0F; + currentBalChamberFillCounter = 0; + balChamberFillTimeoutCount = 0; + diffSpentFillCompleteCount = 0; + isSpentFillComplete = FALSE; isBalChamberSwitchingActive = FALSE; isBalChamberSwitchingOnRequested = FALSE; isBalChamberSwitchingOffRequested = FALSE; - //TODO:remove once level sensor working bicarbChamberPeriodicFillCounter = 0; - - currentBalChamberFillCounter = 0; - balChamberFillTimeoutCount = 0; - diffSpentFillCompleteCount = 0; - isSpentFillComplete = FALSE; } /*********************************************************************//** @@ -534,6 +531,9 @@ { //Alarm when pressure is not in range SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DD_BC_STATE1_FILL_START_PRESSURE_OUT_OF_RANGE, freshDialPressure, spentDialPressure ); + + // Move to the idle state + state = BAL_CHAMBER_STATE_IDLE; } } @@ -632,7 +632,8 @@ isFirstCycleNotDone = ( FALSE == isFirstCycleBCSwitchingCompleted ); isFillCompleteOrFirstCycle = isBothFillsComplete || isFirstCycleNotDone; - if ( TRUE == isFillCompleteOrFirstCycle ) + if ( ( TRUE == isFillCompleteOrFirstCycle ) || + ( ( currentBalChamberSwitchingCounter >= balChamberValveClosePeriod ) && ( TRUE == getBalChamberSwitchingOnlyStatus() ) ) ) { // close the state 1 opened valves valveControlForBCState1FillEnd(); @@ -654,8 +655,10 @@ * @brief * The handleBalChamberState1FillEnd function check for the balancing chamber * switching period and transition to next state switching. - * @details \b Inputs: currentBalChamberSwitchingCounter, balChamberSwitchingPeriod + * @details \b Inputs: currentBalChamberSwitchingCounter, balChamberSwitchingPeriod, + * isBalChamberSwitchingOffRequested * @details \b Outputs: balChamberFillPressureDropCounter,balChamberFillCompleteStablePressureCounter + * isBalChamberSwitchingOnRequested, isBalChamberSwitchingOffRequested, isBalChamberSwitchingActive * @details \b Alarm: ALARM_ID_DD_BC_STATE1_FILL_PRESSURE_DROP_OUT_OF_RANGE * when pressure drop is not in range during balancing chamber fill in progress. * @details \b Alarm: ALARM_ID_DD_BC_STATE1_FILL_END_PRESSURE_OUT_OF_RANGE @@ -677,11 +680,18 @@ { // When fill initiated, pressure is not dropped to the expected range, possible valve failures. SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DD_BC_STATE1_FILL_PRESSURE_DROP_OUT_OF_RANGE, freshDialPressure, spentDialPressure ); + + // Move to the idle state + state = BAL_CHAMBER_STATE_IDLE; } else if ( TRUE != isPressureStabilizedDuringFill ) { // Alarm when switching time expired, but still pressure not in range which indicates fill is not yet completed. SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DD_BC_STATE1_FILL_END_PRESSURE_OUT_OF_RANGE, freshDialPressure, spentDialPressure ); + + // Move to the idle state + state = BAL_CHAMBER_STATE_IDLE; + } else { @@ -709,9 +719,6 @@ //Clear the request flag to indicate that the request was processed. isBalChamberSwitchingOffRequested = FALSE; - // Clear the flag to indicate that balancing chamber switching is inactive - isBalChamberSwitchingActive = FALSE; - // Move to the idle state state = BAL_CHAMBER_STATE_IDLE; } @@ -785,6 +792,9 @@ { //Alarm when pressure is not in range SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DD_BC_STATE2_FILL_START_PRESSURE_OUT_OF_RANGE, freshDialPressure, spentDialPressure ); + + // Move to the idle state + state = BAL_CHAMBER_STATE_IDLE; } } @@ -832,7 +842,8 @@ isFirstCycleNotDone = ( FALSE == isFirstCycleBCSwitchingCompleted ); isFillCompleteOrFirstCycle = isBothFillsComplete || isFirstCycleNotDone; - if ( TRUE == isFillCompleteOrFirstCycle ) + if ( ( TRUE == isFillCompleteOrFirstCycle ) || + ( ( currentBalChamberSwitchingCounter >= balChamberValveClosePeriod ) && ( TRUE == getBalChamberSwitchingOnlyStatus() ) ) ) { // close the valves valveControlForBCState2FillEnd(); @@ -854,8 +865,10 @@ * @brief * The handleBalChamberState2FillEnd function check for the balancing chamber * switching period complete and transition to next state. - * @details \b Inputs: currentBalChamberSwitchingCounter, balChamberSwitchingPeriod - * @details \b Outputs: isPressureStalbilizedDuringFill,isBalChamberFillInProgress + * @details \b Inputs: currentBalChamberSwitchingCounter, balChamberSwitchingPeriod, + * isBalChamberSwitchingOffRequested + * @details \b Outputs: isPressureStabilizedDuringFill,isBalChamberFillInProgress, + * isBalChamberSwitchingOnRequested, isBalChamberSwitchingOffRequested, isBalChamberSwitchingActive * @details \b Alarm: ALARM_ID_DD_BC_STATE2_FILL_PRESSURE_DROP_OUT_OF_RANGE * when pressure is not in range during balacing chamber state 2 fill in progress. * @details \b Alarm: ALARM_ID_DD_BC_STATE2_FILL_END_PRESSURE_OUT_OF_RANGE @@ -878,11 +891,17 @@ { // When fill initiated, pressure is not dropped to the expected range, possible valve failures. SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DD_BC_STATE2_FILL_PRESSURE_DROP_OUT_OF_RANGE, freshDialPressure, spentDialPressure ); + + // Move to the idle state + state = BAL_CHAMBER_STATE_IDLE; } else if ( TRUE != isPressureStabilizedDuringFill ) { // Alarm when switching time expired, but still pressure not in range which indicates fill is not completed. SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DD_BC_STATE2_FILL_END_PRESSURE_OUT_OF_RANGE, freshDialPressure, spentDialPressure ); + + // Move to the idle state + state = BAL_CHAMBER_STATE_IDLE; } else { @@ -916,9 +935,6 @@ // Clear the request flag to indicate that the request was processed. isBalChamberSwitchingOffRequested = FALSE; - // Clear flag to indicate that balancing chamber switching is inactive - isBalChamberSwitchingActive = FALSE; - // Move to the idle state state = BAL_CHAMBER_STATE_IDLE; } @@ -930,7 +946,8 @@ * @brief * The handleBalChamberStateIdle function handles balancing chamber idle state. * @details \b Inputs: isBalChamberSwitchingOnRequested - * @details \b Outputs: isBalChamberSwitchingActive + * @details \b Outputs: isBalChamberSwitchingOnRequested, isBalChamberSwitchingOffRequested, + * isBalChamberSwitchingActive * @return next balancing chamber state. *************************************************************************/ static BAL_CHAMBER_EXEC_STATE_T handleBalChamberStateIdle( void ) @@ -940,6 +957,9 @@ // Keep Clearing the off request flag in case an off request was made while we were already in the idle state isBalChamberSwitchingOffRequested = FALSE; + // Clear flag to indicate that balancing chamber switching is inactive + isBalChamberSwitchingActive = FALSE; + // Check if a request made was to activate the balancing chamber switching. if ( TRUE == isBalChamberSwitchingOnRequested ) { @@ -1024,8 +1044,12 @@ d48SpeedPostRangeCheck = RANGE( spentDialPumpSpeed, minD48Speed, maxD48Speed ); - // Update the D48 pump speed - setD48PumpSpeedForBCFill( d48SpeedPostRangeCheck ); + // Do not turn on the pump if the switching only is enabled in the standby mode. + if ( FALSE == getBalChamberSwitchingOnlyStatus() ) + { + // Update the D48 pump speed + setD48PumpSpeedForBCFill( d48SpeedPostRangeCheck ); + } } //Update spent fill is complete Index: firmware/App/Modes/ModeGenDialysate.c =================================================================== diff -u -r4053bb88fd83acda93e7b6a27480658e82814609 -r16c5398fed27670d52609b19ad870a5f99111534 --- firmware/App/Modes/ModeGenDialysate.c (.../ModeGenDialysate.c) (revision 4053bb88fd83acda93e7b6a27480658e82814609) +++ firmware/App/Modes/ModeGenDialysate.c (.../ModeGenDialysate.c) (revision 16c5398fed27670d52609b19ad870a5f99111534) @@ -258,8 +258,6 @@ case DD_GEND_STATE_START: // Deactivate Balancing Chamber Switching requestBalChamberSwitching( FALSE ); - - // Do nothing break; case DD_GEND_DIALYSATE_BYPASS_STATE: