Index: firmware/App/Controllers/Heaters.c =================================================================== diff -u -rab14e70c7bac24b0c3ebd02c6763285cdd3951ce -rbcb768dd6a13286e028533394916a9f69c9f254f --- firmware/App/Controllers/Heaters.c (.../Heaters.c) (revision ab14e70c7bac24b0c3ebd02c6763285cdd3951ce) +++ firmware/App/Controllers/Heaters.c (.../Heaters.c) (revision bcb768dd6a13286e028533394916a9f69c9f254f) @@ -59,7 +59,7 @@ #define HEATERS_MAX_ALLOWED_INTERNAL_TEMPERATURE_C 170.0F ///< Heaters max allowed internal temperature in C. #define HEATERS_MAX_ALLOWED_COLD_JUNCTION_TEMPERATURE_C 80.0F ///< Heaters max allowed cold junction temperature in C. #define HEATERS_MAX_ALLOWED_INTERNAL_TEMPERATURE_TIMEOUT_MS ( 2 * SEC_PER_MIN * MS_PER_SECOND ) ///< Heaters max allowed internal temperature timeout in milliseconds. -#define HEATERS_ON_NO_FLOW_TIMEOUT_MS ( 2 * MS_PER_SECOND ) ///< Heaters on with no flow time out in milliseconds. +#define HEATERS_ON_NO_FLOW_TIMEOUT_MS ( 1 * MS_PER_SECOND ) ///< Heaters on with no flow time out in milliseconds. #define HEATERS_MAX_OPERATING_VOLTAGE_V 24.0F ///< Heaters max operating voltage in volts. #define HEATERS_VOLTAGE_MONITOR_TIME_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< Heaters voltage monitor timer interval. #define HEATERS_MAX_VOLTAGE_OUT_OF_RANGE_TOL 0.2F ///< Heaters max voltage out of range tolerance. @@ -363,10 +363,8 @@ for ( heater = DG_PRIMARY_HEATER; heater < NUM_OF_DG_HEATERS; heater++ ) { - F32 maxDutyCycle = MAX( heatersStatus[ heater ].dutyCyleBeforeFlow, heatersStatus[ heater ].dutycycle ); - - // Check if a heater is on and whether is duty cycle is not zero - if ( ( TRUE == heatersStatus[ heater ].isHeaterOn ) && ( maxDutyCycle > NEARLY_ZERO ) ) + // Check if the heater is on and if it is, check the flow sensor's status + if ( TRUE == heatersStatus[ heater ].isHeaterOn ) { // TODO add the function that gets the flow of the new flow sensor for DG. For now it is assumed that trimmer heater flow sensor // is not 0 so the heater can run if needed @@ -380,29 +378,26 @@ // Check if the flow of the heater is below minimum for the first time if ( FALSE == heatersStatus[ heater ].isFlowBelowMin ) { + // Set the variables for the flow below minimum situation. + // Remember the current duty cycle of the heater heatersStatus[ heater ].isFlowBelowMin = TRUE; heatersStatus[ heater ].heaterOnWithNoFlowTimer = getMSTimerCount(); heatersStatus[ heater ].dutyCyleBeforeFlow = heatersStatus[ heater ].dutycycle; } else if ( TRUE == didTimeout( heatersStatus[ heater ].heaterOnWithNoFlowTimer, HEATERS_ON_NO_FLOW_TIMEOUT_MS ) ) { + // The flow is below minimum for a certain period of time so set the heater's duty cycle to 0. The heaters is not + // set to off and its duty cycle is set to 0 setHeaterDutyCycle( heater, HEATERS_MIN_DUTY_CYCLE ); - - /*ALARM_ID_T alarm = ( DG_PRIMARY_HEATER == heater ? ALARM_ID_DG_PRIMARY_HEATER_ON_WITH_NO_FLOW_TIMEOUT : - ALARM_ID_DG_TRIMMER_HEATER_ON_WITH_NO_FLOW_TIMEOUT ); - activateAlarmNoData( alarm ); TODO DEBUG_DENALI*/ } } else { - if ( TRUE == heatersStatus[ heater ].isFlowBelowMin ) - { - setHeaterDutyCycle( heater, heatersStatus[ heater ].dutyCyleBeforeFlow ); - } - heatersStatus[ heater ].isFlowBelowMin = FALSE; heatersStatus[ heater ].heaterOnWithNoFlowTimer = getMSTimerCount(); + // Flow is back on, set the heater to the duty cycle that was saved before zeroing the heater + setHeaterDutyCycle( heater, heatersStatus[ heater ].dutyCyleBeforeFlow ); } } } @@ -643,17 +638,37 @@ *************************************************************************/ static void setHeaterDutyCycle( DG_HEATERS_T heater, F32 pwm ) { - if ( DG_PRIMARY_HEATER == heater ) + // Only if there is a minimum flow, or if 0 duty cycle has been requested, the duty cycle can be changed + // This is to make sure while heaters are temporarily turned off due to a flow drop are not set to another + // duty cycle that might cause an over heat since there is no water flowing through + if ( ( FALSE == heatersStatus[ heater ].isFlowBelowMin ) || ( pwm < NEARLY_ZERO ) ) { - setMainPrimaryHeaterPWM( pwm ); - setSmallPrimaryHeaterPWM( pwm ); + // 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 ( DG_PRIMARY_HEATER == heater ) + { + setMainPrimaryHeaterPWM( pwm ); + setSmallPrimaryHeaterPWM( pwm ); + } + else if ( DG_TRIMMER_HEATER == heater ) + { + setTrimmerHeaterPWM( pwm ); + } + + // Updated the heater's information + heatersStatus[ heater ].dutycycle = pwm; + } } - else if ( DG_TRIMMER_HEATER == heater ) + else { - setTrimmerHeaterPWM( pwm ); + // The flow is below minimum and the heater is temporarily powered down + // Update the other duty cycle with the requested duty cycle so as soon as the + // flow is back on, the new duty cycle is set + heatersStatus[ heater ].dutyCyleBeforeFlow = pwm; } - - heatersStatus[ heater ].dutycycle = pwm; } /*********************************************************************//** @@ -861,6 +876,7 @@ { if ( ++voltageMonitorTimeCounter >= HEATERS_VOLTAGE_MONITOR_TIME_INTERVAL ) { + // TODO the voltages are disabled for now until they are implemented into the persistent alarms. F32 mainPriVoltage = getIntADCVoltageConverted( INT_ADC_PRIMARY_HEATER_24_VOLTS ); // TODO it is assumed that the main and small primary heaters have equal voltage since the PWMs are divided into 2 // before applying the PWMs to the heaters. Right now, there is no ADC channel available for the small primary @@ -877,17 +893,17 @@ // The corresponding voltage of the current PWM must be close to the sensed voltage if ( fabs( ( HEATERS_MAX_OPERATING_VOLTAGE_V * mainPri ) - mainPriVoltage ) > HEATERS_MAX_VOLTAGE_OUT_OF_RANGE_TOL * mainPriVoltage ) { - SET_ALARM_WITH_1_F32_DATA( ALARM_ID_DG_MAIN_PRIMARY_HEATER_VOLTAGE_OUT_OF_RANGE, mainPriVoltage ); + //SET_ALARM_WITH_1_F32_DATA( ALARM_ID_DG_MAIN_PRIMARY_HEATER_VOLTAGE_OUT_OF_RANGE, mainPriVoltage ); } // Check small primary heater's voltage if ( fabs( ( HEATERS_MAX_OPERATING_VOLTAGE_V * smallPri ) - smallPriVoltage ) > HEATERS_MAX_VOLTAGE_OUT_OF_RANGE_TOL * smallPriVoltage ) { - SET_ALARM_WITH_1_F32_DATA( ALARM_ID_DG_SMALL_PRIMARY_HEATER_VOLTAGE_OUT_OF_RANGE, smallPriVoltage ); + //SET_ALARM_WITH_1_F32_DATA( ALARM_ID_DG_SMALL_PRIMARY_HEATER_VOLTAGE_OUT_OF_RANGE, smallPriVoltage ); } // Check trimmer heater's voltage if ( fabs( ( HEATERS_MAX_OPERATING_VOLTAGE_V * trimmer ) - trimmerVoltage ) > HEATERS_MAX_VOLTAGE_OUT_OF_RANGE_TOL * trimmerVoltage ) { - //SET_ALARM_WITH_1_F32_DATA( ALARM_ID_DG_TRIMMER_HEATER_VOLTAGE_OUT_OF_RANGE, trimmerVoltage ); // TODO DEBUG_DENALI + //SET_ALARM_WITH_1_F32_DATA( ALARM_ID_DG_TRIMMER_HEATER_VOLTAGE_OUT_OF_RANGE, trimmerVoltage ); } voltageMonitorTimeCounter = 0; @@ -916,7 +932,7 @@ { U32 interval = value / TASK_PRIORITY_INTERVAL; - result = TRUE; + result = TRUE; heatersDataPublishInterval.ovData = interval; heatersDataPublishInterval.override = OVERRIDE_KEY; } @@ -938,7 +954,7 @@ if ( TRUE == isTestingActivated() ) { - result = TRUE; + result = TRUE; heatersDataPublishInterval.override = OVERRIDE_RESET; heatersDataPublishInterval.ovData = heatersDataPublishInterval.ovInitData; }