Commit a6879c86 authored by MagoKimbra's avatar MagoKimbra

Update Temperature.cpp

parent 03bb009c
...@@ -18,40 +18,40 @@ ...@@ -18,40 +18,40 @@
#define MSG_BED_SETTING "Bed Setting" #define MSG_BED_SETTING "Bed Setting"
#define MSG_SET_HOME_OFFSETS "Set home offsets" #define MSG_SET_HOME_OFFSETS "Set home offsets"
#define MSG_SET_ORIGIN "Aseta origo" #define MSG_SET_ORIGIN "Aseta origo"
#define MSG_PREHEAT_PLA "Esilammita PLA" #define MSG_PREHEAT_PLA "Esil" STR_ae "mmit" STR_ae " PLA"
#define MSG_PREHEAT_PLA_ALL "Esila. PLA Kaikki" #define MSG_PREHEAT_PLA_ALL "Esil" STR_ae ". PLA Kaikki"
#define MSG_PREHEAT_PLA_BEDONLY "Esila. PLA Alusta" #define MSG_PREHEAT_PLA_BEDONLY "Esil" STR_ae ". PLA Alusta"
#define MSG_PREHEAT_PLA_SETTINGS "Esilamm. PLA konf" #define MSG_PREHEAT_PLA_SETTINGS "Esil" STR_ae "mm. PLA konf"
#define MSG_PREHEAT_ABS "Esilammita ABS" #define MSG_PREHEAT_ABS "Esil" STR_ae "mmit" STR_ae " ABS"
#define MSG_PREHEAT_ABS_ALL "Esila. ABS Kaikki" #define MSG_PREHEAT_ABS_ALL "Esil" STR_ae ". ABS Kaikki"
#define MSG_PREHEAT_ABS_BEDONLY "Esila. ABS Alusta" #define MSG_PREHEAT_ABS_BEDONLY "Esil" STR_ae ". ABS Alusta"
#define MSG_PREHEAT_ABS_SETTINGS "Esilamm. ABS konf" #define MSG_PREHEAT_ABS_SETTINGS "Esil" STR_ae "mm. ABS konf"
#define MSG_PREHEAT_GUM "Preheat GUM" #define MSG_PREHEAT_GUM "Esil" STR_ae "mmit" STR_ae " GUM"
#define MSG_PREHEAT_GUM_ALL "Preheat GUM All" #define MSG_PREHEAT_GUM_ALL "Esil" STR_ae ". GUM Kaikki"
#define MSG_PREHEAT_GUM_BEDONLY "Preheat GUM Bed" #define MSG_PREHEAT_GUM_BEDONLY "Esil" STR_ae ". GUM Alusta"
#define MSG_PREHEAT_GUM_SETTINGS "Preheat GUM conf" #define MSG_PREHEAT_GUM_SETTINGS "Esil" STR_ae "mm. GUM konf"
#define MSG_COOLDOWN "Jaahdyta" #define MSG_COOLDOWN "J" STR_ae "" STR_ae "hdyt" STR_ae ""
#define MSG_SWITCH_PS_ON "Virta paalle" #define MSG_SWITCH_PS_ON "Virta p" STR_ae "" STR_ae "lle"
#define MSG_SWITCH_PS_OFF "Virta pois" #define MSG_SWITCH_PS_OFF "Virta pois"
#define MSG_EXTRUDE "Pursota" #define MSG_EXTRUDE "Pursota"
#define MSG_RETRACT "Veda takaisin" #define MSG_RETRACT "Ved" STR_ae " takaisin"
#define MSG_MOVE_AXIS "Liikuta akseleita" #define MSG_MOVE_AXIS "Liikuta akseleita"
#define MSG_MOVE_X "Move X" #define MSG_MOVE_X "Liikuta X"
#define MSG_MOVE_Y "Move Y" #define MSG_MOVE_Y "Liikuta Y"
#define MSG_MOVE_Z "Move Z" #define MSG_MOVE_Z "Liikuta Z"
#define MSG_MOVE_E "Extruder" #define MSG_MOVE_E "Extruder"
#define MSG_MOVE_01MM "Move 0.1mm" #define MSG_MOVE_01MM "Liikuta 0.1mm"
#define MSG_MOVE_1MM "Move 1mm" #define MSG_MOVE_1MM "Liikuta 1mm"
#define MSG_MOVE_10MM "Move 10mm" #define MSG_MOVE_10MM "Liikuta 10mm"
#define MSG_SPEED "Nopeus" #define MSG_SPEED "Nopeus"
#define MSG_NOZZLE "Suutin" #define MSG_NOZZLE "Suutin"
#define MSG_BED "Alusta" #define MSG_BED "Alusta"
#define MSG_FAN_SPEED "Tuul. nopeus" #define MSG_FAN_SPEED "Tuul. nopeus"
#define MSG_FLOW "Virtaus" #define MSG_FLOW "Virtaus"
#define MSG_CONTROL "Kontrolli" #define MSG_CONTROL "Kontrolli"
#define MSG_MIN " " STR_THERMOMETER " Min" #define MSG_MIN STR_THERMOMETER " Min"
#define MSG_MAX " " STR_THERMOMETER " Max" #define MSG_MAX STR_THERMOMETER " Max"
#define MSG_FACTOR " " STR_THERMOMETER " Fact" #define MSG_FACTOR STR_THERMOMETER " Kerr"
#define MSG_AUTOTEMP "Autotemp" #define MSG_AUTOTEMP "Autotemp"
#define MSG_ON "On " #define MSG_ON "On "
#define MSG_OFF "Off" #define MSG_OFF "Off"
...@@ -78,22 +78,22 @@ ...@@ -78,22 +78,22 @@
#define MSG_E1STEPS "E1 steps/mm" #define MSG_E1STEPS "E1 steps/mm"
#define MSG_E2STEPS "E2 steps/mm" #define MSG_E2STEPS "E2 steps/mm"
#define MSG_E3STEPS "E3 steps/mm" #define MSG_E3STEPS "E3 steps/mm"
#define MSG_TEMPERATURE "Lampotila" #define MSG_TEMPERATURE "L" STR_ae "mp" STR_oe "tila"
#define MSG_MOTION "Liike" #define MSG_MOTION "Liike"
#define MSG_VOLUMETRIC "Filament" #define MSG_VOLUMETRIC "Filament"
#define MSG_VOLUMETRIC_ENABLED "E in mm" STR_h3 #define MSG_VOLUMETRIC_ENABLED "E in mm" STR_h3
#define MSG_FILAMENT_SIZE_EXTRUDER "Fil. Dia." #define MSG_FILAMENT_SIZE_EXTRUDER "Fil. Dia."
#define MSG_CONTRAST "LCD contrast" #define MSG_CONTRAST "LCD kontrasti"
#define MSG_STORE_EPROM "Tallenna muistiin" #define MSG_STORE_EPROM "Tallenna muistiin"
#define MSG_LOAD_EPROM "Lataa muistista" #define MSG_LOAD_EPROM "Lataa muistista"
#define MSG_RESTORE_FAILSAFE "Palauta oletus" #define MSG_RESTORE_FAILSAFE "Palauta oletus"
#define MSG_REFRESH "Paivita" #define MSG_REFRESH "P" STR_ae "ivit" STR_ae ""
#define MSG_WATCH "Seuraa" #define MSG_WATCH "Seuraa"
#define MSG_PREPARE "Valmistele" #define MSG_PREPARE "Valmistele"
#define MSG_TUNE "Saada" #define MSG_TUNE "S" STR_ae "" STR_ae "d" STR_ae ""
#define MSG_PAUSE_PRINT "Keskeyta tulostus" #define MSG_PAUSE_PRINT "Keskeyt" STR_ae " tulostus"
#define MSG_RESUME_PRINT "Jatka tulostusta" #define MSG_RESUME_PRINT "Jatka tulostusta"
#define MSG_STOP_PRINT "Pysayta tulostus" #define MSG_STOP_PRINT "Pys" STR_ae "yt" STR_ae " tulostus"
#define MSG_CARD_MENU "Korttivalikko" #define MSG_CARD_MENU "Korttivalikko"
#define MSG_NO_CARD "Ei korttia" #define MSG_NO_CARD "Ei korttia"
#define MSG_DWELL "Nukkumassa..." #define MSG_DWELL "Nukkumassa..."
...@@ -103,9 +103,9 @@ ...@@ -103,9 +103,9 @@
#define MSG_NO_MOVE "Ei liiketta." #define MSG_NO_MOVE "Ei liiketta."
#define MSG_KILLED "KILLED. " #define MSG_KILLED "KILLED. "
#define MSG_STOPPED "STOPPED. " #define MSG_STOPPED "STOPPED. "
#define MSG_CONTROL_RETRACT "Veda mm" #define MSG_CONTROL_RETRACT "Ved" STR_ae " mm"
#define MSG_CONTROL_RETRACT_SWAP "Va. Veda mm" #define MSG_CONTROL_RETRACT_SWAP "Va. Ved" STR_ae " mm"
#define MSG_CONTROL_RETRACTF "Veda V" #define MSG_CONTROL_RETRACTF "Ved" STR_ae " V"
#define MSG_CONTROL_RETRACT_ZLIFT "Z mm" #define MSG_CONTROL_RETRACT_ZLIFT "Z mm"
#define MSG_CONTROL_RETRACT_RECOVER "UnRet +mm" #define MSG_CONTROL_RETRACT_RECOVER "UnRet +mm"
#define MSG_CONTROL_RETRACT_RECOVER_SWAP "Va. UnRet +mm" #define MSG_CONTROL_RETRACT_RECOVER_SWAP "Va. UnRet +mm"
...@@ -123,11 +123,11 @@ ...@@ -123,11 +123,11 @@
#define MSG_ENDSTOP_ABORT "Endstop abort" #define MSG_ENDSTOP_ABORT "Endstop abort"
#ifdef DELTA #ifdef DELTA
#define MSG_DELTA_CALIBRATE "Delta Calibration" #define MSG_DELTA_CALIBRATE "Delta Kalibrointi"
#define MSG_DELTA_CALIBRATE_X "Calibrate X" #define MSG_DELTA_CALIBRATE_X "Kalibroi X"
#define MSG_DELTA_CALIBRATE_Y "Calibrate Y" #define MSG_DELTA_CALIBRATE_Y "Kalibroi Y"
#define MSG_DELTA_CALIBRATE_Z "Calibrate Z" #define MSG_DELTA_CALIBRATE_Z "Kalibroi Z"
#define MSG_DELTA_CALIBRATE_CENTER "Calibrate Center" #define MSG_DELTA_CALIBRATE_CENTER "Kalibroi Center"
#endif // DELTA #endif // DELTA
#define MSG_LASER "Laser Preset" #define MSG_LASER "Laser Preset"
......
...@@ -418,7 +418,8 @@ int getHeaterPower(int heater) { ...@@ -418,7 +418,8 @@ int getHeaterPower(int heater) {
#if (defined(EXTRUDER_0_AUTO_FAN_PIN) && EXTRUDER_0_AUTO_FAN_PIN > -1) || \ #if (defined(EXTRUDER_0_AUTO_FAN_PIN) && EXTRUDER_0_AUTO_FAN_PIN > -1) || \
(defined(EXTRUDER_1_AUTO_FAN_PIN) && EXTRUDER_1_AUTO_FAN_PIN > -1) || \ (defined(EXTRUDER_1_AUTO_FAN_PIN) && EXTRUDER_1_AUTO_FAN_PIN > -1) || \
(defined(EXTRUDER_2_AUTO_FAN_PIN) && EXTRUDER_2_AUTO_FAN_PIN > -1) (defined(EXTRUDER_2_AUTO_FAN_PIN) && EXTRUDER_2_AUTO_FAN_PIN > -1) || \
(defined(EXTRUDER_3_AUTO_FAN_PIN) && EXTRUDER_3_AUTO_FAN_PIN > -1)
#if defined(FAN_PIN) && FAN_PIN > -1 #if defined(FAN_PIN) && FAN_PIN > -1
#if EXTRUDER_0_AUTO_FAN_PIN == FAN_PIN #if EXTRUDER_0_AUTO_FAN_PIN == FAN_PIN
...@@ -430,19 +431,22 @@ int getHeaterPower(int heater) { ...@@ -430,19 +431,22 @@ int getHeaterPower(int heater) {
#if EXTRUDER_2_AUTO_FAN_PIN == FAN_PIN #if EXTRUDER_2_AUTO_FAN_PIN == FAN_PIN
#error "You cannot set EXTRUDER_2_AUTO_FAN_PIN equal to FAN_PIN" #error "You cannot set EXTRUDER_2_AUTO_FAN_PIN equal to FAN_PIN"
#endif #endif
#if EXTRUDER_3_AUTO_FAN_PIN == FAN_PIN
#error "You cannot set EXTRUDER_3_AUTO_FAN_PIN equal to FAN_PIN"
#endif
#endif #endif
void setExtruderAutoFanState(int pin, bool state) void setExtruderAutoFanState(int pin, bool state)
{ {
unsigned char newFanSpeed = (state != 0) ? EXTRUDER_AUTO_FAN_SPEED : 0; unsigned char newFanSpeed = (state != 0) ? EXTRUDER_AUTO_FAN_SPEED : 0;
// this idiom allows both digital and PWM fan outputs (see M42 handling). // this idiom allows both digital and PWM fan outputs (see M42 handling).
pinMode(pin, OUTPUT); pinMode(pin, OUTPUT);
digitalWrite(pin, newFanSpeed); digitalWrite(pin, newFanSpeed);
analogWrite(pin, newFanSpeed); analogWrite(pin, newFanSpeed);
} }
void checkExtruderAutoFans() void checkExtruderAutoFans()
{ {
uint8_t fanState = 0; uint8_t fanState = 0;
// which fan pins need to be turned on? // which fan pins need to be turned on?
...@@ -451,7 +455,7 @@ void checkExtruderAutoFans() ...@@ -451,7 +455,7 @@ void checkExtruderAutoFans()
fanState |= 1; fanState |= 1;
#endif #endif
#ifndef SINGLENOZZLE #ifndef SINGLENOZZLE
#if defined(EXTRUDER_1_AUTO_FAN_PIN) && EXTRUDER_1_AUTO_FAN_PIN > -1 #if defined(EXTRUDER_1_AUTO_FAN_PIN) && EXTRUDER_1_AUTO_FAN_PIN > -1
if (current_temperature[1] > EXTRUDER_AUTO_FAN_TEMPERATURE) if (current_temperature[1] > EXTRUDER_AUTO_FAN_TEMPERATURE)
{ {
...@@ -485,14 +489,14 @@ void checkExtruderAutoFans() ...@@ -485,14 +489,14 @@ void checkExtruderAutoFans()
fanState |= 8; fanState |= 8;
} }
#endif #endif
#endif // !SINLGENOZZE #endif // !SINLGENOZZE
// update extruder auto fan states // update extruder auto fan states
#if defined(EXTRUDER_0_AUTO_FAN_PIN) && EXTRUDER_0_AUTO_FAN_PIN > -1 #if defined(EXTRUDER_0_AUTO_FAN_PIN) && EXTRUDER_0_AUTO_FAN_PIN > -1
setExtruderAutoFanState(EXTRUDER_0_AUTO_FAN_PIN, (fanState & 1) != 0); setExtruderAutoFanState(EXTRUDER_0_AUTO_FAN_PIN, (fanState & 1) != 0);
#endif #endif
#ifndef SINGLENOZZLE #ifndef SINGLENOZZLE
#if defined(EXTRUDER_1_AUTO_FAN_PIN) && EXTRUDER_1_AUTO_FAN_PIN > -1 #if defined(EXTRUDER_1_AUTO_FAN_PIN) && EXTRUDER_1_AUTO_FAN_PIN > -1
if (EXTRUDER_1_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN) if (EXTRUDER_1_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN)
setExtruderAutoFanState(EXTRUDER_1_AUTO_FAN_PIN, (fanState & 2) != 0); setExtruderAutoFanState(EXTRUDER_1_AUTO_FAN_PIN, (fanState & 2) != 0);
...@@ -508,9 +512,8 @@ void checkExtruderAutoFans() ...@@ -508,9 +512,8 @@ void checkExtruderAutoFans()
&& EXTRUDER_3_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN) && EXTRUDER_3_AUTO_FAN_PIN != EXTRUDER_0_AUTO_FAN_PIN)
setExtruderAutoFanState(EXTRUDER_3_AUTO_FAN_PIN, (fanState & 8) != 0); setExtruderAutoFanState(EXTRUDER_3_AUTO_FAN_PIN, (fanState & 8) != 0);
#endif #endif
#endif // !SINLGENOZZE #endif // !SINLGENOZZE
} }
#endif // any extruder auto fan pins set #endif // any extruder auto fan pins set
void manage_heater() void manage_heater()
...@@ -524,12 +527,10 @@ void manage_heater() ...@@ -524,12 +527,10 @@ void manage_heater()
updateTemperaturesFromRawValues(); updateTemperaturesFromRawValues();
#ifdef HEATER_0_USES_MAX6675 #ifdef HEATER_0_USES_MAX6675
if (current_temperature[0] > 1023 || current_temperature[0] > HEATER_0_MAXTEMP) if (current_temperature[0] > 1023 || current_temperature[0] > HEATER_0_MAXTEMP) {
{
max_temp_error(0); max_temp_error(0);
} }
if (current_temperature[0] == 0 || current_temperature[0] < HEATER_0_MINTEMP) if (current_temperature[0] == 0 || current_temperature[0] < HEATER_0_MINTEMP) {
{
min_temp_error(0); min_temp_error(0);
} }
#endif //HEATER_0_USES_MAX6675 #endif //HEATER_0_USES_MAX6675
...@@ -550,20 +551,16 @@ void manage_heater() ...@@ -550,20 +551,16 @@ void manage_heater()
#ifndef PID_OPENLOOP #ifndef PID_OPENLOOP
pid_error[e] = target_temperature[e] - pid_input; pid_error[e] = target_temperature[e] - pid_input;
if(pid_error[e] > PID_FUNCTIONAL_RANGE) if(pid_error[e] > PID_FUNCTIONAL_RANGE) {
{
pid_output = BANG_MAX; pid_output = BANG_MAX;
pid_reset[e] = true; pid_reset[e] = true;
} }
else if(pid_error[e] < -PID_FUNCTIONAL_RANGE || target_temperature[e] == 0) else if(pid_error[e] < -PID_FUNCTIONAL_RANGE || target_temperature[e] == 0) {
{
pid_output = 0; pid_output = 0;
pid_reset[e] = true; pid_reset[e] = true;
} }
else else {
{ if(pid_reset[e] == true) {
if(pid_reset[e] == true)
{
temp_iState[e] = 0.0; temp_iState[e] = 0.0;
pid_reset[e] = false; pid_reset[e] = false;
} }
...@@ -576,12 +573,11 @@ void manage_heater() ...@@ -576,12 +573,11 @@ void manage_heater()
#define K2 (1.0-K1) #define K2 (1.0-K1)
dTerm[e] = (Kd[e] * (pid_input - temp_dState[e]))*K2 + (K1 * dTerm[e]); dTerm[e] = (Kd[e] * (pid_input - temp_dState[e]))*K2 + (K1 * dTerm[e]);
pid_output = pTerm[e] + iTerm[e] - dTerm[e]; pid_output = pTerm[e] + iTerm[e] - dTerm[e];
if (pid_output > PID_MAX) if (pid_output > PID_MAX) {
{
if (pid_error[e] > 0 ) temp_iState[e] -= pid_error[e]; // conditional un-integration if (pid_error[e] > 0 ) temp_iState[e] -= pid_error[e]; // conditional un-integration
pid_output=PID_MAX; pid_output=PID_MAX;
} else if (pid_output < 0) }
{ else if (pid_output < 0) {
if (pid_error[e] < 0 ) temp_iState[e] -= pid_error[e]; // conditional un-integration if (pid_error[e] < 0 ) temp_iState[e] -= pid_error[e]; // conditional un-integration
pid_output=0; pid_output=0;
} }
...@@ -608,45 +604,37 @@ void manage_heater() ...@@ -608,45 +604,37 @@ void manage_heater()
#endif //PID_DEBUG #endif //PID_DEBUG
#else //NO PIDTEMP #else //NO PIDTEMP
pid_output = 0; pid_output = 0;
if(current_temperature[e] < target_temperature[e]) if(current_temperature[e] < target_temperature[e]) {
{
pid_output = PID_MAX; pid_output = PID_MAX;
} }
#endif //PIDTEMP #endif //PIDTEMP
// Check if temperature is within the correct range // Check if temperature is within the correct range
if((current_temperature[e] > minttemp[e]) && (current_temperature[e] < maxttemp[e])) if((current_temperature[e] > minttemp[e]) && (current_temperature[e] < maxttemp[e])) {
{
soft_pwm[e] = (int)pid_output >> 1; soft_pwm[e] = (int)pid_output >> 1;
} }
else else {
{
soft_pwm[e] = 0; soft_pwm[e] = 0;
} }
#ifdef WATCH_TEMP_PERIOD #ifdef WATCH_TEMP_PERIOD
if(watchmillis[e] && millis() - watchmillis[e] > WATCH_TEMP_PERIOD) if(watchmillis[e] && millis() - watchmillis[e] > WATCH_TEMP_PERIOD) {
{ if(degHotend(e) < watch_start_temp[e] + WATCH_TEMP_INCREASE) {
if(degHotend(e) < watch_start_temp[e] + WATCH_TEMP_INCREASE)
{
setTargetHotend(0, e); setTargetHotend(0, e);
LCD_MESSAGEPGM("Heating failed"); LCD_MESSAGEPGM("Heating failed");
SERIAL_ECHO_START; SERIAL_ECHO_START;
SERIAL_ECHOLN("Heating failed"); SERIAL_ECHOLN("Heating failed");
} }
else else {
{
watchmillis[e] = 0; watchmillis[e] = 0;
} }
} }
#endif //WATCH_TEMP_PERIOD #endif //WATCH_TEMP_PERIOD
#ifdef TEMP_SENSOR_1_AS_REDUNDANT #ifdef TEMP_SENSOR_1_AS_REDUNDANT
if(fabs(current_temperature[0] - redundant_temperature) > MAX_REDUNDANT_TEMP_SENSOR_DIFF) if(fabs(current_temperature[0] - redundant_temperature) > MAX_REDUNDANT_TEMP_SENSOR_DIFF) {
{
disable_heater(); disable_heater();
if(IsStopped() == false) if(IsStopped() == false) {
{
SERIAL_ERROR_START; SERIAL_ERROR_START;
SERIAL_ERRORLNPGM("Extruder switched off. Temperature difference between temp sensors is too high !"); SERIAL_ERRORLNPGM("Extruder switched off. Temperature difference between temp sensors is too high !");
LCD_ALERTMESSAGEPGM("Err: REDUNDANT TEMP ERROR"); LCD_ALERTMESSAGEPGM("Err: REDUNDANT TEMP ERROR");
...@@ -656,13 +644,13 @@ void manage_heater() ...@@ -656,13 +644,13 @@ void manage_heater()
#endif #endif
} }
#endif //TEMP_SENSOR_1_AS_REDUNDANT #endif //TEMP_SENSOR_1_AS_REDUNDANT
} // End extruder for loop } //End extruder for loop
#if (defined(EXTRUDER_0_AUTO_FAN_PIN) && EXTRUDER_0_AUTO_FAN_PIN > -1) || \ #if (defined(EXTRUDER_0_AUTO_FAN_PIN) && EXTRUDER_0_AUTO_FAN_PIN > -1) || \
(defined(EXTRUDER_1_AUTO_FAN_PIN) && EXTRUDER_1_AUTO_FAN_PIN > -1) || \ (defined(EXTRUDER_1_AUTO_FAN_PIN) && EXTRUDER_1_AUTO_FAN_PIN > -1) || \
(defined(EXTRUDER_2_AUTO_FAN_PIN) && EXTRUDER_2_AUTO_FAN_PIN > -1) (defined(EXTRUDER_2_AUTO_FAN_PIN) && EXTRUDER_2_AUTO_FAN_PIN > -1) || \
if(millis() - extruder_autofan_last_check > 2500) // only need to check fan state very infrequently (defined(EXTRUDER_3_AUTO_FAN_PIN) && EXTRUDER_3_AUTO_FAN_PIN > -1)
{ if(millis() - extruder_autofan_last_check > 2500) { // only need to check fan state very infrequently
checkExtruderAutoFans(); checkExtruderAutoFans();
extruder_autofan_last_check = millis(); extruder_autofan_last_check = millis();
} }
...@@ -675,14 +663,12 @@ void manage_heater() ...@@ -675,14 +663,12 @@ void manage_heater()
#endif #endif
#if TEMP_SENSOR_BED != 0 #if TEMP_SENSOR_BED != 0
#if defined(THERMAL_RUNAWAY_PROTECTION_BED_PERIOD) && THERMAL_RUNAWAY_PROTECTION_BED_PERIOD > 0 #if defined(THERMAL_RUNAWAY_PROTECTION_BED_PERIOD) && THERMAL_RUNAWAY_PROTECTION_BED_PERIOD > 0
thermal_runaway_protection(&thermal_runaway_bed_state_machine, &thermal_runaway_bed_timer, current_temperature_bed, target_temperature_bed, 9, THERMAL_RUNAWAY_PROTECTION_BED_PERIOD, THERMAL_RUNAWAY_PROTECTION_BED_HYSTERESIS); thermal_runaway_protection(&thermal_runaway_bed_state_machine, &thermal_runaway_bed_timer, current_temperature_bed, target_temperature_bed, 9, THERMAL_RUNAWAY_PROTECTION_BED_PERIOD, THERMAL_RUNAWAY_PROTECTION_BED_HYSTERESIS);
#endif #endif
#ifdef PIDTEMPBED #ifdef PIDTEMPBED
pid_input = current_temperature_bed; pid_input = current_temperature_bed;
#ifndef PID_OPENLOOP #ifndef PID_OPENLOOP
pid_error_bed = target_temperature_bed - pid_input; pid_error_bed = target_temperature_bed - pid_input;
pTerm_bed = bedKp * pid_error_bed; pTerm_bed = bedKp * pid_error_bed;
...@@ -699,7 +685,8 @@ void manage_heater() ...@@ -699,7 +685,8 @@ void manage_heater()
if (pid_output > MAX_BED_POWER) { if (pid_output > MAX_BED_POWER) {
if (pid_error_bed > 0 ) temp_iState_bed -= pid_error_bed; // conditional un-integration if (pid_error_bed > 0 ) temp_iState_bed -= pid_error_bed; // conditional un-integration
pid_output=MAX_BED_POWER; pid_output=MAX_BED_POWER;
} else if (pid_output < 0){ }
else if (pid_output < 0) {
if (pid_error_bed < 0 ) temp_iState_bed -= pid_error_bed; // conditional un-integration if (pid_error_bed < 0 ) temp_iState_bed -= pid_error_bed; // conditional un-integration
pid_output=0; pid_output=0;
} }
...@@ -723,8 +710,7 @@ void manage_heater() ...@@ -723,8 +710,7 @@ void manage_heater()
SERIAL_ECHOLN(dTerm_bed); SERIAL_ECHOLN(dTerm_bed);
#endif //PID_BED_DEBUG #endif //PID_BED_DEBUG
if((current_temperature_bed > BED_MINTEMP) && (current_temperature_bed < BED_MAXTEMP)) if((current_temperature_bed > BED_MINTEMP) && (current_temperature_bed < BED_MAXTEMP)) {
{
soft_pwm_bed = (int)pid_output >> 1; soft_pwm_bed = (int)pid_output >> 1;
} }
else { else {
...@@ -733,47 +719,38 @@ void manage_heater() ...@@ -733,47 +719,38 @@ void manage_heater()
#elif !defined(BED_LIMIT_SWITCHING) #elif !defined(BED_LIMIT_SWITCHING)
// Check if temperature is within the correct range // Check if temperature is within the correct range
if((current_temperature_bed > BED_MINTEMP) && (current_temperature_bed < BED_MAXTEMP)) if((current_temperature_bed > BED_MINTEMP) && (current_temperature_bed < BED_MAXTEMP)) {
{ if(current_temperature_bed >= target_temperature_bed) {
if(current_temperature_bed >= target_temperature_bed)
{
soft_pwm_bed = 0; soft_pwm_bed = 0;
} }
else else {
{
soft_pwm_bed = MAX_BED_POWER>>1; soft_pwm_bed = MAX_BED_POWER>>1;
} }
} }
else else {
{
soft_pwm_bed = 0; soft_pwm_bed = 0;
WRITE(HEATER_BED_PIN,LOW); WRITE(HEATER_BED_PIN,LOW);
} }
#else //#ifdef BED_LIMIT_SWITCHING #else //#ifdef BED_LIMIT_SWITCHING
// Check if temperature is within the correct band // Check if temperature is within the correct band
if((current_temperature_bed > BED_MINTEMP) && (current_temperature_bed < BED_MAXTEMP)) if((current_temperature_bed > BED_MINTEMP) && (current_temperature_bed < BED_MAXTEMP)) {
{ if(current_temperature_bed > target_temperature_bed + BED_HYSTERESIS) {
if(current_temperature_bed > target_temperature_bed + BED_HYSTERESIS)
{
soft_pwm_bed = 0; soft_pwm_bed = 0;
} }
else if(current_temperature_bed <= target_temperature_bed - BED_HYSTERESIS) 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 else {
{
soft_pwm_bed = 0; soft_pwm_bed = 0;
WRITE(HEATER_BED_PIN,LOW); WRITE(HEATER_BED_PIN,LOW);
} }
#endif #endif //BED_LIMIT_SWITCHING
#endif #endif //TEMP_SENSOR_BED != 0
//code for controlling the extruder rate based on the width sensor //code for controlling the extruder rate based on the width sensor
#ifdef FILAMENT_SENSOR #ifdef FILAMENT_SENSOR
if(filament_sensor) if(filament_sensor) {
{
meas_shift_index=delay_index1-meas_delay_cm; meas_shift_index=delay_index1-meas_delay_cm;
if(meas_shift_index<0) if(meas_shift_index<0)
meas_shift_index = meas_shift_index + (MAX_MEASUREMENT_DELAY+1); //loop around buffer if needed meas_shift_index = meas_shift_index + (MAX_MEASUREMENT_DELAY+1); //loop around buffer if needed
...@@ -790,18 +767,19 @@ void manage_heater() ...@@ -790,18 +767,19 @@ void manage_heater()
if (volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM] <0.01) if (volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM] <0.01)
volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM]=0.01; volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM]=0.01;
} }
#endif #endif //FILAMENT_SENSOR
} }
#define PGM_RD_W(x) (short)pgm_read_word(&x) #define PGM_RD_W(x) (short)pgm_read_word(&x)
// Derived from RepRap FiveD extruder::getTemperature() // Derived from RepRap FiveD extruder::getTemperature()
// For hot end temperature measurement. // For hot end temperature measurement.
static float analog2temp(int raw, uint8_t e) { static float analog2temp(int raw, uint8_t e)
#ifdef TEMP_SENSOR_1_AS_REDUNDANT {
#ifdef TEMP_SENSOR_1_AS_REDUNDANT
if(e > EXTRUDERS) if(e > EXTRUDERS)
#else #else
if(e >= EXTRUDERS) if(e >= EXTRUDERS)
#endif #endif
{ {
SERIAL_ERROR_START; SERIAL_ERROR_START;
SERIAL_ERROR((int)e); SERIAL_ERROR((int)e);
...@@ -811,21 +789,16 @@ static float analog2temp(int raw, uint8_t e) { ...@@ -811,21 +789,16 @@ static float analog2temp(int raw, uint8_t e) {
} }
#ifdef HEATER_0_USES_MAX6675 #ifdef HEATER_0_USES_MAX6675
if (e == 0) if (e == 0)
{
return 0.25 * raw; return 0.25 * raw;
}
#endif #endif
if(heater_ttbl_map[e] != NULL) if(heater_ttbl_map[e] != NULL) {
{
float celsius = 0; float celsius = 0;
uint8_t i; uint8_t i;
short (*tt)[][2] = (short (*)[][2])(heater_ttbl_map[e]); short (*tt)[][2] = (short (*)[][2])(heater_ttbl_map[e]);
for (i=1; i<heater_ttbllen_map[e]; i++) for (i=1; i<heater_ttbllen_map[e]; i++) {
{ if (PGM_RD_W((*tt)[i][0]) > raw) {
if (PGM_RD_W((*tt)[i][0]) > raw)
{
celsius = PGM_RD_W((*tt)[i-1][1]) + celsius = PGM_RD_W((*tt)[i-1][1]) +
(raw - PGM_RD_W((*tt)[i-1][0])) * (raw - PGM_RD_W((*tt)[i-1][0])) *
(float)(PGM_RD_W((*tt)[i][1]) - PGM_RD_W((*tt)[i-1][1])) / (float)(PGM_RD_W((*tt)[i][1]) - PGM_RD_W((*tt)[i-1][1])) /
...@@ -844,15 +817,14 @@ static float analog2temp(int raw, uint8_t e) { ...@@ -844,15 +817,14 @@ static float analog2temp(int raw, uint8_t e) {
// Derived from RepRap FiveD extruder::getTemperature() // Derived from RepRap FiveD extruder::getTemperature()
// For bed temperature measurement. // For bed temperature measurement.
static float analog2tempBed(int raw) { static float analog2tempBed(int raw)
{
#ifdef BED_USES_THERMISTOR #ifdef BED_USES_THERMISTOR
float celsius = 0; float celsius = 0;
byte i; byte i;
for (i=1; i<BEDTEMPTABLE_LEN; i++) for (i=1; i<BEDTEMPTABLE_LEN; i++) {
{ if (PGM_RD_W(BEDTEMPTABLE[i][0]) > raw) {
if (PGM_RD_W(BEDTEMPTABLE[i][0]) > raw)
{
celsius = PGM_RD_W(BEDTEMPTABLE[i-1][1]) + celsius = PGM_RD_W(BEDTEMPTABLE[i-1][1]) +
(raw - PGM_RD_W(BEDTEMPTABLE[i-1][0])) * (raw - PGM_RD_W(BEDTEMPTABLE[i-1][0])) *
(float)(PGM_RD_W(BEDTEMPTABLE[i][1]) - PGM_RD_W(BEDTEMPTABLE[i-1][1])) / (float)(PGM_RD_W(BEDTEMPTABLE[i][1]) - PGM_RD_W(BEDTEMPTABLE[i-1][1])) /
...@@ -867,9 +839,9 @@ static float analog2tempBed(int raw) { ...@@ -867,9 +839,9 @@ static float analog2tempBed(int raw) {
return celsius; return celsius;
#elif defined BED_USES_AD595 #elif defined BED_USES_AD595
return ((raw * ((5.0 * 100.0) / 1024.0) / OVERSAMPLENR) * TEMP_SENSOR_AD595_GAIN) + TEMP_SENSOR_AD595_OFFSET; return ((raw * ((5.0 * 100.0) / 1024.0) / OVERSAMPLENR) * TEMP_SENSOR_AD595_GAIN) + TEMP_SENSOR_AD595_OFFSET;
#else #else //NO BED_USES_THERMISTOR
return 0; return 0;
#endif #endif //BED_USES_THERMISTOR
} }
/* Called to get the raw values into the the actual temperatures. The raw values are created in interrupt context, /* Called to get the raw values into the the actual temperatures. The raw values are created in interrupt context,
...@@ -882,11 +854,10 @@ static void updateTemperaturesFromRawValues() ...@@ -882,11 +854,10 @@ static void updateTemperaturesFromRawValues()
#ifndef SINGLENOZZLE #ifndef SINGLENOZZLE
for(uint8_t e=0;e<EXTRUDERS;e++) for(uint8_t e=0;e<EXTRUDERS;e++)
{
#else #else
uint8_t e=0; uint8_t e=0;
{
#endif // !SINGLENOZZLE #endif // !SINGLENOZZLE
{
current_temperature[e] = analog2temp(current_temperature_raw[e], e); current_temperature[e] = analog2temp(current_temperature_raw[e], e);
} }
current_temperature_bed = analog2tempBed(current_temperature_bed_raw); current_temperature_bed = analog2tempBed(current_temperature_bed_raw);
...@@ -904,67 +875,56 @@ static void updateTemperaturesFromRawValues() ...@@ -904,67 +875,56 @@ static void updateTemperaturesFromRawValues()
CRITICAL_SECTION_END; CRITICAL_SECTION_END;
} }
// For converting raw Filament Width to milimeters // For converting raw Filament Width to milimeters
#ifdef FILAMENT_SENSOR #ifdef FILAMENT_SENSOR
float analog2widthFil() { float analog2widthFil() {
return current_raw_filwidth/16383.0*5.0; return current_raw_filwidth/16383.0*5.0;
//return current_raw_filwidth; //return current_raw_filwidth;
} }
// For converting raw Filament Width to a ratio
int widthFil_to_size_ratio() {
float temp;
temp=filament_width_meas; // For converting raw Filament Width to a ratio
if(filament_width_meas<MEASURED_LOWER_LIMIT) int widthFil_to_size_ratio() {
float temp;
temp=filament_width_meas;
if(filament_width_meas<MEASURED_LOWER_LIMIT)
temp=filament_width_nominal; //assume sensor cut out temp=filament_width_nominal; //assume sensor cut out
else if (filament_width_meas>MEASURED_UPPER_LIMIT) else if (filament_width_meas>MEASURED_UPPER_LIMIT)
temp= MEASURED_UPPER_LIMIT; temp= MEASURED_UPPER_LIMIT;
return(filament_width_nominal/temp*100);
}
return(filament_width_nominal/temp*100);
}
#endif #endif
void tp_init() void tp_init()
{ {
#if MB(RUMBA) && ((TEMP_SENSOR_0==-1)||(TEMP_SENSOR_1==-1)||(TEMP_SENSOR_2==-1)||(TEMP_SENSOR_BED==-1)) #if MB(RUMBA) && ((TEMP_SENSOR_0==-1)||(TEMP_SENSOR_1==-1)||(TEMP_SENSOR_2==-1)||(TEMP_SENSOR_BED==-1))
//disable RUMBA JTAG in case the thermocouple extension is plugged on top of JTAG connector //disable RUMBA JTAG in case the thermocouple extension is plugged on top of JTAG connector
MCUCR=(1<<JTD); MCUCR=(1<<JTD);
MCUCR=(1<<JTD); MCUCR=(1<<JTD);
#endif #endif
// Finish init of mult extruder arrays // Finish init of mult extruder arrays
#ifndef SINGLENOZZLE #ifndef SINGLENOZZLE
for (uint8_t e = 0; e < EXTRUDERS; e++) for (uint8_t e = 0; e < EXTRUDERS; e++)
{
#else #else
uint8_t e = 0; uint8_t e = 0;
{
#endif // !SINGLENOZZLE #endif // !SINGLENOZZLE
{
// populate with the first value // populate with the first value
maxttemp[e] = maxttemp[0]; maxttemp[e] = maxttemp[0];
#ifdef PIDTEMP #ifdef PIDTEMP
temp_iState_min[e] = 0.0; temp_iState_min[e] = 0.0;
temp_iState_max[e] = PID_INTEGRAL_DRIVE_MAX / Ki[e]; temp_iState_max[e] = PID_INTEGRAL_DRIVE_MAX / Ki[e];
#endif //PIDTEMP #endif //PIDTEMP
#ifdef PIDTEMPBED #ifdef PIDTEMPBED
temp_iState_min_bed = 0.0; temp_iState_min_bed = 0.0;
temp_iState_max_bed = PID_INTEGRAL_DRIVE_MAX / bedKi; temp_iState_max_bed = PID_INTEGRAL_DRIVE_MAX / bedKi;
#endif //PIDTEMPBED #endif //PIDTEMPBED
} }
#if defined(HEATER_0_PIN) && (HEATER_0_PIN > -1) #if defined(HEATER_0_PIN) && (HEATER_0_PIN > -1)
SET_OUTPUT(HEATER_0_PIN); SET_OUTPUT(HEATER_0_PIN);
#endif #endif
#ifndef SINGLENOZZLE #ifndef SINGLENOZZLE
#if defined(HEATER_1_PIN) && (HEATER_1_PIN > -1) #if defined(HEATER_1_PIN) && (HEATER_1_PIN > -1)
SET_OUTPUT(HEATER_1_PIN); SET_OUTPUT(HEATER_1_PIN);
...@@ -980,6 +940,7 @@ void tp_init() ...@@ -980,6 +940,7 @@ void tp_init()
#if defined(HEATER_BED_PIN) && (HEATER_BED_PIN > -1) #if defined(HEATER_BED_PIN) && (HEATER_BED_PIN > -1)
SET_OUTPUT(HEATER_BED_PIN); SET_OUTPUT(HEATER_BED_PIN);
#endif #endif
#if defined(FAN_PIN) && (FAN_PIN > -1) #if defined(FAN_PIN) && (FAN_PIN > -1)
SET_OUTPUT(FAN_PIN); SET_OUTPUT(FAN_PIN);
#ifdef FAST_PWM_FAN #ifdef FAST_PWM_FAN
...@@ -991,7 +952,6 @@ void tp_init() ...@@ -991,7 +952,6 @@ void tp_init()
#endif #endif
#ifdef HEATER_0_USES_MAX6675 #ifdef HEATER_0_USES_MAX6675
#ifndef SDSUPPORT #ifndef SDSUPPORT
SET_OUTPUT(SCK_PIN); SET_OUTPUT(SCK_PIN);
WRITE(SCK_PIN,0); WRITE(SCK_PIN,0);
...@@ -1004,11 +964,10 @@ void tp_init() ...@@ -1004,11 +964,10 @@ void tp_init()
#else #else
pinMode(SS_PIN, OUTPUT); pinMode(SS_PIN, OUTPUT);
digitalWrite(SS_PIN, HIGH); digitalWrite(SS_PIN, HIGH);
#endif #endif //SDSUPPORT
SET_OUTPUT(MAX6675_SS); SET_OUTPUT(MAX6675_SS);
WRITE(MAX6675_SS,1); WRITE(MAX6675_SS,1);
#endif //HEATER_0_USES_MAX6675 #endif //HEATER_0_USES_MAX6675
// Set analog inputs // Set analog inputs
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment