Skip to content

Commit

Permalink
Temperature changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikZalm committed Nov 5, 2011
1 parent d7c4f07 commit d15f01e
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 87 deletions.
22 changes: 12 additions & 10 deletions Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
#define THERMISTORHEATER_2 3
#define THERMISTORBED 3

//#define HEATER_0_USES_THERMISTOR
//#define HEATER_1_USES_THERMISTOR
//#define HEATER_2_USES_THERMISTOR
#define HEATER_1_USES_AD595
//#define HEATER_2_USES_AD595
#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
Expand All @@ -47,8 +47,8 @@ const bool ENDSTOPS_INVERTING = true; // set to true to invert the logic of the
// 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 250000
//#define BAUDRATE 115200
//#define BAUDRATE 230400

// Comment out (using // at the start of the line) to disable SD support:
Expand All @@ -57,7 +57,7 @@ const bool ENDSTOPS_INVERTING = true; // set to true to invert the logic of the
#define LCD_WIDTH 16
#define LCD_HEIGHT 2

//#define ULTIPANEL
#define ULTIPANEL
#ifdef ULTIPANEL
//#define NEWPANEL //enable this if you have a click-encoder panel
#define SDSUPPORT
Expand Down Expand Up @@ -157,15 +157,17 @@ const int dropsegments=5; //everything with this number of steps will be ignore
//#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 MINTEMP 5
#define BED_MINTEMP 5
#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 MAXTEMP 275
#define BED_MAXTEMP 150
#define HEATER_0_MAXTEMP 275
//#define_HEATER_1_MAXTEMP 275
//#define BED_MAXTEMP 150

/// PID settings:
// Uncomment the following line to enable PID support.
Expand Down
2 changes: 1 addition & 1 deletion Marlin/Marlin.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void ClearToSend();

void get_coordinates();
void prepare_move();
void kill(byte debug);
void kill();

//void check_axes_activity();
//void plan_init();
Expand Down
2 changes: 2 additions & 0 deletions Marlin/Marlin.pde
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ char version_string[] = "1.0.0 Alpha 1";
//-------------------
// G0 -> G1
// G1 - Coordinated Movement X Y Z E
// G2 - CW ARC
// G3 - CCW ARC
// G4 - Dwell S<seconds> or P<milliseconds>
// G28 - Home all Axis
// G90 - Use Absolute Coordinates
Expand Down
86 changes: 51 additions & 35 deletions Marlin/temperature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,18 @@ unsigned long previous_millis_heater, previous_millis_bed_heater;
float Kc=DEFAULT_Kc;
#endif //PIDTEMP

#ifdef MINTEMP
int minttemp = temp2analog(MINTEMP);
#ifdef HEATER_0_MINTEMP
int minttemp_0 = temp2analog(HEATER_0_MINTEMP);
#endif //MINTEMP
#ifdef MAXTEMP
int maxttemp = temp2analog(MAXTEMP);
#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
Expand Down Expand Up @@ -173,29 +180,28 @@ CRITICAL_SECTION_END;
// 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.
float temp2analog(int celsius) {
#ifdef HEATER_USES_THERMISTOR_1
int temp2analog(int celsius) {
#ifdef HEATER_0_USES_THERMISTOR
int raw = 0;
byte i;

for (i=1; i<NUMTEMPS_HEATER_1; i++)
for (i=1; i<NUMTEMPS_HEATER_0; i++)
{
if (temptable_1[i][1] < celsius)
if (heater_0_temptable[i][1] < celsius)
{
raw = temptable_1[i-1][0] +
(celsius - temptable_1[i-1][1]) *
(temptable_1[i][0] - temptable_1[i-1][0]) /
(temptable_1[i][1] - temptable_1[i-1][1]);

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_1) raw = temptable_1[i-1][0];
if (i == NUMTEMPS_0) raw = heater_0_temptable[i-1][0];

return (1023 * OVERSAMPLENR) - raw;
#elif defined HEATER_1_USES_AD595
#elif defined HEATER_0_USES_AD595
return celsius * (1024.0 / (5.0 * 100.0) ) * OVERSAMPLENR;
#endif
}
Expand All @@ -204,7 +210,7 @@ float temp2analog(int celsius) {
// 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.
float temp2analogBed(int celsius) {
int temp2analogBed(int celsius) {
#ifdef BED_USES_THERMISTOR

int raw = 0;
Expand Down Expand Up @@ -235,28 +241,28 @@ float temp2analogBed(int celsius) {
// Derived from RepRap FiveD extruder::getTemperature()
// For hot end temperature measurement.
float analog2temp(int raw) {
#ifdef HEATER_1_USES_THERMISTOR
int celsius = 0;
#ifdef HEATER_0_USES_THERMISTOR
float celsius = 0;
byte i;
raw = (1023 * OVERSAMPLENR) - raw;
for (i=1; i<NUMTEMPS_HEATER_1; i++)
for (i=1; i<NUMTEMPS_HEATER_0; i++)
{
if (temptable_1[i][0] > raw)
if (heater_0_temptable[i][0] > raw)
{
celsius = temptable_1[i-1][1] +
(raw - temptable_1[i-1][0]) *
(temptable_1[i][1] - temptable_1[i-1][1]) /
(temptable_1[i][0] - temptable_1[i-1][0]);
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_1) celsius = temptable_1[i-1][1];
if (i == NUMTEMPS_HEATER_0) celsius = heater_0_temptable[i-1][1];

return celsius;
#elif defined HEATER_1_USES_AD595
#elif defined HEATER_0_USES_AD595
return raw * ((5.0 * 100.0) / 1024.0) / OVERSAMPLENR;
#endif
}
Expand Down Expand Up @@ -403,13 +409,13 @@ ISR(TIMER0_COMPB_vect)

if(temp_count >= 16) // 6 ms * 16 = 96ms.
{
#ifdef HEATER_1_USES_AD595
#ifdef HEATER_0_USES_AD595
current_raw[0] = raw_temp_0_value;
#else
current_raw[0] = 16383 - raw_temp_0_value;
#endif

#ifdef HEATER_2_USES_AD595
#ifdef HEATER_1_USES_AD595
current_raw[2] = raw_temp_2_value;
#else
current_raw[2] = 16383 - raw_temp_2_value;
Expand All @@ -426,35 +432,43 @@ ISR(TIMER0_COMPB_vect)
raw_temp_0_value = 0;
raw_temp_1_value = 0;
raw_temp_2_value = 0;
#ifdef MAXTEMP
#ifdef HEATER_0_MAXTEMP
#if (HEATER_0_PIN > -1)
if(current_raw[0] >= maxttemp) {
if(current_raw[0] >= maxttemp_0) {
target_raw[0] = 0;
analogWrite(HEATER_0_PIN, 0);
Serial.println("!! Temperature extruder 0 switched off. MAXTEMP triggered !!");
kill();
}
#endif
#if (HEATER_2_PIN > -1)
if(current_raw[2] >= maxttemp) {
#endif
#ifdef HEATER_1_MAXTEMP
#if (HEATER_1_PIN > -1)
if(current_raw[2] >= maxttemp_1) {
target_raw[2] = 0;
analogWrite(HEATER_2_PIN, 0);
Serial.println("!! Temperature extruder 1 switched off. MAXTEMP triggered !!");
kill()
}
#endif
#endif //MAXTEMP
#ifdef MINTEMP
#ifdef HEATER_0_MINTEMP
#if (HEATER_0_PIN > -1)
if(current_raw[0] <= minttemp) {
if(current_raw[0] <= minttemp_0) {
target_raw[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[2] <= minttemp) {
if(current_raw[2] <= minttemp_1) {
target_raw[2] = 0;
analogWrite(HEATER_2_PIN, 0);
Serial.println("!! Temperature extruder 1 switched off. MINTEMP triggered !!");
kill();
}
#endif
#endif //MAXTEMP
Expand All @@ -464,6 +478,7 @@ ISR(TIMER0_COMPB_vect)
target_raw[1] = 0;
WRITE(HEATER_1_PIN, 0);
Serial.println("!! Temperatur heated bed switched off. MINTEMP triggered !!");
kill();
}
#endif
#endif
Expand All @@ -473,6 +488,7 @@ ISR(TIMER0_COMPB_vect)
target_raw[1] = 0;
WRITE(HEATER_1_PIN, 0);
Serial.println("!! Temperature heated bed switched off. MAXTEMP triggered !!");
kill();
}
#endif
#endif
Expand Down
4 changes: 2 additions & 2 deletions Marlin/temperature.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ 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);
float temp2analog(int celsius);
float temp2analogBed(int celsius);
int temp2analog(int celsius);
int temp2analogBed(int celsius);
float analog2temp(int raw);
float analog2tempBed(int raw);

Expand Down
Loading

0 comments on commit d15f01e

Please sign in to comment.