Cleanup to software PWM variables

This commit is contained in:
Scott Lahteine 2017-04-20 14:04:26 -05:00
parent 83b6bc8e05
commit a1e04942a2
4 changed files with 82 additions and 90 deletions

View file

@ -11516,7 +11516,7 @@ void prepare_move_to_destination() {
const millis_t ms = millis();
if (ELAPSED(ms, nextMotorCheck)) {
nextMotorCheck = ms + 2500UL; // Not a time critical function, so only check every 2.5s
if (X_ENABLE_READ == X_ENABLE_ON || Y_ENABLE_READ == Y_ENABLE_ON || Z_ENABLE_READ == Z_ENABLE_ON || thermalManager.soft_pwm_bed > 0
if (X_ENABLE_READ == X_ENABLE_ON || Y_ENABLE_READ == Y_ENABLE_ON || Z_ENABLE_READ == Z_ENABLE_ON || thermalManager.soft_pwm_amount_bed > 0
|| E0_ENABLE_READ == E_ENABLE_ON // If any of the drivers are enabled...
#if E_STEPPERS > 1
|| E1_ENABLE_READ == E_ENABLE_ON

View file

@ -491,13 +491,13 @@ void Planner::check_axes_activity() {
#if ENABLED(FAN_SOFT_PWM)
#if HAS_FAN0
thermalManager.fanSpeedSoftPwm[0] = CALC_FAN_SPEED(0);
thermalManager.soft_pwm_amount_fan[0] = CALC_FAN_SPEED(0);
#endif
#if HAS_FAN1
thermalManager.fanSpeedSoftPwm[1] = CALC_FAN_SPEED(1);
thermalManager.soft_pwm_amount_fan[1] = CALC_FAN_SPEED(1);
#endif
#if HAS_FAN2
thermalManager.fanSpeedSoftPwm[2] = CALC_FAN_SPEED(2);
thermalManager.soft_pwm_amount_fan[2] = CALC_FAN_SPEED(2);
#endif
#else
#if HAS_FAN0

View file

@ -74,12 +74,6 @@ int16_t Temperature::current_temperature_raw[HOTENDS] = { 0 },
float Temperature::redundant_temperature = 0.0;
#endif
uint8_t Temperature::soft_pwm_bed;
#if ENABLED(FAN_SOFT_PWM)
uint8_t Temperature::fanSpeedSoftPwm[FAN_COUNT];
#endif
#if ENABLED(PIDTEMP)
#if ENABLED(PID_PARAMS_PER_HOTEND) && HOTENDS > 1
float Temperature::Kp[HOTENDS] = ARRAY_BY_HOTENDS1(DEFAULT_Kp),
@ -194,10 +188,12 @@ int16_t Temperature::minttemp_raw[HOTENDS] = ARRAY_BY_HOTENDS(HEATER_0_RAW_LO_TE
millis_t Temperature::next_auto_fan_check_ms = 0;
#endif
uint8_t Temperature::soft_pwm[HOTENDS];
uint8_t Temperature::soft_pwm_amount[HOTENDS],
Temperature::soft_pwm_amount_bed;
#if ENABLED(FAN_SOFT_PWM)
uint8_t Temperature::soft_pwm_fan[FAN_COUNT];
uint8_t Temperature::soft_pwm_amount_fan[FAN_COUNT],
Temperature::soft_pwm_count_fan[FAN_COUNT];
#endif
#if ENABLED(FILAMENT_WIDTH_SENSOR)
@ -206,7 +202,7 @@ uint8_t Temperature::soft_pwm[HOTENDS];
#if ENABLED(PROBING_HEATERS_OFF)
bool Temperature::paused;
int16_t Temperature::paused_hotend_temps[HOTENDS];
int16_t Temperature::paused_hotend_temp[HOTENDS];
#if HAS_TEMP_BED
int16_t Temperature::paused_bed_temp;
#endif
@ -254,13 +250,13 @@ uint8_t Temperature::soft_pwm[HOTENDS];
#if HAS_PID_FOR_BOTH
if (hotend < 0)
soft_pwm_bed = bias = d = (MAX_BED_POWER) >> 1;
soft_pwm_amount_bed = bias = d = (MAX_BED_POWER) >> 1;
else
soft_pwm[hotend] = bias = d = (PID_MAX) >> 1;
soft_pwm_amount[hotend] = bias = d = (PID_MAX) >> 1;
#elif ENABLED(PIDTEMP)
soft_pwm[hotend] = bias = d = (PID_MAX) >> 1;
soft_pwm_amount[hotend] = bias = d = (PID_MAX) >> 1;
#else
soft_pwm_bed = bias = d = (MAX_BED_POWER) >> 1;
soft_pwm_amount_bed = bias = d = (MAX_BED_POWER) >> 1;
#endif
wait_for_heatup = true;
@ -298,13 +294,13 @@ uint8_t Temperature::soft_pwm[HOTENDS];
heating = false;
#if HAS_PID_FOR_BOTH
if (hotend < 0)
soft_pwm_bed = (bias - d) >> 1;
soft_pwm_amount_bed = (bias - d) >> 1;
else
soft_pwm[hotend] = (bias - d) >> 1;
soft_pwm_amount[hotend] = (bias - d) >> 1;
#elif ENABLED(PIDTEMP)
soft_pwm[hotend] = (bias - d) >> 1;
soft_pwm_amount[hotend] = (bias - d) >> 1;
#elif ENABLED(PIDTEMPBED)
soft_pwm_bed = (bias - d) >> 1;
soft_pwm_amount_bed = (bias - d) >> 1;
#endif
t1 = ms;
t_high = t1 - t2;
@ -367,13 +363,13 @@ uint8_t Temperature::soft_pwm[HOTENDS];
}
#if HAS_PID_FOR_BOTH
if (hotend < 0)
soft_pwm_bed = (bias + d) >> 1;
soft_pwm_amount_bed = (bias + d) >> 1;
else
soft_pwm[hotend] = (bias + d) >> 1;
soft_pwm_amount[hotend] = (bias + d) >> 1;
#elif ENABLED(PIDTEMP)
soft_pwm[hotend] = (bias + d) >> 1;
soft_pwm_amount[hotend] = (bias + d) >> 1;
#else
soft_pwm_bed = (bias + d) >> 1;
soft_pwm_amount_bed = (bias + d) >> 1;
#endif
cycles++;
min = temp;
@ -466,7 +462,7 @@ void Temperature::updatePID() {
}
int Temperature::getHeaterPower(int heater) {
return heater < 0 ? soft_pwm_bed : soft_pwm[heater];
return heater < 0 ? soft_pwm_amount_bed : soft_pwm_amount[heater];
}
#if HAS_AUTO_FAN
@ -717,7 +713,7 @@ void Temperature::manage_heater() {
float pid_output = get_pid_output(e);
// Check if temperature is within the correct range
soft_pwm[e] = (current_temperature[e] > minttemp[e] || is_preheating(e)) && current_temperature[e] < maxttemp[e] ? (int)pid_output >> 1 : 0;
soft_pwm_amount[e] = (current_temperature[e] > minttemp[e] || is_preheating(e)) && current_temperature[e] < maxttemp[e] ? (int)pid_output >> 1 : 0;
// Check if the temperature is failing to increase
#if WATCH_HOTENDS
@ -798,27 +794,27 @@ void Temperature::manage_heater() {
#if ENABLED(PIDTEMPBED)
float pid_output = get_pid_output_bed();
soft_pwm_bed = WITHIN(current_temperature_bed, BED_MINTEMP, BED_MAXTEMP) ? (int)pid_output >> 1 : 0;
soft_pwm_amount_bed = WITHIN(current_temperature_bed, BED_MINTEMP, BED_MAXTEMP) ? (int)pid_output >> 1 : 0;
#elif ENABLED(BED_LIMIT_SWITCHING)
// Check if temperature is within the correct band
if (WITHIN(current_temperature_bed, BED_MINTEMP, BED_MAXTEMP)) {
if (current_temperature_bed >= target_temperature_bed + BED_HYSTERESIS)
soft_pwm_bed = 0;
soft_pwm_amount_bed = 0;
else if (current_temperature_bed <= target_temperature_bed - (BED_HYSTERESIS))
soft_pwm_bed = MAX_BED_POWER >> 1;
soft_pwm_amount_bed = MAX_BED_POWER >> 1;
}
else {
soft_pwm_bed = 0;
soft_pwm_amount_bed = 0;
WRITE_HEATER_BED(LOW);
}
#else // !PIDTEMPBED && !BED_LIMIT_SWITCHING
// Check if temperature is within the correct range
if (WITHIN(current_temperature_bed, BED_MINTEMP, BED_MAXTEMP)) {
soft_pwm_bed = current_temperature_bed < target_temperature_bed ? MAX_BED_POWER >> 1 : 0;
soft_pwm_amount_bed = current_temperature_bed < target_temperature_bed ? MAX_BED_POWER >> 1 : 0;
}
else {
soft_pwm_bed = 0;
soft_pwm_amount_bed = 0;
WRITE_HEATER_BED(LOW);
}
#endif
@ -1205,7 +1201,7 @@ void Temperature::init() {
#if ENABLED(PROBING_HEATERS_OFF)
paused = false;
ZERO(paused_hotend_temps);
ZERO(paused_hotend_temp);
#if HAS_TEMP_BED
paused_bed_temp = 0;
#endif
@ -1316,7 +1312,7 @@ void Temperature::disable_all_heaters() {
// Unpause and reset everything
#if ENABLED(PROBING_HEATERS_OFF)
paused = false;
ZERO(paused_hotend_temps);
ZERO(paused_hotend_temp);
#if HAS_TEMP_BED
paused_bed_temp = 0;
#endif
@ -1327,7 +1323,7 @@ void Temperature::disable_all_heaters() {
#define DISABLE_HEATER(NR) { \
setTargetHotend(0, NR); \
soft_pwm[NR] = 0; \
soft_pwm_amount[NR] = 0; \
WRITE_HEATER_ ##NR (LOW); \
}
@ -1349,7 +1345,7 @@ void Temperature::disable_all_heaters() {
#if HAS_TEMP_BED
target_temperature_bed = 0;
soft_pwm_bed = 0;
soft_pwm_amount_bed = 0;
#if HAS_HEATER_BED
WRITE_HEATER_BED(LOW);
#endif
@ -1366,7 +1362,7 @@ void Temperature::disable_all_heaters() {
if (p) {
HOTEND_LOOP() {
paused_hotend_temps[e] = degTargetHotend(e);
paused_hotend_temp[e] = degTargetHotend(e);
setTargetHotend(0, e);
}
#if HAS_TEMP_BED
@ -1375,7 +1371,7 @@ void Temperature::disable_all_heaters() {
#endif
}
else {
HOTEND_LOOP() setTargetHotend(paused_hotend_temps[e], e);
HOTEND_LOOP() setTargetHotend(paused_hotend_temp[e], e);
#if HAS_TEMP_BED
setTargetBed(paused_bed_temp);
#endif
@ -1613,11 +1609,11 @@ void Temperature::isr() {
#if ENABLED(SLOW_PWM_HEATERS)
static uint8_t slow_pwm_count = 0;
#define ISR_STATICS(n) \
static uint8_t soft_pwm_ ## n; \
static uint8_t state_heater_ ## n = 0; \
static uint8_t state_timer_heater_ ## n = 0
static uint8_t soft_pwm_count_ ## n, \
state_heater_ ## n = 0, \
state_timer_heater_ ## n = 0
#else
#define ISR_STATICS(n) static uint8_t soft_pwm_ ## n = 0
#define ISR_STATICS(n) static uint8_t soft_pwm_count_ ## n = 0
#endif
// Statics per heater
@ -1656,73 +1652,73 @@ void Temperature::isr() {
*/
if (pwm_count_tmp >= 127) {
pwm_count_tmp -= 127;
soft_pwm_0 = (soft_pwm_0 & pwm_mask) + soft_pwm[0];
WRITE_HEATER_0(soft_pwm_0 > pwm_mask ? HIGH : LOW);
soft_pwm_count_0 = (soft_pwm_count_0 & pwm_mask) + soft_pwm_amount[0];
WRITE_HEATER_0(soft_pwm_count_0 > pwm_mask ? HIGH : LOW);
#if HOTENDS > 1
soft_pwm_1 = (soft_pwm_1 & pwm_mask) + soft_pwm[1];
WRITE_HEATER_1(soft_pwm_1 > pwm_mask ? HIGH : LOW);
soft_pwm_count_1 = (soft_pwm_count_1 & pwm_mask) + soft_pwm_amount[1];
WRITE_HEATER_1(soft_pwm_count_1 > pwm_mask ? HIGH : LOW);
#if HOTENDS > 2
soft_pwm_2 = (soft_pwm_2 & pwm_mask) + soft_pwm[2];
WRITE_HEATER_2(soft_pwm_2 > pwm_mask ? HIGH : LOW);
soft_pwm_count_2 = (soft_pwm_count_2 & pwm_mask) + soft_pwm_amount[2];
WRITE_HEATER_2(soft_pwm_count_2 > pwm_mask ? HIGH : LOW);
#if HOTENDS > 3
soft_pwm_3 = (soft_pwm_3 & pwm_mask) + soft_pwm[3];
WRITE_HEATER_3(soft_pwm_3 > pwm_mask ? HIGH : LOW);
soft_pwm_count_3 = (soft_pwm_count_3 & pwm_mask) + soft_pwm_amount[3];
WRITE_HEATER_3(soft_pwm_count_3 > pwm_mask ? HIGH : LOW);
#if HOTENDS > 4
soft_pwm_4 = (soft_pwm_4 & pwm_mask) + soft_pwm[4];
WRITE_HEATER_4(soft_pwm_4 > pwm_mask ? HIGH : LOW);
soft_pwm_count_4 = (soft_pwm_count_4 & pwm_mask) + soft_pwm_amount[4];
WRITE_HEATER_4(soft_pwm_count_4 > pwm_mask ? HIGH : LOW);
#endif // HOTENDS > 4
#endif // HOTENDS > 3
#endif // HOTENDS > 2
#endif // HOTENDS > 1
#if HAS_HEATER_BED
soft_pwm_BED = (soft_pwm_BED & pwm_mask) + soft_pwm_bed;
WRITE_HEATER_BED(soft_pwm_BED > pwm_mask ? HIGH : LOW);
soft_pwm_count_BED = (soft_pwm_count_BED & pwm_mask) + soft_pwm_amount_bed;
WRITE_HEATER_BED(soft_pwm_count_BED > pwm_mask ? HIGH : LOW);
#endif
#if ENABLED(FAN_SOFT_PWM)
#if HAS_FAN0
soft_pwm_fan[0] = (soft_pwm_fan[0] & pwm_mask) + fanSpeedSoftPwm[0] >> 1;
WRITE_FAN(soft_pwm_fan[0] > pwm_mask ? HIGH : LOW);
soft_pwm_count_fan[0] = (soft_pwm_count_fan[0] & pwm_mask) + soft_pwm_amount_fan[0] >> 1;
WRITE_FAN(soft_pwm_count_fan[0] > pwm_mask ? HIGH : LOW);
#endif
#if HAS_FAN1
soft_pwm_fan[1] = (soft_pwm_fan[1] & pwm_mask) + fanSpeedSoftPwm[1] >> 1;
WRITE_FAN1(soft_pwm_fan[1] > pwm_mask ? HIGH : LOW);
soft_pwm_count_fan[1] = (soft_pwm_count_fan[1] & pwm_mask) + soft_pwm_amount_fan[1] >> 1;
WRITE_FAN1(soft_pwm_count_fan[1] > pwm_mask ? HIGH : LOW);
#endif
#if HAS_FAN2
soft_pwm_fan[2] = (soft_pwm_fan[2] & pwm_mask) + fanSpeedSoftPwm[2] >> 1;
WRITE_FAN2(soft_pwm_fan[2] > pwm_mask ? HIGH : LOW);
soft_pwm_count_fan[2] = (soft_pwm_count_fan[2] & pwm_mask) + soft_pwm_amount_fan[2] >> 1;
WRITE_FAN2(soft_pwm_count_fan[2] > pwm_mask ? HIGH : LOW);
#endif
#endif
}
else {
if (soft_pwm_0 <= pwm_count_tmp) WRITE_HEATER_0(0);
if (soft_pwm_count_0 <= pwm_count_tmp) WRITE_HEATER_0(0);
#if HOTENDS > 1
if (soft_pwm_1 <= pwm_count_tmp) WRITE_HEATER_1(0);
if (soft_pwm_count_1 <= pwm_count_tmp) WRITE_HEATER_1(0);
#if HOTENDS > 2
if (soft_pwm_2 <= pwm_count_tmp) WRITE_HEATER_2(0);
if (soft_pwm_count_2 <= pwm_count_tmp) WRITE_HEATER_2(0);
#if HOTENDS > 3
if (soft_pwm_3 <= pwm_count_tmp) WRITE_HEATER_3(0);
if (soft_pwm_count_3 <= pwm_count_tmp) WRITE_HEATER_3(0);
#if HOTENDS > 4
if (soft_pwm_4 <= pwm_count_tmp) WRITE_HEATER_4(0);
if (soft_pwm_count_4 <= pwm_count_tmp) WRITE_HEATER_4(0);
#endif // HOTENDS > 4
#endif // HOTENDS > 3
#endif // HOTENDS > 2
#endif // HOTENDS > 1
#if HAS_HEATER_BED
if (soft_pwm_BED <= pwm_count_tmp) WRITE_HEATER_BED(0);
if (soft_pwm_count_BED <= pwm_count_tmp) WRITE_HEATER_BED(0);
#endif
#if ENABLED(FAN_SOFT_PWM)
#if HAS_FAN0
if (soft_pwm_fan[0] <= pwm_count_tmp) WRITE_FAN(0);
if (soft_pwm_count_fan[0] <= pwm_count_tmp) WRITE_FAN(0);
#endif
#if HAS_FAN1
if (soft_pwm_fan[1] <= pwm_count_tmp) WRITE_FAN1(0);
if (soft_pwm_count_fan[1] <= pwm_count_tmp) WRITE_FAN1(0);
#endif
#if HAS_FAN2
if (soft_pwm_fan[2] <= pwm_count_tmp) WRITE_FAN2(0);
if (soft_pwm_count_fan[2] <= pwm_count_tmp) WRITE_FAN2(0);
#endif
#endif
}
@ -1765,7 +1761,7 @@ void Temperature::isr() {
WRITE_HEATER_ ##NR(0); \
} \
}
#define SLOW_PWM_ROUTINE(n) _SLOW_PWM_ROUTINE(n, soft_pwm[n])
#define SLOW_PWM_ROUTINE(n) _SLOW_PWM_ROUTINE(n, soft_pwm_amount[n])
#define PWM_OFF_ROUTINE(NR) \
if (soft_pwm_ ##NR < slow_pwm_count) { \
@ -1792,7 +1788,7 @@ void Temperature::isr() {
#endif // HOTENDS > 2
#endif // HOTENDS > 1
#if HAS_HEATER_BED
_SLOW_PWM_ROUTINE(BED, soft_pwm_bed); // BED
_SLOW_PWM_ROUTINE(BED, soft_pwm_amount_bed); // BED
#endif
} // slow_pwm_count == 0
@ -1818,26 +1814,26 @@ void Temperature::isr() {
if (pwm_count_tmp >= 127) {
pwm_count_tmp = 0;
#if HAS_FAN0
soft_pwm_fan[0] = fanSpeedSoftPwm[0] >> 1;
WRITE_FAN(soft_pwm_fan[0] > 0 ? HIGH : LOW);
soft_pwm_count_fan[0] = soft_pwm_amount_fan[0] >> 1;
WRITE_FAN(soft_pwm_count_fan[0] > 0 ? HIGH : LOW);
#endif
#if HAS_FAN1
soft_pwm_fan[1] = fanSpeedSoftPwm[1] >> 1;
WRITE_FAN1(soft_pwm_fan[1] > 0 ? HIGH : LOW);
soft_pwm_count_fan[1] = soft_pwm_amount_fan[1] >> 1;
WRITE_FAN1(soft_pwm_count_fan[1] > 0 ? HIGH : LOW);
#endif
#if HAS_FAN2
soft_pwm_fan[2] = fanSpeedSoftPwm[2] >> 1;
WRITE_FAN2(soft_pwm_fan[2] > 0 ? HIGH : LOW);
soft_pwm_count_fan[2] = soft_pwm_amount_fan[2] >> 1;
WRITE_FAN2(soft_pwm_count_fan[2] > 0 ? HIGH : LOW);
#endif
}
#if HAS_FAN0
if (soft_pwm_fan[0] <= pwm_count_tmp) WRITE_FAN(0);
if (soft_pwm_count_fan[0] <= pwm_count_tmp) WRITE_FAN(0);
#endif
#if HAS_FAN1
if (soft_pwm_fan[1] <= pwm_count_tmp) WRITE_FAN1(0);
if (soft_pwm_count_fan[1] <= pwm_count_tmp) WRITE_FAN1(0);
#endif
#if HAS_FAN2
if (soft_pwm_fan[2] <= pwm_count_tmp) WRITE_FAN2(0);
if (soft_pwm_count_fan[2] <= pwm_count_tmp) WRITE_FAN2(0);
#endif
#endif // FAN_SOFT_PWM

View file

@ -109,10 +109,12 @@ class Temperature {
static float redundant_temperature;
#endif
static uint8_t soft_pwm_bed;
static uint8_t soft_pwm_amount[HOTENDS],
soft_pwm_amount_bed;
#if ENABLED(FAN_SOFT_PWM)
static uint8_t fanSpeedSoftPwm[FAN_COUNT];
static uint8_t soft_pwm_amount_fan[FAN_COUNT],
soft_pwm_count_fan[FAN_COUNT];
#endif
#if ENABLED(PIDTEMP) || ENABLED(PIDTEMPBED)
@ -249,19 +251,13 @@ class Temperature {
static millis_t next_auto_fan_check_ms;
#endif
static uint8_t soft_pwm[HOTENDS];
#if ENABLED(FAN_SOFT_PWM)
static uint8_t soft_pwm_fan[FAN_COUNT];
#endif
#if ENABLED(FILAMENT_WIDTH_SENSOR)
static int current_raw_filwidth; //Holds measured filament diameter - one extruder only
#endif
#if ENABLED(PROBING_HEATERS_OFF)
static bool paused;
static int16_t paused_hotend_temps[HOTENDS];
static int16_t paused_hotend_temp[HOTENDS];
#if HAS_TEMP_BED
static int16_t paused_bed_temp;