|
@@ -94,12 +94,12 @@ Temperature thermalManager;
|
94
|
94
|
*/
|
95
|
95
|
|
96
|
96
|
#if HAS_HEATED_BED
|
97
|
|
- #define _BED_PSTR(M,E) (E) == -1 ? PSTR(M) :
|
|
97
|
+ #define _BED_PSTR(M,E) (E) == H_BED ? PSTR(M) :
|
98
|
98
|
#else
|
99
|
99
|
#define _BED_PSTR(M,E)
|
100
|
100
|
#endif
|
101
|
101
|
#if HAS_HEATED_CHAMBER
|
102
|
|
- #define _CHAMBER_PSTR(M,E) (E) == -2 ? PSTR(M) :
|
|
102
|
+ #define _CHAMBER_PSTR(M,E) (E) == H_CHAMBER ? PSTR(M) :
|
103
|
103
|
#else
|
104
|
104
|
#define _CHAMBER_PSTR(M,E)
|
105
|
105
|
#endif
|
|
@@ -345,7 +345,7 @@ temp_range_t Temperature::temp_range[HOTENDS] = ARRAY_BY_HOTENDS(sensor_heater_0
|
345
|
345
|
* Needs sufficient heater power to make some overshoot at target
|
346
|
346
|
* temperature to succeed.
|
347
|
347
|
*/
|
348
|
|
- void Temperature::PID_autotune(const float &target, const int8_t heater, const int8_t ncycles, const bool set_result/*=false*/) {
|
|
348
|
+ void Temperature::PID_autotune(const float &target, const heater_ind_t heater, const int8_t ncycles, const bool set_result/*=false*/) {
|
349
|
349
|
float current = 0.0;
|
350
|
350
|
int cycles = 0;
|
351
|
351
|
bool heating = true;
|
|
@@ -357,7 +357,7 @@ temp_range_t Temperature::temp_range[HOTENDS] = ARRAY_BY_HOTENDS(sensor_heater_0
|
357
|
357
|
PID_t tune_pid = { 0, 0, 0 };
|
358
|
358
|
float max = 0, min = 10000;
|
359
|
359
|
|
360
|
|
- const bool isbed = (heater < 0);
|
|
360
|
+ const bool isbed = (heater == H_BED);
|
361
|
361
|
|
362
|
362
|
#if HAS_PID_FOR_BOTH
|
363
|
363
|
#define GHV(B,H) (isbed ? (B) : (H))
|
|
@@ -618,26 +618,16 @@ temp_range_t Temperature::temp_range[HOTENDS] = ARRAY_BY_HOTENDS(sensor_heater_0
|
618
|
618
|
|
619
|
619
|
Temperature::Temperature() { }
|
620
|
620
|
|
621
|
|
-int16_t Temperature::getHeaterPower(const int8_t heater) {
|
622
|
|
- return (
|
623
|
|
- #if HAS_HEATED_CHAMBER
|
624
|
|
- #if HAS_HEATED_BED
|
625
|
|
- heater == -2
|
626
|
|
- #else
|
627
|
|
- heater < 0
|
628
|
|
- #endif
|
629
|
|
- ? temp_chamber.soft_pwm_amount :
|
630
|
|
- #endif
|
|
621
|
+int16_t Temperature::getHeaterPower(const heater_ind_t heater_id) {
|
|
622
|
+ switch (heater_id) {
|
|
623
|
+ default: return temp_hotend[heater_id].soft_pwm_amount;
|
631
|
624
|
#if HAS_HEATED_BED
|
632
|
|
- #if HAS_HEATED_CHAMBER
|
633
|
|
- heater == -1
|
634
|
|
- #else
|
635
|
|
- heater < 0
|
636
|
|
- #endif
|
637
|
|
- ? temp_bed.soft_pwm_amount :
|
|
625
|
+ case H_BED: return temp_bed.soft_pwm_amount;
|
|
626
|
+ #endif
|
|
627
|
+ #if HAS_HEATED_CHAMBER
|
|
628
|
+ case H_CHAMBER: return temp_chamber.soft_pwm_amount;
|
638
|
629
|
#endif
|
639
|
|
- temp_hotend[heater].soft_pwm_amount
|
640
|
|
- );
|
|
630
|
+ }
|
641
|
631
|
}
|
642
|
632
|
|
643
|
633
|
#if HAS_AUTO_FAN
|
|
@@ -756,7 +746,7 @@ int16_t Temperature::getHeaterPower(const int8_t heater) {
|
756
|
746
|
//
|
757
|
747
|
// Temperature Error Handlers
|
758
|
748
|
//
|
759
|
|
-void Temperature::_temp_error(const int8_t heater, PGM_P const serial_msg, PGM_P const lcd_msg) {
|
|
749
|
+void Temperature::_temp_error(const heater_ind_t heater, PGM_P const serial_msg, PGM_P const lcd_msg) {
|
760
|
750
|
static bool killed = false;
|
761
|
751
|
if (IsRunning()) {
|
762
|
752
|
SERIAL_ERROR_START();
|
|
@@ -764,7 +754,7 @@ void Temperature::_temp_error(const int8_t heater, PGM_P const serial_msg, PGM_P
|
764
|
754
|
SERIAL_ECHOPGM(MSG_STOPPED_HEATER);
|
765
|
755
|
if (heater >= 0) SERIAL_ECHO((int)heater);
|
766
|
756
|
#if HAS_HEATED_CHAMBER
|
767
|
|
- else if (heater == -2) SERIAL_ECHOPGM(MSG_HEATER_CHAMBER);
|
|
757
|
+ else if (heater == H_CHAMBER) SERIAL_ECHOPGM(MSG_HEATER_CHAMBER);
|
768
|
758
|
#endif
|
769
|
759
|
else SERIAL_ECHOPGM(MSG_HEATER_BED);
|
770
|
760
|
SERIAL_EOL();
|
|
@@ -794,21 +784,22 @@ void Temperature::_temp_error(const int8_t heater, PGM_P const serial_msg, PGM_P
|
794
|
784
|
#endif
|
795
|
785
|
}
|
796
|
786
|
|
797
|
|
-void Temperature::max_temp_error(const int8_t heater) {
|
|
787
|
+void Temperature::max_temp_error(const heater_ind_t heater) {
|
798
|
788
|
_temp_error(heater, PSTR(MSG_T_MAXTEMP), TEMP_ERR_PSTR(MSG_ERR_MAXTEMP, heater));
|
799
|
789
|
}
|
800
|
790
|
|
801
|
|
-void Temperature::min_temp_error(const int8_t heater) {
|
|
791
|
+void Temperature::min_temp_error(const heater_ind_t heater) {
|
802
|
792
|
_temp_error(heater, PSTR(MSG_T_MINTEMP), TEMP_ERR_PSTR(MSG_ERR_MINTEMP, heater));
|
803
|
793
|
}
|
804
|
794
|
|
805
|
|
-float Temperature::get_pid_output(const int8_t e) {
|
|
795
|
+float Temperature::get_pid_output_hotend(const uint8_t e) {
|
806
|
796
|
#if HOTENDS == 1
|
807
|
797
|
#define _HOTEND_TEST true
|
808
|
798
|
#else
|
809
|
799
|
#define _HOTEND_TEST (e == active_extruder)
|
810
|
800
|
#endif
|
811
|
801
|
E_UNUSED();
|
|
802
|
+ const uint8_t ee = HOTEND_INDEX;
|
812
|
803
|
float pid_output;
|
813
|
804
|
#if ENABLED(PIDTEMP)
|
814
|
805
|
#if DISABLED(PID_OPENLOOP)
|
|
@@ -816,38 +807,38 @@ float Temperature::get_pid_output(const int8_t e) {
|
816
|
807
|
static float temp_iState[HOTENDS] = { 0 },
|
817
|
808
|
temp_dState[HOTENDS] = { 0 };
|
818
|
809
|
static bool pid_reset[HOTENDS] = { false };
|
819
|
|
- const float pid_error = temp_hotend[HOTEND_INDEX].target - temp_hotend[HOTEND_INDEX].current;
|
|
810
|
+ const float pid_error = temp_hotend[ee].target - temp_hotend[ee].current;
|
820
|
811
|
|
821
|
|
- if (temp_hotend[HOTEND_INDEX].target == 0
|
|
812
|
+ if (temp_hotend[ee].target == 0
|
822
|
813
|
|| pid_error < -(PID_FUNCTIONAL_RANGE)
|
823
|
814
|
#if HEATER_IDLE_HANDLER
|
824
|
|
- || hotend_idle[HOTEND_INDEX].timed_out
|
|
815
|
+ || hotend_idle[ee].timed_out
|
825
|
816
|
#endif
|
826
|
817
|
) {
|
827
|
818
|
pid_output = 0;
|
828
|
|
- pid_reset[HOTEND_INDEX] = true;
|
|
819
|
+ pid_reset[ee] = true;
|
829
|
820
|
}
|
830
|
821
|
else if (pid_error > PID_FUNCTIONAL_RANGE) {
|
831
|
822
|
pid_output = BANG_MAX;
|
832
|
|
- pid_reset[HOTEND_INDEX] = true;
|
|
823
|
+ pid_reset[ee] = true;
|
833
|
824
|
}
|
834
|
825
|
else {
|
835
|
|
- if (pid_reset[HOTEND_INDEX]) {
|
836
|
|
- temp_iState[HOTEND_INDEX] = 0.0;
|
837
|
|
- work_pid[HOTEND_INDEX].Kd = 0.0;
|
838
|
|
- pid_reset[HOTEND_INDEX] = false;
|
|
826
|
+ if (pid_reset[ee]) {
|
|
827
|
+ temp_iState[ee] = 0.0;
|
|
828
|
+ work_pid[ee].Kd = 0.0;
|
|
829
|
+ pid_reset[ee] = false;
|
839
|
830
|
}
|
840
|
831
|
|
841
|
|
- work_pid[HOTEND_INDEX].Kd = work_pid[HOTEND_INDEX].Kd + PID_K2 * (PID_PARAM(Kd, HOTEND_INDEX) * (temp_dState[HOTEND_INDEX] - temp_hotend[HOTEND_INDEX].current) - work_pid[HOTEND_INDEX].Kd);
|
842
|
|
- const float max_power_over_i_gain = (float)PID_MAX / PID_PARAM(Ki, HOTEND_INDEX);
|
843
|
|
- temp_iState[HOTEND_INDEX] = constrain(temp_iState[HOTEND_INDEX] + pid_error, 0, max_power_over_i_gain);
|
844
|
|
- work_pid[HOTEND_INDEX].Kp = PID_PARAM(Kp, HOTEND_INDEX) * pid_error;
|
845
|
|
- work_pid[HOTEND_INDEX].Ki = PID_PARAM(Ki, HOTEND_INDEX) * temp_iState[HOTEND_INDEX];
|
|
832
|
+ work_pid[ee].Kd = work_pid[ee].Kd + PID_K2 * (PID_PARAM(Kd, ee) * (temp_dState[ee] - temp_hotend[ee].current) - work_pid[ee].Kd);
|
|
833
|
+ const float max_power_over_i_gain = (float)PID_MAX / PID_PARAM(Ki, ee);
|
|
834
|
+ temp_iState[ee] = constrain(temp_iState[ee] + pid_error, 0, max_power_over_i_gain);
|
|
835
|
+ work_pid[ee].Kp = PID_PARAM(Kp, ee) * pid_error;
|
|
836
|
+ work_pid[ee].Ki = PID_PARAM(Ki, ee) * temp_iState[ee];
|
846
|
837
|
|
847
|
|
- pid_output = work_pid[HOTEND_INDEX].Kp + work_pid[HOTEND_INDEX].Ki + work_pid[HOTEND_INDEX].Kd;
|
|
838
|
+ pid_output = work_pid[ee].Kp + work_pid[ee].Ki + work_pid[ee].Kd;
|
848
|
839
|
|
849
|
840
|
#if ENABLED(PID_EXTRUSION_SCALING)
|
850
|
|
- work_pid[HOTEND_INDEX].Kc = 0;
|
|
841
|
+ work_pid[ee].Kc = 0;
|
851
|
842
|
if (_HOTEND_TEST) {
|
852
|
843
|
const long e_position = stepper.position(E_AXIS);
|
853
|
844
|
if (e_position > last_e_position) {
|
|
@@ -858,49 +849,51 @@ float Temperature::get_pid_output(const int8_t e) {
|
858
|
849
|
lpq[lpq_ptr] = 0;
|
859
|
850
|
|
860
|
851
|
if (++lpq_ptr >= lpq_len) lpq_ptr = 0;
|
861
|
|
- work_pid[HOTEND_INDEX].Kc = (lpq[lpq_ptr] * planner.steps_to_mm[E_AXIS]) * PID_PARAM(Kc, HOTEND_INDEX);
|
862
|
|
- pid_output += work_pid[HOTEND_INDEX].Kc;
|
|
852
|
+ work_pid[ee].Kc = (lpq[lpq_ptr] * planner.steps_to_mm[E_AXIS]) * PID_PARAM(Kc, ee);
|
|
853
|
+ pid_output += work_pid[ee].Kc;
|
863
|
854
|
}
|
864
|
855
|
#endif // PID_EXTRUSION_SCALING
|
865
|
856
|
|
866
|
857
|
pid_output = constrain(pid_output, 0, PID_MAX);
|
867
|
858
|
}
|
868
|
|
- temp_dState[HOTEND_INDEX] = temp_hotend[HOTEND_INDEX].current;
|
|
859
|
+ temp_dState[ee] = temp_hotend[ee].current;
|
869
|
860
|
|
870
|
861
|
#else // PID_OPENLOOP
|
871
|
862
|
|
872
|
|
- const float pid_output = constrain(temp_hotend[HOTEND_INDEX].target, 0, PID_MAX);
|
|
863
|
+ const float pid_output = constrain(temp_hotend[ee].target, 0, PID_MAX);
|
873
|
864
|
|
874
|
865
|
#endif // PID_OPENLOOP
|
875
|
866
|
|
876
|
867
|
#if ENABLED(PID_DEBUG)
|
877
|
868
|
SERIAL_ECHO_START();
|
878
|
869
|
SERIAL_ECHOPAIR(
|
879
|
|
- MSG_PID_DEBUG, HOTEND_INDEX,
|
880
|
|
- MSG_PID_DEBUG_INPUT, temp_hotend[HOTEND_INDEX].current,
|
|
870
|
+ MSG_PID_DEBUG, ee,
|
|
871
|
+ MSG_PID_DEBUG_INPUT, temp_hotend[ee].current,
|
881
|
872
|
MSG_PID_DEBUG_OUTPUT, pid_output
|
882
|
873
|
);
|
883
|
874
|
#if DISABLED(PID_OPENLOOP)
|
884
|
875
|
SERIAL_ECHOPAIR(
|
885
|
|
- MSG_PID_DEBUG_PTERM, work_pid[HOTEND_INDEX].Kp,
|
886
|
|
- MSG_PID_DEBUG_ITERM, work_pid[HOTEND_INDEX].Ki,
|
887
|
|
- MSG_PID_DEBUG_DTERM, work_pid[HOTEND_INDEX].Kd
|
|
876
|
+ MSG_PID_DEBUG_PTERM, work_pid[ee].Kp,
|
|
877
|
+ MSG_PID_DEBUG_ITERM, work_pid[ee].Ki,
|
|
878
|
+ MSG_PID_DEBUG_DTERM, work_pid[ee].Kd
|
888
|
879
|
#if ENABLED(PID_EXTRUSION_SCALING)
|
889
|
|
- , MSG_PID_DEBUG_CTERM, work_pid[HOTEND_INDEX].Kc
|
|
880
|
+ , MSG_PID_DEBUG_CTERM, work_pid[ee].Kc
|
890
|
881
|
#endif
|
891
|
882
|
);
|
892
|
883
|
#endif
|
893
|
884
|
SERIAL_EOL();
|
894
|
885
|
#endif // PID_DEBUG
|
895
|
886
|
|
896
|
|
- #else /* PID off */
|
|
887
|
+ #else // No PID enabled
|
|
888
|
+
|
897
|
889
|
#if HEATER_IDLE_HANDLER
|
898
|
|
- #define _TIMED_OUT_TEST hotend_idle[HOTEND_INDEX].timed_out
|
|
890
|
+ #define _TIMED_OUT_TEST hotend_idle[ee].timed_out
|
899
|
891
|
#else
|
900
|
892
|
#define _TIMED_OUT_TEST false
|
901
|
893
|
#endif
|
902
|
|
- pid_output = (!_TIMED_OUT_TEST && temp_hotend[HOTEND_INDEX].current < temp_hotend[HOTEND_INDEX].target) ? BANG_MAX : 0;
|
|
894
|
+ pid_output = (!_TIMED_OUT_TEST && temp_hotend[ee].current < temp_hotend[ee].target) ? BANG_MAX : 0;
|
903
|
895
|
#undef _TIMED_OUT_TEST
|
|
896
|
+
|
904
|
897
|
#endif
|
905
|
898
|
|
906
|
899
|
return pid_output;
|
|
@@ -983,13 +976,13 @@ void Temperature::manage_heater() {
|
983
|
976
|
updateTemperaturesFromRawValues(); // also resets the watchdog
|
984
|
977
|
|
985
|
978
|
#if ENABLED(HEATER_0_USES_MAX6675)
|
986
|
|
- if (temp_hotend[0].current > MIN(HEATER_0_MAXTEMP, HEATER_0_MAX6675_TMAX - 1.0)) max_temp_error(0);
|
987
|
|
- if (temp_hotend[0].current < MAX(HEATER_0_MINTEMP, HEATER_0_MAX6675_TMIN + .01)) min_temp_error(0);
|
|
979
|
+ if (temp_hotend[0].current > MIN(HEATER_0_MAXTEMP, HEATER_0_MAX6675_TMAX - 1.0)) max_temp_error(H_E0);
|
|
980
|
+ if (temp_hotend[0].current < MAX(HEATER_0_MINTEMP, HEATER_0_MAX6675_TMIN + .01)) min_temp_error(H_E0);
|
988
|
981
|
#endif
|
989
|
982
|
|
990
|
983
|
#if ENABLED(HEATER_1_USES_MAX6675)
|
991
|
|
- if (temp_hotend[1].current > MIN(HEATER_1_MAXTEMP, HEATER_1_MAX6675_TMAX - 1.0)) max_temp_error(1);
|
992
|
|
- if (temp_hotend[1].current < MAX(HEATER_1_MINTEMP, HEATER_1_MAX6675_TMIN + .01)) min_temp_error(1);
|
|
984
|
+ if (temp_hotend[1].current > MIN(HEATER_1_MAXTEMP, HEATER_1_MAX6675_TMAX - 1.0)) max_temp_error(H_E1);
|
|
985
|
+ if (temp_hotend[1].current < MAX(HEATER_1_MINTEMP, HEATER_1_MAX6675_TMIN + .01)) min_temp_error(H_E1);
|
993
|
986
|
#endif
|
994
|
987
|
|
995
|
988
|
#define HAS_THERMAL_PROTECTION (ENABLED(THERMAL_PROTECTION_HOTENDS) || HAS_THERMALLY_PROTECTED_BED || ENABLED(THERMAL_PROTECTION_CHAMBER))
|
|
@@ -1010,7 +1003,7 @@ void Temperature::manage_heater() {
|
1010
|
1003
|
HOTEND_LOOP() {
|
1011
|
1004
|
#if ENABLED(THERMAL_PROTECTION_HOTENDS)
|
1012
|
1005
|
if (!grace_period && degHotend(e) > temp_range[e].maxtemp)
|
1013
|
|
- _temp_error(e, PSTR(MSG_T_THERMAL_RUNAWAY), TEMP_ERR_PSTR(MSG_THERMAL_RUNAWAY, e));
|
|
1006
|
+ _temp_error((heater_ind_t)e, PSTR(MSG_T_THERMAL_RUNAWAY), TEMP_ERR_PSTR(MSG_THERMAL_RUNAWAY, e));
|
1014
|
1007
|
#endif
|
1015
|
1008
|
|
1016
|
1009
|
#if HEATER_IDLE_HANDLER
|
|
@@ -1019,25 +1012,25 @@ void Temperature::manage_heater() {
|
1019
|
1012
|
|
1020
|
1013
|
#if ENABLED(THERMAL_PROTECTION_HOTENDS)
|
1021
|
1014
|
// Check for thermal runaway
|
1022
|
|
- thermal_runaway_protection(tr_state_machine[e], temp_hotend[e].current, temp_hotend[e].target, e, THERMAL_PROTECTION_PERIOD, THERMAL_PROTECTION_HYSTERESIS);
|
|
1015
|
+ thermal_runaway_protection(tr_state_machine[e], temp_hotend[e].current, temp_hotend[e].target, (heater_ind_t)e, THERMAL_PROTECTION_PERIOD, THERMAL_PROTECTION_HYSTERESIS);
|
1023
|
1016
|
#endif
|
1024
|
1017
|
|
1025
|
|
- temp_hotend[e].soft_pwm_amount = (temp_hotend[e].current > temp_range[e].mintemp || is_preheating(e)) && temp_hotend[e].current < temp_range[e].maxtemp ? (int)get_pid_output(e) >> 1 : 0;
|
|
1018
|
+ temp_hotend[e].soft_pwm_amount = (temp_hotend[e].current > temp_range[e].mintemp || is_preheating(e)) && temp_hotend[e].current < temp_range[e].maxtemp ? (int)get_pid_output_hotend(e) >> 1 : 0;
|
1026
|
1019
|
|
1027
|
1020
|
#if WATCH_HOTENDS
|
1028
|
1021
|
// Make sure temperature is increasing
|
1029
|
1022
|
if (watch_hotend[e].next_ms && ELAPSED(ms, watch_hotend[e].next_ms)) { // Time to check this extruder?
|
1030
|
1023
|
if (degHotend(e) < watch_hotend[e].target) // Failed to increase enough?
|
1031
|
|
- _temp_error(e, PSTR(MSG_T_HEATING_FAILED), TEMP_ERR_PSTR(MSG_HEATING_FAILED_LCD, e));
|
|
1024
|
+ _temp_error((heater_ind_t)e, PSTR(MSG_T_HEATING_FAILED), TEMP_ERR_PSTR(MSG_HEATING_FAILED_LCD, e));
|
1032
|
1025
|
else // Start again if the target is still far off
|
1033
|
|
- start_watching_heater(e);
|
|
1026
|
+ start_watching_hotend(e);
|
1034
|
1027
|
}
|
1035
|
1028
|
#endif
|
1036
|
1029
|
|
1037
|
1030
|
#if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
|
1038
|
1031
|
// Make sure measured temperatures are close together
|
1039
|
1032
|
if (ABS(temp_hotend[0].current - redundant_temperature) > MAX_REDUNDANT_TEMP_SENSOR_DIFF)
|
1040
|
|
- _temp_error(0, PSTR(MSG_REDUNDANCY), PSTR(MSG_ERR_REDUNDANT_TEMP));
|
|
1033
|
+ _temp_error(H_E0, PSTR(MSG_REDUNDANCY), PSTR(MSG_ERR_REDUNDANT_TEMP));
|
1041
|
1034
|
#endif
|
1042
|
1035
|
|
1043
|
1036
|
} // HOTEND_LOOP
|
|
@@ -1066,14 +1059,14 @@ void Temperature::manage_heater() {
|
1066
|
1059
|
|
1067
|
1060
|
#if ENABLED(THERMAL_PROTECTION_BED)
|
1068
|
1061
|
if (!grace_period && degBed() > BED_MAXTEMP)
|
1069
|
|
- _temp_error(-1, PSTR(MSG_T_THERMAL_RUNAWAY), TEMP_ERR_PSTR(MSG_THERMAL_RUNAWAY, -1));
|
|
1062
|
+ _temp_error(H_BED, PSTR(MSG_T_THERMAL_RUNAWAY), TEMP_ERR_PSTR(MSG_THERMAL_RUNAWAY, H_BED));
|
1070
|
1063
|
#endif
|
1071
|
1064
|
|
1072
|
1065
|
#if WATCH_BED
|
1073
|
1066
|
// Make sure temperature is increasing
|
1074
|
1067
|
if (watch_bed.elapsed(ms)) { // Time to check the bed?
|
1075
|
1068
|
if (degBed() < watch_bed.target) // Failed to increase enough?
|
1076
|
|
- _temp_error(-1, PSTR(MSG_T_HEATING_FAILED), TEMP_ERR_PSTR(MSG_HEATING_FAILED_LCD, -1));
|
|
1069
|
+ _temp_error(H_BED, PSTR(MSG_T_HEATING_FAILED), TEMP_ERR_PSTR(MSG_HEATING_FAILED_LCD, H_BED));
|
1077
|
1070
|
else // Start again if the target is still far off
|
1078
|
1071
|
start_watching_bed();
|
1079
|
1072
|
}
|
|
@@ -1098,7 +1091,7 @@ void Temperature::manage_heater() {
|
1098
|
1091
|
#endif
|
1099
|
1092
|
|
1100
|
1093
|
#if HAS_THERMALLY_PROTECTED_BED
|
1101
|
|
- thermal_runaway_protection(tr_state_machine_bed, temp_bed.current, temp_bed.target, -1, THERMAL_PROTECTION_BED_PERIOD, THERMAL_PROTECTION_BED_HYSTERESIS);
|
|
1094
|
+ thermal_runaway_protection(tr_state_machine_bed, temp_bed.current, temp_bed.target, H_BED, THERMAL_PROTECTION_BED_PERIOD, THERMAL_PROTECTION_BED_HYSTERESIS);
|
1102
|
1095
|
#endif
|
1103
|
1096
|
|
1104
|
1097
|
#if HEATER_IDLE_HANDLER
|
|
@@ -1144,14 +1137,14 @@ void Temperature::manage_heater() {
|
1144
|
1137
|
|
1145
|
1138
|
#if ENABLED(THERMAL_PROTECTION_CHAMBER)
|
1146
|
1139
|
if (!grace_period && degChamber() > CHAMBER_MAXTEMP)
|
1147
|
|
- _temp_error(-2, PSTR(MSG_T_THERMAL_RUNAWAY), TEMP_ERR_PSTR(MSG_THERMAL_RUNAWAY, -2));
|
|
1140
|
+ _temp_error(H_CHAMBER, PSTR(MSG_T_THERMAL_RUNAWAY), TEMP_ERR_PSTR(MSG_THERMAL_RUNAWAY, H_CHAMBER));
|
1148
|
1141
|
#endif
|
1149
|
1142
|
|
1150
|
1143
|
#if WATCH_CHAMBER
|
1151
|
1144
|
// Make sure temperature is increasing
|
1152
|
1145
|
if (watch_chamber.elapsed(ms)) { // Time to check the chamber?
|
1153
|
1146
|
if (degChamber() < watch_chamber.target) // Failed to increase enough?
|
1154
|
|
- _temp_error(-2, PSTR(MSG_T_HEATING_FAILED), TEMP_ERR_PSTR(MSG_HEATING_FAILED_LCD, -2));
|
|
1147
|
+ _temp_error(H_CHAMBER, PSTR(MSG_T_HEATING_FAILED), TEMP_ERR_PSTR(MSG_HEATING_FAILED_LCD, H_CHAMBER));
|
1155
|
1148
|
else
|
1156
|
1149
|
start_watching_chamber(); // Start again if the target is still far off
|
1157
|
1150
|
}
|
|
@@ -1176,7 +1169,7 @@ void Temperature::manage_heater() {
|
1176
|
1169
|
}
|
1177
|
1170
|
|
1178
|
1171
|
#if ENABLED(THERMAL_PROTECTION_CHAMBER)
|
1179
|
|
- thermal_runaway_protection(tr_state_machine_chamber, temp_chamber.current, temp_chamber.target, -2, THERMAL_PROTECTION_CHAMBER_PERIOD, THERMAL_PROTECTION_CHAMBER_HYSTERESIS);
|
|
1172
|
+ thermal_runaway_protection(tr_state_machine_chamber, temp_chamber.current, temp_chamber.target, H_CHAMBER, THERMAL_PROTECTION_CHAMBER_PERIOD, THERMAL_PROTECTION_CHAMBER_HYSTERESIS);
|
1180
|
1173
|
#endif
|
1181
|
1174
|
}
|
1182
|
1175
|
|
|
@@ -1782,14 +1775,15 @@ void Temperature::init() {
|
1782
|
1775
|
* their target temperature by a configurable margin.
|
1783
|
1776
|
* This is called when the temperature is set. (M104, M109)
|
1784
|
1777
|
*/
|
1785
|
|
- void Temperature::start_watching_heater(const uint8_t e) {
|
|
1778
|
+ void Temperature::start_watching_hotend(const uint8_t e) {
|
1786
|
1779
|
E_UNUSED();
|
1787
|
|
- if (degTargetHotend(HOTEND_INDEX) && degHotend(HOTEND_INDEX) < degTargetHotend(HOTEND_INDEX) - (WATCH_TEMP_INCREASE + TEMP_HYSTERESIS + 1)) {
|
1788
|
|
- watch_hotend[HOTEND_INDEX].target = degHotend(HOTEND_INDEX) + WATCH_TEMP_INCREASE;
|
1789
|
|
- watch_hotend[HOTEND_INDEX].next_ms = millis() + (WATCH_TEMP_PERIOD) * 1000UL;
|
|
1780
|
+ const uint8_t ee = HOTEND_INDEX;
|
|
1781
|
+ if (degTargetHotend(ee) && degHotend(ee) < degTargetHotend(ee) - (WATCH_TEMP_INCREASE + TEMP_HYSTERESIS + 1)) {
|
|
1782
|
+ watch_hotend[ee].target = degHotend(ee) + WATCH_TEMP_INCREASE;
|
|
1783
|
+ watch_hotend[ee].next_ms = millis() + (WATCH_TEMP_PERIOD) * 1000UL;
|
1790
|
1784
|
}
|
1791
|
1785
|
else
|
1792
|
|
- watch_hotend[HOTEND_INDEX].next_ms = 0;
|
|
1786
|
+ watch_hotend[ee].next_ms = 0;
|
1793
|
1787
|
}
|
1794
|
1788
|
#endif
|
1795
|
1789
|
|
|
@@ -1837,14 +1831,14 @@ void Temperature::init() {
|
1837
|
1831
|
Temperature::tr_state_machine_t Temperature::tr_state_machine_chamber; // = { TRInactive, 0 };
|
1838
|
1832
|
#endif
|
1839
|
1833
|
|
1840
|
|
- void Temperature::thermal_runaway_protection(Temperature::tr_state_machine_t &sm, const float ¤t, const float &target, const int8_t heater_id, const uint16_t period_seconds, const uint16_t hysteresis_degc) {
|
|
1834
|
+ void Temperature::thermal_runaway_protection(Temperature::tr_state_machine_t &sm, const float ¤t, const float &target, const heater_ind_t heater_id, const uint16_t period_seconds, const uint16_t hysteresis_degc) {
|
1841
|
1835
|
|
1842
|
1836
|
static float tr_target_temperature[HOTENDS + 1] = { 0.0 };
|
1843
|
1837
|
|
1844
|
1838
|
/**
|
1845
|
1839
|
SERIAL_ECHO_START();
|
1846
|
1840
|
SERIAL_ECHOPGM("Thermal Thermal Runaway Running. Heater ID: ");
|
1847
|
|
- if (heater_id == -2) SERIAL_ECHOPGM("chamber");
|
|
1841
|
+ if (heater_id == H_CHAMBER) SERIAL_ECHOPGM("chamber");
|
1848
|
1842
|
if (heater_id < 0) SERIAL_ECHOPGM("bed"); else SERIAL_ECHO(heater_id);
|
1849
|
1843
|
SERIAL_ECHOPAIR(" ; State:", sm.state, " ; Timer:", sm.timer, " ; Temperature:", current, " ; Target Temp:", target);
|
1850
|
1844
|
if (heater_id >= 0)
|
|
@@ -2233,12 +2227,12 @@ void Temperature::readings_ready() {
|
2233
|
2227
|
|| temp_hotend[e].soft_pwm_amount > 0
|
2234
|
2228
|
#endif
|
2235
|
2229
|
);
|
2236
|
|
- if (rawtemp > temp_range[e].raw_max * tdir) max_temp_error(e);
|
|
2230
|
+ if (rawtemp > temp_range[e].raw_max * tdir) max_temp_error((heater_ind_t)e);
|
2237
|
2231
|
if (heater_on && rawtemp < temp_range[e].raw_min * tdir && !is_preheating(e)) {
|
2238
|
2232
|
#ifdef MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED
|
2239
|
2233
|
if (++consecutive_low_temperature_error[e] >= MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED)
|
2240
|
2234
|
#endif
|
2241
|
|
- min_temp_error(e);
|
|
2235
|
+ min_temp_error((heater_ind_t)e);
|
2242
|
2236
|
}
|
2243
|
2237
|
#ifdef MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED
|
2244
|
2238
|
else
|
|
@@ -2258,8 +2252,8 @@ void Temperature::readings_ready() {
|
2258
|
2252
|
|| (temp_bed.soft_pwm_amount > 0)
|
2259
|
2253
|
#endif
|
2260
|
2254
|
;
|
2261
|
|
- if (BEDCMP(temp_bed.raw, maxtemp_raw_BED)) max_temp_error(-1);
|
2262
|
|
- if (bed_on && BEDCMP(mintemp_raw_BED, temp_bed.raw)) min_temp_error(-1);
|
|
2255
|
+ if (BEDCMP(temp_bed.raw, maxtemp_raw_BED)) max_temp_error(H_BED);
|
|
2256
|
+ if (bed_on && BEDCMP(mintemp_raw_BED, temp_bed.raw)) min_temp_error(H_BED);
|
2263
|
2257
|
#endif
|
2264
|
2258
|
|
2265
|
2259
|
#if HAS_HEATED_CHAMBER
|
|
@@ -2269,8 +2263,8 @@ void Temperature::readings_ready() {
|
2269
|
2263
|
#define CHAMBERCMP(A,B) ((A)>=(B))
|
2270
|
2264
|
#endif
|
2271
|
2265
|
const bool chamber_on = (temp_chamber.target > 0);
|
2272
|
|
- if (CHAMBERCMP(temp_chamber.raw, maxtemp_raw_CHAMBER)) max_temp_error(-2);
|
2273
|
|
- if (chamber_on && CHAMBERCMP(mintemp_raw_CHAMBER, temp_chamber.raw)) min_temp_error(-2);
|
|
2266
|
+ if (CHAMBERCMP(temp_chamber.raw, maxtemp_raw_CHAMBER)) max_temp_error(H_CHAMBER);
|
|
2267
|
+ if (chamber_on && CHAMBERCMP(mintemp_raw_CHAMBER, temp_chamber.raw)) min_temp_error(H_CHAMBER);
|
2274
|
2268
|
#endif
|
2275
|
2269
|
}
|
2276
|
2270
|
|
|
@@ -2782,20 +2776,20 @@ void Temperature::isr() {
|
2782
|
2776
|
#if ENABLED(SHOW_TEMP_ADC_VALUES)
|
2783
|
2777
|
, const float r
|
2784
|
2778
|
#endif
|
2785
|
|
- , const int8_t e=-3
|
|
2779
|
+ , const heater_ind_t e=INDEX_NONE
|
2786
|
2780
|
) {
|
2787
|
2781
|
char k;
|
2788
|
2782
|
switch (e) {
|
2789
|
2783
|
#if HAS_TEMP_CHAMBER
|
2790
|
|
- case -2: k = 'C'; break;
|
|
2784
|
+ case H_CHAMBER: k = 'C'; break;
|
2791
|
2785
|
#endif
|
2792
|
2786
|
#if HAS_TEMP_HOTEND
|
2793
|
2787
|
default: k = 'T'; break;
|
2794
|
2788
|
#if HAS_HEATED_BED
|
2795
|
|
- case -1: k = 'B'; break;
|
|
2789
|
+ case H_BED: k = 'B'; break;
|
2796
|
2790
|
#endif
|
2797
|
2791
|
#if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
|
2798
|
|
- case -3: k = 'R'; break;
|
|
2792
|
+ case H_REDUNDANT: k = 'R'; break;
|
2799
|
2793
|
#endif
|
2800
|
2794
|
#elif HAS_HEATED_BED
|
2801
|
2795
|
default: k = 'B'; break;
|
|
@@ -2832,7 +2826,7 @@ void Temperature::isr() {
|
2832
|
2826
|
#if ENABLED(SHOW_TEMP_ADC_VALUES)
|
2833
|
2827
|
, redundant_temperature_raw
|
2834
|
2828
|
#endif
|
2835
|
|
- , -3 // REDUNDANT
|
|
2829
|
+ , H_REDUNDANT
|
2836
|
2830
|
);
|
2837
|
2831
|
#endif
|
2838
|
2832
|
#endif
|
|
@@ -2841,7 +2835,7 @@ void Temperature::isr() {
|
2841
|
2835
|
#if ENABLED(SHOW_TEMP_ADC_VALUES)
|
2842
|
2836
|
, rawBedTemp()
|
2843
|
2837
|
#endif
|
2844
|
|
- , -1 // BED
|
|
2838
|
+ , H_BED
|
2845
|
2839
|
);
|
2846
|
2840
|
#endif
|
2847
|
2841
|
#if HAS_TEMP_CHAMBER
|
|
@@ -2854,7 +2848,7 @@ void Temperature::isr() {
|
2854
|
2848
|
#if ENABLED(SHOW_TEMP_ADC_VALUES)
|
2855
|
2849
|
, rawChamberTemp()
|
2856
|
2850
|
#endif
|
2857
|
|
- , -2 // CHAMBER
|
|
2851
|
+ , H_CHAMBER
|
2858
|
2852
|
);
|
2859
|
2853
|
#endif // HAS_TEMP_CHAMBER
|
2860
|
2854
|
#if HOTENDS > 1
|
|
@@ -2862,21 +2856,21 @@ void Temperature::isr() {
|
2862
|
2856
|
#if ENABLED(SHOW_TEMP_ADC_VALUES)
|
2863
|
2857
|
, rawHotendTemp(e)
|
2864
|
2858
|
#endif
|
2865
|
|
- , e
|
|
2859
|
+ , (heater_ind_t)e
|
2866
|
2860
|
);
|
2867
|
2861
|
#endif
|
2868
|
|
- SERIAL_ECHOPAIR(" @:", getHeaterPower(target_extruder));
|
|
2862
|
+ SERIAL_ECHOPAIR(" @:", getHeaterPower((heater_ind_t)target_extruder));
|
2869
|
2863
|
#if HAS_HEATED_BED
|
2870
|
|
- SERIAL_ECHOPAIR(" B@:", getHeaterPower(-1));
|
|
2864
|
+ SERIAL_ECHOPAIR(" B@:", getHeaterPower(H_BED));
|
2871
|
2865
|
#endif
|
2872
|
2866
|
#if HAS_HEATED_CHAMBER
|
2873
|
|
- SERIAL_ECHOPAIR(" C@:", getHeaterPower(-2));
|
|
2867
|
+ SERIAL_ECHOPAIR(" C@:", getHeaterPower(H_CHAMBER));
|
2874
|
2868
|
#endif
|
2875
|
2869
|
#if HOTENDS > 1
|
2876
|
2870
|
HOTEND_LOOP() {
|
2877
|
2871
|
SERIAL_ECHOPAIR(" @", e);
|
2878
|
2872
|
SERIAL_CHAR(':');
|
2879
|
|
- SERIAL_ECHO(getHeaterPower(e));
|
|
2873
|
+ SERIAL_ECHO(getHeaterPower((heater_ind_t)e));
|
2880
|
2874
|
}
|
2881
|
2875
|
#endif
|
2882
|
2876
|
}
|