Index: firmware/App/Controllers/Heaters.c =================================================================== diff -u -r52d1378ccddcede0445ddb8a08fc1f70b9007b50 -r54e58f64179ea382d2e2c403c8c3b9a15a612636 --- firmware/App/Controllers/Heaters.c (.../Heaters.c) (revision 52d1378ccddcede0445ddb8a08fc1f70b9007b50) +++ firmware/App/Controllers/Heaters.c (.../Heaters.c) (revision 54e58f64179ea382d2e2c403c8c3b9a15a612636) @@ -42,13 +42,7 @@ // ********** private definitions ********** #define HEATERS_MAX_DUTY_CYCLE 1.00 ///< Main primary heater (heater A) max duty cycle (100%). -#define SMALL_PRIMAY_HEATER_MAX_DUTY_CYCLE 1.00 // TODO remove ///< Small Primary heater (heater B) max duty cycle (100%). -#define TRIMMER_HEATER_MAX_DUTY_CYCLE 1.00 // TODO remove ///< Trimmer heater max duty cycle (100%). #define HEATERS_MIN_DUTY_CYCLE 0.00 ///< Primary and trimmer heaters minimum duty cycle (0.00%). -#define PRIMARY_HEATERS_CUMULATIVE_DUTY_CYCLE ( HEATERS_MAX_DUTY_CYCLE + \ - SMALL_PRIMAY_HEATER_MAX_DUTY_CYCLE ) //TODO remove ///< Primary heaters cumulative duty cycle. -#define PRIMARY_HEATER_INITIAL_DUTY_CYCLE_ESTIMATE_DIVISOR 2.0 // TODO remove ///< Primary heaters initial duty cycle estimation divisor. -#define MAIN_AND_SMALL_PRIMARY_HEATER_DUTY_CYCLE_DIVISOR 2.0 // TODO remove ///< Main and small primary heater duty cycle divisor #define PRIMARY_HEATER_P_COEFFICIENT 0.05 ///< Primary heaters proportional coefficient. #define PRIMARY_HEATER_I_COEFFICIENT 0.00 // TODO remove? ///< Primary heaters integral coefficient. @@ -77,7 +71,6 @@ #define PRIMARY_HEATERS_THERMAL_POWER_TO_VOLTAGE_SLOPE 0.31644 ///< Primary heaters thermal power to voltage slope. #define PRIMARY_HEATERS_THERMAL_POWER_TO_VOLTAGE_INTERCEPT 0.021 ///< Primary heaters thermal power to voltage intercept. -/**************************************************** New defines ***********************/ typedef enum Heaters_Exec_States { HEATER_EXEC_STATE_NOT_RUNNING = 0, ///< Heater exec state not running @@ -129,76 +122,11 @@ static void setMainPrimaryHeaterPWM( F32 pwm ); static void setSmallPrimaryHeaterPWM( F32 pwm ); static void setTrimmerHeaterPWM( F32 pwm ); -static U32 getPublishHeatersDataInterval( void ); static void publishHeatersData( void ); static void checkPrimaryHeaterTempSensors( void ); static void checkTrimmerHeaterTempSensors( void ); static void monitorHeatersVoltage( void ); -/**************************************************** New defines ***********************/ - -/// Primary heaters exec states TODO remove -typedef enum primary_heaters_exec_states -{ - PRIMARY_HEATERS_EXEC_STATE_OFF = 0, ///< Primary heaters exec state off - PRIMARY_HEATERS_EXEC_STATE_CONTROL_TO_TARGET, ///< Primary heaters exec state control to target (PI controller state) - NUM_OF_PRIMARY_HEATERS_EXEC_STATES ///< Number of primary heaters exec states -} PRIMARY_HEATERS_EXEC_STATES_T; - -/// Trimmer heater exec states TODO remove -typedef enum trimmer_heater_exec_states -{ - TRIMMER_HEATER_EXEC_STATE_OFF = 0, ///< Trimmer heater exec state off - TRIMMER_HEATER_EXEC_STATE_CONTROL_TO_TARGET, ///< Trimmer heater exec state control to target (PI controller state) - NUM_OF_TRIMMER_HEATER_EXEC_STATES ///< Number of trimmer heater exec states -} TRIMMER_HEATER_EXEC_STATES_T; - -/// Name of the heaters states TODO remove -typedef enum name_of_heaters -{ - PRIMARY_HEATER = 0, ///< Primary heater - TRIMMER_HEATER, ///< Trimmer heater - NUM_OF_HEATERS ///< Number of heaters -} NAME_OF_HEATER_T; - -// ********** private data ********** - -static PRIMARY_HEATERS_EXEC_STATES_T primaryHeatersExecState; ///< Primary heaters exec state. TODO remove -static TRIMMER_HEATER_EXEC_STATES_T trimmerHeaterExecState; ///< Trimmer heater exec state. TODO remove - -static F32 primaryHeaterTargetTemperature; ///< Primary heaters target temperature. TODO remove -static F32 trimmerHeaterTargetTemperature; ///< Trimmer heater target temperature. TODO remove - -static F32 mainPrimaryHeaterDutyCycle; ///< Main primary heater duty cycle. TODO remove -static F32 smallPrimaryHeaterDutyCycle; ///< Small primary heater duty cycle. TODO remove -static F32 trimmerHeaterDutyCycle; ///< Trimmer heater duty cycle. TODO remove -static U32 primaryHeaterTimerCounter; ///< Primary heater timer counter. TODO remove -static U32 trimmerHeaterTimerCounter; ///< Trimmer heater timer counter. TODO remove - -static BOOL isPrimaryHeaterOn; ///< Flag to show if the primary heater is on. TODO remove -static BOOL isTrimmerHeaterOn; ///< Flag to show if the trimmer heater is on. TODO remove - -static BOOL hasStartPrimaryHeaterRequested; ///< Start primary heater request flag. TODO remove -static BOOL hasStartTrimmerHeaterRequested; ///< Start trimmer heater request flag. TODO remove - -static TEMPERATURE_SENSORS_T primaryHeatersFeedbackTempSensor = TEMPSENSORS_OUTLET_PRIMARY_HEATER; ///< Primary heaters feedback temperature sensors. TODO remove -static TEMPERATURE_SENSORS_T trimmerHeaterFeedbackTempSensor = TEMPSENSORS_INLET_DIALYSATE; ///< Trimmer heater feedback temperature sensors. TODO remove - -static U32 primaryHeaterTempOutTimer = 0; ///< Primary heaters temperature out of range start timer. TODO remove -static U32 trimmerHeaterTempOutTimer = 0; ///< Trimmer heater internal temperature out of range timer. TODO remove -static BOOL isPrimaryHeaterTempOutOfRange = FALSE; ///< Boolean flag to indicate if the primary heaters internal temperature out of range. TODO remove -static BOOL isTrimmerHeaterTempOutOfRange = FALSE; ///< Boolean flag to indicate if the trimmer heater internal temperature out of range. TODO remove - -// ********** private function prototypes ********** - -static PRIMARY_HEATERS_EXEC_STATES_T handlePrimaryHeaterStateOff( void ); // TODO remove -static PRIMARY_HEATERS_EXEC_STATES_T handlePrimaryHeaterStateControlToTarget( void ); // TODO remove - -static TRIMMER_HEATER_EXEC_STATES_T handleTrimmerHeaterStateOff( void ); // TODO remove -static TRIMMER_HEATER_EXEC_STATES_T handleTrimmerHeaterControlToTarget( void ); // TODO remove - -static void resetHeaterState( NAME_OF_HEATER_T heater ); // TODO remove - /*********************************************************************//** * @brief * The initHeaters initializes the heaters driver. @@ -240,7 +168,7 @@ // Initialize the PI controller for the trimmer heater initializePIController( PI_CONTROLLER_ID_TRIMMER_HEATER, HEATERS_MIN_DUTY_CYCLE, TRIMMER_HEATER_P_COEFFICIENT, TRIMMER_HEATER_I_COEFFICIENT, - HEATERS_MIN_DUTY_CYCLE, TRIMMER_HEATER_MAX_DUTY_CYCLE ); + HEATERS_MIN_DUTY_CYCLE, HEATERS_MAX_DUTY_CYCLE ); } /*********************************************************************//** @@ -271,12 +199,24 @@ /*********************************************************************//** * @brief - * The startHeater function starts the specified heater. + * The getHeaterTargetTemperature function returns the heater target temperature. * @details Inputs: none * @details Outputs: heaterStatus - * @param heater: heater ID that is requested to turn on - * @return TRUE if the start was accepted otherwise, FALSE + * @return heater target temperature *************************************************************************/ +F32 getHeaterTargetTemperature( DG_HEATERS_T heater ) +{ + return heaterStatus[ heater ].targetTemp; +} + +/*********************************************************************//** + * @brief + * The startPrimaryHeater function starts the primary heaters. It resets + * the primary heaters state and sets the main primary heater duty cycle. + * @details Inputs: primaryHeaterTargetTemperature + * @details Outputs: hasStartPrimaryHeaterRequested + * @return status + *************************************************************************/ BOOL startHeater( DG_HEATERS_T heater ) { BOOL status = FALSE; @@ -375,8 +315,8 @@ { cmdResponse.rejected = FALSE; #ifndef DISABLE_HEATERS_AND_TEMPS - trimmerHeaterTargetTemperature = heaterCmdPtr->targetTemp; - hasStartTrimmerHeaterRequested = TRUE; + heaterStatus[ DG_TRIMMER_HEATER ].targetTemp = heaterCmdPtr->targetTemp; + heaterStatus[ DG_TRIMMER_HEATER ].startHeaterSignal = TRUE; #endif } else @@ -387,7 +327,7 @@ else { cmdResponse.rejected = FALSE; - stopTrimmerHeater(); + stopHeater( DG_TRIMMER_HEATER ); } sendCommandResponseMsg( &cmdResponse ); @@ -580,6 +520,10 @@ isItHandOffTime = TRUE; } } + else if ( feedbackTemperature > targetTemperature ) + { + isItHandOffTime = TRUE; + } if ( TRUE == isItHandOffTime ) { @@ -618,12 +562,13 @@ HEATERS_STATE_T state = HEATER_EXEC_STATE_CONTROL_TO_TARGET; F32 targetFlow = getTargetROPumpFlowRate(); - BOOL hasFlowChanged = fabs( targetFlow - heaterStatus[ heater ].targetROFlow ) > NEARLY_ZERO; + BOOL hasFlowChanged = ( fabs( targetFlow - heaterStatus[ heater ].targetROFlow ) > NEARLY_ZERO ? TRUE : FALSE ); if ( TRUE == hasFlowChanged ) { // Moving back from control to target to ramp. heaterStatus[ heater ].rampStateStartTime = getMSTimerCount(); + heaterStatus[ heater ].targetROFlow = targetFlow; // Go back to ramp state with 100% duty cycle setHeaterDutyCycle( heater, HEATERS_MAX_DUTY_CYCLE ); @@ -648,9 +593,8 @@ dutyCycle = heaterStatus[ heater ].initialDutyCycle + 0.09; } - // TODO remove - //dutyCycle = ( deltaDutyCycle < 0.0 ? ( fabs( deltaDutyCycle ) < 0.05 ? dutyCycle : heaterStatus[ heater ].initialDutyCycle - 0.05 ) : - // ( deltaDutyCycle < 0.05 ? dutyCycle : heaterStatus[ heater ].initialDutyCycle + 0.05 ) ); + dutyCycle = ( dutyCycle > HEATERS_MAX_DUTY_CYCLE ? HEATERS_MAX_DUTY_CYCLE : dutyCycle ); + dutyCycle = ( dutyCycle < HEATERS_MIN_DUTY_CYCLE ? HEATERS_MIN_DUTY_CYCLE : dutyCycle ); setHeaterDutyCycle( heater, dutyCycle ); @@ -756,25 +700,6 @@ /*********************************************************************//** * @brief - * The getPublishHeatersDataInterval function gets the publish interval. - * @details Inputs: heatersDataPublishInterval - * @details Outputs: none - * @return result - *************************************************************************/ -U32 getPublishHeatersDataInterval( void ) -{ - U32 result = heatersDataPublishInterval.data; - - if ( OVERRIDE_KEY == heatersDataPublishInterval.override ) - { - result = heatersDataPublishInterval.ovData; - } - - return result; -} - -/*********************************************************************//** - * @brief * The publishTemperatureData function publishes the heaters data into * at the defined time interval. * @details Inputs: dataPublicationTimerCounter @@ -783,7 +708,7 @@ *************************************************************************/ static void publishHeatersData( void ) { - if ( ++dataPublicationTimerCounter >= getPublishHeatersDataInterval() ) + if ( ++dataPublicationTimerCounter >= getU32OverrideValue( &heatersDataPublishInterval ) ) { HEATERS_DATA_T data; @@ -797,9 +722,9 @@ data.primaryHeaterState = heaterStatus[ DG_PRIMARY_HEATER ].state; data.trimmerHeaterState = heaterStatus[ DG_TRIMMER_HEATER ].state; - broadcastHeatersData( &data ); + //broadcastHeatersData( &data ); - //broadcastData( MSG_ID_DG_HEATERS_DATA, COMM_BUFFER_OUT_CAN_DG_BROADCAST, (U08*)&data, sizeof( HEATERS_DATA_T ) ); + broadcastData( MSG_ID_DG_HEATERS_DATA, COMM_BUFFER_OUT_CAN_DG_BROADCAST, (U08*)&data, sizeof( HEATERS_DATA_T ) ); dataPublicationTimerCounter = 0; } @@ -831,8 +756,8 @@ SET_ALARM_WITH_1_U32_DATA( ALARM_ID_DG_PRIMARY_HEATER_CJ_TEMP_OUT_OF_RANGE, primaryHeaterInternalTemp ); } - // If any of the temperatures are above the range - if ( ( FALSE == isPrimaryHeaterTempOutOfRange ) && ( TRUE == isTempOut ) ) + /*/ If any of the temperatures are above the range + /if ( ( FALSE == isPrimaryHeaterTempOutOfRange ) && ( TRUE == isTempOut ) ) { stopPrimaryHeater(); isPrimaryHeaterTempOutOfRange = TRUE; @@ -844,7 +769,7 @@ { isPrimaryHeaterTempOutOfRange = FALSE; activateSafetyShutdown(); - } + }*/ } /*********************************************************************//** @@ -875,7 +800,7 @@ // If it is above the range for the first time, stop the trimmer heater // and set the variables - if ( ( FALSE == isTrimmerHeaterTempOutOfRange ) && ( TRUE == isTempOut ) ) + /*if ( ( FALSE == isTrimmerHeaterTempOutOfRange ) && ( TRUE == isTempOut ) ) { stopTrimmerHeater(); isTrimmerHeaterTempOutOfRange = TRUE; @@ -886,7 +811,7 @@ ( TRUE == didTimeout( trimmerHeaterTempOutTimer, HEATERS_MAX_ALLOWED_INTERNAL_TEMPERATURE_TIMEOUT_MS ) ) ) { activateSafetyShutdown(); - } + }*/ } /*********************************************************************//** @@ -908,9 +833,9 @@ F32 trimmerVoltage = getIntADCVoltageConverted( INT_ADC_TRIMMER_HEATER_24_VOLTS ); // Voltage to PWM is reverse. If PWM = 0 -> V = 24V - F32 mainPri = 1.0 - mainPrimaryHeaterDutyCycle; - F32 smallPri = 1.0 - smallPrimaryHeaterDutyCycle; - F32 trimmer = 1.0 - trimmerHeaterDutyCycle; + F32 mainPri = 1.0 - heaterStatus[ DG_PRIMARY_HEATER ].dutycycle; + F32 smallPri = 1.0 - heaterStatus[ DG_PRIMARY_HEATER ].dutycycle; + F32 trimmer = 1.0 - heaterStatus[ DG_TRIMMER_HEATER ].dutycycle; // Check main primary heater's voltage // The corresponding voltage of the current PWM must be close to the sensed voltage @@ -934,377 +859,6 @@ } -// TODO remove the below functions - - - - -/*********************************************************************//** - * @brief - * The setPrimaryHeaterTargetTemperature function sets the primary heater - * target temperature. - * @details Inputs: none - * @details Outputs: primaryHeaterTargetTemperature - * @param targetTemp target temperature for the primary heater - * @return none - *************************************************************************/ -void setPrimaryHeaterTargetTemperature( F32 targetTemp ) -{ - primaryHeaterTargetTemperature = targetTemp; -} - -/*********************************************************************//** - * @brief - * The setTrimmerHeaterTargetTemperature function sets the trimmer heater - * target temperature. - * @details Inputs: none - * @details Outputs: trimmerHeaterTargetTemperature - * @param targetTemp target temperature for the trimmer heater - * @return none - *************************************************************************/ -void setTrimmerHeaterTargetTemperature( F32 targetTemp ) -{ - trimmerHeaterTargetTemperature = targetTemp; -} - -/*********************************************************************//** - * @brief - * The startPrimaryHeater function starts the primary heaters. It resets - * the primary heaters state and sets the main primary heater duty cycle. - * @details Inputs: primaryHeaterTargetTemperature - * @details Outputs: hasStartPrimaryHeaterRequested - * @return status - *************************************************************************/ -BOOL startPrimaryHeater( void ) -{ - BOOL status = FALSE; - - if ( ( primaryHeaterTargetTemperature >= MINIMUM_TARGET_TEMPERATURE ) && ( primaryHeaterTargetTemperature <= MAXIMUM_TARGET_TEMPERATURE ) ) - { - hasStartPrimaryHeaterRequested = TRUE; - status = TRUE; - } - - return status; -} - -/*********************************************************************//** - * @brief - * The startTrimmerHeater function starts the trimmer heater. It resets the - * trimmer heater's state and sets the duty cycle of the trimmer heater. - * @details Inputs: trimmerHeaterTargetTemperature - * @details Outputs: hasStartTrimmerHeaterRequested - * @return status - *************************************************************************/ -BOOL startTrimmerHeater( void ) -{ - BOOL status = FALSE; - - if ( ( trimmerHeaterTargetTemperature >= MINIMUM_TARGET_TEMPERATURE ) && ( trimmerHeaterTargetTemperature <= MAXIMUM_TARGET_TEMPERATURE ) ) - { - hasStartTrimmerHeaterRequested = TRUE; - status = TRUE; - } - - return status; -} - -/*********************************************************************//** - * @brief - * The stopPrimaryHeater function stops the primary heater. - * @details Inputs: none - * @details Outputs: Primary heater stops - * @return none - *************************************************************************/ -void stopPrimaryHeater( void ) -{ - setMainPrimaryHeaterPWM( HEATERS_MIN_DUTY_CYCLE ); - setSmallPrimaryHeaterPWM( HEATERS_MIN_DUTY_CYCLE ); - isPrimaryHeaterOn = FALSE; -} - -/*********************************************************************//** - * @brief - * The stopTrimmerHeater function stops the trimmer heater. - * @details Inputs: none - * @details Outputs: Trimmer heater stops - * @return none - *************************************************************************/ -void stopTrimmerHeater( void ) -{ - setTrimmerHeaterPWM( HEATERS_MIN_DUTY_CYCLE ); - isTrimmerHeaterOn = FALSE; -} - - - -/*********************************************************************//** - * @brief - * The execPrimaryHeaters function executes the primary heaters' state machine. - * @details Inputs: primaryHeatersExecState - * @details Outputs: primaryHeatersExecState - * @return none - *************************************************************************/ -void execPrimaryHeaters( void ) -{ - switch ( primaryHeatersExecState ) - { - case PRIMARY_HEATERS_EXEC_STATE_OFF: - primaryHeatersExecState = handlePrimaryHeaterStateOff(); - break; - - case PRIMARY_HEATERS_EXEC_STATE_CONTROL_TO_TARGET: - primaryHeatersExecState = handlePrimaryHeaterStateControlToTarget(); - break; - - default: - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_HEATERS_INVALID_EXEC_STATE, primaryHeatersExecState ); - primaryHeatersExecState = PRIMARY_HEATERS_EXEC_STATE_CONTROL_TO_TARGET; - break; - } -} - -/*********************************************************************//** - * @brief - * The execTrimmerHeater function executes the trimmer heater's state machine. - * @details Inputs: trimmerHeaterExecState - * @details Outputs: trimmerHeaterExecState - * @return none - *************************************************************************/ -void execTrimmerHeater( void ) -{ - switch ( trimmerHeaterExecState ) - { - case TRIMMER_HEATER_EXEC_STATE_OFF: - trimmerHeaterExecState = handleTrimmerHeaterStateOff(); - break; - - case TRIMMER_HEATER_EXEC_STATE_CONTROL_TO_TARGET: - trimmerHeaterExecState = handleTrimmerHeaterControlToTarget(); - break; - - default: - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_HEATERS_INVALID_EXEC_STATE, trimmerHeaterExecState ); - trimmerHeaterExecState = TRIMMER_HEATER_EXEC_STATE_CONTROL_TO_TARGET; - break; - } -} - -/*********************************************************************//** - * @brief - * The handlePrimaryHeaterStateOff function handles the primary heaters at - * off state. - * @details Inputs: hasStartPrimaryHeaterRequested, isPrimaryHeaterOn - * @details Outputs: state (PRIMARY_HEATERS_EXEC_STATES_T), isPrimaryHeaterOn - * @return state (PRIMARY_HEATERS_EXEC_STATES_T) - *************************************************************************/ -static PRIMARY_HEATERS_EXEC_STATES_T handlePrimaryHeaterStateOff( void ) -{ - PRIMARY_HEATERS_EXEC_STATES_T state = PRIMARY_HEATERS_EXEC_STATE_OFF; - - if ( TRUE == hasStartPrimaryHeaterRequested ) - { - resetHeaterState( PRIMARY_HEATER ); - // Once the primary heaters duty cycle is set, it is divided into 2 - // so both heaters will start and both elements are heated up - setMainPrimaryHeaterPWM( mainPrimaryHeaterDutyCycle ); - setSmallPrimaryHeaterPWM( smallPrimaryHeaterDutyCycle ); - isPrimaryHeaterOn = TRUE; - hasStartPrimaryHeaterRequested = FALSE; - - // Check if the operation mode is heat disinfect. If the mode is - // heat disinfect, the feedback sensor will be Thd - if ( DG_MODE_HEAT == getCurrentOperationMode() ) - { -#ifdef THD_USING_TRO_CONNECTOR - // Set the feedback temperature sensor - // THd uses TRo in V3 - primaryHeatersFeedbackTempSensor = TEMPSENSORS_OUTLET_REDUNDANT; -#else - primaryHeatersFeedbackTempSensor = TEMPSENSORS_HEAT_DISINFECT; -#endif - } - - state = PRIMARY_HEATERS_EXEC_STATE_CONTROL_TO_TARGET; - } - - return state; -} - -/*********************************************************************//** - * @brief - * The handlePrimaryHeaterStateControlToTarget function handles the primary - * heaters at control state when the heaters are active. - * @details Inputs: primaryHeaterTimerCounter, mainPrimaryHeaterDutyCycle, - * smallPrimaryHeaterDutyCycle, isPrimaryHeaterOn - * @details Outputs: primaryHeaterTimerCounter, mainPrimaryHeaterDutyCycle, - * smallPrimaryHeaterDutyCycle - * @return state (PRIMARY_HEATERS_EXEC_STATES_T) - *************************************************************************/ -static PRIMARY_HEATERS_EXEC_STATES_T handlePrimaryHeaterStateControlToTarget( void ) -{ - PRIMARY_HEATERS_EXEC_STATES_T state = PRIMARY_HEATERS_EXEC_STATE_CONTROL_TO_TARGET; - - if ( ++primaryHeaterTimerCounter >= HEATERS_RAMP_STATE_CHECK_INTERVAL_COUNT ) - { - // Check if the flow is not below minimum required first - // If the flow is below minimum, send 0.00 to the PWM until the flow comes back to range - // If the flow is within range, run the PI controller to control the heaters normally - if ( FALSE == isFlowBelowMin ) - { - // If the primary heater is running and another start primary heater request - // is set, reset the primary heater again - if ( TRUE == hasStartPrimaryHeaterRequested ) - { - resetHeaterState( PRIMARY_HEATER ); - hasStartPrimaryHeaterRequested = FALSE; - } - else - { - F32 outletTemp = getTemperatureValue( primaryHeatersFeedbackTempSensor ); - mainPrimaryHeaterDutyCycle = runPIController( PI_CONTROLLER_ID_PRIMARY_HEATER, primaryHeaterTargetTemperature, outletTemp ); - - // Once the primary heaters duty cycle is set, it is divided into 2 so both heaters will start and both elements are heated up - smallPrimaryHeaterDutyCycle = mainPrimaryHeaterDutyCycle; // MAIN_AND_SMALL_PRIMARY_HEATER_DUTY_CYCLE_DIVISOR; - mainPrimaryHeaterDutyCycle = mainPrimaryHeaterDutyCycle; // MAIN_AND_SMALL_PRIMARY_HEATER_DUTY_CYCLE_DIVISOR; - } - - setMainPrimaryHeaterPWM( mainPrimaryHeaterDutyCycle ); - setSmallPrimaryHeaterPWM( smallPrimaryHeaterDutyCycle ); - } - // Flow is below the minimum required flow to run the primary heaters - else - { - setMainPrimaryHeaterPWM( HEATERS_MIN_DUTY_CYCLE ); - setSmallPrimaryHeaterPWM( HEATERS_MIN_DUTY_CYCLE ); - } - - primaryHeaterTimerCounter = 0; - } - - if ( FALSE == isPrimaryHeaterOn ) - { - // Switch to off state. Set the duty cycles to 0 - mainPrimaryHeaterDutyCycle = HEATERS_MIN_DUTY_CYCLE; - smallPrimaryHeaterDutyCycle = HEATERS_MIN_DUTY_CYCLE; - state = PRIMARY_HEATERS_EXEC_STATE_OFF; - } - - return state; -} - -/*********************************************************************//** - * @brief - * The handleTrimmerHeaterStateOff function handles the trimmer heater at - * off state. - * @details Inputs: hasStartTrimmerHeaterRequested, isTrimmerHeaterOn - * @details Outputs: state (TRIMMER_HEATER_EXEC_STATES_T), isTrimmerHeaterOn - * @return state (TRIMMER_HEATER_EXEC_STATES_T) - *************************************************************************/ -static TRIMMER_HEATER_EXEC_STATES_T handleTrimmerHeaterStateOff( void ) -{ - TRIMMER_HEATER_EXEC_STATES_T state = TRIMMER_HEATER_EXEC_STATE_OFF; - - if ( TRUE == hasStartTrimmerHeaterRequested ) - { - resetHeaterState( TRIMMER_HEATER ); - isTrimmerHeaterOn = TRUE; - hasStartTrimmerHeaterRequested = FALSE; - setTrimmerHeaterPWM( trimmerHeaterDutyCycle ); - state = TRIMMER_HEATER_EXEC_STATE_CONTROL_TO_TARGET; - } - - return state; -} - -/*********************************************************************//** - * @brief - * The handleTrimmerHeaterControlToTarget function handles the trimmer - * heater at control state when the heater is active. - * @details Inputs: trimmerHeaterTimerCounter, trimmerHeaterDutyCycle - * @details Outputs: trimmerHeaterTimerCounter, trimmerHeaterDutyCycle, - * isTrimmerHeaterOn - * @return state (TRIMMER_HEATER_EXEC_STATES_T) - *************************************************************************/ -static TRIMMER_HEATER_EXEC_STATES_T handleTrimmerHeaterControlToTarget( void ) -{ - TRIMMER_HEATER_EXEC_STATES_T state = TRIMMER_HEATER_EXEC_STATE_CONTROL_TO_TARGET; - - if ( ++trimmerHeaterTimerCounter >= HEATERS_RAMP_STATE_CHECK_INTERVAL_COUNT ) - { - // Check if the flow is not below minimum required first - // If the flow is below minimum, send 0.00 to the PWM until the flow comes back to range - // If the flow is within range, run the PI controller to control the heaters normally - if ( FALSE == isFlowBelowMin ) - { - F32 outletTemp = getTemperatureValue( trimmerHeaterFeedbackTempSensor ); - trimmerHeaterDutyCycle = runPIController( PI_CONTROLLER_ID_TRIMMER_HEATER, trimmerHeaterTargetTemperature, outletTemp ); - setTrimmerHeaterPWM( trimmerHeaterDutyCycle ); - } - else - { - setTrimmerHeaterPWM( HEATERS_MIN_DUTY_CYCLE ); - } - - trimmerHeaterTimerCounter = 0; - } - - if ( FALSE == isTrimmerHeaterOn ) - { - // Set the duty cycle to 0 and switch to off state - trimmerHeaterDutyCycle = HEATERS_MIN_DUTY_CYCLE; - state = TRIMMER_HEATER_EXEC_STATE_OFF; - } - - return state; -} - -/*********************************************************************//** - * @brief - * The resetHeaterState function resets the PI controller of the selected heater. - * @details Inputs: mainPrimaryHeaterDutyCycle, trimmerHeaterDutyCycle - * @details Outputs: mainPrimaryHeaterDutyCycle, trimmerHeaterDutyCycle - * @param heater enumeration of the heater for which the PI controller will be reset - * @return none - *************************************************************************/ -static void resetHeaterState( NAME_OF_HEATER_T heater ) -{ - if ( PRIMARY_HEATER == heater ) - { - // Calculate the delta temperature from the inlet primary heater to target temperature - F32 inletPrimaryHeaterTemp = getTemperatureValue( TEMPSENSORS_INLET_PRIMARY_HEATER ); - F32 deltaTemp = primaryHeaterTargetTemperature - inletPrimaryHeaterTemp; - - // If the delta temperature (target temperature - inlet primary heater temperature) - // Is 0 or negative, the duty cycle is 0.0 - if ( deltaTemp <= 0.0 ) - { - mainPrimaryHeaterDutyCycle = HEATERS_MIN_DUTY_CYCLE; - smallPrimaryHeaterDutyCycle = HEATERS_MIN_DUTY_CYCLE; - } - else - { - // The formula for the initial guess is: (delta temperature * target flow) / 2.0 - F32 targetFlow = getTargetROPumpFlowRate(); - F32 duty = ( targetFlow * deltaTemp ) / PRIMARY_HEATER_INITIAL_DUTY_CYCLE_ESTIMATE_DIVISOR; - // If the duty cycle is greater 200% on the primary and small primary heaters, set it to 200%, otherwise set it to the - // estimated duty cycles - duty = ( duty > PRIMARY_HEATERS_CUMULATIVE_DUTY_CYCLE ? PRIMARY_HEATERS_CUMULATIVE_DUTY_CYCLE : duty ); - mainPrimaryHeaterDutyCycle = duty / MAIN_AND_SMALL_PRIMARY_HEATER_DUTY_CYCLE_DIVISOR; - smallPrimaryHeaterDutyCycle = duty / MAIN_AND_SMALL_PRIMARY_HEATER_DUTY_CYCLE_DIVISOR; - } - - // The PI controller of the primary heater consists of main and small primary heaters duty cycles - resetPIController( PI_CONTROLLER_ID_PRIMARY_HEATER, mainPrimaryHeaterDutyCycle + smallPrimaryHeaterDutyCycle ); - } - else if ( TRIMMER_HEATER == heater ) - { - trimmerHeaterDutyCycle = TRIMMER_HEATER_MAX_DUTY_CYCLE; - resetPIController( PI_CONTROLLER_ID_TRIMMER_HEATER, TRIMMER_HEATER_MAX_DUTY_CYCLE ); - } -} - - /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/