Implement automatic extruder/cold-end fan control based on temperature
This change allows fan outputs to automatically turn on/off when the associated nozzle temperature of an extruder is above/below a threshold temperature. Multiple extruders can be assigned to the same pin in which case the fan will turn on when any selected extruder is above the threshold. It also makes the M42 command compatible with the M106/M107 command. The majority of the logic in this change will be evaluated by the compiler at build time (i.e, low code space requirements).
This commit is contained in:
@ -71,6 +71,16 @@
|
||||
// before setting a PWM value. (Does not work with software PWM for fan on Sanguinololu)
|
||||
//#define FAN_KICKSTART_TIME 100
|
||||
|
||||
// Configure fan pin outputs to automatically turn on/off when the associated
|
||||
// extruder temperature is above/below EXTRUDER_AUTO_FAN_TEMPERATURE.
|
||||
// Multiple extruders can be assigned to the same pin in which case
|
||||
// the fan will turn on when any selected extruder is above the threshold.
|
||||
#define EXTRUDER_0_AUTO_FAN_PIN -1
|
||||
#define EXTRUDER_1_AUTO_FAN_PIN -1
|
||||
#define EXTRUDER_2_AUTO_FAN_PIN -1
|
||||
#define EXTRUDER_AUTO_FAN_TEMPERATURE 50
|
||||
#define EXTRUDER_AUTO_FAN_SPEED 255 // == full speed
|
||||
|
||||
//===========================================================================
|
||||
//=============================Mechanical Settings===========================
|
||||
//===========================================================================
|
||||
@ -210,9 +220,9 @@
|
||||
// However, THIS FEATURE IS UNSAFE!, as it will only work if interrupts are disabled. And the code could hang in an interrupt routine with interrupts disabled.
|
||||
//#define WATCHDOG_RESET_MANUAL
|
||||
#endif
|
||||
|
||||
// Enable the option to stop SD printing when hitting and endstops, needs to be enabled from the LCD menu when this option is enabled.
|
||||
//#define ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED
|
||||
|
||||
// Enable the option to stop SD printing when hitting and endstops, needs to be enabled from the LCD menu when this option is enabled.
|
||||
//#define ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED
|
||||
|
||||
// extruder advance constant (s2/mm3)
|
||||
//
|
||||
@ -276,7 +286,7 @@ const unsigned int dropsegments=5; //everything with less than this number of st
|
||||
#else
|
||||
#define BLOCK_BUFFER_SIZE 16 // maximize block buffer
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
//The ASCII buffer for recieving from the serial:
|
||||
#define MAX_CMD_SIZE 96
|
||||
|
@ -157,12 +157,12 @@ float add_homeing[3]={0,0,0};
|
||||
float min_pos[3] = { X_MIN_POS, Y_MIN_POS, Z_MIN_POS };
|
||||
float max_pos[3] = { X_MAX_POS, Y_MAX_POS, Z_MAX_POS };
|
||||
// Extruder offset, only in XY plane
|
||||
#if EXTRUDERS > 1
|
||||
#if EXTRUDERS > 1
|
||||
float extruder_offset[2][EXTRUDERS] = {
|
||||
#if defined(EXTRUDER_OFFSET_X) && defined(EXTRUDER_OFFSET_Y)
|
||||
EXTRUDER_OFFSET_X, EXTRUDER_OFFSET_Y
|
||||
#endif
|
||||
};
|
||||
};
|
||||
#endif
|
||||
uint8_t active_extruder = 0;
|
||||
int fanSpeed=0;
|
||||
@ -982,6 +982,10 @@ void process_commands()
|
||||
break;
|
||||
}
|
||||
}
|
||||
#if FAN_PIN > -1
|
||||
if (pin_number == FAN_PIN)
|
||||
fanSpeed = pin_status;
|
||||
#endif
|
||||
if (pin_number > -1)
|
||||
{
|
||||
pinMode(pin_number, OUTPUT);
|
||||
@ -1380,7 +1384,7 @@ void process_commands()
|
||||
}
|
||||
|
||||
}break;
|
||||
#endif // FWRETRACT
|
||||
#endif // FWRETRACT
|
||||
#if EXTRUDERS > 1
|
||||
case 218: // M218 - set hotend offset (in mm), T<extruder_number> X<offset_on_X> Y<offset_on_Y>
|
||||
{
|
||||
@ -1405,7 +1409,7 @@ void process_commands()
|
||||
SERIAL_ECHO(extruder_offset[Y_AXIS][tmp_extruder]);
|
||||
}
|
||||
SERIAL_ECHOLN("");
|
||||
}break;
|
||||
}break;
|
||||
#endif
|
||||
case 220: // M220 S<factor in percent>- set speed factor override percentage
|
||||
{
|
||||
@ -1756,7 +1760,7 @@ void process_commands()
|
||||
if(make_move && Stopped == false) {
|
||||
prepare_move();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
SERIAL_ECHO_START;
|
||||
SERIAL_ECHO(MSG_ACTIVE_EXTRUDER);
|
||||
|
@ -99,8 +99,9 @@ static volatile bool temp_meas_ready = false;
|
||||
#ifdef FAN_SOFT_PWM
|
||||
static unsigned char soft_pwm_fan;
|
||||
#endif
|
||||
|
||||
|
||||
#if EXTRUDER_0_AUTO_FAN_PIN > -1 || EXTRUDER_1_AUTO_FAN_PIN > -1 || EXTRUDER_2_AUTO_FAN_PIN > -1
|
||||
static uint8_t extruderAutoFanState = 0; // extruder auto fan state stored as bitmap
|
||||
#endif
|
||||
|
||||
#if EXTRUDERS > 3
|
||||
# error Unsupported number of extruders
|
||||
@ -399,6 +400,55 @@ void manage_heater()
|
||||
|
||||
} // End extruder for loop
|
||||
|
||||
#if EXTRUDER_0_AUTO_FAN_PIN > -1
|
||||
// check the extruder 0 setting (and any ganged auto fan outputs)
|
||||
bool newFanState = (EXTRUDER_0_AUTO_FAN_PIN > -1 &&
|
||||
(current_temperature[0] > EXTRUDER_AUTO_FAN_TEMPERATURE ||
|
||||
(EXTRUDER_0_AUTO_FAN_PIN == EXTRUDER_1_AUTO_FAN_PIN && current_temperature[1] > EXTRUDER_AUTO_FAN_TEMPERATURE) ||
|
||||
(EXTRUDER_0_AUTO_FAN_PIN == EXTRUDER_2_AUTO_FAN_PIN && current_temperature[2] > EXTRUDER_AUTO_FAN_TEMPERATURE)));
|
||||
if ((extruderAutoFanState & 1) != newFanState) // store state in first bit
|
||||
{
|
||||
int newFanSpeed = (newFanState ? EXTRUDER_AUTO_FAN_SPEED : 0);
|
||||
if (EXTRUDER_0_AUTO_FAN_PIN == FAN_PIN)
|
||||
fanSpeed = newFanSpeed;
|
||||
pinMode(EXTRUDER_0_AUTO_FAN_PIN, OUTPUT);
|
||||
digitalWrite(EXTRUDER_0_AUTO_FAN_PIN, newFanSpeed);
|
||||
analogWrite(EXTRUDER_0_AUTO_FAN_PIN, newFanSpeed);
|
||||
extruderAutoFanState = newFanState | (extruderAutoFanState & ~1);
|
||||
}
|
||||
#endif //EXTRUDER_0_AUTO_FAN_PIN > -1
|
||||
#if EXTRUDER_1_AUTO_FAN_PIN > -1
|
||||
// check the extruder 1 setting (except when extruder 1 is the same as 0)
|
||||
newFanState = (EXTRUDER_1_AUTO_FAN_PIN > -1 && EXTRUDER_1_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN &&
|
||||
(current_temperature[1] > EXTRUDER_AUTO_FAN_TEMPERATURE ||
|
||||
(EXTRUDER_1_AUTO_FAN_PIN == EXTRUDER_2_AUTO_FAN_PIN && current_temperature[2] > EXTRUDER_AUTO_FAN_TEMPERATURE)));
|
||||
if ((extruderAutoFanState & 2) != (newFanState<<1)) // use second bit
|
||||
{
|
||||
int newFanSpeed = (newFanState ? EXTRUDER_AUTO_FAN_SPEED : 0);
|
||||
if (EXTRUDER_1_AUTO_FAN_PIN == FAN_PIN)
|
||||
fanSpeed = newFanSpeed;
|
||||
pinMode(EXTRUDER_1_AUTO_FAN_PIN, OUTPUT);
|
||||
digitalWrite(EXTRUDER_1_AUTO_FAN_PIN, newFanSpeed);
|
||||
analogWrite(EXTRUDER_1_AUTO_FAN_PIN, newFanSpeed);
|
||||
extruderAutoFanState = (newFanState<<1) | (extruderAutoFanState & ~2);
|
||||
}
|
||||
#endif //EXTRUDER_1_AUTO_FAN_PIN > -1
|
||||
#if EXTRUDER_2_AUTO_FAN_PIN > -1
|
||||
// check the extruder 2 setting (except when extruder 2 is the same as 1 or 0)
|
||||
newFanState = (EXTRUDER_2_AUTO_FAN_PIN > -1 &&
|
||||
EXTRUDER_2_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN && EXTRUDER_2_AUTO_FAN_PIN != EXTRUDER_1_AUTO_FAN_PIN &&
|
||||
current_temperature[2] > EXTRUDER_AUTO_FAN_TEMPERATURE);
|
||||
if ((extruderAutoFanState & 4) != (newFanState<<2)) // use third bit
|
||||
{
|
||||
int newFanSpeed = (newFanState ? EXTRUDER_AUTO_FAN_SPEED : 0);
|
||||
if (EXTRUDER_2_AUTO_FAN_PIN == FAN_PIN)
|
||||
fanSpeed = newFanSpeed;
|
||||
pinMode(EXTRUDER_2_AUTO_FAN_PIN, OUTPUT);
|
||||
digitalWrite(EXTRUDER_2_AUTO_FAN_PIN, newFanSpeed);
|
||||
analogWrite(EXTRUDER_2_AUTO_FAN_PIN, newFanSpeed);
|
||||
extruderAutoFanState = (newFanState<<2) | (extruderAutoFanState & ~4);
|
||||
}
|
||||
#endif //EXTRUDER_2_AUTO_FAN_PIN > -1
|
||||
|
||||
#ifndef PIDTEMPBED
|
||||
if(millis() - previous_millis_bed_heater < BED_CHECK_INTERVAL)
|
||||
|
Reference in New Issue
Block a user