Enforce sensor range for temperature target (#18465)
* Mitigate stepper timeout * Add CHAMBER PWM code * Structured thermistor tables * Fix reversed sensor ranges * Prevent temps outside sensor range
This commit is contained in:
@ -110,12 +110,12 @@
|
||||
|
||||
#if HOTEND_USES_THERMISTOR
|
||||
#if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
|
||||
static const void* heater_ttbl_map[2] = { (void*)HEATER_0_TEMPTABLE, (void*)HEATER_1_TEMPTABLE };
|
||||
static const temp_entry_t* heater_ttbl_map[2] = { HEATER_0_TEMPTABLE, HEATER_1_TEMPTABLE };
|
||||
static constexpr uint8_t heater_ttbllen_map[2] = { HEATER_0_TEMPTABLE_LEN, HEATER_1_TEMPTABLE_LEN };
|
||||
#else
|
||||
#define NEXT_TEMPTABLE(N) ,HEATER_##N##_TEMPTABLE
|
||||
#define NEXT_TEMPTABLE_LEN(N) ,HEATER_##N##_TEMPTABLE_LEN
|
||||
static const void* heater_ttbl_map[HOTENDS] = ARRAY_BY_HOTENDS(HEATER_0_TEMPTABLE REPEAT_S(1, HOTENDS, NEXT_TEMPTABLE));
|
||||
static const temp_entry_t* heater_ttbl_map[HOTENDS] = ARRAY_BY_HOTENDS(HEATER_0_TEMPTABLE REPEAT_S(1, HOTENDS, NEXT_TEMPTABLE));
|
||||
static constexpr uint8_t heater_ttbllen_map[HOTENDS] = ARRAY_BY_HOTENDS(HEATER_0_TEMPTABLE_LEN REPEAT_S(1, HOTENDS, NEXT_TEMPTABLE_LEN));
|
||||
#endif
|
||||
#endif
|
||||
@ -900,11 +900,13 @@ void Temperature::min_temp_error(const heater_ind_t heater) {
|
||||
SERIAL_ECHO_START();
|
||||
SERIAL_ECHOPAIR(STR_PID_DEBUG, ee, STR_PID_DEBUG_INPUT, temp_hotend[ee].celsius, STR_PID_DEBUG_OUTPUT, pid_output);
|
||||
#if DISABLED(PID_OPENLOOP)
|
||||
{
|
||||
SERIAL_ECHOPAIR( STR_PID_DEBUG_PTERM, work_pid[ee].Kp, STR_PID_DEBUG_ITERM, work_pid[ee].Ki, STR_PID_DEBUG_DTERM, work_pid[ee].Kd
|
||||
#if ENABLED(PID_EXTRUSION_SCALING)
|
||||
, STR_PID_DEBUG_CTERM, work_pid[ee].Kc
|
||||
#endif
|
||||
);
|
||||
}
|
||||
#endif
|
||||
SERIAL_EOL();
|
||||
}
|
||||
@ -920,7 +922,7 @@ void Temperature::min_temp_error(const heater_ind_t heater) {
|
||||
return pid_output;
|
||||
}
|
||||
|
||||
#endif // HOTENDS
|
||||
#endif // HAS_HOTEND
|
||||
|
||||
#if ENABLED(PIDTEMPBED)
|
||||
|
||||
@ -1058,7 +1060,7 @@ void Temperature::manage_heater() {
|
||||
|
||||
} // HOTEND_LOOP
|
||||
|
||||
#endif // HOTENDS
|
||||
#endif // HAS_HOTEND
|
||||
|
||||
#if HAS_AUTO_FAN
|
||||
if (ELAPSED(ms, next_auto_fan_check_ms)) { // only need to check fan state very infrequently
|
||||
@ -1208,22 +1210,22 @@ void Temperature::manage_heater() {
|
||||
* Bisect search for the range of the 'raw' value, then interpolate
|
||||
* proportionally between the under and over values.
|
||||
*/
|
||||
#define SCAN_THERMISTOR_TABLE(TBL,LEN) do{ \
|
||||
uint8_t l = 0, r = LEN, m; \
|
||||
for (;;) { \
|
||||
m = (l + r) >> 1; \
|
||||
if (!m) return short(pgm_read_word(&TBL[0][1])); \
|
||||
if (m == l || m == r) return short(pgm_read_word(&TBL[LEN-1][1])); \
|
||||
short v00 = pgm_read_word(&TBL[m-1][0]), \
|
||||
v10 = pgm_read_word(&TBL[m-0][0]); \
|
||||
if (raw < v00) r = m; \
|
||||
else if (raw > v10) l = m; \
|
||||
else { \
|
||||
const short v01 = short(pgm_read_word(&TBL[m-1][1])), \
|
||||
v11 = short(pgm_read_word(&TBL[m-0][1])); \
|
||||
return v01 + (raw - v00) * float(v11 - v01) / float(v10 - v00); \
|
||||
} \
|
||||
} \
|
||||
#define SCAN_THERMISTOR_TABLE(TBL,LEN) do{ \
|
||||
uint8_t l = 0, r = LEN, m; \
|
||||
for (;;) { \
|
||||
m = (l + r) >> 1; \
|
||||
if (!m) return int16_t(pgm_read_word(&TBL[0].celsius)); \
|
||||
if (m == l || m == r) return int16_t(pgm_read_word(&TBL[LEN-1].celsius)); \
|
||||
int16_t v00 = pgm_read_word(&TBL[m-1].value), \
|
||||
v10 = pgm_read_word(&TBL[m-0].value); \
|
||||
if (raw < v00) r = m; \
|
||||
else if (raw > v10) l = m; \
|
||||
else { \
|
||||
const int16_t v01 = int16_t(pgm_read_word(&TBL[m-1].celsius)), \
|
||||
v11 = int16_t(pgm_read_word(&TBL[m-0].celsius)); \
|
||||
return v01 + (raw - v00) * float(v11 - v01) / float(v10 - v00); \
|
||||
} \
|
||||
} \
|
||||
}while(0)
|
||||
|
||||
#if HAS_USER_THERMISTORS
|
||||
@ -1452,13 +1454,13 @@ void Temperature::manage_heater() {
|
||||
|
||||
#if HOTEND_USES_THERMISTOR
|
||||
// Thermistor with conversion table?
|
||||
const short(*tt)[][2] = (short(*)[][2])(heater_ttbl_map[e]);
|
||||
const temp_entry_t(*tt)[] = (temp_entry_t(*)[])(heater_ttbl_map[e]);
|
||||
SCAN_THERMISTOR_TABLE((*tt), heater_ttbllen_map[e]);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif // HOTENDS
|
||||
#endif // HAS_HOTEND
|
||||
|
||||
#if HAS_HEATED_BED
|
||||
// Derived from RepRap FiveD extruder::getTemperature()
|
||||
@ -1790,80 +1792,91 @@ void Temperature::init() {
|
||||
#if HAS_HOTEND
|
||||
|
||||
#define _TEMP_MIN_E(NR) do{ \
|
||||
temp_range[NR].mintemp = HEATER_ ##NR## _MINTEMP; \
|
||||
while (analog_to_celsius_hotend(temp_range[NR].raw_min, NR) < HEATER_ ##NR## _MINTEMP) \
|
||||
const int16_t tmin = _MAX(HEATER_ ##NR## _MINTEMP, (int16_t)pgm_read_word(&HEATER_ ##NR## _TEMPTABLE[HEATER_ ##NR## _SENSOR_MINTEMP_IND].celsius)); \
|
||||
temp_range[NR].mintemp = tmin; \
|
||||
while (analog_to_celsius_hotend(temp_range[NR].raw_min, NR) < tmin) \
|
||||
temp_range[NR].raw_min += TEMPDIR(NR) * (OVERSAMPLENR); \
|
||||
}while(0)
|
||||
#define _TEMP_MAX_E(NR) do{ \
|
||||
temp_range[NR].maxtemp = HEATER_ ##NR## _MAXTEMP; \
|
||||
while (analog_to_celsius_hotend(temp_range[NR].raw_max, NR) > HEATER_ ##NR## _MAXTEMP) \
|
||||
const int16_t tmax = _MIN(HEATER_ ##NR## _MAXTEMP, (int16_t)pgm_read_word(&HEATER_ ##NR## _TEMPTABLE[HEATER_ ##NR## _SENSOR_MAXTEMP_IND].celsius) - 1); \
|
||||
temp_range[NR].maxtemp = tmax; \
|
||||
while (analog_to_celsius_hotend(temp_range[NR].raw_max, NR) > tmax) \
|
||||
temp_range[NR].raw_max -= TEMPDIR(NR) * (OVERSAMPLENR); \
|
||||
}while(0)
|
||||
|
||||
#ifdef HEATER_0_MINTEMP
|
||||
#if THERMISTOR_HEATER_0
|
||||
#ifdef HEATER_0_MINTEMP
|
||||
_TEMP_MIN_E(0);
|
||||
#endif
|
||||
#ifdef HEATER_0_MAXTEMP
|
||||
_TEMP_MAX_E(0);
|
||||
#endif
|
||||
#endif
|
||||
#ifdef HEATER_0_MAXTEMP
|
||||
_TEMP_MAX_E(0);
|
||||
#endif
|
||||
#if HAS_MULTI_HOTEND
|
||||
|
||||
#if HAS_MULTI_HOTEND && THERMISTOR_HEATER_1
|
||||
#ifdef HEATER_1_MINTEMP
|
||||
_TEMP_MIN_E(1);
|
||||
#endif
|
||||
#ifdef HEATER_1_MAXTEMP
|
||||
_TEMP_MAX_E(1);
|
||||
#endif
|
||||
#if HOTENDS > 2
|
||||
#ifdef HEATER_2_MINTEMP
|
||||
_TEMP_MIN_E(2);
|
||||
#endif
|
||||
#ifdef HEATER_2_MAXTEMP
|
||||
_TEMP_MAX_E(2);
|
||||
#endif
|
||||
#if HOTENDS > 3
|
||||
#ifdef HEATER_3_MINTEMP
|
||||
_TEMP_MIN_E(3);
|
||||
#endif
|
||||
#ifdef HEATER_3_MAXTEMP
|
||||
_TEMP_MAX_E(3);
|
||||
#endif
|
||||
#if HOTENDS > 4
|
||||
#ifdef HEATER_4_MINTEMP
|
||||
_TEMP_MIN_E(4);
|
||||
#endif
|
||||
#ifdef HEATER_4_MAXTEMP
|
||||
_TEMP_MAX_E(4);
|
||||
#endif
|
||||
#if HOTENDS > 5
|
||||
#ifdef HEATER_5_MINTEMP
|
||||
_TEMP_MIN_E(5);
|
||||
#endif
|
||||
#ifdef HEATER_5_MAXTEMP
|
||||
_TEMP_MAX_E(5);
|
||||
#endif
|
||||
#if HOTENDS > 6
|
||||
#ifdef HEATER_6_MINTEMP
|
||||
_TEMP_MIN_E(6);
|
||||
#endif
|
||||
#ifdef HEATER_6_MAXTEMP
|
||||
_TEMP_MAX_E(6);
|
||||
#endif
|
||||
#if HOTENDS > 7
|
||||
#ifdef HEATER_7_MINTEMP
|
||||
_TEMP_MIN_E(7);
|
||||
#endif
|
||||
#ifdef HEATER_7_MAXTEMP
|
||||
_TEMP_MAX_E(7);
|
||||
#endif
|
||||
#endif // HOTENDS > 7
|
||||
#endif // HOTENDS > 6
|
||||
#endif // HOTENDS > 5
|
||||
#endif // HOTENDS > 4
|
||||
#endif // HOTENDS > 3
|
||||
#endif // HOTENDS > 2
|
||||
#endif // HAS_MULTI_HOTEND
|
||||
#endif
|
||||
|
||||
#endif // HOTENDS
|
||||
#if HOTENDS > 2 && THERMISTOR_HEATER_2
|
||||
#ifdef HEATER_2_MINTEMP
|
||||
_TEMP_MIN_E(2);
|
||||
#endif
|
||||
#ifdef HEATER_2_MAXTEMP
|
||||
_TEMP_MAX_E(2);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if HOTENDS > 3 && THERMISTOR_HEATER_3
|
||||
#ifdef HEATER_3_MINTEMP
|
||||
_TEMP_MIN_E(3);
|
||||
#endif
|
||||
#ifdef HEATER_3_MAXTEMP
|
||||
_TEMP_MAX_E(3);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if HOTENDS > 4 && THERMISTOR_HEATER_4
|
||||
#ifdef HEATER_4_MINTEMP
|
||||
_TEMP_MIN_E(4);
|
||||
#endif
|
||||
#ifdef HEATER_4_MAXTEMP
|
||||
_TEMP_MAX_E(4);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if HOTENDS > 5 && THERMISTOR_HEATER_5
|
||||
#ifdef HEATER_5_MINTEMP
|
||||
_TEMP_MIN_E(5);
|
||||
#endif
|
||||
#ifdef HEATER_5_MAXTEMP
|
||||
_TEMP_MAX_E(5);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if HOTENDS > 6 && THERMISTOR_HEATER_6
|
||||
#ifdef HEATER_6_MINTEMP
|
||||
_TEMP_MIN_E(6);
|
||||
#endif
|
||||
#ifdef HEATER_6_MAXTEMP
|
||||
_TEMP_MAX_E(6);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if HOTENDS > 7 && THERMISTOR_HEATER_7
|
||||
#ifdef HEATER_7_MINTEMP
|
||||
_TEMP_MIN_E(7);
|
||||
#endif
|
||||
#ifdef HEATER_7_MAXTEMP
|
||||
_TEMP_MAX_E(7);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif // HAS_HOTEND
|
||||
|
||||
#if HAS_HEATED_BED
|
||||
#ifdef BED_MINTEMP
|
||||
@ -2319,7 +2332,7 @@ void Temperature::readings_ready() {
|
||||
}
|
||||
}
|
||||
|
||||
#endif // HOTENDS
|
||||
#endif // HAS_HOTEND
|
||||
|
||||
#if HAS_HEATED_BED
|
||||
#if TEMPDIR(BED) < 0
|
||||
@ -2573,6 +2586,10 @@ void Temperature::tick() {
|
||||
_SLOW_PWM(BED, soft_pwm_bed, temp_bed);
|
||||
#endif
|
||||
|
||||
#if HAS_HEATED_CHAMBER
|
||||
_SLOW_PWM(CHAMBER, soft_pwm_chamber, temp_chamber);
|
||||
#endif
|
||||
|
||||
} // slow_pwm_count == 0
|
||||
|
||||
#if HAS_HOTEND
|
||||
@ -2584,6 +2601,10 @@ void Temperature::tick() {
|
||||
_PWM_OFF(BED, soft_pwm_bed);
|
||||
#endif
|
||||
|
||||
#if HAS_HEATED_CHAMBER
|
||||
_PWM_OFF(CHAMBER, soft_pwm_chamber);
|
||||
#endif
|
||||
|
||||
#if ENABLED(FAN_SOFT_PWM)
|
||||
if (pwm_count_tmp >= 127) {
|
||||
pwm_count_tmp = 0;
|
||||
@ -2662,6 +2683,7 @@ void Temperature::tick() {
|
||||
HOTEND_LOOP() soft_pwm_hotend[e].dec();
|
||||
#endif
|
||||
TERN_(HAS_HEATED_BED, soft_pwm_bed.dec());
|
||||
TERN_(HAS_HEATED_CHAMBER, soft_pwm_chamber.dec());
|
||||
}
|
||||
|
||||
#endif // SLOW_PWM_HEATERS
|
||||
|
Reference in New Issue
Block a user