Corrected temp variables.

master
Erik van der Zalm 13 years ago
parent 04d3b5537f
commit 2e8e8878e5

@ -1,245 +1,245 @@
#ifndef CONFIGURATION_H #ifndef CONFIGURATION_H
#define CONFIGURATION_H #define CONFIGURATION_H
//#define DEBUG_STEPS //#define DEBUG_STEPS
// BASIC SETTINGS: select your board type, thermistor type, axis scaling, and endstop configuration // BASIC SETTINGS: select your board type, thermistor type, axis scaling, and endstop configuration
//// The following define selects which electronics board you have. Please choose the one that matches your setup //// The following define selects which electronics board you have. Please choose the one that matches your setup
// MEGA/RAMPS up to 1.2 = 3, // MEGA/RAMPS up to 1.2 = 3,
// RAMPS 1.3 = 33 // RAMPS 1.3 = 33
// Gen6 = 5, // Gen6 = 5,
// Sanguinololu 1.2 and above = 62 // Sanguinololu 1.2 and above = 62
// Ultimaker = 7, // Ultimaker = 7,
#define MOTHERBOARD 7 #define MOTHERBOARD 7
//#define MOTHERBOARD 5 //#define MOTHERBOARD 5
//// Thermistor settings: //// Thermistor settings:
// 1 is 100k thermistor // 1 is 100k thermistor
// 2 is 200k thermistor // 2 is 200k thermistor
// 3 is mendel-parts thermistor // 3 is mendel-parts thermistor
// 4 is 10k thermistor // 4 is 10k thermistor
// 5 is ParCan supplied 104GT-2 100K // 5 is ParCan supplied 104GT-2 100K
// 6 is EPCOS 100k // 6 is EPCOS 100k
// 7 is 100k Honeywell thermistor 135-104LAG-J01 // 7 is 100k Honeywell thermistor 135-104LAG-J01
#define THERMISTORHEATER_1 3 #define THERMISTORHEATER_1 3
#define THERMISTORHEATER_2 3 #define THERMISTORHEATER_2 3
#define THERMISTORBED 3 #define THERMISTORBED 3
//#define HEATER_0_USES_THERMISTOR //#define HEATER_0_USES_THERMISTOR
//#define HEATER_1_USES_THERMISTOR //#define HEATER_1_USES_THERMISTOR
#define HEATER_0_USES_AD595 #define HEATER_0_USES_AD595
//#define HEATER_1_USES_AD595 //#define HEATER_1_USES_AD595
// Select one of these only to define how the bed temp is read. // Select one of these only to define how the bed temp is read.
//#define BED_USES_THERMISTOR //#define BED_USES_THERMISTOR
//#define BED_USES_AD595 //#define BED_USES_AD595
#define HEATER_CHECK_INTERVAL 50 #define HEATER_CHECK_INTERVAL 50
#define BED_CHECK_INTERVAL 5000 #define BED_CHECK_INTERVAL 5000
//// Endstop Settings //// Endstop Settings
#define ENDSTOPPULLUPS // Comment this out (using // at the start of the line) to disable the endstop pullup resistors #define ENDSTOPPULLUPS // Comment this out (using // at the start of the line) to disable the endstop pullup resistors
// The pullups are needed if you directly connect a mechanical endswitch between the signal and ground pins. // The pullups are needed if you directly connect a mechanical endswitch between the signal and ground pins.
const bool ENDSTOPS_INVERTING = true; // set to true to invert the logic of the endstops. const bool ENDSTOPS_INVERTING = true; // set to true to invert the logic of the endstops.
// For optos H21LOB set to true, for Mendel-Parts newer optos TCST2103 set to false // For optos H21LOB set to true, for Mendel-Parts newer optos TCST2103 set to false
// This determines the communication speed of the printer // This determines the communication speed of the printer
#define BAUDRATE 250000 #define BAUDRATE 250000
//#define BAUDRATE 115200 //#define BAUDRATE 115200
//#define BAUDRATE 230400 //#define BAUDRATE 230400
// Comment out (using // at the start of the line) to disable SD support: // Comment out (using // at the start of the line) to disable SD support:
// #define ULTRA_LCD //any lcd // #define ULTRA_LCD //any lcd
#define ULTIPANEL #define ULTIPANEL
#define ULTIPANEL #define ULTIPANEL
#ifdef ULTIPANEL #ifdef ULTIPANEL
//#define NEWPANEL //enable this if you have a click-encoder panel //#define NEWPANEL //enable this if you have a click-encoder panel
#define SDSUPPORT #define SDSUPPORT
#define ULTRA_LCD #define ULTRA_LCD
#define LCD_WIDTH 20 #define LCD_WIDTH 20
#define LCD_HEIGHT 4 #define LCD_HEIGHT 4
#else //no panel but just lcd #else //no panel but just lcd
#ifdef ULTRA_LCD #ifdef ULTRA_LCD
#define LCD_WIDTH 16 #define LCD_WIDTH 16
#define LCD_HEIGHT 2 #define LCD_HEIGHT 2
#endif #endif
#endif #endif
//#define SDSUPPORT // Enable SD Card Support in Hardware Console //#define SDSUPPORT // Enable SD Card Support in Hardware Console
const int dropsegments=5; //everything with this number of steps will be ignored as move const int dropsegments=5; //everything with this number of steps will be ignored as move
//// ADVANCED SETTINGS - to tweak parameters //// ADVANCED SETTINGS - to tweak parameters
#include "thermistortables.h" #include "thermistortables.h"
// For Inverting Stepper Enable Pins (Active Low) use 0, Non Inverting (Active High) use 1 // For Inverting Stepper Enable Pins (Active Low) use 0, Non Inverting (Active High) use 1
#define X_ENABLE_ON 0 #define X_ENABLE_ON 0
#define Y_ENABLE_ON 0 #define Y_ENABLE_ON 0
#define Z_ENABLE_ON 0 #define Z_ENABLE_ON 0
#define E_ENABLE_ON 0 #define E_ENABLE_ON 0
// Disables axis when it's not being used. // Disables axis when it's not being used.
#define DISABLE_X false #define DISABLE_X false
#define DISABLE_Y false #define DISABLE_Y false
#define DISABLE_Z false #define DISABLE_Z false
#define DISABLE_E false #define DISABLE_E false
// Inverting axis direction // Inverting axis direction
#define INVERT_X_DIR true // for Mendel set to false, for Orca set to true #define INVERT_X_DIR true // for Mendel set to false, for Orca set to true
#define INVERT_Y_DIR false // for Mendel set to true, for Orca set to false #define INVERT_Y_DIR false // for Mendel set to true, for Orca set to false
#define INVERT_Z_DIR true // for Mendel set to false, for Orca set to true #define INVERT_Z_DIR true // for Mendel set to false, for Orca set to true
#define INVERT_E_DIR false // for direct drive extruder v9 set to true, for geared extruder set to false #define INVERT_E_DIR false // for direct drive extruder v9 set to true, for geared extruder set to false
//// ENDSTOP SETTINGS: //// ENDSTOP SETTINGS:
// Sets direction of endstops when homing; 1=MAX, -1=MIN // Sets direction of endstops when homing; 1=MAX, -1=MIN
#define X_HOME_DIR -1 #define X_HOME_DIR -1
#define Y_HOME_DIR -1 #define Y_HOME_DIR -1
#define Z_HOME_DIR -1 #define Z_HOME_DIR -1
#define min_software_endstops false //If true, axis won't move to coordinates less than zero. #define min_software_endstops false //If true, axis won't move to coordinates less than zero.
#define max_software_endstops false //If true, axis won't move to coordinates greater than the defined lengths below. #define max_software_endstops false //If true, axis won't move to coordinates greater than the defined lengths below.
#define X_MAX_LENGTH 210 #define X_MAX_LENGTH 210
#define Y_MAX_LENGTH 210 #define Y_MAX_LENGTH 210
#define Z_MAX_LENGTH 210 #define Z_MAX_LENGTH 210
//// MOVEMENT SETTINGS //// MOVEMENT SETTINGS
#define NUM_AXIS 4 // The axis order in all axis related arrays is X, Y, Z, E #define NUM_AXIS 4 // The axis order in all axis related arrays is X, Y, Z, E
//note: on bernhards ultimaker 200 200 12 are working well. //note: on bernhards ultimaker 200 200 12 are working well.
#define HOMING_FEEDRATE {50*60, 50*60, 12*60, 0} // set the homing speeds #define HOMING_FEEDRATE {50*60, 50*60, 12*60, 0} // set the homing speeds
//the followint checks if an extrusion is existent in the move. if _not_, the speed of the move is set to the maximum speed. //the followint checks if an extrusion is existent in the move. if _not_, the speed of the move is set to the maximum speed.
//!!!!!!Use only if you know that your printer works at the maximum declared speeds. //!!!!!!Use only if you know that your printer works at the maximum declared speeds.
// works around the skeinforge cool-bug. There all moves are slowed to have a minimum layer time. However slow travel moves= ooze // works around the skeinforge cool-bug. There all moves are slowed to have a minimum layer time. However slow travel moves= ooze
#define TRAVELING_AT_MAXSPEED #define TRAVELING_AT_MAXSPEED
#define AXIS_RELATIVE_MODES {false, false, false, false} #define AXIS_RELATIVE_MODES {false, false, false, false}
#define MAX_STEP_FREQUENCY 40000 // Max step frequency for Ultimaker (5000 pps / half step) #define MAX_STEP_FREQUENCY 40000 // Max step frequency for Ultimaker (5000 pps / half step)
// default settings // default settings
#define DEFAULT_AXIS_STEPS_PER_UNIT {79.87220447,79.87220447,200*8/3,14} // default steps per unit for ultimaker #define DEFAULT_AXIS_STEPS_PER_UNIT {79.87220447,79.87220447,200*8/3,14} // default steps per unit for ultimaker
#define DEFAULT_MAX_FEEDRATE {160*60, 160*60, 10*60, 500000} #define DEFAULT_MAX_FEEDRATE {160*60, 160*60, 10*60, 500000}
#define DEFAULT_MAX_ACCELERATION {9000,9000,150,10000} // X, Y, Z, E maximum start speed for accelerated moves. E default values are good for skeinforge 40+, for older versions raise them a lot. #define DEFAULT_MAX_ACCELERATION {9000,9000,150,10000} // X, Y, Z, E maximum start speed for accelerated moves. E default values are good for skeinforge 40+, for older versions raise them a lot.
#define DEFAULT_ACCELERATION 3000 // X, Y, Z and E max acceleration in mm/s^2 for printing moves #define DEFAULT_ACCELERATION 3000 // X, Y, Z and E max acceleration in mm/s^2 for printing moves
#define DEFAULT_RETRACT_ACCELERATION 7000 // X, Y, Z and E max acceleration in mm/s^2 for r retracts #define DEFAULT_RETRACT_ACCELERATION 7000 // X, Y, Z and E max acceleration in mm/s^2 for r retracts
#define DEFAULT_MINIMUMFEEDRATE 10 // minimum feedrate #define DEFAULT_MINIMUMFEEDRATE 10 // minimum feedrate
#define DEFAULT_MINTRAVELFEEDRATE 10 #define DEFAULT_MINTRAVELFEEDRATE 10
// minimum time in microseconds that a movement needs to take if the buffer is emptied. Increase this number if you see blobs while printing high speed & high detail. It will slowdown on the detailed stuff. // minimum time in microseconds that a movement needs to take if the buffer is emptied. Increase this number if you see blobs while printing high speed & high detail. It will slowdown on the detailed stuff.
#define DEFAULT_MINSEGMENTTIME 20000 #define DEFAULT_MINSEGMENTTIME 20000
#define DEFAULT_XYJERK 30.0*60 #define DEFAULT_XYJERK 30.0*60
#define DEFAULT_ZJERK 10.0*60 #define DEFAULT_ZJERK 10.0*60
// The watchdog waits for the watchperiod in milliseconds whenever an M104 or M109 increases the target temperature // The watchdog waits for the watchperiod in milliseconds whenever an M104 or M109 increases the target temperature
//this enables the watchdog interrupt. //this enables the watchdog interrupt.
#define USE_WATCHDOG #define USE_WATCHDOG
//you cannot reboot on a mega2560 due to a bug in he bootloader. Hence, you have to reset manually, and this is done hereby: //you cannot reboot on a mega2560 due to a bug in he bootloader. Hence, you have to reset manually, and this is done hereby:
#define RESET_MANUAL #define RESET_MANUAL
#define WATCHDOG_TIMEOUT 4 #define WATCHDOG_TIMEOUT 4
//// Experimental watchdog and minimal temp //// Experimental watchdog and minimal temp
// The watchdog waits for the watchperiod in milliseconds whenever an M104 or M109 increases the target temperature // The watchdog waits for the watchperiod in milliseconds whenever an M104 or M109 increases the target temperature
// If the temperature has not increased at the end of that period, the target temperature is set to zero. It can be reset with another M104/M109 // If the temperature has not increased at the end of that period, the target temperature is set to zero. It can be reset with another M104/M109
//#define WATCHPERIOD 5000 //5 seconds //#define WATCHPERIOD 5000 //5 seconds
// Actual temperature must be close to target for this long before M109 returns success // Actual temperature must be close to target for this long before M109 returns success
//#define TEMP_RESIDENCY_TIME 20 // (seconds) //#define TEMP_RESIDENCY_TIME 20 // (seconds)
//#define TEMP_HYSTERESIS 5 // (C°) range of +/- temperatures considered "close" to the target one //#define TEMP_HYSTERESIS 5 // (C°) range of +/- temperatures considered "close" to the target one
//// The minimal temperature defines the temperature below which the heater will not be enabled //// The minimal temperature defines the temperature below which the heater will not be enabled
#define HEATER_0_MINTEMP 5 #define HEATER_0_MINTEMP 5
//#define HEATER_1_MINTEMP 5 //#define HEATER_1_MINTEMP 5
//#define BED_MINTEMP 5 //#define BED_MINTEMP 5
// When temperature exceeds max temp, your heater will be switched off. // When temperature exceeds max temp, your heater will be switched off.
// 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
#define PIDTEMP #define PIDTEMP
#ifdef PIDTEMP #ifdef PIDTEMP
/// PID settings: /// PID settings:
// Uncomment the following line to enable PID support. // Uncomment the following line to enable PID support.
//#define SMOOTHING //#define SMOOTHING
//#define SMOOTHFACTOR 5.0 //#define SMOOTHFACTOR 5.0
//float current_raw_average=0; //float current_raw_average=0;
#define K1 0.95 //smoothing of the PID #define K1 0.95 //smoothing of the PID
//#define PID_DEBUG // Sends debug data to the serial port. //#define PID_DEBUG // Sends debug data to the serial port.
//#define PID_OPENLOOP 1 // Puts PID in open loop. M104 sets the output power in % //#define PID_OPENLOOP 1 // Puts PID in open loop. M104 sets the output power in %
#define PID_MAX 255 // limits current to nozzle #define PID_MAX 255 // limits current to nozzle
#define PID_INTEGRAL_DRIVE_MAX 255 #define PID_INTEGRAL_DRIVE_MAX 255
#define PID_dT 0.1 #define PID_dT 0.1
//machine with red silicon: 1950:45 second ; with fan fully blowin 3000:47 //machine with red silicon: 1950:45 second ; with fan fully blowin 3000:47
#define PID_CRITIAL_GAIN 3000 #define PID_CRITIAL_GAIN 3000
#define PID_SWING_AT_CRITIAL 45 //seconds #define PID_SWING_AT_CRITIAL 45 //seconds
#define PIDIADD 5 #define PIDIADD 5
/* /*
//PID according to Ziegler-Nichols method //PID according to Ziegler-Nichols method
float Kp = 0.6*PID_CRITIAL_GAIN; float Kp = 0.6*PID_CRITIAL_GAIN;
float Ki =PIDIADD+2*Kp/PID_SWING_AT_CRITIAL*PID_dT; float Ki =PIDIADD+2*Kp/PID_SWING_AT_CRITIAL*PID_dT;
float Kd = Kp*PID_SWING_AT_CRITIAL/8./PID_dT; float Kd = Kp*PID_SWING_AT_CRITIAL/8./PID_dT;
*/ */
//PI according to Ziegler-Nichols method //PI according to Ziegler-Nichols method
#define DEFAULT_Kp (PID_CRITIAL_GAIN/2.2) #define DEFAULT_Kp (PID_CRITIAL_GAIN/2.2)
#define DEFAULT_Ki (1.2*Kp/PID_SWING_AT_CRITIAL*PID_dT) #define DEFAULT_Ki (1.2*Kp/PID_SWING_AT_CRITIAL*PID_dT)
#define DEFAULT_Kd (0) #define DEFAULT_Kd (0)
#define PID_ADD_EXTRUSION_RATE #define PID_ADD_EXTRUSION_RATE
#ifdef PID_ADD_EXTRUSION_RATE #ifdef PID_ADD_EXTRUSION_RATE
#define DEFAULT_Kc (5) //heatingpower=Kc*(e_speed) #define DEFAULT_Kc (5) //heatingpower=Kc*(e_speed)
#endif #endif
#endif // PIDTEMP #endif // PIDTEMP
// extruder advance constant (s2/mm3) // extruder advance constant (s2/mm3)
// //
// advance (steps) = STEPS_PER_CUBIC_MM_E * EXTUDER_ADVANCE_K * cubic mm per second ^ 2 // advance (steps) = STEPS_PER_CUBIC_MM_E * EXTUDER_ADVANCE_K * cubic mm per second ^ 2
// //
// hooke's law says: force = k * distance // hooke's law says: force = k * distance
// bernoulli's priniciple says: v ^ 2 / 2 + g . h + pressure / density = constant // bernoulli's priniciple says: v ^ 2 / 2 + g . h + pressure / density = constant
// so: v ^ 2 is proportional to number of steps we advance the extruder // so: v ^ 2 is proportional to number of steps we advance the extruder
//#define ADVANCE //#define ADVANCE
#ifdef ADVANCE #ifdef ADVANCE
#define EXTRUDER_ADVANCE_K .3 #define EXTRUDER_ADVANCE_K .3
#define D_FILAMENT 1.7 #define D_FILAMENT 1.7
#define STEPS_MM_E 65 #define STEPS_MM_E 65
#define EXTRUTION_AREA (0.25 * D_FILAMENT * D_FILAMENT * 3.14159) #define EXTRUTION_AREA (0.25 * D_FILAMENT * D_FILAMENT * 3.14159)
#define STEPS_PER_CUBIC_MM_E (axis_steps_per_unit[E_AXIS]/ EXTRUTION_AREA) #define STEPS_PER_CUBIC_MM_E (axis_steps_per_unit[E_AXIS]/ EXTRUTION_AREA)
#endif // ADVANCE #endif // ADVANCE
// THE BLOCK_BUFFER_SIZE NEEDS TO BE A POWER OF 2, e.g. 8,16,32 // THE BLOCK_BUFFER_SIZE NEEDS TO BE A POWER OF 2, e.g. 8,16,32
#if defined SDSUPPORT #if defined SDSUPPORT
// The number of linear motions that can be in the plan at any give time. // The number of linear motions that can be in the plan at any give time.
#define BLOCK_BUFFER_SIZE 16 // SD,LCD,Buttons take more memory, block buffer needs to be smaller #define BLOCK_BUFFER_SIZE 16 // SD,LCD,Buttons take more memory, block buffer needs to be smaller
#else #else
#define BLOCK_BUFFER_SIZE 16 // maximize block buffer #define BLOCK_BUFFER_SIZE 16 // maximize block buffer
#endif #endif
#endif #endif

File diff suppressed because it is too large Load Diff

@ -1,501 +1,503 @@
/* /*
temperature.c - temperature control temperature.c - temperature control
Part of Marlin Part of Marlin
Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
/* /*
This firmware is a mashup between Sprinter and grbl. This firmware is a mashup between Sprinter and grbl.
(https://github.com/kliment/Sprinter) (https://github.com/kliment/Sprinter)
(https://github.com/simen/grbl/tree) (https://github.com/simen/grbl/tree)
It has preliminary support for Matthew Roberts advance algorithm It has preliminary support for Matthew Roberts advance algorithm
http://reprap.org/pipermail/reprap-dev/2011-May/003323.html http://reprap.org/pipermail/reprap-dev/2011-May/003323.html
This firmware is optimized for gen6 electronics. This firmware is optimized for gen6 electronics.
*/ */
#include "fastio.h" #include "fastio.h"
#include "Configuration.h" #include "Configuration.h"
#include "pins.h" #include "pins.h"
#include "Marlin.h" #include "Marlin.h"
#include "ultralcd.h" #include "ultralcd.h"
#include "streaming.h" #include "streaming.h"
#include "temperature.h" #include "temperature.h"
int target_bed_raw = 0; int target_bed_raw = 0;
int current_bed_raw = 0; int current_bed_raw = 0;
int target_raw[3] = {0, 0, 0}; int target_raw[3] = {0, 0, 0};
int current_raw[3] = {0, 0, 0}; int current_raw[3] = {0, 0, 0};
unsigned char temp_meas_ready = false; unsigned char temp_meas_ready = false;
unsigned long previous_millis_heater, previous_millis_bed_heater; unsigned long previous_millis_heater, previous_millis_bed_heater;
#ifdef PIDTEMP #ifdef PIDTEMP
double temp_iState = 0; double temp_iState = 0;
double temp_dState = 0; double temp_dState = 0;
double pTerm; double pTerm;
double iTerm; double iTerm;
double dTerm; double dTerm;
//int output; //int output;
double pid_error; double pid_error;
double temp_iState_min; double temp_iState_min;
double temp_iState_max; double temp_iState_max;
double pid_setpoint = 0.0; double pid_setpoint = 0.0;
double pid_input; double pid_input;
double pid_output; double pid_output;
bool pid_reset; bool pid_reset;
float HeaterPower; float HeaterPower;
float Kp=DEFAULT_Kp; float Kp=DEFAULT_Kp;
float Ki=DEFAULT_Ki; float Ki=DEFAULT_Ki;
float Kd=DEFAULT_Kd; float Kd=DEFAULT_Kd;
float Kc=DEFAULT_Kc; float Kc=DEFAULT_Kc;
#endif //PIDTEMP #endif //PIDTEMP
#ifdef HEATER_0_MINTEMP #ifdef HEATER_0_MINTEMP
int minttemp_0 = temp2analog(HEATER_0_MINTEMP); int minttemp_0 = temp2analog(HEATER_0_MINTEMP);
#endif //MINTEMP #endif //MINTEMP
#ifdef HEATER_0_MAXTEMP #ifdef HEATER_0_MAXTEMP
int maxttemp_0 = temp2analog(HEATER_0_MAXTEMP); int maxttemp_0 = temp2analog(HEATER_0_MAXTEMP);
#endif //MAXTEMP #endif //MAXTEMP
#ifdef HEATER_1_MINTEMP #ifdef HEATER_1_MINTEMP
int minttemp_1 = temp2analog(HEATER_1_MINTEMP); int minttemp_1 = temp2analog(HEATER_1_MINTEMP);
#endif //MINTEMP #endif //MINTEMP
#ifdef HEATER_1_MAXTEMP #ifdef HEATER_1_MAXTEMP
int maxttemp_1 = temp2analog(HEATER_1_MAXTEMP); int maxttemp_1 = temp2analog(HEATER_1_MAXTEMP);
#endif //MAXTEMP #endif //MAXTEMP
#ifdef BED_MINTEMP #ifdef BED_MINTEMP
int bed_minttemp = temp2analog(BED_MINTEMP); int bed_minttemp = temp2analog(BED_MINTEMP);
#endif //BED_MINTEMP #endif //BED_MINTEMP
#ifdef BED_MAXTEMP #ifdef BED_MAXTEMP
int bed_maxttemp = temp2analog(BED_MAXTEMP); int bed_maxttemp = temp2analog(BED_MAXTEMP);
#endif //BED_MAXTEMP #endif //BED_MAXTEMP
void manage_heater() void manage_heater()
{ {
#ifdef USE_WATCHDOG #ifdef USE_WATCHDOG
wd_reset(); wd_reset();
#endif #endif
float pid_input; float pid_input;
float pid_output; float pid_output;
if(temp_meas_ready != true) //better readability if(temp_meas_ready != true) //better readability
return; return;
CRITICAL_SECTION_START; CRITICAL_SECTION_START;
temp_meas_ready = false; temp_meas_ready = false;
CRITICAL_SECTION_END; CRITICAL_SECTION_END;
#ifdef PIDTEMP #ifdef PIDTEMP
pid_input = analog2temp(current_raw[TEMPSENSOR_HOTEND]); pid_input = analog2temp(current_raw[TEMPSENSOR_HOTEND_0]);
#ifndef PID_OPENLOOP #ifndef PID_OPENLOOP
pid_error = pid_setpoint - pid_input; pid_error = pid_setpoint - pid_input;
if(pid_error > 10){ if(pid_error > 10){
pid_output = PID_MAX; pid_output = PID_MAX;
pid_reset = true; pid_reset = true;
} }
else if(pid_error < -10) { else if(pid_error < -10) {
pid_output = 0; pid_output = 0;
pid_reset = true; pid_reset = true;
} }
else { else {
if(pid_reset == true) { if(pid_reset == true) {
temp_iState = 0.0; temp_iState = 0.0;
pid_reset = false; pid_reset = false;
} }
pTerm = Kp * pid_error; pTerm = Kp * pid_error;
temp_iState += pid_error; temp_iState += pid_error;
temp_iState = constrain(temp_iState, temp_iState_min, temp_iState_max); temp_iState = constrain(temp_iState, temp_iState_min, temp_iState_max);
iTerm = Ki * temp_iState; iTerm = Ki * temp_iState;
//K1 defined in Configuration.h in the PID settings //K1 defined in Configuration.h in the PID settings
#define K2 (1.0-K1) #define K2 (1.0-K1)
dTerm = (Kd * (pid_input - temp_dState))*K2 + (K1 * dTerm); dTerm = (Kd * (pid_input - temp_dState))*K2 + (K1 * dTerm);
temp_dState = pid_input; temp_dState = pid_input;
#ifdef PID_ADD_EXTRUSION_RATE #ifdef PID_ADD_EXTRUSION_RATE
pTerm+=Kc*current_block->speed_e; //additional heating if extrusion speed is high pTerm+=Kc*current_block->speed_e; //additional heating if extrusion speed is high
#endif #endif
pid_output = constrain(pTerm + iTerm - dTerm, 0, PID_MAX); pid_output = constrain(pTerm + iTerm - dTerm, 0, PID_MAX);
} }
#endif //PID_OPENLOOP #endif //PID_OPENLOOP
#ifdef PID_DEBUG #ifdef PID_DEBUG
Serial.print(" Input "); Serial.print(" Input ");
Serial.print(pid_input); Serial.print(pid_input);
Serial.print(" Output "); Serial.print(" Output ");
Serial.print(pid_output); Serial.print(pid_output);
Serial.print(" pTerm "); Serial.print(" pTerm ");
Serial.print(pTerm); Serial.print(pTerm);
Serial.print(" iTerm "); Serial.print(" iTerm ");
Serial.print(iTerm); Serial.print(iTerm);
Serial.print(" dTerm "); Serial.print(" dTerm ");
Serial.print(dTerm); Serial.print(dTerm);
Serial.println(); Serial.println();
#endif //PID_DEBUG #endif //PID_DEBUG
analogWrite(HEATER_0_PIN, pid_output); analogWrite(HEATER_0_PIN, pid_output);
#endif //PIDTEMP #endif //PIDTEMP
#ifndef PIDTEMP #ifndef PIDTEMP
if(current_raw[0] >= target_raw[0]) if(current_raw[0] >= target_raw[0])
{ {
WRITE(HEATER_0_PIN,LOW); WRITE(HEATER_0_PIN,LOW);
} }
else else
{ {
WRITE(HEATER_0_PIN,HIGH); WRITE(HEATER_0_PIN,HIGH);
} }
#endif #endif
if(millis() - previous_millis_bed_heater < BED_CHECK_INTERVAL) if(millis() - previous_millis_bed_heater < BED_CHECK_INTERVAL)
return; return;
previous_millis_bed_heater = millis(); previous_millis_bed_heater = millis();
#if TEMP_1_PIN > -1 #if TEMP_1_PIN > -1
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);
} }
else else
{ {
WRITE(HEATER_1_PIN,HIGH); WRITE(HEATER_1_PIN,HIGH);
} }
#endif #endif
} }
// Takes hot end temperature value as input and returns corresponding raw value. // Takes hot end temperature value as input and returns corresponding raw value.
// For a thermistor, it uses the RepRap thermistor temp table. // For a thermistor, it uses the RepRap thermistor temp table.
// This is needed because PID in hydra firmware hovers around a given analog value, not a temp value. // This is needed because PID in hydra firmware hovers around a given analog value, not a temp value.
// This function is derived from inversing the logic from a portion of getTemperature() in FiveD RepRap firmware. // This function is derived from inversing the logic from a portion of getTemperature() in FiveD RepRap firmware.
int temp2analog(int celsius) { int temp2analog(int celsius) {
#ifdef HEATER_0_USES_THERMISTOR #ifdef HEATER_0_USES_THERMISTOR
int raw = 0; int raw = 0;
byte i; byte i;
for (i=1; i<NUMTEMPS_HEATER_0; i++) for (i=1; i<NUMTEMPS_HEATER_0; i++)
{ {
if (heater_0_temptable[i][1] < celsius) if (heater_0_temptable[i][1] < celsius)
{ {
raw = heater_0_temptable[i-1][0] + raw = heater_0_temptable[i-1][0] +
(celsius - heater_0_temptable[i-1][1]) * (celsius - heater_0_temptable[i-1][1]) *
(heater_0_temptable[i][0] - heater_0_temptable[i-1][0]) / (heater_0_temptable[i][0] - heater_0_temptable[i-1][0]) /
(heater_0_temptable[i][1] - heater_0_temptable[i-1][1]); (heater_0_temptable[i][1] - heater_0_temptable[i-1][1]);
break; break;
} }
} }
// Overflow: Set to last value in the table // Overflow: Set to last value in the table
if (i == NUMTEMPS_0) raw = heater_0_temptable[i-1][0]; if (i == NUMTEMPS_0) raw = heater_0_temptable[i-1][0];
return (1023 * OVERSAMPLENR) - raw; return (1023 * OVERSAMPLENR) - raw;
#elif defined HEATER_0_USES_AD595 #elif defined HEATER_0_USES_AD595
return celsius * (1024.0 / (5.0 * 100.0) ) * OVERSAMPLENR; return celsius * (1024.0 / (5.0 * 100.0) ) * OVERSAMPLENR;
#endif #endif
} }
// Takes bed temperature value as input and returns corresponding raw value. // Takes bed temperature value as input and returns corresponding raw value.
// For a thermistor, it uses the RepRap thermistor temp table. // For a thermistor, it uses the RepRap thermistor temp table.
// This is needed because PID in hydra firmware hovers around a given analog value, not a temp value. // This is needed because PID in hydra firmware hovers around a given analog value, not a temp value.
// This function is derived from inversing the logic from a portion of getTemperature() in FiveD RepRap firmware. // This function is derived from inversing the logic from a portion of getTemperature() in FiveD RepRap firmware.
int temp2analogBed(int celsius) { int temp2analogBed(int celsius) {
#ifdef BED_USES_THERMISTOR #ifdef BED_USES_THERMISTOR
int raw = 0; int raw = 0;
byte i; byte i;
for (i=1; i<BNUMTEMPS; i++) for (i=1; i<BNUMTEMPS; i++)
{ {
if (bedtemptable[i][1] < celsius) if (bedtemptable[i][1] < celsius)
{ {
raw = bedtemptable[i-1][0] + raw = bedtemptable[i-1][0] +
(celsius - bedtemptable[i-1][1]) * (celsius - bedtemptable[i-1][1]) *
(bedtemptable[i][0] - bedtemptable[i-1][0]) / (bedtemptable[i][0] - bedtemptable[i-1][0]) /
(bedtemptable[i][1] - bedtemptable[i-1][1]); (bedtemptable[i][1] - bedtemptable[i-1][1]);
break; break;
} }
} }
// Overflow: Set to last value in the table // Overflow: Set to last value in the table
if (i == BNUMTEMPS) raw = bedtemptable[i-1][0]; if (i == BNUMTEMPS) raw = bedtemptable[i-1][0];
return (1023 * OVERSAMPLENR) - raw; return (1023 * OVERSAMPLENR) - raw;
#elif defined BED_USES_AD595 #elif defined BED_USES_AD595
return celsius * (1024.0 / (5.0 * 100.0) ) * OVERSAMPLENR; return celsius * (1024.0 / (5.0 * 100.0) ) * OVERSAMPLENR;
#endif #endif
} }
// Derived from RepRap FiveD extruder::getTemperature() // Derived from RepRap FiveD extruder::getTemperature()
// For hot end temperature measurement. // For hot end temperature measurement.
float analog2temp(int raw) { float analog2temp(int raw) {
#ifdef HEATER_0_USES_THERMISTOR #ifdef HEATER_0_USES_THERMISTOR
float celsius = 0; float celsius = 0;
byte i; byte i;
raw = (1023 * OVERSAMPLENR) - raw; raw = (1023 * OVERSAMPLENR) - raw;
for (i=1; i<NUMTEMPS_HEATER_0; i++) for (i=1; i<NUMTEMPS_HEATER_0; i++)
{ {
if (heater_0_temptable[i][0] > raw) if (heater_0_temptable[i][0] > raw)
{ {
celsius = heater_0_temptable[i-1][1] + celsius = heater_0_temptable[i-1][1] +
(raw - heater_0_temptable[i-1][0]) * (raw - heater_0_temptable[i-1][0]) *
(float)(heater_0_temptable[i][1] - heater_0_temptable[i-1][1]) / (float)(heater_0_temptable[i][1] - heater_0_temptable[i-1][1]) /
(float)(heater_0_temptable[i][0] - heater_0_temptable[i-1][0]); (float)(heater_0_temptable[i][0] - heater_0_temptable[i-1][0]);
break; break;
} }
} }
// Overflow: Set to last value in the table // Overflow: Set to last value in the table
if (i == NUMTEMPS_HEATER_0) celsius = heater_0_temptable[i-1][1]; if (i == NUMTEMPS_HEATER_0) celsius = heater_0_temptable[i-1][1];
return celsius; return celsius;
#elif defined HEATER_0_USES_AD595 #elif defined HEATER_0_USES_AD595
return raw * ((5.0 * 100.0) / 1024.0) / OVERSAMPLENR; return raw * ((5.0 * 100.0) / 1024.0) / OVERSAMPLENR;
#endif #endif
} }
// Derived from RepRap FiveD extruder::getTemperature() // Derived from RepRap FiveD extruder::getTemperature()
// For bed temperature measurement. // For bed temperature measurement.
float analog2tempBed(int raw) { float analog2tempBed(int raw) {
#ifdef BED_USES_THERMISTOR #ifdef BED_USES_THERMISTOR
int celsius = 0; int celsius = 0;
byte i; byte i;
raw = (1023 * OVERSAMPLENR) - raw; raw = (1023 * OVERSAMPLENR) - raw;
for (i=1; i<BNUMTEMPS; i++) for (i=1; i<BNUMTEMPS; i++)
{ {
if (bedtemptable[i][0] > raw) if (bedtemptable[i][0] > raw)
{ {
celsius = bedtemptable[i-1][1] + celsius = bedtemptable[i-1][1] +
(raw - bedtemptable[i-1][0]) * (raw - bedtemptable[i-1][0]) *
(bedtemptable[i][1] - bedtemptable[i-1][1]) / (bedtemptable[i][1] - bedtemptable[i-1][1]) /
(bedtemptable[i][0] - bedtemptable[i-1][0]); (bedtemptable[i][0] - bedtemptable[i-1][0]);
break; break;
} }
} }
// Overflow: Set to last value in the table // Overflow: Set to last value in the table
if (i == BNUMTEMPS) celsius = bedtemptable[i-1][1]; if (i == BNUMTEMPS) celsius = bedtemptable[i-1][1];
return celsius; return celsius;
#elif defined BED_USES_AD595 #elif defined BED_USES_AD595
return raw * ((5.0 * 100.0) / 1024.0) / OVERSAMPLENR; return raw * ((5.0 * 100.0) / 1024.0) / OVERSAMPLENR;
#endif #endif
} }
void tp_init() void tp_init()
{ {
#if (HEATER_0_PIN > -1) #if (HEATER_0_PIN > -1)
SET_OUTPUT(HEATER_0_PIN); SET_OUTPUT(HEATER_0_PIN);
#endif #endif
#if (HEATER_1_PIN > -1) #if (HEATER_1_PIN > -1)
SET_OUTPUT(HEATER_1_PIN); SET_OUTPUT(HEATER_1_PIN);
#endif #endif
#if (HEATER_2_PIN > -1) #if (HEATER_2_PIN > -1)
SET_OUTPUT(HEATER_2_PIN); SET_OUTPUT(HEATER_2_PIN);
#endif #endif
#ifdef PIDTEMP #ifdef PIDTEMP
temp_iState_min = 0.0; temp_iState_min = 0.0;
temp_iState_max = PID_INTEGRAL_DRIVE_MAX / Ki; temp_iState_max = PID_INTEGRAL_DRIVE_MAX / Ki;
#endif //PIDTEMP #endif //PIDTEMP
// Set analog inputs // Set analog inputs
ADCSRA = 1<<ADEN | 1<<ADSC | 1<<ADIF | 0x07; ADCSRA = 1<<ADEN | 1<<ADSC | 1<<ADIF | 0x07;
// Use timer0 for temperature measurement // Use timer0 for temperature measurement
// Interleave temperature interrupt with millies interrupt // Interleave temperature interrupt with millies interrupt
OCR0B = 128; OCR0B = 128;
TIMSK0 |= (1<<OCIE0B); TIMSK0 |= (1<<OCIE0B);
} }
// Timer 0 is shared with millies // Timer 0 is shared with millies
ISR(TIMER0_COMPB_vect) ISR(TIMER0_COMPB_vect)
{ {
//these variables are only accesible from the ISR, but static, so they don't loose their value //these variables are only accesible from the ISR, but static, so they don't loose their value
static unsigned char temp_count = 0; static unsigned char temp_count = 0;
static unsigned long raw_temp_0_value = 0; static unsigned long raw_temp_0_value = 0;
static unsigned long raw_temp_1_value = 0; static unsigned long raw_temp_1_value = 0;
static unsigned long raw_temp_2_value = 0; static unsigned long raw_temp_2_value = 0;
static unsigned char temp_state = 0; static unsigned char temp_state = 0;
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 < 8
DIDR0 = 1 << TEMP_0_PIN; DIDR0 = 1 << TEMP_0_PIN;
#else #else
DIDR2 = 1<<(TEMP_0_PIN - 8); 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));
ADCSRA |= 1<<ADSC; // Start conversion ADCSRA |= 1<<ADSC; // Start conversion
#endif #endif
#ifdef ULTIPANEL #ifdef ULTIPANEL
buttons_check(); buttons_check();
#endif #endif
temp_state = 1; temp_state = 1;
break; break;
case 1: // Measure TEMP_0 case 1: // Measure TEMP_0
#if (TEMP_0_PIN > -1) #if (TEMP_0_PIN > -1)
raw_temp_0_value += ADC; raw_temp_0_value += ADC;
#endif #endif
temp_state = 2; temp_state = 2;
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; DIDR0 = 1<<TEMP_1_PIN;
#else #else
DIDR2 = 1<<(TEMP_1_PIN - 8); 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));
ADCSRA |= 1<<ADSC; // Start conversion ADCSRA |= 1<<ADSC; // Start conversion
#endif #endif
#ifdef ULTIPANEL #ifdef ULTIPANEL
buttons_check(); buttons_check();
#endif #endif
temp_state = 3; temp_state = 3;
break; break;
case 3: // Measure TEMP_1 case 3: // Measure TEMP_1
#if (TEMP_1_PIN > -1) #if (TEMP_1_PIN > -1)
raw_temp_1_value += ADC; raw_temp_1_value += ADC;
#endif #endif
temp_state = 4; temp_state = 4;
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; DIDR0 = 1 << TEMP_2_PIN;
#else #else
DIDR2 = 1<<(TEMP_2_PIN - 8); 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));
ADCSRA |= 1<<ADSC; // Start conversion ADCSRA |= 1<<ADSC; // Start conversion
#endif #endif
#ifdef ULTIPANEL #ifdef ULTIPANEL
buttons_check(); buttons_check();
#endif #endif
temp_state = 5; temp_state = 5;
break; break;
case 5: // Measure TEMP_2 case 5: // Measure TEMP_2
#if (TEMP_2_PIN > -1) #if (TEMP_2_PIN > -1)
raw_temp_2_value += ADC; raw_temp_2_value += ADC;
#endif #endif
temp_state = 0; temp_state = 0;
temp_count++; temp_count++;
break; break;
default: default:
Serial.println("!! Temp measurement error !!"); Serial.println("!! Temp measurement error !!");
break; break;
} }
if(temp_count >= 16) // 6 ms * 16 = 96ms. if(temp_count >= 16) // 6 ms * 16 = 96ms.
{ {
#ifdef HEATER_0_USES_AD595 #ifdef HEATER_0_USES_AD595
current_raw[0] = raw_temp_0_value; current_raw[0] = raw_temp_0_value;
#else #else
current_raw[0] = 16383 - raw_temp_0_value; current_raw[0] = 16383 - raw_temp_0_value;
#endif #endif
#ifdef HEATER_1_USES_AD595 #ifdef HEATER_1_USES_AD595
current_raw[2] = raw_temp_2_value; current_raw[2] = raw_temp_2_value;
#else #else
current_raw[2] = 16383 - raw_temp_2_value; current_raw[2] = 16383 - raw_temp_2_value;
#endif #endif
#ifdef BED_USES_AD595 #ifdef BED_USES_AD595
current_raw[1] = raw_temp_1_value; current_raw[1] = raw_temp_1_value;
#else #else
current_raw[1] = 16383 - raw_temp_1_value; current_raw[1] = 16383 - raw_temp_1_value;
#endif #endif
temp_meas_ready = true; temp_meas_ready = true;
temp_count = 0; temp_count = 0;
raw_temp_0_value = 0; raw_temp_0_value = 0;
raw_temp_1_value = 0; raw_temp_1_value = 0;
raw_temp_2_value = 0; raw_temp_2_value = 0;
#ifdef HEATER_0_MAXTEMP #ifdef HEATER_0_MAXTEMP
#if (HEATER_0_PIN > -1) #if (HEATER_0_PIN > -1)
if(current_raw[TEMPSENSOR_HOTEND] >= maxttemp) { if(current_raw[TEMPSENSOR_HOTEND_0] >= maxttemp_0) {
target_raw[TEMPSENSOR_HOTEND] = 0; target_raw[TEMPSENSOR_HOTEND_0] = 0;
analogWrite(HEATER_0_PIN, 0); analogWrite(HEATER_0_PIN, 0);
Serial.println("!! Temperature extruder 0 switched off. MAXTEMP triggered !!"); Serial.println("!! Temperature extruder 0 switched off. MAXTEMP triggered !!");
kill(); kill();
} }
#endif #endif
#endif #endif
if(current_raw[TEMPSENSOR_AUX] >= maxttemp) { #ifdef HEATER_1_MAXTEMP
target_raw[TEMPSENSOR_AUX] = 0; #if (HEATER_1_PIN > -1)
if(current_raw[2] >= maxttemp_1) { if(current_raw[TEMPSENSOR_HOTEND_1] >= maxttemp_1) {
analogWrite(HEATER_2_PIN, 0); target_raw[TEMPSENSOR_HOTEND_1] = 0;
Serial.println("!! Temperature extruder 1 switched off. MAXTEMP triggered !!"); if(current_raw[2] >= maxttemp_1) {
kill() analogWrite(HEATER_2_PIN, 0);
} Serial.println("!! Temperature extruder 1 switched off. MAXTEMP triggered !!");
#endif kill()
#endif //MAXTEMP }
#ifdef HEATER_0_MINTEMP #endif
#if (HEATER_0_PIN > -1) #endif //MAXTEMP
if(current_raw[TEMPSENSOR_HOTEND] <= minttemp) { #ifdef HEATER_0_MINTEMP
target_raw[TEMPSENSOR_HOTEND] = 0; #if (HEATER_0_PIN > -1)
analogWrite(HEATER_0_PIN, 0); if(current_raw[TEMPSENSOR_HOTEND_0] <= minttemp_0) {
Serial.println("!! Temperature extruder 0 switched off. MINTEMP triggered !!"); target_raw[TEMPSENSOR_HOTEND_0] = 0;
kill(); analogWrite(HEATER_0_PIN, 0);
} Serial.println("!! Temperature extruder 0 switched off. MINTEMP triggered !!");
#endif kill();
#endif }
#ifdef HEATER_1_MINTEMP #endif
#if (HEATER_2_PIN > -1) #endif
if(current_raw[TEMPSENSOR_AUX] <= minttemp) { #ifdef HEATER_1_MINTEMP
target_raw[TEMPSENSOR_AUX] = 0; #if (HEATER_2_PIN > -1)
analogWrite(HEATER_2_PIN, 0); if(current_raw[TEMPSENSOR_HOTEND_1] <= minttemp_1) {
Serial.println("!! Temperature extruder 1 switched off. MINTEMP triggered !!"); target_raw[TEMPSENSOR_HOTEND_1] = 0;
kill(); analogWrite(HEATER_2_PIN, 0);
} Serial.println("!! Temperature extruder 1 switched off. MINTEMP triggered !!");
#endif kill();
#endif //MAXTEMP }
#ifdef BED_MINTEMP #endif
#if (HEATER_1_PIN > -1) #endif //MAXTEMP
if(current_raw[1] <= bed_minttemp) { #ifdef BED_MINTEMP
target_raw[1] = 0; #if (HEATER_1_PIN > -1)
WRITE(HEATER_1_PIN, 0); if(current_raw[1] <= bed_minttemp) {
Serial.println("!! Temperatur heated bed switched off. MINTEMP triggered !!"); target_raw[1] = 0;
kill(); WRITE(HEATER_1_PIN, 0);
} Serial.println("!! Temperatur heated bed switched off. MINTEMP triggered !!");
#endif kill();
#endif }
#ifdef BED_MAXTEMP #endif
#if (HEATER_1_PIN > -1) #endif
if(current_raw[1] >= bed_maxttemp) { #ifdef BED_MAXTEMP
target_raw[1] = 0; #if (HEATER_1_PIN > -1)
WRITE(HEATER_1_PIN, 0); if(current_raw[1] >= bed_maxttemp) {
Serial.println("!! Temperature heated bed switched off. MAXTEMP triggered !!"); target_raw[1] = 0;
kill(); WRITE(HEATER_1_PIN, 0);
} Serial.println("!! Temperature heated bed switched off. MAXTEMP triggered !!");
#endif kill();
#endif }
} #endif
} #endif
}
}

@ -1,58 +1,58 @@
/* /*
temperature.h - temperature controller temperature.h - temperature controller
Part of Marlin Part of Marlin
Copyright (c) 2011 Erik van der Zalm Copyright (c) 2011 Erik van der Zalm
Grbl is free software: you can redistribute it and/or modify Grbl is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
Grbl is distributed in the hope that it will be useful, Grbl is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with Grbl. If not, see <http://www.gnu.org/licenses/>. along with Grbl. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef temperature_h #ifndef temperature_h
#define temperature_h #define temperature_h
#include "Marlin.h" #include "Marlin.h"
#ifdef PID_ADD_EXTRUSION_RATE #ifdef PID_ADD_EXTRUSION_RATE
#include "stepper.h" #include "stepper.h"
#endif #endif
void tp_init(); void tp_init();
void manage_heater(); void manage_heater();
//int temp2analogu(int celsius, const short table[][2], int numtemps); //int temp2analogu(int celsius, const short table[][2], int numtemps);
//float analog2tempu(int raw, const short table[][2], int numtemps); //float analog2tempu(int raw, const short table[][2], int numtemps);
int temp2analog(int celsius); int temp2analog(int celsius);
int temp2analogBed(int celsius); int temp2analogBed(int celsius);
float analog2temp(int raw); float analog2temp(int raw);
float analog2tempBed(int raw); float analog2tempBed(int raw);
#ifdef HEATER_USES_THERMISTOR #ifdef HEATER_0_USES_THERMISTOR
#define HEATERSOURCE 1 #define HEATERSOURCE 1
#endif #endif
#ifdef BED_USES_THERMISTOR #ifdef BED_USES_THERMISTOR
#define BEDSOURCE 1 #define BEDSOURCE 1
#endif #endif
//#define temp2analogh( c ) temp2analogu((c),temptable,NUMTEMPS) //#define temp2analogh( c ) temp2analogu((c),temptable,NUMTEMPS)
//#define analog2temp( c ) analog2tempu((c),temptable,NUMTEMPS //#define analog2temp( c ) analog2tempu((c),temptable,NUMTEMPS
extern float Kp; extern float Kp;
extern float Ki; extern float Ki;
extern float Kd; extern float Kd;
extern float Kc; extern float Kc;
enum {TEMPSENSOR_HOTEND=0,TEMPSENSOR_BED=1, TEMPSENSOR_AUX=2}; enum {TEMPSENSOR_HOTEND_0=0,TEMPSENSOR_BED=1, TEMPSENSOR_HOTEND_1=2};
extern int target_raw[3]; extern int target_raw[3];
extern int current_raw[3]; extern int current_raw[3];
extern double pid_setpoint; extern double pid_setpoint;
#endif #endif

@ -253,17 +253,17 @@ void MainMenu::showStatus()
} }
if((abs(current_raw[TEMPSENSOR_HOTEND]-oldcurrentraw)>3)||force_lcd_update) if((abs(current_raw[TEMPSENSOR_HOTEND_0]-oldcurrentraw)>3)||force_lcd_update)
{ {
lcd.setCursor(1,0); lcd.setCursor(1,0);
lcd.print(ftostr3(analog2temp(current_raw[TEMPSENSOR_HOTEND]))); lcd.print(ftostr3(analog2temp(current_raw[TEMPSENSOR_HOTEND_0])));
oldcurrentraw=current_raw[TEMPSENSOR_HOTEND]; oldcurrentraw=current_raw[TEMPSENSOR_HOTEND_0];
} }
if((target_raw[TEMPSENSOR_HOTEND]!=oldtargetraw)||force_lcd_update) if((target_raw[TEMPSENSOR_HOTEND_0]!=oldtargetraw)||force_lcd_update)
{ {
lcd.setCursor(5,0); lcd.setCursor(5,0);
lcd.print(ftostr3(analog2temp(target_raw[TEMPSENSOR_HOTEND]))); lcd.print(ftostr3(analog2temp(target_raw[TEMPSENSOR_HOTEND_0])));
oldtargetraw=target_raw[TEMPSENSOR_HOTEND]; oldtargetraw=target_raw[TEMPSENSOR_HOTEND_0];
} }
#if defined BED_USES_THERMISTOR || defined BED_USES_AD595 #if defined BED_USES_THERMISTOR || defined BED_USES_AD595
static int oldcurrentbedraw=-1; static int oldcurrentbedraw=-1;
@ -426,7 +426,7 @@ void MainMenu::showPrepare()
if((activeline==line) && CLICKED) if((activeline==line) && CLICKED)
{ {
BLOCK BLOCK
target_raw[TEMPSENSOR_HOTEND] = temp2analog(170); target_raw[TEMPSENSOR_HOTEND_0] = temp2analog(170);
beepshort(); beepshort();
} }
}break; }break;
@ -531,7 +531,7 @@ void MainMenu::showControl()
if(force_lcd_update) if(force_lcd_update)
{ {
lcd.setCursor(0,line);lcd.print(" \002Nozzle:"); lcd.setCursor(0,line);lcd.print(" \002Nozzle:");
lcd.setCursor(13,line);lcd.print(ftostr3(analog2temp(target_raw[TEMPSENSOR_HOTEND]))); lcd.setCursor(13,line);lcd.print(ftostr3(analog2temp(target_raw[TEMPSENSOR_HOTEND_0])));
} }
if((activeline==line) ) if((activeline==line) )
@ -541,11 +541,11 @@ void MainMenu::showControl()
linechanging=!linechanging; linechanging=!linechanging;
if(linechanging) if(linechanging)
{ {
encoderpos=(int)analog2temp(target_raw[TEMPSENSOR_HOTEND]); encoderpos=(int)analog2temp(target_raw[TEMPSENSOR_HOTEND_0]);
} }
else else
{ {
target_raw[TEMPSENSOR_HOTEND] = temp2analog(encoderpos); target_raw[TEMPSENSOR_HOTEND_0] = temp2analog(encoderpos);
encoderpos=activeline*lcdslow; encoderpos=activeline*lcdslow;
beepshort(); beepshort();
} }
@ -1590,4 +1590,4 @@ char *fillto(int8_t n,char *c)
#else #else
inline void lcd_status() {}; inline void lcd_status() {};
#endif #endif

Loading…
Cancel
Save