Index: firmware/App/Services/Reservoirs.c =================================================================== diff -u -r22176ce95e49213c48454f34ddf5d29b8109f2cb -r669f36cf32c3b500aa2fd5b08c58ee5e6b2e7f08 --- firmware/App/Services/Reservoirs.c (.../Reservoirs.c) (revision 22176ce95e49213c48454f34ddf5d29b8109f2cb) +++ firmware/App/Services/Reservoirs.c (.../Reservoirs.c) (revision 669f36cf32c3b500aa2fd5b08c58ee5e6b2e7f08) @@ -17,6 +17,7 @@ #include // for memcpy() +#include "ConcentratePumps.h" #include "DrainPump.h" #include "Heaters.h" #include "LoadCell.h" @@ -50,6 +51,7 @@ #define MAX_REDUNDANT_LOAD_CELL_DIFF 50.0F ///< Maximum difference in redundant load cells when determining if fill completed. #define MAX_DRAIN_RPM_MLP 2400.0F ///< Maximum drain RPM in mL/min. #define DATA_PUBLISH_COUNTER_START_COUNT 5 ///< Data publish counter start count. +#define ENVIRONMENT_TEMPERATURE_C 23.5F ///< Device's environment temperature in C. // TODo add this to the cal records // ********** private data ********** @@ -66,6 +68,9 @@ F32 tempReservoirEndFill; ///< Temperature reservoir at the end of the fill in C. F32 tempTargetTrimmer; ///< Temperature target trimmer heater in C. F32 flowTargetDialysateLPM; ///< Dialysate target flow rate in L/min. + F32 tempRsrvr0ActualTrimmer; ///< Temperature actual reservoir in C. + F32 tempFillMixAvgTrimmer; ///< Temperature fill mix average trimmer in C. + F32 tempRsrvrEndFillTrimmer; ///< Temperature reservoir end fill trimmer in C. } HEATERS_TEMPERATURE_CALC_DATA_T; /// Reservoirs previous status @@ -536,7 +541,7 @@ heatersTempCalc.flowTargetDialysateLPM = params.dialysateFlowLPM; // Set the trimmer heater target temperature since this value is needed for calculations - setHeaterTargetTemperature( DG_TRIMMER_HEATER, heatersTempCalc.tempTargetTrimmer ); + //setHeaterTargetTemperature( DG_TRIMMER_HEATER, getTrimmerHeaterTargetTemperature() ); // TODO remove // Check if this is the first time that the dialysate heating parameters are set in DG if ( TRUE == isThisTheFirstCycle ) @@ -589,19 +594,24 @@ * @brief * The getPrimaryHeaterTargetTemperature function calculates the primary * heater target temperature and returns target temperature value. - * @details Inputs: none + * @details Inputs: heatingConstsCalRecord * @details Outputs: heatersTempCalc * @return primary heater target temperature *************************************************************************/ F32 getPrimaryHeaterTargetTemperature( void ) { // TODO once the equations are solidified, add the equations as comments to the lines - F32 tempTarget = 0.0; - F32 targetFillVolML = getTargetFillVolumeML(); - F32 UFTimeConstant = 0.0; - F32 tempLastFill = getLastFillTemperature(); - F32 UFTauCPerMS = heatingConstsCalRecord.ultrafilterTempTauCPerMin / ( SEC_PER_MIN * MS_PER_SECOND ); - F32 RsrvrTauCPerMS = heatingConstsCalRecord.reservoirTempTauCPerMin / ( SEC_PER_MIN * MS_PER_SECOND ); + F32 tempTarget = 0.0; + F32 priTargetTemp = 0.0; + F32 targetFillVolML = getTargetFillVolumeML(); + F32 UFTimeConstant = 0.0; + F32 tempLastFill = getLastFillTemperature(); + F32 UFTauCPerMS = heatingConstsCalRecord.ultrafilterTempTauCPerMin / ( SEC_PER_MIN * MS_PER_SECOND ); + F32 RsrvrTauCPerMS = heatingConstsCalRecord.reservoirTempTauCPerMin / ( SEC_PER_MIN * MS_PER_SECOND ); + F32 targetROFlowLPM = getTargetROPumpFlowRateLPM(); + F32 tgtAicdFlowLPM = getConcentratePumpTargetFlowMLPM( CONCENTRATEPUMPS_CP1_ACID ) / ML_PER_LITER; + F32 tgtBicarbFlowLPM = getConcentratePumpTargetFlowMLPM( CONCENTRATEPUMPS_CP2_BICARB ) / ML_PER_LITER; + F32 tgtTotalFlowLPM = targetROFlowLPM + tgtAicdFlowLPM + tgtBicarbFlowLPM; if ( FALSE == isThisTheFirstFill() ) { @@ -626,11 +636,57 @@ tempTarget = heatersTempCalc.tempTargetTrimmer + RESERVOIR_EXTRA_TEMPERATURE; } - return tempTarget; + if ( targetROFlowLPM > 0 ) + { + priTargetTemp = ( tempTarget * ( tgtTotalFlowLPM / targetROFlowLPM ) ) - ( ENVIRONMENT_TEMPERATURE_C * ( tgtAicdFlowLPM / targetROFlowLPM ) ) - + ( ENVIRONMENT_TEMPERATURE_C * ( tgtBicarbFlowLPM / targetROFlowLPM ) ); + } + + return priTargetTemp; } /*********************************************************************//** * @brief + * The getTrimmerHeaterTargetTemperature function calculates the trimmer + * heater target temperature and returns target temperature value. + * @details Inputs: heatingConstsCalRecord + * @details Outputs: heatersTempCalc + * @return primary heater target temperature + *************************************************************************/ +F32 getTrimmerHeaterTargetTemperature( void ) +{ + F32 tempRsrvrActual = 0.0; + F32 fillROAvgActual = getAvgFillTemperature(); + F32 targetFillVolML = getTargetFillVolumeML(); + F32 UFTauCPerMS = heatingConstsCalRecord.ultrafilterTempTauCPerMin / ( SEC_PER_MIN * MS_PER_SECOND ); + F32 tempLastFill = getLastFillTemperature(); + F32 tempUFFill = tempLastFill + ( heatersTempCalc.timeUFDecayMS * UFTauCPerMS ); + F32 rsrvrTauCPerMS = heatingConstsCalRecord.reservoirTempTauCPerMin / ( SEC_PER_MIN * MS_PER_SECOND ); + F32 targetROFlowLPM = getTargetROPumpFlowRateLPM(); + F32 tgtAicdFlowLPM = getConcentratePumpTargetFlowMLPM( CONCENTRATEPUMPS_CP1_ACID ) / ML_PER_LITER; + F32 tgtBicarbFlowLPM = getConcentratePumpTargetFlowMLPM( CONCENTRATEPUMPS_CP2_BICARB ) / ML_PER_LITER; + F32 tgtTotalFlowLPM = targetROFlowLPM + tgtAicdFlowLPM + tgtBicarbFlowLPM; + + if ( tgtTotalFlowLPM > 0 ) + { + heatersTempCalc.tempFillMixAvgTrimmer = ( fillROAvgActual * ( tgtTotalFlowLPM / targetROFlowLPM ) ) - + ( ENVIRONMENT_TEMPERATURE_C * ( tgtAicdFlowLPM / targetROFlowLPM ) ) - + ( ENVIRONMENT_TEMPERATURE_C * ( tgtBicarbFlowLPM / targetROFlowLPM ) ); + + heatersTempCalc.tempRsrvr0ActualTrimmer = ( ( heatingConstsCalRecord.ultrafilterVolmL / targetFillVolML ) * tempUFFill ) + + ( ( ( targetFillVolML - heatingConstsCalRecord.ultrafilterVolmL ) / targetFillVolML ) * + heatersTempCalc.tempFillMixAvgTrimmer ); + + heatersTempCalc.tempRsrvrEndFillTrimmer = heatersTempCalc.tempRsrvr0ActualTrimmer + ( ( heatersTempCalc.timeReservoirFillMS * 0.5 ) * rsrvrTauCPerMS ); + + tempRsrvrActual = heatersTempCalc.tempRsrvrEndFillTrimmer + ( ( heatersTempCalc.timeReservoirFillMS * 0.5 ) * rsrvrTauCPerMS ); + } + + return tempRsrvrActual; +} + +/*********************************************************************//** + * @brief * The getReservoirsCalRecord function returns the reservoirs' calibration * record. * @details Inputs: reservoirsCalRecord