Index: firmware/App/Controllers/BalancingChamber.c =================================================================== diff -u -reaa0ce5fe4890d9c7ff14d14828ea90209c1ad97 -r7d24ef2e6a4130b3a049e6106a0371fc6503271f --- firmware/App/Controllers/BalancingChamber.c (.../BalancingChamber.c) (revision eaa0ce5fe4890d9c7ff14d14828ea90209c1ad97) +++ firmware/App/Controllers/BalancingChamber.c (.../BalancingChamber.c) (revision 7d24ef2e6a4130b3a049e6106a0371fc6503271f) @@ -69,13 +69,17 @@ 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 +static F32 freshDialPressure; ///< Fresh side dialysate pressure +static F32 spentDialPressure; ///< Spent side dialysate pressure // ********** private function prototypes ********** static BAL_CHAMBER_EXEC_STATE_T handleBalChamberState1FillStart( void ); static BAL_CHAMBER_EXEC_STATE_T handleBalChamberConcentrateControl(void); +static BAL_CHAMBER_EXEC_STATE_T handleBalChamberState1ValvesClose( void ); static BAL_CHAMBER_EXEC_STATE_T handleBalChamberState1FillEnd(void); static BAL_CHAMBER_EXEC_STATE_T handleBalChamberState2FillStart( void ); +static BAL_CHAMBER_EXEC_STATE_T handleBalChamberState2ValvesClose( void ); static BAL_CHAMBER_EXEC_STATE_T handleBalChamberState2FillEnd(void); static void publishBalChamberData( void ); static U32 getBalChamberDataPublishInterval( void ); @@ -119,6 +123,8 @@ balChamberFillCompleteStablePressureCounter = 0; isFirstCycleBCSwitchingCompleted = FALSE; isPressureDroppedDuringFill = FALSE; + freshDialPressure = 0.0F; + spentDialPressure = 0.0F; } /*********************************************************************//** @@ -201,6 +207,10 @@ balChamberExecState = handleBalChamberConcentrateControl(); break; + case BAL_CHAMBER_STATE1_VALVES_CLOSE: + balChamberExecState = handleBalChamberState1ValvesClose(); + break; + case BAL_CHAMBER_STATE1_FILL_END: balChamberExecState = handleBalChamberState1FillEnd(); break; @@ -213,6 +223,10 @@ balChamberExecState = handleBalChamberConcentrateControl(); break; + case BAL_CHAMBER_STATE2_VALVES_CLOSE: + balChamberExecState = handleBalChamberState2ValvesClose(); + break; + case BAL_CHAMBER_STATE2_FILL_END: balChamberExecState = handleBalChamberState2FillEnd(); break; @@ -355,7 +369,6 @@ setValveState( D22_VALV, VALVE_STATE_OPEN ); } - /*********************************************************************//** * @brief * The valveControlForBCFreshSideOnlyOpenState function opens the fresh side @@ -398,10 +411,10 @@ isPressureDroppedDuringFill = FALSE; balChamberSWState = BAL_CHAMBER_SW_STATE1; - F32 freshDialPressure = getFilteredPressure( D18_PRES ); - F32 spentDialPressure = getFilteredPressure( D51_PRES ); F32 acidVolume = getF32OverrideValue( &acidDoseVolume ); F32 bicarbVolume = getF32OverrideValue( &bicarbDoseVolume ); + freshDialPressure = getFilteredPressure( D18_PRES ); + spentDialPressure = getFilteredPressure( D51_PRES ); // Check fresh and spent dialysate pressure in range or BC switch only flag set if ( ( ( freshDialPressure >= FRESH_DIAL_PRESSURE_MIN_PSIG ) && ( freshDialPressure <= FRESH_DIAL_PRESSURE_MAX_PSIG ) ) && @@ -449,8 +462,8 @@ static BAL_CHAMBER_EXEC_STATE_T handleBalChamberConcentrateControl( void ) { BAL_CHAMBER_EXEC_STATE_T state; - F32 freshDialPressure = getFilteredPressure( D18_PRES ); - F32 spentDialPressure = getFilteredPressure( D51_PRES ); + freshDialPressure = getFilteredPressure( D18_PRES ); + spentDialPressure = getFilteredPressure( D51_PRES ); if ( BAL_CHAMBER_SW_STATE1 == balChamberSWState ) { @@ -477,11 +490,11 @@ { if ( BAL_CHAMBER_SW_STATE1 == balChamberSWState ) { - state = BAL_CHAMBER_STATE1_FILL_END; + state = BAL_CHAMBER_STATE1_VALVES_CLOSE; } else { - state = BAL_CHAMBER_STATE2_FILL_END; + state = BAL_CHAMBER_STATE2_VALVES_CLOSE; } } @@ -490,22 +503,18 @@ /*********************************************************************//** * @brief - * The handleBalChamberState1FillEnd function check for the balancing chamber + * The handleBalChamberState1ValvesClose function check for the balancing chamber * fill complete and close the currently opened valves. - * @details \b Inputs: balChamberSWState, spent and fresh dialysate pressure + * @details \b Inputs: currentBalChamberSwitchingCounter, spent and fresh dialysate pressure * @details \b Outputs: isPressureStalbilizedDuringFill,isBalChamberFillInProgress - * @details \b Alarm: ALARM_ID_DD_BC_STATE1_FILL_PRESSURE_DROP_OUT_OF_RANGE - * when pressure drop is not in range during balacing chamber fill in progress. - * @details \b Alarm: ALARM_ID_DD_BC_STATE1_FILL_END_PRESSURE_OUT_OF_RANGE - * when pressure is not in range during balacing chamber fill complete. * @return next balancing chamber state. *************************************************************************/ -static BAL_CHAMBER_EXEC_STATE_T handleBalChamberState1FillEnd( void ) +static BAL_CHAMBER_EXEC_STATE_T handleBalChamberState1ValvesClose( void ) { - BAL_CHAMBER_EXEC_STATE_T state = BAL_CHAMBER_STATE1_FILL_END; + BAL_CHAMBER_EXEC_STATE_T state = BAL_CHAMBER_STATE1_VALVES_CLOSE; - F32 freshDialPressure = getFilteredPressure( D18_PRES ); - F32 spentDialPressure = getFilteredPressure( D51_PRES ); + freshDialPressure = getFilteredPressure( D18_PRES ); + spentDialPressure = getFilteredPressure( D51_PRES ); // Check fresh and spent dialysate pressure back in range to indicate fill complete. if ( getTestConfigStatus( TEST_CONFIG_DISABLE_BC_PRESSURE_ALARMS ) != TRUE ) @@ -517,7 +526,6 @@ { // stabilized pressure indicating fill is complete isPressureStalbilizedDuringFill = TRUE; - isBalChamberFillInProgress = FALSE; } } } @@ -532,8 +540,31 @@ { // close the state 1 opened valves valveControlForBCState1FillEnd(); + isBalChamberFillInProgress = FALSE; + + //Transition to next state + state = BAL_CHAMBER_STATE1_FILL_END; } + return state; +} + +/*********************************************************************//** + * @brief + * The handleBalChamberState1FillEnd function check for the balancing chamber + * switching period and tranistion to next state switching. + * @details \b Inputs: currentBalChamberSwitchingCounter, balChamberSwitchingPeriod + * @details \b Outputs: balChamberFillPressureDropCounter,balChamberFillCompleteStablePressureCounter + * @details \b Alarm: ALARM_ID_DD_BC_STATE1_FILL_PRESSURE_DROP_OUT_OF_RANGE + * when pressure drop is not in range during balacing chamber fill in progress. + * @details \b Alarm: ALARM_ID_DD_BC_STATE1_FILL_END_PRESSURE_OUT_OF_RANGE + * when pressure is not in range during balacing chamber fill complete. + * @return next balancing chamber state. + *************************************************************************/ +static BAL_CHAMBER_EXEC_STATE_T handleBalChamberState1FillEnd( void ) +{ + BAL_CHAMBER_EXEC_STATE_T state = BAL_CHAMBER_STATE1_FILL_END; + // On completion of cycle time, transition to next state if ( currentBalChamberSwitchingCounter >= balChamberSwitchingPeriod ) { @@ -594,10 +625,10 @@ isPressureDroppedDuringFill = FALSE; balChamberSWState = BAL_CHAMBER_SW_STATE2; - F32 freshDialPressure = getFilteredPressure( D18_PRES ); - F32 spentDialPressure = getFilteredPressure( D51_PRES ); F32 acidVolume = getF32OverrideValue( &acidDoseVolume ); F32 bicarbVolume = getF32OverrideValue( &bicarbDoseVolume ); + freshDialPressure = getFilteredPressure( D18_PRES ); + spentDialPressure = getFilteredPressure( D51_PRES ); // Check fresh and spent dialysate pressure in range if ( ( ( freshDialPressure >= FRESH_DIAL_PRESSURE_MIN_PSIG ) && ( freshDialPressure <= FRESH_DIAL_PRESSURE_MAX_PSIG ) ) && @@ -635,22 +666,18 @@ /*********************************************************************//** * @brief - * The handleBalChamberState2FillEnd function check for the balancing chamber + * The handleBalChamberState2ValvesClose function check for the balancing chamber * fill complete and close the currently opened valves. - * @details \b Inputs: balChamberSWState, spent and fresh dialysate pressure + * @details \b Inputs: currentBalChamberSwitchingCounter, spent and fresh dialysate pressure * @details \b Outputs: isPressureStalbilizedDuringFill,isBalChamberFillInProgress - * @details \b Alarm: ALARM_ID_DD_BC_STATE2_FILL_PRESSURE_DROP_OUT_OF_RANGE - * when pressure is not in range during balacing chamber state 2 fill in progress. - * @details \b Alarm: ALARM_ID_DD_BC_STATE2_FILL_END_PRESSURE_OUT_OF_RANGE - * when pressure is not in range during balacing chamber state 2 fill complete. * @return next balancing chamber state. *************************************************************************/ -static BAL_CHAMBER_EXEC_STATE_T handleBalChamberState2FillEnd( void ) +static BAL_CHAMBER_EXEC_STATE_T handleBalChamberState2ValvesClose( void ) { - BAL_CHAMBER_EXEC_STATE_T state = BAL_CHAMBER_STATE2_FILL_END; + BAL_CHAMBER_EXEC_STATE_T state = BAL_CHAMBER_STATE2_VALVES_CLOSE; - F32 freshDialPressure = getFilteredPressure( D18_PRES ); - F32 spentDialPressure = getFilteredPressure( D51_PRES ); + freshDialPressure = getFilteredPressure( D18_PRES ); + spentDialPressure = getFilteredPressure( D51_PRES ); // Check fresh and spent dialysate pressure back in range to indicate fill complete. if ( getTestConfigStatus( TEST_CONFIG_DISABLE_BC_PRESSURE_ALARMS ) != TRUE ) @@ -662,7 +689,6 @@ { // stabilized pressure indicating fill is complete isPressureStalbilizedDuringFill = TRUE; - isBalChamberFillInProgress = FALSE; } } } @@ -677,8 +703,31 @@ { // close the valves valveControlForBCState2FillEnd(); + isBalChamberFillInProgress = FALSE; + + //Transition to next state + state = BAL_CHAMBER_STATE2_FILL_END; } + return state; +} + +/*********************************************************************//** + * @brief + * The handleBalChamberState2FillEnd function check for the balancing chamber + * switching period complete and transition to next state. + * @details \b Inputs: currentBalChamberSwitchingCounter, balChamberSwitchingPeriod + * @details \b Outputs: isPressureStalbilizedDuringFill,isBalChamberFillInProgress + * @details \b Alarm: ALARM_ID_DD_BC_STATE2_FILL_PRESSURE_DROP_OUT_OF_RANGE + * when pressure is not in range during balacing chamber state 2 fill in progress. + * @details \b Alarm: ALARM_ID_DD_BC_STATE2_FILL_END_PRESSURE_OUT_OF_RANGE + * when pressure is not in range during balacing chamber state 2 fill complete. + * @return next balancing chamber state. + *************************************************************************/ +static BAL_CHAMBER_EXEC_STATE_T handleBalChamberState2FillEnd( void ) +{ + BAL_CHAMBER_EXEC_STATE_T state = BAL_CHAMBER_STATE2_FILL_END; + // On completion of cycle time, transition to next state if ( currentBalChamberSwitchingCounter >= balChamberSwitchingPeriod ) { @@ -802,6 +851,19 @@ /*********************************************************************//** * @brief + * The getBalChamberSwitchingPeriod function gets the balancing chamber + * switching period. + * @details \b Inputs: balChamberSwitchingPeriod + * @details \b Outputs: none + * @return balancing chamber switching period + *************************************************************************/ +U32 getBalChamberSwitchingPeriod( void ) +{ + return balChamberSwitchingPeriod; +} + +/*********************************************************************//** + * @brief * The getBalChamberDataPublishInterval function gets the balancing chamber * data publish interval. * @details \b Inputs: balChamberDataPublishInterval