Index: firmware/App/Controllers/Heaters.c =================================================================== diff -u -r19934ca6e36e2dcabd6a6083a9a1f15b1ed32189 -r0516c804fc8c41a097fda9ab8dac1527e1683d29 --- firmware/App/Controllers/Heaters.c (.../Heaters.c) (revision 19934ca6e36e2dcabd6a6083a9a1f15b1ed32189) +++ firmware/App/Controllers/Heaters.c (.../Heaters.c) (revision 0516c804fc8c41a097fda9ab8dac1527e1683d29) @@ -65,7 +65,8 @@ #define HEATERS_VOLTAGE_OUT_OF_RANGE_TIMEOUT_MS ( 2 * MS_PER_SECOND ) ///< Heaters voltage out of range time out in milliseconds. #define HEATERS_MAX_VOLTAGE_OUT_OF_RANGE_TOL 0.2F ///< Heaters max voltage out of range tolerance. #define TRIMMER_HEATER_MAX_POWER_W 66.5F ///< Trimmer heater maximum power in Watts. -#define HEATER_CONTROL_CHECK_INTERVAL_COUNT ( ( 30 * MS_PER_SECOND ) / TASK_GENERAL_INTERVAL ) ///< Heater control interval count. +#define TRIMMER_HEATER_INITIAL_CONTROL_INTERVAL_COUNT ( ( 10 * MS_PER_SECOND ) / TASK_GENERAL_INTERVAL ) ///< Trimmer heater initial control interval count. +#define TRIMMER_HEATER_CONTROL_INTERVAL_COUNT ( ( 30 * MS_PER_SECOND ) / TASK_GENERAL_INTERVAL ) ///< Trimmer heater control interval count. #define DELTA_TEMPERATURE_TIME_COSNTANT_C 8.6F ///< Delta temperature calculated from time constant. #define PRIMARY_HEATER_DUTY_CYCLE_PER_TEMPERATURE_C 0.015F ///< Primary heaters duty cycle per temperature in C. @@ -93,11 +94,12 @@ BOOL hasTargetBeenReached; ///< Heater flag to indicate whether the target temperature has been reached. F32 calculatedTemperature; ///< Heater calculated temperature. DG_RESERVOIR_ID_T inactiveRsrvr; ///< Heater inactive reservoir. + U32 controlIntervalCounter; ///< Heater control interval counter. + BOOL isThisFirstControl; ///< Heater is this first control interval. } HEATER_STATUS_T; static HEATER_STATUS_T heatersStatus[ NUM_OF_DG_HEATERS ]; ///< Heaters status. static U32 dataPublicationTimerCounter; ///< Data publication timer counter. -static U32 heaterControlCounter; ///< Heater control counter. static OVERRIDE_U32_T heatersDataPublishInterval = { HEATERS_DATA_PUBLISH_INTERVAL, HEATERS_DATA_PUBLISH_INTERVAL, 0, 0 }; ///< Heaters data publish time interval. // ********** private function prototypes ********** @@ -125,27 +127,27 @@ * The initHeaters initializes the heaters driver. * @details Inputs: none * @details Outputs: voltageMonitorTimeCounter, heaterStatus, - * hasTreatmentInternalTempBeenSet, dataPublicationTimerCounter, - * trimmerHeaterControlCounter + * hasTreatmentInternalTempBeenSet, dataPublicationTimerCounter * @return none *************************************************************************/ void initHeaters( void ) { DG_HEATERS_T heater; dataPublicationTimerCounter = DATA_PUBLISH_COUNTER_START_COUNT; - heaterControlCounter = 0; for ( heater = DG_PRIMARY_HEATER; heater < NUM_OF_DG_HEATERS; heater++ ) { - heatersStatus[ heater ].targetTemp = 0.0F; - heatersStatus[ heater ].state = HEATER_EXEC_STATE_OFF; - heatersStatus[ heater ].startHeaterSignal = FALSE; - heatersStatus[ heater ].isHeaterOn = FALSE; - heatersStatus[ heater ].dutyCycle = 0.0F; - heatersStatus[ heater ].targetFlow = 0.0F; - heatersStatus[ heater ].hasTargetTempChanged = FALSE; - heatersStatus[ heater ].heaterEstGain = HEATERS_NEUTRAL_EST_GAIN; - heatersStatus[ heater ].hasTargetBeenReached = FALSE; + heatersStatus[ heater ].targetTemp = 0.0F; + heatersStatus[ heater ].state = HEATER_EXEC_STATE_OFF; + heatersStatus[ heater ].startHeaterSignal = FALSE; + heatersStatus[ heater ].isHeaterOn = FALSE; + heatersStatus[ heater ].dutyCycle = 0.0F; + heatersStatus[ heater ].targetFlow = 0.0F; + heatersStatus[ heater ].hasTargetTempChanged = FALSE; + heatersStatus[ heater ].heaterEstGain = HEATERS_NEUTRAL_EST_GAIN; + heatersStatus[ heater ].hasTargetBeenReached = FALSE; + heatersStatus[ heater ].controlIntervalCounter = 0; + heatersStatus[ heater ].isThisFirstControl = TRUE; } // Initialize the persistent alarms @@ -534,7 +536,20 @@ { state = HEATER_EXEC_STATE_PRIMARY_RAMP_TO_TARGET; } + else if ( TRUE == heatersStatus[ heater ].hasTargetTempChanged ) + { + F32 inletTemperature = getTemperatureValue( (U32)TEMPSENSORS_HEAT_DISINFECT ); + F32 targetTemperature = heatersStatus[ heater ].targetTemp; + F32 targetFlow = getTargetROPumpFlowRateLPM(); + F32 dutyCycle = calculatePrimaryHeaterDutyCycle( targetTemperature, inletTemperature, targetFlow, TRUE ); + heatersStatus[ heater ].calculatedTemperature = targetTemperature; + heatersStatus[ heater ].targetFlow = targetFlow; + heatersStatus[ heater ].hasTargetTempChanged = FALSE; + + setHeaterDutyCycle( heater, dutyCycle ); + } + return state; } @@ -620,7 +635,7 @@ heatersStatus[ heater ].calculatedTemperature = currentTemperature; heatersStatus[ heater ].inactiveRsrvr = getInactiveReservoir(); heatersStatus[ heater ].targetFlow = targetFlowLPM; - heaterControlCounter = 0; + heatersStatus[ heater ].isThisFirstControl = TRUE; // Cap the minimum duty cycle. So if it is calculated to negative, set it to 0 dutyCycle = MAX( dutyCycle, HEATERS_MIN_DUTY_CYCLE ); @@ -641,28 +656,34 @@ { HEATERS_STATE_T state = HEATER_EXEC_STATE_TRIMMER_CONTROL_TO_TARGET; F32 tempDutyCycle = 0.0F; + DG_HEATERS_T heater = DG_TRIMMER_HEATER; + U32 controlInterval = ( TRUE == heatersStatus[ heater ].isThisFirstControl ? TRIMMER_HEATER_INITIAL_CONTROL_INTERVAL_COUNT : + TRIMMER_HEATER_CONTROL_INTERVAL_COUNT ); // If the inactive reservoir has changed from the last run transition to ramp state to recalculate the // duty cycle for the next delivery - if ( heatersStatus[ DG_TRIMMER_HEATER ].inactiveRsrvr != getInactiveReservoir() ) + if ( heatersStatus[ heater ].inactiveRsrvr != getInactiveReservoir() ) { state = HEATER_EXEC_STATE_TRIMMER_RAMP_TO_TARGET; } - else if ( ++heaterControlCounter > HEATER_CONTROL_CHECK_INTERVAL_COUNT ) + else if ( ++heatersStatus[ heater ].controlIntervalCounter > controlInterval ) { + // Reset the control counter + heatersStatus[ heater ].controlIntervalCounter = 0; + heatersStatus[ heater ].isThisFirstControl = FALSE; + // When the trimmer heater is on, its duty cycle is adjusted at the control interval. For this control check, // dialysate inlet temperature sensor is used rather than the theoretical calculations. F32 outletRedundantTemperature = getTemperatureValue( TEMPSENSORS_OUTLET_REDUNDANT ); - F32 targetTemperature = heatersStatus[ DG_TRIMMER_HEATER ].targetTemp; - F32 targetFlowLPM = heatersStatus[ DG_TRIMMER_HEATER ].targetFlow; + F32 targetTemperature = heatersStatus[ heater ].targetTemp; + F32 targetFlowLPM = heatersStatus[ heater ].targetFlow; F32 dutyCycle = calculateTrimmerHeaterDutyCycle( targetTemperature, outletRedundantTemperature, targetFlowLPM, TRUE ); - heaterControlCounter = 0; - tempDutyCycle = heatersStatus[ DG_TRIMMER_HEATER ].dutyCycle + dutyCycle; + tempDutyCycle = heatersStatus[ heater ].dutyCycle + dutyCycle; tempDutyCycle = MIN( tempDutyCycle, HEATERS_MAX_DUTY_CYCLE ); tempDutyCycle = MAX( tempDutyCycle, HEATERS_MIN_DUTY_CYCLE ); - setHeaterDutyCycle( DG_TRIMMER_HEATER, tempDutyCycle ); + setHeaterDutyCycle( heater, tempDutyCycle ); } return state; @@ -776,11 +797,10 @@ 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 ) ) + if ( TRUE == hasFlowChanged ) { - status = TRUE; - heatersStatus[ heater ].targetFlow = targetFlow; - heatersStatus[ heater ].hasTargetTempChanged = FALSE; + status = TRUE; + heatersStatus[ heater ].targetFlow = targetFlow; } return status;