Index: firmware/App/Controllers/BalancingChamber.c =================================================================== diff -u -r5b4cead5cae17e59fb9d3a004a989a70c2fa916d -r9ac478c0572c655fe9f204c39b680f1ceb536226 --- firmware/App/Controllers/BalancingChamber.c (.../BalancingChamber.c) (revision 5b4cead5cae17e59fb9d3a004a989a70c2fa916d) +++ firmware/App/Controllers/BalancingChamber.c (.../BalancingChamber.c) (revision 9ac478c0572c655fe9f204c39b680f1ceb536226) @@ -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. @@ -495,8 +494,8 @@ F32 bicarbVolume = getF32OverrideValue( &bicarbDoseVolume ); freshDialPressure = getFilteredPressure( D18_PRES ); spentDialPressure = getFilteredPressure( D51_PRES ); - lastPrevSpentDialPressure = spentDialPressure; + // Check fresh dialysate pressure in range or BC switch only flag set or BC pressure alarms are disabled if ( ( ( freshDialPressure >= FRESH_DIAL_PRESSURE_MIN_PSIG ) && ( freshDialPressure <= FRESH_DIAL_PRESSURE_MAX_PSIG ) ) || ( TRUE == getBalChamberSwitchingOnlyStatus() ) || ( TRUE == getTestConfigStatus( TEST_CONFIG_DD_DISABLE_BC_PRESSURE_ALARMS ) ) ) @@ -542,8 +541,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 ) { @@ -723,7 +724,6 @@ F32 bicarbVolume = getF32OverrideValue( &bicarbDoseVolume ); freshDialPressure = getFilteredPressure( D18_PRES ); spentDialPressure = getFilteredPressure( D51_PRES ); - lastPrevSpentDialPressure = spentDialPressure; // Check fresh dialysate pressure in range if ( ( ( freshDialPressure >= FRESH_DIAL_PRESSURE_MIN_PSIG ) && ( freshDialPressure <= FRESH_DIAL_PRESSURE_MAX_PSIG ) ) || @@ -895,6 +895,7 @@ 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; @@ -904,6 +905,7 @@ 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; @@ -914,7 +916,7 @@ } else { - requiredRiseCount = 1U; + requiredRiseCount = 2U; } if ( ( TRUE == riseHit ) && ( TRUE == isDetectionInCountWindow ) ) @@ -939,14 +941,16 @@ lastPrevSpentDialPressure = prevSpentDialPressure; prevSpentDialPressure = spentDialPressure; + // 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 ) || - ( ( currentBalChamberFillCounter >= balChamberValveClosePeriod ) && + ( ( qdMlpm > QD_THRESHOLD_LOW_MLPM ) && + ( currentBalChamberFillCounter >= balChamberValveClosePeriod ) && ( spentDialPressure >= spentFillCompletePresPsig ) ) ) ? TRUE : FALSE; } else { + // 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; } @@ -982,12 +986,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 @@ -1008,7 +1008,7 @@ adjustedSpeed = ( ( (F32)absDiffSpentFillCount / (F32)balChamberValveClosePeriod ) * spentDialPumpSpeed ) * D48_SPEED_ADJUST_FACTOR; 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). + // 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). if ( FALSE == result ) { if ( diffSpentFillCompleteCount < SPENT_DIFF_COUNT_ZERO ) Index: firmware/App/Modes/ModeGenDialysate.c =================================================================== diff -u -r0fdb539277f865425aba65d98e8e9147484a99e0 -r9ac478c0572c655fe9f204c39b680f1ceb536226 --- firmware/App/Modes/ModeGenDialysate.c (.../ModeGenDialysate.c) (revision 0fdb539277f865425aba65d98e8e9147484a99e0) +++ firmware/App/Modes/ModeGenDialysate.c (.../ModeGenDialysate.c) (revision 9ac478c0572c655fe9f204c39b680f1ceb536226) @@ -175,7 +175,6 @@ initGenDialysateMode(); setCurrentSubState( NO_SUB_STATE ); - //calculateD48PumpSpeedForBCFill(); initialD48PumpSpeed = getCalculatedD48PumpSpeedForBCFill(); setD48PumpSpeedForBCFill( initialD48PumpSpeed ); transitionToUltrafiltration(); @@ -1009,7 +1008,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 -rb2e7c9194acd84783d2bbad64c5720410493e199 -r9ac478c0572c655fe9f204c39b680f1ceb536226 --- firmware/App/Modes/ModeGenDialysate.h (.../ModeGenDialysate.h) (revision b2e7c9194acd84783d2bbad64c5720410493e199) +++ firmware/App/Modes/ModeGenDialysate.h (.../ModeGenDialysate.h) (revision 9ac478c0572c655fe9f204c39b680f1ceb536226) @@ -61,7 +61,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