Index: firmware/App/Controllers/Heaters.c =================================================================== diff -u -r025612ad77fe630889a364586de54bffe5262d56 -r4b208641ed0c22d13211e6343ffaec9778560cc5 --- firmware/App/Controllers/Heaters.c (.../Heaters.c) (revision 025612ad77fe630889a364586de54bffe5262d56) +++ firmware/App/Controllers/Heaters.c (.../Heaters.c) (revision 4b208641ed0c22d13211e6343ffaec9778560cc5) @@ -68,6 +68,7 @@ #define DELTA_TEMPERATURE_TIME_COSNTANT_C 8.6 ///< Delta temperature calculated from time constant. #define MAXIMUM_ALLOWED_TARGET_TEMPERATURE_DEVIATION_C 0.25 ///< Maximum allowed temperature deviation from target temperature in C. #define PRIMARY_HEATER_DUTY_CYCLE_PER_TEMPERATURE_C 0.03 ///< Primary heaters duty cycle per temperature in C. +#define DATA_PUBLISH_COUNTER_START_COUNT 70 ///< Data publish counter start count. 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.5; ///< Primary heaters maximum power (main primary = 475W and small primary = 237.5W). @@ -108,7 +109,6 @@ static U32 dataPublicationTimerCounter; ///< Data publication timer counter. static OVERRIDE_U32_T heatersDataPublishInterval = { HEATERS_DATA_PUBLISH_INTERVAL, HEATERS_DATA_PUBLISH_INTERVAL, 0, 0 }; ///< Heaters data publish time interval. static U32 voltageMonitorTimeCounter = 0; ///< Heaters voltage monitor counter. -static U32 operationMode = 0; // ********** private function prototypes ********** @@ -128,24 +128,22 @@ static void setSmallPrimaryHeaterPWM( F32 pwm ); static void setTrimmerHeaterPWM( F32 pwm ); static void publishHeatersData( void ); -static void checkPrimaryHeaterTempSensors( void ); -static void checkTrimmerHeaterTempSensors( void ); static void monitorHeatersVoltage( void ); /*********************************************************************//** * @brief * The initHeaters initializes the heaters driver. * @details Inputs: none * @details Outputs: voltageMonitorTimeCounter, heaterStatus, - * hasTreatmentInternalTempBeenSet + * hasTreatmentInternalTempBeenSet, dataPublicationTimerCounter * @return none *************************************************************************/ void initHeaters( void ) { DG_HEATERS_T heater; - voltageMonitorTimeCounter = 0; - operationMode = 0; + voltageMonitorTimeCounter = 0; + dataPublicationTimerCounter = DATA_PUBLISH_COUNTER_START_COUNT; for ( heater = DG_PRIMARY_HEATER; heater < NUM_OF_DG_HEATERS; heater++ ) { @@ -359,14 +357,9 @@ *************************************************************************/ void execHeatersMonitor( void ) { -#if 0 // This code is disabled to prevent any heaters monitoring while the driver in in development. +#ifndef IGNORE_HEATERS_MONITOR DG_HEATERS_T heater; -#ifndef IGNORE_HEATERS_MONITOR - checkPrimaryHeaterTempSensors(); - checkTrimmerHeaterTempSensors(); -#endif - for ( heater = DG_PRIMARY_HEATER; heater < NUM_OF_DG_HEATERS; heater++ ) { // Check if a heater is on and whether is duty cycle is not zero @@ -492,7 +485,7 @@ state = HEATER_EXEC_STATE_CONTROL_TO_DISINFECT_TARGET; } - // TODO remove + // TODO remove once dialysate heating is done heatersStatus[ DG_PRIMARY_HEATER ].temporaryInterimTemperature = targetTemperature; // TODO remove @@ -666,9 +659,10 @@ // Get the primary heater's efficiency and the last fill temperature from the ModeFill F32 heaterEfficiency = heatersStatus[ DG_PRIMARY_HEATER ].heaterEfficiency; - if ( TRUE == checkEfficiency ) // TODO ignore the efficiency for now until it is fixed +#ifndef DISABLE_HEATERS_EFFICIENCY + if ( TRUE == checkEfficiency ) { - /*F32 lastFillTemperature = getLastFillTemperature(); + 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 @@ -678,17 +672,17 @@ { heaterEfficiency -= ( lastFillTemperature - primaryTargetTemperature ) * PRIMARY_HEATER_DUTY_CYCLE_PER_TEMPERATURE_C; } - else if ( lastFillTemperature - primaryTargetTemperature <= MAXIMUM_ALLOWED_TARGET_TEMPERATURE_DEVIATION_C ) + else { heaterEfficiency += ( primaryTargetTemperature - lastFillTemperature ) * PRIMARY_HEATER_DUTY_CYCLE_PER_TEMPERATURE_C; } heaterEfficiency = heaterEfficiency <= 0.0 ? 0.0 : heaterEfficiency; - //heaterEfficiency = heaterEfficiency >= 1.0 ? 1.0 : heaterEfficiency; // Update the heaters efficiency - heatersStatus[ DG_PRIMARY_HEATER ].heaterEfficiency = heaterEfficiency; */ + heatersStatus[ DG_PRIMARY_HEATER ].heaterEfficiency = heaterEfficiency; } +#endif // Duty cycle = ( 69.73 * flow rate * deltaT / primary heater maximum power ) ^ 1/2 // Multiply the duty cycle to the heater efficiency @@ -721,11 +715,12 @@ F32 heaterEfficiency = heatersStatus[ DG_TRIMMER_HEATER ].heaterEfficiency; F32 dutyCycle = 0.0; - +#ifndef DISABLE_HEATERS_EFFICIENCY if ( TRUE == checkEfficiency ) { // TODO Do we need to recalculate the efficiency? } +#endif dutyCycle = flow * WATER_SPECIFIC_HEAT_DIVIDED_BY_MINUTES * ( targetTemperature - currentTemperature ) * heaterEfficiency; @@ -841,94 +836,6 @@ /*********************************************************************//** * @brief - * The checkPrimaryHeaterTempSensors function checks the primary heater's - * thermocouple and cold junction temperature sensors. - * @details Inputs: isPrimaryHeaterTempOutOfRange - * @details Outputs: isPrimaryHeaterTempOutOfRange - * @return none - *************************************************************************/ -static void checkPrimaryHeaterTempSensors( void ) -{ - F32 primaryHeaterInternalTemp = getTemperatureValue( TEMPSENSORS_PRIMARY_HEATER_INTERNAL ); - F32 primaryHeaterColdJunctionTemp = getTemperatureValue( TEMPSENSORS_PRIMARY_HEATER_COLD_JUNCTION ); - BOOL isTempOut = FALSE; - - // Check if the primary heater's internal temperature or the cold junction temperature is above the allowed limit - if ( primaryHeaterInternalTemp > HEATERS_MAX_ALLOWED_INTERNAL_TEMPERATURE_C ) - { - isTempOut = TRUE; - SET_ALARM_WITH_1_U32_DATA( ALARM_ID_DG_PRIMARY_HEATER_INTERNAL_TEMP_OUT_OF_RANGE, primaryHeaterInternalTemp ); - } - else if ( primaryHeaterColdJunctionTemp > HEATERS_MAX_ALLOWED_COLD_JUNCTION_TEMPERATURE_C ) - { - isTempOut = TRUE; - SET_ALARM_WITH_1_U32_DATA( ALARM_ID_DG_PRIMARY_HEATER_CJ_TEMP_OUT_OF_RANGE, primaryHeaterInternalTemp ); - } - -#ifndef IGNORE_HEATERS_MONITOR - // If any of the temperatures are above the range - if ( ( FALSE == isPrimaryHeaterTempOutOfRange ) && ( TRUE == isTempOut ) ) - { - stopPrimaryHeater(); - isPrimaryHeaterTempOutOfRange = TRUE; - primaryHeaterTempOutTimer = getMSTimerCount(); - } - // If the primary heaters internal temperature was out for more than the define period, activate the safety shutdown - else if ( ( TRUE == isPrimaryHeaterTempOutOfRange ) && - ( TRUE == didTimeout( primaryHeaterTempOutTimer, HEATERS_MAX_ALLOWED_INTERNAL_TEMPERATURE_TIMEOUT_MS ) ) ) - { - isPrimaryHeaterTempOutOfRange = FALSE; - activateSafetyShutdown(); - } -#endif -} - -/*********************************************************************//** - * @brief - * The checkTrimmerHeaterTempSensors function checks the trimmer heater's - * thermocouple and cold junction temperature sensors. - * @details Inputs: isTrimmerHeaterTempOutOfRange - * @details Outputs: isTrimmerHeaterTempOutOfRange - * @return none - *************************************************************************/ -static void checkTrimmerHeaterTempSensors( void ) -{ - F32 trimmerHeaterInternalTemp = getTemperatureValue( TEMPSENSORS_TRIMMER_HEATER_INTERNAL ); - F32 trimmerHeaterColdJunctionTemp = getTemperatureValue( TEMPSENSORS_TRIMMER_HEATER_COLD_JUNCTION ); - BOOL isTempOut = FALSE; - - // Check if the primary heater's internal temperature or the cold junction temperature is above the allowed limit - if ( trimmerHeaterInternalTemp > HEATERS_MAX_ALLOWED_INTERNAL_TEMPERATURE_C ) - { - isTempOut = TRUE; - SET_ALARM_WITH_1_U32_DATA( ALARM_ID_DG_TRIMMER_HEATER_INTERNAL_TEMP_OUT_OF_RANGE, trimmerHeaterInternalTemp ); - } - else if ( trimmerHeaterColdJunctionTemp > HEATERS_MAX_ALLOWED_COLD_JUNCTION_TEMPERATURE_C ) - { - isTempOut = TRUE; - SET_ALARM_WITH_1_U32_DATA( ALARM_ID_DG_TRIMMER_HEATER_CJ_TEMP_OUT_OF_RANGE, trimmerHeaterColdJunctionTemp ); - } - -#ifndef IGNORE_HEATERS_MONITOR - // If it is above the range for the first time, stop the trimmer heater - // and set the variables - if ( ( FALSE == isTrimmerHeaterTempOutOfRange ) && ( TRUE == isTempOut ) ) - { - stopTrimmerHeater(); - isTrimmerHeaterTempOutOfRange = TRUE; - trimmerHeaterTempOutTimer = getMSTimerCount(); - } - // If the trimmer heater internal temperature was out for more than the define period, activate the safety shutdown - else if ( ( TRUE == isTrimmerHeaterTempOutOfRange ) && - ( TRUE == didTimeout( trimmerHeaterTempOutTimer, HEATERS_MAX_ALLOWED_INTERNAL_TEMPERATURE_TIMEOUT_MS ) ) ) - { - activateSafetyShutdown(); - } -#endif -} - -/*********************************************************************//** - * @brief * The monitorHeatersVoltage function monitors the heaters' voltages * @details Inputs: voltageMonitorTimeCounter * @details Outputs: voltageMonitorTimeCounter