Corrected temp variables.

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

@ -1,245 +1,245 @@
#ifndef CONFIGURATION_H
#define CONFIGURATION_H
//#define DEBUG_STEPS
// 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
// MEGA/RAMPS up to 1.2 = 3,
// RAMPS 1.3 = 33
// Gen6 = 5,
// Sanguinololu 1.2 and above = 62
// Ultimaker = 7,
#define MOTHERBOARD 7
//#define MOTHERBOARD 5
//// Thermistor settings:
// 1 is 100k thermistor
// 2 is 200k thermistor
// 3 is mendel-parts thermistor
// 4 is 10k thermistor
// 5 is ParCan supplied 104GT-2 100K
// 6 is EPCOS 100k
// 7 is 100k Honeywell thermistor 135-104LAG-J01
#define THERMISTORHEATER_1 3
#define THERMISTORHEATER_2 3
#define THERMISTORBED 3
//#define HEATER_0_USES_THERMISTOR
//#define HEATER_1_USES_THERMISTOR
#define HEATER_0_USES_AD595
//#define HEATER_1_USES_AD595
// Select one of these only to define how the bed temp is read.
//#define BED_USES_THERMISTOR
//#define BED_USES_AD595
#define HEATER_CHECK_INTERVAL 50
#define BED_CHECK_INTERVAL 5000
//// Endstop Settings
#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.
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
// This determines the communication speed of the printer
#define BAUDRATE 250000
//#define BAUDRATE 115200
//#define BAUDRATE 230400
// Comment out (using // at the start of the line) to disable SD support:
// #define ULTRA_LCD //any lcd
#define ULTIPANEL
#define ULTIPANEL
#ifdef ULTIPANEL
//#define NEWPANEL //enable this if you have a click-encoder panel
#define SDSUPPORT
#define ULTRA_LCD
#define LCD_WIDTH 20
#define LCD_HEIGHT 4
#else //no panel but just lcd
#ifdef ULTRA_LCD
#define LCD_WIDTH 16
#define LCD_HEIGHT 2
#endif
#endif
//#define SDSUPPORT // Enable SD Card Support in Hardware Console
const int dropsegments=5; //everything with this number of steps will be ignored as move
//// ADVANCED SETTINGS - to tweak parameters
#include "thermistortables.h"
// For Inverting Stepper Enable Pins (Active Low) use 0, Non Inverting (Active High) use 1
#define X_ENABLE_ON 0
#define Y_ENABLE_ON 0
#define Z_ENABLE_ON 0
#define E_ENABLE_ON 0
// Disables axis when it's not being used.
#define DISABLE_X false
#define DISABLE_Y false
#define DISABLE_Z false
#define DISABLE_E false
// Inverting axis direction
#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_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
//// ENDSTOP SETTINGS:
// Sets direction of endstops when homing; 1=MAX, -1=MIN
#define X_HOME_DIR -1
#define Y_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 max_software_endstops false //If true, axis won't move to coordinates greater than the defined lengths below.
#define X_MAX_LENGTH 210
#define Y_MAX_LENGTH 210
#define Z_MAX_LENGTH 210
//// MOVEMENT SETTINGS
#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.
#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.
//!!!!!!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
#define TRAVELING_AT_MAXSPEED
#define AXIS_RELATIVE_MODES {false, false, false, false}
#define MAX_STEP_FREQUENCY 40000 // Max step frequency for Ultimaker (5000 pps / half step)
// default settings
#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_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_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_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.
#define DEFAULT_MINSEGMENTTIME 20000
#define DEFAULT_XYJERK 30.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
//this enables the watchdog interrupt.
#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:
#define RESET_MANUAL
#define WATCHDOG_TIMEOUT 4
//// Experimental watchdog and minimal temp
// 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
//#define WATCHPERIOD 5000 //5 seconds
// Actual temperature must be close to target for this long before M109 returns success
//#define TEMP_RESIDENCY_TIME 20 // (seconds)
//#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
#define HEATER_0_MINTEMP 5
//#define HEATER_1_MINTEMP 5
//#define BED_MINTEMP 5
// 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!
// You should use MINTEMP for thermistor short/failure protection.
#define HEATER_0_MAXTEMP 275
//#define_HEATER_1_MAXTEMP 275
//#define BED_MAXTEMP 150
#define PIDTEMP
#ifdef PIDTEMP
/// PID settings:
// Uncomment the following line to enable PID support.
//#define SMOOTHING
//#define SMOOTHFACTOR 5.0
//float current_raw_average=0;
#define K1 0.95 //smoothing of the PID
//#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_MAX 255 // limits current to nozzle
#define PID_INTEGRAL_DRIVE_MAX 255
#define PID_dT 0.1
//machine with red silicon: 1950:45 second ; with fan fully blowin 3000:47
#define PID_CRITIAL_GAIN 3000
#define PID_SWING_AT_CRITIAL 45 //seconds
#define PIDIADD 5
/*
//PID according to Ziegler-Nichols method
float Kp = 0.6*PID_CRITIAL_GAIN;
float Ki =PIDIADD+2*Kp/PID_SWING_AT_CRITIAL*PID_dT;
float Kd = Kp*PID_SWING_AT_CRITIAL/8./PID_dT;
*/
//PI according to Ziegler-Nichols method
#define DEFAULT_Kp (PID_CRITIAL_GAIN/2.2)
#define DEFAULT_Ki (1.2*Kp/PID_SWING_AT_CRITIAL*PID_dT)
#define DEFAULT_Kd (0)
#define PID_ADD_EXTRUSION_RATE
#ifdef PID_ADD_EXTRUSION_RATE
#define DEFAULT_Kc (5) //heatingpower=Kc*(e_speed)
#endif
#endif // PIDTEMP
// extruder advance constant (s2/mm3)
//
// advance (steps) = STEPS_PER_CUBIC_MM_E * EXTUDER_ADVANCE_K * cubic mm per second ^ 2
//
// hooke's law says: force = k * distance
// 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
//#define ADVANCE
#ifdef ADVANCE
#define EXTRUDER_ADVANCE_K .3
#define D_FILAMENT 1.7
#define STEPS_MM_E 65
#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)
#endif // ADVANCE
// THE BLOCK_BUFFER_SIZE NEEDS TO BE A POWER OF 2, e.g. 8,16,32
#if defined SDSUPPORT
// 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
#else
#define BLOCK_BUFFER_SIZE 16 // maximize block buffer
#endif
#endif
#ifndef CONFIGURATION_H
#define CONFIGURATION_H
//#define DEBUG_STEPS
// 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
// MEGA/RAMPS up to 1.2 = 3,
// RAMPS 1.3 = 33
// Gen6 = 5,
// Sanguinololu 1.2 and above = 62
// Ultimaker = 7,
#define MOTHERBOARD 7
//#define MOTHERBOARD 5
//// Thermistor settings:
// 1 is 100k thermistor
// 2 is 200k thermistor
// 3 is mendel-parts thermistor
// 4 is 10k thermistor
// 5 is ParCan supplied 104GT-2 100K
// 6 is EPCOS 100k
// 7 is 100k Honeywell thermistor 135-104LAG-J01
#define THERMISTORHEATER_1 3
#define THERMISTORHEATER_2 3
#define THERMISTORBED 3
//#define HEATER_0_USES_THERMISTOR
//#define HEATER_1_USES_THERMISTOR
#define HEATER_0_USES_AD595
//#define HEATER_1_USES_AD595
// Select one of these only to define how the bed temp is read.
//#define BED_USES_THERMISTOR
//#define BED_USES_AD595
#define HEATER_CHECK_INTERVAL 50
#define BED_CHECK_INTERVAL 5000
//// Endstop Settings
#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.
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
// This determines the communication speed of the printer
#define BAUDRATE 250000
//#define BAUDRATE 115200
//#define BAUDRATE 230400
// Comment out (using // at the start of the line) to disable SD support:
// #define ULTRA_LCD //any lcd
#define ULTIPANEL
#define ULTIPANEL
#ifdef ULTIPANEL
//#define NEWPANEL //enable this if you have a click-encoder panel
#define SDSUPPORT
#define ULTRA_LCD
#define LCD_WIDTH 20
#define LCD_HEIGHT 4
#else //no panel but just lcd
#ifdef ULTRA_LCD
#define LCD_WIDTH 16
#define LCD_HEIGHT 2
#endif
#endif
//#define SDSUPPORT // Enable SD Card Support in Hardware Console
const int dropsegments=5; //everything with this number of steps will be ignored as move
//// ADVANCED SETTINGS - to tweak parameters
#include "thermistortables.h"
// For Inverting Stepper Enable Pins (Active Low) use 0, Non Inverting (Active High) use 1
#define X_ENABLE_ON 0
#define Y_ENABLE_ON 0
#define Z_ENABLE_ON 0
#define E_ENABLE_ON 0
// Disables axis when it's not being used.
#define DISABLE_X false
#define DISABLE_Y false
#define DISABLE_Z false
#define DISABLE_E false
// Inverting axis direction
#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_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
//// ENDSTOP SETTINGS:
// Sets direction of endstops when homing; 1=MAX, -1=MIN
#define X_HOME_DIR -1
#define Y_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 max_software_endstops false //If true, axis won't move to coordinates greater than the defined lengths below.
#define X_MAX_LENGTH 210
#define Y_MAX_LENGTH 210
#define Z_MAX_LENGTH 210
//// MOVEMENT SETTINGS
#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.
#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.
//!!!!!!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
#define TRAVELING_AT_MAXSPEED
#define AXIS_RELATIVE_MODES {false, false, false, false}
#define MAX_STEP_FREQUENCY 40000 // Max step frequency for Ultimaker (5000 pps / half step)
// default settings
#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_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_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_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.
#define DEFAULT_MINSEGMENTTIME 20000
#define DEFAULT_XYJERK 30.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
//this enables the watchdog interrupt.
#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:
#define RESET_MANUAL
#define WATCHDOG_TIMEOUT 4
//// Experimental watchdog and minimal temp
// 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
//#define WATCHPERIOD 5000 //5 seconds
// Actual temperature must be close to target for this long before M109 returns success
//#define TEMP_RESIDENCY_TIME 20 // (seconds)
//#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
#define HEATER_0_MINTEMP 5
//#define HEATER_1_MINTEMP 5
//#define BED_MINTEMP 5
// 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!
// You should use MINTEMP for thermistor short/failure protection.
#define HEATER_0_MAXTEMP 275
//#define_HEATER_1_MAXTEMP 275
//#define BED_MAXTEMP 150
#define PIDTEMP
#ifdef PIDTEMP
/// PID settings:
// Uncomment the following line to enable PID support.
//#define SMOOTHING
//#define SMOOTHFACTOR 5.0
//float current_raw_average=0;
#define K1 0.95 //smoothing of the PID
//#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_MAX 255 // limits current to nozzle
#define PID_INTEGRAL_DRIVE_MAX 255
#define PID_dT 0.1
//machine with red silicon: 1950:45 second ; with fan fully blowin 3000:47
#define PID_CRITIAL_GAIN 3000
#define PID_SWING_AT_CRITIAL 45 //seconds
#define PIDIADD 5
/*
//PID according to Ziegler-Nichols method
float Kp = 0.6*PID_CRITIAL_GAIN;
float Ki =PIDIADD+2*Kp/PID_SWING_AT_CRITIAL*PID_dT;
float Kd = Kp*PID_SWING_AT_CRITIAL/8./PID_dT;
*/
//PI according to Ziegler-Nichols method
#define DEFAULT_Kp (PID_CRITIAL_GAIN/2.2)
#define DEFAULT_Ki (1.2*Kp/PID_SWING_AT_CRITIAL*PID_dT)
#define DEFAULT_Kd (0)
#define PID_ADD_EXTRUSION_RATE
#ifdef PID_ADD_EXTRUSION_RATE
#define DEFAULT_Kc (5) //heatingpower=Kc*(e_speed)
#endif
#endif // PIDTEMP
// extruder advance constant (s2/mm3)
//
// advance (steps) = STEPS_PER_CUBIC_MM_E * EXTUDER_ADVANCE_K * cubic mm per second ^ 2
//
// hooke's law says: force = k * distance
// 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
//#define ADVANCE
#ifdef ADVANCE
#define EXTRUDER_ADVANCE_K .3
#define D_FILAMENT 1.7
#define STEPS_MM_E 65
#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)
#endif // ADVANCE
// THE BLOCK_BUFFER_SIZE NEEDS TO BE A POWER OF 2, e.g. 8,16,32
#if defined SDSUPPORT
// 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
#else
#define BLOCK_BUFFER_SIZE 16 // maximize block buffer
#endif
#endif

File diff suppressed because it is too large Load Diff

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

@ -1,58 +1,58 @@
/*
temperature.h - temperature controller
Part of Marlin
Copyright (c) 2011 Erik van der Zalm
Grbl is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Grbl is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Grbl. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef temperature_h
#define temperature_h
#include "Marlin.h"
#ifdef PID_ADD_EXTRUSION_RATE
#include "stepper.h"
#endif
void tp_init();
void manage_heater();
//int temp2analogu(int celsius, const short table[][2], int numtemps);
//float analog2tempu(int raw, const short table[][2], int numtemps);
int temp2analog(int celsius);
int temp2analogBed(int celsius);
float analog2temp(int raw);
float analog2tempBed(int raw);
#ifdef HEATER_USES_THERMISTOR
#define HEATERSOURCE 1
#endif
#ifdef BED_USES_THERMISTOR
#define BEDSOURCE 1
#endif
//#define temp2analogh( c ) temp2analogu((c),temptable,NUMTEMPS)
//#define analog2temp( c ) analog2tempu((c),temptable,NUMTEMPS
extern float Kp;
extern float Ki;
extern float Kd;
extern float Kc;
enum {TEMPSENSOR_HOTEND=0,TEMPSENSOR_BED=1, TEMPSENSOR_AUX=2};
extern int target_raw[3];
extern int current_raw[3];
extern double pid_setpoint;
#endif
/*
temperature.h - temperature controller
Part of Marlin
Copyright (c) 2011 Erik van der Zalm
Grbl is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Grbl is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Grbl. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef temperature_h
#define temperature_h
#include "Marlin.h"
#ifdef PID_ADD_EXTRUSION_RATE
#include "stepper.h"
#endif
void tp_init();
void manage_heater();
//int temp2analogu(int celsius, const short table[][2], int numtemps);
//float analog2tempu(int raw, const short table[][2], int numtemps);
int temp2analog(int celsius);
int temp2analogBed(int celsius);
float analog2temp(int raw);
float analog2tempBed(int raw);
#ifdef HEATER_0_USES_THERMISTOR
#define HEATERSOURCE 1
#endif
#ifdef BED_USES_THERMISTOR
#define BEDSOURCE 1
#endif
//#define temp2analogh( c ) temp2analogu((c),temptable,NUMTEMPS)
//#define analog2temp( c ) analog2tempu((c),temptable,NUMTEMPS
extern float Kp;
extern float Ki;
extern float Kd;
extern float Kc;
enum {TEMPSENSOR_HOTEND_0=0,TEMPSENSOR_BED=1, TEMPSENSOR_HOTEND_1=2};
extern int target_raw[3];
extern int current_raw[3];
extern double pid_setpoint;
#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.print(ftostr3(analog2temp(current_raw[TEMPSENSOR_HOTEND])));
oldcurrentraw=current_raw[TEMPSENSOR_HOTEND];
lcd.print(ftostr3(analog2temp(current_raw[TEMPSENSOR_HOTEND_0])));
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.print(ftostr3(analog2temp(target_raw[TEMPSENSOR_HOTEND])));
oldtargetraw=target_raw[TEMPSENSOR_HOTEND];
lcd.print(ftostr3(analog2temp(target_raw[TEMPSENSOR_HOTEND_0])));
oldtargetraw=target_raw[TEMPSENSOR_HOTEND_0];
}
#if defined BED_USES_THERMISTOR || defined BED_USES_AD595
static int oldcurrentbedraw=-1;
@ -426,7 +426,7 @@ void MainMenu::showPrepare()
if((activeline==line) && CLICKED)
{
BLOCK
target_raw[TEMPSENSOR_HOTEND] = temp2analog(170);
target_raw[TEMPSENSOR_HOTEND_0] = temp2analog(170);
beepshort();
}
}break;
@ -531,7 +531,7 @@ void MainMenu::showControl()
if(force_lcd_update)
{
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) )
@ -541,11 +541,11 @@ void MainMenu::showControl()
linechanging=!linechanging;
if(linechanging)
{
encoderpos=(int)analog2temp(target_raw[TEMPSENSOR_HOTEND]);
encoderpos=(int)analog2temp(target_raw[TEMPSENSOR_HOTEND_0]);
}
else
{
target_raw[TEMPSENSOR_HOTEND] = temp2analog(encoderpos);
target_raw[TEMPSENSOR_HOTEND_0] = temp2analog(encoderpos);
encoderpos=activeline*lcdslow;
beepshort();
}
@ -1590,4 +1590,4 @@ char *fillto(int8_t n,char *c)
#else
inline void lcd_status() {};
#endif

Loading…
Cancel
Save