Index: firmware/App/Controllers/Heaters.c =================================================================== diff -u -r669f36cf32c3b500aa2fd5b08c58ee5e6b2e7f08 -re8c019d3d43b517cabfdfe75fa5d03749d036018 --- firmware/App/Controllers/Heaters.c (.../Heaters.c) (revision 669f36cf32c3b500aa2fd5b08c58ee5e6b2e7f08) +++ firmware/App/Controllers/Heaters.c (.../Heaters.c) (revision e8c019d3d43b517cabfdfe75fa5d03749d036018) @@ -72,7 +72,7 @@ #define PRIMARY_HEATER_DUTY_CYCLE_PER_TEMPERATURE_C 0.03F ///< Primary heaters duty cycle per temperature in C. #define DATA_PUBLISH_COUNTER_START_COUNT 70 ///< Data publish counter start count. -static const F32 WATER_SPECIFIC_HEAT_DIVIDED_BY_MINUTES = 4184 / SEC_PER_MIN; ///< Water specific heat in J/KgC / 60. +static const F32 WATER_SPECIFIC_HEAT_DIVIDED_BY_MINUTES = 4184 / SEC_PER_MIN; ///< Water specific heat in J/KgC / 60. static const F32 PRIMARY_HEATERS_MAXIMUM_POWER_WATTS = 475 + 237.5F; ///< Primary heaters maximum power (main primary = 475W and small primary = 237.5W). /// Heaters exec states @@ -95,12 +95,11 @@ BOOL startHeaterSignal; ///< Heater start indication flag. BOOL isHeaterOn; ///< Heater on/off status flag. F32 dutycycle; ///< Heater duty cycle. - F32 targetROFlow; ///< Heater target flow. + F32 targetFlow; ///< Heater target flow. BOOL hasTargetTempChanged; ///< Heater target temperature change flag indicator. F32 heaterEfficiency; ///< Heater efficiency during the run. BOOL hasTargetBeenReached; ///< Heater flag to indicate whether the target temperature has been reached. - - F32 temporaryInterimTemperature; ///< TODO remove + F32 calculatedTemperature; ///< Heater calculated temperature. } HEATER_STATUS_T; static HEATER_STATUS_T heatersStatus[ NUM_OF_DG_HEATERS ]; ///< Heaters status. @@ -147,7 +146,7 @@ heatersStatus[ heater ].startHeaterSignal = FALSE; heatersStatus[ heater ].isHeaterOn = FALSE; heatersStatus[ heater ].dutycycle = 0.0; - heatersStatus[ heater ].targetROFlow = 0.0; + heatersStatus[ heater ].targetFlow = 0.0; heatersStatus[ heater ].hasTargetTempChanged = FALSE; heatersStatus[ heater ].heaterEfficiency = 1.0; // Assuming 100% efficiency during initialization until it is updated heatersStatus[ heater ].hasTargetBeenReached = FALSE; @@ -229,7 +228,7 @@ { if ( TRUE == heatersStatus[ heater ].hasTargetTempChanged ) { - status = TRUE; + status = TRUE; heatersStatus[ heater ].startHeaterSignal = TRUE; } } @@ -315,52 +314,6 @@ /*********************************************************************//** * @brief - * The handleTrimmerHeaterCmd handles a start trimmer heater command from the HD. - * It resets the trimmer heater's state and sets the duty cycle of the trimmer heater. - * @details Inputs: none - * @details Outputs: process command and send back response - * @param heaterCmdPtr pointer to heater command data record - * @return status - *************************************************************************/ -void handleTrimmerHeaterCmd( TRIMMER_HEATER_CMD_T *heaterCmdPtr ) // TODo remove this function -{ - DG_CMD_RESPONSE_T cmdResponse; - cmdResponse.commandID = DG_CMD_START_TRIMMER_HEATER; - cmdResponse.rejected = TRUE; - cmdResponse.rejectCode = DG_CMD_REQUEST_REJECT_REASON_NONE; - - if ( TRUE == heaterCmdPtr->startHeater ) - { - F32 tempTrimmerTarget = getTrimmerHeaterTargetTemperature(); - - if ( ( tempTrimmerTarget >= MINIMUM_TARGET_TEMPERATURE ) && ( tempTrimmerTarget <= MAXIMUM_TARGET_TEMPERATURE ) ) - { - cmdResponse.rejected = FALSE; - heatersStatus[ DG_TRIMMER_HEATER ].targetTemp = tempTrimmerTarget; - -#ifndef _RELEASE_ - if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_TRIMMER_HEATER ) != SW_CONFIG_ENABLE_VALUE ) -#endif - { - heatersStatus[ DG_TRIMMER_HEATER ].startHeaterSignal = TRUE; - } - } - else - { - cmdResponse.rejectCode = DG_CMD_REQUEST_REJECT_REASON_INVALID_PARAMETER; - } - } - else - { - cmdResponse.rejected = FALSE; - stopHeater( DG_TRIMMER_HEATER ); - } - - sendCommandResponseMsg( &cmdResponse ); -} - -/*********************************************************************//** - * @brief * The execHeatersMonitor function monitors the status of the heaters. * The internal temperature sensors and the voltages of the heaters are * monitored. The flow is continuously checked and if there is no flow @@ -462,7 +415,7 @@ if ( DG_MODE_FILL == opMode ) { // If the previous average fill flow rate is 0, use the nominal target RO flow from the RO pump - targetFlow = ( getAvgFillFlowRate() - 0.0 > NEARLY_ZERO ? getAvgFillFlowRate() : getTargetROPumpFlowRateLPM() ); + targetFlow = ( getAvgFillFlowRateLPM() - 0.0 > NEARLY_ZERO ? getAvgFillFlowRateLPM() : getTargetROPumpFlowRateLPM() ); dutyCycle = calculatePrimaryHeaterDutyCycle( targetTemperature, inletTemperature, targetFlow, TRUE ); state = HEATER_EXEC_STATE_PRIMARY_CONTROL_TO_TARGET; } @@ -483,9 +436,8 @@ state = HEATER_EXEC_STATE_CONTROL_TO_DISINFECT_TARGET; } - // TODO remove once dialysate heating is done - heatersStatus[ DG_PRIMARY_HEATER ].temporaryInterimTemperature = targetTemperature; - // TODO remove + // Update the calculated target temperature + heatersStatus[ DG_PRIMARY_HEATER ].calculatedTemperature = targetTemperature; setHeaterDutyCycle( heater, dutyCycle ); @@ -569,15 +521,15 @@ HEATERS_STATE_T state = HEATER_EXEC_STATE_TRIMMER_RAMP_TO_TARGET; DG_HEATERS_T heater = DG_TRIMMER_HEATER; F32 currentTemperature = 0.0; - F32 targetFlow = getTargetDialysateFlowLPM(); + F32 targetFlowLPM = getTargetDialysateFlowLPM(); F32 dutyCycle = 0.0; F32 targetTemperature = heatersStatus[ heater ].targetTemp; DG_OP_MODE_T opMode = getCurrentOperationMode(); if ( ( DG_MODE_FILL == opMode ) || ( DG_MODE_GENE == opMode ) || ( DG_MODE_DRAI == opMode ) ) { currentTemperature = getTrimmerHeaterTargetTemperature(); - dutyCycle = calculateTrimmerHeaterDutyCycle( targetTemperature, currentTemperature, targetFlow, TRUE ); + dutyCycle = calculateTrimmerHeaterDutyCycle( targetTemperature, currentTemperature, targetFlowLPM, TRUE ); state = HEATER_EXEC_STATE_TRIMMER_CONTROL_TO_TARGET; } else if ( DG_MODE_HEAT == opMode ) @@ -586,11 +538,14 @@ // 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 = getTargetROPumpFlowRateLPM(); - dutyCycle = calculateTrimmerHeaterDutyCycle( targetTemperature, currentTemperature, targetFlow, FALSE ); + targetFlowLPM = getTargetROPumpFlowRateLPM(); + dutyCycle = calculateTrimmerHeaterDutyCycle( targetTemperature, currentTemperature, targetFlowLPM, FALSE ); state = HEATER_EXEC_STATE_CONTROL_TO_DISINFECT_TARGET; } + // Update the calculated target temperature + heatersStatus[ DG_TRIMMER_HEATER ].calculatedTemperature = currentTemperature; + setHeaterDutyCycle( heater, dutyCycle ); return state; @@ -734,7 +689,7 @@ // Check the boundaries of the calculated duty cycle dutyCycle = MIN( dutyCycle, HEATERS_MAX_DUTY_CYCLE ); - dutyCycle = MIN( dutyCycle, HEATERS_MIN_DUTY_CYCLE ); + dutyCycle = MAX( dutyCycle, HEATERS_MIN_DUTY_CYCLE ); return dutyCycle; } @@ -753,15 +708,13 @@ { BOOL status = FALSE; F32 targetFlow = ( DG_PRIMARY_HEATER == heater ? getTargetROPumpFlowRateLPM() : getTargetDialysateFlowLPM() ); - BOOL hasFlowChanged = ( fabs( targetFlow - heatersStatus[ heater ].targetROFlow ) > NEARLY_ZERO ? TRUE : FALSE ); + BOOL hasFlowChanged = ( fabs( targetFlow - heatersStatus[ heater ].targetFlow ) > NEARLY_ZERO ? TRUE : FALSE ); // Check if the target flow has changed or the target temperature has changed. if ( ( TRUE == hasFlowChanged ) || ( TRUE == heatersStatus[ heater ].hasTargetTempChanged ) ) { - status = TRUE; - - // Moving back from control to target to ramp. - heatersStatus[ heater ].targetROFlow = targetFlow; + status = TRUE; + heatersStatus[ heater ].targetFlow = targetFlow; heatersStatus[ heater ].hasTargetTempChanged = FALSE; } @@ -820,22 +773,19 @@ if ( ++dataPublicationTimerCounter >= getU32OverrideValue( &heatersDataPublishInterval ) ) { HEATERS_DATA_T data; - - data.mainPrimayHeaterDC = heatersStatus[ DG_PRIMARY_HEATER ].dutycycle * 100.0; + data.mainPrimayHeaterDC = heatersStatus[ DG_PRIMARY_HEATER ].dutycycle * 100.0; // The duty cycle of the primary heater is divided into 2 parts and is applied to main // and small primary heaters. So they are always the same. - data.smallPrimaryHeaterDC = heatersStatus[ DG_PRIMARY_HEATER ].dutycycle * 100.0; - data.trimmerHeaterDC = heatersStatus[ DG_TRIMMER_HEATER ].dutycycle * 100.0; - data.primaryTargetTemp = heatersStatus[ DG_PRIMARY_HEATER ].targetTemp; - data.trimmerTargetTemp = heatersStatus[ DG_TRIMMER_HEATER ].targetTemp; - data.primaryHeaterState = heatersStatus[ DG_PRIMARY_HEATER ].state; - data.trimmerHeaterState = heatersStatus[ DG_TRIMMER_HEATER ].state; - data.primaryEfficiency = heatersStatus[ DG_PRIMARY_HEATER ].heaterEfficiency * 100; + data.smallPrimaryHeaterDC = heatersStatus[ DG_PRIMARY_HEATER ].dutycycle * 100.0; + data.trimmerHeaterDC = heatersStatus[ DG_TRIMMER_HEATER ].dutycycle * 100.0; + data.primaryTargetTemp = heatersStatus[ DG_PRIMARY_HEATER ].targetTemp; + data.trimmerTargetTemp = heatersStatus[ DG_TRIMMER_HEATER ].targetTemp; + data.primaryHeaterState = heatersStatus[ DG_PRIMARY_HEATER ].state; + data.trimmerHeaterState = heatersStatus[ DG_TRIMMER_HEATER ].state; + data.primaryEfficiency = heatersStatus[ DG_PRIMARY_HEATER ].heaterEfficiency * 100; + data.primaryCalcTargetTemp = heatersStatus[ DG_PRIMARY_HEATER ].calculatedTemperature; + data.trimmerCalcCurrentTemp = heatersStatus[ DG_TRIMMER_HEATER ].calculatedTemperature; - data.dialysateTargetLPM = getTargetDialysateFlowLPM(); - data.interimTargetTemp = heatersStatus[ DG_PRIMARY_HEATER ].temporaryInterimTemperature; - data.targetHeaterFlowLPM = heatersStatus[ DG_PRIMARY_HEATER ].targetROFlow; - broadcastData( MSG_ID_DG_HEATERS_DATA, COMM_BUFFER_OUT_CAN_DG_BROADCAST, (U08*)&data, sizeof( HEATERS_DATA_T ) ); dataPublicationTimerCounter = 0;