Big temperature code update. No longer converts back and forwards between temperature and raw sample value. Reducing complexity, removing code. Also named some variables better. While keeping the safety intact and functionality the same.
This commit is contained in:
@ -37,19 +37,14 @@
|
||||
//===========================================================================
|
||||
//=============================public variables============================
|
||||
//===========================================================================
|
||||
int target_raw[EXTRUDERS] = { 0 };
|
||||
int target_raw_bed = 0;
|
||||
#ifdef BED_LIMIT_SWITCHING
|
||||
int target_bed_low_temp =0;
|
||||
int target_bed_high_temp =0;
|
||||
#endif
|
||||
int current_raw[EXTRUDERS] = { 0 };
|
||||
int current_raw_bed = 0;
|
||||
int target_temperature[EXTRUDERS] = { 0 };
|
||||
int target_temperature_bed = 0;
|
||||
int current_temperature_raw[EXTRUDERS] = { 0 };
|
||||
float current_temperature[EXTRUDERS] = { 0 };
|
||||
int current_temperature_bed_raw = 0;
|
||||
float current_temperature_bed = 0;
|
||||
|
||||
#ifdef PIDTEMP
|
||||
// used external
|
||||
float pid_setpoint[EXTRUDERS] = { 0.0 };
|
||||
|
||||
float Kp=DEFAULT_Kp;
|
||||
float Ki=(DEFAULT_Ki*PID_dT);
|
||||
float Kd=(DEFAULT_Kd/PID_dT);
|
||||
@ -59,9 +54,6 @@ int current_raw_bed = 0;
|
||||
#endif //PIDTEMP
|
||||
|
||||
#ifdef PIDTEMPBED
|
||||
// used external
|
||||
float pid_setpoint_bed = { 0.0 };
|
||||
|
||||
float bedKp=DEFAULT_bedKp;
|
||||
float bedKi=(DEFAULT_bedKi*PID_dT);
|
||||
float bedKd=(DEFAULT_bedKd/PID_dT);
|
||||
@ -116,12 +108,20 @@ static volatile bool temp_meas_ready = false;
|
||||
#endif
|
||||
|
||||
// Init min and max temp with extreme values to prevent false errors during startup
|
||||
static int minttemp[EXTRUDERS] = ARRAY_BY_EXTRUDERS(0, 0, 0);
|
||||
static int maxttemp[EXTRUDERS] = ARRAY_BY_EXTRUDERS(16383, 16383, 16383); // the first value used for all
|
||||
static int bed_minttemp = 0;
|
||||
static int bed_maxttemp = 16383;
|
||||
static void *heater_ttbl_map[EXTRUDERS] = ARRAY_BY_EXTRUDERS((void *)heater_0_temptable, (void *)heater_1_temptable, (void *)heater_2_temptable);
|
||||
static int heater_ttbllen_map[EXTRUDERS] = ARRAY_BY_EXTRUDERS(heater_0_temptable_len, heater_1_temptable_len, heater_2_temptable_len);
|
||||
static int minttemp_raw[EXTRUDERS] = ARRAY_BY_EXTRUDERS( HEATER_0_RAW_LO_TEMP , HEATER_1_RAW_LO_TEMP , HEATER_2_RAW_LO_TEMP );
|
||||
static int maxttemp_raw[EXTRUDERS] = ARRAY_BY_EXTRUDERS( HEATER_0_RAW_HI_TEMP , HEATER_1_RAW_HI_TEMP , HEATER_2_RAW_HI_TEMP );
|
||||
static int minttemp[EXTRUDERS] = ARRAY_BY_EXTRUDERS( 0, 0, 0 );
|
||||
static int maxttemp[EXTRUDERS] = ARRAY_BY_EXTRUDERS( 16383, 16383, 16383 );
|
||||
//static int bed_minttemp_raw = HEATER_BED_RAW_LO_TEMP; /* No bed mintemp error implemented?!? */
|
||||
#ifdef BED_MAXTEMP
|
||||
static int bed_maxttemp_raw = HEATER_BED_RAW_HI_TEMP;
|
||||
#endif
|
||||
static void *heater_ttbl_map[EXTRUDERS] = ARRAY_BY_EXTRUDERS( (void *)HEATER_0_TEMPTABLE, (void *)HEATER_1_TEMPTABLE, (void *)HEATER_2_TEMPTABLE );
|
||||
static int heater_ttbllen_map[EXTRUDERS] = ARRAY_BY_EXTRUDERS( HEATER_0_TEMPTABLE_LEN, HEATER_1_TEMPTABLE_LEN, HEATER_2_TEMPTABLE_LEN );
|
||||
|
||||
static float analog2temp(int raw, uint8_t e);
|
||||
static float analog2tempBed(int raw);
|
||||
static void updateTemperaturesFromRawValues();
|
||||
|
||||
#ifdef WATCH_TEMP_PERIOD
|
||||
int watch_start_temp[EXTRUDERS] = ARRAY_BY_EXTRUDERS(0,0,0);
|
||||
@ -179,13 +179,9 @@ void PID_autotune(float temp, int extruder, int ncycles)
|
||||
for(;;) {
|
||||
|
||||
if(temp_meas_ready == true) { // temp sample ready
|
||||
//Reset the watchdog after we know we have a temperature measurement.
|
||||
watchdog_reset();
|
||||
|
||||
CRITICAL_SECTION_START;
|
||||
temp_meas_ready = false;
|
||||
CRITICAL_SECTION_END;
|
||||
input = (extruder<0)?analog2tempBed(current_raw_bed):analog2temp(current_raw[extruder], extruder);
|
||||
updateTemperaturesFromRawValues();
|
||||
|
||||
input = (extruder<0)?current_temperature_bed:current_temperature[extruder];
|
||||
|
||||
max=max(max,input);
|
||||
min=min(min,input);
|
||||
@ -313,21 +309,16 @@ void manage_heater()
|
||||
if(temp_meas_ready != true) //better readability
|
||||
return;
|
||||
|
||||
//Reset the watchdog after we know we have a temperature measurement.
|
||||
watchdog_reset();
|
||||
|
||||
CRITICAL_SECTION_START;
|
||||
temp_meas_ready = false;
|
||||
CRITICAL_SECTION_END;
|
||||
updateTemperaturesFromRawValues();
|
||||
|
||||
for(int e = 0; e < EXTRUDERS; e++)
|
||||
{
|
||||
|
||||
#ifdef PIDTEMP
|
||||
pid_input = analog2temp(current_raw[e], e);
|
||||
pid_input = current_temperature[e];
|
||||
|
||||
#ifndef PID_OPENLOOP
|
||||
pid_error[e] = pid_setpoint[e] - pid_input;
|
||||
pid_error[e] = target_temperature[e] - pid_input;
|
||||
if(pid_error[e] > 10) {
|
||||
pid_output = PID_MAX;
|
||||
pid_reset[e] = true;
|
||||
@ -354,20 +345,20 @@ void manage_heater()
|
||||
pid_output = constrain(pTerm[e] + iTerm[e] - dTerm[e], 0, PID_MAX);
|
||||
}
|
||||
#else
|
||||
pid_output = constrain(pid_setpoint[e], 0, PID_MAX);
|
||||
pid_output = constrain(target_temperature[e], 0, PID_MAX);
|
||||
#endif //PID_OPENLOOP
|
||||
#ifdef PID_DEBUG
|
||||
SERIAL_ECHOLN(" PIDDEBUG "<<e<<": Input "<<pid_input<<" Output "<<pid_output" pTerm "<<pTerm[e]<<" iTerm "<<iTerm[e]<<" dTerm "<<dTerm[e]);
|
||||
#endif //PID_DEBUG
|
||||
#else /* PID off */
|
||||
pid_output = 0;
|
||||
if(current_raw[e] < target_raw[e]) {
|
||||
if(current_temperature[e] < target_temperature[e]) {
|
||||
pid_output = PID_MAX;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Check if temperature is within the correct range
|
||||
if((current_raw[e] > minttemp[e]) && (current_raw[e] < maxttemp[e]))
|
||||
if((current_temperature[e] > minttemp[e]) && (current_temperature[e] < maxttemp[e]))
|
||||
{
|
||||
soft_pwm[e] = (int)pid_output >> 1;
|
||||
}
|
||||
@ -393,19 +384,19 @@ void manage_heater()
|
||||
} // End extruder for loop
|
||||
|
||||
|
||||
#ifndef PIDTEMPBED
|
||||
#ifndef PIDTEMPBED
|
||||
if(millis() - previous_millis_bed_heater < BED_CHECK_INTERVAL)
|
||||
return;
|
||||
previous_millis_bed_heater = millis();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if TEMP_BED_PIN > -1
|
||||
#if TEMP_SENSOR_BED != 0
|
||||
|
||||
#ifdef PIDTEMPBED
|
||||
pid_input = analog2tempBed(current_raw_bed);
|
||||
#ifdef PIDTEMPBED
|
||||
pid_input = current_temperature_bed;
|
||||
|
||||
#ifndef PID_OPENLOOP
|
||||
pid_error_bed = pid_setpoint_bed - pid_input;
|
||||
pid_error_bed = target_temperature_bed - pid_input;
|
||||
pTerm_bed = bedKp * pid_error_bed;
|
||||
temp_iState_bed += pid_error_bed;
|
||||
temp_iState_bed = constrain(temp_iState_bed, temp_iState_min_bed, temp_iState_max_bed);
|
||||
@ -419,10 +410,10 @@ void manage_heater()
|
||||
pid_output = constrain(pTerm_bed + iTerm_bed - dTerm_bed, 0, MAX_BED_POWER);
|
||||
|
||||
#else
|
||||
pid_output = constrain(pid_setpoint_bed, 0, MAX_BED_POWER);
|
||||
pid_output = constrain(target_temperature_bed, 0, MAX_BED_POWER);
|
||||
#endif //PID_OPENLOOP
|
||||
|
||||
if((current_raw_bed > bed_minttemp) && (current_raw_bed < bed_maxttemp))
|
||||
if((current_temperature_bed > BED_MINTEMP) && (current_temperature_bed < BED_MAXTEMP))
|
||||
{
|
||||
soft_pwm_bed = (int)pid_output >> 1;
|
||||
}
|
||||
@ -432,35 +423,38 @@ void manage_heater()
|
||||
|
||||
#elif not defined BED_LIMIT_SWITCHING
|
||||
// Check if temperature is within the correct range
|
||||
if((current_raw_bed > bed_minttemp) && (current_raw_bed < bed_maxttemp)) {
|
||||
if(current_raw_bed >= target_raw_bed)
|
||||
if((current_temperature_bed > BED_MAXTEMP) && (current_temperature_bed < BED_MINTEMP))
|
||||
{
|
||||
if(current_temperature_bed >= target_temperature_bed)
|
||||
{
|
||||
soft_pwm_bed = 0;
|
||||
soft_pwm_bed = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
soft_pwm_bed = MAX_BED_POWER>>1;
|
||||
soft_pwm_bed = MAX_BED_POWER>>1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
soft_pwm_bed = 0;
|
||||
else
|
||||
{
|
||||
soft_pwm_bed = 0;
|
||||
WRITE(HEATER_BED_PIN,LOW);
|
||||
}
|
||||
#else //#ifdef BED_LIMIT_SWITCHING
|
||||
// Check if temperature is within the correct band
|
||||
if((current_raw_bed > bed_minttemp) && (current_raw_bed < bed_maxttemp)) {
|
||||
if(current_raw_bed > target_bed_high_temp)
|
||||
if((current_temperature_bed > BED_MINTEMP) && (current_temperature_bed < BED_MAXTEMP))
|
||||
{
|
||||
if(current_temperature_bed > target_temperature_bed + BED_HYSTERESIS)
|
||||
{
|
||||
soft_pwm_bed = 0;
|
||||
soft_pwm_bed = 0;
|
||||
}
|
||||
else
|
||||
if(current_raw_bed <= target_bed_low_temp)
|
||||
else if(current_temperature_bed <= target_temperature_bed - BED_HYSTERESIS)
|
||||
{
|
||||
soft_pwm_bed = MAX_BED_POWER>>1;
|
||||
soft_pwm_bed = MAX_BED_POWER>>1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
soft_pwm_bed = 0;
|
||||
else
|
||||
{
|
||||
soft_pwm_bed = 0;
|
||||
WRITE(HEATER_BED_PIN,LOW);
|
||||
}
|
||||
#endif
|
||||
@ -468,86 +462,9 @@ void manage_heater()
|
||||
}
|
||||
|
||||
#define PGM_RD_W(x) (short)pgm_read_word(&x)
|
||||
// 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, uint8_t e) {
|
||||
if(e >= EXTRUDERS)
|
||||
{
|
||||
SERIAL_ERROR_START;
|
||||
SERIAL_ERROR((int)e);
|
||||
SERIAL_ERRORLNPGM(" - Invalid extruder number!");
|
||||
kill();
|
||||
}
|
||||
#ifdef HEATER_0_USES_MAX6675
|
||||
if (e == 0)
|
||||
{
|
||||
return celsius * 4;
|
||||
}
|
||||
#endif
|
||||
if(heater_ttbl_map[e] != 0)
|
||||
{
|
||||
int raw = 0;
|
||||
byte i;
|
||||
short (*tt)[][2] = (short (*)[][2])(heater_ttbl_map[e]);
|
||||
|
||||
for (i=1; i<heater_ttbllen_map[e]; i++)
|
||||
{
|
||||
if (PGM_RD_W((*tt)[i][1]) < celsius)
|
||||
{
|
||||
raw = PGM_RD_W((*tt)[i-1][0]) +
|
||||
(celsius - PGM_RD_W((*tt)[i-1][1])) *
|
||||
(PGM_RD_W((*tt)[i][0]) - PGM_RD_W((*tt)[i-1][0])) /
|
||||
(PGM_RD_W((*tt)[i][1]) - PGM_RD_W((*tt)[i-1][1]));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Overflow: Set to last value in the table
|
||||
if (i == heater_ttbllen_map[e]) raw = PGM_RD_W((*tt)[i-1][0]);
|
||||
|
||||
return (1023 * OVERSAMPLENR) - raw;
|
||||
}
|
||||
return ((celsius-TEMP_SENSOR_AD595_OFFSET)/TEMP_SENSOR_AD595_GAIN) * (1024.0 / (5.0 * 100.0) ) * OVERSAMPLENR;
|
||||
}
|
||||
|
||||
// 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<bedtemptable_len; i++)
|
||||
{
|
||||
if (PGM_RD_W(bedtemptable[i][1]) < celsius)
|
||||
{
|
||||
raw = PGM_RD_W(bedtemptable[i-1][0]) +
|
||||
(celsius - PGM_RD_W(bedtemptable[i-1][1])) *
|
||||
(PGM_RD_W(bedtemptable[i][0]) - PGM_RD_W(bedtemptable[i-1][0])) /
|
||||
(PGM_RD_W(bedtemptable[i][1]) - PGM_RD_W(bedtemptable[i-1][1]));
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Overflow: Set to last value in the table
|
||||
if (i == bedtemptable_len) raw = PGM_RD_W(bedtemptable[i-1][0]);
|
||||
|
||||
return (1023 * OVERSAMPLENR) - raw;
|
||||
#elif defined BED_USES_AD595
|
||||
return lround(((celsius-TEMP_SENSOR_AD595_OFFSET)/TEMP_SENSOR_AD595_GAIN) * (1024.0 * OVERSAMPLENR/ (5.0 * 100.0) ) );
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Derived from RepRap FiveD extruder::getTemperature()
|
||||
// For hot end temperature measurement.
|
||||
float analog2temp(int raw, uint8_t e) {
|
||||
static float analog2temp(int raw, uint8_t e) {
|
||||
if(e >= EXTRUDERS)
|
||||
{
|
||||
SERIAL_ERROR_START;
|
||||
@ -565,10 +482,9 @@ float analog2temp(int raw, uint8_t e) {
|
||||
if(heater_ttbl_map[e] != NULL)
|
||||
{
|
||||
float celsius = 0;
|
||||
byte i;
|
||||
byte i;
|
||||
short (*tt)[][2] = (short (*)[][2])(heater_ttbl_map[e]);
|
||||
|
||||
raw = (1023 * OVERSAMPLENR) - raw;
|
||||
for (i=1; i<heater_ttbllen_map[e]; i++)
|
||||
{
|
||||
if (PGM_RD_W((*tt)[i][0]) > raw)
|
||||
@ -591,13 +507,11 @@ float analog2temp(int raw, uint8_t e) {
|
||||
|
||||
// Derived from RepRap FiveD extruder::getTemperature()
|
||||
// For bed temperature measurement.
|
||||
float analog2tempBed(int raw) {
|
||||
static float analog2tempBed(int raw) {
|
||||
#ifdef BED_USES_THERMISTOR
|
||||
float celsius = 0;
|
||||
byte i;
|
||||
|
||||
raw = (1023 * OVERSAMPLENR) - raw;
|
||||
|
||||
for (i=1; i<bedtemptable_len; i++)
|
||||
{
|
||||
if (PGM_RD_W(bedtemptable[i][0]) > raw)
|
||||
@ -621,6 +535,24 @@ float analog2tempBed(int raw) {
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Called to get the raw values into the the actual temperatures. The raw values are created in interrupt context,
|
||||
and this function is called from normal context as it is too slow to run in interrupts and will block the stepper routine otherwise */
|
||||
static void updateTemperaturesFromRawValues()
|
||||
{
|
||||
for(uint8_t e=0;e<EXTRUDERS;e++)
|
||||
{
|
||||
current_temperature[e] = analog2temp(current_temperature_raw[e], e);
|
||||
}
|
||||
current_temperature_bed = analog2tempBed(current_temperature_bed_raw);
|
||||
|
||||
//Reset the watchdog after we know we have a temperature measurement.
|
||||
watchdog_reset();
|
||||
|
||||
CRITICAL_SECTION_START;
|
||||
temp_meas_ready = false;
|
||||
CRITICAL_SECTION_END;
|
||||
}
|
||||
|
||||
void tp_init()
|
||||
{
|
||||
// Finish init of mult extruder arrays
|
||||
@ -716,31 +648,87 @@ void tp_init()
|
||||
delay(250);
|
||||
|
||||
#ifdef HEATER_0_MINTEMP
|
||||
minttemp[0] = temp2analog(HEATER_0_MINTEMP, 0);
|
||||
minttemp[0] = HEATER_0_MINTEMP;
|
||||
while(analog2temp(minttemp_raw[0], 0) < HEATER_0_MINTEMP) {
|
||||
#if HEATER_0_RAW_LO_TEMP < HEATER_0_RAW_HI_TEMP
|
||||
minttemp_raw[0] += OVERSAMPLENR;
|
||||
#else
|
||||
minttemp_raw[0] -= OVERSAMPLENR;
|
||||
#endif
|
||||
}
|
||||
#endif //MINTEMP
|
||||
#ifdef HEATER_0_MAXTEMP
|
||||
maxttemp[0] = temp2analog(HEATER_0_MAXTEMP, 0);
|
||||
maxttemp[0] = HEATER_0_MAXTEMP;
|
||||
while(analog2temp(maxttemp_raw[0], 0) > HEATER_0_MAXTEMP) {
|
||||
#if HEATER_0_RAW_LO_TEMP < HEATER_0_RAW_HI_TEMP
|
||||
maxttemp_raw[0] -= OVERSAMPLENR;
|
||||
#else
|
||||
maxttemp_raw[0] += OVERSAMPLENR;
|
||||
#endif
|
||||
}
|
||||
#endif //MAXTEMP
|
||||
|
||||
#if (EXTRUDERS > 1) && defined(HEATER_1_MINTEMP)
|
||||
minttemp[1] = temp2analog(HEATER_1_MINTEMP, 1);
|
||||
minttemp[1] = HEATER_1_MINTEMP;
|
||||
while(analog2temp(minttemp_raw[1], 1) > HEATER_1_MINTEMP) {
|
||||
#if HEATER_1_RAW_LO_TEMP < HEATER_1_RAW_HI_TEMP
|
||||
minttemp_raw[1] += OVERSAMPLENR;
|
||||
#else
|
||||
minttemp_raw[1] -= OVERSAMPLENR;
|
||||
#endif
|
||||
}
|
||||
#endif // MINTEMP 1
|
||||
#if (EXTRUDERS > 1) && defined(HEATER_1_MAXTEMP)
|
||||
maxttemp[1] = temp2analog(HEATER_1_MAXTEMP, 1);
|
||||
maxttemp[1] = HEATER_1_MAXTEMP;
|
||||
while(analog2temp(maxttemp_raw[1], 1) > HEATER_1_MAXTEMP) {
|
||||
#if HEATER_1_RAW_LO_TEMP < HEATER_1_RAW_HI_TEMP
|
||||
maxttemp_raw[1] -= OVERSAMPLENR;
|
||||
#else
|
||||
maxttemp_raw[1] += OVERSAMPLENR;
|
||||
#endif
|
||||
}
|
||||
#endif //MAXTEMP 1
|
||||
|
||||
#if (EXTRUDERS > 2) && defined(HEATER_2_MINTEMP)
|
||||
minttemp[2] = temp2analog(HEATER_2_MINTEMP, 2);
|
||||
minttemp[2] = HEATER_2_MINTEMP;
|
||||
while(analog2temp(minttemp_raw[2], 2) > HEATER_2_MINTEMP) {
|
||||
#if HEATER_2_RAW_LO_TEMP < HEATER_2_RAW_HI_TEMP
|
||||
minttemp_raw[2] += OVERSAMPLENR;
|
||||
#else
|
||||
minttemp_raw[2] -= OVERSAMPLENR;
|
||||
#endif
|
||||
}
|
||||
#endif //MINTEMP 2
|
||||
#if (EXTRUDERS > 2) && defined(HEATER_2_MAXTEMP)
|
||||
maxttemp[2] = temp2analog(HEATER_2_MAXTEMP, 2);
|
||||
maxttemp[2] = HEATER_2_MAXTEMP;
|
||||
while(analog2temp(maxttemp_raw[2], 2) > HEATER_2_MAXTEMP) {
|
||||
#if HEATER_2_RAW_LO_TEMP < HEATER_2_RAW_HI_TEMP
|
||||
maxttemp_raw[2] -= OVERSAMPLENR;
|
||||
#else
|
||||
maxttemp_raw[2] += OVERSAMPLENR;
|
||||
#endif
|
||||
}
|
||||
#endif //MAXTEMP 2
|
||||
|
||||
#ifdef BED_MINTEMP
|
||||
bed_minttemp = temp2analogBed(BED_MINTEMP);
|
||||
/* No bed MINTEMP error implemented?!? */ /*
|
||||
while(analog2tempBed(bed_minttemp_raw) < BED_MINTEMP) {
|
||||
#if HEATER_BED_RAW_LO_TEMP < HEATER_BED_RAW_HI_TEMP
|
||||
bed_minttemp_raw += OVERSAMPLENR;
|
||||
#else
|
||||
bed_minttemp_raw -= OVERSAMPLENR;
|
||||
#endif
|
||||
}
|
||||
*/
|
||||
#endif //BED_MINTEMP
|
||||
#ifdef BED_MAXTEMP
|
||||
bed_maxttemp = temp2analogBed(BED_MAXTEMP);
|
||||
while(analog2tempBed(bed_maxttemp_raw) > BED_MAXTEMP) {
|
||||
#if HEATER_BED_RAW_LO_TEMP < HEATER_BED_RAW_HI_TEMP
|
||||
bed_maxttemp_raw -= OVERSAMPLENR;
|
||||
#else
|
||||
bed_maxttemp_raw += OVERSAMPLENR;
|
||||
#endif
|
||||
}
|
||||
#endif //BED_MAXTEMP
|
||||
}
|
||||
|
||||
@ -765,7 +753,7 @@ void disable_heater()
|
||||
setTargetHotend(0,i);
|
||||
setTargetBed(0);
|
||||
#if TEMP_0_PIN > -1
|
||||
target_raw[0]=0;
|
||||
target_temperature[0]=0;
|
||||
soft_pwm[0]=0;
|
||||
#if HEATER_0_PIN > -1
|
||||
WRITE(HEATER_0_PIN,LOW);
|
||||
@ -773,7 +761,7 @@ void disable_heater()
|
||||
#endif
|
||||
|
||||
#if TEMP_1_PIN > -1
|
||||
target_raw[1]=0;
|
||||
target_temperature[1]=0;
|
||||
soft_pwm[1]=0;
|
||||
#if HEATER_1_PIN > -1
|
||||
WRITE(HEATER_1_PIN,LOW);
|
||||
@ -781,7 +769,7 @@ void disable_heater()
|
||||
#endif
|
||||
|
||||
#if TEMP_2_PIN > -1
|
||||
target_raw[2]=0;
|
||||
target_temperature[2]=0;
|
||||
soft_pwm[2]=0;
|
||||
#if HEATER_2_PIN > -1
|
||||
WRITE(HEATER_2_PIN,LOW);
|
||||
@ -789,7 +777,7 @@ void disable_heater()
|
||||
#endif
|
||||
|
||||
#if TEMP_BED_PIN > -1
|
||||
target_raw_bed=0;
|
||||
target_temperature_bed=0;
|
||||
soft_pwm_bed=0;
|
||||
#if HEATER_BED_PIN > -1
|
||||
WRITE(HEATER_BED_PIN,LOW);
|
||||
@ -1031,33 +1019,16 @@ ISR(TIMER0_COMPB_vect)
|
||||
|
||||
if(temp_count >= 16) // 8 ms * 16 = 128ms.
|
||||
{
|
||||
#if defined(HEATER_0_USES_AD595) || defined(HEATER_0_USES_MAX6675)
|
||||
current_raw[0] = raw_temp_0_value;
|
||||
#else
|
||||
current_raw[0] = 16383 - raw_temp_0_value;
|
||||
#endif
|
||||
|
||||
#if EXTRUDERS > 1
|
||||
#ifdef HEATER_1_USES_AD595
|
||||
current_raw[1] = raw_temp_1_value;
|
||||
#else
|
||||
current_raw[1] = 16383 - raw_temp_1_value;
|
||||
#endif
|
||||
if (!temp_meas_ready) //Only update the raw values if they have been read. Else we could be updating them during reading.
|
||||
{
|
||||
current_temperature_raw[0] = raw_temp_0_value;
|
||||
#if EXTRUDERS > 1
|
||||
current_temperature_raw[1] = raw_temp_0_value;
|
||||
#endif
|
||||
|
||||
#if EXTRUDERS > 2
|
||||
#ifdef HEATER_2_USES_AD595
|
||||
current_raw[2] = raw_temp_2_value;
|
||||
#else
|
||||
current_raw[2] = 16383 - raw_temp_2_value;
|
||||
#endif
|
||||
current_temperature_raw[2] = raw_temp_0_value;
|
||||
#endif
|
||||
|
||||
#ifdef BED_USES_AD595
|
||||
current_raw_bed = raw_temp_bed_value;
|
||||
#else
|
||||
current_raw_bed = 16383 - raw_temp_bed_value;
|
||||
#endif
|
||||
}
|
||||
|
||||
temp_meas_ready = true;
|
||||
temp_count = 0;
|
||||
@ -1066,23 +1037,63 @@ ISR(TIMER0_COMPB_vect)
|
||||
raw_temp_2_value = 0;
|
||||
raw_temp_bed_value = 0;
|
||||
|
||||
for(unsigned char e = 0; e < EXTRUDERS; e++) {
|
||||
if(current_raw[e] >= maxttemp[e]) {
|
||||
target_raw[e] = 0;
|
||||
max_temp_error(e);
|
||||
}
|
||||
if(current_raw[e] <= minttemp[e]) {
|
||||
target_raw[e] = 0;
|
||||
min_temp_error(e);
|
||||
}
|
||||
#if HEATER_0_RAW_LO_TEMP > HEATER_0_RAW_HI_TEMP
|
||||
if(current_temperature_raw[0] <= maxttemp_raw[0]) {
|
||||
#else
|
||||
if(current_temperature_raw[0] >= maxttemp_raw[0]) {
|
||||
#endif
|
||||
max_temp_error(0);
|
||||
}
|
||||
#if HEATER_0_RAW_LO_TEMP > HEATER_0_RAW_HI_TEMP
|
||||
if(current_temperature_raw[0] >= minttemp_raw[0]) {
|
||||
#else
|
||||
if(current_temperature_raw[0] <= minttemp_raw[0]) {
|
||||
#endif
|
||||
min_temp_error(0);
|
||||
}
|
||||
#if EXTRUDERS > 1
|
||||
#if HEATER_1_RAW_LO_TEMP > HEATER_1_RAW_HI_TEMP
|
||||
if(current_temperature_raw[1] <= maxttemp_raw[1]) {
|
||||
#else
|
||||
if(current_temperature_raw[1] >= maxttemp_raw[1]) {
|
||||
#endif
|
||||
max_temp_error(1);
|
||||
}
|
||||
#if HEATER_1_RAW_LO_TEMP > HEATER_1_RAW_HI_TEMP
|
||||
if(current_temperature_raw[1] >= minttemp_raw[1]) {
|
||||
#else
|
||||
if(current_temperature_raw[1] <= minttemp_raw[1]) {
|
||||
#endif
|
||||
min_temp_error(1);
|
||||
}
|
||||
#endif
|
||||
#if EXTRUDERS > 2
|
||||
#if HEATER_2_RAW_LO_TEMP > HEATER_2_RAW_HI_TEMP
|
||||
if(current_temperature_raw[2] <= maxttemp_raw[2]) {
|
||||
#else
|
||||
if(current_temperature_raw[2] >= maxttemp_raw[2]) {
|
||||
#endif
|
||||
max_temp_error(2);
|
||||
}
|
||||
#if HEATER_2_RAW_LO_TEMP > HEATER_2_RAW_HI_TEMP
|
||||
if(current_temperature_raw[2] >= minttemp_raw[2]) {
|
||||
#else
|
||||
if(current_temperature_raw[2] <= minttemp_raw[2]) {
|
||||
#endif
|
||||
min_temp_error(2);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(BED_MAXTEMP) && (HEATER_BED_PIN > -1)
|
||||
if(current_raw_bed >= bed_maxttemp) {
|
||||
target_raw_bed = 0;
|
||||
/* No bed MINTEMP error? */
|
||||
#if defined(BED_MAXTEMP) && (TEMP_SENSOR_BED != 0)
|
||||
# if HEATER_BED_RAW_LO_TEMP > HEATER_BED_RAW_HI_TEMP
|
||||
if(current_temperature_bed <= bed_maxttemp_raw) {
|
||||
#else
|
||||
if(current_temperature_bed >= bed_maxttemp_raw) {
|
||||
#endif
|
||||
target_temperature_bed = 0;
|
||||
bed_max_temp_error();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user