Index: firmware/App/Controllers/BalancingChamber.c =================================================================== diff -u -r25371dc5442fafdc0b138b4afe034b2f31ca3d1e -r13bfd2e759fbe5753ba8bcefc3227563c09ff055 --- firmware/App/Controllers/BalancingChamber.c (.../BalancingChamber.c) (revision 25371dc5442fafdc0b138b4afe034b2f31ca3d1e) +++ firmware/App/Controllers/BalancingChamber.c (.../BalancingChamber.c) (revision 13bfd2e759fbe5753ba8bcefc3227563c09ff055) @@ -44,7 +44,6 @@ #define BAL_CHAMBER_FILL_PRES_DROP_MS ( 200 / TASK_GENERAL_INTERVAL ) ///< Time (ms/tasktime) to confirm the balancing chamber filling started and corrosponding valves opened. #define BAL_CHAMBER_FILL_COMPLETE_MS ( 300 / TASK_GENERAL_INTERVAL ) ///< Time (ms/tasktime) to confirm the balancing chamber fill completed and pressure is within range #define SPENT_FILL_COMPLETE_PRES 25.0F ///< Spent fill complete pressure (PSI) for Diener 2000 pump. -#define SPENT_FILL_COMPLETE_PRES_QD_LOW_PSIG 3.5F ///< Spent fill complete pressure (PSI) when Diener 1000 and Qd <= 200. #define SPENT_FILL_COMPLETE_PRES_QD_MID_PSIG 15.0F ///< Spent fill complete pressure (PSI) when Diener 1000 and 200 < Qd <= 400. #define SPENT_FILL_COMPLETE_PRES_QD_HIGH_PSIG 20.0F ///< Spent fill complete pressure (PSI) when Diener 1000 and Qd > 400. #define SPENT_FILL_COMPLETE_QD_SLOPE_MAX_MLPM 300.0F ///< For Qd <= 300 mL/min, spent fill completion uses pressure-rise slope detection. @@ -54,7 +53,6 @@ #define SPENT_FILL_SLOPE_SPENT_PRESSURE_LOW_PSIG 0.5F ///< Below this absolute spent pressure, use Qd-based required rise hit count. #define SPENT_FILL_SLOPE_MAX_RISE_HITS 2 ///< Rise hits required when Qd <= 150 in the low spent-pressure band. #define SPENT_FILL_DETECT_COUNT_TOL_PCT 0.20F ///< Allowed detection timing tolerance as a fraction of expected BC switching count. -#define QD_THRESHOLD_LOW_MLPM 200.0F ///< Qd threshold (mL/min) below which low pressure limit applies. #define QD_THRESHOLD_HIGH_MLPM 400.0F ///< Qd threshold (mL/min) below which mid pressure limit applies. #define SPENT_DIFF_COUNT_ZERO 0 ///< Zero count difference for spent side fill comparing target count #define D48_SPEED_ADJUST_FACTOR 0.5F ///< D48 speed adjustment factor ( 50% of speed adjustment = 0.5) @@ -538,8 +536,6 @@ freshDialPressure = getFilteredPressure( D18_PRES ); spentDialPressure = getFilteredPressure( D51_PRES ); - lastPrevSpentDialPressure = spentDialPressure; - 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 @@ -599,8 +595,10 @@ static BAL_CHAMBER_EXEC_STATE_T handleBalChamberConcentrateControl( void ) { BAL_CHAMBER_EXEC_STATE_T state; - freshDialPressure = getFilteredPressure( D18_PRES ); - spentDialPressure = getFilteredPressure( D51_PRES ); + freshDialPressure = getFilteredPressure( D18_PRES ); + spentDialPressure = getFilteredPressure( D51_PRES ); + lastPrevSpentDialPressure = prevSpentDialPressure; + prevSpentDialPressure = spentDialPressure; if ( BAL_CHAMBER_SW_STATE1 == balChamberSWState ) { @@ -842,8 +840,6 @@ freshDialPressure = getFilteredPressure( D18_PRES ); spentDialPressure = getFilteredPressure( D51_PRES ); - lastPrevSpentDialPressure = spentDialPressure; - 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 @@ -1098,7 +1094,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 @@ -1126,21 +1122,23 @@ *************************************************************************/ static BOOL isSpentFillCompleteByPressure( F32 spentDialPressure, F32 qdMlpm, F32 spentFillCompletePresPsig ) { - BOOL useSlopeDetector = ( ( TRUE != getTestConfigStatus( TEST_CONFIG_DD_ENABLE_DIENER_2000_PUMP ) ) && - ( qdMlpm <= SPENT_FILL_COMPLETE_QD_SLOPE_MAX_MLPM ) ); + BOOL useSlopeDetector = ( ( ( TRUE != getTestConfigStatus( TEST_CONFIG_DD_ENABLE_DIENER_2000_PUMP ) ) && + ( qdMlpm <= SPENT_FILL_COMPLETE_QD_SLOPE_MAX_MLPM ) ) ? TRUE : FALSE ); BOOL state; if ( TRUE == useSlopeDetector ) { + // Gate slope hits near expected valve-close count (current vs balChamberValveClosePeriod +/- tolerance). U32 detectTolCount = (U32)( (F32)balChamberValveClosePeriod * SPENT_FILL_DETECT_COUNT_TOL_PCT ); U32 maxDetectCount = balChamberValveClosePeriod + detectTolCount; U32 minDetectCount = balChamberValveClosePeriod - detectTolCount; BOOL isDetectionInCountWindow = ( ( currentBalChamberFillCounter >= minDetectCount ) && - ( currentBalChamberFillCounter <= maxDetectCount ) ); + ( currentBalChamberFillCounter <= maxDetectCount ) ) ? TRUE : FALSE; F32 riseDeltaPsi = spentDialPressure - lastPrevSpentDialPressure; - BOOL riseHit = ( riseDeltaPsi > SPENT_FILL_COMPLETE_DP_RISE_PSIG ); + BOOL riseHit = ( riseDeltaPsi > SPENT_FILL_COMPLETE_DP_RISE_PSIG ) ? TRUE : FALSE; U32 requiredRiseCount; + // Mid band between low/high spent pressure: require two rise hits. if ( riseDeltaPsi > SPENT_FILL_SLOPE_SPENT_PRESSURE_HIGH_PSIG ) { requiredRiseCount = 1U; @@ -1151,7 +1149,7 @@ } else { - requiredRiseCount = 1U; + requiredRiseCount = 2U; } if ( ( TRUE == riseHit ) && ( TRUE == isDetectionInCountWindow ) ) @@ -1176,14 +1174,13 @@ lastPrevSpentDialPressure = prevSpentDialPressure; prevSpentDialPressure = spentDialPressure; - state = ( ( spentFillRiseHitCount >= requiredRiseCount ) || - ( ( currentBalChamberFillCounter >= balChamberValveClosePeriod ) && - ( spentDialPressure >= spentFillCompletePresPsig ) ) ); + // Complete on slope hits, or on absolute pressure at period only if Qd > low band (low Qd: slope-only, no absolute-pressure fallback). + state = ( spentFillRiseHitCount >= requiredRiseCount ) ? TRUE : FALSE; } else { - state = ( spentDialPressure >= spentFillCompletePresPsig ); - + // Not in slope mode (Diener 2000 pump or Qd > SPENT_FILL_COMPLETE_QD_SLOPE_MAX_MLPM): threshold-only spent fill complete. + state = ( spentDialPressure >= spentFillCompletePresPsig ) ? TRUE : FALSE; } return state; } @@ -1219,12 +1216,8 @@ } else { - if ( qdMlpm <= QD_THRESHOLD_LOW_MLPM ) + if ( qdMlpm <= QD_THRESHOLD_HIGH_MLPM ) { - spentFillCompletePresPsig = SPENT_FILL_COMPLETE_PRES_QD_LOW_PSIG; - } - else if ( qdMlpm <= QD_THRESHOLD_HIGH_MLPM ) - { spentFillCompletePresPsig = SPENT_FILL_COMPLETE_PRES_QD_MID_PSIG; } else @@ -1244,8 +1237,9 @@ absDiffSpentFillCount = abs(diffSpentFillCompleteCount); adjustedSpeed = ( ( (F32)absDiffSpentFillCount / (F32)balChamberValveClosePeriod ) * spentDialPumpSpeed ) * D48_SPEED_ADJUST_FACTOR; + // Skip D48 trim in deadband: diff 0..-2 counts (0..100 ms at 50 ms/task); positive band only (larger negative may mean under-fill). result = ( ( diffSpentFillCompleteCount <= 0 ) && ( diffSpentFillCompleteCount >= -2 ) ) ? TRUE : FALSE; - //Not adjust the D48 pump speed if the fill counter is just 50ms difference from the closing period (considering only positive DEADBAND as negative deadband might indicate under fill of BC). + if ( FALSE == result ) { if ( diffSpentFillCompleteCount < SPENT_DIFF_COUNT_ZERO ) Index: firmware/App/Modes/ModeGenDialysate.c =================================================================== diff -u -r25371dc5442fafdc0b138b4afe034b2f31ca3d1e -r13bfd2e759fbe5753ba8bcefc3227563c09ff055 --- firmware/App/Modes/ModeGenDialysate.c (.../ModeGenDialysate.c) (revision 25371dc5442fafdc0b138b4afe034b2f31ca3d1e) +++ firmware/App/Modes/ModeGenDialysate.c (.../ModeGenDialysate.c) (revision 13bfd2e759fbe5753ba8bcefc3227563c09ff055) @@ -171,7 +171,6 @@ setCurrentSubState( NO_SUB_STATE ); // Deactivate Balancing Chamber Switching requestBalChamberSwitching( FALSE ); - //calculateD48PumpSpeedForBCFill(); initialD48PumpSpeed = getCalculatedD48PumpSpeedForBCFill(); setD48PumpSpeedForBCFill( initialD48PumpSpeed ); transitionToUltrafiltration(); @@ -1010,7 +1009,6 @@ signalUFRateUpdate(); //Update D48 pump speed - //calculateD48PumpSpeedForBCFill(); initialPumpSpeed = getCalculatedD48PumpSpeedForBCFill(); setD48PumpSpeedForBCFill( initialPumpSpeed ); setDialysatePumpTargetRPM( D48_PUMP, (U32)initialPumpSpeed, TRUE ); Index: firmware/App/Modes/ModeGenDialysate.h =================================================================== diff -u -r1bea59c13158a871b80e76d75a2a1a579ae67434 -r13bfd2e759fbe5753ba8bcefc3227563c09ff055 --- firmware/App/Modes/ModeGenDialysate.h (.../ModeGenDialysate.h) (revision 1bea59c13158a871b80e76d75a2a1a579ae67434) +++ firmware/App/Modes/ModeGenDialysate.h (.../ModeGenDialysate.h) (revision 13bfd2e759fbe5753ba8bcefc3227563c09ff055) @@ -62,7 +62,6 @@ BOOL requestDDGenDialyasteStop( void ); // Stop generate dialysate U32 getD48PumpSpeedForBCFill( void ); // Get D48 pump speed void setD48PumpSpeedForBCFill( U32 pumpSpeed ); // Set D48 pump speed -U32 calculateD48PumpSpeedForBCFill( void ); // Calculate and store initial D48 pump speed U32 getCalculatedD48PumpSpeedForBCFill( void ); // Get nominal D48 speed from formula only BOOL testDDGenDialysateDataPublishIntervalOverride( MESSAGE_T *message ); // GenD Mode data publish interval override