Index: firmware/App/Controllers/Heaters.c =================================================================== diff -u -r353d01d31bc69d4d1901ff09097ee610bb1c9dbc -ra3960210792d0811093a6913e505d43eda1918ea --- firmware/App/Controllers/Heaters.c (.../Heaters.c) (revision 353d01d31bc69d4d1901ff09097ee610bb1c9dbc) +++ firmware/App/Controllers/Heaters.c (.../Heaters.c) (revision a3960210792d0811093a6913e505d43eda1918ea) @@ -27,7 +27,7 @@ #include "MessageSupport.h" #include "ModeFill.h" #include "OperationModes.h" -#include "PIControllers.h" +#include "Reservoirs.h" #include "ROPump.h" #include "SafetyShutdown.h" #include "SystemCommMessages.h" @@ -120,6 +120,7 @@ static void setHeaterDutyCycle( DG_HEATERS_T heater, F32 pwm ); static F32 calculatePrimaryHeaterDutyCycle( F32 targetTemperature, F32 currentTemperature, F32 flow, BOOL checkEfficiency ); +static F32 calculateTrimmerHeaterDutyCycle( F32 targetTemperature, F32 currentTemperature, F32 flow, BOOL checkEfficiency ); static BOOL haveHeaterControlConditionsChanged( DG_HEATERS_T heater ); static void setMainPrimaryHeaterPWM( F32 pwm ); @@ -567,8 +568,40 @@ *************************************************************************/ static HEATERS_STATE_T handleHeaterStateTrimmerRampToTarget( void ) { - HEATERS_STATE_T state = HEATER_EXEC_STATE_TRIMMER_RAMP_TO_TARGET; + HEATERS_STATE_T state = HEATER_EXEC_STATE_TRIMMER_RAMP_TO_TARGET; + DG_HEATERS_T heater = DG_TRIMMER_HEATER; + F32 currentTemperature = 0.0; + F32 targetFlow = 0.35; // TODO get target dialysate flow from HD + F32 dutyCycle = 0.0; + F32 targetTemperature = heatersStatus[ heater ].targetTemp; + if ( DG_MODE_FILL == getCurrentOperationMode() ) + { + currentTemperature = getReservoirActualTemperature(); + dutyCycle = calculatePrimaryHeaterDutyCycle( targetTemperature, currentTemperature, targetFlow, TRUE ); + state = HEATER_EXEC_STATE_TRIMMER_CONTROL_TO_TARGET; + } + /*else if ( ( DG_MODE_GENE == getCurrentOperationMode() ) || ( DG_MODE_DRAI == getCurrentOperationMode() ) ) + { + targetTemperature += DELTA_TEMPERATURE_TIME_COSNTANT_C; + // Use target flow rate during Idle and drain + targetFlow = getTargetROPumpFlowRate(); + dutyCycle = calculatePrimaryHeaterDutyCycle( targetTemperature, inletTemperature, targetFlow, FALSE ); + state = HEATER_EXEC_STATE_PRIMARY_CONTROL_TO_TARGET; + }*/ // TODO do we need this else if for the trimmer heater + else if ( DG_MODE_HEAT == getCurrentOperationMode() ) + { + // If the mode is heat disinfect, use the target flow rate instead of the avg. flow + // Most of the times the heater should be running at 100% duty cycle since the target temperature is 81 C and + // it is far from the inlet temperature. + currentTemperature = getTemperatureValue( (U32)TEMPSENSORS_HEAT_DISINFECT ); + targetFlow = getTargetROPumpFlowRate(); + dutyCycle = calculatePrimaryHeaterDutyCycle( targetTemperature, currentTemperature, targetFlow, FALSE ); + state = HEATER_EXEC_STATE_CONTROL_TO_DISINFECT_TARGET; + } + + setHeaterDutyCycle( heater, dutyCycle ); + return state; } @@ -583,8 +616,14 @@ static HEATERS_STATE_T handleHeaterStateTrimmerControlToTarget( void ) { HEATERS_STATE_T state = HEATER_EXEC_STATE_TRIMMER_CONTROL_TO_TARGET; + DG_HEATERS_T heater = DG_TRIMMER_HEATER; + //if ( TRUE == haveHeaterControlConditionsChanged( heater ) ) // TODO do we need this kind of check from trimmer?? + { + //state = HEATER_EXEC_STATE_TRIMMER_RAMP_TO_TARGET; + } + return state; } @@ -660,6 +699,26 @@ return dutyCycle; } +static F32 calculateTrimmerHeaterDutyCycle( F32 targetTemperature, F32 currentTemperature, F32 flow, BOOL checkEfficiency ) +{ + // Get the primary heater's efficiency and the last fill temperature from the ModeFill + F32 heaterEfficiency = heatersStatus[ DG_TRIMMER_HEATER ].heaterEfficiency; + + + if ( TRUE == checkEfficiency ) + { + // TODO add the trimmer efficiency + } + + F32 dutyCycle = flow * WATER_SPECIFIC_HEAT_DIVIDED_BY_MINUTES * ( targetTemperature - currentTemperature ) * heaterEfficiency; + + // Check the boundaries of the calculated duty cycle + dutyCycle = ( dutyCycle > HEATERS_MAX_DUTY_CYCLE ? HEATERS_MAX_DUTY_CYCLE : dutyCycle ); + dutyCycle = ( dutyCycle < HEATERS_MIN_DUTY_CYCLE ? HEATERS_MIN_DUTY_CYCLE : dutyCycle ); + + return dutyCycle; +} + /*********************************************************************//** * @brief * The haveHeaterControlConditionsChanged function checks whether the heater