Revert "this is not working. Do you maybe know why?"
This reverts commit 8bcdb9f5f0
.
This commit is contained in:
parent
8bcdb9f5f0
commit
b9ea0651ec
@ -48,9 +48,9 @@ void StoreSettings() {
|
||||
EEPROM_writeAnything(i,max_xy_jerk);
|
||||
EEPROM_writeAnything(i,max_z_jerk);
|
||||
#ifdef PIDTEMP
|
||||
EEPROM_writeAnything(i,Heater::Kp);
|
||||
EEPROM_writeAnything(i,Heater::Ki);
|
||||
EEPROM_writeAnything(i,Heater::Kd);
|
||||
EEPROM_writeAnything(i,Kp);
|
||||
EEPROM_writeAnything(i,Ki);
|
||||
EEPROM_writeAnything(i,Kd);
|
||||
#else
|
||||
EEPROM_writeAnything(i,3000);
|
||||
EEPROM_writeAnything(i,0);
|
||||
@ -81,11 +81,11 @@ void RetrieveSettings(bool def=false){ // if def=true, the default values will
|
||||
EEPROM_readAnything(i,max_xy_jerk);
|
||||
EEPROM_readAnything(i,max_z_jerk);
|
||||
#ifndef PIDTEMP
|
||||
float Kp,Ki,Kd; //read and ignore..
|
||||
float Kp,Ki,Kd;
|
||||
#endif
|
||||
EEPROM_readAnything(i,Heater::Kp);
|
||||
EEPROM_readAnything(i,Heater::Ki);
|
||||
EEPROM_readAnything(i,Heater::Kd);
|
||||
EEPROM_readAnything(i,Kp);
|
||||
EEPROM_readAnything(i,Ki);
|
||||
EEPROM_readAnything(i,Kd);
|
||||
|
||||
ECHOLN("Stored settings retreived:");
|
||||
}
|
||||
@ -119,7 +119,7 @@ void RetrieveSettings(bool def=false){ // if def=true, the default values will
|
||||
ECHOLN(" M205 S" <<_FLOAT(minimumfeedrate/60,2) << " T" << _FLOAT(mintravelfeedrate/60,2) << " B" << _FLOAT(minsegmenttime,2) << " X" << _FLOAT(max_xy_jerk/60,2) << " Z" << _FLOAT(max_z_jerk/60,2));
|
||||
#ifdef PIDTEMP
|
||||
ECHOLN("PID settings:");
|
||||
ECHOLN(" M301 P" << _FLOAT(Heater::Kp,3) << " I" << _FLOAT(Heater::Ki,3) << " D" << _FLOAT(Heater::Kd,3));
|
||||
ECHOLN(" M301 P" << _FLOAT(Kp,3) << " I" << _FLOAT(Ki,3) << " D" << _FLOAT(Kd,3));
|
||||
#endif
|
||||
|
||||
}
|
||||
|
@ -10,7 +10,6 @@
|
||||
#define ECHO(x) Serial << "echo: " << x;
|
||||
#define ECHOLN(x) Serial << "echo: "<<x<<endl;
|
||||
|
||||
|
||||
void get_command();
|
||||
void process_commands();
|
||||
|
||||
|
@ -40,7 +40,6 @@
|
||||
#include "Simplelcd.h"
|
||||
#endif
|
||||
|
||||
Heater htr;
|
||||
char version_string[] = "1.0.0 Alpha 1";
|
||||
|
||||
#ifdef SDSUPPORT
|
||||
@ -264,7 +263,7 @@ void setup()
|
||||
#endif //SDSUPPORT
|
||||
plan_init(); // Initialize planner;
|
||||
st_init(); // Initialize stepper;
|
||||
//tp_init(); // Initialize temperature loop is now done by the constructor of the Heater class
|
||||
tp_init(); // Initialize temperature loop
|
||||
//checkautostart();
|
||||
}
|
||||
|
||||
@ -368,7 +367,7 @@ void loop()
|
||||
bufindr = (bufindr + 1)%BUFSIZE;
|
||||
}
|
||||
//check heater every n milliseconds
|
||||
Heater::manage_heater();
|
||||
manage_heater();
|
||||
manage_inactivity(1);
|
||||
LCD_STATUS;
|
||||
}
|
||||
@ -548,7 +547,7 @@ inline void process_commands()
|
||||
if(code_seen('S')) codenum = code_value() * 1000; // seconds to wait
|
||||
codenum += millis(); // keep track of when we started waiting
|
||||
while(millis() < codenum ){
|
||||
Heater::manage_heater();
|
||||
manage_heater();
|
||||
}
|
||||
break;
|
||||
case 28: //G28 Home all Axis one at a time
|
||||
@ -802,9 +801,12 @@ inline void process_commands()
|
||||
}
|
||||
break;
|
||||
case 104: // M104
|
||||
if (code_seen('S')) Heater::setCelsius(TEMPSENSOR_HOTEND,code_value());
|
||||
if (code_seen('S')) target_raw[TEMPSENSOR_HOTEND] = temp2analog(code_value());
|
||||
#ifdef PIDTEMP
|
||||
pid_setpoint = code_value();
|
||||
#endif //PIDTEM
|
||||
#ifdef WATCHPERIOD
|
||||
if(Heater::isHeating(TEMPSENSOR_HOTEND)){
|
||||
if(target_raw[TEMPSENSOR_HOTEND] > current_raw[TEMPSENSOR_HOTEND]){
|
||||
watchmillis = max(1,millis());
|
||||
watch_raw[TEMPSENSOR_HOTEND] = current_raw[TEMPSENSOR_HOTEND];
|
||||
}else{
|
||||
@ -813,14 +815,14 @@ inline void process_commands()
|
||||
#endif
|
||||
break;
|
||||
case 140: // M140 set bed temp
|
||||
if (code_seen('S')) Heater::setCelsius(TEMPSENSOR_BED,code_value());
|
||||
if (code_seen('S')) target_raw[TEMPSENSOR_BED] = temp2analogBed(code_value());
|
||||
break;
|
||||
case 105: // M105
|
||||
#if (TEMP_0_PIN > -1) || defined (HEATER_USES_AD595)
|
||||
tt = Heater::celsius(TEMPSENSOR_HOTEND);
|
||||
tt = analog2temp(current_raw[TEMPSENSOR_HOTEND]);
|
||||
#endif
|
||||
#if TEMP_1_PIN > -1
|
||||
bt = Heater::celsius(TEMPSENSOR_BED);
|
||||
bt = analog2tempBed(current_raw[TEMPSENSOR_BED]);
|
||||
#endif
|
||||
#if (TEMP_0_PIN > -1) || defined (HEATER_USES_AD595)
|
||||
Serial.print("ok T:");
|
||||
@ -831,14 +833,14 @@ inline void process_commands()
|
||||
#ifdef PIDTEMP
|
||||
Serial.print(" B:");
|
||||
#if TEMP_1_PIN > -1
|
||||
Serial.println(bt);
|
||||
Serial.println(bt);
|
||||
#else
|
||||
Serial.println(Heater::HeaterPower);
|
||||
Serial.println(HeaterPower);
|
||||
#endif
|
||||
#else
|
||||
Serial.println();
|
||||
#endif
|
||||
#else<
|
||||
#else
|
||||
Serial.println();
|
||||
#endif
|
||||
#else
|
||||
@ -848,12 +850,14 @@ inline void process_commands()
|
||||
//break;
|
||||
case 109: {// M109 - Wait for extruder heater to reach target.
|
||||
LCD_MESSAGE("Heating...");
|
||||
if (code_seen('S')) Heater::setCelsius(TEMPSENSOR_HOTEND,code_value());
|
||||
|
||||
if (code_seen('S')) target_raw[TEMPSENSOR_HOTEND] = temp2analog(code_value());
|
||||
#ifdef PIDTEMP
|
||||
pid_setpoint = code_value();
|
||||
#endif //PIDTEM
|
||||
#ifdef WATCHPERIOD
|
||||
if(Heater::isHeating(TEMPSENSOR_HOTEND)){
|
||||
if(target_raw[TEMPSENSOR_HOTEND]>current_raw[TEMPSENSOR_HOTEND]){
|
||||
watchmillis = max(1,millis());
|
||||
watch_raw[TEMPSENSOR_HOTEND] = Heater::current_raw[TEMPSENSOR_HOTEND];
|
||||
watch_raw[TEMPSENSOR_HOTEND] = current_raw[TEMPSENSOR_HOTEND];
|
||||
} else {
|
||||
watchmillis = 0;
|
||||
}
|
||||
@ -861,31 +865,31 @@ inline void process_commands()
|
||||
codenum = millis();
|
||||
|
||||
/* See if we are heating up or cooling down */
|
||||
bool target_direction = Heater::isHeating(TEMPSENSOR_HOTEND); // true if heating, false if cooling
|
||||
bool target_direction = (current_raw[0] < target_raw[0]); // true if heating, false if cooling
|
||||
|
||||
#ifdef TEMP_RESIDENCY_TIME
|
||||
long residencyStart;
|
||||
residencyStart = -1;
|
||||
/* continue to loop until we have reached the target temp
|
||||
_and_ until TEMP_RESIDENCY_TIME hasn't passed since we reached it */
|
||||
while((target_direction ? Heater::isHeating(TEMPSENSOR_HOTEND) : Heater::isCooling(TEMPSENSOR_HOTEND)) ||
|
||||
while((target_direction ? (current_raw[0] < target_raw[0]) : (current_raw[0] > target_raw[0])) ||
|
||||
(residencyStart > -1 && (millis() - residencyStart) < TEMP_RESIDENCY_TIME*1000) ) {
|
||||
#else
|
||||
while ( target_direction ? Heater::isHeating(TEMPSENSOR_HOTEND) : Heater::isCooling(TEMPSENSOR_HOTEND) ) {
|
||||
while ( target_direction ? (current_raw[0] < target_raw[0]) : (current_raw[0] > target_raw[0]) ) {
|
||||
#endif //TEMP_RESIDENCY_TIME
|
||||
if( (millis() - codenum) > 1000 ) { //Print Temp Reading every 1 second while heating up/cooling down
|
||||
Serial.print("T:");
|
||||
Serial.println( Heater::celsius(TEMPSENSOR_HOTEND) );
|
||||
Serial.println( analog2temp(current_raw[TEMPSENSOR_HOTEND]) );
|
||||
codenum = millis();
|
||||
}
|
||||
Heater::manage_heater();
|
||||
manage_heater();
|
||||
LCD_STATUS;
|
||||
#ifdef TEMP_RESIDENCY_TIME
|
||||
/* start/restart the TEMP_RESIDENCY_TIME timer whenever we reach target temp for the first time
|
||||
or when current temp falls outside the hysteresis after target temp was reached */
|
||||
if ((residencyStart == -1 && target_direction && !Heater::isHeating(TEMPSENSOR_HOTEND)) ||
|
||||
(residencyStart == -1 && !target_direction && !Heater::isCooling(TEMPSENSOR_HOTEND)) ||
|
||||
(residencyStart > -1 && labs(Heater::celsius(TEMPSENSOR_HOTEND) - Heater::celsiusTarget(TEMPSENSOR_HOTEND)) > TEMP_HYSTERESIS) ) {
|
||||
if ((residencyStart == -1 && target_direction && current_raw[0] >= target_raw[0]) ||
|
||||
(residencyStart == -1 && !target_direction && current_raw[0] <= target_raw[0]) ||
|
||||
(residencyStart > -1 && labs(analog2temp(current_raw[0]) - analog2temp(target_raw[0])) > TEMP_HYSTERESIS) ) {
|
||||
residencyStart = millis();
|
||||
}
|
||||
#endif //TEMP_RESIDENCY_TIME
|
||||
@ -895,22 +899,22 @@ inline void process_commands()
|
||||
break;
|
||||
case 190: // M190 - Wait bed for heater to reach target.
|
||||
#if TEMP_1_PIN > -1
|
||||
if (code_seen('S')) Heater::setCelsius(TEMPSENSOR_BED,code_value());
|
||||
if (code_seen('S')) target_raw[TEMPSENSOR_BED] = temp2analog(code_value());
|
||||
codenum = millis();
|
||||
while(Heater::isHeating(TEMPSENSOR_BED))
|
||||
{
|
||||
while(current_raw[TEMPSENSOR_BED] < target_raw[TEMPSENSOR_BED])
|
||||
{
|
||||
if( (millis()-codenum) > 1000 ) //Print Temp Reading every 1 second while heating up.
|
||||
{
|
||||
float tt=Heater::celsius(TEMPSENSOR_HOTEND);
|
||||
float tt=analog2temp(current_raw[TEMPSENSOR_HOTEND]);
|
||||
Serial.print("T:");
|
||||
Serial.println( tt );
|
||||
Serial.print("ok T:");
|
||||
Serial.print( tt );
|
||||
Serial.print(" B:");
|
||||
Serial.println( Heater::celsius(TEMPSENSOR_BED) );
|
||||
Serial.println( analog2temp(current_raw[TEMPSENSOR_BED]) );
|
||||
codenum = millis();
|
||||
}
|
||||
Heater::manage_heater();
|
||||
manage_heater();
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
@ -1062,13 +1066,9 @@ inline void process_commands()
|
||||
break;
|
||||
#ifdef PIDTEMP
|
||||
case 301: // M301
|
||||
if(code_seen('P')) Heater::Kp = code_value();
|
||||
if(code_seen('I')) Heater::Ki = code_value()*PID_dT;
|
||||
if(code_seen('D')) Heater::Kd = code_value()/PID_dT;
|
||||
#ifdef PID_ADD_EXTRUSION_RATE
|
||||
if(code_seen('C')) Heater::Kc = code_value();
|
||||
#endif
|
||||
|
||||
if(code_seen('P')) Kp = code_value();
|
||||
if(code_seen('I')) Ki = code_value()*PID_dT;
|
||||
if(code_seen('D')) Kd = code_value()/PID_dT;
|
||||
// ECHOLN("Kp "<<_FLOAT(Kp,2));
|
||||
// ECHOLN("Ki "<<_FLOAT(Ki/PID_dT,2));
|
||||
// ECHOLN("Kd "<<_FLOAT(Kd*PID_dT,2));
|
||||
@ -1194,19 +1194,19 @@ void wd_reset() {
|
||||
inline void kill()
|
||||
{
|
||||
#if TEMP_0_PIN > -1
|
||||
Heater::setCelsius(TEMPSENSOR_HOTEND,0);
|
||||
target_raw[0]=0;
|
||||
#if HEATER_0_PIN > -1
|
||||
WRITE(HEATER_0_PIN,LOW);
|
||||
#endif
|
||||
#endif
|
||||
#if TEMP_1_PIN > -1
|
||||
Heater::setCelsius(TEMPSENSOR_BED,0);
|
||||
target_raw[1]=0;
|
||||
#if HEATER_1_PIN > -1
|
||||
WRITE(HEATER_1_PIN,LOW);
|
||||
#endif
|
||||
#endif
|
||||
#if TEMP_2_PIN > -1
|
||||
Heater::setCelsius(TEMPSENSOR_AUX,0);
|
||||
target_raw[2]=0;
|
||||
#if HEATER_2_PIN > -1
|
||||
WRITE(HEATER_2_PIN,LOW);
|
||||
#endif
|
||||
|
@ -388,7 +388,7 @@ void plan_buffer_line(float x, float y, float z, float e, float feed_rate) {
|
||||
// If the buffer is full: good! That means we are well ahead of the robot.
|
||||
// Rest here until there is room in the buffer.
|
||||
while(block_buffer_tail == next_buffer_head) {
|
||||
htr.manage_heater();
|
||||
manage_heater();
|
||||
manage_inactivity(1);
|
||||
LCD_STATUS;
|
||||
}
|
||||
|
@ -585,7 +585,7 @@ void st_init()
|
||||
void st_synchronize()
|
||||
{
|
||||
while(plan_get_current_block()) {
|
||||
htr.manage_heater();
|
||||
manage_heater();
|
||||
manage_inactivity(1);
|
||||
LCD_STATUS;
|
||||
}
|
||||
|
@ -37,11 +37,52 @@
|
||||
#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
|
||||
|
||||
void static Heater::manage_heater()
|
||||
#ifdef MINTEMP
|
||||
int minttemp = temp2analog(MINTEMP);
|
||||
#endif //MINTEMP
|
||||
#ifdef MAXTEMP
|
||||
int maxttemp = temp2analog(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();
|
||||
@ -49,11 +90,11 @@ void static Heater::manage_heater()
|
||||
|
||||
float pid_input;
|
||||
float pid_output;
|
||||
if(htr.temp_meas_ready != true) //better readability
|
||||
if(temp_meas_ready != true) //better readability
|
||||
return;
|
||||
|
||||
CRITICAL_SECTION_START;
|
||||
htr.temp_meas_ready = false;
|
||||
temp_meas_ready = false;
|
||||
CRITICAL_SECTION_END;
|
||||
|
||||
#ifdef PIDTEMP
|
||||
@ -135,8 +176,7 @@ 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 const static temp2analog(const int celsius)
|
||||
{
|
||||
float temp2analog(int celsius) {
|
||||
#ifdef HEATER_USES_THERMISTOR_1
|
||||
int raw = 0;
|
||||
byte i;
|
||||
@ -167,8 +207,7 @@ float const static temp2analog(const 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 const static temp2analogBed(const int celsius)
|
||||
{
|
||||
float temp2analogBed(int celsius) {
|
||||
#ifdef BED_USES_THERMISTOR
|
||||
|
||||
int raw = 0;
|
||||
@ -198,7 +237,7 @@ float const static temp2analogBed(const int celsius)
|
||||
|
||||
// Derived from RepRap FiveD extruder::getTemperature()
|
||||
// For hot end temperature measurement.
|
||||
float const static Heater::analog2temp(const int raw) {
|
||||
float analog2temp(int raw) {
|
||||
#ifdef HEATER_1_USES_THERMISTOR
|
||||
int celsius = 0;
|
||||
byte i;
|
||||
@ -227,7 +266,7 @@ float const static Heater::analog2temp(const int raw) {
|
||||
|
||||
// Derived from RepRap FiveD extruder::getTemperature()
|
||||
// For bed temperature measurement.
|
||||
float const static Heater::analog2tempBed(const int raw) {
|
||||
float analog2tempBed(int raw) {
|
||||
#ifdef BED_USES_THERMISTOR
|
||||
int celsius = 0;
|
||||
byte i;
|
||||
@ -257,28 +296,8 @@ float const static Heater::analog2tempBed(const int raw) {
|
||||
#endif
|
||||
}
|
||||
|
||||
Heater::Heater()
|
||||
void tp_init()
|
||||
{
|
||||
for(short i=0;i<3;i++)
|
||||
{
|
||||
target_raw[i]=0;
|
||||
current_raw[i] =0;
|
||||
}
|
||||
htr.temp_meas_ready = false;
|
||||
#ifdef MINTEMP
|
||||
minttemp = temp2analog(MINTEMP);
|
||||
#endif //MINTEMP
|
||||
#ifdef MAXTEMP
|
||||
maxttemp = temp2analog(MAXTEMP);
|
||||
#endif //MAXTEMP
|
||||
|
||||
#ifdef BED_MINTEMP
|
||||
bed_minttemp = temp2analog(BED_MINTEMP);
|
||||
#endif //BED_MINTEMP
|
||||
#ifdef BED_MAXTEMP
|
||||
bed_maxttemp = temp2analog(BED_MAXTEMP);
|
||||
#endif //BED_MAXTEMP
|
||||
|
||||
#if (HEATER_0_PIN > -1)
|
||||
SET_OUTPUT(HEATER_0_PIN);
|
||||
#endif
|
||||
@ -292,14 +311,6 @@ Heater::Heater()
|
||||
#ifdef PIDTEMP
|
||||
temp_iState_min = 0.0;
|
||||
temp_iState_max = PID_INTEGRAL_DRIVE_MAX / Ki;
|
||||
temp_iState = 0;
|
||||
temp_dState = 0;
|
||||
Kp=DEFAULT_Kp;
|
||||
Ki=DEFAULT_Ki;
|
||||
Kd=DEFAULT_Kd;
|
||||
Kc=DEFAULT_Kc;
|
||||
pid_setpoint = 0.0;
|
||||
|
||||
#endif //PIDTEMP
|
||||
|
||||
// Set analog inputs
|
||||
@ -396,39 +407,39 @@ ISR(TIMER0_COMPB_vect)
|
||||
if(temp_count >= 16) // 6 ms * 16 = 96ms.
|
||||
{
|
||||
#ifdef HEATER_1_USES_AD595
|
||||
htr.current_raw[0] = raw_temp_0_value;
|
||||
current_raw[0] = raw_temp_0_value;
|
||||
#else
|
||||
htr.current_raw[0] = 16383 - raw_temp_0_value;
|
||||
current_raw[0] = 16383 - raw_temp_0_value;
|
||||
#endif
|
||||
|
||||
#ifdef HEATER_2_USES_AD595
|
||||
htr.current_raw[2] = raw_temp_2_value;
|
||||
current_raw[2] = raw_temp_2_value;
|
||||
#else
|
||||
htr.current_raw[2] = 16383 - raw_temp_2_value;
|
||||
current_raw[2] = 16383 - raw_temp_2_value;
|
||||
#endif
|
||||
|
||||
#ifdef BED_USES_AD595
|
||||
htr.current_raw[1] = raw_temp_1_value;
|
||||
current_raw[1] = raw_temp_1_value;
|
||||
#else
|
||||
htr.current_raw[1] = 16383 - raw_temp_1_value;
|
||||
current_raw[1] = 16383 - raw_temp_1_value;
|
||||
#endif
|
||||
|
||||
htr.temp_meas_ready = true;
|
||||
temp_meas_ready = true;
|
||||
temp_count = 0;
|
||||
raw_temp_0_value = 0;
|
||||
raw_temp_1_value = 0;
|
||||
raw_temp_2_value = 0;
|
||||
#ifdef MAXTEMP
|
||||
#if (HEATER_0_PIN > -1)
|
||||
if(htr.current_raw[TEMPSENSOR_HOTEND] >= htr.maxttemp) {
|
||||
htr.target_raw[TEMPSENSOR_HOTEND] = 0;
|
||||
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 !!");
|
||||
}
|
||||
#endif
|
||||
#if (HEATER_2_PIN > -1)
|
||||
if(htr.current_raw[TEMPSENSOR_AUX] >= htr.maxttemp) {
|
||||
htr.target_raw[TEMPSENSOR_AUX] = 0;
|
||||
if(current_raw[TEMPSENSOR_AUX] >= maxttemp) {
|
||||
target_raw[TEMPSENSOR_AUX] = 0;
|
||||
analogWrite(HEATER_2_PIN, 0);
|
||||
Serial.println("!! Temperature extruder 1 switched off. MAXTEMP triggered !!");
|
||||
}
|
||||
@ -436,15 +447,15 @@ ISR(TIMER0_COMPB_vect)
|
||||
#endif //MAXTEMP
|
||||
#ifdef MINTEMP
|
||||
#if (HEATER_0_PIN > -1)
|
||||
if(htr.current_raw[TEMPSENSOR_HOTEND] <= htr.minttemp) {
|
||||
htr.target_raw[TEMPSENSOR_HOTEND] = 0;
|
||||
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 !!");
|
||||
}
|
||||
#endif
|
||||
#if (HEATER_2_PIN > -1)
|
||||
if(htr.current_raw[TEMPSENSOR_AUX] <= htr.minttemp) {
|
||||
htr.target_raw[TEMPSENSOR_AUX] = 0;
|
||||
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 !!");
|
||||
}
|
||||
@ -452,8 +463,8 @@ ISR(TIMER0_COMPB_vect)
|
||||
#endif //MAXTEMP
|
||||
#ifdef BED_MINTEMP
|
||||
#if (HEATER_1_PIN > -1)
|
||||
if(htr.current_raw[1] <= htr.bed_minttemp) {
|
||||
htr.target_raw[1] = 0;
|
||||
if(current_raw[1] <= bed_minttemp) {
|
||||
target_raw[1] = 0;
|
||||
WRITE(HEATER_1_PIN, 0);
|
||||
Serial.println("!! Temperatur heated bed switched off. MINTEMP triggered !!");
|
||||
}
|
||||
@ -461,8 +472,8 @@ ISR(TIMER0_COMPB_vect)
|
||||
#endif
|
||||
#ifdef BED_MAXTEMP
|
||||
#if (HEATER_1_PIN > -1)
|
||||
if(htr.current_raw[1] >= htr.bed_maxttemp) {
|
||||
htr.target_raw[1] = 0;
|
||||
if(current_raw[1] >= bed_maxttemp) {
|
||||
target_raw[1] = 0;
|
||||
WRITE(HEATER_1_PIN, 0);
|
||||
Serial.println("!! Temperature heated bed switched off. MAXTEMP triggered !!");
|
||||
}
|
||||
@ -470,6 +481,3 @@ ISR(TIMER0_COMPB_vect)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
//Heater htr;
|
||||
|
||||
|
@ -25,116 +25,14 @@
|
||||
#ifdef PID_ADD_EXTRUSION_RATE
|
||||
#include "stepper.h"
|
||||
#endif
|
||||
|
||||
enum TempSensor {TEMPSENSOR_HOTEND=0,TEMPSENSOR_BED=1, TEMPSENSOR_AUX=2};
|
||||
|
||||
// ther must be only one instance of this class, and it is created in temperature.cpp by itself and is called "htr".
|
||||
// all the variables are static, so that of the compiler optimization is more easy.
|
||||
// I honestly hope that this increases readability and structure.
|
||||
// none of the variables or routines should be called from an secondary process/interrupt with the exceptino of current_raw[].
|
||||
|
||||
class Heater
|
||||
{
|
||||
public:
|
||||
Heater(); //treplaces tp_init();
|
||||
~Heater();
|
||||
|
||||
void static manage_heater(); /// it is critical that this is called continously.
|
||||
|
||||
// conversion routines, const since they don't change any class variables.
|
||||
float const static temp2analog(const int celsius);
|
||||
float const static temp2analogBed(const int celsius);
|
||||
float const static analog2temp(const int raw);
|
||||
float const static analog2tempBed(const int raw);
|
||||
|
||||
inline float const static celsius(const TempSensor s)
|
||||
{
|
||||
if(s==TEMPSENSOR_BED)
|
||||
return analog2tempBed(Heater::current_raw[s]);
|
||||
else
|
||||
return analog2temp(Heater::current_raw[s]);
|
||||
};
|
||||
inline float const static celsiusTarget(const TempSensor s)
|
||||
{
|
||||
if(s==TEMPSENSOR_BED)
|
||||
return analog2tempBed(Heater::target_raw[s]);
|
||||
else
|
||||
return analog2temp(Heater::target_raw[s]);
|
||||
};
|
||||
inline float static setCelsius(const TempSensor s, const int celsius)
|
||||
{
|
||||
#ifdef PIDTEMP
|
||||
if(s==TEMPSENSOR_HOTEND)
|
||||
Heater::pid_setpoint = celsius;
|
||||
#endif //PIDTEM
|
||||
if(s==TEMPSENSOR_BED)
|
||||
Heater::target_raw[s] = temp2analog(celsius);
|
||||
else
|
||||
Heater::target_raw[s] = temp2analogBed(celsius);
|
||||
};
|
||||
|
||||
inline bool const static isHeating(TempSensor s)
|
||||
{ return (Heater::target_raw[s]>Heater::current_raw[s]);};
|
||||
inline bool const static isCooling(TempSensor s)
|
||||
{ return (Heater::target_raw[s]<Heater::current_raw[s]);};
|
||||
|
||||
public:
|
||||
#ifdef PIDTEMP
|
||||
static float Kp;
|
||||
static float Ki;
|
||||
static float Kd;
|
||||
static float Kc;
|
||||
#endif
|
||||
|
||||
static int target_raw[3];
|
||||
static float pid_setpoint;
|
||||
|
||||
volatile static int current_raw[3]; //this are written by an ISR, so volatile.
|
||||
volatile static bool temp_meas_ready ; //also this is set by the ISR
|
||||
|
||||
|
||||
private:
|
||||
|
||||
|
||||
|
||||
static unsigned long previous_millis_heater, previous_millis_bed_heater;
|
||||
|
||||
#ifdef PIDTEMP
|
||||
static float temp_iState;
|
||||
static float temp_dState;
|
||||
static float pTerm;
|
||||
static float iTerm;
|
||||
static float dTerm;
|
||||
//int output;
|
||||
static float pid_error;
|
||||
static float temp_iState_min;
|
||||
static float temp_iState_max;
|
||||
static float pid_input;
|
||||
static float pid_output;
|
||||
|
||||
static bool pid_reset;
|
||||
static float HeaterPower;
|
||||
|
||||
#endif //PIDTEMP
|
||||
|
||||
public: //but only accesed from the ISR hence not volatile
|
||||
#ifdef MINTEMP
|
||||
static int minttemp;
|
||||
#endif //MINTEMP
|
||||
#ifdef MAXTEMP
|
||||
static int maxttemp;
|
||||
#endif //MAXTEMP
|
||||
|
||||
#ifdef BED_MINTEMP
|
||||
static int bed_minttemp ;
|
||||
#endif //BED_MINTEMP
|
||||
#ifdef BED_MAXTEMP
|
||||
static int bed_maxttemp;
|
||||
#endif //BED_MAXTEMP
|
||||
|
||||
};
|
||||
|
||||
extern Heater htr; //this creates the single, global instance
|
||||
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);
|
||||
float analog2temp(int raw);
|
||||
float analog2tempBed(int raw);
|
||||
|
||||
#ifdef HEATER_USES_THERMISTOR
|
||||
#define HEATERSOURCE 1
|
||||
@ -143,5 +41,18 @@ extern Heater htr; //this creates the single, global instance
|
||||
#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
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include "ultralcd.h"
|
||||
#include "temperature.h"
|
||||
|
||||
|
||||
#ifdef ULTRA_LCD
|
||||
extern volatile int feedmultiply;
|
||||
@ -238,8 +238,8 @@ extern volatile bool feedmultiplychanged;
|
||||
void MainMenu::showStatus()
|
||||
{
|
||||
#if LCD_HEIGHT==4
|
||||
static int oldcurrent=-1;
|
||||
static int oldtarget=-1;
|
||||
static int oldcurrentraw=-1;
|
||||
static int oldtargetraw=-1;
|
||||
//force_lcd_update=true;
|
||||
if(force_lcd_update||feedmultiplychanged) //initial display of content
|
||||
{
|
||||
@ -252,36 +252,33 @@ void MainMenu::showStatus()
|
||||
#endif
|
||||
}
|
||||
|
||||
int tt=Heater::celsius(TEMPSENSOR_HOTEND);
|
||||
if((abs(tt-oldcurrent)>1)||force_lcd_update)
|
||||
|
||||
if((abs(current_raw[TEMPSENSOR_HOTEND]-oldcurrentraw)>3)||force_lcd_update)
|
||||
{
|
||||
lcd.setCursor(1,0);
|
||||
lcd.print(ftostr3(tt));
|
||||
oldcurrent=tt;
|
||||
lcd.print(ftostr3(analog2temp(current_raw[TEMPSENSOR_HOTEND])));
|
||||
oldcurrentraw=current_raw[TEMPSENSOR_HOTEND];
|
||||
}
|
||||
int ttg=Heater::celsiusTarget(TEMPSENSOR_HOTEND);
|
||||
if((ttg!=oldtarget)||force_lcd_update)
|
||||
if((target_raw[TEMPSENSOR_HOTEND]!=oldtargetraw)||force_lcd_update)
|
||||
{
|
||||
lcd.setCursor(5,0);
|
||||
lcd.print(ftostr3(ttg));
|
||||
oldtarget=ttg;
|
||||
lcd.print(ftostr3(analog2temp(target_raw[TEMPSENSOR_HOTEND])));
|
||||
oldtargetraw=target_raw[TEMPSENSOR_HOTEND];
|
||||
}
|
||||
#if defined BED_USES_THERMISTOR || defined BED_USES_AD595
|
||||
static int oldcurrentbed=-1;
|
||||
static int oldtargetbed=-1;
|
||||
int tb=Heater::celsius(TEMPSENSOR_BED);
|
||||
if((tb!=oldcurrentbed)||force_lcd_update)
|
||||
static int oldcurrentbedraw=-1;
|
||||
static int oldtargetbedraw=-1;
|
||||
if((current_bed_raw!=oldcurrentbedraw)||force_lcd_update)
|
||||
{
|
||||
lcd.setCursor(1,0);
|
||||
lcd.print(ftostr3(tb));
|
||||
oldcurrentbed=tb;
|
||||
lcd.print(ftostr3(analog2temp(current_bed_raw)));
|
||||
oldcurrentraw=current_raw[TEMPSENSOR_BED];
|
||||
}
|
||||
int tg=Heater::celsiusTarget(TEMPSENSOR_BED);
|
||||
if((tg!=oldtargebed)||force_lcd_update)
|
||||
if((target_bed_raw!=oldtargebedtraw)||force_lcd_update)
|
||||
{
|
||||
lcd.setCursor(5,0);
|
||||
lcd.print(Heater::celsiusTarget(TEMPSENSOR_BED));
|
||||
oldtargebed=tg;
|
||||
lcd.print(ftostr3(analog2temp(target_bed_raw)));
|
||||
oldtargetraw=target_bed_raw;
|
||||
}
|
||||
#endif
|
||||
//starttime=2;
|
||||
@ -330,8 +327,8 @@ void MainMenu::showStatus()
|
||||
messagetext[0]='\0';
|
||||
}
|
||||
#else //smaller LCDS----------------------------------
|
||||
static int oldcurrent=-1;
|
||||
static int oldtarget=-1;
|
||||
static int oldcurrentraw=-1;
|
||||
static int oldtargetraw=-1;
|
||||
if(force_lcd_update) //initial display of content
|
||||
{
|
||||
encoderpos=feedmultiply;
|
||||
@ -341,19 +338,18 @@ void MainMenu::showStatus()
|
||||
#endif
|
||||
}
|
||||
|
||||
int tt=Heater::celsius(TEMPSENSOR_HOTEND);
|
||||
if((abs(tt-oldcurrent)>1)||force_lcd_update)
|
||||
|
||||
if((abs(current_raw[TEMPSENSOR_HOTEND]-oldcurrentraw)>3)||force_lcd_update)
|
||||
{
|
||||
lcd.setCursor(1,0);
|
||||
lcd.print(ftostr3(tt));
|
||||
oldcurrent=tt;
|
||||
lcd.print(ftostr3(analog2temp(current_raw[TEMPSENSOR_HOTEND])));
|
||||
oldcurrentraw=current_raw[TEMPSENSOR_HOTEND];
|
||||
}
|
||||
int ttg=Heater::celsiusTarget(TEMPSENSOR_HOTEND);
|
||||
if((ttg!=oldtarget)||force_lcd_update)
|
||||
if((target_raw[TEMPSENSOR_HOTEND]!=oldtargetraw)||force_lcd_update)
|
||||
{
|
||||
lcd.setCursor(5,0);
|
||||
lcd.print(ftostr3(ttg));
|
||||
oldtarge=ttg;
|
||||
lcd.print(ftostr3(analog2temp(target_raw[TEMPSENSOR_HOTEND])));
|
||||
oldtargetraw=target_raw[TEMPSENSOR_HOTEND];
|
||||
}
|
||||
|
||||
if(messagetext[0]!='\0')
|
||||
@ -430,7 +426,7 @@ void MainMenu::showPrepare()
|
||||
if((activeline==line) && CLICKED)
|
||||
{
|
||||
BLOCK
|
||||
Heater::setCelsius(TEMPSENSOR_HOTEND, 170);
|
||||
target_raw[TEMPSENSOR_HOTEND] = temp2analog(170);
|
||||
beepshort();
|
||||
}
|
||||
}break;
|
||||
@ -535,7 +531,7 @@ void MainMenu::showControl()
|
||||
if(force_lcd_update)
|
||||
{
|
||||
lcd.setCursor(0,line);lcd.print(" \002Nozzle:");
|
||||
lcd.setCursor(13,line);lcd.print(ftostr3(Heater::celsiusTarget(TEMPSENSOR_HOTEND)));
|
||||
lcd.setCursor(13,line);lcd.print(ftostr3(analog2temp(target_raw[TEMPSENSOR_HOTEND])));
|
||||
}
|
||||
|
||||
if((activeline==line) )
|
||||
@ -545,11 +541,11 @@ void MainMenu::showControl()
|
||||
linechanging=!linechanging;
|
||||
if(linechanging)
|
||||
{
|
||||
encoderpos=(int)Heater::celsiusTarget(TEMPSENSOR_HOTEND);
|
||||
encoderpos=(int)analog2temp(target_raw[TEMPSENSOR_HOTEND]);
|
||||
}
|
||||
else
|
||||
{
|
||||
Heater::setCelsius(TEMPSENSOR_HOTEND,encoderpos);
|
||||
target_raw[TEMPSENSOR_HOTEND] = temp2analog(encoderpos);
|
||||
encoderpos=activeline*lcdslow;
|
||||
beepshort();
|
||||
}
|
||||
@ -673,7 +669,7 @@ void MainMenu::showControl()
|
||||
if(force_lcd_update)
|
||||
{
|
||||
lcd.setCursor(0,line);lcd.print(" PID-P: ");
|
||||
lcd.setCursor(13,line);lcd.print(itostr4(Heater::Kp));
|
||||
lcd.setCursor(13,line);lcd.print(itostr4(Kp));
|
||||
}
|
||||
|
||||
if((activeline==line) )
|
||||
@ -683,11 +679,11 @@ void MainMenu::showControl()
|
||||
linechanging=!linechanging;
|
||||
if(linechanging)
|
||||
{
|
||||
encoderpos=(int)Heater::Kp/5;
|
||||
encoderpos=(int)Kp/5;
|
||||
}
|
||||
else
|
||||
{
|
||||
Heater::Kp= encoderpos*5;
|
||||
Kp= encoderpos*5;
|
||||
encoderpos=activeline*lcdslow;
|
||||
|
||||
}
|
||||
@ -707,7 +703,7 @@ void MainMenu::showControl()
|
||||
if(force_lcd_update)
|
||||
{
|
||||
lcd.setCursor(0,line);lcd.print(" PID-I: ");
|
||||
lcd.setCursor(13,line);lcd.print(ftostr51(Heater::Ki));
|
||||
lcd.setCursor(13,line);lcd.print(ftostr51(Ki));
|
||||
}
|
||||
|
||||
if((activeline==line) )
|
||||
@ -717,11 +713,11 @@ void MainMenu::showControl()
|
||||
linechanging=!linechanging;
|
||||
if(linechanging)
|
||||
{
|
||||
encoderpos=(int)(Heater::Ki*10);
|
||||
encoderpos=(int)(Ki*10);
|
||||
}
|
||||
else
|
||||
{
|
||||
Heater::Ki= encoderpos/10.;
|
||||
Ki= encoderpos/10.;
|
||||
encoderpos=activeline*lcdslow;
|
||||
|
||||
}
|
||||
@ -741,7 +737,7 @@ void MainMenu::showControl()
|
||||
if(force_lcd_update)
|
||||
{
|
||||
lcd.setCursor(0,line);lcd.print(" PID-D: ");
|
||||
lcd.setCursor(13,line);lcd.print(itostr4(Heater::Kd));
|
||||
lcd.setCursor(13,line);lcd.print(itostr4(Kd));
|
||||
}
|
||||
|
||||
if((activeline==line) )
|
||||
@ -751,11 +747,11 @@ void MainMenu::showControl()
|
||||
linechanging=!linechanging;
|
||||
if(linechanging)
|
||||
{
|
||||
encoderpos=(int)(Heater::Kd/5.);
|
||||
encoderpos=(int)Kd/5;
|
||||
}
|
||||
else
|
||||
{
|
||||
Heater::Kd= encoderpos*5;
|
||||
Kd= encoderpos*5;
|
||||
encoderpos=activeline*lcdslow;
|
||||
|
||||
}
|
||||
@ -778,7 +774,7 @@ void MainMenu::showControl()
|
||||
if(force_lcd_update)
|
||||
{
|
||||
lcd.setCursor(0,line);lcd.print(" PID-C: ");
|
||||
lcd.setCursor(13,line);lcd.print(itostr3(Heater::Kc));
|
||||
lcd.setCursor(13,line);lcd.print(itostr3(Kc));
|
||||
}
|
||||
|
||||
if((activeline==line) )
|
||||
@ -788,11 +784,11 @@ void MainMenu::showControl()
|
||||
linechanging=!linechanging;
|
||||
if(linechanging)
|
||||
{
|
||||
encoderpos=(int)Heater::Kc;
|
||||
encoderpos=(int)Kc;
|
||||
}
|
||||
else
|
||||
{
|
||||
Heater::Kc= encoderpos;
|
||||
Kc= encoderpos;
|
||||
encoderpos=activeline*lcdslow;
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user