Index: firmware/App/Controllers/Ultrafiltration.c =================================================================== diff -u -r387ea33c2e45705550905bc1a97e13db1cc95bf8 -r94789b2f2324d5901685b6ff7b6224d4af3a0276 --- firmware/App/Controllers/Ultrafiltration.c (.../Ultrafiltration.c) (revision 387ea33c2e45705550905bc1a97e13db1cc95bf8) +++ firmware/App/Controllers/Ultrafiltration.c (.../Ultrafiltration.c) (revision 94789b2f2324d5901685b6ff7b6224d4af3a0276) @@ -1,17 +1,17 @@ /************************************************************************** * -* Copyright (c) 2024-2025 Diality Inc. - All Rights Reserved. +* Copyright (c) 2025-2026 Diality Inc. - All Rights Reserved. * * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * * @file Ultrafiltration.c * * @author (last) Vinayakam Mani -* @date (last) 23-Jul-2025 +* @date (last) 14-Apr-2026 * * @author (original) Vinayakam Mani -* @date (original) 23-Jul-2025 +* @date (original) 28-Jul-2025 * ***************************************************************************/ @@ -97,16 +97,31 @@ * @details \b Outputs: ufExecState * @details \b Alarm: ALARM_ID_DD_SOFTWARE_FAULT when wrong ultrafiltration * state invoked. + * @details Warning: The compensated UF should be caclulated first and then + * call 'updateUFRequest' function. * @return current state. *************************************************************************/ U32 execUFControl( void ) { + // Trimmer heater enabled, hence UF temp compensation is optional + if ( getTestConfigStatus( TEST_CONFIG_DD_DISABLE_UF_TEMP_COMPENSATION ) != TRUE ) + { + // Compensate balancing error at defined interval + UpdateUFCompensation(); + } + else if ( TRUE == isUFRateUpdated ) + { + //get updated UF rate + compUFrate = getTDUFRate(); + + // Update UF rate + setConcentratePumpTargetSpeed( D76_PUMP, compUFrate, DOSING_CONT_VOLUME ); + isUFRateUpdated = FALSE; + } + // Calculate UF volume and determine UF pause/run updateUFRequest(); - // Compensate balancing error at defined interval - UpdateUFCompensation(); - // execute current ultrafiltration exec state switch ( ufExecState ) { @@ -181,17 +196,16 @@ /*********************************************************************//** * @brief - * The updateUFRequest function updates the ultrafiltration rate per iteration - * and of the ultrafiltration. - * @details \b Inputs: TD Uf rate, TD Dialysate flow rate and bypass flag - * @details \b Outputs: ufVolumeperIteration , isUltrafiltrationRequested + * The updateUFRequest function updates the ultrafiltration requested + * flag to true or false based on the compensated UF rate. + * @details \b Inputs: compensated UF + * @details \b Outputs: isUltrafiltrationRequested * @return none. *************************************************************************/ static void updateUFRequest( void ) { // update latest UF run/pause request - if ( ( getTDUFRate() > ZERO_RATE ) && ( TRUE != getTDDialyzerBypass() ) && - ( getTDDialysateFlowrate() > ZERO_RATE ) ) + if ( compUFrate > ZERO_RATE ) { isUltrafiltrationRequested = TRUE; } @@ -226,12 +240,26 @@ { if ( ( ++currentUFCompCounter >= UF_COMP_INTERVAL ) || ( TRUE == isUFRateUpdated ) ) { - F32 freshDensity = ( COMP_SLOPE * getD4AverageTemperature() ) + COMP_INTERCEPT; // Fresh side dialysate density - F32 spentDensity = ( COMP_SLOPE * getD50AverageTemperature() ) + COMP_INTERCEPT; // spent side dialysate density - F32 compFreshFlowrate = getTDDialysateFlowrate() * freshDensity; // Qd * fresh density - F32 compSpentFlowrate = getTDDialysateFlowrate() * spentDensity; // Qd * spent density - F32 balancingError = compFreshFlowrate - compSpentFlowrate; // Error in g/min + F32 freshDensity = 0.0F; + F32 spentDensity = 0.0F; + F32 compFreshFlowrate = 0.0F; + F32 compSpentFlowrate = 0.0F; + F32 balancingError = 0.0F; + // Fresh side dialysate density + if ( getTestConfigStatus( TEST_CONFIG_DD_FP_ENABLE_BETA_1_0_HW ) == TRUE ) + { + freshDensity = ( COMP_SLOPE * getFilteredTemperatureValue( D4_TEMP ) ) + COMP_INTERCEPT; + } + else + { + freshDensity = ( COMP_SLOPE * getFilteredTemperatureValue( D99_TEMP ) ) + COMP_INTERCEPT; + } + spentDensity = ( COMP_SLOPE * getFilteredTemperatureValue( D50_TEMP ) ) + COMP_INTERCEPT; // spent side dialysate density + compFreshFlowrate = getTDDialysateFlowrate() * freshDensity; // Qd * fresh density + compSpentFlowrate = getTDDialysateFlowrate() * spentDensity; // Qd * spent density + balancingError = compFreshFlowrate - compSpentFlowrate; // Error in g/min + //Update compensate UF rate with the balancing chamber error compUFrate = getTDUFRate() + balancingError;