Index: firmware/App/DDCommon.h =================================================================== diff -u -rd2e48222c175acf0e90d61a1177c7516e03ba5df -r6be1432c0c90124ca24e20544987b09bc4dc59a0 --- firmware/App/DDCommon.h (.../DDCommon.h) (revision d2e48222c175acf0e90d61a1177c7516e03ba5df) +++ firmware/App/DDCommon.h (.../DDCommon.h) (revision 6be1432c0c90124ca24e20544987b09bc4dc59a0) @@ -57,6 +57,10 @@ //Uncomment below to disable Teensy conductivity driver #define __TEENSY_CONDUCTIVITY_DRIVER__ 1 +//Uncomment below to disable revised heater model +//#define __REVISED_HEATER_MODEL__ 1 + + #include #include #endif Index: firmware/App/Modes/ModeGenDialysate.c =================================================================== diff -u -rbd896114f304304a7096b30b2a85067a64645e82 -r6be1432c0c90124ca24e20544987b09bc4dc59a0 --- firmware/App/Modes/ModeGenDialysate.c (.../ModeGenDialysate.c) (revision bd896114f304304a7096b30b2a85067a64645e82) +++ firmware/App/Modes/ModeGenDialysate.c (.../ModeGenDialysate.c) (revision 6be1432c0c90124ca24e20544987b09bc4dc59a0) @@ -14,6 +14,7 @@ * @date (original) 06-Nov-2024 * ***************************************************************************/ +#include "math.h" #include "BalancingChamber.h" #include "ConcentratePumps.h" @@ -63,6 +64,15 @@ #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 B1B2_HEAT_DIS_FIRST_COEFF 0.00000000487858F ///< First coefficient for Heat loss dissipation calculation from D4 to D28(cubic equation). +#define B1B2_HEAT_DIS_SEC_COEFF 0.0000063124F ///< Second coefficient for Heat loss dissipation calculation from D4 to D28. +#define B1B2_HEAT_DIS_THIRD_COEFF 0.00258513F ///< Third coefficient for Heat loss dissipation calculation from D4 to D28. +#define B1B2_HEAT_DIS_FOURTH_COEFF 0.242013F ///< Fourth coefficient for Heat loss dissipation calculation from D4 to D28. +#define B3_HEAT_DIS_FIRST_COEFF 0.0000000067756F ///< First coefficient for Heat loss dissipation calculation from D28 to Dialyzer(cubic equation). +#define B3_HEAT_DIS_SEC_COEFF 0.0000085278F ///< Second coefficient for Heat loss dissipation calculation from D28 to Dialyzer. +#define B3_HEAT_DIS_THIRD_COEFF 0.0035126F ///< Third coefficient for Heat loss dissipation calculation from D28 to Dialyzer. +#define B3_HEAT_DIS_FOURTH_COEFF 0.63893F ///< Fourth coefficient for Heat loss dissipation calculation from D28 to Dialyzer. + //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., /// Payload record structure for Gen dialysate execution state set request @@ -103,6 +113,9 @@ static void updateDialysateToDialyzerFlowRate( void ); static void checkDialysateTemperature( void ); static void monitorChamberLevelStatus( void ); +static F32 calculateHeatDissipationB1andB2( void ); +static F32 calculateHeatDissipationB3( void ); +static F32 calculateInitialTemp( F32 targetTemp, F32 heatDissipation ); static void publishGenDialysateModeData( void ); /*********************************************************************//** @@ -529,9 +542,14 @@ static void calculateTargetDialysateTemp( void ) { // Get the dialysate flow rate from TD - F32 dialFlowrate = getTDDialysateFlowrate(); - F32 deltaTemp = 0.0F; - + F32 dialFlowrate = getTDDialysateFlowrate(); + F32 deltaTemp = 0.0F; + F32 heatDissipation_b1b2 = 0.0F; + F32 heatDissipation_b3 = 0.0F; + F32 targetTemp = getTDTargetDialysateTemperature(); + F32 initialTempAtD28 = 0.0F; + F32 initialTempAtD4 = 0.0F; +#ifndef __REVISED_HEATER_MODEL__ if ( dialFlowrate >= LOW_DIAL_FLOW_RATE ) { // linear releationship seen against high dialysate flowrate Vs DeltaTemp @@ -544,13 +562,98 @@ deltaTemp = ( QUAD_FIRST_COEFFICIENT * dialFlowrate * dialFlowrate ) + ( QUAD_SECOND_COEFFICIENT * dialFlowrate ) + QUAD_THIRD_COEFFICIENT; } - // Adjust the D4 target temperature targetHydChamberFluidTemp.data = getTDTargetDialysateTemperature() + deltaTemp; +#else + //Lets calculate the B1,B2 and B3 heat dissipation factors + heatDissipation_b3 = calculateHeatDissipationB3(); + heatDissipation_b1b2 = calculateHeatDissipationB1andB2(); + + // Reverse calculation of Initial temp at D28 to get the target dialyzer temperature + initialTempAtD28 = calculateInitialTemp( targetTemp, heatDissipation_b3 ); + // calculation of Initial temp at D4 to get the target temp at D28 level + initialTempAtD4 = calculateInitialTemp( initialTempAtD28, heatDissipation_b1b2 ); + + targetHydChamberFluidTemp.data = initialTempAtD4; +#endif } /*********************************************************************//** * @brief + * The calculateHeatDissipationB1andB2 function calculates the heat dissipation + * constants called B1 and B2 that describes the heat loss between D4 to D28 in + * the PID flow path. + * @details \b Inputs: Qd. + * @details \b Outputs: none + * @return the calculated heat dissipation constants. + *************************************************************************/ +static F32 calculateHeatDissipationB1andB2( void ) +{ + // Get the dialysate flow rate from TD + F32 b1b2 = 0.0F; + F32 qd = getTDDialysateFlowrate(); + F32 firstPart = B1B2_HEAT_DIS_FIRST_COEFF * qd * qd * qd; + F32 secondPart = B1B2_HEAT_DIS_SEC_COEFF * qd * qd; + F32 thirdPart = B1B2_HEAT_DIS_THIRD_COEFF * qd; + + // B1B2 = 4.87858E-09x3 - 6.31264E-06x2 + 2.58513E-03x - 2.42013E-01 + b1b2 = firstPart - secondPart + thirdPart - B1B2_HEAT_DIS_FOURTH_COEFF; + + return b1b2; +} + +/*********************************************************************//** + * @brief + * The calculateHeatDissipationB3 function calculates the heat dissipation + * constants called B3 that describes the heat loss between D28 to dialyzer in + * the PID flow path. + * @details \b Inputs: Qd. + * @details \b Outputs: none + * @return the calculated heat dissipation constant. + *************************************************************************/ +static F32 calculateHeatDissipationB3( void ) +{ + // Get the dialysate flow rate from TD + F32 b3 = 0.0F; + F32 qd = getTDDialysateFlowrate(); + F32 firstPart = B3_HEAT_DIS_FIRST_COEFF * qd * qd * qd; + F32 secondPart = B3_HEAT_DIS_SEC_COEFF * qd * qd; + F32 thirdPart = B3_HEAT_DIS_THIRD_COEFF * qd; + + // B3 = 6.7756E-09x3 - 8.5278E-06x2 + 3.5126E-03x - 6.3893E-01 + b3 = firstPart - secondPart + thirdPart - B3_HEAT_DIS_FOURTH_COEFF; + + return b3; +} + +/*********************************************************************//** + * @brief + * The calculateInitialTemp function calculates the initial temperature + * required to get the target temperature considering heat loss. + * @details \b Inputs: ambient temperature + * @details \b Outputs: none + * @param targetTemp the target/final temperature + * @param heatDissipation the heat dissipation constant + * @return the calculated initial temperature. + *************************************************************************/ +static F32 calculateInitialTemp( F32 targetTemp, F32 heatDissipation ) +{ + // Get the ambient temperature from TD + //TODO : replace once amb temp is in place. using board temperature + // to make use of feeding the value via dialin + F32 ambTemp = getTemperatureValue( BRD_TEMP ); + F32 expB = exp(-heatDissipation); + F32 tempDiff = targetTemp - ambTemp; + F32 T0 = 0.0F; + + // T0 = Tamb + (Tf -Tamb)e^-B + T0 = ambTemp + ( tempDiff * expB ); + + return T0; +} + +/*********************************************************************//** + * @brief * The handleGenDDialysateIsolatedUFState function performs the * Isolated ultrafiltration operations. * @details \b Inputs: none. @@ -1056,8 +1159,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 @@ -1073,8 +1176,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