Index: firmware/App/Controllers/Heaters.c =================================================================== diff -u -r4468dcb6d88bb364c60412ac368d1420adb66b27 -r3d9542c3bc8df7950b8374a6d91c2b3412de1dd9 --- firmware/App/Controllers/Heaters.c (.../Heaters.c) (revision 4468dcb6d88bb364c60412ac368d1420adb66b27) +++ firmware/App/Controllers/Heaters.c (.../Heaters.c) (revision 3d9542c3bc8df7950b8374a6d91c2b3412de1dd9) @@ -93,7 +93,7 @@ HEATERS_STATE_T state; ///< Heater state. BOOL startHeaterSignal; ///< Heater start indication flag. BOOL isHeaterOn; ///< Heater on/off status flag. - F32 dutycycle; ///< Heater duty cycle. + F32 dutyCycle; ///< Heater duty cycle. F32 targetFlow; ///< Heater target flow. BOOL hasTargetTempChanged; ///< Heater target temperature change flag indicator. F32 heaterEstGain; ///< Heater estimation gain during the run. @@ -148,7 +148,7 @@ heatersStatus[ heater ].state = HEATER_EXEC_STATE_OFF; heatersStatus[ heater ].startHeaterSignal = FALSE; heatersStatus[ heater ].isHeaterOn = FALSE; - heatersStatus[ heater ].dutycycle = 0.0; + heatersStatus[ heater ].dutyCycle = 0.0; heatersStatus[ heater ].targetFlow = 0.0; heatersStatus[ heater ].hasTargetTempChanged = FALSE; heatersStatus[ heater ].heaterEstGain = HEATERS_NEUTRAL_EST_GAIN; @@ -407,7 +407,7 @@ #endif { F32 heaterEstGain = heatersStatus[ heater ].heaterEstGain; - F32 heaterDutyCycle = heatersStatus[ heater ].dutycycle; + F32 heaterDutyCycle = heatersStatus[ heater ].dutyCycle; F32 lastFillTemperature = getAvgFillTemperature(); F32 primaryTargetTemperature = heatersStatus[ heater ].targetTemp; BOOL isTempUnderTarget = ( lastFillTemperature < primaryTargetTemperature ? TRUE : FALSE ); @@ -553,7 +553,7 @@ state = HEATER_EXEC_STATE_PRIMARY_RAMP_TO_TARGET; } - // If the heat disifect sensor indicates that the temperature is below target temperature but the target temperature had been reached + // If the heat disinfect sensor indicates that the temperature is below target temperature but the target temperature had been reached // before turn on the heaters with 100% power if ( ( heatDisinfectSensorTemp <= heatersStatus[ heater ].targetTemp ) && ( TRUE == heatersStatus[ heater ].hasTargetBeenReached ) ) { @@ -610,10 +610,15 @@ } // Update the calculated target temperature + // Reset the duty cycle since the reservoir has been switched heatersStatus[ heater ].calculatedTemperature = currentTemperature; heatersStatus[ heater ].inactiveRsrvr = getInactiveReservoir(); heatersStatus[ heater ].targetFlow = targetFlowLPM; + heatersStatus[ heater ].dutyCycle = 0.0F; trimmerHeaterControlCounter = 0; + + // Cap the minimum duty cycle. So if it is calculated to negative, set it to 0 + dutyCycle = MAX( dutyCycle, HEATERS_MIN_DUTY_CYCLE ); setHeaterDutyCycle( heater, dutyCycle ); return state; @@ -647,7 +652,7 @@ F32 dutyCycle = calculateTrimmerHeaterDutyCycle( targetTemperature, outletRedundantTemperature, targetFlowLPM, TRUE ); trimmerHeaterControlCounter = 0; - setHeaterDutyCycle( DG_TRIMMER_HEATER, ( heatersStatus[ DG_TRIMMER_HEATER ].dutycycle + dutyCycle ) ); + setHeaterDutyCycle( DG_TRIMMER_HEATER, ( heatersStatus[ DG_TRIMMER_HEATER ].dutyCycle + dutyCycle ) ); } return state; @@ -667,7 +672,7 @@ // Check if the requested duty cycle is different from what the heater's duty cycle is. // If the same duty cycle is requested, then it is not needed to send it again. This is to make sure // the same duty cycle is not sent to the hardware all the time. - if ( fabs( heatersStatus[ heater ].dutycycle - pwm ) > NEARLY_ZERO ) + if ( fabs( heatersStatus[ heater ].dutyCycle - pwm ) > NEARLY_ZERO ) { if ( DG_PRIMARY_HEATER == heater ) { @@ -680,7 +685,7 @@ } // Updated the heater's information - heatersStatus[ heater ].dutycycle = pwm; + heatersStatus[ heater ].dutyCycle = pwm; } } @@ -737,12 +742,9 @@ } // Duty cycle = ( 69.73 * flow rate * deltaT / primary heater maximum power ) and multiply the duty cycle to the heater efficiency - dutyCycle = ( ( flow * WATER_SPECIFIC_HEAT_DIVIDED_BY_MINUTES * - ( targetTemperature - currentTemperature ) ) / TRIMMER_HEATER_MAX_POWER_W ) * heaterEstGain; - - // Check the boundaries of the calculated duty cycle + dutyCycle = ( ( flow * WATER_SPECIFIC_HEAT_DIVIDED_BY_MINUTES * ( targetTemperature - currentTemperature ) ) / TRIMMER_HEATER_MAX_POWER_W ) * heaterEstGain; dutyCycle = MIN( dutyCycle, HEATERS_MAX_DUTY_CYCLE ); - dutyCycle = MAX( dutyCycle, HEATERS_MIN_DUTY_CYCLE ); + dutyCycle = MAX( dutyCycle, ( HEATERS_MAX_DUTY_CYCLE * -1.0F ) ); return dutyCycle; } @@ -827,11 +829,11 @@ { 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.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; @@ -867,9 +869,9 @@ F32 trimmerVoltage = getMonitoredLineLevel( MONITORED_LINE_24V_TRIM_HTR_V ); // Voltage to PWM is reverse. If PWM = 0 -> V = 24V - F32 mainPriDC = heatersStatus[ DG_PRIMARY_HEATER ].dutycycle; - F32 smallPriDC = heatersStatus[ DG_PRIMARY_HEATER ].dutycycle; - F32 trimmerDC = heatersStatus[ DG_TRIMMER_HEATER ].dutycycle; + F32 mainPriDC = heatersStatus[ DG_PRIMARY_HEATER ].dutyCycle; + F32 smallPriDC = heatersStatus[ DG_PRIMARY_HEATER ].dutyCycle; + F32 trimmerDC = heatersStatus[ DG_TRIMMER_HEATER ].dutyCycle; F32 mainPriExpectedVoltage = HEATERS_MAX_OPERATING_VOLTAGE_V * ( 1.0 - mainPriDC ); F32 smallPriExpectedVoltage = HEATERS_MAX_OPERATING_VOLTAGE_V * ( 1.0 - smallPriDC );