Continue to add code for cooler

parent 832050e2
......@@ -18,12 +18,12 @@
/// #define HIGH_TO_FIRE
// Uncomment the following to enable the use of the PWM (the one for the extruder 0) to drive a peltier cell or any PWM driven cooler for the laser
#define LASER_WATER_COOLING
#define LASER_WATER_MAXTEMP 25
#define COOLER
#define COOLER_MAXTEMP 25
// Uncomment the following to enable LASER_WATER_COOLING PWM instead of bang-bang
#define LASER_PWM
#define LASER_PWM_FREQUENCY 1000 // Frequency in Hz
// Uncomment the following to enable COOLER PWM instead of bang-bang
#define COOLER_PWM
#define COOLER_PWM_FREQUENCY 1000 // Frequency in Hz
//// The following defines select which G codes tell the laser to fire. It's OK to uncomment more than one.
#define LASER_FIRE_G1 10 // fire the laser on a G1 move, extinguish when the move ends
......@@ -37,7 +37,7 @@
#define LASER_RASTER_MM_PER_PULSE 0.2 //Can be overridden by providing an R value in M649 command : M649 S17 B2 D0 R0.1 F4000
//// Uncomment the following if the laser cutter is equipped with a peripheral relay board
//// to control power to an exhaust fan, water pump, laser power supply, etc.
//// to control power to an exhaust fan, cooler pump, laser power supply, etc.
//#define LASER_PERIPHERALS
//#define LASER_PERIPHERALS_TIMEOUT 30000 // Number of milliseconds to wait for status signal from peripheral control board
......@@ -68,12 +68,12 @@
/***********************************************************************
************************ PID Settings - WATER ***************************
************************ PID Settings - COOLER ************************
***********************************************************************
* *
* PID Tuning Guide here: http://reprap.org/wiki/PID_Tuning *
* Select PID or bang-bang with PIDTEMPWATER. *
* If bang-bang, WATER_LIMIT_SWITCHING will enable hysteresis *
* Select PID or bang-bang with PIDTEMPCOOLER. *
* If bang-bang, COOLER_LIMIT_SWITCHING will enable hysteresis *
* *
***********************************************************************/
// Uncomment this to enable PID on the bed. It uses the same frequency PWM as the extruder.
......@@ -83,28 +83,28 @@
// If your configuration is significantly different than this and you don't understand the issues involved, you probably
// shouldn't use bed PID until someone else verifies your hardware works.
// If this is enabled, find your own PID constants below.
#define PIDTEMPWATER
#define PIDTEMPCOOLER
//#define WATER_LIMIT_SWITCHING
#define WATER_HYSTERESIS 2 //only disable heating if T<target-WATER_HYSTERESIS and enable heating if T<target+WATER_HYSTERESIS (works only if WATER_LIMIT_SWITCHING is enabled)
#define WATER_CHECK_INTERVAL 5000 //ms between checks in bang-bang control
//#define COOLER_LIMIT_SWITCHING
#define COOLER_HYSTERESIS 2 //only disable heating if T<target-COOLER_HYSTERESIS and enable heating if T<target+COOLER_HYSTERESIS (works only if COOLER_LIMIT_SWITCHING is enabled)
#define COOLER_CHECK_INTERVAL 5000 //ms between checks in bang-bang control
// This sets the max power delivered to the bed.
// all forms of bed control obey this (PID, bang-bang, bang-bang with hysteresis)
// setting this to anything other than 255 enables a form of PWM to the bed,
// so you shouldn't use it unless you are OK with PWM on your bed. (see the comment on enabling PIDTEMPWATER)
#define MAX_WATER_POWER 255 // limits duty cycle to bed; 255=full current
// so you shouldn't use it unless you are OK with PWM on your bed. (see the comment on enabling PIDTEMPCOOLER)
#define MAX_COOLER_POWER 255 // limits duty cycle to bed; 255=full current
#define PID_WATER_INTEGRAL_DRIVE_MAX MAX_WATER_POWER // limit for the integral term
#define PID_COOLER_INTEGRAL_DRIVE_MAX MAX_COOLER_POWER // limit for the integral term
// 120v 250W silicone heater into 4mm borosilicate (MendelMax 1.5+)
// from FOPDT model - kp=.39 Tp=405 Tdead=66, Tc set to 79.2, aggressive factor of .15 (vs .1, 1, 10)
#define DEFAULT_waterKp 10.00
#define DEFAULT_waterKi .023
#define DEFAULT_waterKd 305.4
#define DEFAULT_coolerKp 10.00
#define DEFAULT_coolerKi .023
#define DEFAULT_coolerKd 305.4
// FIND YOUR OWN: "M303 E-1 C8 S90" to run autotune on the bed at 90 degreesC for 8 cycles.
//#define PID_WATER_DEBUG // Sends debug data to the serial port.
//#define PID_COOLER_DEBUG // Sends debug data to the serial port.
/***********************************************************************/
......
......@@ -121,9 +121,9 @@
#define LASER_PERIPHERALS_PIN 11
#define LASER_PERIPHERALS_STATUS_PIN 4
#endif // LASER_PERIPHERALS
#if ENABLED(LASER_WATER_COOLING)
#define LASER_WATER_COOLING_PIN 2 // Digital pins 2, 3, 5, 6, 7, 8 are attached to timers we can use
#endif // LASER WATER_COOLING
#if ENABLED(COOLER)
#define COOLER_PIN 2 // Digital pins 2, 3, 5, 6, 7, 8 are attached to timers we can use
#endif // COOLER
#endif
......
......@@ -73,7 +73,7 @@
*
* PIDTEMPBED:
* M304 PID bedKp, bedKi, bedKd
* M304 L PID waterKp, waterKi, waterKd
* M304 L PID coolerKp, coolerKi, coolerKd
*
* DOGLCD:
* M250 C lcd_contrast
......@@ -211,10 +211,10 @@ void Config_StoreSettings() {
EEPROM_WRITE_VAR(i, bedKd);
#endif
#if ENABLED(PIDTEMPWATER)
EEPROM_WRITE_VAR(i, waterKp);
EEPROM_WRITE_VAR(i, waterKi);
EEPROM_WRITE_VAR(i, waterKd);
#if ENABLED(PIDTEMPCOOLER)
EEPROM_WRITE_VAR(i, coolerKp);
EEPROM_WRITE_VAR(i, coolerKi);
EEPROM_WRITE_VAR(i, coolerKd);
#endif
#if HASNT(LCD_CONTRAST)
......@@ -366,10 +366,10 @@ void Config_RetrieveSettings() {
EEPROM_READ_VAR(i, bedKd);
#endif
#if ENABLED(PIDTEMPWATER)
EEPROM_READ_VAR(i, waterKp);
EEPROM_READ_VAR(i, waterKi);
EEPROM_READ_VAR(i, waterKd);
#if ENABLED(PIDTEMPCOOLER)
EEPROM_READ_VAR(i, coolerKp);
EEPROM_READ_VAR(i, coolerKi);
EEPROM_READ_VAR(i, coolerKd);
#endif
......@@ -598,10 +598,10 @@ void Config_ResetDefault() {
bedKd = scalePID_d(DEFAULT_bedKd);
#endif
#if ENABLED(PIDTEMPWATER)
waterKp = DEFAULT_waterKp;
waterKi = scalePID_i(DEFAULT_waterKi);
waterKd = scalePID_d(DEFAULT_waterKd);
#if ENABLED(PIDTEMPCOOLER)
coolerKp = DEFAULT_coolerKp;
coolerKi = scalePID_i(DEFAULT_coolerKi);
coolerKd = scalePID_d(DEFAULT_coolerKd);
#endif
......@@ -807,7 +807,7 @@ void Config_ResetDefault() {
ECHO_EM(" (Material GUM)");
#endif // ULTIPANEL
#if ENABLED(PIDTEMP) || ENABLED(PIDTEMPBED) || ENABLED(PIDTEMPWATER)
#if ENABLED(PIDTEMP) || ENABLED(PIDTEMPBED) || ENABLED(PIDTEMPCOOLER)
if (!forReplay) {
ECHO_LM(CFG, "PID settings:");
}
......@@ -831,10 +831,10 @@ void Config_ResetDefault() {
ECHO_MV(" I", unscalePID_i(bedKi));
ECHO_EMV(" D", unscalePID_d(bedKd));
#endif
#if ENABLED(PIDTEMPWATER)
ECHO_SMV(CFG, " M304 L P", waterKp); // for compatibility with hosts, only echos values for E0
ECHO_MV(" I", unscalePID_i(waterKi));
ECHO_EMV(" D", unscalePID_d(waterKd));
#if ENABLED(PIDTEMPCOOLER)
ECHO_SMV(CFG, " M304 L P", coolerKp); // for compatibility with hosts, only echos values for E0
ECHO_MV(" I", unscalePID_i(coolerKi));
ECHO_EMV(" D", unscalePID_d(coolerKd));
#endif
#endif
......
......@@ -149,7 +149,7 @@
* M301 - Set PID parameters P I D and C
* M302 - Allow cold extrudes, or set the minimum extrude S<temperature>.
* M303 - PID relay autotune S<temperature> sets the target temperature (default target temperature = 150C). H<hotend> C<cycles> U<Apply result>
* M304 - Set bed PID parameters P I and D or Water cooling if L parameter
* M304 - Set bed PID parameters P I and D or cooling if L parameter
* M350 - Set microstepping mode.
* M351 - Toggle MS1 MS2 pins directly.
* M380 - Activate solenoid on active extruder
......
......@@ -6479,11 +6479,11 @@ inline void gcode_M226() {
}
#endif // PREVENT_DANGEROUS_EXTRUDE
#if HAS(PID_HEATING)
#if HAS(PID_HEATING) || HAS(PID_COOLING)
/**
* M303: PID relay autotune
* S<temperature> sets the target temperature. (default target temperature = 150C)
* H<hotend> (-1 for the bed) (default 0)
* H<hotend> (-1 for the bed, -2 for cooler) (default 0)
* C<cycles>
* U<bool> with a non-zero value will apply the result to current settings
*/
......@@ -6504,23 +6504,23 @@ inline void gcode_M226() {
}
#endif
#if ENABLED(PIDTEMPBED) || ENABLED(PIDTEMPWATER)
#if ENABLED(PIDTEMPBED) || ENABLED(PIDTEMPCOOLER)
// M304: Set bed PID parameters P I and D
inline void gcode_M304() {
#if ENABLED(PIDTEMPWATER)
#if ENABLED(PIDTEMPCOOLER)
if (code_seen('L')) {
if (code_seen('P')) waterKp = code_value();
if (code_seen('I')) waterKi = scalePID_i(code_value());
if (code_seen('D')) waterKd = scalePID_d(code_value());
if (code_seen('P')) coolerKp = code_value();
if (code_seen('I')) coolerKi = scalePID_i(code_value());
if (code_seen('D')) coolerKd = scalePID_d(code_value());
updatePID();
ECHO_SMV(OK, " L p:", waterKp);
ECHO_MV(" i:", unscalePID_i(waterKi));
ECHO_EMV(" d:", unscalePID_d(waterKd));
ECHO_SMV(OK, " L p:", coolerKp);
ECHO_MV(" i:", unscalePID_i(coolerKi));
ECHO_EMV(" d:", unscalePID_d(coolerKd));
}
#endif
#if ENABLED(PIDTEMPWATER) && ENABLED(PIDTEMPBED)
#if ENABLED(PIDTEMPCOOLER) && ENABLED(PIDTEMPBED)
else {
#endif
if (code_seen('P')) bedKp = code_value();
......@@ -6531,11 +6531,11 @@ inline void gcode_M226() {
ECHO_SMV(OK, "p:", bedKp);
ECHO_MV(" i:", unscalePID_i(bedKi));
ECHO_EMV(" d:", unscalePID_d(bedKd));
#if ENABLED(PIDTEMPWATER) && ENABLED(PIDTEMPBED)
#if ENABLED(PIDTEMPCOOLER) && ENABLED(PIDTEMPBED)
}
#endif
}
#endif // PIDTEMPBED || PIDTEMPWATER
#endif // PIDTEMPBED || PIDTEMPCOOLER
#if HAS(MICROSTEPS)
// M350 Set microstepping mode. Warning: Steps per unit remains unchanged. S code sets stepping mode for all drivers.
......@@ -8318,7 +8318,7 @@ void process_next_command() {
gcode_M303(); break;
#endif
#if ENABLED(PIDTEMPBED) || ENABLED(PIDTEMPWATER)
#if ENABLED(PIDTEMPBED) || ENABLED(PIDTEMPCOOLER)
case 304: // M304
gcode_M304(); break;
#endif // PIDTEMPBED
......@@ -9336,7 +9336,7 @@ void kill(const char* lcd_msg) {
}
#endif
#if ENABLED(FAST_PWM_FAN) || ENABLED(LASER_WATER_COOLING)
#if ENABLED(FAST_PWM_FAN) || ENABLED(LASER_COOLER_COOLING)
void setPwmFrequency(uint8_t pin, int val) {
val &= 0x07;
......
......@@ -117,7 +117,7 @@ void refresh_cmd_timeout();
extern void delay_ms(millis_t ms);
#if ENABLED(FAST_PWM_FAN) || ENABLED(LASER_WATER_COOLING)
#if ENABLED(FAST_PWM_FAN) || ENABLED(COOLER_PWM)
void setPwmFrequency(uint8_t pin, int val);
#endif
......
......@@ -597,6 +597,7 @@
* Flags for PID handling
*/
#define HAS_PID_HEATING (ENABLED(PIDTEMP) || ENABLED(PIDTEMPBED))
#define HAS_PID_HEATING (ENABLED(PIDTEMPCOOLER))
#define HAS_PID_FOR_BOTH (ENABLED(PIDTEMP) && ENABLED(PIDTEMPBED))
/**
......@@ -647,11 +648,13 @@
#define HAS_TEMP_2 (PIN_EXISTS(TEMP_2) && TEMP_SENSOR_2 != 0)
#define HAS_TEMP_3 (PIN_EXISTS(TEMP_3) && TEMP_SENSOR_3 != 0)
#define HAS_TEMP_BED (PIN_EXISTS(TEMP_BED) && TEMP_SENSOR_BED != 0)
#define HAS_TEMP_COOLER (PIN_EXISTS(TEMP_COOLER) && TEMP_SENSOR_COOLER != 0)
#define HAS_HEATER_0 (PIN_EXISTS(HEATER_0))
#define HAS_HEATER_1 (PIN_EXISTS(HEATER_1))
#define HAS_HEATER_2 (PIN_EXISTS(HEATER_2))
#define HAS_HEATER_3 (PIN_EXISTS(HEATER_3))
#define HAS_HEATER_BED (PIN_EXISTS(HEATER_BED))
#define HAS_COOLER (PIN_EXISTS(COOLER))
#define HAS_AUTO_FAN_0 (ENABLED(EXTRUDER_AUTO_FAN) && PIN_EXISTS(EXTRUDER_0_AUTO_FAN))
#define HAS_AUTO_FAN_1 (ENABLED(EXTRUDER_AUTO_FAN) && PIN_EXISTS(EXTRUDER_1_AUTO_FAN))
#define HAS_AUTO_FAN_2 (ENABLED(EXTRUDER_AUTO_FAN) && PIN_EXISTS(EXTRUDER_2_AUTO_FAN))
......
......@@ -191,8 +191,9 @@
#define SERIAL_PID_AUTOTUNE "PID Autotune"
#define SERIAL_PID_AUTOTUNE_START SERIAL_PID_AUTOTUNE " start"
#define SERIAL_PID_AUTOTUNE_FAILED SERIAL_PID_AUTOTUNE " failed!"
#define SERIAL_PID_BAD_EXTRUDER_NUM SERIAL_PID_AUTOTUNE_FAILED " Bad extruder number"
#define SERIAL_PID_BAD_TEMP_CONTROLLER_NUM SERIAL_PID_AUTOTUNE_FAILED " Bad temperature controller number"
#define SERIAL_PID_TEMP_TOO_HIGH SERIAL_PID_AUTOTUNE_FAILED " Temperature too high"
#define SERIAL_PID_TEMP_TOO_LOW SERIAL_PID_AUTOTUNE_FAILED " Temperature too low"
#define SERIAL_PID_TIMEOUT SERIAL_PID_AUTOTUNE_FAILED " timeout"
#define SERIAL_BIAS " bias: "
#define SERIAL_D " d: "
......@@ -221,6 +222,7 @@
#define SERIAL_HEATER_BED "bed"
#define SERIAL_STOPPED_HEATER ", system stopped! Heater_ID: "
#define SERIAL_STOPPED_COOLER "system stopped! Cooler"
//#define SERIAL_REDUNDANCY "Heater switched off. Temperature difference between temp sensors is too high !"
#define SERIAL_T_HEATING_FAILED "Heating failed"
#define SERIAL_T_THERMAL_RUNAWAY "Thermal Runaway"
......
......@@ -223,18 +223,18 @@
#error DEPENDENCY ERROR: Missing setting DEFAULT_bedKd
#endif
#endif
#if ENABLED(PIDTEMPWATER)
#if DISABLED(PID_WATER_INTEGRAL_DRIVE_MAX)
#error DEPENDENCY ERROR: Missing setting PID_WATER_INTEGRAL_DRIVE_MAX
#if ENABLED(PIDTEMPCOOLER)
#if DISABLED(PID_COOLER_INTEGRAL_DRIVE_MAX)
#error DEPENDENCY ERROR: Missing setting PID_COOLER_INTEGRAL_DRIVE_MAX
#endif
#if DISABLED(DEFAULT_waterKp)
#error DEPENDENCY ERROR: Missing setting DEFAULT_waterKp
#if DISABLED(DEFAULT_coolerKp)
#error DEPENDENCY ERROR: Missing setting DEFAULT_coolerKp
#endif
#if DISABLED(DEFAULT_waterKi)
#error DEPENDENCY ERROR: Missing setting DEFAULT_waterKi
#if DISABLED(DEFAULT_coolerKi)
#error DEPENDENCY ERROR: Missing setting DEFAULT_coolerKi
#endif
#if DISABLED(DEFAULT_waterKd)
#error DEPENDENCY ERROR: Missing setting DEFAULT_waterKd
#if DISABLED(DEFAULT_coolerKd)
#error DEPENDENCY ERROR: Missing setting DEFAULT_coolerKd
#endif
#endif
......
This diff is collapsed.
......@@ -72,9 +72,12 @@ extern float current_temperature[4];
#if ENABLED(SHOW_TEMP_ADC_VALUES)
extern int current_temperature_raw[4];
extern int current_temperature_bed_raw;
extern int current_temperature_cooler_raw;
#endif
extern int target_temperature_bed;
extern float current_temperature_bed;
extern int target_temperature_cooler;
extern float current_temperature_cooler;
#if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
extern float redundant_temperature;
#endif
......@@ -92,7 +95,11 @@ extern float current_temperature_bed;
extern float bedKp, bedKi, bedKd;
#endif
#if ENABLED(PIDTEMP) || ENABLED(PIDTEMPBED)
#if ENABLED(PIDTEMPCOOLER)
extern float coolerKp, coolerKi, coolerKd;
#endif
#if ENABLED(PIDTEMP) || ENABLED(PIDTEMPBED) || ENABLED(PIDTEMPCOOLER)
float scalePID_i(float i);
float scalePID_d(float d);
float unscalePID_i(float i);
......@@ -114,14 +121,17 @@ extern float current_temperature_bed;
FORCE_INLINE float degHotend(uint8_t hotend) { return current_temperature[HOTEND_ARG]; }
FORCE_INLINE float degBed() { return current_temperature_bed; }
FORCE_INLINE float degCooler() { return current_temperature_cooler; }
#if ENABLED(SHOW_TEMP_ADC_VALUES)
FORCE_INLINE float rawHotendTemp(uint8_t hotend) { return current_temperature_raw[HOTEND_ARG]; }
FORCE_INLINE float rawBedTemp() { return current_temperature_bed_raw; }
FORCE_INLINE float rawCoolerTemp() { return current_temperature_cooler_raw; }
#endif
FORCE_INLINE float degTargetHotend(uint8_t hotend) { return target_temperature[HOTEND_ARG]; }
FORCE_INLINE float degTargetBed() { return target_temperature_bed; }
FORCE_INLINE float degTargetCooler() { return target_temperature_cooler; }
#if ENABLED(THERMAL_PROTECTION_HOTENDS)
void start_watching_heater(int h = 0);
......@@ -134,12 +144,15 @@ FORCE_INLINE void setTargetHotend(const float& celsius, uint8_t hotend) {
#endif
}
FORCE_INLINE void setTargetBed(const float& celsius) { target_temperature_bed = celsius; }
FORCE_INLINE void setTargetCooler(const float& celsius) { target_temperature_cooler = celsius; }
FORCE_INLINE bool isHeatingHotend(uint8_t hotend) { return target_temperature[HOTEND_ARG] > current_temperature[HOTEND_ARG]; }
FORCE_INLINE bool isHeatingBed() { return target_temperature_bed > current_temperature_bed; }
FORCE_INLINE bool isHeatingCooler() { return target_temperature_cooler > current_temperature_cooler; }
FORCE_INLINE bool isCoolingHotend(uint8_t hotend) { return target_temperature[HOTEND_ARG] < current_temperature[HOTEND_ARG]; }
FORCE_INLINE bool isCoolingBed() { return target_temperature_bed < current_temperature_bed; }
FORCE_INLINE bool isCoolingCooler() { return target_temperature_cooler < current_temperature_cooler; }
#define HOTEND_ROUTINES(NR) \
FORCE_INLINE float degHotend##NR() { return degHotend(NR); } \
......@@ -165,11 +178,14 @@ HOTEND_ROUTINES(0);
#endif
int getHeaterPower(int heater);
void disable_all_heaters();
int getCoolerPower(void);
void disable_all_heaters();
#define disable_all_coolers() setTargetCooler(0)
void updatePID();
#if HAS(PID_HEATING)
void PID_autotune(float temp, int hotend, int ncycles, bool set_result = false);
#if HAS(PID_HEATING) || HAS(PID_COOLING)
void PID_autotune(float temp, int temp_controller, int ncycles, bool set_result = false);
#endif
void setExtruderAutoFanState(int pin, bool state);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment