Index: firmware/App/Services/Reservoirs.c =================================================================== diff -u -r8a553b10a224c745cb4bd6d963c867391905ba8c -re59287e5915e01c44af22fc54eafc29cb0f6c2c0 --- firmware/App/Services/Reservoirs.c (.../Reservoirs.c) (revision 8a553b10a224c745cb4bd6d963c867391905ba8c) +++ firmware/App/Services/Reservoirs.c (.../Reservoirs.c) (revision e59287e5915e01c44af22fc54eafc29cb0f6c2c0) @@ -55,8 +55,8 @@ // TODO add doxygen comments yes for all of the new variables and align them #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_VOLUME_ML 700 -#define RESERVOIR_EXTRA_TEMPERATURE 1.0 +#define ULTRAFILTER_VOLUME_ML 700 +#define RESERVOIR_EXTRA_TEMPERATURE 1.0 // ********** private data ********** @@ -95,6 +95,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; // TODO add doxygen comments static const F32 ULTRAFILTER_TAU_C_PER_MS = ULTRAFILTER_TEMPERATURE_TAU_C_PER_MIN / ( SEC_PER_MIN * MS_PER_SECOND ); @@ -109,7 +110,7 @@ * The initReservoirs function initializes the Reservoirs module. * @details Inputs: none * @details Outputs: activeReservoir.data, fillVolumeTargetMl.data, - * drainVolumeTargetMl.data, targetFillFlowRateLPM + * drainVolumeTargetMl.data, targetFillFlowRateLPM, isThisTheFirstCycle * @return none *************************************************************************/ void initReservoirs( void ) @@ -118,6 +119,7 @@ fillVolumeTargetMl.data = DEFAULT_FILL_VOLUME_ML; drainVolumeTargetMl.data = DEFAULT_DRAIN_VOLUME_ML; targetFillFlowRateLPM = 0.0; + isThisTheFirstCycle = TRUE; } /*********************************************************************//** @@ -548,6 +550,16 @@ heatersTempCalc.timeReservoirFillMS = params.timeReservoirFillMS; heatersTempCalc.tempTargetTrimmer = params.trimmerTargetTemperature; heatersTempCalc.flowTargetDialysateLPM = params.dialysateFlowLPM; + + // Set the trimmer heater target temperature since this value is needed for calculations + setHeaterTargetTemperature( DG_TRIMMER_HEATER, heatersTempCalc.tempTargetTrimmer ); + + // Check if this is the first time that the dialysate heating parameters are set in DG + if ( TRUE == isThisTheFirstCycle ) + { + resetFillStatusParameters(); + isThisTheFirstCycle = FALSE; + } } /*********************************************************************//** @@ -562,12 +574,12 @@ { F32 UFTimeConstant = 0.0; F32 targetFillVolML = getTargetFillVolumeML(); - F32 tempLastFill = getLastFillTemperature() < NEARLY_ZERO ? heatersTempCalc.tempTargetTrimmer : getLastFillTemperature(); // TODO move to reset fill items function - F32 tempAvgFill = getAvgFillTemperature() < NEARLY_ZERO ? heatersTempCalc.tempTargetTrimmer : getAvgFillTemperature(); // TODO move this to the reset function + F32 tempLastFill = getLastFillTemperature(); + F32 tempAvgFill = getAvgFillTemperature(); - 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 ultrafilterPart = ( ULTRAFILTER_VOLUME_ML / targetFillVolML ) * heatersTempCalc.tempUFFill; F32 fillPart = ( ( targetFillVolML - ULTRAFILTER_VOLUME_ML ) / targetFillVolML ) * tempAvgFill; @@ -593,7 +605,7 @@ F32 tempTarget = 0.0; F32 targetFillVolML = getTargetFillVolumeML(); F32 UFTimeConstant = 0.0; - F32 tempLastFill = getLastFillTemperature() < NEARLY_ZERO ? heatersTempCalc.tempTargetTrimmer : getLastFillTemperature(); // TODO move this to the reset function + F32 tempLastFill = getLastFillTemperature(); F32 tempReservoirUse = heatersTempCalc.tempTargetTrimmer + RESERVOIR_EXTRA_TEMPERATURE; heatersTempCalc.tempReservoirEndFill = tempReservoirUse - ( heatersTempCalc.timeReservoirFill2SwitchMS * RESERVOIR_TAU_C_PER_MS );