Index: firmware/App/Controllers/Heaters.c =================================================================== diff -u -rbdbc27dc5dc85c84f71ea1bbb4e465317a6d11de -rd5f2ac4d84453feb1b782f35f9d69432977a95f6 --- firmware/App/Controllers/Heaters.c (.../Heaters.c) (revision bdbc27dc5dc85c84f71ea1bbb4e465317a6d11de) +++ firmware/App/Controllers/Heaters.c (.../Heaters.c) (revision d5f2ac4d84453feb1b782f35f9d69432977a95f6) @@ -7,8 +7,8 @@ * * @file Heaters.c * -* @author (last) Dara Navaei -* @date (last) 23-May-2022 +* @author (last) Michael Garthwaite +* @date (last) 07-Sep-2022 * * @author (original) Dara Navaei * @date (original) 23-Apr-2020 @@ -22,8 +22,8 @@ #include "AlarmMgmt.h" #include "DGDefs.h" +#include "FlowSensors.h" #include "Heaters.h" -#include "InternalADC.h" #include "MessageSupport.h" #include "ModeFill.h" #include "NVDataMgmt.h" @@ -37,6 +37,7 @@ #include "TaskPriority.h" #include "TemperatureSensors.h" #include "Timers.h" +#include "Voltages.h" /** * @addtogroup Heaters @@ -48,49 +49,42 @@ #define HEATERS_MAX_DUTY_CYCLE 1.00F ///< Heaters max duty cycle (100%). #define HEATERS_MIN_DUTY_CYCLE 0.00F ///< Heaters minimum duty cycle (0.00%). #define HEATERS_MIN_HEAT_DISINFECT_DUTY_CYCLE 0.6F ///< Heaters minimum duty cycle during heat disinfect. +#define HEATERS_MIN_EST_GAIN 0.2F ///< Heaters minimum estimation gain. +#define HEATERS_MAX_EST_GAIN 5.0F ///< Heaters maximum estimation gain. +#define HEATERS_NEUTRAL_EST_GAIN 1.0F ///< Heaters neutral estimation gain. #define HEATERS_DATA_PUBLISH_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< Heaters data publish interval. #define MINIMUM_TARGET_TEMPERATURE 10.0F ///< Minimum allowed target temperature for the heaters. #define MAXIMUM_TARGET_TEMPERATURE 90.0F ///< Maximum allowed target temperature for the heaters. -#define HEATERS_ON_NO_FLOW_TIMEOUT_MS ( 1 * MS_PER_SECOND ) ///< Heaters on with no flow time out in milliseconds. +#define HEATERS_ON_NO_FLOW_TIMEOUT_MS ( 10 * 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_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 TRIMMER_HEATER_CONTROL_CHECK_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.03F ///< Primary heaters duty cycle per temperature in C. +#define PRIMARY_HEATER_DUTY_CYCLE_PER_TEMPERATURE_C 0.015F ///< Primary heaters duty cycle per temperature in C. #define DATA_PUBLISH_COUNTER_START_COUNT 70 ///< Data publish counter start count. +#define MIN_RO_HEATER_FLOWRATE_LPM 0.2F ///< Minimum target RO heater flow rate in L/min. 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). +static const F32 HEATERS_VOLTAGE_TOLERANCE_V = HEATERS_MAX_OPERATING_VOLTAGE_V * HEATERS_MAX_VOLTAGE_OUT_OF_RANGE_TOL; ///< Heaters voltage tolerance in volts. -/// Heaters exec states -typedef enum Heaters_Exec_States -{ - HEATER_EXEC_STATE_OFF = 0, ///< Heater exec state off. - HEATER_EXEC_STATE_PRIMARY_RAMP_TO_TARGET, ///< Heater exec state primary ramp to target. - HEATER_EXEC_STATE_PRIMARY_CONTROL_TO_TARGET, ///< Heater exec state primary control to target. - HEATER_EXEC_STATE_CONTROL_TO_DISINFECT_TARGET, ///< Heater exec state control to disinfect (heat or chemical) target. - HEATER_EXEC_STATE_TRIMMER_RAMP_TO_TARGET, ///< Heater exec state trimmer ramp to target. - HEATER_EXEC_STATE_TRIMMER_CONTROL_TO_TARGET, ///< Heater exec state trimmer control to target. - NUM_OF_HEATERS_STATE, ///< Number of heaters state. -} HEATERS_STATE_T; - /// Heaters data structure typedef struct { F32 targetTemp; ///< Heater target temperature. 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 heaterEfficiency; ///< Heater efficiency during the run. + F32 heaterEstGain; ///< Heater estimation gain during the run. 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. @@ -138,28 +132,23 @@ for ( heater = DG_PRIMARY_HEATER; heater < NUM_OF_DG_HEATERS; heater++ ) { - heatersStatus[ heater ].targetTemp = 0.0; + heatersStatus[ heater ].targetTemp = 0.0F; heatersStatus[ heater ].state = HEATER_EXEC_STATE_OFF; heatersStatus[ heater ].startHeaterSignal = FALSE; heatersStatus[ heater ].isHeaterOn = FALSE; - heatersStatus[ heater ].dutycycle = 0.0; - heatersStatus[ heater ].targetFlow = 0.0; + heatersStatus[ heater ].dutyCycle = 0.0F; + heatersStatus[ heater ].targetFlow = 0.0F; heatersStatus[ heater ].hasTargetTempChanged = FALSE; - heatersStatus[ heater ].heaterEfficiency = 1.0; // Assuming 100% efficiency during initialization until it is updated + heatersStatus[ heater ].heaterEstGain = HEATERS_NEUTRAL_EST_GAIN; heatersStatus[ heater ].hasTargetBeenReached = FALSE; } // Initialize the persistent alarms - initPersistentAlarm( ALARM_ID_DG_MAIN_PRIMARY_HEATER_VOLTAGE_OUT_OF_RANGE, HEATERS_VOLTAGE_OUT_OF_RANGE_TIMEOUT_MS, - HEATERS_VOLTAGE_OUT_OF_RANGE_TIMEOUT_MS ); - - initPersistentAlarm( ALARM_ID_DG_SMALL_PRIMARY_HEATER_VOLTAGE_OUT_OF_RANGE, HEATERS_VOLTAGE_OUT_OF_RANGE_TIMEOUT_MS, - HEATERS_VOLTAGE_OUT_OF_RANGE_TIMEOUT_MS ); - - initPersistentAlarm( ALARM_ID_DG_TRIMMER_HEATER_VOLTAGE_OUT_OF_RANGE, HEATERS_VOLTAGE_OUT_OF_RANGE_TIMEOUT_MS, - HEATERS_VOLTAGE_OUT_OF_RANGE_TIMEOUT_MS ); - - initPersistentAlarm( ALARM_ID_DG_FLOW_TOO_LOW_WHILE_HEATER_ON, HEATERS_ON_NO_FLOW_TIMEOUT_MS, HEATERS_ON_NO_FLOW_TIMEOUT_MS ); + initPersistentAlarm( ALARM_ID_DG_MAIN_PRIMARY_HEATER_VOLTAGE_OUT_OF_RANGE, HEATERS_VOLTAGE_OUT_OF_RANGE_TIMEOUT_MS, HEATERS_VOLTAGE_OUT_OF_RANGE_TIMEOUT_MS ); + initPersistentAlarm( ALARM_ID_DG_SMALL_PRIMARY_HEATER_VOLTAGE_OUT_OF_RANGE, HEATERS_VOLTAGE_OUT_OF_RANGE_TIMEOUT_MS, HEATERS_VOLTAGE_OUT_OF_RANGE_TIMEOUT_MS ); + initPersistentAlarm( ALARM_ID_DG_TRIMMER_HEATER_VOLTAGE_OUT_OF_RANGE, HEATERS_VOLTAGE_OUT_OF_RANGE_TIMEOUT_MS, HEATERS_VOLTAGE_OUT_OF_RANGE_TIMEOUT_MS ); + initPersistentAlarm( ALARM_ID_RO_FLOW_TOO_LOW_WHILE_PRIMARY_HEATER_IS_ON, HEATERS_ON_NO_FLOW_TIMEOUT_MS, HEATERS_ON_NO_FLOW_TIMEOUT_MS ); + initPersistentAlarm( ALARM_ID_DIALYSATE_FLOW_TOO_LOW_WHILE_TRIMMER_HEATER_IS_ON, HEATERS_ON_NO_FLOW_TIMEOUT_MS, HEATERS_ON_NO_FLOW_TIMEOUT_MS ); } /*********************************************************************//** @@ -223,7 +212,7 @@ if( heater < NUM_OF_DG_HEATERS ) { - if ( TRUE == heatersStatus[ heater ].hasTargetTempChanged ) + if ( HEATER_EXEC_STATE_OFF == heatersStatus[ heater ].state ) { status = TRUE; heatersStatus[ heater ].startHeaterSignal = TRUE; @@ -328,17 +317,32 @@ // 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 - F32 measFlow = ( DG_PRIMARY_HEATER == heater ? getMeasuredROFlowRateLPM() : 50.0 ); - F32 minFlow = ( DG_PRIMARY_HEATER == heater ? MIN_RO_FLOWRATE_LPM : MIN_RO_FLOWRATE_LPM ); - BOOL isFlowLow = ( measFlow < minFlow ? TRUE : FALSE ); + ALARM_ID_T alarm; + F32 measFlow; + F32 minFlow; + BOOL isFlowLow; - checkPersistentAlarm( ALARM_ID_DG_FLOW_TOO_LOW_WHILE_HEATER_ON, isFlowLow, measFlow, minFlow ); + if ( DG_PRIMARY_HEATER == heater ) + { + alarm = ALARM_ID_RO_FLOW_TOO_LOW_WHILE_PRIMARY_HEATER_IS_ON; + measFlow = getMeasuredFlowRateLPM( RO_FLOW_SENSOR ); + minFlow = MIN_RO_FLOWRATE_LPM; + } + else + { + alarm = ALARM_ID_DIALYSATE_FLOW_TOO_LOW_WHILE_TRIMMER_HEATER_IS_ON; + measFlow = getMeasuredFlowRateLPM( DIALYSATE_FLOW_SENSOR ); + minFlow = MIN_DIALYSATE_FLOWRATE_LPM; + } + + isFlowLow = ( measFlow < minFlow ? TRUE : FALSE ); + + checkPersistentAlarm( alarm, isFlowLow, measFlow, minFlow ); } else { - checkPersistentAlarm( ALARM_ID_DG_FLOW_TOO_LOW_WHILE_HEATER_ON, FALSE, 0.0, 0.0 ); + checkPersistentAlarm( ALARM_ID_RO_FLOW_TOO_LOW_WHILE_PRIMARY_HEATER_IS_ON, FALSE, 0.0, 0.0 ); + checkPersistentAlarm( ALARM_ID_DIALYSATE_FLOW_TOO_LOW_WHILE_TRIMMER_HEATER_IS_ON, FALSE, 0.0, 0.0 ); } } @@ -355,20 +359,61 @@ /*********************************************************************//** * @brief - * The resetHeatersEfficiency function resets the heaters efficiency upon + * The resetHeatersEstimationGain function resets the heaters estimation gain upon * the start of a treatment. * @details Inputs: none * @details Outputs: heaterStatus * @return none *************************************************************************/ -void resetHeatersEfficiency( void ) +void resetHeatersEstimationGain( void ) { - heatersStatus[ DG_PRIMARY_HEATER ].heaterEfficiency = 1.0; - heatersStatus[ DG_TRIMMER_HEATER ].heaterEfficiency = 1.0; + heatersStatus[ DG_PRIMARY_HEATER ].heaterEstGain = HEATERS_NEUTRAL_EST_GAIN; + heatersStatus[ DG_TRIMMER_HEATER ].heaterEstGain = HEATERS_NEUTRAL_EST_GAIN; } /*********************************************************************//** * @brief + * The calculateHeaterEstimationGain function calculates the heater estimation + * gain. + * @details Inputs: none + * @details Outputs: heatersStatus + * @return none + *************************************************************************/ +void calculateHeaterEstimationGain( DG_HEATERS_T heater ) +{ +#ifndef _RELEASE_ + if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_HEATERS_EFFICIENCY ) != SW_CONFIG_ENABLE_VALUE ) +#endif + { + F32 heaterEstGain = heatersStatus[ heater ].heaterEstGain; + F32 heaterDutyCycle = heatersStatus[ heater ].dutyCycle; + F32 lastFillTemperature = getAvgFillTemperature(); + F32 primaryTargetTemperature = heatersStatus[ heater ].targetTemp; + BOOL isTempUnderTarget = ( lastFillTemperature < primaryTargetTemperature ? TRUE : FALSE ); + + if ( TRUE == isTempUnderTarget ) + { + if ( heaterDutyCycle < HEATERS_MAX_DUTY_CYCLE ) + { + heaterEstGain += ( primaryTargetTemperature - lastFillTemperature ) * PRIMARY_HEATER_DUTY_CYCLE_PER_TEMPERATURE_C; + } + } + else + { + if ( heaterDutyCycle > HEATERS_MIN_DUTY_CYCLE ) + { + heaterEstGain -= ( lastFillTemperature - primaryTargetTemperature ) * PRIMARY_HEATER_DUTY_CYCLE_PER_TEMPERATURE_C; + } + } + + heaterEstGain = MAX( heaterEstGain, HEATERS_MIN_EST_GAIN ); + heaterEstGain = MIN( heaterEstGain, HEATERS_MAX_EST_GAIN ); + heatersStatus[ heater ].heaterEstGain = heaterEstGain; + } +} + +/*********************************************************************//** + * @brief * The handleHeaterStateOff function handles the heater not running state. * @details Inputs: heaterStatus * @details Outputs: heaterStatus @@ -419,10 +464,9 @@ else if ( ( DG_MODE_GENE == opMode ) || ( DG_MODE_DRAI == opMode ) ) { targetTemperature += DELTA_TEMPERATURE_TIME_COSNTANT_C; - // Use target flow rate during Idle and drain - targetFlow = getTargetROPumpFlowRateLPM(); - dutyCycle = calculatePrimaryHeaterDutyCycle( targetTemperature, inletTemperature, targetFlow, FALSE ); - state = HEATER_EXEC_STATE_PRIMARY_CONTROL_TO_TARGET; + targetFlow = getTargetROPumpFlowRateLPM(); + dutyCycle = calculatePrimaryHeaterDutyCycle( targetTemperature, inletTemperature, targetFlow, FALSE ); + state = HEATER_EXEC_STATE_PRIMARY_CONTROL_TO_TARGET; } else if ( ( DG_MODE_HEAT == opMode ) || ( DG_MODE_CHEM == opMode ) ) { @@ -432,6 +476,11 @@ dutyCycle = calculatePrimaryHeaterDutyCycle( targetTemperature, inletTemperature, targetFlow, FALSE ); state = HEATER_EXEC_STATE_CONTROL_TO_DISINFECT_TARGET; } + else + { + // No other modes are using the heaters + // TODO software fault + } // Update the calculated target temperature heatersStatus[ DG_PRIMARY_HEATER ].calculatedTemperature = targetTemperature; @@ -483,7 +532,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 ) ) { @@ -524,7 +573,7 @@ if ( ( DG_MODE_FILL == opMode ) || ( DG_MODE_GENE == opMode ) || ( DG_MODE_DRAI == opMode ) ) { - currentTemperature = getTrimmerHeaterTargetTemperature(); + currentTemperature = getReservoirCurrentTemperature(); dutyCycle = calculateTrimmerHeaterDutyCycle( targetTemperature, currentTemperature, targetFlowLPM, TRUE ); state = HEATER_EXEC_STATE_TRIMMER_CONTROL_TO_TARGET; } @@ -540,10 +589,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; @@ -560,6 +614,7 @@ static HEATERS_STATE_T handleHeaterStateTrimmerControlToTarget( void ) { HEATERS_STATE_T state = HEATER_EXEC_STATE_TRIMMER_CONTROL_TO_TARGET; + F32 tempDutyCycle = 0.0; // If the inactive reservoir has changed from the last run transition to ramp state to recalculate the // duty cycle for the next delivery @@ -571,14 +626,17 @@ { // 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_INLET_DIALYSATE ); // TODO Change to TRo in DVT + F32 outletRedundantTemperature = getTemperatureValue( TEMPSENSORS_OUTLET_REDUNDANT ); F32 targetTemperature = heatersStatus[ DG_TRIMMER_HEATER ].targetTemp; F32 targetFlowLPM = heatersStatus[ DG_TRIMMER_HEATER ].targetFlow; F32 dutyCycle = calculateTrimmerHeaterDutyCycle( targetTemperature, outletRedundantTemperature, targetFlowLPM, TRUE ); - trimmerHeaterControlCounter = 0; - setHeaterDutyCycle( DG_TRIMMER_HEATER, dutyCycle ); + tempDutyCycle = heatersStatus[ DG_TRIMMER_HEATER ].dutyCycle + dutyCycle; + tempDutyCycle = MIN( tempDutyCycle, HEATERS_MAX_DUTY_CYCLE ); + tempDutyCycle = MAX( tempDutyCycle, HEATERS_MIN_DUTY_CYCLE ); + + setHeaterDutyCycle( DG_TRIMMER_HEATER, tempDutyCycle ); } return state; @@ -598,7 +656,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 ) { @@ -611,7 +669,7 @@ } // Updated the heater's information - heatersStatus[ heater ].dutycycle = pwm; + heatersStatus[ heater ].dutyCycle = pwm; } } @@ -628,48 +686,13 @@ *************************************************************************/ static F32 calculatePrimaryHeaterDutyCycle( F32 targetTemperature, F32 currentTemperature, F32 flow, BOOL checkEfficiency ) { - // Get the primary heater's efficiency and the last fill temperature from the ModeFill - F32 heaterEfficiency = heatersStatus[ DG_PRIMARY_HEATER ].heaterEfficiency; - -#ifndef _RELEASE_ - if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_HEATERS_EFFICIENCY ) != SW_CONFIG_ENABLE_VALUE ) -#endif - { - if ( TRUE == checkEfficiency ) - { - F32 lastFillTemperature = getLastFillTemperature(); - F32 primaryTargetTemperature = heatersStatus[ DG_PRIMARY_HEATER ].targetTemp; - - // If the last fill temperature > target temperature, it means the primary heater overshot the duty cycle - // so with its efficiency is toned down for the next fill cycle - // If the heater under-shoots the duty cycle, the efficiency increases the duty cycle for the next fill cycle - if ( lastFillTemperature - primaryTargetTemperature < 0.0F ) - { - heaterEfficiency -= ( lastFillTemperature - primaryTargetTemperature ) * PRIMARY_HEATER_DUTY_CYCLE_PER_TEMPERATURE_C; - } - else - { - heaterEfficiency += ( primaryTargetTemperature - lastFillTemperature ) * PRIMARY_HEATER_DUTY_CYCLE_PER_TEMPERATURE_C; - } - - // If the efficiency is less than 0, set it to 0 but if the efficiency is greater than 100, it is not enforced - // to be 100 since the duty cycle range check will cap the duty cycle to 100 anyways. - heaterEfficiency = MAX( heaterEfficiency, 0.0 ); - - // Update the heaters efficiency - heatersStatus[ DG_PRIMARY_HEATER ].heaterEfficiency = heaterEfficiency; - } - } - // Duty cycle = ( 69.73 * flow rate * deltaT / primary heater maximum power ) ^ 1/2 // Multiply the duty cycle to the heater efficiency - F32 dutyCycle = sqrt( ( WATER_SPECIFIC_HEAT_DIVIDED_BY_MINUTES * - fabs( targetTemperature - currentTemperature ) * flow ) / PRIMARY_HEATERS_MAXIMUM_POWER_WATTS ) * heaterEfficiency; + F32 dutyCycle = sqrt( ( WATER_SPECIFIC_HEAT_DIVIDED_BY_MINUTES * fabs( targetTemperature - currentTemperature ) * flow ) / PRIMARY_HEATERS_MAXIMUM_POWER_WATTS ); + dutyCycle *= heatersStatus[ DG_PRIMARY_HEATER ].heaterEstGain; + dutyCycle = MIN( dutyCycle, HEATERS_MAX_DUTY_CYCLE ); + dutyCycle = MAX( dutyCycle, HEATERS_MIN_DUTY_CYCLE ); - // Check the boundaries of the calculated duty cycle - dutyCycle = MIN( dutyCycle, HEATERS_MAX_DUTY_CYCLE ); - dutyCycle = MAX( dutyCycle, HEATERS_MIN_DUTY_CYCLE ); - return dutyCycle; } @@ -689,8 +712,8 @@ static F32 calculateTrimmerHeaterDutyCycle( F32 targetTemperature, F32 currentTemperature, F32 flow, BOOL checkEfficiency ) { // Get the primary heater's efficiency and the last fill temperature from the ModeFill - F32 heaterEfficiency = heatersStatus[ DG_TRIMMER_HEATER ].heaterEfficiency; - F32 dutyCycle = 0.0; + F32 heaterEstGain = heatersStatus[ DG_TRIMMER_HEATER ].heaterEstGain; + F32 dutyCycle = 0.0F; #ifndef _RELEASE_ if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_HEATERS_EFFICIENCY ) != SW_CONFIG_ENABLE_VALUE ) @@ -703,12 +726,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 ) * heaterEfficiency ) / TRIMMER_HEATER_MAX_POWER_W ) * heaterEfficiency; - - // 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; } @@ -793,22 +813,21 @@ { 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; data.trimmerHeaterState = heatersStatus[ DG_TRIMMER_HEATER ].state; - data.primaryEfficiency = heatersStatus[ DG_PRIMARY_HEATER ].heaterEfficiency * 100; + data.primaryEfficiency = heatersStatus[ DG_PRIMARY_HEATER ].heaterEstGain * 100; data.primaryCalcTargetTemp = heatersStatus[ DG_PRIMARY_HEATER ].calculatedTemperature; data.trimmerCalcCurrentTemp = heatersStatus[ DG_TRIMMER_HEATER ].calculatedTemperature; + dataPublicationTimerCounter = 0; broadcastData( MSG_ID_DG_HEATERS_DATA, COMM_BUFFER_OUT_CAN_DG_BROADCAST, (U08*)&data, sizeof( HEATERS_DATA_T ) ); - - dataPublicationTimerCounter = 0; } } @@ -821,29 +840,37 @@ *************************************************************************/ static void monitorHeatersVoltage( void ) { - 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 - // heater so the main primary heater's ADC channel is used for the small primary heater as well. - F32 smallPriVoltage = getIntADCVoltageConverted( INT_ADC_PRIMARY_HEATER_24_VOLTS ); - F32 trimmerVoltage = getIntADCVoltageConverted( INT_ADC_TRIMMER_HEATER_24_VOLTS ); + // NOTE: Default to using Primary heater voltage from FPGA + F32 mainPriVoltage = getMonitoredLineLevel( MONITORED_LINE_24V_PRIM_HTR_GND_V ); +#ifndef _RELEASE_ + if ( SW_CONFIG_ENABLE_VALUE == getSoftwareConfigStatus( SW_CONFIG_ENABLE_V3_SYSTEM ) ) + { + // V3 use CPU based value for Primary, same as Secondary + mainPriVoltage = getMonitoredLineLevel( MONITORED_LINE_24V_SEC_HTR_V ); + } +#endif + F32 smallPriVoltage = getMonitoredLineLevel( MONITORED_LINE_24V_SEC_HTR_V ); + F32 trimmerVoltage = getMonitoredLineLevel( MONITORED_LINE_24V_TRIM_HTR_V ); // Voltage to PWM is reverse. If PWM = 0 -> V = 24V - F32 mainPri = heatersStatus[ DG_PRIMARY_HEATER ].dutycycle > NEARLY_ZERO ? heatersStatus[ DG_PRIMARY_HEATER ].dutycycle : 1.0; - F32 smallPri = heatersStatus[ DG_PRIMARY_HEATER ].dutycycle > NEARLY_ZERO ? heatersStatus[ DG_PRIMARY_HEATER ].dutycycle : 1.0; - F32 trimmer = heatersStatus[ DG_TRIMMER_HEATER ].dutycycle > NEARLY_ZERO ? heatersStatus[ DG_TRIMMER_HEATER ].dutycycle : 1.0; + F32 mainPriDC = heatersStatus[ DG_PRIMARY_HEATER ].dutyCycle; + F32 smallPriDC = heatersStatus[ DG_PRIMARY_HEATER ].dutyCycle; + F32 trimmerDC = heatersStatus[ DG_TRIMMER_HEATER ].dutyCycle; - F32 mainPriVoltageTol = HEATERS_MAX_VOLTAGE_OUT_OF_RANGE_TOL * mainPriVoltage; - F32 smallPriVoltageTol = HEATERS_MAX_VOLTAGE_OUT_OF_RANGE_TOL * smallPriVoltage; - F32 trimmerVoltageTol = HEATERS_MAX_VOLTAGE_OUT_OF_RANGE_TOL * trimmerVoltage; + F32 mainPriExpectedVoltage = HEATERS_MAX_OPERATING_VOLTAGE_V * ( 1.0F - mainPriDC ); + F32 smallPriExpectedVoltage = HEATERS_MAX_OPERATING_VOLTAGE_V * ( 1.0F - smallPriDC ); + F32 trimmerExpectedVoltage = HEATERS_MAX_OPERATING_VOLTAGE_V * ( 1.0F - trimmerDC ); - BOOL isMainPriOut = ( fabs( ( HEATERS_MAX_OPERATING_VOLTAGE_V * mainPri ) - mainPriVoltage ) > mainPriVoltageTol ? TRUE : FALSE ); - BOOL isSmallPriOut = ( fabs( ( HEATERS_MAX_OPERATING_VOLTAGE_V * smallPri ) - smallPriVoltage ) > smallPriVoltageTol ? TRUE : FALSE ); - BOOL isTrimmerOut = ( fabs( ( HEATERS_MAX_OPERATING_VOLTAGE_V * trimmer ) - trimmerVoltage ) > trimmerVoltageTol ? TRUE : FALSE ); + BOOL isMainPriOut = ( fabs( mainPriExpectedVoltage - mainPriVoltage ) > HEATERS_VOLTAGE_TOLERANCE_V ? TRUE : FALSE ); + BOOL isSmallPriOut = ( fabs( smallPriExpectedVoltage - smallPriVoltage ) > HEATERS_VOLTAGE_TOLERANCE_V ? TRUE : FALSE ); + BOOL isTrimmerOut = ( fabs( trimmerExpectedVoltage - trimmerVoltage ) > HEATERS_VOLTAGE_TOLERANCE_V ? TRUE : FALSE ); - //checkPersistentAlarm( ALARM_ID_DG_MAIN_PRIMARY_HEATER_VOLTAGE_OUT_OF_RANGE, isMainPriOut, mainPri, mainPriVoltageTol ); - //checkPersistentAlarm( ALARM_ID_DG_SMALL_PRIMARY_HEATER_VOLTAGE_OUT_OF_RANGE, isSmallPriOut, smallPri, smallPriVoltageTol ); - //checkPersistentAlarm( ALARM_ID_DG_TRIMMER_HEATER_VOLTAGE_OUT_OF_RANGE, isTrimmerOut, trimmer, trimmerVoltageTol ); + if ( getCurrentOperationMode() != DG_MODE_INIT ) + { + checkPersistentAlarm( ALARM_ID_DG_MAIN_PRIMARY_HEATER_VOLTAGE_OUT_OF_RANGE, isMainPriOut, mainPriDC, HEATERS_VOLTAGE_TOLERANCE_V ); + checkPersistentAlarm( ALARM_ID_DG_SMALL_PRIMARY_HEATER_VOLTAGE_OUT_OF_RANGE, isSmallPriOut, smallPriDC, HEATERS_VOLTAGE_TOLERANCE_V ); + checkPersistentAlarm( ALARM_ID_DG_TRIMMER_HEATER_VOLTAGE_OUT_OF_RANGE, isTrimmerOut, trimmerDC, HEATERS_VOLTAGE_TOLERANCE_V ); + } }