Index: firmware/App/Controllers/BalancingChamber.c =================================================================== diff -u -re0102a0a08c0d83bcc8e959551079063e2e60d9f -racb534a5d5921959493304a26dbc21d2b03338e0 --- firmware/App/Controllers/BalancingChamber.c (.../BalancingChamber.c) (revision e0102a0a08c0d83bcc8e959551079063e2e60d9f) +++ firmware/App/Controllers/BalancingChamber.c (.../BalancingChamber.c) (revision acb534a5d5921959493304a26dbc21d2b03338e0) @@ -39,6 +39,8 @@ // ********** 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_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 /// Payload record structure for balancing chamber switch only request typedef struct @@ -59,6 +61,8 @@ static BOOL isPressureDroppedDuringFill; ///< Flag indicating that the pressure is dropped due to BC fill (state 1 or state 2) in progress condition. static BAL_CHAMBER_SW_STATE_T balChamberSWState; ///< Current balancing chamber switching state ( state 1 or state 2). static U32 balChamberDataPublicationTimerCounter; ///< Used to schedule balancing chamber data publication to CAN bus. +static U32 balChamberFillPressureDropCounter; ///< Counter to check balancing chamber valves opened and there by pressure drop is seen. +static U32 balChamberFillCompleteStablePressureCounter; ///< Counter to check balancing chamber fill complete and stable pressure is met. static OVERRIDE_U32_T balChamberDataPublishInterval; ///< Balancing chamber data publish interval. static BOOL balanceChamberSwitchingOnly; ///< Balancing chamber switching without any pressure check and dosing delivery. static OVERRIDE_F32_T acidDoseVolume; ///< Acid concentrate volume in ml ( overrideable). @@ -110,6 +114,8 @@ isPressureStalbilizedDuringFill = FALSE; lastTdDialysateFlowrate = 0.0F; balChamberDataPublicationTimerCounter = 0; + balChamberFillPressureDropCounter = 0; + balChamberFillCompleteStablePressureCounter = 0; } /*********************************************************************//** @@ -392,10 +398,10 @@ F32 bicarbVolume = getF32OverrideValue( &bicarbDoseVolume ); // Check fresh and spent dialysate pressure in range or BC switch only flag set //TODO : comment the pressure check - if ( 1 ) - //if ( ( ( freshDialPressure >= FRESH_DIAL_PRESSURE_MIN_PSIG ) && ( freshDialPressure <= FRESH_DIAL_PRESSURE_MAX_PSIG ) ) && - // ( ( spentDialPressure >= SPENT_DIAL_PRESSURE_MIN_PSIG ) && ( spentDialPressure <= SPENT_DIAL_PRESSURE_MAX_PSIG ) ) || - // ( TRUE == getBalChamberSwitchingOnlyStatus() ) ) + //if ( 1 ) + if ( ( ( freshDialPressure >= FRESH_DIAL_PRESSURE_MIN_PSIG ) && ( freshDialPressure <= FRESH_DIAL_PRESSURE_MAX_PSIG ) ) && + ( ( spentDialPressure >= SPENT_DIAL_PRESSURE_MIN_PSIG ) && ( spentDialPressure <= SPENT_DIAL_PRESSURE_MAX_PSIG ) ) || + ( TRUE == getBalChamberSwitchingOnlyStatus() ) ) { //Valve control for state 1 fill valveControlForBCState1FillStart(); @@ -417,10 +423,10 @@ } else { -#ifdef ENABLE_ALARM_2 +//#ifdef ENABLE_ALARM_2 //Alarm when pressure is not in range SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DD_BC_STATE1_FILL_START_PRESSURE_OUT_OF_RANGE, freshDialPressure, spentDialPressure ); -#endif +//#endif } return state; @@ -442,17 +448,19 @@ F32 spentDialPressure = getFilteredPressure( D51_PRES ); // Pressure drop check during fill process helps to find if there is any issue with valves opening - if ( ( freshDialPressure <= BC_FILL_PRESSURE_MIN_PSIG ) && ( spentDialPressure <= BC_FILL_PRESSURE_MIN_PSIG ) ) + if ( ( freshDialPressure <= BC_FRESH_FILL_PRESSURE_PSIG ) && ( spentDialPressure <= BC_SPENT_FILL_PRESSURE_PSIG ) ) { - isPressureDroppedDuringFill = TRUE; + if ( ++balChamberFillPressureDropCounter >= BAL_CHAMBER_FILL_PRES_DROP_MS ) + { + isPressureDroppedDuringFill = TRUE; + } } // On dosing completion, transition to next state based on the current switching state - // TODO : Need an updated FPGA to perform this check. For now commenting this check. -// if ( ( ( TRUE == isConcentratePumpDosingCompleted( D11_PUMP ) ) && -// ( TRUE == isConcentratePumpDosingCompleted( D10_PUMP ) ) ) || -// ( TRUE == getBalChamberSwitchingOnlyStatus() ) ) -// { + if ( ( ( TRUE == isConcentratePumpDosingCompleted( D11_PUMP ) ) && + ( TRUE == isConcentratePumpDosingCompleted( D10_PUMP ) ) ) || + ( TRUE == getBalChamberSwitchingOnlyStatus() ) ) + { if ( BAL_CHAMBER_SW_STATE1 == balChamberSWState ) { state = BAL_CHAMBER_STATE1_FILL_END; @@ -461,7 +469,7 @@ { state = BAL_CHAMBER_STATE2_FILL_END; } -// } + } return state; } @@ -488,18 +496,21 @@ // Check fresh and spent dialysate pressure back in range to indicate fill complete. //TODO : comment the pressure check //if ( 1 ) - if ( currentBalChamberSwitchingCounter >= balChamberValveClosePeriod ) - //if ( ( ( freshDialPressure >= FRESH_DIAL_PRESSURE_MIN_PSIG ) && ( freshDialPressure <= FRESH_DIAL_PRESSURE_MAX_PSIG ) ) && - // ( ( spentDialPressure >= SPENT_DIAL_PRESSURE_MIN_PSIG ) && ( spentDialPressure <= SPENT_DIAL_PRESSURE_MAX_PSIG ) ) ) + //if ( currentBalChamberSwitchingCounter >= balChamberValveClosePeriod ) + if ( ( ( freshDialPressure >= FRESH_DIAL_PRESSURE_MIN_PSIG ) && ( freshDialPressure <= FRESH_DIAL_PRESSURE_MAX_PSIG ) ) && + ( ( spentDialPressure >= SPENT_DIAL_PRESSURE_MIN_PSIG ) && ( spentDialPressure <= SPENT_DIAL_PRESSURE_MAX_PSIG ) ) ) { - // stabilized pressure indicating fill is complete - isPressureStalbilizedDuringFill = TRUE; - isBalChamberFillInProgress = FALSE; + if ( ++balChamberFillCompleteStablePressureCounter >= BAL_CHAMBER_FILL_COMPLETE_MS ) + { + // stabilized pressure indicating fill is complete + isPressureStalbilizedDuringFill = TRUE; + isBalChamberFillInProgress = FALSE; + } // isPressureStalbilizedDuringFill = FALSE; } // Switching time met or pressure in range, close valves - if ( ( currentBalChamberSwitchingCounter >= balChamberSwitchingPeriod ) || + if ( ( currentBalChamberSwitchingCounter >= balChamberValveClosePeriod ) || ( TRUE == isPressureStalbilizedDuringFill ) ) { // close the state 1 opened valves @@ -509,21 +520,24 @@ // On completion of cycle time, transition to next state if ( currentBalChamberSwitchingCounter >= balChamberSwitchingPeriod ) { + balChamberFillPressureDropCounter = 0; + balChamberFillCompleteStablePressureCounter = 0; + if ( TRUE != getBalChamberSwitchingOnlyStatus() ) { if ( TRUE != isPressureDroppedDuringFill ) { -#ifdef ENABLE_ALARM_2 +//#ifdef ENABLE_ALARM_2 // When fill initiated, pressure is not dropped to the expected range, possible valve failures. SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DD_BC_STATE1_FILL_PRESSURE_DROP_OUT_OF_RANGE, freshDialPressure, spentDialPressure ); -#endif +//#endif } else if ( TRUE != isPressureStalbilizedDuringFill ) { -#ifdef ENABLE_ALARM_2 +//#ifdef ENABLE_ALARM_2 // Alarm when switching time expired, but still pressure not in range which indicates fill is not yet completed. SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DD_BC_STATE1_FILL_END_PRESSURE_OUT_OF_RANGE, freshDialPressure, spentDialPressure ); -#endif +//#endif } else { @@ -532,7 +546,7 @@ } //TODO : Temporarily allow to proceed next state even though pressure is not stabilized. - state = BAL_CHAMBER_STATE2_FILL_START; + //state = BAL_CHAMBER_STATE2_FILL_START; } else { @@ -569,10 +583,10 @@ // Check fresh and spent dialysate pressure in range //TODO : comment the pressure check - if ( 1 ) - //if ( ( ( freshDialPressure >= FRESH_DIAL_PRESSURE_MIN_PSIG ) && ( freshDialPressure <= FRESH_DIAL_PRESSURE_MAX_PSIG ) ) && - // ( ( spentDialPressure >= SPENT_DIAL_PRESSURE_MIN_PSIG ) && ( spentDialPressure <= SPENT_DIAL_PRESSURE_MAX_PSIG ) ) || - // ( TRUE == getBalChamberSwitchingOnlyStatus() ) ) + //if ( 1 ) + if ( ( ( freshDialPressure >= FRESH_DIAL_PRESSURE_MIN_PSIG ) && ( freshDialPressure <= FRESH_DIAL_PRESSURE_MAX_PSIG ) ) && + ( ( spentDialPressure >= SPENT_DIAL_PRESSURE_MIN_PSIG ) && ( spentDialPressure <= SPENT_DIAL_PRESSURE_MAX_PSIG ) ) || + ( TRUE == getBalChamberSwitchingOnlyStatus() ) ) { // Valve control for state 2 fill valveControlForBCState2FillStart(); @@ -594,10 +608,10 @@ } else { -#ifdef ENABLE_ALARM_2 +//#ifdef ENABLE_ALARM_2 //Alarm when pressure is not in range SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DD_BC_STATE2_FILL_START_PRESSURE_OUT_OF_RANGE, freshDialPressure, spentDialPressure ); -#endif +//#endif } return state; } @@ -624,18 +638,21 @@ // Check fresh and spent dialysate pressure back in range to indicate fill complete. //TODO : comment the pressure check //if ( 1 ) - if ( currentBalChamberSwitchingCounter >= balChamberValveClosePeriod ) - //if ( ( ( freshDialPressure >= FRESH_DIAL_PRESSURE_MIN_PSIG ) && ( freshDialPressure <= FRESH_DIAL_PRESSURE_MAX_PSIG ) ) && - // ( ( spentDialPressure >= SPENT_DIAL_PRESSURE_MIN_PSIG ) && ( spentDialPressure <= SPENT_DIAL_PRESSURE_MAX_PSIG ) ) ) + //if ( currentBalChamberSwitchingCounter >= balChamberValveClosePeriod ) + if ( ( ( freshDialPressure >= FRESH_DIAL_PRESSURE_MIN_PSIG ) && ( freshDialPressure <= FRESH_DIAL_PRESSURE_MAX_PSIG ) ) && + ( ( spentDialPressure >= SPENT_DIAL_PRESSURE_MIN_PSIG ) && ( spentDialPressure <= SPENT_DIAL_PRESSURE_MAX_PSIG ) ) ) { - // stabilized pressure indicating fill is complete - isPressureStalbilizedDuringFill = TRUE; - isBalChamberFillInProgress = FALSE; + if ( ++balChamberFillCompleteStablePressureCounter >= BAL_CHAMBER_FILL_COMPLETE_MS ) + { + // stabilized pressure indicating fill is complete + isPressureStalbilizedDuringFill = TRUE; + isBalChamberFillInProgress = FALSE; + } //isPressureStalbilizedDuringFill = FALSE; } // Check switching cycle time or pressure check for valve closure - if ( ( currentBalChamberSwitchingCounter >= balChamberSwitchingPeriod ) || + if ( ( currentBalChamberSwitchingCounter >= balChamberValveClosePeriod ) || ( TRUE == isPressureStalbilizedDuringFill ) ) { // close the valves @@ -645,22 +662,25 @@ // On completion of cycle time, transition to next state if ( currentBalChamberSwitchingCounter >= balChamberSwitchingPeriod ) { + balChamberFillPressureDropCounter = 0; + balChamberFillCompleteStablePressureCounter = 0; + // Pressure alarm check if ( TRUE != getBalChamberSwitchingOnlyStatus() ) { if ( TRUE != isPressureDroppedDuringFill ) { -#ifdef ENABLE_ALARM_2 +//#ifdef ENABLE_ALARM_2 // When fill initiated, pressure is not dropped to the expected range, possible valve failures. SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DD_BC_STATE2_FILL_PRESSURE_DROP_OUT_OF_RANGE, freshDialPressure, spentDialPressure ); -#endif +//#endif } else if ( TRUE != isPressureStalbilizedDuringFill ) { -#ifdef ENABLE_ALARM_2 +//#ifdef ENABLE_ALARM_2 // Alarm when switching time expired, but still pressure not in range which indicates fill is not completed. SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DD_BC_STATE2_FILL_END_PRESSURE_OUT_OF_RANGE, freshDialPressure, spentDialPressure ); -#endif +//#endif } else { @@ -669,7 +689,7 @@ } //TODO : Temporarily allow to proceed next state even though pressure is not stabilized. - state = BAL_CHAMBER_STATE1_FILL_START; + //state = BAL_CHAMBER_STATE1_FILL_START; } else {