Merge pull request #11368 from thinkyhead/bf1_pwm_adjustments
[1.1.x] Tweak some SoftPWM code
This commit is contained in:
commit
5061c3a016
@ -125,6 +125,10 @@
|
|||||||
// Please choose the name from boards.h that matches your setup
|
// Please choose the name from boards.h that matches your setup
|
||||||
#ifndef MOTHERBOARD
|
#ifndef MOTHERBOARD
|
||||||
#define MOTHERBOARD BOARD_RAMPS_14_EFB
|
#define MOTHERBOARD BOARD_RAMPS_14_EFB
|
||||||
|
#define PIN_EXP1 65 // A11
|
||||||
|
#define PIN_EXP2 66 // A12
|
||||||
|
#define PIN_EXP3 11 // SERVO0_PIN
|
||||||
|
#define PIN_EXP4 12 // PS_ON_PIN
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Optional custom name for your RepStrap or other custom machine
|
// Optional custom name for your RepStrap or other custom machine
|
||||||
|
@ -260,19 +260,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;
|
||||||
@ -302,16 +312,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
|
||||||
|
|
||||||
@ -324,15 +325,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);
|
||||||
|
|
||||||
@ -346,16 +339,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;
|
||||||
@ -368,15 +352,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;
|
||||||
@ -415,16 +391,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;
|
||||||
}
|
}
|
||||||
@ -453,10 +420,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...
|
||||||
@ -487,7 +454,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();
|
||||||
@ -575,7 +542,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++) {
|
||||||
pin_t pin = pgm_read_byte(&fanPin[f]);
|
const pin_t pin =
|
||||||
|
#ifdef ARDUINO
|
||||||
|
pgm_read_byte(&fanPin[f])
|
||||||
|
#else
|
||||||
|
fanPin[f]
|
||||||
|
#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