Index: firmware/App/Controllers/BalancingChamber.c =================================================================== diff -u -r5075786897d42d24a93ae5485936b5d50c307f65 -r991b728889da6617433aca9d6fbdcdbc0c16c901 --- firmware/App/Controllers/BalancingChamber.c (.../BalancingChamber.c) (revision 5075786897d42d24a93ae5485936b5d50c307f65) +++ firmware/App/Controllers/BalancingChamber.c (.../BalancingChamber.c) (revision 991b728889da6617433aca9d6fbdcdbc0c16c901) @@ -62,13 +62,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 0.4F ///< 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 +118,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 +212,7 @@ prevBalChamberState = BAL_CHAMBER_STATE_IDLE; //TODO:remove once level sensor working bicarbChamberPeriodicFillCounter = 0; + balChamberTolSwitchTime = 0.0F; } /*********************************************************************//** @@ -401,6 +404,8 @@ //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 ) ); + balChamberTolSwitchTime = (F32)balChamberSwitchingPeriod + (F32)balChamberSwitchingPeriod * BAL_CHAMBER_MAX_SWITCH_TIME_TOL; + // finish the balancing chamber fill 50 ms prior completing the regular cycle time. balChamberSwitchingPeriod -= 1; @@ -1481,34 +1486,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; }