diff --git a/Firmware/Configuration_adv.h b/Firmware/Configuration_adv.h index 7deff3c12..7ab7a2ee8 100644 --- a/Firmware/Configuration_adv.h +++ b/Firmware/Configuration_adv.h @@ -437,6 +437,10 @@ const unsigned int dropsegments=5; //everything with less than this number of st #undef BED_MINTEMP #undef BED_MAXTEMP #endif +#if TEMP_SENSOR_AMBIENT == 0 + #undef AMBIENT_MINTEMP + #undef AMBIENT_MAXTEMP +#endif #endif //__CONFIGURATION_ADV_H diff --git a/Firmware/temperature.cpp b/Firmware/temperature.cpp index 6e9b6985a..2d09f8e0f 100755 --- a/Firmware/temperature.cpp +++ b/Firmware/temperature.cpp @@ -180,6 +180,12 @@ static int bed_minttemp_raw = HEATER_BED_RAW_LO_TEMP; #ifdef BED_MAXTEMP static int bed_maxttemp_raw = HEATER_BED_RAW_HI_TEMP; #endif +#ifdef AMBIENT_MINTEMP +static int ambient_minttemp_raw = AMBIENT_RAW_LO_TEMP; +#endif +#ifdef AMBIENT_MAXTEMP +static int ambient_maxttemp_raw = AMBIENT_RAW_HI_TEMP; +#endif static void *heater_ttbl_map[EXTRUDERS] = ARRAY_BY_EXTRUDERS( (void *)HEATER_0_TEMPTABLE, (void *)HEATER_1_TEMPTABLE, (void *)HEATER_2_TEMPTABLE ); static uint8_t heater_ttbllen_map[EXTRUDERS] = ARRAY_BY_EXTRUDERS( HEATER_0_TEMPTABLE_LEN, HEATER_1_TEMPTABLE_LEN, HEATER_2_TEMPTABLE_LEN ); @@ -639,6 +645,7 @@ void manage_heater() return; // more precisely - this condition partially stabilizes time interval for regulation values evaluation (@ ~ 230ms) + // ADC values need to be converted before checking: converted values are later used in MINTEMP updateTemperaturesFromRawValues(); check_max_temp(); @@ -1165,7 +1172,6 @@ void tp_init() #endif //MAXTEMP 2 #ifdef BED_MINTEMP - /* No bed MINTEMP error implemented?!? */ while(analog2tempBed(bed_minttemp_raw) < BED_MINTEMP) { #if HEATER_BED_RAW_LO_TEMP < HEATER_BED_RAW_HI_TEMP bed_minttemp_raw += OVERSAMPLENR; @@ -1173,7 +1179,6 @@ void tp_init() bed_minttemp_raw -= OVERSAMPLENR; #endif } - #endif //BED_MINTEMP #ifdef BED_MAXTEMP while(analog2tempBed(bed_maxttemp_raw) > BED_MAXTEMP) { @@ -1184,6 +1189,25 @@ void tp_init() #endif } #endif //BED_MAXTEMP + +#ifdef AMBIENT_MINTEMP + while(analog2tempAmbient(ambient_minttemp_raw) < AMBIENT_MINTEMP) { +#if HEATER_AMBIENT_RAW_LO_TEMP < HEATER_AMBIENT_RAW_HI_TEMP + ambient_minttemp_raw += OVERSAMPLENR; +#else + ambient_minttemp_raw -= OVERSAMPLENR; +#endif + } +#endif //AMBIENT_MINTEMP +#ifdef AMBIENT_MAXTEMP + while(analog2tempAmbient(ambient_maxttemp_raw) > AMBIENT_MAXTEMP) { +#if HEATER_AMBIENT_RAW_LO_TEMP < HEATER_AMBIENT_RAW_HI_TEMP + ambient_maxttemp_raw -= OVERSAMPLENR; +#else + ambient_maxttemp_raw += OVERSAMPLENR; +#endif + } +#endif //AMBIENT_MAXTEMP } #if (defined (TEMP_RUNAWAY_BED_HYSTERESIS) && TEMP_RUNAWAY_BED_TIMEOUT > 0) || (defined (TEMP_RUNAWAY_EXTRUDER_HYSTERESIS) && TEMP_RUNAWAY_EXTRUDER_TIMEOUT > 0) @@ -1427,20 +1451,47 @@ enum { LCDALERT_NONE = 0, LCDALERT_HEATERMINTEMP, LCDALERT_BEDMINTEMP, LCDALERT_ //! to prevent flicker and improve speed uint8_t last_alert_sent_to_lcd = LCDALERT_NONE; + +//! update the current temperature error message +//! @param type short error abbreviation (PROGMEM) +//! @param func optional lcd update function (lcd_setalertstatus when first setting the error) +void temp_update_messagepgm(const char* PROGMEM type, void (*func)(const char*) = lcd_updatestatus) +{ + char msg[LCD_WIDTH]; + strcpy_P(msg, PSTR("Err: ")); + strcat_P(msg, type); + (*func)(msg); +} + +//! signal a temperature error on both the lcd and serial +//! @param type short error abbreviation (PROGMEM) +//! @param e optional extruder index for hotend errors +void temp_error_messagepgm(const char* PROGMEM type, uint8_t e = EXTRUDERS) +{ + temp_update_messagepgm(type, lcd_setalertstatus); + + SERIAL_ERROR_START; + + if(e != EXTRUDERS) { + SERIAL_ERROR((int)e); + SERIAL_ERRORPGM(": "); + } + + SERIAL_ERRORPGM("Heaters switched off. "); + SERIAL_ERRORRPGM(type); + SERIAL_ERRORLNPGM(" triggered!"); +} + + void max_temp_error(uint8_t e) { disable_heater(); if(IsStopped() == false) { - SERIAL_ERROR_START; - SERIAL_ERRORLN((int)e); - SERIAL_ERRORLNPGM(": Extruder switched off. MAXTEMP triggered !"); - LCD_ALERTMESSAGEPGM("Err: MAXTEMP"); + temp_error_messagepgm(PSTR("MAXTEMP"), e); } #ifndef BOGUS_TEMPERATURE_FAILSAFE_OVERRIDE Stop(); - - - #endif + SET_OUTPUT(FAN_PIN); SET_OUTPUT(BEEPER); WRITE(FAN_PIN, 1); @@ -1458,18 +1509,15 @@ void min_temp_error(uint8_t e) { #ifdef DEBUG_DISABLE_MINTEMP return; #endif -//if (current_temperature_ambient < MINTEMP_MINAMBIENT) return; disable_heater(); - static const char err[] PROGMEM = "Err: MINTEMP"; +//if (current_temperature_ambient < MINTEMP_MINAMBIENT) return; + static const char err[] PROGMEM = "MINTEMP"; if(IsStopped() == false) { - SERIAL_ERROR_START; - SERIAL_ERRORLN((int)e); - SERIAL_ERRORLNPGM(": Extruder switched off. MINTEMP triggered !"); - lcd_setalertstatuspgm(err); + temp_error_messagepgm(err, e); last_alert_sent_to_lcd = LCDALERT_HEATERMINTEMP; } else if( last_alert_sent_to_lcd != LCDALERT_HEATERMINTEMP ){ // only update, if the lcd message is to be changed (i.e. not the same as last time) // we are already stopped due to some error, only update the status message without flickering - lcd_updatestatuspgm(err); + temp_update_messagepgm(err); last_alert_sent_to_lcd = LCDALERT_HEATERMINTEMP; } #ifndef BOGUS_TEMPERATURE_FAILSAFE_OVERRIDE @@ -1484,37 +1532,27 @@ void min_temp_error(uint8_t e) { } void bed_max_temp_error(void) { -#if HEATER_BED_PIN > -1 - //WRITE(HEATER_BED_PIN, 0); -#endif + disable_heater(); if(IsStopped() == false) { - SERIAL_ERROR_START; - SERIAL_ERRORLNPGM("Temperature heated bed switched off. MAXTEMP triggered !"); - LCD_ALERTMESSAGEPGM("Err: MAXTEMP BED"); + temp_error_messagepgm(PSTR("MAXTEMP BED")); } #ifndef BOGUS_TEMPERATURE_FAILSAFE_OVERRIDE Stop(); #endif - } void bed_min_temp_error(void) { #ifdef DEBUG_DISABLE_MINTEMP return; #endif -//if (current_temperature_ambient < MINTEMP_MINAMBIENT) return; -#if HEATER_BED_PIN > -1 - //WRITE(HEATER_BED_PIN, 0); -#endif - static const char err[] PROGMEM = "Err: MINTEMP BED"; + disable_heater(); + static const char err[] PROGMEM = "MINTEMP BED"; if(IsStopped() == false) { - SERIAL_ERROR_START; - SERIAL_ERRORLNPGM("Temperature heated bed switched off. MINTEMP triggered !"); - lcd_setalertstatuspgm(err); + temp_error_messagepgm(err); last_alert_sent_to_lcd = LCDALERT_BEDMINTEMP; } else if( last_alert_sent_to_lcd != LCDALERT_BEDMINTEMP ){ // only update, if the lcd message is to be changed (i.e. not the same as last time) // we are already stopped due to some error, only update the status message without flickering - lcd_updatestatuspgm(err); + temp_update_messagepgm(err); last_alert_sent_to_lcd = LCDALERT_BEDMINTEMP; } #ifndef BOGUS_TEMPERATURE_FAILSAFE_OVERRIDE @@ -1522,6 +1560,33 @@ void bed_min_temp_error(void) { #endif } + +#ifdef AMBIENT_THERMISTOR +void ambient_max_temp_error(void) { + disable_heater(); + if(IsStopped() == false) { + temp_error_messagepgm(PSTR("MAXTEMP AMB")); + } +#ifndef BOGUS_TEMPERATURE_FAILSAFE_OVERRIDE + Stop(); +#endif +} + +void ambient_min_temp_error(void) { +#ifdef DEBUG_DISABLE_MINTEMP + return; +#endif + disable_heater(); + if(IsStopped() == false) { + temp_error_messagepgm(PSTR("MINTEMP AMB")); + } +#ifndef BOGUS_TEMPERATURE_FAILSAFE_OVERRIDE + Stop(); +#endif +} +#endif + + #ifdef HEATER_0_USES_MAX6675 #define MAX6675_HEAT_INTERVAL 250 long max6675_previous_millis = MAX6675_HEAT_INTERVAL; @@ -2004,11 +2069,19 @@ void check_max_temp() #else if (current_temperature_bed_raw >= bed_maxttemp_raw) { #endif - target_temperature_bed = 0; bed_max_temp_error(); } #endif - +//ambient +#if defined(AMBIENT_MAXTEMP) && (TEMP_SENSOR_AMBIENT != 0) +#if AMBIENT_RAW_LO_TEMP > AMBIENT_RAW_HI_TEMP + if (current_temperature_raw_ambient <= ambient_maxttemp_raw) { +#else + if (current_temperature_raw_ambient >= ambient_maxttemp_raw) { +#endif + ambient_max_temp_error(); + } +#endif } //! number of repeating the same state with consecutive step() calls //! used to slow down text switching @@ -2103,12 +2176,32 @@ void check_min_temp_bed() } } +#ifdef AMBIENT_MINTEMP +void check_min_temp_ambient() +{ +#if AMBIENT_RAW_LO_TEMP > AMBIENT_RAW_HI_TEMP + if (current_temperature_raw_ambient >= ambient_minttemp_raw) { +#else + if (current_temperature_raw_ambient <= ambient_minttemp_raw) { +#endif + ambient_min_temp_error(); + } +} +#endif + void check_min_temp() { static bool bCheckingOnHeater=false; // state variable, which allows to short no-checking delay (is set, when temperature is (first time) over heaterMintemp) static bool bCheckingOnBed=false; // state variable, which allows to short no-checking delay (is set, when temperature is (first time) over bedMintemp) #ifdef AMBIENT_THERMISTOR -if(current_temperature_raw_ambient>(OVERSAMPLENR*MINTEMP_MINAMBIENT_RAW)) // thermistor is NTC type, so operator is ">" ;-) +#ifdef AMBIENT_MINTEMP +check_min_temp_ambient(); +#endif +#if AMBIENT_RAW_LO_TEMP > AMBIENT_RAW_HI_TEMP +if(current_temperature_raw_ambient>(OVERSAMPLENR*MINTEMP_MINAMBIENT_RAW)) // thermistor is NTC type +#else +if(current_temperature_raw_ambient=<(OVERSAMPLENR*MINTEMP_MINAMBIENT_RAW)) +#endif { // ambient temperature is low #endif //AMBIENT_THERMISTOR // *** 'common' part of code for MK2.5 & MK3 diff --git a/Firmware/thermistortables.h b/Firmware/thermistortables.h index dc934ccfd..721c6b359 100644 --- a/Firmware/thermistortables.h +++ b/Firmware/thermistortables.h @@ -1213,6 +1213,8 @@ const short temptable_1047[][2] PROGMEM = { #endif #if (THERMISTORAMBIENT == 2000) //100k thermistor NTCG104LH104JT1 +# define AMBIENT_RAW_HI_TEMP 0 +# define AMBIENT_RAW_LO_TEMP 16383 const short temptable_2000[][2] PROGMEM = { // Source: https://product.tdk.com/info/en/catalog/datasheets/503021/tpd_ntc-thermistor_ntcg_en.pdf // Calculated using 4.7kohm pullup, voltage divider math, and manufacturer provided temp/resistance diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 87266914f..a08f8a365 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -8951,13 +8951,14 @@ void lcd_finishstatus() { lcd_draw_update = 2; } + void lcd_setstatus(const char* message) { if (lcd_status_message_level > 0) return; - strncpy(lcd_status_message, message, LCD_WIDTH); - lcd_finishstatus(); + lcd_updatestatus(message); } + void lcd_updatestatuspgm(const char *message){ strncpy_P(lcd_status_message, message, LCD_WIDTH); lcd_status_message[LCD_WIDTH] = 0; @@ -8972,12 +8973,29 @@ void lcd_setstatuspgm(const char* message) return; lcd_updatestatuspgm(message); } + +void lcd_updatestatus(const char *message){ + strncpy(lcd_status_message, message, LCD_WIDTH); + lcd_status_message[LCD_WIDTH] = 0; + lcd_finishstatus(); + // hack lcd_draw_update to 1, i.e. without clear + lcd_draw_update = 1; +} + void lcd_setalertstatuspgm(const char* message) { lcd_setstatuspgm(message); lcd_status_message_level = 1; lcd_return_to_status(); } + +void lcd_setalertstatus(const char* message) +{ + lcd_setstatus(message); + lcd_status_message_level = 1; + lcd_return_to_status(); +} + void lcd_reset_alert_level() { lcd_status_message_level = 0; diff --git a/Firmware/ultralcd.h b/Firmware/ultralcd.h index 844c7c7d3..a5f07673f 100755 --- a/Firmware/ultralcd.h +++ b/Firmware/ultralcd.h @@ -23,9 +23,11 @@ void lcd_setstatuspgm(const char* message); //! - always returns the display to the main status screen //! - always makes lcd_reset (which is slow and causes flicker) //! - does not update the message if there is already one (i.e. lcd_status_message_level > 0) +void lcd_setalertstatus(const char* message); void lcd_setalertstatuspgm(const char* message); //! only update the alert message on the main status screen //! has no sideeffects, may be called multiple times +void lcd_updatestatus(const char *message); void lcd_updatestatuspgm(const char *message); void lcd_reset_alert_level(); diff --git a/Firmware/variants/1_75mm_MK3-EINSy10a-E3Dv6full.h b/Firmware/variants/1_75mm_MK3-EINSy10a-E3Dv6full.h index b135d8d13..04b4c5266 100644 --- a/Firmware/variants/1_75mm_MK3-EINSy10a-E3Dv6full.h +++ b/Firmware/variants/1_75mm_MK3-EINSy10a-E3Dv6full.h @@ -296,6 +296,7 @@ #endif #define DETECT_SUPERPINDA #define PINDA_MINTEMP BED_MINTEMP +#define AMBIENT_MINTEMP -30 // Maxtemps #if defined(E3D_PT100_EXTRUDER_WITH_AMP) || defined(E3D_PT100_EXTRUDER_NO_AMP) @@ -306,6 +307,7 @@ #define HEATER_1_MAXTEMP 305 #define HEATER_2_MAXTEMP 305 #define BED_MAXTEMP 125 +#define AMBIENT_MAXTEMP 100 #if defined(E3D_PT100_EXTRUDER_WITH_AMP) || defined(E3D_PT100_EXTRUDER_NO_AMP) // Define PID constants for extruder with PT100 diff --git a/Firmware/variants/1_75mm_MK3S-EINSy10a-E3Dv6full.h b/Firmware/variants/1_75mm_MK3S-EINSy10a-E3Dv6full.h index e618c54ef..c869ec517 100644 --- a/Firmware/variants/1_75mm_MK3S-EINSy10a-E3Dv6full.h +++ b/Firmware/variants/1_75mm_MK3S-EINSy10a-E3Dv6full.h @@ -298,6 +298,7 @@ #endif #define DETECT_SUPERPINDA #define PINDA_MINTEMP BED_MINTEMP +#define AMBIENT_MINTEMP -30 // Maxtemps #if defined(E3D_PT100_EXTRUDER_WITH_AMP) || defined(E3D_PT100_EXTRUDER_NO_AMP) @@ -308,6 +309,7 @@ #define HEATER_1_MAXTEMP 305 #define HEATER_2_MAXTEMP 305 #define BED_MAXTEMP 125 +#define AMBIENT_MAXTEMP 100 #if defined(E3D_PT100_EXTRUDER_WITH_AMP) || defined(E3D_PT100_EXTRUDER_NO_AMP) // Define PID constants for extruder with PT100