Index: firmware/App/Modes/ModeGenDialysate.c =================================================================== diff -u -r8aa885b17330f096934f175d35912c3c95825039 -r21d8cec02d7e0f8ad98b54ca310243f690948ddc --- firmware/App/Modes/ModeGenDialysate.c (.../ModeGenDialysate.c) (revision 8aa885b17330f096934f175d35912c3c95825039) +++ firmware/App/Modes/ModeGenDialysate.c (.../ModeGenDialysate.c) (revision 21d8cec02d7e0f8ad98b54ca310243f690948ddc) @@ -7,13 +7,14 @@ * * @file ModeGenDialysate.c * -* @author (last) Dara Navaei -* @date (last) 18-Mar-2026 +* @author (last) Vinayakam Mani +* @date (last) 14-Apr-2026 * * @author (original) Vinayakam Mani * @date (original) 06-Nov-2024 * ***************************************************************************/ + #include // For ceilf #include "BalancingChamber.h" @@ -56,15 +57,10 @@ #define DIALYSATE_TEMP_UPPER_SAFETY_LIMIT_C 42.0F ///< Dialysate upper bound safety temperature limit in C. #define DIALYSATE_TEMP_LOWER_SAFETY_LIMIT_C 33.0F ///< Dialysate lower bound safety temperature limit in C. #define DIALYSATE_TEMP_CLEAR_TIMEOUT_MS ( 10 * MS_PER_SECOND ) ///< Dialysate temperature clear persistence timeout. -#define QUAD_FIRST_COEFFICIENT 0.0006F ///< First coefficient used in adjusted dialysate temperature quadratic calculation for low Qds -#define QUAD_SECOND_COEFFICIENT -0.1743F ///< Second coefficient used in adjusted dialysate temperature quadratic calculation for low Qds -#define QUAD_THIRD_COEFFICIENT 17.3F ///< Third coefficient used in adjusted dialysate temperature quadratic calculation for low Qds -#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 ZERO_DIAL_FLOW_RATE 0.0F ///< Zero dialysate flow rate #define SPENT_CHAMBER_FILL_MAX_COUNT 10 ///< Total number of spent chamber fill allowed. #define BICARB_CHAMBER_FILL_TIMEOUT ( 1 * MS_PER_SECOND ) ///< Bicarb chamber fill timeout. + #define PUMP_SPEED_SLOPE_FACTOR_DIENER_2000 1.24F ///< D48 Diener 2000 pump speed slope (y = 1.24x + 30). #define PUMP_SPEED_INTERCEPT_FACTOR_DIENER_2000 30.0F ///< D48 Diener 2000 pump speed intercept. #define PUMP_SPEED_SLOPE_FACTOR_DIENER_1000 2.869F ///< D48 Diener 1000 pump speed slope (y = 2.869x + 25.956). @@ -108,7 +104,6 @@ static DD_GEND_MODE_STATE_T handleGenDBicarbChamberFillState( void ); static DD_GEND_MODE_STATE_T handleGenDIsolatedUFState( void ); static F32 getGenDialysateTargetTemperature( void ); -static void calculateTargetDialysateTemp( void ); static void updateDialysateToDialyzerFlowRate( void ); static void checkDialysateTemperature( void ); static void monitorChamberLevelStatus( void ); @@ -175,7 +170,8 @@ initGenDialysateMode(); setCurrentSubState( NO_SUB_STATE ); - //calculateD48PumpSpeedForBCFill(); + // Deactivate Balancing Chamber Switching + requestBalChamberSwitching( FALSE ); initialD48PumpSpeed = getCalculatedD48PumpSpeedForBCFill(); setD48PumpSpeedForBCFill( initialD48PumpSpeed ); transitionToUltrafiltration(); @@ -243,7 +239,8 @@ switch( state ) { case DD_GEND_STATE_START: - // Do nothing + // Deactivate Balancing Chamber Switching + requestBalChamberSwitching( FALSE ); break; case DD_GEND_DIALYSATE_BYPASS_STATE: @@ -272,7 +269,14 @@ startHeater( D5_HEAT ); //Turn on Trimmer heater - setHeaterTargetTemperature( D45_HEAT, getD4AverageTemperature() ); + if ( getTestConfigStatus( TEST_CONFIG_DD_FP_ENABLE_BETA_1_0_HW ) == TRUE ) + { + setHeaterTargetTemperature( D45_HEAT, getFilteredTemperatureValue( D4_TEMP ) ); + } + else + { + setHeaterTargetTemperature( D45_HEAT, getFilteredTemperatureValue( D99_TEMP ) ); + } startHeater( D45_HEAT ); //Testing : Enable close loop once testing is complete @@ -285,13 +289,18 @@ setRinsePumpState( RINSE_PUMP_STATE_ON ); transitionToBalChamberFill(); + // Activate Balancing Chamber Switching + requestBalChamberSwitching( TRUE ); //Testing bypassStateDelayStartTimeMS = getMSTimerCount(); delayBypassStateFlag = TRUE; break; case DD_GEND_DIALYSATE_DELIVERY_STATE: + // Activate Balancing Chamber Switching + requestBalChamberSwitching( TRUE ); + //Previous state setValveState( D47_VALV, VALVE_STATE_CLOSED ); // spent chamber purge valve setValveState( D8_VALV, VALVE_STATE_CLOSED ); @@ -309,7 +318,14 @@ startHeater( D5_HEAT ); //Turn on Trimmer heater - setHeaterTargetTemperature( D45_HEAT, getD4AverageTemperature() ); + if ( getTestConfigStatus( TEST_CONFIG_DD_FP_ENABLE_BETA_1_0_HW ) == TRUE ) + { + setHeaterTargetTemperature( D45_HEAT, getFilteredTemperatureValue( D4_TEMP ) ); + } + else + { + setHeaterTargetTemperature( D45_HEAT, getFilteredTemperatureValue( D99_TEMP ) ); + } startHeater( D45_HEAT ); //setDialysatePumpTargetRPM( D12_PUMP, FRESH_DIAL_PUMP_INITIAL_RPM, FALSE ); @@ -333,6 +349,9 @@ break; case DD_GEND_SPENT_CHAMBER_FILL_STATE: + // Deactivate Balancing Chamber Switching + requestBalChamberSwitching( FALSE ); + //Set valves and actuators setValveState( D35_VALV, VALVE_STATE_CLOSED ); // VDI setValveState( D40_VALV, VALVE_STATE_CLOSED ); // VDO @@ -376,6 +395,9 @@ break; case DD_GEND_BICARB_CHAMBER_FILL_STATE: + // Deactivate Balancing Chamber Switching + requestBalChamberSwitching( FALSE ); + requestConcentratePumpOff( D11_PUMP, FALSE ); requestConcentratePumpOff( D10_PUMP, FALSE ); requestConcentratePumpOff( D76_PUMP, FALSE ); @@ -412,6 +434,8 @@ break; case DD_GEND_DIALYSATE_DELIVERY_PAUSE: + // Deactivate Balancing Chamber Switching + requestBalChamberSwitching( FALSE ); setDialysatePumpTargetRPM( D12_PUMP, getFreshDialPumpInitialRpm(), TRUE ); signalDialysatePumpHardStop( D48_PUMP ); requestConcentratePumpOff( D11_PUMP, FALSE ); @@ -453,6 +477,8 @@ break; case DD_GEND_ISOLATED_UF_STATE: + // Deactivate Balancing Chamber Switching + requestBalChamberSwitching( FALSE ); //TODO : define actuators states break; @@ -629,37 +655,6 @@ /*********************************************************************//** * @brief - * The calculateTargetDialysateTemp function calculate the delta temperature - * required for dialysate temperature to meet the set temperature at dialyzer. - * @details \b Inputs: Qd and target temperature. - * @details \b Outputs: Adjusted Target temperature - * @return none. - *************************************************************************/ -static void calculateTargetDialysateTemp( void ) -{ - // Get the dialysate flow rate from TD - F32 dialFlowrate = getTDDialysateFlowrate(); - F32 deltaTemp = 0.0F; - - if ( dialFlowrate >= LOW_DIAL_FLOW_RATE ) - { - // linear relationship seen against high dialysate flowrate Vs DeltaTemp - // deltaTemp = (-0.0029 * Qd) + 3.47 - deltaTemp = ( LINEAR_SLOPE_FACTOR * dialFlowrate ) + LINEAR_INTERCEPT_FACTOR; - } - else - { - // deltaTemp = (0.0006 * Qd * Qd)-(0.1743*Qd) + 17.3 - deltaTemp = ( QUAD_FIRST_COEFFICIENT * dialFlowrate * dialFlowrate ) + - ( QUAD_SECOND_COEFFICIENT * dialFlowrate ) + QUAD_THIRD_COEFFICIENT; - } - - // Adjust the D4 target temperature - targetHydChamberFluidTemp.data = getTDTargetDialysateTemperature() + deltaTemp; -} - -/*********************************************************************//** - * @brief * The getCalculatedD48PumpSpeedForBCFill function returns the D48 pump speed * calculated from dialysate flow rate (Qd) for continuous delivery. * @details \b Inputs: Qd from TD, test config TEST_CONFIG_DD_ENABLE_DIENER_1000_PUMP. @@ -741,11 +736,6 @@ delayBypassStateFlag = FALSE; } } - else - { - //Execute balancing chamber - execBalancingChamberControl(); - } if ( getTestConfigStatus( TEST_CONFIG_DD_ENABLE_SPENT_CHAMBER_H_FILL ) == TRUE ) { @@ -822,9 +812,6 @@ #endif else { - //Execute balancing chamber - execBalancingChamberControl(); - //Execute ultrafiltration execUFControl(); } @@ -980,6 +967,20 @@ /*********************************************************************//** * @brief + * The setTargetHydChamberTemp function updates the target hydraulics temperature + * for D5 heater control + * @details \b Inputs: none + * @details \b Outputs: targetHydChamberFluidTemp + * @param temperature The target temperature for D5 heater control + * @return none + *************************************************************************/ +void setTargetHydChamberTemp( F32 temperature ) +{ + targetHydChamberFluidTemp.data = temperature; +} + +/*********************************************************************//** + * @brief * The updateTreatmentSettings function updates the switching rate post the * treatement parameters updated during treatement. * @details \b Inputs: isTreatmentParamUpdated @@ -1009,9 +1010,9 @@ signalUFRateUpdate(); //Update D48 pump speed - //calculateD48PumpSpeedForBCFill(); initialPumpSpeed = getCalculatedD48PumpSpeedForBCFill(); setD48PumpSpeedForBCFill( initialPumpSpeed ); + setDialysatePumpTargetRPM( D48_PUMP, (U32)initialPumpSpeed, TRUE ); //reset the flag isTreatmentParamUpdated = FALSE; @@ -1213,8 +1214,8 @@ * @brief * The testDialDeliveryInProgressOverride function sets the override value * of the dialysate delivery In progress flag. - * @details Inputs: isDialDeliveryInProgress - * @details Outputs: isDialDeliveryInProgress + * @details \b Inputs: isDialDeliveryInProgress + * @details \b Outputs: isDialDeliveryInProgress * @param message Override message from Dialin which includes the override * value to override the dialysate delivery in progress flag. * @return TRUE if override successful, FALSE if not @@ -1230,8 +1231,8 @@ * @brief * The testDialGoodToDeliverStatusOverride function sets the override value * of the dialysate good to deliver status flag. - * @details Inputs: isDialysateGoodtoDeliver - * @details Outputs: isDialysateGoodtoDeliver + * @details \b Inputs: isDialysateGoodtoDeliver + * @details \b Outputs: isDialysateGoodtoDeliver * @param message Override message from Dialin which includes the override * value to override the dialysate delivery in progress flag. * @return TRUE if override successful, FALSE if not