Index: firmware/App/Controllers/BalancingChamber.c =================================================================== diff -u -rb7aca6a5c7073dbae6a31d0f87d81bc241eece33 -r67453852a25077d0da103dca88449ee79d628680 --- firmware/App/Controllers/BalancingChamber.c (.../BalancingChamber.c) (revision b7aca6a5c7073dbae6a31d0f87d81bc241eece33) +++ firmware/App/Controllers/BalancingChamber.c (.../BalancingChamber.c) (revision 67453852a25077d0da103dca88449ee79d628680) @@ -44,12 +44,12 @@ // ********** private definitions ********** -#define BAL_CHAMBER_DATA_PUBLISH_INTERVAL ( 250 / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the balancing chamber data published. +#define BAL_CHAMBER_DATA_PUBLISH_INTERVAL ( 50 / 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. #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 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. @@ -69,6 +69,7 @@ #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 SPENT_FILL_COMPLETE_PRESSURE 33.0F /// Payload record structure for balancing chamber switch only request typedef struct @@ -117,6 +118,8 @@ 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 riseDeltaPsi; +static BOOL riseHit; //TODO: remove later once level sensor working static U32 bicarbChamberPeriodicFillCounter; @@ -1472,43 +1475,43 @@ U32 minDetectCount = balChamberValveClosePeriod - detectTolCount; BOOL isDetectionInCountWindow = ( ( currentBalChamberFillCounter >= minDetectCount ) && ( currentBalChamberFillCounter <= maxDetectCount ) ) ? TRUE : FALSE; - F32 riseDeltaPsi = spentDialPressure - lastPrevSpentDialPressure; - BOOL riseHit = ( riseDeltaPsi > riseThresholdPsig ) ? TRUE : FALSE; + riseDeltaPsi = spentDialPressure - lastPrevSpentDialPressure; + 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 ) { 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 = ( ( spentFillRiseHitCount >= requiredRiseCount ) || ( spentDialPressure >= SPENT_FILL_COMPLETE_PRESSURE ) ) ? TRUE : FALSE; return state; } @@ -1846,8 +1849,8 @@ BAL_CHAMBER_DATA_T data; data.balChamberExecState = (U32)balChamberExecState; - data.balChamberSWState = (U32)balChamberSWState; - data.balChamberSWFreq = getBalChamberSwitchingFreq(); + data.balChamberSWState = (U32)spentFillRiseHitCount; + data.balChamberSWFreq = riseDeltaPsi; data.isSpentFillComplete = isSpentFillComplete; data.currentBalChamberSwitchingCounter = currentBalChamberFillCounter; data.isPressureStabilizedDuringFill = isPressureStabilizedDuringFill;