Tweak some SoftPWM code
This commit is contained in:
parent
32de09f5c5
commit
22ebbc091f
@ -267,19 +267,29 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
|
|||||||
workKp = 0, workKi = 0, workKd = 0,
|
workKp = 0, workKi = 0, workKd = 0,
|
||||||
max = 0, min = 10000;
|
max = 0, min = 10000;
|
||||||
|
|
||||||
#define HAS_TP_BED (ENABLED(THERMAL_PROTECTION_BED) && ENABLED(PIDTEMPBED))
|
#if HAS_PID_FOR_BOTH
|
||||||
#if HAS_TP_BED && ENABLED(THERMAL_PROTECTION_HOTENDS) && ENABLED(PIDTEMP)
|
#define GHV(B,H) (hotend < 0 ? (B) : (H))
|
||||||
#define TV(B,H) (hotend < 0 ? (B) : (H))
|
#define SHV(S,B,H) if (hotend < 0) S##_bed = B; else S [hotend] = H;
|
||||||
#elif HAS_TP_BED
|
#elif ENABLED(PIDTEMPBED)
|
||||||
#define TV(B,H) (B)
|
#define GHV(B,H) B
|
||||||
|
#define SHV(S,B,H) (S##_bed = B)
|
||||||
#else
|
#else
|
||||||
#define TV(B,H) (H)
|
#define GHV(B,H) H
|
||||||
|
#define SHV(S,B,H) (S [hotend] = H)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if WATCH_THE_BED || WATCH_HOTENDS
|
#if WATCH_THE_BED || WATCH_HOTENDS
|
||||||
const uint16_t watch_temp_period = TV(WATCH_BED_TEMP_PERIOD, WATCH_TEMP_PERIOD);
|
#define HAS_TP_BED (ENABLED(THERMAL_PROTECTION_BED) && ENABLED(PIDTEMPBED))
|
||||||
const uint8_t watch_temp_increase = TV(WATCH_BED_TEMP_INCREASE, WATCH_TEMP_INCREASE);
|
#if HAS_TP_BED && ENABLED(THERMAL_PROTECTION_HOTENDS) && ENABLED(PIDTEMP)
|
||||||
const float watch_temp_target = target - float(watch_temp_increase + TV(TEMP_BED_HYSTERESIS, TEMP_HYSTERESIS) + 1);
|
#define GTV(B,H) (hotend < 0 ? (B) : (H))
|
||||||
|
#elif HAS_TP_BED
|
||||||
|
#define GTV(B,H) (B)
|
||||||
|
#else
|
||||||
|
#define GTV(B,H) (H)
|
||||||
|
#endif
|
||||||
|
const uint16_t watch_temp_period = GTV(WATCH_BED_TEMP_PERIOD, WATCH_TEMP_PERIOD);
|
||||||
|
const uint8_t watch_temp_increase = GTV(WATCH_BED_TEMP_INCREASE, WATCH_TEMP_INCREASE);
|
||||||
|
const float watch_temp_target = target - float(watch_temp_increase + GTV(TEMP_BED_HYSTERESIS, TEMP_HYSTERESIS) + 1);
|
||||||
millis_t temp_change_ms = next_temp_ms + watch_temp_period * 1000UL;
|
millis_t temp_change_ms = next_temp_ms + watch_temp_period * 1000UL;
|
||||||
float next_watch_temp = 0.0;
|
float next_watch_temp = 0.0;
|
||||||
bool heated = false;
|
bool heated = false;
|
||||||
@ -309,16 +319,7 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
|
|||||||
|
|
||||||
disable_all_heaters(); // switch off all heaters.
|
disable_all_heaters(); // switch off all heaters.
|
||||||
|
|
||||||
#if HAS_PID_FOR_BOTH
|
SHV(soft_pwm_amount, bias = d = (MAX_BED_POWER) >> 1, bias = d = (PID_MAX) >> 1);
|
||||||
if (hotend < 0)
|
|
||||||
soft_pwm_amount_bed = bias = d = (MAX_BED_POWER) >> 1;
|
|
||||||
else
|
|
||||||
soft_pwm_amount[hotend] = bias = d = (PID_MAX) >> 1;
|
|
||||||
#elif ENABLED(PIDTEMP)
|
|
||||||
soft_pwm_amount[hotend] = bias = d = (PID_MAX) >> 1;
|
|
||||||
#else
|
|
||||||
soft_pwm_amount_bed = bias = d = (MAX_BED_POWER) >> 1;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
wait_for_heatup = true; // Can be interrupted with M108
|
wait_for_heatup = true; // Can be interrupted with M108
|
||||||
|
|
||||||
@ -331,15 +332,7 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
|
|||||||
updateTemperaturesFromRawValues();
|
updateTemperaturesFromRawValues();
|
||||||
|
|
||||||
// Get the current temperature and constrain it
|
// Get the current temperature and constrain it
|
||||||
current =
|
current = GHV(current_temperature_bed, current_temperature[hotend]);
|
||||||
#if HAS_PID_FOR_BOTH
|
|
||||||
hotend < 0 ? current_temperature_bed : current_temperature[hotend]
|
|
||||||
#elif ENABLED(PIDTEMP)
|
|
||||||
current_temperature[hotend]
|
|
||||||
#else
|
|
||||||
current_temperature_bed
|
|
||||||
#endif
|
|
||||||
;
|
|
||||||
NOLESS(max, current);
|
NOLESS(max, current);
|
||||||
NOMORE(min, current);
|
NOMORE(min, current);
|
||||||
|
|
||||||
@ -353,16 +346,7 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
|
|||||||
if (heating && current > target) {
|
if (heating && current > target) {
|
||||||
if (ELAPSED(ms, t2 + 5000UL)) {
|
if (ELAPSED(ms, t2 + 5000UL)) {
|
||||||
heating = false;
|
heating = false;
|
||||||
#if HAS_PID_FOR_BOTH
|
SHV(soft_pwm_amount, (bias - d) >> 1, (bias - d) >> 1);
|
||||||
if (hotend < 0)
|
|
||||||
soft_pwm_amount_bed = (bias - d) >> 1;
|
|
||||||
else
|
|
||||||
soft_pwm_amount[hotend] = (bias - d) >> 1;
|
|
||||||
#elif ENABLED(PIDTEMP)
|
|
||||||
soft_pwm_amount[hotend] = (bias - d) >> 1;
|
|
||||||
#elif ENABLED(PIDTEMPBED)
|
|
||||||
soft_pwm_amount_bed = (bias - d) >> 1;
|
|
||||||
#endif
|
|
||||||
t1 = ms;
|
t1 = ms;
|
||||||
t_high = t1 - t2;
|
t_high = t1 - t2;
|
||||||
max = target;
|
max = target;
|
||||||
@ -375,15 +359,7 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
|
|||||||
t2 = ms;
|
t2 = ms;
|
||||||
t_low = t2 - t1;
|
t_low = t2 - t1;
|
||||||
if (cycles > 0) {
|
if (cycles > 0) {
|
||||||
long max_pow =
|
const long max_pow = GHV(MAX_BED_POWER, PID_MAX);
|
||||||
#if HAS_PID_FOR_BOTH
|
|
||||||
hotend < 0 ? MAX_BED_POWER : PID_MAX
|
|
||||||
#elif ENABLED(PIDTEMP)
|
|
||||||
PID_MAX
|
|
||||||
#else
|
|
||||||
MAX_BED_POWER
|
|
||||||
#endif
|
|
||||||
;
|
|
||||||
bias += (d * (t_high - t_low)) / (t_low + t_high);
|
bias += (d * (t_high - t_low)) / (t_low + t_high);
|
||||||
bias = constrain(bias, 20, max_pow - 20);
|
bias = constrain(bias, 20, max_pow - 20);
|
||||||
d = (bias > max_pow >> 1) ? max_pow - 1 - bias : bias;
|
d = (bias > max_pow >> 1) ? max_pow - 1 - bias : bias;
|
||||||
@ -422,16 +398,7 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
|
|||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#if HAS_PID_FOR_BOTH
|
SHV(soft_pwm_amount, (bias + d) >> 1, (bias + d) >> 1);
|
||||||
if (hotend < 0)
|
|
||||||
soft_pwm_amount_bed = (bias + d) >> 1;
|
|
||||||
else
|
|
||||||
soft_pwm_amount[hotend] = (bias + d) >> 1;
|
|
||||||
#elif ENABLED(PIDTEMP)
|
|
||||||
soft_pwm_amount[hotend] = (bias + d) >> 1;
|
|
||||||
#else
|
|
||||||
soft_pwm_amount_bed = (bias + d) >> 1;
|
|
||||||
#endif
|
|
||||||
cycles++;
|
cycles++;
|
||||||
min = target;
|
min = target;
|
||||||
}
|
}
|
||||||
@ -460,10 +427,10 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
|
|||||||
if (
|
if (
|
||||||
#if WATCH_THE_BED && WATCH_HOTENDS
|
#if WATCH_THE_BED && WATCH_HOTENDS
|
||||||
true
|
true
|
||||||
#elif WATCH_THE_BED
|
#elif WATCH_HOTENDS
|
||||||
hotend < 0
|
|
||||||
#else
|
|
||||||
hotend >= 0
|
hotend >= 0
|
||||||
|
#else
|
||||||
|
hotend < 0
|
||||||
#endif
|
#endif
|
||||||
) {
|
) {
|
||||||
if (!heated) { // If not yet reached target...
|
if (!heated) { // If not yet reached target...
|
||||||
@ -494,7 +461,7 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
|
|||||||
SERIAL_PROTOCOLLNPGM(MSG_PID_AUTOTUNE_FINISHED);
|
SERIAL_PROTOCOLLNPGM(MSG_PID_AUTOTUNE_FINISHED);
|
||||||
|
|
||||||
#if HAS_PID_FOR_BOTH
|
#if HAS_PID_FOR_BOTH
|
||||||
const char* estring = hotend < 0 ? "bed" : "";
|
const char* estring = GHV("bed", "");
|
||||||
SERIAL_PROTOCOLPAIR("#define DEFAULT_", estring); SERIAL_PROTOCOLPAIR("Kp ", workKp); SERIAL_EOL();
|
SERIAL_PROTOCOLPAIR("#define DEFAULT_", estring); SERIAL_PROTOCOLPAIR("Kp ", workKp); SERIAL_EOL();
|
||||||
SERIAL_PROTOCOLPAIR("#define DEFAULT_", estring); SERIAL_PROTOCOLPAIR("Ki ", workKi); SERIAL_EOL();
|
SERIAL_PROTOCOLPAIR("#define DEFAULT_", estring); SERIAL_PROTOCOLPAIR("Ki ", workKi); SERIAL_EOL();
|
||||||
SERIAL_PROTOCOLPAIR("#define DEFAULT_", estring); SERIAL_PROTOCOLPAIR("Kd ", workKd); SERIAL_EOL();
|
SERIAL_PROTOCOLPAIR("#define DEFAULT_", estring); SERIAL_PROTOCOLPAIR("Kd ", workKd); SERIAL_EOL();
|
||||||
@ -582,11 +549,13 @@ int Temperature::getHeaterPower(const int heater) {
|
|||||||
|
|
||||||
uint8_t fanDone = 0;
|
uint8_t fanDone = 0;
|
||||||
for (uint8_t f = 0; f < COUNT(fanPin); f++) {
|
for (uint8_t f = 0; f < COUNT(fanPin); f++) {
|
||||||
|
const pin_t pin =
|
||||||
#ifdef ARDUINO
|
#ifdef ARDUINO
|
||||||
pin_t pin = pgm_read_byte(&fanPin[f]);
|
pgm_read_byte(&fanPin[f])
|
||||||
#else
|
#else
|
||||||
pin_t pin = fanPin[f];
|
fanPin[f]
|
||||||
#endif
|
#endif
|
||||||
|
;
|
||||||
const uint8_t bit = pgm_read_byte(&fanBit[f]);
|
const uint8_t bit = pgm_read_byte(&fanBit[f]);
|
||||||
if (pin >= 0 && !TEST(fanDone, bit)) {
|
if (pin >= 0 && !TEST(fanDone, bit)) {
|
||||||
uint8_t newFanSpeed = TEST(fanState, bit) ? EXTRUDER_AUTO_FAN_SPEED : 0;
|
uint8_t newFanSpeed = TEST(fanState, bit) ? EXTRUDER_AUTO_FAN_SPEED : 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user