Index: firmware/App/Modes/ModeFill.c =================================================================== diff -u -re59287e5915e01c44af22fc54eafc29cb0f6c2c0 -r38974e7129adace42bc44cacbf384a0b1442046c --- firmware/App/Modes/ModeFill.c (.../ModeFill.c) (revision e59287e5915e01c44af22fc54eafc29cb0f6c2c0) +++ firmware/App/Modes/ModeFill.c (.../ModeFill.c) (revision 38974e7129adace42bc44cacbf384a0b1442046c) @@ -71,12 +71,13 @@ /// Fill conditions status typedef struct { - F32 fillFlowRateRunningSum; ///< Fill flow running sum. - U32 fillSampleCounter; ///< Fill flow sample counter. - F32 fillTemperatureRunningSum; ///< Fill temperature running sum. - F32 fillTemperatureAverage; ///< Fill temperature average value. - F32 fillFlowRateAverage; ///< Fill flow average value. - F32 fillLastTemperature; ///< Fill last temperature value. + F32 fillFlowRateRunningSum; ///< Fill flow running sum. + U32 fillSampleCounter; ///< Fill flow sample counter. + F32 fillTemperatureRunningSum; ///< Fill temperature running sum. + F32 fillTemperatureAverage; ///< Fill temperature average value. + F32 fillFlowRateAverage; ///< Fill flow average value. + F32 fillLastTemperature; ///< Fill last temperature value. + BOOL isThisFirstFill; ///< Fill flag to indicate whether it is the first fill or not. } FILL_CONDITION_STATUS_T; static DG_FILL_MODE_STATE_T fillState; ///< Currently active fill state. @@ -88,13 +89,13 @@ static U32 concentrateTestStartTime; ///< Starting time for concentrate test. static U32 concentratePumpPrimeCount; ///< Interval count for concentrate pump prime. -static F32 totalROFlowRateMLPM; ///< Total RO flow rate over period of time. +static F32 totalROFlowRateMLPM; ///< Total RO flow rate over period of time. static F32 acidConductivityTotal; ///< Total of acid conductivity during fill. static F32 dialysateConductivityTotal; ///< Total of dialysate conductivity during fill. static U32 conductivitySampleCount; ///< Sample count of conductivity during fill. -static OVERRIDE_F32_T usedAcidVolumeML = { 0.0, 0.0, 0.0, 0.0 }; ///< The integrated acid concentration volume has been used in ml. -static OVERRIDE_F32_T usedBicarbVolumeML = { 0.0, 0.0, 0.0, 0.0 }; ///< The integrated bicarb concentration volume has been used in ml. +static OVERRIDE_F32_T usedAcidVolumeML = { 0.0, 0.0, 0.0, 0.0 }; ///< The integrated acid concentration volume has been used in ml. +static OVERRIDE_F32_T usedBicarbVolumeML = { 0.0, 0.0, 0.0, 0.0 }; ///< The integrated bicarb concentration volume has been used in ml. // ********** private function prototypes ********** @@ -289,11 +290,25 @@ // At the beginning the last and average temperatures are considered as the trimmer heater target temperature which // is the dialysate temperature fillStatus.fillTemperatureAverage = getHeaterTargetTemperature( DG_TRIMMER_HEATER ); - fillStatus.fillLastTemperature = getHeaterTargetTemperature( DG_TRIMMER_HEATER ); + fillStatus.fillLastTemperature = getHeaterTargetTemperature( DG_TRIMMER_HEATER ) + RESERVOIR_EXTRA_TEMPERATURE; + fillStatus.isThisFirstFill = TRUE; } /*********************************************************************//** * @brief + * The isThisTheFirstFill function returns the boolean flag that indicates + * whether this is the first fill of a treatment or not. + * @details Inputs: none + * @details Outputs: none + * @return fillStatus.isThisFirstFill + *************************************************************************/ +BOOL isThisTheFirstFill( void ) +{ + return fillStatus.isThisFirstFill; +} + +/*********************************************************************//** + * @brief * The handleCheckInletWaterState function checks for inlet water quality * before jumping to dialysate production state. * @details Inputs: Temperature and conductivity alarms @@ -310,9 +325,10 @@ { concentrateTestStartTime = getMSTimerCount(); #ifndef DISABLE_MIXING - setConcentratePumpTargetSpeed( CONCENTRATEPUMPS_CP2_BICARB, CONCENTRATE_PUMP_MAX_SPEED ); - requestConcentratePumpOff( CONCENTRATEPUMPS_CP1_ACID ); - requestConcentratePumpOn( CONCENTRATEPUMPS_CP2_BICARB ); + + setConcentratePumpTargetSpeed( CONCENTRATEPUMPS_CP2_BICARB, CONCENTRATE_PUMP_MAX_SPEED ); + requestConcentratePumpOff( CONCENTRATEPUMPS_CP1_ACID ); + requestConcentratePumpOn( CONCENTRATEPUMPS_CP2_BICARB ); #endif result = DG_FILL_MODE_STATE_BICARB_PUMP_CHECK; } @@ -588,6 +604,7 @@ fillStatus.fillTemperatureRunningSum = 0.0; fillStatus.fillSampleCounter = 1; fillStatus.fillLastTemperature = getTemperatureValue( (U32)TEMPSENSORS_OUTLET_PRIMARY_HEATER ); + fillStatus.isThisFirstFill = FALSE; // Write the latest fill data into the RTC RAM for heaters control // TODO test this and make sure it is writing it correctly Index: firmware/App/Modes/ModeFill.h =================================================================== diff -u -re59287e5915e01c44af22fc54eafc29cb0f6c2c0 -r38974e7129adace42bc44cacbf384a0b1442046c --- firmware/App/Modes/ModeFill.h (.../ModeFill.h) (revision e59287e5915e01c44af22fc54eafc29cb0f6c2c0) +++ firmware/App/Modes/ModeFill.h (.../ModeFill.h) (revision 38974e7129adace42bc44cacbf384a0b1442046c) @@ -47,6 +47,8 @@ void resetFillStatusParameters( void ); +BOOL isThisTheFirstFill( void ); + /**@}*/ #endif Index: firmware/App/Modes/ModeStandby.c =================================================================== diff -u -re59287e5915e01c44af22fc54eafc29cb0f6c2c0 -r38974e7129adace42bc44cacbf384a0b1442046c --- firmware/App/Modes/ModeStandby.c (.../ModeStandby.c) (revision e59287e5915e01c44af22fc54eafc29cb0f6c2c0) +++ firmware/App/Modes/ModeStandby.c (.../ModeStandby.c) (revision 38974e7129adace42bc44cacbf384a0b1442046c) @@ -90,6 +90,10 @@ // Reset the heaters efficiency for another treatment resetHeatersEfficiency(); + + // Initialize the reservoirs parameters for another treatment. + // This is to make sure the boolean flag for the first fill is set to TRUE. + initReservoirs(); } /*********************************************************************//** Index: firmware/App/Services/Reservoirs.c =================================================================== diff -u -rf5dc98b3d5fcd39e3ab502fbe81110e188ce0ec5 -r38974e7129adace42bc44cacbf384a0b1442046c --- firmware/App/Services/Reservoirs.c (.../Reservoirs.c) (revision f5dc98b3d5fcd39e3ab502fbe81110e188ce0ec5) +++ firmware/App/Services/Reservoirs.c (.../Reservoirs.c) (revision 38974e7129adace42bc44cacbf384a0b1442046c) @@ -52,12 +52,12 @@ #define MAX_REDUNDANT_LOAD_CELL_DIFF 50.0 ///< Maximum difference in redundant load cells when determining if fill completed. #define RESERVOIR_TEMPERATURE_TAU_C_PER_MIN -0.512 ///< Reservoir temperature time constant C/min. -#define ULTRAFILTER_TEMPERATURE_TAU_C_PER_MIN -0.512 ///< Ultrafilter temperature time constant C/min. +#define ULTRAFILTER_TEMPERATURE_TAU_C_PER_MIN -4.565 ///< Ultrafilter temperature time constant C/min. #define ULTRAFILTER_VOLUME_ML 700 ///< Ultrafilter volume in milliliters. -#define RESERVOIR_EXTRA_TEMPERATURE 1.0 ///< Reservoirs extra margin temperature. // ********** private data ********** +/// Heaters temperature calculation data structure typedef struct { U32 timeReservoirCycleMS; ///< Time reservoir cycle in milliseconds. @@ -72,7 +72,7 @@ F32 flowTargetDialysateLPM; ///< Dialysate target flow rate in L/min. } HEATERS_TEMPERATURE_CALC_DATA_T; -static HEATERS_TEMPERATURE_CALC_DATA_T heatersTempCalc; +static HEATERS_TEMPERATURE_CALC_DATA_T heatersTempCalc; ///< Heaters temperature calculations data structure. static U32 reservoirDataPublicationTimerCounter = 0; ///< used to schedule reservoir data publication to CAN bus. static OVERRIDE_U32_T activeReservoir = { 0, 0, 0, 0 }; ///< The active reservoir that the DG is filling/draining/etc. @@ -91,7 +91,7 @@ static BOOL tareLoadCellRequest; ///< Flag indicates if load cell tare has been requested by HD. static DG_RESERVOIR_VOLUME_RECORD_T reservoirsCalRecord; ///< DG reservoirs non-volatile record. static F32 targetFillFlowRateLPM; ///< Target fill flow rate in L/min. -static BOOL isThisTheFirstCycle = TRUE; +static BOOL isThisTheFirstCycle = TRUE; ///< Boolean flag to indicate whether this is the first cycle. /// Conversion of ultrafilter tau in C/min to C/ms. static const F32 ULTRAFILTER_TAU_C_PER_MS = ULTRAFILTER_TEMPERATURE_TAU_C_PER_MIN / ( SEC_PER_MIN * MS_PER_SECOND ); @@ -346,7 +346,6 @@ // stop fill command only valid in fill mode if ( DG_MODE_FILL == getCurrentOperationMode() ) { - fillVolumeTargetMl.data = 0; requestNewOperationMode( DG_MODE_GENE ); cmdResponse.rejected = FALSE; } @@ -613,18 +612,26 @@ F32 UFTimeConstant = 0.0; F32 tempLastFill = getLastFillTemperature(); - F32 tempReservoirUse = heatersTempCalc.tempTargetTrimmer + RESERVOIR_EXTRA_TEMPERATURE; - heatersTempCalc.tempReservoirEndFill = tempReservoirUse - ( heatersTempCalc.timeReservoirFill2SwitchMS * RESERVOIR_TAU_C_PER_MS ); - heatersTempCalc.tempReservoir0 = heatersTempCalc.tempReservoirEndFill - ( ( heatersTempCalc.timeReservoirFillMS * 0.5 ) * RESERVOIR_TAU_C_PER_MS ); + if ( FALSE == isThisTheFirstFill() ) + { + F32 tempReservoirUse = heatersTempCalc.tempTargetTrimmer + RESERVOIR_EXTRA_TEMPERATURE; + heatersTempCalc.tempReservoirEndFill = tempReservoirUse - ( heatersTempCalc.timeReservoirFill2SwitchMS * RESERVOIR_TAU_C_PER_MS ); + heatersTempCalc.tempReservoir0 = heatersTempCalc.tempReservoirEndFill - ( ( heatersTempCalc.timeReservoirFillMS * 0.5 ) * RESERVOIR_TAU_C_PER_MS ); - heatersTempCalc.timeUFDecayMS = (F32)heatersTempCalc.timeReservoirCycleMS - heatersTempCalc.timeReservoirFillMS; - UFTimeConstant = heatersTempCalc.timeUFDecayMS * ULTRAFILTER_TAU_C_PER_MS; - heatersTempCalc.tempUFFill = tempLastFill + UFTimeConstant; + heatersTempCalc.timeUFDecayMS = (F32)heatersTempCalc.timeReservoirCycleMS - heatersTempCalc.timeReservoirFillMS; + UFTimeConstant = heatersTempCalc.timeUFDecayMS * ULTRAFILTER_TAU_C_PER_MS; + heatersTempCalc.tempUFFill = tempLastFill + UFTimeConstant; - F32 tempTargetNumerator = heatersTempCalc.tempReservoir0 - ( ( ULTRAFILTER_VOLUME_ML / targetFillVolML ) * heatersTempCalc.tempUFFill ); - F32 targetTempDenominator = ( ( targetFillVolML - ULTRAFILTER_VOLUME_ML ) / targetFillVolML ); - tempTarget = tempTargetNumerator / targetTempDenominator; + F32 tempTargetNumerator = heatersTempCalc.tempReservoir0 - ( ( ULTRAFILTER_VOLUME_ML / targetFillVolML ) * heatersTempCalc.tempUFFill ); + F32 targetTempDenominator = ( ( targetFillVolML - ULTRAFILTER_VOLUME_ML ) / targetFillVolML ); + tempTarget = tempTargetNumerator / targetTempDenominator; + } + else + { + tempTarget = heatersTempCalc.tempTargetTrimmer + RESERVOIR_EXTRA_TEMPERATURE; + } + return tempTarget; } Index: firmware/App/Services/Reservoirs.h =================================================================== diff -u -r8a553b10a224c745cb4bd6d963c867391905ba8c -r38974e7129adace42bc44cacbf384a0b1442046c --- firmware/App/Services/Reservoirs.h (.../Reservoirs.h) (revision 8a553b10a224c745cb4bd6d963c867391905ba8c) +++ firmware/App/Services/Reservoirs.h (.../Reservoirs.h) (revision 38974e7129adace42bc44cacbf384a0b1442046c) @@ -34,6 +34,8 @@ // ********** public definitions ********** #define MAX_RESERVOIR_VOLUME_ML 2000 ///< Maximum reservoir volume in mL. +// TODO the extra temperature includes 1 degree of extra temperature to account for the concentrate pumps +#define RESERVOIR_EXTRA_TEMPERATURE 2.0 ///< Reservoirs extra margin temperature. /// Fill command data structure. typedef struct