Index: firmware/App/Modes/ModeGenDialysate.c =================================================================== diff -u -r977f03e20990ed5579160b9b927df1c0f2428101 -rc51c9d66062c27c588006850550b412ea7dd5144 --- firmware/App/Modes/ModeGenDialysate.c (.../ModeGenDialysate.c) (revision 977f03e20990ed5579160b9b927df1c0f2428101) +++ firmware/App/Modes/ModeGenDialysate.c (.../ModeGenDialysate.c) (revision c51c9d66062c27c588006850550b412ea7dd5144) @@ -59,6 +59,7 @@ #define LINEAR_SLOPE_FACTOR -0.0029F ///< Slope factor used in adjusted dialysate temperature linear calculation for high Qds #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. //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., @@ -70,7 +71,7 @@ // ********** private data ********** -static DD_GEND_MODE_STATE_T genDialysateState = DD_GEND_STATE_START; ///< Currently active gen dialysate state. +static DD_GEND_MODE_STATE_T genDialysateState; ///< Currently active gen dialysate state. static OVERRIDE_F32_T targetHydChamberFluidTemp; ///< Target hydraulics chamber fluid temperature. static OVERRIDE_U32_T isDialDeliveryInProgress; ///< To indicate dialysate started delivering to dialyzer for treatment (overrideable) static OVERRIDE_U32_T isDialysateGoodtoDeliver; ///< Flag indicating whether ready to deliver dialysate or not. @@ -90,6 +91,8 @@ static DD_GEND_MODE_STATE_T handleGenDDialysateDeliveryPauseState( void ); static DD_GEND_MODE_STATE_T handleGenDSpentChamberFillState(void); static DD_GEND_MODE_STATE_T handleGenDIsolatedUFState( void ); +static F32 getGenDialysateTargetTemperature( void ); +static void calculateTargetDialysateTemp( void ); static void checkDialysateTemperature( void ); static void publishGenDialysateModeData( void ); @@ -195,12 +198,13 @@ break; case DD_GEND_DIALYSATE_BYPASS_STATE: + //Close all balancing chamber valves + valveControlForBCClosedState(); //Previous state setValveState( DD_M4_VALV, VALVE_STATE_OPEN ); - // Get the target temperature from TD - //targetHydChamberFluidTemp.data = getTDTargetDialysateTemperature(); - calculateTargetDialysateTemp(); + // Turn on the primary heater + calculateTargetDialysateTemp(); setHeaterTargetTemperature( D5_HEAT, getGenDialysateTargetTemperature() ); startHeater( D5_HEAT ); @@ -224,8 +228,8 @@ case DD_GEND_DIALYSATE_DELIVERY_STATE: //Previous state setValveState( DD_M4_VALV, VALVE_STATE_OPEN ); - // Get the target temperature from TD - //targetHydChamberFluidTemp.data = getTDTargetDialysateTemperature(); + + // Turn on the primary heater calculateTargetDialysateTemp(); setHeaterTargetTemperature( D5_HEAT, getGenDialysateTargetTemperature() ); startHeater( D5_HEAT ); @@ -242,6 +246,28 @@ setValveState( D40_VALV, VALVE_STATE_OPEN ); // VDO break; + case DD_GEND_SPENT_CHAMBER_FILL_STATE: + //Close all balancing chamber valves + valveControlForBCClosedState(); + transitionToSpentChamberFill(); + + //Set valves and actuators + setValveState( DD_M4_VALV, VALVE_STATE_OPEN ); + + calculateTargetDialysateTemp(); + // Turn on the primary heater + setHeaterTargetTemperature( D5_HEAT, getGenDialysateTargetTemperature() ); + 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 + 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_FILL_RPM, TRUE ); + break; + case DD_GEND_DIALYSATE_DELIVERY_PAUSE: // stop the motor during pause conditions signalDialysatePumpHardStop( D12_PUMP ); @@ -387,7 +413,7 @@ * @details \b Outputs: Adjusted Target temperature * @return none. *************************************************************************/ -void calculateTargetDialysateTemp( void ) +static void calculateTargetDialysateTemp( void ) { // Get the dialysate flow rate from TD F32 dialFlowrate = getTDDialysateFlowrate(); @@ -438,7 +464,8 @@ *************************************************************************/ static DD_GEND_MODE_STATE_T handleGenDDialysateBypassState( void ) { - DD_GEND_MODE_STATE_T state = DD_GEND_DIALYSATE_BYPASS_STATE; + DD_GEND_MODE_STATE_T state = DD_GEND_DIALYSATE_BYPASS_STATE; + LEVEL_STATE_T spentChamberLevel = getLevelStatus( D46_LEVL ); //Testing if ( TRUE == delayBypassStateFlag ) @@ -454,6 +481,14 @@ execBalancingChamberControl(); } +#ifdef __SPENT_CHAMBER_FILL__ + if ( LEVEL_STATE_LOW == spentChamberLevel ) + { + setModeGenDStateTransition( DD_GEND_SPENT_CHAMBER_FILL_STATE ); + isDialDeliveryInProgress.data = FALSE; + state = DD_GEND_SPENT_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() ) ) @@ -476,14 +511,9 @@ *************************************************************************/ static DD_GEND_MODE_STATE_T handleGenDDialysateDeliveryState( void ) { - DD_GEND_MODE_STATE_T state = DD_GEND_DIALYSATE_DELIVERY_STATE; + DD_GEND_MODE_STATE_T state = DD_GEND_DIALYSATE_DELIVERY_STATE; + LEVEL_STATE_T spentChamberLevel = getLevelStatus( D46_LEVL ); - //Execute balancing chamber - execBalancingChamberControl(); - - //Execute ultrafiltration - execUFControl(); - // if TD asks for bypass or dialysate is not good to deliver //transition to bypass dialystate state if ( ( FALSE == getDialGoodToDeliverStatus() ) || ( TRUE == getTDDialyzerBypass() ) ) @@ -492,7 +522,23 @@ isDialDeliveryInProgress.data = FALSE; state = DD_GEND_DIALYSATE_BYPASS_STATE; } +#ifdef __SPENT_CHAMBER_FILL__ + else if ( LEVEL_STATE_LOW == spentChamberLevel ) + { + setModeGenDStateTransition( DD_GEND_SPENT_CHAMBER_FILL_STATE ); + isDialDeliveryInProgress.data = FALSE; + state = DD_GEND_SPENT_CHAMBER_FILL_STATE; + } +#endif + else + { + //Execute balancing chamber + execBalancingChamberControl(); + //Execute ultrafiltration + execUFControl(); + } + return state; } /*********************************************************************//** @@ -508,9 +554,11 @@ DD_GEND_MODE_STATE_T state = DD_GEND_SPENT_CHAMBER_FILL_STATE; LEVEL_STATE_T spentChamberLevel = getLevelStatus( D46_LEVL ); + U32 totalSpentChamberFill = getTotalSpentChamberFillCounts(); - // High level is met - if ( LEVEL_STATE_HIGH == spentChamberLevel ) + // High level is met or total fill count exceeded + if ( ( LEVEL_STATE_HIGH == spentChamberLevel ) || + ( totalSpentChamberFill >= SPENT_CHAMBER_FILL_MAX_COUNT ) ) { setModeGenDStateTransition( DD_GEND_DIALYSATE_BYPASS_STATE ); isDialDeliveryInProgress.data = FALSE; @@ -678,7 +726,7 @@ * @details \b Outputs: none * @return the target dialysate temperature for the treatment. *************************************************************************/ -F32 getGenDialysateTargetTemperature( void ) +static F32 getGenDialysateTargetTemperature( void ) { F32 temp = getF32OverrideValue( &targetHydChamberFluidTemp );