Index: firmware/App/Controllers/BalancingChamber.c =================================================================== diff -u -r9e6e86f604c8cce7c1704ae55d1e026de3422782 -rf68d42f6972d7be8e994cc35ba52d72a275800f0 --- firmware/App/Controllers/BalancingChamber.c (.../BalancingChamber.c) (revision 9e6e86f604c8cce7c1704ae55d1e026de3422782) +++ firmware/App/Controllers/BalancingChamber.c (.../BalancingChamber.c) (revision f68d42f6972d7be8e994cc35ba52d72a275800f0) @@ -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 @@ -56,11 +58,14 @@ static U32 currentBalChamberSwitchingCounter; ///< Counter (in task interval) to monitor the timing spent during balancing chamber fill/drain operation. static BOOL isBalChamberFillInProgress; ///< Flag indicating balancing chamber fill/drain is in progress. static BOOL isPressureStalbilizedDuringFill; ///< Flag indicating that the pressure is stablized due to fill complete. -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 OVERRIDE_U32_T balChamberDataPublishInterval; ///< Balancing chamber data publish interval. static BOOL balanceChamberSwitchingOnly; ///< Balancing chamber switching without any pressure check and dosing delivery. +static BOOL isPressureDroppedDuringFill; ///< Flag indicating that the pressure is dropped due to BC fill (state 1 or state 2) in progress condition. +static BOOL isFirstCycleBCSwitchingCompleted; ///< Flag indicating that first time balancing chamber swithcing is done to trigger alarms from next cycle onwards. +static U32 balChamberFillCompleteStablePressureCounter; ///< Counter to check balancing chamber fill complete and stable pressure is met. static OVERRIDE_F32_T acidDoseVolume; ///< Acid concentrate volume in ml ( overrideable). static OVERRIDE_F32_T bicarbDoseVolume; ///< Bicarb concentrate volume in ml ( overrideable). static F32 lastTdDialysateFlowrate; ///< Previous TD dialysate flow rate @@ -110,6 +115,10 @@ isPressureStalbilizedDuringFill = FALSE; lastTdDialysateFlowrate = 0.0F; balChamberDataPublicationTimerCounter = 0; + balChamberFillPressureDropCounter = 0; + balChamberFillCompleteStablePressureCounter = 0; + isFirstCycleBCSwitchingCompleted = FALSE; + isPressureDroppedDuringFill = FALSE; } /*********************************************************************//** @@ -152,6 +161,9 @@ //Update last td dialysate flow rate lastTdDialysateFlowrate = tdDialysateFlowrate; + //Reset the BC switching flag for new Qd. + isFirstCycleBCSwitchingCompleted = FALSE; + //Update heater control on dialysate flow change signalHeaterControlOnQDUpdate( D5_HEAT ); @@ -390,12 +402,15 @@ F32 spentDialPressure = getFilteredPressure( D51_PRES ); F32 acidVolume = getF32OverrideValue( &acidDoseVolume ); F32 bicarbVolume = getF32OverrideValue( &bicarbDoseVolume ); + // Check fresh and spent dialysate pressure in range or BC switch only flag set - //TODO : comment the pressure check +#ifndef __BC_PRESSURE_ALARM__ 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() ) ) +#else + 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() ) ) +#endif { //Valve control for state 1 fill valveControlForBCState1FillStart(); @@ -417,7 +432,7 @@ } else { -#ifdef ENABLE_ALARM_2 +#ifdef __BC_PRESSURE_ALARM__ //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 @@ -437,22 +452,32 @@ static BAL_CHAMBER_EXEC_STATE_T handleBalChamberConcentrateControl( void ) { BAL_CHAMBER_EXEC_STATE_T state; - F32 freshDialPressure = getFilteredPressure( D18_PRES ); F32 spentDialPressure = getFilteredPressure( D51_PRES ); + if ( BAL_CHAMBER_SW_STATE1 == balChamberSWState ) + { + state = BAL_CHAMBER_STATE1_BICARB_ACID_DOSING_CNTRL; + } + else + { + state = BAL_CHAMBER_STATE2_BICARB_ACID_DOSING_CNTRL; + } + // 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 +486,7 @@ { state = BAL_CHAMBER_STATE2_FILL_END; } -// } + } return state; } @@ -486,20 +511,23 @@ F32 spentDialPressure = getFilteredPressure( D51_PRES ); // 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 ) ) ) +#ifdef __BC_PRESSURE_ALARM__ + 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; - // isPressureStalbilizedDuringFill = FALSE; + if ( ++balChamberFillCompleteStablePressureCounter >= BAL_CHAMBER_FILL_COMPLETE_MS ) + { + // stabilized pressure indicating fill is complete + isPressureStalbilizedDuringFill = TRUE; + isBalChamberFillInProgress = FALSE; + } } +#else + isPressureStalbilizedDuringFill = FALSE; +#endif // Switching time met or pressure in range, close valves - if ( ( currentBalChamberSwitchingCounter >= balChamberSwitchingPeriod ) || + if ( ( currentBalChamberSwitchingCounter >= balChamberValveClosePeriod ) || ( TRUE == isPressureStalbilizedDuringFill ) ) { // close the state 1 opened valves @@ -509,30 +537,31 @@ // On completion of cycle time, transition to next state if ( currentBalChamberSwitchingCounter >= balChamberSwitchingPeriod ) { + balChamberFillPressureDropCounter = 0; + balChamberFillCompleteStablePressureCounter = 0; + if ( TRUE != getBalChamberSwitchingOnlyStatus() ) { - if ( TRUE != isPressureDroppedDuringFill ) +#ifdef __BC_PRESSURE_ALARM__ + if ( ( TRUE != isPressureDroppedDuringFill ) && ( TRUE == isFirstCycleBCSwitchingCompleted ) ) { -#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 } else if ( TRUE != isPressureStalbilizedDuringFill ) { -#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 } else { // Move to next state when pressure is in range. state = BAL_CHAMBER_STATE2_FILL_START; } - - //TODO : Temporarily allow to proceed next state even though pressure is not stabilized. +#else + // Allow to proceed next state even though pressure is not stabilized. state = BAL_CHAMBER_STATE2_FILL_START; +#endif } else { @@ -568,11 +597,13 @@ F32 bicarbVolume = getF32OverrideValue( &bicarbDoseVolume ); // Check fresh and spent dialysate pressure in range - //TODO : comment the pressure check +#ifndef __BC_PRESSURE_ALARM__ 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() ) ) +#else + 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() ) ) +#endif { // Valve control for state 2 fill valveControlForBCState2FillStart(); @@ -594,7 +625,7 @@ } else { -#ifdef ENABLE_ALARM_2 +#ifdef __BC_PRESSURE_ALARM__ //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 @@ -622,20 +653,23 @@ F32 spentDialPressure = getFilteredPressure( D51_PRES ); // 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 ) ) ) +#ifdef __BC_PRESSURE_ALARM__ + 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; - //isPressureStalbilizedDuringFill = FALSE; + if ( ++balChamberFillCompleteStablePressureCounter >= BAL_CHAMBER_FILL_COMPLETE_MS ) + { + // stabilized pressure indicating fill is complete + isPressureStalbilizedDuringFill = TRUE; + isBalChamberFillInProgress = FALSE; + } } +#else + isPressureStalbilizedDuringFill = FALSE; +#endif // Check switching cycle time or pressure check for valve closure - if ( ( currentBalChamberSwitchingCounter >= balChamberSwitchingPeriod ) || + if ( ( currentBalChamberSwitchingCounter >= balChamberValveClosePeriod ) || ( TRUE == isPressureStalbilizedDuringFill ) ) { // close the valves @@ -645,31 +679,38 @@ // 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 __BC_PRESSURE_ALARM__ + if ( ( TRUE != isPressureDroppedDuringFill ) && ( TRUE == isFirstCycleBCSwitchingCompleted ) ) { -#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 } else if ( TRUE != isPressureStalbilizedDuringFill ) { -#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 } else { // Move to next state when pressure is in range. state = BAL_CHAMBER_STATE1_FILL_START; - } - //TODO : Temporarily allow to proceed next state even though pressure is not stabilized. + // Trigger pressure drop alarm after first cycle of balancing chamber switching complete + if ( FALSE == isFirstCycleBCSwitchingCompleted ) + { + isFirstCycleBCSwitchingCompleted = TRUE; + } + } +#else + // Allow to proceed next state even though pressure is not stabilized. state = BAL_CHAMBER_STATE1_FILL_START; +#endif } else {