Index: firmware/App/Controllers/Ultrafiltration.c =================================================================== diff -u -r0bcac6885c8461b05da276fd245b580b7339ddfd -r78dc7a98fb2a3d28bbdeb4eade1bba03641433d3 --- firmware/App/Controllers/Ultrafiltration.c (.../Ultrafiltration.c) (revision 0bcac6885c8461b05da276fd245b580b7339ddfd) +++ firmware/App/Controllers/Ultrafiltration.c (.../Ultrafiltration.c) (revision 78dc7a98fb2a3d28bbdeb4eade1bba03641433d3) @@ -15,6 +15,7 @@ * ***************************************************************************/ +#include "BalancingChamber.h" #include "ConcentratePumps.h" #include "Messaging.h" #include "OperationModes.h" @@ -34,13 +35,10 @@ #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 @@ -50,10 +48,7 @@ // ********** private function prototypes ********** -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 ); /*********************************************************************//** @@ -65,7 +60,6 @@ *************************************************************************/ void initUltrafiltration( void ) { - ufExecState = DD_UF_PAUSED; ufDataPublishInterval.data = UF_DATA_PUBLISH_INTERVAL; ufDataPublishInterval.ovData = UF_DATA_PUBLISH_INTERVAL; ufDataPublishInterval.ovInitData = 0; @@ -74,7 +68,7 @@ currentUFCompCounter = 0; compUFrate = getTDUFRate(); ufDataPublicationTimerCounter = 0; - isUFRateUpdated = FALSE; + isUFRateUpdated = TRUE; } /*********************************************************************//** @@ -92,106 +86,55 @@ /*********************************************************************//** * @brief - * The execUFControl function executes the ultrafiltration state machine. - * @details \b Inputs: ufExecState - * @details \b Outputs: ufExecState - * @details \b Alarm: ALARM_ID_DD_SOFTWARE_FAULT when wrong ultrafiltration - * state invoked. + * The handleUFControl function handles the ultrafiltration run/stop states + * and calcualtes the final ultrafilration rate if the temp compensation is enbaled. + * @details \b Inputs: balancing error, TD UF rate + * @details \b Outputs: calculated UF rate * @details Warning: The compensated UF should be caclulated first and then * call 'updateUFRequest' function. * @return current state. *************************************************************************/ -U32 execUFControl( void ) +void handleUFControl( void ) { - // Trimmer heater enabled, hence UF temp compensation is optional + F32 balancingError; + if ( getTestConfigStatus( TEST_CONFIG_DD_DISABLE_UF_TEMP_COMPENSATION ) != TRUE ) { - // Compensate balancing error at defined interval - UpdateUFCompensation(); + if ( ( ++currentUFCompCounter >= UF_COMP_INTERVAL ) || ( TRUE == isUFRateUpdated ) ) + { + // Find the offset + balancingError = getBalancingChamberError(); + // Update compensate UF rate with the balancing chamber error + compUFrate = getTDUFRate() + balancingError; + + currentUFCompCounter = 0; + isUFRateUpdated = FALSE; + } } else if ( TRUE == isUFRateUpdated ) { - //get updated UF rate + // Get updated UF rate compUFrate = getTDUFRate(); - - // Update UF rate - setConcentratePumpTargetSpeed( D76_PUMP, compUFrate, DOSING_CONT_VOLUME ); - isUFRateUpdated = FALSE; + // Reset the flag + isUFRateUpdated = FALSE; } // Calculate UF volume and determine UF pause/run updateUFRequest(); - // execute current ultrafiltration exec state - switch ( ufExecState ) - { - case DD_UF_PAUSED: - ufExecState = handleUFPausedState(); - break; - - case DD_UF_RUNNING: - ufExecState = handleUFRunningState(); - break; - - default: - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DD_SOFTWARE_FAULT, SW_FAULT_ID_UF_INVALID_EXEC_STATE, ufExecState ) - ufExecState = DD_UF_PAUSED; - break; - } - - //Publish ultrafiltration data - publishUltrafiltrationData(); - - return ufExecState; -} - -/*********************************************************************//** - * @brief - * The handleUFPausedState function handles the ultrafiltration - * paused state. - * @details \b Inputs:isUltrafiltrationRequested - * @details \b Outputs: UF state - * @return next UF state. - *************************************************************************/ -static UF_EXEC_STATE_T handleUFPausedState( void ) -{ - UF_EXEC_STATE_T state = DD_UF_PAUSED; - + // UF pump run or stop based on the flag if ( TRUE == isUltrafiltrationRequested ) { - // start with TD UF rate - compUFrate = getTDUFRate(); - currentUFCompCounter = 0; - setConcentratePumpTargetSpeed( D76_PUMP, compUFrate, DOSING_CONT_VOLUME ); requestConcentratePumpOn( D76_PUMP ); - - //Tranistion to run state - state = DD_UF_RUNNING; } - - return state; -} - -/*********************************************************************//** - * @brief - * The handleUFPausedState function handles the ultrafiltration - * running state. - * @details \b Inputs:isUltrafiltrationRequested - * @details \b Outputs: UF state - * @return next UF state. - *************************************************************************/ -static UF_EXEC_STATE_T handleUFRunningState( void ) -{ - UF_EXEC_STATE_T state = DD_UF_RUNNING; - - if ( TRUE != isUltrafiltrationRequested ) + else { requestConcentratePumpOff( D76_PUMP, FALSE ); - state = DD_UF_PAUSED; } - return state; + //Publish ultrafiltration data + publishUltrafiltrationData(); } /*********************************************************************//** @@ -234,62 +177,6 @@ /*********************************************************************//** * @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 ) || ( TRUE == isUFRateUpdated ) ) - { - 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; - - // Update UF rate - setConcentratePumpTargetSpeed( D76_PUMP, compUFrate, DOSING_CONT_VOLUME ); - - currentUFCompCounter = 0; - isUFRateUpdated = FALSE; - } -} - -/*********************************************************************//** - * @brief - * The getCurrentUFExecState function returns the current state - * of the ultrafiltration. - * @details \b Inputs: ufExecState - * @details \b Outputs: none - * @return the current state of UF execution state. - *************************************************************************/ -UF_EXEC_STATE_T getCurrentUFExecState( void ) -{ - return ufExecState; -} - -/*********************************************************************//** - * @brief * The publishUltrafiltrationData function broadcasts the ultrafiltration * data at defined interval. * @details \b Inputs: ufDataPublicationTimerCounter @@ -304,7 +191,6 @@ { UF_DATA_T data; - data.ufExecState = (U32)ufExecState; data.ufRate = getTDUFRate(); data.compUFrate = compUFrate; data.isUFRequested = (U32)isUltrafiltrationRequested;