Index: firmware/App/Controllers/BalancingChamber.c =================================================================== diff -u -rc975258f56f54c3369ff658f722d9edbadf4e99c -rebc66999208b337d8cdef22c07f73d47bb0720a4 --- firmware/App/Controllers/BalancingChamber.c (.../BalancingChamber.c) (revision c975258f56f54c3369ff658f722d9edbadf4e99c) +++ firmware/App/Controllers/BalancingChamber.c (.../BalancingChamber.c) (revision ebc66999208b337d8cdef22c07f73d47bb0720a4) @@ -44,16 +44,17 @@ #define BAL_CHAMBER_DATA_PUBLISH_INTERVAL ( 250 / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the balancing chamber data published. #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. +#ifdef __D65_OPENING_DISABLED__ +#define BAL_CHAMBER_FILL_COMPLETE_MS ( 100 / TASK_GENERAL_INTERVAL ) ///< Time (ms/tasktime) to confirm the balancing chamber fill completed and pressure is within range +#else #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_MID_PSIG 10.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. +#endif +#define SPENT_FILL_COMPLETE_QD_LOW_RISE_MAX_MLPM 300.0F ///< For Qd <= 300 mL/min (Diener 1000). #define SPENT_FILL_COMPLETE_DP_RISE_PSIG 0.5F ///< Minimum 100 ms spent pressure rise (current minus n-2) to count as a rise hit at low Qd. -#define SPENT_FILL_SLOPE_SPENT_PRESSURE_HIGH_PSIG 2.0F ///< Above this absolute spent pressure, only one rise hit is required. +#define SPENT_FILL_COMPLETE_DP_RISE_HIGH_QD_PSIG 5.0F ///< Minimum spent pressure rise for Diener 2000 or Qd > 300 mL/min. +#define SPENT_FILL_SLOPE_SPENT_PRESSURE_HIGH_PSIG 2.0F ///< Above this spent pressure rise, only one rise hit is required. #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 1.0F ///< Allowed detection timing tolerance as a fraction of expected BC switching count. -#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) #define D48_SPEED_RANGE_LIMIT 0.25F ///< D48 speed adjustment range check limit ( D48 speed can vary +/-25% of initial calculated speed) @@ -124,7 +125,7 @@ static void publishBalChamberData( void ); static U32 getBalChamberDataPublishInterval( void ); static void checkSpentFillComplete( F32 spentDialPressure ); -static BOOL isSpentFillCompleteByPressure( F32 spentDialPressure, F32 qdMlpm, F32 spentFillCompletePresPsig ); +static BOOL isSpentFillCompleteByPressure( F32 spentDialPressure, F32 qdMlpm ); static void applyBalChamberSwitchingPeriod( F32 tdDialysateFlowrate ); static BOOL isBalChamberTimeBasedSwitching( void ); static void scheduleFirstCycleRelaxAfterQdApply( void ); @@ -1309,73 +1310,65 @@ * @brief * The isSpentFillCompleteByPressure function evaluates whether the spent side of the * balancing chamber fill is complete from D51 pressure. - * @details \b Inputs: spentDialPressure, qdMlpm, spentFillCompletePresPsig, valve-close period, - * fill counter, Diener pump test config, and D51 slope history for low-Qd slope mode. + * @details \b Inputs: spentDialPressure, qdMlpm, valve-close period, fill counter, + * Diener pump test config, and D51 slope history. * @details \b Outputs: spentFillRiseHitCount, spentFillRiseMissCounter, - * lastPrevSpentDialPressure, prevSpentDialPressure (updated only in slope mode). + * lastPrevSpentDialPressure, prevSpentDialPressure. * @param spentDialPressure filtered spent dialysate pressure (PSIG). * @param qdMlpm dialysate flow rate (mL/min). - * @param spentFillCompletePresPsig spent fill complete pressure threshold for current Qd and pump. * @return TRUE if spent fill is detected this task period; FALSE otherwise. *************************************************************************/ -static BOOL isSpentFillCompleteByPressure( F32 spentDialPressure, F32 qdMlpm, F32 spentFillCompletePresPsig ) +static BOOL isSpentFillCompleteByPressure( F32 spentDialPressure, F32 qdMlpm ) { - BOOL useSlopeDetector = ( ( ( TRUE != getTestConfigStatus( TEST_CONFIG_DD_ENABLE_DIENER_2000_PUMP ) ) && - ( qdMlpm <= SPENT_FILL_COMPLETE_QD_SLOPE_MAX_MLPM ) ) ? TRUE : FALSE ); + BOOL useLowQdRiseThreshold = ( ( ( TRUE != getTestConfigStatus( TEST_CONFIG_DD_ENABLE_DIENER_2000_PUMP ) ) && + ( qdMlpm <= SPENT_FILL_COMPLETE_QD_LOW_RISE_MAX_MLPM ) ) ? TRUE : FALSE ); + F32 riseThresholdPsig = ( TRUE == useLowQdRiseThreshold ) ? SPENT_FILL_COMPLETE_DP_RISE_PSIG : + SPENT_FILL_COMPLETE_DP_RISE_HIGH_QD_PSIG; 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 ) ) ? TRUE : FALSE; + F32 riseDeltaPsi = spentDialPressure - lastPrevSpentDialPressure; + BOOL riseHit = ( riseDeltaPsi > riseThresholdPsig ) ? TRUE : FALSE; + U32 requiredRiseCount; + + // Mid band between low/high spent pressure rise: require two rise hits. + if ( riseDeltaPsi > SPENT_FILL_SLOPE_SPENT_PRESSURE_HIGH_PSIG ) { - // 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 ) ) ? TRUE : FALSE; - F32 riseDeltaPsi = spentDialPressure - lastPrevSpentDialPressure; - BOOL riseHit = ( riseDeltaPsi > SPENT_FILL_COMPLETE_DP_RISE_PSIG ) ? TRUE : FALSE; - U32 requiredRiseCount; + requiredRiseCount = 1U; + } + else + { + requiredRiseCount = 2U; + } - // Mid band between low/high spent pressure: require two rise hits. - if ( riseDeltaPsi > SPENT_FILL_SLOPE_SPENT_PRESSURE_HIGH_PSIG ) + if ( ( TRUE == riseHit ) && ( TRUE == isDetectionInCountWindow ) ) + { + spentFillRiseHitCount += 1; + spentFillRiseMissCounter = 0; + } + else if ( spentFillRiseHitCount > 0 ) + { + if ( ( FALSE == riseHit ) && ( TRUE == isDetectionInCountWindow ) ) { - requiredRiseCount = 1U; - } - else - { - requiredRiseCount = 2U; - } + spentFillRiseMissCounter += 1; - if ( ( TRUE == riseHit ) && ( TRUE == isDetectionInCountWindow ) ) - { - spentFillRiseHitCount += 1; - spentFillRiseMissCounter = 0; - } - else if ( spentFillRiseHitCount > 0 ) - { - if ( ( FALSE == riseHit ) && ( TRUE == isDetectionInCountWindow ) ) + if ( spentFillRiseMissCounter >= 2 ) { - spentFillRiseMissCounter += 1; - - if ( spentFillRiseMissCounter >= 2 ) - { - spentFillRiseHitCount = 0; - spentFillRiseMissCounter = 0; - } + spentFillRiseHitCount = 0; + spentFillRiseMissCounter = 0; } } + } - lastPrevSpentDialPressure = prevSpentDialPressure; - prevSpentDialPressure = spentDialPressure; + 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 ) ? 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; - } + state = ( spentFillRiseHitCount >= requiredRiseCount ) ? TRUE : FALSE; return state; } @@ -1400,7 +1393,6 @@ U32 d48SpeedPostRangeCheck = 0; F32 qdMlpm = getBalChamberActiveDialysateFlowrate(); BOOL result = FALSE; - F32 spentFillCompletePresPsig; BOOL isSpentFillCompleteDetected = FALSE; if ( TRUE == isBalChamberTimeBasedSwitching() ) @@ -1412,25 +1404,8 @@ } else { - // Diener 2000 pump: spent fill complete pressure use legacy 25 PSI. Other pump: depends on Qd. - if ( TRUE == getTestConfigStatus( TEST_CONFIG_DD_ENABLE_DIENER_2000_PUMP ) ) - { - spentFillCompletePresPsig = SPENT_FILL_COMPLETE_PRES; - } - else - { - if ( qdMlpm <= QD_THRESHOLD_HIGH_MLPM ) - { - spentFillCompletePresPsig = SPENT_FILL_COMPLETE_PRES_QD_MID_PSIG; - } - else - { - spentFillCompletePresPsig = SPENT_FILL_COMPLETE_PRES_QD_HIGH_PSIG; - } - } + isSpentFillCompleteDetected = isSpentFillCompleteByPressure( spentDialPressure, qdMlpm ); - isSpentFillCompleteDetected = isSpentFillCompleteByPressure( spentDialPressure, qdMlpm, spentFillCompletePresPsig ); - if ( ( TRUE == isSpentFillCompleteDetected ) && ( isSpentFillComplete != TRUE ) ) { // Check spent fill time against the balancing chamber closing period Index: firmware/App/Controllers/DryBiCart.c =================================================================== diff -u -r5a0b55438edfba94b442d8a62384574821cb1679 -rebc66999208b337d8cdef22c07f73d47bb0720a4 --- firmware/App/Controllers/DryBiCart.c (.../DryBiCart.c) (revision 5a0b55438edfba94b442d8a62384574821cb1679) +++ firmware/App/Controllers/DryBiCart.c (.../DryBiCart.c) (revision ebc66999208b337d8cdef22c07f73d47bb0720a4) @@ -1103,7 +1103,9 @@ { BICARB_CHAMBER_FILL_EXEC_STATE_T state = BICARB_CARTRIDGE_FILL_WATER_START_STATE; +#ifdef __D65_OPENING_DISABLED__ if ( TRUE == isDryBicartBalChamberFillWindowOpen() ) +#endif { // Close vent valves and descaling valve setValveState( D80_VALV, VALVE_STATE_CLOSED ); @@ -1136,6 +1138,7 @@ F32 d66Pressure = getFilteredPressure( D66_PRES ); F32 fillCompletePressure = GET_FILL_COMPLETE_PRESSURE_PSI; +#ifdef __D65_OPENING_DISABLED__ if ( FALSE == isDryBicartBalChamberFillWindowOpen() ) { setValveState( D65_VALV, VALVE_STATE_CLOSED ); @@ -1144,7 +1147,7 @@ { setValveState( D65_VALV, VALVE_STATE_OPEN ); } - +#endif // check D66 pressure greater than or equal to 17 PSI if ( d66Pressure >= fillCompletePressure ) { @@ -1249,9 +1252,14 @@ { drybicartPersistenceOnLowercartPressureStartTime = getMSTimerCount(); } + +#ifdef __D65_OPENING_DISABLED__ // 200 ms persistence on D66 pressure if ( ( TRUE == didTimeout( drybicartPersistenceOnLowercartPressureStartTime, DRY_BICART_PERSISTENCE_DURATION_MS ) ) && ( TRUE == isDryBicartBalChamberFillWindowOpen() ) ) +#else + if ( TRUE == didTimeout( drybicartPersistenceOnLowercartPressureStartTime, DRY_BICART_PERSISTENCE_DURATION_MS ) ) +#endif { setValveState( D65_VALV, VALVE_STATE_OPEN ); drybicartPersistenceOnLowercartPressureStartTime = 0; Index: firmware/App/DDCommon.h =================================================================== diff -u -r53bac040ed66a54ebfc0262f4a3b41daaa0703bf -rebc66999208b337d8cdef22c07f73d47bb0720a4 --- firmware/App/DDCommon.h (.../DDCommon.h) (revision 53bac040ed66a54ebfc0262f4a3b41daaa0703bf) +++ firmware/App/DDCommon.h (.../DDCommon.h) (revision ebc66999208b337d8cdef22c07f73d47bb0720a4) @@ -66,7 +66,10 @@ //Uncomment below to disable the conductivity sensor alarms #define __CONDUCTIVITY_SENSOR_ALARMS_DISABLED__ 1 +//Uncommnet below to enable the D65 valves opening during balancincg chamber fill +//#define __D65_OPENING_DISABLED__ 1 + #include #include #endif