Index: firmware/App/Controllers/ConcentratePumps.h =================================================================== diff -u -rf2b23abd44f71103b3ef6b0a96f18cc82d263735 -r0a74bcce6674271e35d5154003dd6c25011f80f9 --- firmware/App/Controllers/ConcentratePumps.h (.../ConcentratePumps.h) (revision f2b23abd44f71103b3ef6b0a96f18cc82d263735) +++ firmware/App/Controllers/ConcentratePumps.h (.../ConcentratePumps.h) (revision 0a74bcce6674271e35d5154003dd6c25011f80f9) @@ -31,13 +31,10 @@ // ********** public definitions ********** #ifdef __DIENER_CONC_PUMP__ -// For 100 RPM, Diener pump delivers 40ml/min,so restricing 300 RPM for now to maintain accuracy. We may allow up to 500 RPM -// that yields 200 ml/min, but as speed increases, accuracy may drop. -#define CONCENTRATE_PUMP_MAX_SPEED 120.0F ///< Optimal speed for concentrate pump in mL/min -#define UF_PUMP_SPEED 100.0F ///< 100 ml/min, runs at 250 RPM +// For 150 RPM, Diener pump delivers 60ml/min +#define CONCENTRATE_PUMP_MAX_SPEED 60.0F ///< Optimal speed for concentrate pump in mL/min #else #define CONCENTRATE_PUMP_MAX_SPEED 48.0F ///< Maximum speed for concentrate pump in mL/min -#define UF_PUMP_SPEED 40.0F ///< 40 ml/min, runs at 400 RPM #endif #define DEFAULT_ACID_VOLUME_ML 0.67F ///< Acid concentrate volume in ml. #define DEFAULT_BICARB_VOLUME_ML 1.15F ///< Bicarb concentrate volume in ml. Index: firmware/App/Controllers/Heaters.c =================================================================== diff -u -rc7dcaa774c66053bcf0a52d56068d1960187bae1 -r0a74bcce6674271e35d5154003dd6c25011f80f9 --- firmware/App/Controllers/Heaters.c (.../Heaters.c) (revision c7dcaa774c66053bcf0a52d56068d1960187bae1) +++ firmware/App/Controllers/Heaters.c (.../Heaters.c) (revision 0a74bcce6674271e35d5154003dd6c25011f80f9) @@ -127,7 +127,8 @@ static U32 dataPublicationTimerCounter; ///< Data publication timer counter. static U32 primaryTargetTempAdjCounter; ///< Primary target temperature adjustment counter. static BOOL isTargetTempAdjusted; ///< Flag indicating that target temperature is adjusted -static U32 adjustedPrimaryTargetTemp; ///< Adjusted primary target temperature +static U32 adjustedPrimaryTargetTemp; ///< Adjusted primary target temperature +static BOOL isDialyzerTempFeedbackEnabled; ///< Flag indicating enable/disable the dilayser temp ( D28) based feedback adjustment static const F32 WATER_SPECIFIC_HEAT_DIVIDED_BY_MINUTES = 4184.0F / (F32)SEC_PER_MIN; ///< Water specific heat in J/KgC / 60. static OVERRIDE_U32_T heatersDataPublishInterval = { HEATERS_DATA_PUBLISH_INTERVAL, HEATERS_DATA_PUBLISH_INTERVAL, 0, 0 }; ///< Heaters data publish time interval. static F32 convertDC; ///< AC Heater converted duty cycle @@ -198,6 +199,7 @@ primaryTargetTempAdjCounter = 0; adjustedPrimaryTargetTemp = 0.0F; isTargetTempAdjusted = FALSE; + isDialyzerTempFeedbackEnabled = TRUE; for ( heater = DD_HEATERS_FIRST; heater < NUM_OF_DD_HEATERS; heater++ ) { @@ -336,6 +338,19 @@ /*********************************************************************//** * @brief + * The setD28TempFeedbackControl function enables/disables the D28 based + * heater control (outer control loop ). + * @details \b Inputs: none + * @details \b Outputs: setD28TempFeedbackControl + * @param enable: Enables/disables the D28 based heater control. + *************************************************************************/ +void setD28TempFeedbackControl( BOOL enable ) +{ + isDialyzerTempFeedbackEnabled = enable; +} + +/*********************************************************************//** + * @brief * The signalHeaterControlOnQDUpdate function updates heater control based on * the latest treatment paratmeter (Dialysate Flow rate) change * @details \b Inputs: heatersStatus @@ -728,7 +743,9 @@ { F32 deltaTempC = 0.0F; - if ( TRUE == isTargetTempAdjusted ) + // If D28 feedback control is enabled and adjusted temp calculation is done + // then update the target temperature. + if ( ( TRUE == isTargetTempAdjusted ) && ( TRUE == isDialyzerTempFeedbackEnabled ) ) { targetTemperature = adjustedPrimaryTargetTemp; } Index: firmware/App/Controllers/Heaters.h =================================================================== diff -u -r4d529ed12453439c30f85108ce8b357a3df83348 -r0a74bcce6674271e35d5154003dd6c25011f80f9 --- firmware/App/Controllers/Heaters.h (.../Heaters.h) (revision 4d529ed12453439c30f85108ce8b357a3df83348) +++ firmware/App/Controllers/Heaters.h (.../Heaters.h) (revision 0a74bcce6674271e35d5154003dd6c25011f80f9) @@ -77,6 +77,7 @@ F32 getHeaterTargetTemperature( DD_HEATERS_T heater ); void signalHeaterControlOnQDUpdate( DD_HEATERS_T heater ); void signaltoResetPrimaryHeaterAdjustedTargetTemp( void ); +void setD28TempFeedbackControl( BOOL enable ); BOOL isHeaterOn( DD_HEATERS_T heater ); void stopHeater( DD_HEATERS_T heater ); void execHeatersControl( void ); Index: firmware/App/Controllers/SpentChamberFill.c =================================================================== diff -u -rc7dcaa774c66053bcf0a52d56068d1960187bae1 -r0a74bcce6674271e35d5154003dd6c25011f80f9 --- firmware/App/Controllers/SpentChamberFill.c (.../SpentChamberFill.c) (revision c7dcaa774c66053bcf0a52d56068d1960187bae1) +++ firmware/App/Controllers/SpentChamberFill.c (.../SpentChamberFill.c) (revision 0a74bcce6674271e35d5154003dd6c25011f80f9) @@ -47,13 +47,17 @@ static U32 currentSpentChamberFillSwitchingCounter; ///< Counter (in task interval) to monitor the timing spent during spent chamber fill operation. static U32 totalSpentChamberfillCounter; ///< Counter (in task interval) to monitor the total number of spent chamber fill operation. static U32 spentChamberFillDataPublicationTimerCounter; ///< Used to schedule spent chamber fill data publication to CAN bus. +static F32 acidDoseVolume; ///< Acid concentrate volume in ml +static F32 bicarbDoseVolume; ///< Bicarb concentrate volume in ml static OVERRIDE_U32_T spentChamberFillDataPublishInterval; ///< Spent chamber fill data publish interval. // ********** private function prototypes ********** static SPENT_CHAMBER_FILL_EXEC_STATE_T handleSpentChamberFillState1FillStart( void ); +static SPENT_CHAMBER_FILL_EXEC_STATE_T handleSpentChamberState1DosingControl( void ); static SPENT_CHAMBER_FILL_EXEC_STATE_T handleSpentChamberFillState1FillEnd(void); static SPENT_CHAMBER_FILL_EXEC_STATE_T handleSpentChamberFillState2FillStart( void ); +static SPENT_CHAMBER_FILL_EXEC_STATE_T handleSpentChamberState2DosingControl( void ); static SPENT_CHAMBER_FILL_EXEC_STATE_T handleSpentChamberFillState2FillEnd(void); static void publishSpentChamberFillData( void ); @@ -71,6 +75,8 @@ spentChamberFillDataPublishInterval.ovData = SPENT_CHAMBER_FILL_DATA_PUBLISH_INTERVAL; spentChamberFillDataPublishInterval.ovInitData = 0; spentChamberFillDataPublishInterval.override = OVERRIDE_RESET; + acidDoseVolume = DEFAULT_ACID_VOLUME_ML; + bicarbDoseVolume = DEFAULT_BICARB_VOLUME_ML; spentChamberFillSwitchingPeriod = 0; currentSpentChamberFillSwitchingCounter = 0; spentChamberFillDataPublicationTimerCounter = 0; @@ -119,6 +125,10 @@ spentChamberFillExecState = handleSpentChamberFillState1FillStart(); break; + case SPENT_CHAMBER_FILL_STATE1_DOSING_CNTRL: + spentChamberFillExecState = handleSpentChamberState1DosingControl(); + break; + case SPENT_CHAMBER_FILL_STATE1_FILL_END: spentChamberFillExecState = handleSpentChamberFillState1FillEnd(); break; @@ -127,6 +137,10 @@ spentChamberFillExecState = handleSpentChamberFillState2FillStart(); break; + case SPENT_CHAMBER_FILL_STATE2_DOSING_CNTRL: + spentChamberFillExecState = handleSpentChamberState2DosingControl(); + break; + case SPENT_CHAMBER_FILL_STATE2_FILL_END: spentChamberFillExecState = handleSpentChamberFillState2FillEnd(); break; @@ -195,7 +209,7 @@ * state 1 fill operations. * @details \b Inputs: fresh and spent dialysate pressure * @details \b Outputs: valve states,current spent chamber fill state - * @details \b Alarm: ALARM_ID_DD_BC_STATE1_FILL_START_PRESSURE_OUT_OF_RANGE + * @details \b Alarm: ALARM_ID_DD_SC_STATE1_FILL_START_PRESSURE_OUT_OF_RANGE * when pressure is not in range during balacing chamber fill start. * @return next spent chamber fill state. *************************************************************************/ @@ -213,8 +227,11 @@ { //Valve control for state 1 spent chamber fill valveControlForSCFillState1FillStart(); + // start acid and bicarb pump with the expected quantity + setConcentratePumpTargetSpeed( D11_PUMP, CONCENTRATE_PUMP_MAX_SPEED, acidDoseVolume ); + setConcentratePumpTargetSpeed( D10_PUMP, CONCENTRATE_PUMP_MAX_SPEED, bicarbDoseVolume ); - state = SPENT_CHAMBER_FILL_STATE1_FILL_END; + state = SPENT_CHAMBER_FILL_STATE1_DOSING_CNTRL; } else { @@ -227,6 +244,28 @@ /*********************************************************************//** * @brief + * The handleSpentChamberState1DosingControl function checks the completion of + * the Acid and Bicarb concentrate dosing. + * @details \b Inputs: Dosing pump completion status + * @details \b Outputs: state + * @return next spent chamber fill state. + *************************************************************************/ +static SPENT_CHAMBER_FILL_EXEC_STATE_T handleSpentChamberState1DosingControl( void ) +{ + SPENT_CHAMBER_FILL_EXEC_STATE_T state = SPENT_CHAMBER_FILL_STATE1_DOSING_CNTRL; + + // On dosing completion, transition to next state + if ( ( TRUE == isConcentratePumpDosingCompleted( D11_PUMP ) ) && + ( TRUE == isConcentratePumpDosingCompleted( D10_PUMP ) ) ) + { + state = SPENT_CHAMBER_FILL_STATE1_FILL_END; + } + + return state; +} + +/*********************************************************************//** + * @brief * The handleSpentChamberFillState1FillEnd function check for the spent chamber * fill switching period and tranistion to next state. * @details \b Inputs: currentSpentChamberFillSwitchingCounter,spentChamberFillSwitchingPeriod @@ -257,7 +296,7 @@ * state 2 fill operations. * @details \b Inputs: fresh and spent dialysate pressure * @details \b Outputs: balancing chamber valves state - * @details \b Alarm: ALARM_ID_DD_BC_STATE2_FILL_START_PRESSURE_OUT_OF_RANGE + * @details \b Alarm: ALARM_ID_DD_SC_STATE2_FILL_START_PRESSURE_OUT_OF_RANGE * when pressure is not in range during balacing chamber state 2 fill start. * @return next spent chamber fill state. *************************************************************************/ @@ -275,8 +314,11 @@ { // Valve control for state 2 fill valveControlForSCFillState2FillStart(); + // start acid and bicarb pump with the expected quantity + setConcentratePumpTargetSpeed( D11_PUMP, CONCENTRATE_PUMP_MAX_SPEED, acidDoseVolume ); + setConcentratePumpTargetSpeed( D10_PUMP, CONCENTRATE_PUMP_MAX_SPEED, bicarbDoseVolume ); - state = SPENT_CHAMBER_FILL_STATE2_FILL_END; + state = SPENT_CHAMBER_FILL_STATE2_DOSING_CNTRL; } else { @@ -288,6 +330,28 @@ /*********************************************************************//** * @brief + * The handleSpentChamberState2DosingControl function checks the completion of + * the Acid and Bicarb concentrate dosing. + * @details \b Inputs: Dosing pump completion status + * @details \b Outputs: state + * @return next spent chamber fill state. + *************************************************************************/ +static SPENT_CHAMBER_FILL_EXEC_STATE_T handleSpentChamberState2DosingControl( void ) +{ + SPENT_CHAMBER_FILL_EXEC_STATE_T state = SPENT_CHAMBER_FILL_STATE2_DOSING_CNTRL; + + // On dosing completion, transition to next state + if ( ( TRUE == isConcentratePumpDosingCompleted( D11_PUMP ) ) && + ( TRUE == isConcentratePumpDosingCompleted( D10_PUMP ) ) ) + { + state = SPENT_CHAMBER_FILL_STATE2_FILL_END; + } + + return state; +} + +/*********************************************************************//** + * @brief * The handleSpentChamberFillState2FillEnd function check for the spent chamber * switching period complete and transition to next state. * @details \b Inputs: currentSpentChamberFillSwitchingCounter,spentChamberFillSwitchingPeriod Index: firmware/App/DDCommon.h =================================================================== diff -u -r977f03e20990ed5579160b9b927df1c0f2428101 -r0a74bcce6674271e35d5154003dd6c25011f80f9 --- firmware/App/DDCommon.h (.../DDCommon.h) (revision 977f03e20990ed5579160b9b927df1c0f2428101) +++ firmware/App/DDCommon.h (.../DDCommon.h) (revision 0a74bcce6674271e35d5154003dd6c25011f80f9) @@ -57,6 +57,9 @@ //Uncomment below for spent chamber filling #define __SPENT_CHAMBER_FILL__ 1 +//Uncomment below for bicarb chamber filling +#define __BICARB_CHAMBER_FILL__ 1 + //Uncomment below if balancing chamber pressure alarm is required #define __BC_PRESSURE_ALARM__ 1 Index: firmware/App/Modes/ModeGenDialysate.c =================================================================== diff -u -r89cf53e72625123054b11897c2e0a8359d82b7ce -r0a74bcce6674271e35d5154003dd6c25011f80f9 --- firmware/App/Modes/ModeGenDialysate.c (.../ModeGenDialysate.c) (revision 89cf53e72625123054b11897c2e0a8359d82b7ce) +++ firmware/App/Modes/ModeGenDialysate.c (.../ModeGenDialysate.c) (revision 0a74bcce6674271e35d5154003dd6c25011f80f9) @@ -60,7 +60,7 @@ #define LINEAR_INTERCEPT_FACTOR 3.47F ///< Intercept factor used in adjusted dialysate temperature linear calculation for high Qds #define LOW_DIAL_FLOW_RATE 150.0F ///< Dialysate flow rate lesser than 150 considered to be low Qds. #define SPENT_CHAMBER_FILL_MAX_COUNT 7 ///< Total number of spent chamber fill allowed. - +#define BICARB_CHAMBER_FILL_TIMEOUT ( 1 * MS_PER_SECOND ) ///< Bicarb chamber fill timeout. //Testing #define DELAY_BC_SWITCHING_AT_START_UP ( 10 * MS_PER_SECOND ) ///< Provide a balancing chamber switching start up delay to stabilize pump speed etc., /// Payload record structure for Gen dialysate execution state set request @@ -79,6 +79,7 @@ static U32 genDialysateDataPublicationTimerCounter; ///< Used to schedule generate dialysate data publication to CAN bus. static OVERRIDE_U32_T genDialysateDataPublishInterval; ///< Generate dialysate mode data publish interval. static BOOL isTreatmentParamUpdated; ///< To indicate change in treatment parameters +static U32 bicarbFillStartTimeMS; ///< Bicarb fill start time to check the timeout for filling process. //Testing static U32 bypassStateDelayStartTimeMS; ///< Delay balancing chamber switching for a second to preapre pump steady state. static BOOL delayBypassStateFlag; ///< To indicate change in treatment parameters @@ -90,6 +91,7 @@ static DD_GEND_MODE_STATE_T handleGenDDialysateDeliveryState( void ); static DD_GEND_MODE_STATE_T handleGenDDialysateDeliveryPauseState( void ); static DD_GEND_MODE_STATE_T handleGenDSpentChamberFillState(void); +static DD_GEND_MODE_STATE_T handleGenDBicarbChamberFillState( void ); static DD_GEND_MODE_STATE_T handleGenDIsolatedUFState( void ); static F32 getGenDialysateTargetTemperature( void ); static void calculateTargetDialysateTemp( void ); @@ -125,6 +127,7 @@ genDialysateDataPublishInterval.override = OVERRIDE_RESET; genDialysateDataPublicationTimerCounter = 0; isTreatmentParamUpdated = FALSE; + bicarbFillStartTimeMS = 0; //Testing bypassStateDelayStartTimeMS = 0; delayBypassStateFlag = TRUE; @@ -200,43 +203,46 @@ case DD_GEND_DIALYSATE_BYPASS_STATE: //Close all balancing chamber valves valveControlForBCClosedState(); - //Previous state setValveState( DD_M4_VALV, VALVE_STATE_OPEN ); + setValveState( D14_VALV, VALVE_STATE_OPEN ); + setValveState( D53_VALV, VALVE_STATE_OPEN ); // Drain valve + setValveState( D35_VALV, VALVE_STATE_CLOSED ); // VDI + setValveState( D40_VALV, VALVE_STATE_CLOSED ); // VDO + setValveState( D34_VALV, VALVE_STATE_OPEN ); // Bypass valve // Turn on the primary heater calculateTargetDialysateTemp(); setHeaterTargetTemperature( D5_HEAT, getGenDialysateTargetTemperature() ); + setD28TempFeedbackControl( TRUE ); startHeater( D5_HEAT ); - setValveState( D14_VALV, VALVE_STATE_OPEN ); //Testing : Enable close loop once testing is complete //setDialysatePumpTargetRPM( D12_PUMP, FRESH_DIAL_PUMP_INITIAL_RPM, FALSE ); setDialysatePumpTargetRPM( D12_PUMP, FRESH_DIAL_PUMP_INITIAL_RPM, TRUE ); - setValveState( D53_VALV, VALVE_STATE_OPEN ); // Drain valve - setValveState( D35_VALV, VALVE_STATE_CLOSED ); // VDI - setValveState( D40_VALV, VALVE_STATE_CLOSED ); // VDO - setValveState( D34_VALV, VALVE_STATE_OPEN ); // Bypass valve //setDialysatePumpTargetRPM( D48_PUMP, SPENT_DIAL_PUMP_INITIAL_RPM, FALSE ); setDialysatePumpTargetRPM( D48_PUMP, SPENT_DIAL_PUMP_INITIAL_RPM, TRUE ); transitionToBalChamberFill(); //Testing bypassStateDelayStartTimeMS = getMSTimerCount(); + delayBypassStateFlag = TRUE; break; case DD_GEND_DIALYSATE_DELIVERY_STATE: //Previous state setValveState( DD_M4_VALV, VALVE_STATE_OPEN ); + setValveState( D14_VALV, VALVE_STATE_OPEN ); + setValveState( D53_VALV, VALVE_STATE_OPEN ); // Drain valve // Turn on the primary heater calculateTargetDialysateTemp(); setHeaterTargetTemperature( D5_HEAT, getGenDialysateTargetTemperature() ); + setD28TempFeedbackControl( TRUE ); startHeater( D5_HEAT ); - setValveState( D14_VALV, VALVE_STATE_OPEN ); + //setDialysatePumpTargetRPM( D12_PUMP, FRESH_DIAL_PUMP_INITIAL_RPM, FALSE ); setDialysatePumpTargetRPM( D12_PUMP, FRESH_DIAL_PUMP_INITIAL_RPM, TRUE ); - setValveState( D53_VALV, VALVE_STATE_OPEN ); // Drain valve //setDialysatePumpTargetRPM( D48_PUMP, SPENT_DIAL_PUMP_INITIAL_RPM, FALSE ); setDialysatePumpTargetRPM( D48_PUMP, SPENT_DIAL_PUMP_INITIAL_RPM, TRUE ); @@ -249,24 +255,61 @@ case DD_GEND_SPENT_CHAMBER_FILL_STATE: //Close all balancing chamber valves valveControlForBCClosedState(); - transitionToSpentChamberFill(); - //Set valves and actuators + setValveState( D35_VALV, VALVE_STATE_CLOSED ); // VDI + setValveState( D40_VALV, VALVE_STATE_CLOSED ); // VDO + setValveState( DD_M4_VALV, VALVE_STATE_OPEN ); + setValveState( D14_VALV, VALVE_STATE_OPEN ); + setValveState( D53_VALV, VALVE_STATE_OPEN ); // Drain valve + setValveState( D34_VALV, VALVE_STATE_OPEN ); // Bypass valve + setValveState( D47_VALV, VALVE_STATE_OPEN ); // Spent chamber purge valve - calculateTargetDialysateTemp(); + requestConcentratePumpOff( D76_PUMP, FALSE ); + requestConcentratePumpOff( D11_PUMP, FALSE ); + requestConcentratePumpOff( D10_PUMP, FALSE ); + // Turn on the primary heater + calculateTargetDialysateTemp(); setHeaterTargetTemperature( D5_HEAT, getGenDialysateTargetTemperature() ); + setD28TempFeedbackControl( TRUE ); startHeater( D5_HEAT ); - setValveState( D14_VALV, VALVE_STATE_OPEN ); setDialysatePumpTargetRPM( D12_PUMP, FRESH_DIAL_PUMP_INITIAL_RPM, TRUE ); - setValveState( D53_VALV, VALVE_STATE_OPEN ); // Drain valve + setDialysatePumpTargetRPM( D48_PUMP, SPENT_DIAL_PUMP_FILL_RPM, TRUE ); + + //Transition to spent chamber fill + transitionToSpentChamberFill(); + break; + + case DD_GEND_BICARB_CHAMBER_FILL_STATE: + //Close all balancing chamber valves + valveControlForBCClosedState(); + requestConcentratePumpOff( D11_PUMP, FALSE ); + requestConcentratePumpOff( D10_PUMP, FALSE ); + requestConcentratePumpOff( D76_PUMP, FALSE ); + + //Set valves and actuators + setValveState( D47_VALV, VALVE_STATE_CLOSED ); // Spent chamber purge valve setValveState( D35_VALV, VALVE_STATE_CLOSED ); // VDI setValveState( D40_VALV, VALVE_STATE_CLOSED ); // VDO + setValveState( D14_VALV, VALVE_STATE_CLOSED ); + + setValveState( D53_VALV, VALVE_STATE_OPEN ); // Drain valve setValveState( D34_VALV, VALVE_STATE_OPEN ); // Bypass valve - setValveState( D47_VALV, VALVE_STATE_OPEN ); // Spent chamber purge valve - setDialysatePumpTargetRPM( D48_PUMP, SPENT_DIAL_PUMP_FILL_RPM, TRUE ); + setValveState( DD_M4_VALV, VALVE_STATE_OPEN ); + setValveState( D64_VALV, VALVE_STATE_OPEN ); // Bicarb chamber purge valve + bicarbFillStartTimeMS = getMSTimerCount(); + + // Turn on the primary heater + calculateTargetDialysateTemp(); + setHeaterTargetTemperature( D5_HEAT, getGenDialysateTargetTemperature() ); + //Disable the D28 based temp control as fluid dispense being stopped by balancing chamber. + setD28TempFeedbackControl( FALSE ); + startHeater( D5_HEAT ); + + setDialysatePumpTargetRPM( D12_PUMP, FRESH_DIAL_PUMP_INITIAL_RPM, TRUE ); + setDialysatePumpTargetRPM( D48_PUMP, SPENT_DIAL_PUMP_INITIAL_RPM, TRUE ); break; case DD_GEND_DIALYSATE_DELIVERY_PAUSE: @@ -284,8 +327,6 @@ setValveState( D35_VALV, VALVE_STATE_CLOSED ); // VDI setValveState( D40_VALV, VALVE_STATE_CLOSED ); // VDO setValveState( D34_VALV, VALVE_STATE_OPEN ); // Bypass valve - - //TODO : close the DD - water inlet and drain valves? break; case DD_GEND_ISOLATED_UF_STATE: @@ -350,6 +391,10 @@ genDialysateState = handleGenDSpentChamberFillState(); break; + case DD_GEND_BICARB_CHAMBER_FILL_STATE: + genDialysateState = handleGenDBicarbChamberFillState(); + break; + case DD_GEND_DIALYSATE_DELIVERY_PAUSE: genDialysateState = handleGenDDialysateDeliveryPauseState(); break; @@ -465,8 +510,9 @@ *************************************************************************/ static DD_GEND_MODE_STATE_T handleGenDDialysateBypassState( void ) { - DD_GEND_MODE_STATE_T state = DD_GEND_DIALYSATE_BYPASS_STATE; - LEVEL_STATE_T spentChamberLevel = getLevelStatus( D46_LEVL ); + DD_GEND_MODE_STATE_T state = DD_GEND_DIALYSATE_BYPASS_STATE; + LEVEL_STATE_T spentChamberLevel = getLevelStatus( D46_LEVL ); + LEVEL_STATE_T bicarbChamberLevel = getLevelStatus( D63_LEVL ); //Testing if ( TRUE == delayBypassStateFlag ) @@ -490,6 +536,14 @@ state = DD_GEND_SPENT_CHAMBER_FILL_STATE; } #endif +#ifdef __BICARB_CHAMBER_FILL__ + if ( LEVEL_STATE_LOW == bicarbChamberLevel ) + { + setModeGenDStateTransition( DD_GEND_BICARB_CHAMBER_FILL_STATE ); + isDialDeliveryInProgress.data = FALSE; + state = DD_GEND_BICARB_CHAMBER_FILL_STATE; + } +#endif //if the produced dialysate is good and TD asks for dialysate delivery //move to next state if ( ( TRUE == getDialGoodToDeliverStatus() ) && ( FALSE == getTDDialyzerBypass() ) ) @@ -512,8 +566,9 @@ *************************************************************************/ static DD_GEND_MODE_STATE_T handleGenDDialysateDeliveryState( void ) { - DD_GEND_MODE_STATE_T state = DD_GEND_DIALYSATE_DELIVERY_STATE; - LEVEL_STATE_T spentChamberLevel = getLevelStatus( D46_LEVL ); + DD_GEND_MODE_STATE_T state = DD_GEND_DIALYSATE_DELIVERY_STATE; + LEVEL_STATE_T spentChamberLevel = getLevelStatus( D46_LEVL ); + LEVEL_STATE_T bicarbChamberLevel = getLevelStatus( D63_LEVL ); // if TD asks for bypass or dialysate is not good to deliver //transition to bypass dialystate state @@ -531,6 +586,14 @@ state = DD_GEND_SPENT_CHAMBER_FILL_STATE; } #endif +#ifdef __BICARB_CHAMBER_FILL__ + else if ( LEVEL_STATE_LOW == bicarbChamberLevel ) + { + setModeGenDStateTransition( DD_GEND_BICARB_CHAMBER_FILL_STATE ); + isDialDeliveryInProgress.data = FALSE; + state = DD_GEND_BICARB_CHAMBER_FILL_STATE; + } +#endif else { //Execute balancing chamber @@ -542,11 +605,12 @@ return state; } + /*********************************************************************//** * @brief * The handleGenDSpentChamberFillState function performing spent * chamber filling/degassing by executing balancing chamber. - * @details \b Inputs: none + * @details \b Inputs: D46 level. * @details \b Outputs: balancing chamber state. * @return the current state of gen dialysate mode *************************************************************************/ @@ -578,7 +642,43 @@ } return state; +} +/*********************************************************************//** + * @brief + * The handleGenDBicarbChamberFillState function performing Bicarb + * chamber filling/degassing by opening up the purge valve which is connected + * to negative pressure chamber D of Hydraulics chamber. + * @details \b Inputs: D63 level. + * @details \b Outputs: isBicarbFillTimeout,valves actuation. + * @return the current state of gen dialysate mode + *************************************************************************/ +static DD_GEND_MODE_STATE_T handleGenDBicarbChamberFillState( void ) +{ + DD_GEND_MODE_STATE_T state = DD_GEND_BICARB_CHAMBER_FILL_STATE; + + LEVEL_STATE_T bicarbChamberLevel = getLevelStatus( D63_LEVL ); + BOOL isBicarbFillTimeout = FALSE; + + if ( TRUE == didTimeout( bicarbFillStartTimeMS, BICARB_CHAMBER_FILL_TIMEOUT ) ) + { + isBicarbFillTimeout = TRUE; + // Raise alarm for bicarb fill timeout + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DD_BICARB_FILL_TIMEOUT_FAULT, BICARB_CHAMBER_FILL_TIMEOUT, 0 ) + } + + // High level is met or fill timeout + if ( ( LEVEL_STATE_HIGH == bicarbChamberLevel ) || ( TRUE == isBicarbFillTimeout ) ) + { + setValveState( D64_VALV, VALVE_STATE_CLOSED ); // Close Bicarb chamber purge valve + bicarbFillStartTimeMS = 0; + + setModeGenDStateTransition( DD_GEND_DIALYSATE_BYPASS_STATE ); + isDialDeliveryInProgress.data = FALSE; + state = DD_GEND_DIALYSATE_BYPASS_STATE; + } + + return state; } /*********************************************************************//**