Changed min max temperature code.
This commit is contained in:
parent
6dba34ab0e
commit
2e43f9c809
2 changed files with 76 additions and 80 deletions
|
@ -80,7 +80,7 @@
|
||||||
// This feature exists to protect your hotend from overheating accidentally, but *NOT* from thermistor short/failure!
|
// This feature exists to protect your hotend from overheating accidentally, but *NOT* from thermistor short/failure!
|
||||||
// You should use MINTEMP for thermistor short/failure protection.
|
// You should use MINTEMP for thermistor short/failure protection.
|
||||||
#define HEATER_0_MAXTEMP 275
|
#define HEATER_0_MAXTEMP 275
|
||||||
//#define_HEATER_1_MAXTEMP 275
|
//#define HEATER_1_MAXTEMP 275
|
||||||
//#define BED_MAXTEMP 150
|
//#define BED_MAXTEMP 150
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -90,50 +90,12 @@ static unsigned long previous_millis_heater, previous_millis_bed_heater;
|
||||||
#endif //WATCHPERIOD
|
#endif //WATCHPERIOD
|
||||||
|
|
||||||
// Init min and max temp with extreme values to prevent false errors during startup
|
// Init min and max temp with extreme values to prevent false errors during startup
|
||||||
#ifdef HEATER_0_MINTEMP
|
|
||||||
#ifdef HEATER_0_USES_AD595
|
|
||||||
static int minttemp_0 = 0;
|
static int minttemp_0 = 0;
|
||||||
#else
|
|
||||||
static int minttemp_0 = 16383;
|
|
||||||
#endif
|
|
||||||
#endif //MINTEMP
|
|
||||||
#ifdef HEATER_0_MAXTEMP
|
|
||||||
#ifdef HEATER_0_USES_AD595
|
|
||||||
static int maxttemp_0 = 16383;
|
static int maxttemp_0 = 16383;
|
||||||
#else
|
|
||||||
static int maxttemp_0 = 0;
|
|
||||||
#endif
|
|
||||||
#endif //MAXTEMP
|
|
||||||
|
|
||||||
#ifdef HEATER_1_MINTEMP
|
|
||||||
#ifdef HEATER_1_USES_AD595
|
|
||||||
static int minttemp_1 = 0;
|
static int minttemp_1 = 0;
|
||||||
#else
|
|
||||||
static int minttemp_1 = 16383;
|
|
||||||
#endif
|
|
||||||
#endif //MINTEMP
|
|
||||||
#ifdef HEATER_1_MAXTEMP
|
|
||||||
#ifdef HEATER_1_USES_AD595
|
|
||||||
static int maxttemp_1 = 16383;
|
static int maxttemp_1 = 16383;
|
||||||
#else
|
|
||||||
static int maxttemp_1 = 0;
|
|
||||||
#endif
|
|
||||||
#endif //MAXTEMP
|
|
||||||
|
|
||||||
#ifdef BED_MINTEMP
|
|
||||||
#ifdef BED_USES_AD595
|
|
||||||
static int bed_minttemp = 0;
|
static int bed_minttemp = 0;
|
||||||
#else
|
|
||||||
static int bed_minttemp = 16383;
|
|
||||||
#endif
|
|
||||||
#endif //BED_MINTEMP
|
|
||||||
#ifdef BED_MAXTEMP
|
|
||||||
#ifdef BED_USES_AD595
|
|
||||||
static int bed_maxttemp = 16383;
|
static int bed_maxttemp = 16383;
|
||||||
#else
|
|
||||||
static int bed_maxttemp = 0;
|
|
||||||
#endif
|
|
||||||
#endif //BED_MAXTEMP
|
|
||||||
|
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
//=============================functions ============================
|
//=============================functions ============================
|
||||||
|
@ -198,18 +160,28 @@ void manage_heater()
|
||||||
//SERIAL_ECHOLN(" PIDDEBUG Input "<<pid_input<<" Output "<<pid_output" pTerm "<<pTerm<<" iTerm "<<iTerm<<" dTerm "<<dTerm);
|
//SERIAL_ECHOLN(" PIDDEBUG Input "<<pid_input<<" Output "<<pid_output" pTerm "<<pTerm<<" iTerm "<<iTerm<<" dTerm "<<dTerm);
|
||||||
#endif //PID_DEBUG
|
#endif //PID_DEBUG
|
||||||
HeaterPower=pid_output;
|
HeaterPower=pid_output;
|
||||||
|
// Check if temperature is within the correct range
|
||||||
|
if((current_raw[TEMPSENSOR_HOTEND_0] > minttemp_0) && (current_raw[TEMPSENSOR_HOTEND_0] < maxttemp_0)) {
|
||||||
analogWrite(HEATER_0_PIN, pid_output);
|
analogWrite(HEATER_0_PIN, pid_output);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
analogWrite(HEATER_0_PIN, 0);
|
||||||
|
}
|
||||||
#endif //PIDTEMP
|
#endif //PIDTEMP
|
||||||
|
|
||||||
#ifndef PIDTEMP
|
#ifndef PIDTEMP
|
||||||
if(current_raw[0] >= target_raw[0])
|
// Check if temperature is within the correct range
|
||||||
{
|
if((current_raw[TEMPSENSOR_HOTEND_0] > minttemp_0) && (current_raw[TEMPSENSOR_HOTEND_0] < maxttemp_0)) {
|
||||||
|
if(current_raw[TEMPSENSOR_HOTEND_0] >= target_raw[TEMPSENSOR_HOTEND_0]) {
|
||||||
WRITE(HEATER_0_PIN,LOW);
|
WRITE(HEATER_0_PIN,LOW);
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
WRITE(HEATER_0_PIN,HIGH);
|
WRITE(HEATER_0_PIN,HIGH);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
WRITE(HEATER_0_PIN,LOW);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(millis() - previous_millis_bed_heater < BED_CHECK_INTERVAL)
|
if(millis() - previous_millis_bed_heater < BED_CHECK_INTERVAL)
|
||||||
|
@ -217,6 +189,8 @@ void manage_heater()
|
||||||
previous_millis_bed_heater = millis();
|
previous_millis_bed_heater = millis();
|
||||||
|
|
||||||
#if TEMP_1_PIN > -1
|
#if TEMP_1_PIN > -1
|
||||||
|
// Check if temperature is within the correct range
|
||||||
|
if((current_raw[TEMPSENSOR_BED] > bed_minttemp) && (current_raw[TEMPSENSOR_BED] < bed_maxttemp)) {
|
||||||
if(current_raw[TEMPSENSOR_BED] >= target_raw[TEMPSENSOR_BED])
|
if(current_raw[TEMPSENSOR_BED] >= target_raw[TEMPSENSOR_BED])
|
||||||
{
|
{
|
||||||
WRITE(HEATER_1_PIN,LOW);
|
WRITE(HEATER_1_PIN,LOW);
|
||||||
|
@ -225,6 +199,10 @@ void manage_heater()
|
||||||
{
|
{
|
||||||
WRITE(HEATER_1_PIN,HIGH);
|
WRITE(HEATER_1_PIN,HIGH);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
WRITE(HEATER_1_PIN,LOW);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -370,6 +348,34 @@ void tp_init()
|
||||||
|
|
||||||
// Set analog inputs
|
// Set analog inputs
|
||||||
ADCSRA = 1<<ADEN | 1<<ADSC | 1<<ADIF | 0x07;
|
ADCSRA = 1<<ADEN | 1<<ADSC | 1<<ADIF | 0x07;
|
||||||
|
DIDR0 = 0;
|
||||||
|
#ifdef DIDR2
|
||||||
|
DIDR2 = 0;
|
||||||
|
#endif
|
||||||
|
#if (TEMP_0_PIN > -1)
|
||||||
|
#if TEMP_0_PIN < 8
|
||||||
|
DIDR0 |= 1 << TEMP_0_PIN;
|
||||||
|
#else
|
||||||
|
DIDR2 |= 1<<(TEMP_0_PIN - 8);
|
||||||
|
ADCSRB = 1<<MUX5;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
#if (TEMP_1_PIN > -1)
|
||||||
|
#if TEMP_1_PIN < 8
|
||||||
|
DIDR0 |= 1<<TEMP_1_PIN;
|
||||||
|
#else
|
||||||
|
DIDR2 |= 1<<(TEMP_1_PIN - 8);
|
||||||
|
ADCSRB = 1<<MUX5;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
#if (TEMP_2_PIN > -1)
|
||||||
|
#if TEMP_2_PIN < 8
|
||||||
|
DIDR0 |= 1 << TEMP_2_PIN;
|
||||||
|
#else
|
||||||
|
DIDR2 = 1<<(TEMP_2_PIN - 8);
|
||||||
|
ADCSRB = 1<<MUX5;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
// Use timer0 for temperature measurement
|
// Use timer0 for temperature measurement
|
||||||
// Interleave temperature interrupt with millies interrupt
|
// Interleave temperature interrupt with millies interrupt
|
||||||
|
@ -456,10 +462,7 @@ ISR(TIMER0_COMPB_vect)
|
||||||
switch(temp_state) {
|
switch(temp_state) {
|
||||||
case 0: // Prepare TEMP_0
|
case 0: // Prepare TEMP_0
|
||||||
#if (TEMP_0_PIN > -1)
|
#if (TEMP_0_PIN > -1)
|
||||||
#if TEMP_0_PIN < 8
|
#if TEMP_0_PIN > 7
|
||||||
DIDR0 = 1 << TEMP_0_PIN;
|
|
||||||
#else
|
|
||||||
DIDR2 = 1<<(TEMP_0_PIN - 8);
|
|
||||||
ADCSRB = 1<<MUX5;
|
ADCSRB = 1<<MUX5;
|
||||||
#endif
|
#endif
|
||||||
ADMUX = ((1 << REFS0) | (TEMP_0_PIN & 0x07));
|
ADMUX = ((1 << REFS0) | (TEMP_0_PIN & 0x07));
|
||||||
|
@ -478,10 +481,7 @@ ISR(TIMER0_COMPB_vect)
|
||||||
break;
|
break;
|
||||||
case 2: // Prepare TEMP_1
|
case 2: // Prepare TEMP_1
|
||||||
#if (TEMP_1_PIN > -1)
|
#if (TEMP_1_PIN > -1)
|
||||||
#if TEMP_1_PIN < 7
|
#if TEMP_1_PIN > 7
|
||||||
DIDR0 = 1<<TEMP_1_PIN;
|
|
||||||
#else
|
|
||||||
DIDR2 = 1<<(TEMP_1_PIN - 8);
|
|
||||||
ADCSRB = 1<<MUX5;
|
ADCSRB = 1<<MUX5;
|
||||||
#endif
|
#endif
|
||||||
ADMUX = ((1 << REFS0) | (TEMP_1_PIN & 0x07));
|
ADMUX = ((1 << REFS0) | (TEMP_1_PIN & 0x07));
|
||||||
|
@ -500,10 +500,7 @@ ISR(TIMER0_COMPB_vect)
|
||||||
break;
|
break;
|
||||||
case 4: // Prepare TEMP_2
|
case 4: // Prepare TEMP_2
|
||||||
#if (TEMP_2_PIN > -1)
|
#if (TEMP_2_PIN > -1)
|
||||||
#if TEMP_2_PIN < 7
|
#if TEMP_2_PIN > 7
|
||||||
DIDR0 = 1 << TEMP_2_PIN;
|
|
||||||
#else
|
|
||||||
DIDR2 = 1<<(TEMP_2_PIN - 8);
|
|
||||||
ADCSRB = 1<<MUX5;
|
ADCSRB = 1<<MUX5;
|
||||||
#endif
|
#endif
|
||||||
ADMUX = ((1 << REFS0) | (TEMP_2_PIN & 0x07));
|
ADMUX = ((1 << REFS0) | (TEMP_2_PIN & 0x07));
|
||||||
|
@ -556,7 +553,7 @@ ISR(TIMER0_COMPB_vect)
|
||||||
#if (HEATER_0_PIN > -1)
|
#if (HEATER_0_PIN > -1)
|
||||||
if(current_raw[TEMPSENSOR_HOTEND_0] >= maxttemp_0) {
|
if(current_raw[TEMPSENSOR_HOTEND_0] >= maxttemp_0) {
|
||||||
target_raw[TEMPSENSOR_HOTEND_0] = 0;
|
target_raw[TEMPSENSOR_HOTEND_0] = 0;
|
||||||
analogWrite(HEATER_0_PIN, 0);
|
digitalWrite(HEATER_0_PIN, 0);
|
||||||
SERIAL_ERROR_START;
|
SERIAL_ERROR_START;
|
||||||
SERIAL_ERRORLNPGM("Temperature extruder 0 switched off. MAXTEMP triggered !!");
|
SERIAL_ERRORLNPGM("Temperature extruder 0 switched off. MAXTEMP triggered !!");
|
||||||
kill();
|
kill();
|
||||||
|
@ -567,11 +564,10 @@ ISR(TIMER0_COMPB_vect)
|
||||||
#if (HEATER_1_PIN > -1)
|
#if (HEATER_1_PIN > -1)
|
||||||
if(current_raw[TEMPSENSOR_HOTEND_1] >= maxttemp_1) {
|
if(current_raw[TEMPSENSOR_HOTEND_1] >= maxttemp_1) {
|
||||||
target_raw[TEMPSENSOR_HOTEND_1] = 0;
|
target_raw[TEMPSENSOR_HOTEND_1] = 0;
|
||||||
if(current_raw[2] >= maxttemp_1) {
|
digitalWrite(HEATER_2_PIN, 0);
|
||||||
analogWrite(HEATER_2_PIN, 0);
|
|
||||||
SERIAL_ERROR_START;
|
SERIAL_ERROR_START;
|
||||||
SERIAL_ERRORLNPGM("Temperature extruder 1 switched off. MAXTEMP triggered !!");
|
SERIAL_ERRORLNPGM("Temperature extruder 1 switched off. MAXTEMP triggered !!");
|
||||||
kill()
|
kill();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif //MAXTEMP
|
#endif //MAXTEMP
|
||||||
|
@ -580,7 +576,7 @@ ISR(TIMER0_COMPB_vect)
|
||||||
#if (HEATER_0_PIN > -1)
|
#if (HEATER_0_PIN > -1)
|
||||||
if(current_raw[TEMPSENSOR_HOTEND_0] <= minttemp_0) {
|
if(current_raw[TEMPSENSOR_HOTEND_0] <= minttemp_0) {
|
||||||
target_raw[TEMPSENSOR_HOTEND_0] = 0;
|
target_raw[TEMPSENSOR_HOTEND_0] = 0;
|
||||||
analogWrite(HEATER_0_PIN, 0);
|
digitalWrite(HEATER_0_PIN, 0);
|
||||||
SERIAL_ERROR_START;
|
SERIAL_ERROR_START;
|
||||||
SERIAL_ERRORLNPGM("Temperature extruder 0 switched off. MINTEMP triggered !!");
|
SERIAL_ERRORLNPGM("Temperature extruder 0 switched off. MINTEMP triggered !!");
|
||||||
kill();
|
kill();
|
||||||
|
@ -592,7 +588,7 @@ ISR(TIMER0_COMPB_vect)
|
||||||
#if (HEATER_2_PIN > -1)
|
#if (HEATER_2_PIN > -1)
|
||||||
if(current_raw[TEMPSENSOR_HOTEND_1] <= minttemp_1) {
|
if(current_raw[TEMPSENSOR_HOTEND_1] <= minttemp_1) {
|
||||||
target_raw[TEMPSENSOR_HOTEND_1] = 0;
|
target_raw[TEMPSENSOR_HOTEND_1] = 0;
|
||||||
analogWrite(HEATER_2_PIN, 0);
|
digitalWrite(HEATER_2_PIN, 0);
|
||||||
SERIAL_ERROR_START;
|
SERIAL_ERROR_START;
|
||||||
SERIAL_ERRORLNPGM("Temperature extruder 1 switched off. MINTEMP triggered !!");
|
SERIAL_ERRORLNPGM("Temperature extruder 1 switched off. MINTEMP triggered !!");
|
||||||
kill();
|
kill();
|
||||||
|
@ -604,7 +600,7 @@ ISR(TIMER0_COMPB_vect)
|
||||||
#if (HEATER_1_PIN > -1)
|
#if (HEATER_1_PIN > -1)
|
||||||
if(current_raw[1] <= bed_minttemp) {
|
if(current_raw[1] <= bed_minttemp) {
|
||||||
target_raw[1] = 0;
|
target_raw[1] = 0;
|
||||||
WRITE(HEATER_1_PIN, 0);
|
digitalWrite(HEATER_1_PIN, 0);
|
||||||
SERIAL_ERROR_START;
|
SERIAL_ERROR_START;
|
||||||
SERIAL_ERRORLNPGM("Temperatur heated bed switched off. MINTEMP triggered !!");
|
SERIAL_ERRORLNPGM("Temperatur heated bed switched off. MINTEMP triggered !!");
|
||||||
kill();
|
kill();
|
||||||
|
@ -616,7 +612,7 @@ ISR(TIMER0_COMPB_vect)
|
||||||
#if (HEATER_1_PIN > -1)
|
#if (HEATER_1_PIN > -1)
|
||||||
if(current_raw[1] >= bed_maxttemp) {
|
if(current_raw[1] >= bed_maxttemp) {
|
||||||
target_raw[1] = 0;
|
target_raw[1] = 0;
|
||||||
WRITE(HEATER_1_PIN, 0);
|
digitalWrite(HEATER_1_PIN, 0);
|
||||||
SERIAL_ERROR_START;
|
SERIAL_ERROR_START;
|
||||||
SERIAL_ERRORLNPGM("Temperature heated bed switched off. MAXTEMP triggered !!");
|
SERIAL_ERRORLNPGM("Temperature heated bed switched off. MAXTEMP triggered !!");
|
||||||
kill();
|
kill();
|
||||||
|
|
Reference in a new issue