Index: firmware/App/Controllers/BalancingChamber.h =================================================================== diff -u -rfcd31ba31379396ba18db1a7e13b9f26d7837958 -r847659965e5823e2e25db62c14f4611db9527f8a --- firmware/App/Controllers/BalancingChamber.h (.../BalancingChamber.h) (revision fcd31ba31379396ba18db1a7e13b9f26d7837958) +++ firmware/App/Controllers/BalancingChamber.h (.../BalancingChamber.h) (revision 847659965e5823e2e25db62c14f4611db9527f8a) @@ -83,8 +83,6 @@ F32 getBalancingChamberError( void ); // Get balancing chamber error to adjust UF rate. F32 getBicarbDoseVol( void ); // Get liquid bicarb dose volume F32 getAcidDoseVol( void ); // Get acid dose volume -BOOL isBalChamberSwitchImminent( void ); // Get the balancing chamber is within the valve-close window (50 ms) before switching. -BOOL getBalChamberFreshSideValvesClosedStatus( void ); // Get the balancing chamber fresh side valve close status BOOL testDDBalChamberDataPublishIntervalOverride( MESSAGE_T *message ); // To override the balancing chamber data publish interval BOOL testBalChamberSwFreqOverride( MESSAGE_T *message ); // To override the balancing chamber switching frequency Index: firmware/App/Controllers/DryBiCart.c =================================================================== diff -u -rc479bd8fae14f3bd7dc8574bbb3dc6c5e7f98588 -r847659965e5823e2e25db62c14f4611db9527f8a --- firmware/App/Controllers/DryBiCart.c (.../DryBiCart.c) (revision c479bd8fae14f3bd7dc8574bbb3dc6c5e7f98588) +++ firmware/App/Controllers/DryBiCart.c (.../DryBiCart.c) (revision 847659965e5823e2e25db62c14f4611db9527f8a) @@ -101,6 +101,7 @@ DRY_BICART_SUPPLY, ///< Dry bicart chamber fill DRY_BICART_DRAIN, ///< Dry bicart drain DRY_BICART_DEPRESSURIZE, ///< Dry bicart depressurize + DRY_BICART_PRE_GEN_CHAMBER_FILL, NUM_OF_DRY_BICART_OPERATION ///< Number of dry bicart operation } DRY_BICART_OPERATION_T; @@ -110,6 +111,7 @@ static BICARB_CHAMBER_FILL_EXEC_STATE_T bicarbChamberFillExecState; ///< Current state of bicarb chamber fill executive state machine. static DRY_BICART_DRAIN_EXEC_STATE_T dryBiCartDrainExecState; ///< Current state of dry bicart drain executive state machine static DRY_BICART_DEPRESSURIZE_EXEC_STATE_T dryBiCartDepressurizeExecState; ///< Current state of dry bicart depressurize executive state machine +static BICARB_CHAMBER_PRE_GEN_FILL_EXEC_STATE_T bicarbChamberPreGenFillExecState; // fill static U32 dryBiCartFillStartTime; ///< Dry bicart fill start time. static U32 biCartFillCycleCounter; ///< Number of drybicart fill cycle @@ -125,6 +127,7 @@ static OVERRIDE_U32_T bicarbChamberFillRequested; ///< Start/stop bicarb chamber fill. static OVERRIDE_U32_T dryBiCartDrainRequested; ///< Start/stop dry bicart drain. static OVERRIDE_U32_T dryBiCartDepressurizeRequested; ///< Start/stop dry bicart depressurize +static OVERRIDE_U32_T bicarbChamberPreGenFillRequested; ///< Start/stop bicarb chamber pre gen fill. // publish static OVERRIDE_U32_T dryBiCartDataPublishInterval; ///< Dry bicart data publish interval. static U32 dryBiCartDataPublicationTimerCounter; ///< Used to schedule drybicart data publication to CAN bus. @@ -133,14 +136,17 @@ // supply static U32 dryBiCarbSupplyStartTime; ///< Bicarb supply start time from bicart to Chamber F. // vent -static U32 dryBiCarbSypplyVentStartTime; ///< Bicarb supply vent start time for both bicart & Chamber F. +static U32 dryBiCarbSupplyVentStartTime; ///< Bicarb supply vent start time for both bicart & Chamber F. // drain static U32 dryBiCartDrainStartTime; ///< Drain overall start time (for max timeout) //TODO: implement draining //static U32 dryBiCartDrainLastCondSampleTime; ///< Last time conductivity was sampled //static U32 dryBiCartDrainCondStableCount; ///< Debounce counter for "zero" conductivity static U32 dryBiCartDrainTimePeriod; ///< Dry bicart drain time period +static U32 dryBiCarbPreGenSupplyStartTime; +static U32 dryBiCartPreGenPersistenceStartTime; +static U32 drybicartPreGenPersistenceOnLowercartPressureStartTime; ///< Dry bicart Persistence on lower cart pressure start time. static U32 dryBiCartPersistenceStartTime; ///< Dry bicart Persistence time. static U32 drybicartPersistenceOnLowercartPressureStartTime; ///< Dry bicart Persistence on lower cart pressure start time. static BOOL dryBiCartPressureDecayStartTimeFlag; ///< Dry bicart d66 pressure decay start timer. @@ -177,6 +183,14 @@ static DRY_BICART_DRAIN_EXEC_STATE_T handleDryBicartFluidDrainState( void ); static DRY_BICART_DRAIN_EXEC_STATE_T handleDryBicartFluidDrainDurationCheckState( void ); static DRY_BICART_DRAIN_EXEC_STATE_T handleDryBicartFluidDrainEndState( void ); +// Pre Gen Supply & Vent +static BICARB_CHAMBER_PRE_GEN_FILL_EXEC_STATE_T handleBicarbChamberPreGenStartState( void ); +static BICARB_CHAMBER_PRE_GEN_FILL_EXEC_STATE_T handleBicarbChamberPreGenCartridgeFillWaterStartState( void ); +static BICARB_CHAMBER_PRE_GEN_FILL_EXEC_STATE_T handleBicarbChamberPreGenCartridgeFillWaterEndState( void ); +static BICARB_CHAMBER_PRE_GEN_FILL_EXEC_STATE_T handleBicarbChamberPreGenSupplyStart( void ); +static BICARB_CHAMBER_PRE_GEN_FILL_EXEC_STATE_T handleBicarbChamberPreGenPressureCheckState( void ); +static BICARB_CHAMBER_PRE_GEN_FILL_EXEC_STATE_T handleBicarbChamberPreGenSupplyVentStartState(void); +static BICARB_CHAMBER_PRE_GEN_FILL_EXEC_STATE_T handleBicarbChamberPreGenSupplyVentEndState(void); static DRY_BICART_DEPRESSURIZE_EXEC_STATE_T handleDryBicartDepressurizeStartState( void ); static DRY_BICART_DEPRESSURIZE_EXEC_STATE_T handleDryBicartDepressurizeVentStartState( void ); @@ -254,12 +268,14 @@ dryBiCartDataPublicationTimerCounter = 0; biCartFillCycleCounter = 0; dryBiCarbSupplyStartTime = 0; - dryBiCarbSypplyVentStartTime = 0; + dryBiCarbSupplyVentStartTime = 0; dryBiCartDrainStartTime = 0; //dryBiCartDrainLastCondSampleTime = 0; //dryBiCartDrainCondStableCount = 0; dryBiCartDrainTimePeriod = 0; dryBiCartPersistenceStartTime = 0; + dryBiCarbPreGenSupplyStartTime = 0; + dryBiCartPreGenPersistenceStartTime = 0; drybicartPersistenceOnLowercartPressureStartTime = 0; prevDryBicartState = DRY_BICART_IDLE; } @@ -319,6 +335,11 @@ execDryBicartDepressurize(); break; + case DRY_BICART_PRE_GEN_CHAMBER_FILL: + // Fill Bicarb chamber F exec + execBicarbChamberPreGenFillMode(); + break; + default: // software fault, dryBicartStartRequest = DRY_BICART_IDLE; @@ -515,6 +536,117 @@ /*********************************************************************//** * @brief + * The execBicarbChamberFillMode function executes the bicarb chamber fill + * (delivering bicarbonate from Bicart assembly to chamber F)state machine. + * @details \b Inputs: bicarbChamberFillExecState + * @details \b Outputs: bicarbChamberFillExecState + * @details \b Alarm: ALARM_ID_DD_SOFTWARE_FAULT when wrong bicarb chamber + * fill state invoked. + * @return current state. + *************************************************************************/ +U32 execBicarbChamberPreGenFillMode( void ) +{ + // TODO in pregen mode call hydChamberWaterInletControl(); + // execute bicarb chamber fill state machine + switch ( bicarbChamberPreGenFillExecState ) + { + case PRE_GEN_BICARB_CHAMBER_START_STATE: + bicarbChamberPreGenFillExecState = handleBicarbChamberPreGenStartState(); + break; + + case PRE_GEN_BICARB_CARTRIDGE_FILL_WATER_START_STATE: + bicarbChamberPreGenFillExecState = handleBicarbChamberPreGenCartridgeFillWaterStartState(); + break; + + case PRE_GEN_BICARB_CARTRIDGE_FILL_WATER_END_STATE: + bicarbChamberPreGenFillExecState = handleBicarbChamberPreGenCartridgeFillWaterEndState(); + break; + + case PRE_GEN_BICARB_CHAMBER_SUPPLY_STATE: + bicarbChamberPreGenFillExecState = handleBicarbChamberPreGenSupplyStart(); + break; + + case PRE_GEN_BICARB_CHAMBER_PRESSURE_CHECK_STATE: + bicarbChamberPreGenFillExecState = handleBicarbChamberPreGenPressureCheckState(); + break; + + case PRE_GEN_BICARB_SUPPLY_VENT_START_STATE: + bicarbChamberPreGenFillExecState = handleBicarbChamberPreGenSupplyVentStartState(); + break; + + case PRE_GEN_BICARB_SUPPLY_VENT_END_STATE: + bicarbChamberPreGenFillExecState = handleBicarbChamberPreGenSupplyVentEndState(); + break; + + default: + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DD_SOFTWARE_FAULT, SW_FAULT_ID_BICARB_CHAMBER_FILL_INVALID_EXEC_STATE, bicarbChamberFillExecState ); + break; + } + + return bicarbChamberPreGenFillExecState; +} + +/*********************************************************************//** + * @brief + * The setBicartFillRequested function sets the bicart fill request + * flag value to be True. + * @details \b Inputs: bicarbChamberFillRequested, dryBiCartDrainRequested, + * dryBiCartDepressurizeRequested + * @details \b Outputs: dryBiCartFillRequested + * @return TRUE if successful, FALSE if not. + *************************************************************************/ +BOOL setBicartPreGenFillRequested( void ) +{ + BOOL result = FALSE; + BOOL requestStatus = getU32OverrideValue( &bicarbChamberPreGenFillRequested ) \ + || getU32OverrideValue( &dryBiCartDrainRequested ) || \ + getU32OverrideValue( &dryBiCartDepressurizeRequested ) ; + + //ensure that there is no other operation in progress before new request set to true + if ( FALSE == requestStatus ) + { + bicarbChamberPreGenFillRequested.data = TRUE; + result = TRUE; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The getBicartFillRequested function gets the bicart fill request + * flag value + * @details \b Inputs: dryBiCartFillRequested + * @details \b Outputs: none + * @return TRUE if successful, FALSE if not. + *************************************************************************/ +BOOL getBicartPreGenFillRequested( void ) +{ + BOOL result = FALSE; + + if ( ( TRUE == getU32OverrideValue( &bicarbChamberPreGenFillRequested ) ) ) + { + result = TRUE; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The getCurrentDryBiCartFillExecState function returns the current state + * of the dry bicart fill state. + * @details \b Inputs: dryBiCartFillExecState + * @details \b Outputs: none + * @return the current state of dry bicart fill exec state. + *************************************************************************/ +BICARB_CHAMBER_PRE_GEN_FILL_EXEC_STATE_T getCurrentDryBiCartPreGenFillExecState( void ) +{ + return bicarbChamberPreGenFillExecState; +} + +/*********************************************************************//** + * @brief * The setBicarbChamberFillRequested function sets the chmaberFillRequest * flag value to be True. * @details \b Inputs: dryBiCartFillRequested, dryBiCartDrainRequested, @@ -807,6 +939,11 @@ { dryBicartStartRequest = DRY_BICART_DEPRESSURIZE; } + else if ( TRUE == getBicartPreGenFillRequested() ) + { + // pre gen fill + dryBicartStartRequest = DRY_BICART_PRE_GEN_CHAMBER_FILL ; + } else { // idle @@ -1274,7 +1411,7 @@ setValveState( D85_VALV, VALVE_STATE_OPEN ); dryBiCarbSupplyStartTime = getMSTimerCount(); - dryBiCarbSypplyVentStartTime = getMSTimerCount(); + dryBiCarbSupplyVentStartTime = getMSTimerCount(); state = BICARB_SUPPLY_VENT_START_STATE; } @@ -1345,7 +1482,7 @@ BICARB_CHAMBER_FILL_EXEC_STATE_T state = BICARB_SUPPLY_VENT_START_STATE; F32 d66Pressure = getFilteredPressure( D66_PRES ); - if ( TRUE == didTimeout( dryBiCarbSypplyVentStartTime, DRY_BICART_SUPPLY_VENT_TIME_MS ) ) + if ( TRUE == didTimeout( dryBiCarbSupplyVentStartTime, DRY_BICART_SUPPLY_VENT_TIME_MS ) ) { //Vent chamber F to atmosphere setValveState( D64_VALV, VALVE_STATE_OPEN ); @@ -1367,7 +1504,7 @@ state = BICARB_SUPPLY_VENT_END_STATE; } } - else if ( ( TRUE == didTimeout( dryBiCarbSypplyVentStartTime, DRY_BICART_FILL_VENT_MAX_TIME_MS ) ) ) + else if ( ( TRUE == didTimeout( dryBiCarbSupplyVentStartTime, DRY_BICART_FILL_VENT_MAX_TIME_MS ) ) ) { setValveState( D85_VALV, VALVE_STATE_CLOSED ); dryBiCartPersistenceStartTime = 0; @@ -1628,7 +1765,7 @@ F32 d66Pressure = getFilteredPressure( D66_PRES ); - if ( TRUE == didTimeout( dryBiCarbSypplyVentStartTime, DRY_BICART_SUPPLY_VENT_TIME_MS ) ) + if ( TRUE == didTimeout( dryBiCarbSupplyVentStartTime, DRY_BICART_SUPPLY_VENT_TIME_MS ) ) { //Vent chamber F to atmosphere setValveState( D64_VALV, VALVE_STATE_OPEN ); @@ -1685,6 +1822,275 @@ /*********************************************************************//** * @brief + * The handleBicarbChamberStartState function wait for bicarb chamber fill request + * @details \b Inputs: bicarbChamberFillRequested + * @details \b Outputs: none + * @return the next drybicart fluid drain state. + *************************************************************************/ +static BICARB_CHAMBER_PRE_GEN_FILL_EXEC_STATE_T handleBicarbChamberPreGenStartState( void ) +{ + BICARB_CHAMBER_PRE_GEN_FILL_EXEC_STATE_T state = PRE_GEN_BICARB_CHAMBER_START_STATE; + + dryBiCartPressureDecayStartTimeFlag = FALSE; + + if ( TRUE == getU32OverrideValue( &bicarbChamberPreGenFillRequested ) ) + { + state = PRE_GEN_BICARB_CARTRIDGE_FILL_WATER_START_STATE; + } + + return state; +} +/*********************************************************************//** + * @brief + * The handleBicarbChamberCartridgeFillWaterStartState function fill water in the dry bicart + * @details \b Inputs: none + * @details \b Outputs: valve states, dryBiCarbSupplyStartTime, dryBiCartPersistenceStartTime + * @return the next bicarb cartridge fill water end state. + *************************************************************************/ +static BICARB_CHAMBER_PRE_GEN_FILL_EXEC_STATE_T handleBicarbChamberPreGenCartridgeFillWaterStartState( void ) +{ + BICARB_CHAMBER_PRE_GEN_FILL_EXEC_STATE_T state = PRE_GEN_BICARB_CARTRIDGE_FILL_WATER_END_STATE; + + // Close vent valves and descaling valve + setValveState( D80_VALV, VALVE_STATE_CLOSED ); + setValveState( D81_VALV, VALVE_STATE_CLOSED ); + setValveState( D85_VALV, VALVE_STATE_CLOSED ); + + // open inlet water to bicart + setValveState( D65_VALV, VALVE_STATE_OPEN ); + setValveState( D64_VALV, VALVE_STATE_OPEN ); + setValveState( D14_VALV, VALVE_STATE_OPEN ); + + dryBiCarbPreGenSupplyStartTime = getMSTimerCount(); + dryBiCartPreGenPersistenceStartTime = 0; + + return state; +} + +/*********************************************************************//** + * @brief + * The handleBicarbChamberCartridgeFillWaterStartState function stop water in the dry bicart + * @details \b Inputs: D66 pressure, dryBiCartPersistenceStartTime + * @details \b Outputs: valve states + * @return the next bicarb chamber check level state. + *************************************************************************/ +static BICARB_CHAMBER_PRE_GEN_FILL_EXEC_STATE_T handleBicarbChamberPreGenCartridgeFillWaterEndState( void ) +{ + BICARB_CHAMBER_PRE_GEN_FILL_EXEC_STATE_T state = PRE_GEN_BICARB_CARTRIDGE_FILL_WATER_END_STATE; + F32 d66Pressure = getFilteredPressure( D66_PRES ); + F32 fillCompletePressure = GET_FILL_COMPLETE_PRESSURE_PSI; + + // check D66 pressure greater than or equal to 17 PSI + if ( d66Pressure >= fillCompletePressure ) + { + // start the persistence timer once d66 reaches 17 PSI + if ( 0 == dryBiCartPreGenPersistenceStartTime ) + { + dryBiCartPreGenPersistenceStartTime = getMSTimerCount(); + } + + // 200 ms persistence on D66 pressure since pressure overshoot just after D65 opening + if ( TRUE == didTimeout( dryBiCartPreGenPersistenceStartTime, DRY_BICART_PERSISTENCE_DURATION_MS ) ) + { + // Close water inlet valve as D66 pressure reaches 1 PSI after persistence + setValveState( D65_VALV, VALVE_STATE_CLOSED ); + dryBiCartPreGenPersistenceStartTime = 0; + + state = PRE_GEN_BICARB_CHAMBER_SUPPLY_STATE; + } + } + else + { + dryBiCartPreGenPersistenceStartTime = 0; + } + + return state; +} + +/*********************************************************************//** + * @brief + * The handleBicarbChamberSupplyStart function open the bicarb inlet valve (D80). + * @details \b Inputs: none + * @details \b Outputs: valve states, dryBiCarbSupplyStartTime + * @return the next bicarb chamber fill state. + *************************************************************************/ +static BICARB_CHAMBER_PRE_GEN_FILL_EXEC_STATE_T handleBicarbChamberPreGenSupplyStart( void ) +{ + BICARB_CHAMBER_PRE_GEN_FILL_EXEC_STATE_T state = PRE_GEN_BICARB_CHAMBER_PRESSURE_CHECK_STATE; + + // TODO: set supply in progress to inform BC control to disable alarm + setValveState( D64_VALV, VALVE_STATE_OPEN ); + // Open the Bicarb chamber inlet valve + setValveState( D80_VALV, VALVE_STATE_OPEN ); + + // Start a timer when bicarb supply started to chamber F + dryBiCarbPreGenSupplyStartTime = getMSTimerCount(); + + // TODO: alarm + + return state; +} + +/*********************************************************************//** + * @brief + * The handleBicarbChamberPressureCheckStartState function actuates the vent valve + * present in the Bicart assembly. + * @details \b Inputs: D66 Pressure, D63 level, dryBiCarbSupplyStartTime, + * dryBiCarbSypplyVentStartTime, dryBiCartPersistenceStartTime, bicarbChamberLevel, + * dryBiCartPressureDecayStartTimeFlag, drybicartPersistenceOnLowercartPressureStartTime + * @details \b Outputs: dryBiCarbSypplyVentStartTime + * @return the next bicarb chamber Supply Vent Start state. + *************************************************************************/ +static BICARB_CHAMBER_PRE_GEN_FILL_EXEC_STATE_T handleBicarbChamberPreGenPressureCheckState( void ) +{ + BICARB_CHAMBER_PRE_GEN_FILL_EXEC_STATE_T state = PRE_GEN_BICARB_CHAMBER_PRESSURE_CHECK_STATE; + F32 d66Pressure = getFilteredPressure( D66_PRES ); + LVL_STATE_T bicarbChamberLevel = getBicarbChamberLevelStatus(); + + // Once upper level reached high , close the valve, timeout is for safety in case level sensor didn't work(10 sec), or else its a time based filling (3 sec) + if ( ( LVL_STATE_HIGH == bicarbChamberLevel ) || + ( TRUE == didTimeout( dryBiCarbPreGenSupplyStartTime, DRY_BICART_SUPPLY_VALVE_D80_OPEN_TIME_MS ) ) ) + { + setValveState( D65_VALV, VALVE_STATE_CLOSED ); + + // start the timer for d66 pressure decay + if( FALSE == dryBiCartPressureDecayStartTimeFlag ) + { + dryBiCarbPreGenSupplyStartTime = getMSTimerCount(); + dryBiCartPressureDecayStartTimeFlag = TRUE; + } + // do not close the D80 valve, wait till d66 decays to 3 PSI + if ( TRUE == didTimeout( dryBiCarbPreGenSupplyStartTime, DRY_BICART_SUPPLY_COMPLETE_TIME_MS ) ) + { + if ( d66Pressure <= getDryBicartLowerCartPressure() ) + { + setValveState( D80_VALV, VALVE_STATE_CLOSED ); + setValveState( D85_VALV, VALVE_STATE_OPEN ); + + dryBiCarbPreGenSupplyStartTime = getMSTimerCount(); + dryBiCarbSupplyVentStartTime = getMSTimerCount(); + + state = PRE_GEN_BICARB_SUPPLY_VENT_START_STATE; + } + } + } + else if ( d66Pressure <= getDryBicartLowerCartPressure() ) + { + // start persistence timer + if ( 0 == drybicartPreGenPersistenceOnLowercartPressureStartTime ) + { + drybicartPreGenPersistenceOnLowercartPressureStartTime = getMSTimerCount(); + } + // 200 ms persistence on D66 pressure + if ( TRUE == didTimeout( drybicartPreGenPersistenceOnLowercartPressureStartTime, DRY_BICART_PERSISTENCE_DURATION_MS ) ) + { + setValveState( D65_VALV, VALVE_STATE_OPEN ); + drybicartPreGenPersistenceOnLowercartPressureStartTime = 0; + } + } + // Close water inlet valve as fill is complete. + else if ( d66Pressure >= getDryBicartUpperCartPressure() ) + { + // start persistence timer + if ( 0 == dryBiCartPreGenPersistenceStartTime ) + { + dryBiCartPreGenPersistenceStartTime = getMSTimerCount(); + } + + // 200 ms persistence on D66 pressure since pressure overshoot just after D65 opening + if ( TRUE == didTimeout( dryBiCartPreGenPersistenceStartTime, DRY_BICART_PERSISTENCE_DURATION_MS ) ) + { + setValveState( D65_VALV, VALVE_STATE_CLOSED ); + dryBiCartPreGenPersistenceStartTime = 0; + } + } + else + { + dryBiCartPreGenPersistenceStartTime = 0; + drybicartPreGenPersistenceOnLowercartPressureStartTime = 0; + } + + return state; +} + +/*********************************************************************//** + * @brief + * The handleBicarbChamberSupplyVentStartState function actuates the vent valve + * present in the Bicart assembly. + * @details \b Inputs: dryBiCarbSypplyVentStartTime, dryBiCartPersistenceStartTime + * @details \b Outputs: dryBiCarbSypplyVentStartTime + * @return the next bicarb chamber Supply Vent End state. + *************************************************************************/ +static BICARB_CHAMBER_PRE_GEN_FILL_EXEC_STATE_T handleBicarbChamberPreGenSupplyVentStartState(void) +{ + BICARB_CHAMBER_PRE_GEN_FILL_EXEC_STATE_T state = PRE_GEN_BICARB_SUPPLY_VENT_START_STATE; + F32 d66Pressure = getFilteredPressure( D66_PRES ); + + if ( TRUE == didTimeout( dryBiCarbSupplyVentStartTime, DRY_BICART_SUPPLY_VENT_TIME_MS ) ) + { + //Vent chamber F to atmosphere + setValveState( D64_VALV, VALVE_STATE_OPEN ); + + // D66 pressure drops to below 1.5 PSI or time out + if ( ( d66Pressure <= DRY_BICART_FILL_VENT_COMPLETE_PRESSURE_PSI ) ) + { + // start the persistence timer once d66 reaches if it drops below 1.5 + if ( 0 == dryBiCartPreGenPersistenceStartTime ) + { + dryBiCartPreGenPersistenceStartTime = getMSTimerCount(); + } + // 200 ms persistence on D66 pressure since pressure overshoot just after D65 opening + if ( TRUE == didTimeout( dryBiCartPreGenPersistenceStartTime, DRY_BICART_PERSISTENCE_DURATION_MS ) ) + { + setValveState( D85_VALV, VALVE_STATE_CLOSED ); + dryBiCartPreGenPersistenceStartTime = 0; + + state = PRE_GEN_BICARB_SUPPLY_VENT_END_STATE; + } + } + else if ( ( TRUE == didTimeout( dryBiCarbSupplyVentStartTime, DRY_BICART_FILL_VENT_MAX_TIME_MS ) ) ) + { + setValveState( D85_VALV, VALVE_STATE_CLOSED ); + dryBiCartPreGenPersistenceStartTime = 0; + dryBiCartFillVentTimeOut = TRUE; + + state = PRE_GEN_BICARB_SUPPLY_VENT_END_STATE; + } + else + { + dryBiCartPreGenPersistenceStartTime = 0; + } + } + + return state; +} + +/*********************************************************************//** + * @brief + * The handleBicarbChamberSupplyVentEndState function actuates the vent valve + * present in the Bicart assembly. + * @details \b Inputs: dryBiCarbSypplyVentStartTime + * @details \b Outputs: bicarbChamberFillRequested + * @return the next bicarb chamber start state. + *************************************************************************/ +static BICARB_CHAMBER_PRE_GEN_FILL_EXEC_STATE_T handleBicarbChamberPreGenSupplyVentEndState(void) +{ + BICARB_CHAMBER_PRE_GEN_FILL_EXEC_STATE_T state = PRE_GEN_BICARB_SUPPLY_VENT_END_STATE; + + bicarbChamberPreGenFillRequested.data = FALSE; + // for this request override also cleared + bicarbChamberPreGenFillRequested.ovData = FALSE; + + dryBiCartPressureDecayStartTimeFlag = FALSE; + + state = PRE_GEN_BICARB_CHAMBER_START_STATE; + + dryBicartStartRequest = DRY_BICART_IDLE; + + return state; +} +/*********************************************************************//** + * @brief * The publishDryBicartData function broadcasts the dry bicart * data at defined interval. * @details \b Inputs: dryBiCartDataPublicationTimerCounter @@ -1711,6 +2117,7 @@ data.dryBiCartCurrentFillTime = currentFillDurationInMS; data.dryBiCartType = getU32OverrideValue( &dryBiCartType ); data.dryBiCartDrainTimePeriod = dryBiCartDrainTimePeriod; + data.dryBiCartPreGenFillState = (U32)bicarbChamberPreGenFillExecState; broadcastData( MSG_ID_DD_DRY_BICART_DATA, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08*)&data, sizeof( DRY_BICART_DATA_T ) ); Index: firmware/App/Controllers/MixingControl.c =================================================================== diff -u -rfcd31ba31379396ba18db1a7e13b9f26d7837958 -r847659965e5823e2e25db62c14f4611db9527f8a --- firmware/App/Controllers/MixingControl.c (.../MixingControl.c) (revision fcd31ba31379396ba18db1a7e13b9f26d7837958) +++ firmware/App/Controllers/MixingControl.c (.../MixingControl.c) (revision 847659965e5823e2e25db62c14f4611db9527f8a) @@ -46,8 +46,8 @@ #define MIXING_CONTROL_DATA_PUBLISH_INTERVAL ( 250 / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the mixing control data published. // drybicarb mixing -#define BICARB_VOL_CONTROL_P_COEFFICIENT ( 0.00008484F ) ///< Bicarb proportional gain (kp) -#define BICARB_VOL_CONTROL_I_COEFFICIENT ( 0.00033936F / 8 ) ///< Bicarb integral gain. (ki) +#define BICARB_VOL_CONTROL_P_COEFFICIENT ( 0.00008484F * 2 ) ///< Bicarb proportional gain (kp) +#define BICARB_VOL_CONTROL_I_COEFFICIENT ( 0.00033936F / 4 ) ///< Bicarb integral gain. (ki) #define MIN_BICARB_VOLUME_ML 0.4F ///< Minimum bicarb volume in mL #define MAX_BICARB_VOLUME_ML 1.8F ///< Maximum bicarb volume in mL @@ -69,11 +69,11 @@ #define MIX_NO_FEED_FORWARD 0.0F ///< Feed forward term for dialysate closed loop control -#define BICARB_MIX_CONTROL_INTERVAL_MULTIPLIER ( 3 * MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the bicarb mix is controlled. -#define ACID_MIX_CONTROL_INTERVAL_MULTIPLIER ( 5 * MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the dialysate mix is controlled. +#define BICARB_MIX_CONTROL_INTERVAL ( 9 * MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the bicarb mix is controlled. +#define ACID_MIX_CONTROL_INTERVAL ( 15 * MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the dialysate mix is controlled. -#define BICARB_DEADBAND_CONTROL 30.0F ///< Bicarb dead band control -#define ACID_DEADBAND_CONTROL 70.0F ///< Acid dead band control +#define BICARB_DEADBAND_CONTROL 15.0F ///< Bicarb dead band control +#define ACID_DEADBAND_CONTROL 50.0F ///< Acid dead band control // Proportioning Ratios: 1 Part Acid : 1.72 Parts Bicarb : 42.28 Parts Water // Total parts = 1 + 1.72 + 42.28 = 45.0 @@ -202,7 +202,6 @@ static void setBicarbMixVol( F32 targetValue ); static void setAcidMixVol( F32 targetValue ); -static void updatedCMixingControlInterval( void ); static F32 getBicarbDeltaConductivity( void ); static F32 getBicarbTargetConductivity( void ); @@ -254,8 +253,8 @@ mixingControlAcidVolume.ovInitData = 0.0F; mixingControlAcidVolume.override = OVERRIDE_RESET; - mixingControlBicarbVolume.data = FINAL_BICARB_MIX_VOLUME_UPDATE; - mixingControlBicarbVolume.ovData = FINAL_BICARB_MIX_VOLUME_UPDATE; + mixingControlBicarbVolume.data = FINAL_BICARB_MIX; + mixingControlBicarbVolume.ovData = FINAL_BICARB_MIX; mixingControlBicarbVolume.ovInitData = 0.0F; mixingControlBicarbVolume.override = OVERRIDE_RESET; @@ -314,19 +313,19 @@ mixingControlTargetAdjBicarbSettings.ovInitData = 0.0F; mixingControlTargetAdjBicarbSettings.override = OVERRIDE_RESET; - mixingControlBicarbControlInterval.data = BICARB_MIX_CONTROL_INTERVAL_MULTIPLIER; - mixingControlBicarbControlInterval.ovData = BICARB_MIX_CONTROL_INTERVAL_MULTIPLIER; + mixingControlBicarbControlInterval.data = BICARB_MIX_CONTROL_INTERVAL; + mixingControlBicarbControlInterval.ovData = BICARB_MIX_CONTROL_INTERVAL; mixingControlBicarbControlInterval.ovInitData = 0; mixingControlBicarbControlInterval.override = OVERRIDE_RESET; - mixingControlAcidControlInterval.data = ACID_MIX_CONTROL_INTERVAL_MULTIPLIER; - mixingControlAcidControlInterval.ovData = ACID_MIX_CONTROL_INTERVAL_MULTIPLIER; + mixingControlAcidControlInterval.data = ACID_MIX_CONTROL_INTERVAL; + mixingControlAcidControlInterval.ovData = ACID_MIX_CONTROL_INTERVAL; mixingControlAcidControlInterval.ovInitData = 0; mixingControlAcidControlInterval.override = OVERRIDE_RESET; mixingControlDataPublicationTimerCounter = 0; - mixingControlLastBicarbMixVolume = 0.0F; - mixingControlLastAcidMixVolume = 0.0F; + mixingControlLastBicarbMixVolume = 0; + mixingControlLastAcidMixVolume = 0; initializePIController( PI_CONTROLLER_ID_BICARB_VOL, 0.0F,\ getBicarbKpGainCoefficient(), getBicarbKiGainCoefficient(),\ @@ -363,8 +362,6 @@ { if ( getCurrentBalancingChamberExecState() > BAL_CHAMBER_STATE_IDLE ) { - updatedCMixingControlInterval(); - // closed loop bicarb and acid mixing controller handleDialysateCompositionMixing(); } @@ -431,36 +428,6 @@ /*********************************************************************//** * @brief - * The updatedCMixingControlInterval function sets both acid and bicarb - * Mix volume provided by the controller - * @details \b Inputs: none - * @details \b Outputs: mixingControlBicarbMixVolume - * @param targetValue bicarb Mix volume - * @return TRUE if successful, FALSE if not. - *************************************************************************/ -static void updatedCMixingControlInterval( void ) -{ - F32 tdDialysateFlowRate = 0.0F; - F32 balChamberSwitchingFreq = 0.0F; - U32 balChamberSwitchingPeriod = 0; - - tdDialysateFlowRate = getTDDialysateFlowrate(); - - balChamberSwitchingFreq = tdDialysateFlowRate / 30.0; - balChamberSwitchingPeriod = ( SEC_PER_MIN ) / (U32)balChamberSwitchingFreq; - - // For acid control period, we are using 3 cycles of balancing chamber switching period (for ex: At Qd = 600, switching period = 3sec, so acid control interval = 3*3 = 9sec - // For bicarb control period, we are using 5 cycles of balancing chamber switching period (for ex: At Qd = 600, switching period = 3sec, so bicarb control interval = 3*5 = 15sec - - if ( balChamberSwitchingPeriod > 0) - { - mixingControlAcidControlInterval.data = ACID_MIX_CONTROL_INTERVAL_MULTIPLIER * balChamberSwitchingPeriod; - mixingControlBicarbControlInterval.data = BICARB_MIX_CONTROL_INTERVAL_MULTIPLIER * balChamberSwitchingPeriod; - } -} - -/*********************************************************************//** - * @brief * The getBicarbDeltaConductivity function gets the delta target conductivity * @details \b Inputs: mixingControlBicarbDeltaConductivity * @details \b Outputs: none @@ -1148,7 +1115,7 @@ *************************************************************************/ BOOL testMixingControlBicarbControlIntervalOverride( MESSAGE_T *message ) { - BOOL result = u32Override( message, &mixingControlBicarbControlInterval, 0, BICARB_MIX_CONTROL_INTERVAL_MULTIPLIER ); + BOOL result = u32Override( message, &mixingControlBicarbControlInterval, 0, BICARB_MIX_CONTROL_INTERVAL ); return result; } @@ -1165,7 +1132,7 @@ *************************************************************************/ BOOL testMixingControlAcidControlIntervalOverride( MESSAGE_T *message ) { - BOOL result = u32Override( message, &mixingControlAcidControlInterval, 0, ACID_MIX_CONTROL_INTERVAL_MULTIPLIER ); + BOOL result = u32Override( message, &mixingControlAcidControlInterval, 0, BICARB_MIX_CONTROL_INTERVAL ); return result; } Index: firmware/App/Controllers/MixingControl.h =================================================================== diff -u -r095866efd8f10bdead490578e7584051d79292f0 -r847659965e5823e2e25db62c14f4611db9527f8a --- firmware/App/Controllers/MixingControl.h (.../MixingControl.h) (revision 095866efd8f10bdead490578e7584051d79292f0) +++ firmware/App/Controllers/MixingControl.h (.../MixingControl.h) (revision 847659965e5823e2e25db62c14f4611db9527f8a) @@ -7,8 +7,8 @@ * * @file MixingControl.h * -* @author (last) Sameer Kalliadan Poyil -* @date (last) 17-Jul-2026 +* @author (last) Jashwant Gantyada +* @date (last) 27-Jul-2026 * * @author (original) Sameer Kalliadan Poyil * @date (original) 15-Jun-2026 Index: firmware/App/Drivers/TemperatureSensors.c =================================================================== diff -u -r08ef85235ca795bb01a16b0352a4f3f4405333fa -r847659965e5823e2e25db62c14f4611db9527f8a --- firmware/App/Drivers/TemperatureSensors.c (.../TemperatureSensors.c) (revision 08ef85235ca795bb01a16b0352a4f3f4405333fa) +++ firmware/App/Drivers/TemperatureSensors.c (.../TemperatureSensors.c) (revision 847659965e5823e2e25db62c14f4611db9527f8a) @@ -383,7 +383,7 @@ //TODO: Uncomment after further analysis of the alarm behavior //check freshness of temperature read - //checkTemperatureSensors(); + checkTemperatureSensors(); } /*********************************************************************//** Index: firmware/App/Modes/ModeGenDialysate.h =================================================================== diff -u -r095866efd8f10bdead490578e7584051d79292f0 -r847659965e5823e2e25db62c14f4611db9527f8a --- firmware/App/Modes/ModeGenDialysate.h (.../ModeGenDialysate.h) (revision 095866efd8f10bdead490578e7584051d79292f0) +++ firmware/App/Modes/ModeGenDialysate.h (.../ModeGenDialysate.h) (revision 847659965e5823e2e25db62c14f4611db9527f8a) @@ -8,7 +8,7 @@ * @file ModeGenDialysate.h * * @author (last) Jashwant Gantyada -* @date (last) 07-May-2026 +* @date (last) 20-Jul-2026 * * @author (original) Vinayakam Mani * @date (original) 06-Nov-2024