Index: firmware/App/Controllers/Ultrafiltration.c =================================================================== diff -u -rf2b23abd44f71103b3ef6b0a96f18cc82d263735 -r25dbc6221b63e20fe61b2af0ce9c9f56bf13e807 --- firmware/App/Controllers/Ultrafiltration.c (.../Ultrafiltration.c) (revision f2b23abd44f71103b3ef6b0a96f18cc82d263735) +++ firmware/App/Controllers/Ultrafiltration.c (.../Ultrafiltration.c) (revision 25dbc6221b63e20fe61b2af0ce9c9f56bf13e807) @@ -19,6 +19,7 @@ #include "Messaging.h" #include "OperationModes.h" #include "TaskGeneral.h" +#include "Temperature.h" #include "TDInterface.h" #include "TestSupport.h" #include "Ultrafiltration.h" @@ -31,12 +32,18 @@ // ********** private definitions ********** #define UF_DATA_PUBLISH_INTERVAL ( 1000 / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the ultrafiltration data published. +#define UF_COMPENSATION_PERIOD ( 2 * SEC_PER_MIN * MS_PER_SECOND ) ///< Interval at which the ultrafiltration compenstaion executed. +#define UF_COMP_INTERVAL ( UF_COMPENSATION_PERIOD / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the peroidic ultrafiltration compensation calculated. +#define COMP_SLOPE -0.000376F ///< UF Temperature compensation slope factor +#define COMP_INTERCEPT 1.007269F ///< UF temperature compensation intercept factor #define ZERO_RATE 0.0F ///< Zero value. // ********** private data ********** static UF_EXEC_STATE_T ufExecState; ///< Current ultrafiltration executive state. static BOOL isUltrafiltrationRequested; ///< Flag indicating ultrafiltration request. +static U32 currentUFCompCounter; ///< Counter (in task interval) to initiate the periodic ultrafiltration temperature compensation. +static F32 compUFrate; ///< compensated UF rate static U32 ufDataPublicationTimerCounter; ///< Used to schedule ultrafiltration data publication to CAN bus. static OVERRIDE_U32_T ufDataPublishInterval; ///< Ultrafiltration data publish interval. @@ -45,6 +52,7 @@ static UF_EXEC_STATE_T handleUFRunningState( void ); static UF_EXEC_STATE_T handleUFPausedState( void ); static void updateUFRequest( void ); +static void UpdateUFCompensation( void ); static void publishUltrafiltrationData( void ); /*********************************************************************//** @@ -62,6 +70,8 @@ ufDataPublishInterval.ovInitData = 0; ufDataPublishInterval.override = OVERRIDE_RESET; isUltrafiltrationRequested = FALSE; + currentUFCompCounter = 0; + compUFrate = getTDUFRate(); ufDataPublicationTimerCounter = 0; } @@ -92,6 +102,9 @@ // Calculate UF volume and determine UF pause/run updateUFRequest(); + // Compensate balancing error at defined interval + UpdateUFCompensation(); + // execute current ultrafiltration exec state switch ( ufExecState ) { @@ -129,7 +142,7 @@ if ( TRUE == isUltrafiltrationRequested ) { - setConcentratePumpTargetSpeed( D76_PUMP, getTDUFRate(), DOSING_CONT_VOLUME ); + setConcentratePumpTargetSpeed( D76_PUMP, compUFrate, DOSING_CONT_VOLUME ); requestConcentratePumpOn( D76_PUMP ); //Tranistion to run state @@ -159,7 +172,7 @@ else { // Get the updated rate if there is any change - setConcentratePumpTargetSpeed( D76_PUMP, getTDUFRate(), DOSING_CONT_VOLUME ); + setConcentratePumpTargetSpeed( D76_PUMP, compUFrate, DOSING_CONT_VOLUME ); } return state; @@ -189,6 +202,34 @@ /*********************************************************************//** * @brief + * The UpdateUFCompensation function updates the ultrafiltration rate + * based on the dialysate temperature compensation. + * @details \b Inputs: D4 and D50 temperature + * @details \b Outputs: updated UF rate + * @return none. + *************************************************************************/ +static void UpdateUFCompensation( void ) +{ + if ( ++currentUFCompCounter >= UF_COMP_INTERVAL ) + { + 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 + + //Update compensate UF rate with the balancing chamber error + if ( getTDUFRate() > ZERO_RATE ) + { + compUFrate = getTDUFRate() + balancingError; + } + + currentUFCompCounter = 0; + } +} + +/*********************************************************************//** + * @brief * The getCurrentUFExecState function returns the current state * of the ultrafiltration. * @details \b Inputs: ufExecState @@ -218,6 +259,7 @@ data.ufExecState = (U32)ufExecState; data.ufRate = getTDUFRate(); + data.compUFrate = compUFrate; data.isUFRequested = (U32)isUltrafiltrationRequested; broadcastData( MSG_ID_DD_UF_DATA, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08*)&data, sizeof( UF_DATA_T ) );