Index: firmware/App/Controllers/BalancingChamber.c =================================================================== diff -u -rb7aca6a5c7073dbae6a31d0f87d81bc241eece33 -r5b964c8b60808451ece4379fb74aee9e7532b034 --- firmware/App/Controllers/BalancingChamber.c (.../BalancingChamber.c) (revision b7aca6a5c7073dbae6a31d0f87d81bc241eece33) +++ firmware/App/Controllers/BalancingChamber.c (.../BalancingChamber.c) (revision 5b964c8b60808451ece4379fb74aee9e7532b034) @@ -25,6 +25,7 @@ #include "FpgaDD.h" #include "Heaters.h" #include "Level.h" +#include "MessagePayloads.h" #include "MessageSupport.h" #include "Messaging.h" #include "MixingControl.h" @@ -49,7 +50,7 @@ #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 #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_COMPLETE_DP_RISE_HIGH_QD_PSIG 3.0F ///< Minimum spent pressure rise for Diener 2000 or Qd > 300 mL/min. +#define SPENT_FILL_COMPLETE_DP_RISE_HIGH_QD_PSIG 2.0F ///< Minimum spent pressure rise for Diener 2000 #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. @@ -62,13 +63,14 @@ #define BAL_CHAMBER_FILL_TIMEOUT_FACTOR 3.0F ///< Balancing Chamber fill timeout factor (300% of observed fill count) #define COMP_SLOPE -0.000376F ///< Balancing chamber temperature compensation slope factor #define COMP_INTERCEPT 1.007269F ///< Balancing chamber temperature compensation intercept factor -/// Bicarb (D10) pump speed from instantaneous mix volume: speed = 240 - sqrt(230400 - 96000*v)/2 #define BC_BICARB_SPEED_OFFSET_MLPM 240.0F ///< Bicarb speed formula offset (mL/min). #define BC_BICARB_SPEED_DISC_CONST 230400.0F ///< Bicarb speed formula discriminant constant. #define BC_BICARB_SPEED_DISC_VOL_COEF 96000.0F ///< Bicarb speed formula volume coefficient. #define BC_ACID_SPEED_OFFSET_MLPM 160.0F ///< Acid speed formula offset (mL/min). #define BC_ACID_SPEED_DISC_CONSTANT 102400.0F ///< Acid speed formula discriminant constant. #define BC_ACID_SPEED_DISC_VOL_COEF 96000.0F ///< Acid speed formula volume coefficient. +#define BAL_CHAMBER_MAX_SWITCH_TIME_TOL 1.0F ///< Maximum tolerance defined for switching states +#define BAL_CHAMBER_ABSOLUTE_SPENT_PRESSURE 33.0F ///< Maximum spent(D51) pressure before we declare the fill is complete /// Payload record structure for balancing chamber switch only request typedef struct @@ -117,6 +119,7 @@ static BOOL isBalChamberSwitchingPeriodUpdatePending; ///< BC switching period update pending apply at fill end. static U32 bcSwitchingBasedOnClosedPeriodCounter; ///< Valve-close segments remaining before first-cycle relaxations clear after Qd timing apply. static F32 balancingError; ///< Balancing error that has been calculated during balancing chamber switching. +static F32 balChamberTolSwitchTime; ///< Balancing chamber allowed tolerance time before we switch to next state. //TODO: remove later once level sensor working static U32 bicarbChamberPeriodicFillCounter; @@ -210,6 +213,7 @@ prevBalChamberState = BAL_CHAMBER_STATE_IDLE; //TODO:remove once level sensor working bicarbChamberPeriodicFillCounter = 0; + balChamberTolSwitchTime = 0.0F; } /*********************************************************************//** @@ -401,8 +405,7 @@ //update the switching period in task interval for balancing chamber fill timeout check balChamberSwitchingPeriod = (U32)( (F32)SEC_PER_MIN / getBalChamberSwitchingFreq() * ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ); - // finish the balancing chamber fill 50 ms prior completing the regular cycle time. - balChamberSwitchingPeriod -= 1; + balChamberTolSwitchTime = (F32)balChamberSwitchingPeriod + ( (F32)balChamberSwitchingPeriod * BAL_CHAMBER_MAX_SWITCH_TIME_TOL ); //Update last td dialysate flow rate lastTdDialysateFlowrate = tdDialysateFlowrate; @@ -418,7 +421,7 @@ //Testing balChamberValveClosePeriod = balChamberSwitchingPeriod; - balChamberValveClosePeriod -= 1; // Close valves prior 50 msecond for testing + balChamberValveClosePeriod -= 2; // Close valves 100 msecond prior to switching to next state currentBalChamberFillCounter = 0; currentBalChamberSwitchingCounter = 0; @@ -1481,34 +1484,34 @@ { requiredRiseCount = 1U; } - else - { - requiredRiseCount = 2U; - } +// else +// { +// requiredRiseCount = 2U; +// } if ( ( TRUE == riseHit ) && ( TRUE == isDetectionInCountWindow ) ) { spentFillRiseHitCount += 1; spentFillRiseMissCounter = 0; } - else if ( spentFillRiseHitCount > 0 ) - { - if ( ( FALSE == riseHit ) && ( TRUE == isDetectionInCountWindow ) ) - { - spentFillRiseMissCounter += 1; +// else if ( spentFillRiseHitCount > 0 ) +// { +// if ( ( FALSE == riseHit ) && ( TRUE == isDetectionInCountWindow ) ) +// { +// spentFillRiseMissCounter += 1; +// +// if ( spentFillRiseMissCounter >= 2 ) +// { +// spentFillRiseHitCount = 0; +// spentFillRiseMissCounter = 0; +// } +// } +// } - if ( spentFillRiseMissCounter >= 2 ) - { - spentFillRiseHitCount = 0; - spentFillRiseMissCounter = 0; - } - } - } - lastPrevSpentDialPressure = prevSpentDialPressure; prevSpentDialPressure = spentDialPressure; - state = ( spentFillRiseHitCount >= requiredRiseCount ) ? TRUE : FALSE; + state = ( ( spentDialPressure >= BAL_CHAMBER_ABSOLUTE_SPENT_PRESSURE ) || ( spentFillRiseHitCount >= requiredRiseCount ) || ( currentBalChamberFillCounter >= balChamberTolSwitchTime ) ) ? TRUE : FALSE; return state; }