Index: firmware/App/Controllers/BalancingChamber.c =================================================================== diff -u -rb0da135bc589efaf8ad6f3c8c1988dcb672f3ca0 -r902889c30391b6ca8c9f19adfd3c841c86a5d49f --- firmware/App/Controllers/BalancingChamber.c (.../BalancingChamber.c) (revision b0da135bc589efaf8ad6f3c8c1988dcb672f3ca0) +++ firmware/App/Controllers/BalancingChamber.c (.../BalancingChamber.c) (revision 902889c30391b6ca8c9f19adfd3c841c86a5d49f) @@ -268,14 +268,11 @@ #ifdef CONDUCTIVE_LEVEL_SENSOR_ENABLED if ( LVL_STATE_LOW == bicarbChamberLevel ) { - if ( getCurrentBalancingChamberExecState() > BAL_CHAMBER_STATE_IDLE ) + if ( FALSE == setBicarbChamberFillRequested() ) { - if ( FALSE == setBicarbChamberFillRequested() ) - { - // TODO - //drybicart state machines are combined and so this is not an issue in future - //set alarm ? - } + // TODO + //drybicart state machines are combined and so this is not an issue in future + //set alarm ? } } #else // time based chamber F fill Index: firmware/App/Controllers/DryBiCart.c =================================================================== diff -u -rb0da135bc589efaf8ad6f3c8c1988dcb672f3ca0 -r902889c30391b6ca8c9f19adfd3c841c86a5d49f --- firmware/App/Controllers/DryBiCart.c (.../DryBiCart.c) (revision b0da135bc589efaf8ad6f3c8c1988dcb672f3ca0) +++ firmware/App/Controllers/DryBiCart.c (.../DryBiCart.c) (revision 902889c30391b6ca8c9f19adfd3c841c86a5d49f) @@ -48,11 +48,13 @@ #define DRY_BICART_FILL_DURATION_MIN_MS ( 2 * MS_PER_SECOND ) ///< Minimum fill duration to be met to end the fill cycle. #define DRY_BICART_FILL_COMPLETE_TIME_MS ( 1 * MS_PER_SECOND ) ///< Wait time to reset the request flag after fill complete #define DRY_BICART_FILL_DURATION_DIFF_MS 750 ///< Fill duration difference between last and current fill cycle. -#define PRESSURE_OFFSET 2 ///< Dry bicart pressure offset -#define DRY_BICART_FILL_COMPLETE_PRESSURE ( 10.0F + PRESSURE_OFFSET ) ///< Maximum pressure reached to indicate the dry bicart fill being completed. -#define DRY_BICART_FILL_INITIATE_PRESSURE 3.0F ///< Minimum pressure required to initiate the dry bicart fill process. + +#define PRESSURE_OFFSET_PSI 1 ///< Dry bicart pressure offset. +#define DRY_BICART_FILL_COMPLETE_PRESSURE ( 10.0F + PRESSURE_OFFSET_PSI ) ///< Maximum pressure reached to indicate the dry bicart fill being completed. +#define DRY_BICART_FILL_INITIATE_PRESSURE 1.5F ///< Minimum pressure required to initiate the dry bicart fill process. #define DRY_BICART_FILL_COMPLETE_SUPPLY_PRESSURE 6.0F ///< Maximum pressure allowed at bicart fill during supply process/state #define DRY_BICART_FILL_INITIATE_SUPPLY_PRESSURE 3.0F ///< Minimum pressure required to initiate the dry bicart fill during supply process/state +#define MAX_DRY_BICART_FILL_COMPLETE_PRESSURE 15 ///< Very Max dry bicart fill complete pressure for perisistence on d66 #define DRY_BICART_DEFAULT_MAX_FILL_CYCLE_CNT 10 ///< Default max fill cycle allowed for dry bicart fill/mix with water. #define DRY_BICART_MAX_FILL_CYCLE_CNT 30 ///< Max fill cycle allowed (by override) for dry bicart fill/mix with water. @@ -63,12 +65,13 @@ // Bicarb chamber fill/Supply #ifdef CONDUCTIVE_LEVEL_SENSOR_ENABLED -#define DRY_BICART_SUPPLY_VALVE_D80_TIMEOUT_MS ( 10 * MS_PER_SECOND ) ///< Max time allowed for supply (opening D80 valve) during bicarb chamber (F) fill. +#define DRY_BICART_SUPPLY_VALVE_D80_OPEN_TIME_MS ( 10 * MS_PER_SECOND ) ///< Max time allowed for supply (opening D80 valve) during bicarb chamber (F) fill using level sensor #else -#define DRY_BICART_SUPPLY_VALVE_D80_TIMEOUT_MS ( 3 * MS_PER_SECOND ) ///< Max time allowed for supply (opening D80 valve) during bicarb chamber (F) fill. +#define DRY_BICART_SUPPLY_VALVE_D80_OPEN_TIME_MS ( 3 * MS_PER_SECOND ) ///< Max time allowed for supply (opening D80 valve) during bicarb chamber (F) fill time based fill #endif #define DRY_BICART_SUPPLY_VENT_TIME_MS ( 1 * MS_PER_SECOND ) ///< Wait time to vent dry bicart gas before actuating Bicarb chamber(F) venting. -#define DRY_BICART_SUPPLY_VENT_MAX_TIME_MS ( 1.1 * MS_PER_SECOND ) ///< Max time to vent both dry bicart and Chamber F. +#define DRY_BICART_SUPPLY_VENT_MAX_TIME_MS ( 1 * MS_PER_SECOND ) ///< Max time to vent both dry bicart and Chamber F. +#define DRY_BICART_SUPPLY_COMPLETE_TIME_MS ( 2 * MS_PER_SECOND ) ///< Wait time to close the D80 valve after D65 is closed // Dry Bicart Drain #define LARGE_DRY_BICART_MAX_DRAIN_TIME_MS ( 8 * SEC_PER_MIN * MS_PER_SECOND ) ///< Max drain time for large dry bicart in ms. @@ -80,8 +83,8 @@ #define DRY_BICART_DRAIN_COND_STABLE_SAMPLES 10U ///< Debounce samples (10*50ms=500ms) // drybicarb mixing -#define BICARB_VOL_CONTROL_P_COEFFICIENT 0.00008484 ///< Bicarb proportional gain (kp) -#define BICARB_VOL_CONTROL_I_COEFFICIENT 0.00033936 ///< Bicarb integral gain. (ki) +#define BICARB_VOL_CONTROL_P_COEFFICIENT ( 0.00008484 * 2 ) ///< Bicarb proportional gain (kp) +#define BICARB_VOL_CONTROL_I_COEFFICIENT ( 0.00033936 / 5) ///< Bicarb integral gain. (ki) #define MIN_BICARB_VOLUME_ML 0.868686869 ///< Minimum bicarb volume in mL #define MAX_BICARB_VOLUME_ML 1.8 ///< Maximum bicarb volume in mL @@ -105,9 +108,13 @@ #define MIX_NO_FEED_FORWARD 0.0F ///< Feedforward term for dialysate closed loop control -#define MIXING_CONTROL_INTERVAL_MS ( 15 * MS_PER_SECOND ) ///< Dialysate mixing control interval in ms -#define MIXING_CONTROL_INTERVAL ( MIXING_CONTROL_INTERVAL_MS /\ - TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the dialysate mixing is controlled. +#define MIX_CONTROL_INTERVAL_MS ( 15 * MS_PER_SECOND ) ///< Dialysate dosing control interval in ms +#define BICARB_MIX_CONTROL_INTERVAL ( 3 * MS_PER_SECOND /\ + TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the dialysate mix is controlled. +#define ACID_MIX_CONTROL_INTERVAL ( MIX_CONTROL_INTERVAL_MS /\ + TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the dialysate mix is controlled. +#define BICARB_DEADBAND_CONTROL 50.0F ///< Dry Bicarb dead band control +#define ACID_DEADBAND_CONTROL 100.0F ///< Acid dead band control /// Payload record structure for dry bicart fill request typedef struct @@ -457,11 +464,11 @@ void execDryBicart( void ) { //( TRUE == getBicarbChamberFillRequested() ) - // supply dryBicartStartRequest = DRY_BICART_SUPPLY ; + //supply dryBicartStartRequest = DRY_BICART_SUPPLY ; //( TRUE == getBicartFillRequested() ) - // fill dryBicartStartRequest = DRY_BICART_INITIAL_FILL; + //fill dryBicartStartRequest = DRY_BICART_INITIAL_FILL; //( TRUE == getBicartDrainRequested() ) - // drain dryBicartStartRequest = DRY_BICART_DRAIN; + //drain dryBicartStartRequest = DRY_BICART_DRAIN; //else idle dryBicartStartRequest = DRY_BICART_IDLE; updateDrybicartOperation(); @@ -1263,7 +1270,7 @@ //Close D64 setValveState( D64_VALV, VALVE_STATE_CLOSED); - //Vent bicart + //Vent bicart to chamber F setValveState( D85_VALV, VALVE_STATE_OPEN ); //Initiate timer to measure length of bicart vent @@ -1288,7 +1295,7 @@ if ( TRUE == didTimeout( dryBiCartFillStartTime, DRY_BICART_FILL_VENT_TIME_MS ) ) { - //Vent chamber F + //Vent chamber F to atmosphere setValveState( D64_VALV, VALVE_STATE_OPEN ); } @@ -1433,12 +1440,15 @@ BICARB_CHAMBER_FILL_EXEC_STATE_T state = BICARB_CARTRIDGE_FILL_WATER_END_STATE; // Close vent valves and descaling valve + setValveState( D64_VALV, VALVE_STATE_OPEN ); //open + setValveState( D80_VALV, VALVE_STATE_CLOSED ); setValveState( D81_VALV, VALVE_STATE_CLOSED ); - setValveState( D64_VALV, VALVE_STATE_CLOSED ); setValveState( D85_VALV, VALVE_STATE_CLOSED ); // open inlet water to bicart setValveState( D65_VALV, VALVE_STATE_OPEN ); + //setValveState( D3_VALV, VALVE_STATE_OPEN ); + dryBiCarbSupplyStartTime = getMSTimerCount(); return state; } @@ -1455,11 +1465,22 @@ BICARB_CHAMBER_FILL_EXEC_STATE_T state = BICARB_CARTRIDGE_FILL_WATER_END_STATE; F32 d66Pressure = getFilteredPressure( D66_PRES ); - if ( d66Pressure >= getDryBicartUpperCartPressure() ) + if ( d66Pressure >= DRY_BICART_FILL_COMPLETE_PRESSURE )// DRY_BICART_FILL_COMPLETE_SUPPLY_PRESSURE { - // Close water inlet valve as D66 pressure reaches 15 PSI. - setValveState( D65_VALV, VALVE_STATE_CLOSED ); - state = BICARB_CHAMBER_CHECK_LEVEL_STATE; + // persistence + // to check the the maximum cart pressure during persistence on D66 + if ( d66Pressure >= MAX_DRY_BICART_FILL_COMPLETE_PRESSURE ) + { + setValveState( D65_VALV, VALVE_STATE_CLOSED ); + state = BICARB_CHAMBER_CHECK_LEVEL_STATE; + } + // 200 ms persistence on D66 pressure since pressure overshoot just after D65 opening + if ( TRUE == didTimeout( dryBiCarbSupplyStartTime, DRY_BICART_FILL_PERSISTANCE_DURATION_MS ) ) + { + setValveState( D65_VALV, VALVE_STATE_CLOSED ); + state = BICARB_CHAMBER_CHECK_LEVEL_STATE; + } + // Close water inlet valve as D66 pressure reaches 11 PSI. } return state; @@ -1481,6 +1502,7 @@ // TODO: Confirm D80 open on chamber low or end of balancing chamber switching? // if ( getBalancingChamberFillinProgressStatus() == FALSE ) { + setValveState( D64_VALV, VALVE_STATE_CLOSED ); // Open the Bicarb chamber inlet valve setValveState( D80_VALV, VALVE_STATE_OPEN ); @@ -1544,22 +1566,40 @@ // Once level reached, close the valve if ( ( LVL_STATE_HIGH == bicarbChamberLevel ) || - ( TRUE == didTimeout( dryBiCarbSupplyStartTime, DRY_BICART_SUPPLY_VALVE_D80_TIMEOUT_MS ) ) ) + ( TRUE == didTimeout( dryBiCarbSupplyStartTime, DRY_BICART_SUPPLY_VALVE_D80_OPEN_TIME_MS ) ) ) { setValveState( D65_VALV, VALVE_STATE_CLOSED ); - setValveState( D80_VALV, VALVE_STATE_CLOSED ); - dryBiCarbSypplyVentStartTime = getMSTimerCount(); - state = BICARB_SUPPLY_VENT_START_STATE; + // do not close the D80 valve, wait till d66 decays to 3 PSI + if ( TRUE == didTimeout( dryBiCarbSupplyStartTime, DRY_BICART_SUPPLY_COMPLETE_TIME_MS ) ) + { + if ( d66Pressure <= getDryBicartLowerCartPressure()) + { + setValveState( D80_VALV, VALVE_STATE_CLOSED ); + setValveState( D85_VALV, VALVE_STATE_OPEN ); + dryBiCarbSypplyVentStartTime = getMSTimerCount(); + state = BICARB_SUPPLY_VENT_START_STATE; + } + } } - /*else if ( d66Pressure <= getDryBicartLowerCartPressure() ) + else if ( d66Pressure <= getDryBicartLowerCartPressure() ) { - setValveState( D65_VALV, VALVE_STATE_OPEN ); } + setValveState( D65_VALV, VALVE_STATE_OPEN ); + } // Close water inlet valve as fill is complete. else if ( d66Pressure >= getDryBicartUpperCartPressure() ) { - setValveState( D65_VALV, VALVE_STATE_CLOSED ); - }*/ + // to check the the maximum cart pressure during persistence on D66 + if ( d66Pressure >= MAX_DRY_BICART_FILL_COMPLETE_PRESSURE ) + { + setValveState( D65_VALV, VALVE_STATE_CLOSED ); + } + // 200 ms persistence on D66 pressure since pressure overshoot just after D65 opening + if ( TRUE == didTimeout( dryBiCarbSupplyStartTime, DRY_BICART_FILL_PERSISTANCE_DURATION_MS ) ) + { + setValveState( D65_VALV, VALVE_STATE_CLOSED ); + } + } return state; } @@ -1575,63 +1615,20 @@ static BICARB_CHAMBER_FILL_EXEC_STATE_T handleBicarbChamberSupplyVentStartState(void) { BICARB_CHAMBER_FILL_EXEC_STATE_T state = BICARB_SUPPLY_VENT_START_STATE; - float setpoint; - U32 startTime; F32 d66Pressure = getFilteredPressure( D66_PRES ); - F32 tmpD66Pressure = getFilteredPressure( D66_PRES ); - setpoint = d66Pressure - 1.0; - - if ( ( d66Pressure > DRY_BICART_FILL_INITIATE_SUPPLY_PRESSURE ) ) + if ( TRUE == didTimeout( dryBiCarbSypplyVentStartTime, DRY_BICART_SUPPLY_VENT_MAX_TIME_MS ) ) { setValveState( D64_VALV, VALVE_STATE_OPEN ); - state = BICARB_SUPPLY_VENT_END_STATE; } - //if ( TRUE == didTimeout( dryBiCarbSupplyStartTime, 10 ) ) -#if 0 - while ( tmpD66Pressure >= getDryBicartLowerCartPressure() && tmpD66Pressure >= setpoint ) { - - // Venting loop: stay open until target PSI is reached - setValveState( D64_VALV, VALVE_STATE_CLOSED ); - setValveState( D85_VALV, VALVE_STATE_OPEN ); - startTime = getMSTimerCount(); - while ( TRUE != didTimeout( startTime, 12 ) ) - { - } - // close the valve - setValveState( D85_VALV, VALVE_STATE_CLOSED ); - setValveState( D64_VALV, VALVE_STATE_OPEN ); - startTime = getMSTimerCount(); - while ( TRUE != didTimeout( startTime, 100 ) ) - { - } - tmpD66Pressure = getFilteredPressure( D66_PRES ); - //sleep - } -#endif - else if ( TRUE == didTimeout( dryBiCarbSypplyVentStartTime, DRY_BICART_SUPPLY_VENT_TIME_MS ) ) + // D66 pressure drops or time out + if ( ( d66Pressure <= DRY_BICART_FILL_VENT_COMPLETE_PRESSURE ) || + ( TRUE == didTimeout( dryBiCarbSypplyVentStartTime, DRY_BICART_FILL_VENT_MAX_TIME_MS ) ) ) { - //Vent bicart after 1 sec - setValveState( D85_VALV, VALVE_STATE_OPEN ); - } - else if ( TRUE == didTimeout( dryBiCarbSypplyVentStartTime, DRY_BICART_SUPPLY_VENT_MAX_TIME_MS ) ) - { setValveState( D85_VALV, VALVE_STATE_CLOSED ); - //Vent chamber F after 200 ms - setValveState( D64_VALV, VALVE_STATE_OPEN ); dryBiCarbSypplyVentStartTime = getMSTimerCount(); - //state = BICARB_SUPPLY_VENT_END_STATE; - } - - // D66 pressure drops or time out - else if ( ( d66Pressure <= DRY_BICART_FILL_INITIATE_SUPPLY_PRESSURE ) /*|| - ( TRUE == didTimeout( dryBiCarbSypplyVentStartTime, DRY_BICART_FILL_VENT_MAX_TIME_MS ) )*/ ) - { - setValveState( D64_VALV, VALVE_STATE_OPEN ); - setValveState( D85_VALV, VALVE_STATE_CLOSED ); - dryBiCarbSypplyVentStartTime = getMSTimerCount(); state = BICARB_SUPPLY_VENT_END_STATE; } @@ -1650,18 +1647,11 @@ { BICARB_CHAMBER_FILL_EXEC_STATE_T state = BICARB_SUPPLY_VENT_END_STATE; - // close bicart vent and chamber f vent after 1 sec - if ( TRUE == didTimeout( dryBiCarbSypplyVentStartTime, DRY_BICART_SUPPLY_VENT_TIME_MS ) ) - { - setValveState( D85_VALV, VALVE_STATE_CLOSED ); - setValveState( D64_VALV, VALVE_STATE_OPEN); - - bicarbChamberFillRequested.data = FALSE; - // for this request override also cleared - bicarbChamberFillRequested.ovData = FALSE; + bicarbChamberFillRequested.data = FALSE; + // for this request override also cleared + bicarbChamberFillRequested.ovData = FALSE; - state = BICARB_CHAMBER_START_STATE; - } + state = BICARB_CHAMBER_START_STATE; return state; } Index: firmware/App/Controllers/DryBiCart.h =================================================================== diff -u -rfd897db8177752330ad08d877e0a13620513dbdc -r902889c30391b6ca8c9f19adfd3c841c86a5d49f --- firmware/App/Controllers/DryBiCart.h (.../DryBiCart.h) (revision fd897db8177752330ad08d877e0a13620513dbdc) +++ firmware/App/Controllers/DryBiCart.h (.../DryBiCart.h) (revision 902889c30391b6ca8c9f19adfd3c841c86a5d49f) @@ -82,9 +82,6 @@ F32 getDialysateTargetConductivity( void ); F32 getDialysateDeltaConductivity( void ); -F32 getBicarbTargetConductivity( void ); -F32 getBicarbDeltaConductivity( void ); - F32 getBicarbMixVol( void ); F32 getAcidMixVol( void ); Index: firmware/App/Monitors/Level.h =================================================================== diff -u -r37d6f3341f62349589f63975779c0df952c0cfd4 -r902889c30391b6ca8c9f19adfd3c841c86a5d49f --- firmware/App/Monitors/Level.h (.../Level.h) (revision 37d6f3341f62349589f63975779c0df952c0cfd4) +++ firmware/App/Monitors/Level.h (.../Level.h) (revision 902889c30391b6ca8c9f19adfd3c841c86a5d49f) @@ -37,12 +37,12 @@ { D46_LEVL = 0, ///< Spent dialysate air separation chamber level low or high status FIRST_LEVEL = D46_LEVL, - D63_LEVL, ///< Bicarb upper level low or high status - D98_LEVL, ///< Bicarb lower level low or high status + D63_LEVL, ///< Bicarb lower level conductive level sensor low or high status + D98_LEVL, ///< Bicarb upper level conductive level sensor low or high status LAST_LEVEL = D98_LEVL, - D6_LEVL, ///< floater switch low, medium and high status + D6_LEVL, ///< DD float level sensor low, medium and high status FIRST_FLOAT = D6_LEVL, - P25_LEVL, ///< FP level sensor + P25_LEVL, ///< FP float level sensor low medium high status LAST_FLOAT = P25_LEVL, NUM_OF_LEVELS ///< Number of levels } LEVEL_T;