Index: firmware/App/Controllers/BalancingChamber.c =================================================================== diff -u -r902889c30391b6ca8c9f19adfd3c841c86a5d49f -rb4afc325ebcad1ba8303d307925a2257eff7d8ac --- firmware/App/Controllers/BalancingChamber.c (.../BalancingChamber.c) (revision 902889c30391b6ca8c9f19adfd3c841c86a5d49f) +++ firmware/App/Controllers/BalancingChamber.c (.../BalancingChamber.c) (revision b4afc325ebcad1ba8303d307925a2257eff7d8ac) @@ -60,7 +60,7 @@ #define D48_SPEED_RANGE_LIMIT 0.25F ///< D48 speed adjustment range check limit ( D48 speed can vary +/-25% of initial calculated speed) #define BICARB_CHAMBER_PERIODIC_FILL_TIME ( 1 * SEC_PER_MIN * \ ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ) ///< Periodic bicarb chamber fill request 60 sec x 20 = 1200 -#define BAL_CHAMBER_FILL_TIMEOUT_FACTOR 1.5 ///< Balancing Chamber fill timeout factor (150% of observed fill count) +#define BAL_CHAMBER_FILL_TIMEOUT_FACTOR 2.0F ///< Balancing Chamber fill timeout factor (2000% of observed fill count) /// Payload record structure for balancing chamber switch only request typedef struct @@ -106,7 +106,7 @@ 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; +static U32 bicarbChamberPeriodicFillCounter; // ********** private function prototypes ********** @@ -221,7 +221,7 @@ //Update last td dialysate flow rate lastTdDialysateFlowrate = tdDialysateFlowrate; - // Update fill timeout count based on the switching period (e.g. 150% of period) + // Update fill timeout count based on the switching period (e.g. 200% of period) balChamberFillTimeoutCount = (U32)( (F32)balChamberSwitchingPeriod * BAL_CHAMBER_FILL_TIMEOUT_FACTOR ); //Reset the BC switching flag for new Qd. @@ -528,7 +528,7 @@ BAL_CHAMBER_EXEC_STATE_T state = BAL_CHAMBER_STATE1_FILL_START; balChamberSWState = BAL_CHAMBER_SW_STATE1; - balChamberFillTimeoutCount = 0; + // Preserve the Qd-based timeout so a stuck fill can fault. isBalChamberFillInProgress = FALSE; isPressureStabilizedDuringFill = FALSE; isPressureDroppedDuringFill = FALSE; @@ -554,7 +554,7 @@ freshDialPressure = getFilteredPressure( D18_PRES ); spentDialPressure = getFilteredPressure( D51_PRES ); - if ( getTestConfigStatus( TEST_CONFIG_DD_FP_ENABLE_BETA_1_0_HW ) == TRUE ) + if ( TRUE == getTestConfigStatus( TEST_CONFIG_DD_FP_ENABLE_BETA_1_0_HW ) ) { //Set Trimmer heater Target temp every BC cycle to catch up fresh dialysate temp setHeaterTargetTemperature( D45_HEAT, getFilteredTemperatureValue( D4_TEMP ) ); @@ -673,12 +673,14 @@ BOOL isBothFillsComplete = FALSE; BOOL isFirstCycleNotDone = FALSE; BOOL isFillCompleteOrFirstCycle = FALSE; + BOOL isFillTimeoutEnabled = ( ( TRUE == isFirstCycleBCSwitchingCompleted ) && + ( FALSE == getBalChamberSwitchingOnlyStatus() ) ) ? TRUE : FALSE; freshDialPressure = getFilteredPressure( D18_PRES ); spentDialPressure = getFilteredPressure( D51_PRES ); - // If fill is taking too long, set an alarm for fill timeout - if ( ( balChamberFillTimeoutCount > 0 ) && ( currentBalChamberFillCounter > balChamberFillTimeoutCount ) ) + // After the first BC cycle, fault if fill never completes at the Qd-based timeout. + if ( ( TRUE == isFillTimeoutEnabled ) && ( balChamberFillTimeoutCount > 0 ) && ( currentBalChamberFillCounter > balChamberFillTimeoutCount ) ) { SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DD_BC_FILL_TIMEOUT_FAULT, currentBalChamberFillCounter, balChamberFillTimeoutCount ); @@ -700,21 +702,24 @@ checkSpentFillComplete( spentDialPressure ); // Check both spent and fresh side fill is complete - isBothFillsComplete = ( TRUE == isSpentFillComplete ) && ( TRUE == isPressureStabilizedDuringFill ); - isFirstCycleNotDone = ( FALSE == isFirstCycleBCSwitchingCompleted ); + isBothFillsComplete = ( ( TRUE == isSpentFillComplete ) && ( TRUE == isPressureStabilizedDuringFill ) ) ? TRUE : FALSE; + isFirstCycleNotDone = ( FALSE == isFirstCycleBCSwitchingCompleted ) && ( currentBalChamberSwitchingCounter >= balChamberValveClosePeriod ); if ( FALSE == getBalChamberSwitchingOnlyStatus() ) { - isFillCompleteOrFirstCycle = isBothFillsComplete || isFirstCycleNotDone; + isFillCompleteOrFirstCycle = ( ( TRUE == isBothFillsComplete ) || ( TRUE == isFirstCycleNotDone ) ) ? TRUE : FALSE; } if ( ( TRUE == isFillCompleteOrFirstCycle ) || - ( ( currentBalChamberSwitchingCounter >= balChamberValveClosePeriod ) && ( TRUE == getBalChamberSwitchingOnlyStatus() ) ) ) + ( ( currentBalChamberSwitchingCounter >= balChamberValveClosePeriod ) && ( TRUE == getBalChamberSwitchingOnlyStatus() ) ) ) { // close the state 1 opened valves valveControlForBCState1FillEnd(); isBalChamberFillInProgress = FALSE; - setDialysatePumpTargetRPM( D48_PUMP, getD48PumpSpeedForBCFill(), TRUE ); + if ( FALSE == getBalChamberSwitchingOnlyStatus() ) + { + setDialysatePumpTargetRPM( D48_PUMP, getD48PumpSpeedForBCFill(), TRUE ); + } // Transition to next state state = BAL_CHAMBER_STATE1_FILL_END; @@ -837,7 +842,6 @@ isPressureStabilizedDuringFill = FALSE; isPressureDroppedDuringFill = FALSE; balChamberSWState = BAL_CHAMBER_SW_STATE2; - balChamberFillTimeoutCount = 0; lastPrevSpentDialPressure = 0.0F; prevSpentDialPressure = 0.0F; currentBalChamberSwitchingCounter = 0; @@ -856,10 +860,11 @@ acidVolume = getF32OverrideValue( &acidDoseVolume ); bicarbVolume = getF32OverrideValue( &bicarbDoseVolume ); } + freshDialPressure = getFilteredPressure( D18_PRES ); spentDialPressure = getFilteredPressure( D51_PRES ); - if ( getTestConfigStatus( TEST_CONFIG_DD_FP_ENABLE_BETA_1_0_HW ) == TRUE ) + if ( TRUE == getTestConfigStatus( TEST_CONFIG_DD_FP_ENABLE_BETA_1_0_HW ) ) { //Set Trimmer heater Target temp every BC cycle to catch up fresh dialysate temp setHeaterTargetTemperature( D45_HEAT, getFilteredTemperatureValue( D4_TEMP ) ); @@ -921,6 +926,8 @@ BOOL isBothFillsComplete = FALSE; BOOL isFirstCycleNotDone = FALSE; BOOL isFillCompleteOrFirstCycle = FALSE; + BOOL isFillTimeoutEnabled = ( ( TRUE == isFirstCycleBCSwitchingCompleted ) && + ( FALSE == getBalChamberSwitchingOnlyStatus() ) ) ? TRUE : FALSE; freshDialPressure = getFilteredPressure( D18_PRES ); spentDialPressure = getFilteredPressure( D51_PRES ); @@ -935,8 +942,8 @@ } } - // If fill is taking too long, set an alarm for fill timeout - if ( ( balChamberFillTimeoutCount > 0 ) && ( currentBalChamberFillCounter > balChamberFillTimeoutCount ) ) + // After the first BC cycle, fault if fill never completes at the Qd-based timeout. + if ( ( TRUE == isFillTimeoutEnabled ) && ( balChamberFillTimeoutCount > 0 ) && ( currentBalChamberFillCounter > balChamberFillTimeoutCount ) ) { SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DD_BC_FILL_TIMEOUT_FAULT, currentBalChamberFillCounter, balChamberFillTimeoutCount ); @@ -948,21 +955,24 @@ checkSpentFillComplete( spentDialPressure ); // Check switching cycle time or pressure check for valve closure - isBothFillsComplete = ( TRUE == isSpentFillComplete ) && ( TRUE == isPressureStabilizedDuringFill ); - isFirstCycleNotDone = ( FALSE == isFirstCycleBCSwitchingCompleted ); + isBothFillsComplete = ( ( TRUE == isSpentFillComplete ) && ( TRUE == isPressureStabilizedDuringFill ) ) ? TRUE : FALSE; + isFirstCycleNotDone = ( ( FALSE == isFirstCycleBCSwitchingCompleted ) && ( currentBalChamberSwitchingCounter >= balChamberValveClosePeriod ) ); if ( FALSE == getBalChamberSwitchingOnlyStatus() ) { - isFillCompleteOrFirstCycle = isBothFillsComplete || isFirstCycleNotDone; + isFillCompleteOrFirstCycle = ( ( TRUE == isBothFillsComplete ) || ( TRUE == isFirstCycleNotDone ) ) ? TRUE : FALSE; } if ( ( TRUE == isFillCompleteOrFirstCycle ) || - ( ( currentBalChamberSwitchingCounter >= balChamberValveClosePeriod ) && ( TRUE == getBalChamberSwitchingOnlyStatus() ) ) ) + ( ( currentBalChamberSwitchingCounter >= balChamberValveClosePeriod ) && ( TRUE == getBalChamberSwitchingOnlyStatus() ) ) ) { // close the valves valveControlForBCState2FillEnd(); isBalChamberFillInProgress = FALSE; - setDialysatePumpTargetRPM( D48_PUMP, getD48PumpSpeedForBCFill(), TRUE ); + if ( FALSE == getBalChamberSwitchingOnlyStatus() ) + { + setDialysatePumpTargetRPM( D48_PUMP, getD48PumpSpeedForBCFill(), TRUE ); + } //Transition to next state state = BAL_CHAMBER_STATE2_FILL_END; @@ -1113,7 +1123,7 @@ // Check if a request made was to activate the balancing chamber switching. if ( TRUE == isBalChamberSwitchingOnRequested ) { - //Clear the request flag to indicate that the request was processed. + //Clear request was processed. isBalChamberSwitchingOnRequested = FALSE; // Set flag to indicate that balancing chamber switching is active @@ -1274,6 +1284,7 @@ d48SpeedPostRangeCheck = RANGE( spentDialPumpSpeed, minD48Speed, maxD48Speed ); + // Do not turn on the pump if the switching only is enabled in the standby mode. if ( FALSE == getBalChamberSwitchingOnlyStatus() ) {