Overridable Options - Part 9 (PR#2561)

Apply `ENABLED` / `DISABLED` macros to temperature-related files.
This commit is contained in:
Scott Lahteine 2015-07-30 22:29:30 -07:00 committed by Richard Wackerbarth
parent c35fb88094
commit 51e89a269c
2 changed files with 77 additions and 77 deletions

View File

@ -34,7 +34,7 @@
#define K2 (1.0-K1) #define K2 (1.0-K1)
#endif #endif
#if defined(PIDTEMPBED) || defined(PIDTEMP) #if ENABLED(PIDTEMPBED) || ENABLED(PIDTEMP)
#define PID_dT ((OVERSAMPLENR * 12.0)/(F_CPU / 64.0 / 256.0)) #define PID_dT ((OVERSAMPLENR * 12.0)/(F_CPU / 64.0 / 256.0))
#endif #endif
@ -48,39 +48,39 @@ int current_temperature_raw[4] = { 0 };
float current_temperature[4] = { 0.0 }; float current_temperature[4] = { 0.0 };
int current_temperature_bed_raw = 0; int current_temperature_bed_raw = 0;
float current_temperature_bed = 0.0; float current_temperature_bed = 0.0;
#ifdef TEMP_SENSOR_1_AS_REDUNDANT #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
int redundant_temperature_raw = 0; int redundant_temperature_raw = 0;
float redundant_temperature = 0.0; float redundant_temperature = 0.0;
#endif #endif
#ifdef PIDTEMPBED #if ENABLED(PIDTEMPBED)
float bedKp=DEFAULT_bedKp; float bedKp=DEFAULT_bedKp;
float bedKi=(DEFAULT_bedKi*PID_dT); float bedKi=(DEFAULT_bedKi*PID_dT);
float bedKd=(DEFAULT_bedKd/PID_dT); float bedKd=(DEFAULT_bedKd/PID_dT);
#endif //PIDTEMPBED #endif //PIDTEMPBED
#ifdef FAN_SOFT_PWM #if ENABLED(FAN_SOFT_PWM)
unsigned char fanSpeedSoftPwm; unsigned char fanSpeedSoftPwm;
#endif #endif
unsigned char soft_pwm_bed; unsigned char soft_pwm_bed;
#ifdef BABYSTEPPING #if ENABLED(BABYSTEPPING)
volatile int babystepsTodo[3] = { 0 }; volatile int babystepsTodo[3] = { 0 };
#endif #endif
#ifdef FILAMENT_SENSOR #if ENABLED(FILAMENT_SENSOR)
int current_raw_filwidth = 0; //Holds measured filament diameter - one extruder only int current_raw_filwidth = 0; //Holds measured filament diameter - one extruder only
#endif #endif
#if defined(THERMAL_PROTECTION_HOTENDS) || defined(THERMAL_PROTECTION_BED) #if ENABLED(THERMAL_PROTECTION_HOTENDS) || ENABLED(THERMAL_PROTECTION_BED)
enum TRState { TRReset, TRInactive, TRFirstHeating, TRStable, TRRunaway }; enum TRState { TRReset, TRInactive, TRFirstHeating, TRStable, TRRunaway };
void thermal_runaway_protection(TRState *state, millis_t *timer, float temperature, float target_temperature, int heater_id, int period_seconds, int hysteresis_degc); void thermal_runaway_protection(TRState *state, millis_t *timer, float temperature, float target_temperature, int heater_id, int period_seconds, int hysteresis_degc);
#ifdef THERMAL_PROTECTION_HOTENDS #if ENABLED(THERMAL_PROTECTION_HOTENDS)
static TRState thermal_runaway_state_machine[4] = { TRReset, TRReset, TRReset, TRReset }; static TRState thermal_runaway_state_machine[4] = { TRReset, TRReset, TRReset, TRReset };
static millis_t thermal_runaway_timer[4]; // = {0,0,0,0}; static millis_t thermal_runaway_timer[4]; // = {0,0,0,0};
#endif #endif
#if defined(THERMAL_PROTECTION_BED) && TEMP_SENSOR_BED != 0 #if ENABLED(THERMAL_PROTECTION_BED) && TEMP_SENSOR_BED != 0
static TRState thermal_runaway_bed_state_machine = TRReset; static TRState thermal_runaway_bed_state_machine = TRReset;
static millis_t thermal_runaway_bed_timer; static millis_t thermal_runaway_bed_timer;
#endif #endif
@ -92,7 +92,7 @@ unsigned char soft_pwm_bed;
static volatile bool temp_meas_ready = false; static volatile bool temp_meas_ready = false;
#ifdef PIDTEMP #if ENABLED(PIDTEMP)
//static cannot be external: //static cannot be external:
static float temp_iState[EXTRUDERS] = { 0 }; static float temp_iState[EXTRUDERS] = { 0 };
static float temp_dState[EXTRUDERS] = { 0 }; static float temp_dState[EXTRUDERS] = { 0 };
@ -105,7 +105,7 @@ static volatile bool temp_meas_ready = false;
static float temp_iState_max[EXTRUDERS]; static float temp_iState_max[EXTRUDERS];
static bool pid_reset[EXTRUDERS]; static bool pid_reset[EXTRUDERS];
#endif //PIDTEMP #endif //PIDTEMP
#ifdef PIDTEMPBED #if ENABLED(PIDTEMPBED)
//static cannot be external: //static cannot be external:
static float temp_iState_bed = { 0 }; static float temp_iState_bed = { 0 };
static float temp_dState_bed = { 0 }; static float temp_dState_bed = { 0 };
@ -121,26 +121,26 @@ static volatile bool temp_meas_ready = false;
#endif //PIDTEMPBED #endif //PIDTEMPBED
static unsigned char soft_pwm[EXTRUDERS]; static unsigned char soft_pwm[EXTRUDERS];
#ifdef FAN_SOFT_PWM #if ENABLED(FAN_SOFT_PWM)
static unsigned char soft_pwm_fan; static unsigned char soft_pwm_fan;
#endif #endif
#if HAS_AUTO_FAN #if HAS_AUTO_FAN
static millis_t next_auto_fan_check_ms; static millis_t next_auto_fan_check_ms;
#endif #endif
#ifdef PIDTEMP #if ENABLED(PIDTEMP)
#ifdef PID_PARAMS_PER_EXTRUDER #if ENABLED(PID_PARAMS_PER_EXTRUDER)
float Kp[EXTRUDERS] = ARRAY_BY_EXTRUDERS1(DEFAULT_Kp); float Kp[EXTRUDERS] = ARRAY_BY_EXTRUDERS1(DEFAULT_Kp);
float Ki[EXTRUDERS] = ARRAY_BY_EXTRUDERS1(DEFAULT_Ki*PID_dT); float Ki[EXTRUDERS] = ARRAY_BY_EXTRUDERS1(DEFAULT_Ki*PID_dT);
float Kd[EXTRUDERS] = ARRAY_BY_EXTRUDERS1(DEFAULT_Kd / PID_dT); float Kd[EXTRUDERS] = ARRAY_BY_EXTRUDERS1(DEFAULT_Kd / PID_dT);
#ifdef PID_ADD_EXTRUSION_RATE #if ENABLED(PID_ADD_EXTRUSION_RATE)
float Kc[EXTRUDERS] = ARRAY_BY_EXTRUDERS1(DEFAULT_Kc); float Kc[EXTRUDERS] = ARRAY_BY_EXTRUDERS1(DEFAULT_Kc);
#endif // PID_ADD_EXTRUSION_RATE #endif // PID_ADD_EXTRUSION_RATE
#else //PID_PARAMS_PER_EXTRUDER #else //PID_PARAMS_PER_EXTRUDER
float Kp = DEFAULT_Kp; float Kp = DEFAULT_Kp;
float Ki = DEFAULT_Ki * PID_dT; float Ki = DEFAULT_Ki * PID_dT;
float Kd = DEFAULT_Kd / PID_dT; float Kd = DEFAULT_Kd / PID_dT;
#ifdef PID_ADD_EXTRUSION_RATE #if ENABLED(PID_ADD_EXTRUSION_RATE)
float Kc = DEFAULT_Kc; float Kc = DEFAULT_Kc;
#endif // PID_ADD_EXTRUSION_RATE #endif // PID_ADD_EXTRUSION_RATE
#endif // PID_PARAMS_PER_EXTRUDER #endif // PID_PARAMS_PER_EXTRUDER
@ -158,7 +158,7 @@ static int bed_minttemp_raw = HEATER_BED_RAW_LO_TEMP;
static int bed_maxttemp_raw = HEATER_BED_RAW_HI_TEMP; static int bed_maxttemp_raw = HEATER_BED_RAW_HI_TEMP;
#endif #endif
#ifdef TEMP_SENSOR_1_AS_REDUNDANT #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
static void *heater_ttbl_map[2] = {(void *)HEATER_0_TEMPTABLE, (void *)HEATER_1_TEMPTABLE }; static void *heater_ttbl_map[2] = {(void *)HEATER_0_TEMPTABLE, (void *)HEATER_1_TEMPTABLE };
static uint8_t heater_ttbllen_map[2] = { HEATER_0_TEMPTABLE_LEN, HEATER_1_TEMPTABLE_LEN }; static uint8_t heater_ttbllen_map[2] = { HEATER_0_TEMPTABLE_LEN, HEATER_1_TEMPTABLE_LEN };
#else #else
@ -170,7 +170,7 @@ static float analog2temp(int raw, uint8_t e);
static float analog2tempBed(int raw); static float analog2tempBed(int raw);
static void updateTemperaturesFromRawValues(); static void updateTemperaturesFromRawValues();
#ifdef THERMAL_PROTECTION_HOTENDS #if ENABLED(THERMAL_PROTECTION_HOTENDS)
int watch_target_temp[EXTRUDERS] = { 0 }; int watch_target_temp[EXTRUDERS] = { 0 };
millis_t watch_heater_next_ms[EXTRUDERS] = { 0 }; millis_t watch_heater_next_ms[EXTRUDERS] = { 0 };
#endif #endif
@ -179,11 +179,11 @@ static void updateTemperaturesFromRawValues();
#define SOFT_PWM_SCALE 0 #define SOFT_PWM_SCALE 0
#endif #endif
#ifdef FILAMENT_SENSOR #if ENABLED(FILAMENT_SENSOR)
static int meas_shift_index; //used to point to a delayed sample in buffer for filament width sensor static int meas_shift_index; //used to point to a delayed sample in buffer for filament width sensor
#endif #endif
#ifdef HEATER_0_USES_MAX6675 #if ENABLED(HEATER_0_USES_MAX6675)
static int read_max6675(); static int read_max6675();
#endif #endif
@ -354,12 +354,12 @@ void PID_autotune(float temp, int extruder, int ncycles) {
} }
void updatePID() { void updatePID() {
#ifdef PIDTEMP #if ENABLED(PIDTEMP)
for (int e = 0; e < EXTRUDERS; e++) { for (int e = 0; e < EXTRUDERS; e++) {
temp_iState_max[e] = PID_INTEGRAL_DRIVE_MAX / PID_PARAM(Ki,e); temp_iState_max[e] = PID_INTEGRAL_DRIVE_MAX / PID_PARAM(Ki,e);
} }
#endif #endif
#ifdef PIDTEMPBED #if ENABLED(PIDTEMPBED)
temp_iState_max_bed = PID_BED_INTEGRAL_DRIVE_MAX / bedKi; temp_iState_max_bed = PID_BED_INTEGRAL_DRIVE_MAX / bedKi;
#endif #endif
} }
@ -453,7 +453,7 @@ inline void _temp_error(int e, const char *serial_msg, const char *lcd_msg) {
SERIAL_ERRORPGM(MSG_STOPPED_HEATER); SERIAL_ERRORPGM(MSG_STOPPED_HEATER);
if (e >= 0) SERIAL_ERRORLN((int)e); else SERIAL_ERRORLNPGM(MSG_HEATER_BED); if (e >= 0) SERIAL_ERRORLN((int)e); else SERIAL_ERRORLNPGM(MSG_HEATER_BED);
} }
#ifndef BOGUS_TEMPERATURE_FAILSAFE_OVERRIDE #if DISABLED(BOGUS_TEMPERATURE_FAILSAFE_OVERRIDE)
if (!killed) { if (!killed) {
Running = false; Running = false;
killed = true; killed = true;
@ -473,8 +473,8 @@ void min_temp_error(uint8_t e) {
float get_pid_output(int e) { float get_pid_output(int e) {
float pid_output; float pid_output;
#ifdef PIDTEMP #if ENABLED(PIDTEMP)
#ifndef PID_OPENLOOP #if DISABLED(PID_OPENLOOP)
pid_error[e] = target_temperature[e] - current_temperature[e]; pid_error[e] = target_temperature[e] - current_temperature[e];
dTerm[e] = K2 * PID_PARAM(Kd,e) * (current_temperature[e] - temp_dState[e]) + K1 * dTerm[e]; dTerm[e] = K2 * PID_PARAM(Kd,e) * (current_temperature[e] - temp_dState[e]) + K1 * dTerm[e];
temp_dState[e] = current_temperature[e]; temp_dState[e] = current_temperature[e];
@ -510,7 +510,7 @@ float get_pid_output(int e) {
pid_output = constrain(target_temperature[e], 0, PID_MAX); pid_output = constrain(target_temperature[e], 0, PID_MAX);
#endif //PID_OPENLOOP #endif //PID_OPENLOOP
#ifdef PID_DEBUG #if ENABLED(PID_DEBUG)
SERIAL_ECHO_START; SERIAL_ECHO_START;
SERIAL_ECHO(MSG_PID_DEBUG); SERIAL_ECHO(MSG_PID_DEBUG);
SERIAL_ECHO(e); SERIAL_ECHO(e);
@ -533,10 +533,10 @@ float get_pid_output(int e) {
return pid_output; return pid_output;
} }
#ifdef PIDTEMPBED #if ENABLED(PIDTEMPBED)
float get_pid_output_bed() { float get_pid_output_bed() {
float pid_output; float pid_output;
#ifndef PID_OPENLOOP #if DISABLED(PID_OPENLOOP)
pid_error_bed = target_temperature_bed - current_temperature_bed; pid_error_bed = target_temperature_bed - current_temperature_bed;
pTerm_bed = bedKp * pid_error_bed; pTerm_bed = bedKp * pid_error_bed;
temp_iState_bed += pid_error_bed; temp_iState_bed += pid_error_bed;
@ -559,7 +559,7 @@ float get_pid_output(int e) {
pid_output = constrain(target_temperature_bed, 0, MAX_BED_POWER); pid_output = constrain(target_temperature_bed, 0, MAX_BED_POWER);
#endif // PID_OPENLOOP #endif // PID_OPENLOOP
#ifdef PID_BED_DEBUG #if ENABLED(PID_BED_DEBUG)
SERIAL_ECHO_START; SERIAL_ECHO_START;
SERIAL_ECHO(" PID_BED_DEBUG "); SERIAL_ECHO(" PID_BED_DEBUG ");
SERIAL_ECHO(": Input "); SERIAL_ECHO(": Input ");
@ -592,20 +592,20 @@ void manage_heater() {
updateTemperaturesFromRawValues(); updateTemperaturesFromRawValues();
#ifdef HEATER_0_USES_MAX6675 #if ENABLED(HEATER_0_USES_MAX6675)
float ct = current_temperature[0]; float ct = current_temperature[0];
if (ct > min(HEATER_0_MAXTEMP, 1023)) max_temp_error(0); if (ct > min(HEATER_0_MAXTEMP, 1023)) max_temp_error(0);
if (ct < max(HEATER_0_MINTEMP, 0.01)) min_temp_error(0); if (ct < max(HEATER_0_MINTEMP, 0.01)) min_temp_error(0);
#endif #endif
#if defined(THERMAL_PROTECTION_HOTENDS) || !defined(PIDTEMPBED) || HAS_AUTO_FAN #if ENABLED(THERMAL_PROTECTION_HOTENDS) || DISABLED(PIDTEMPBED) || HAS_AUTO_FAN
millis_t ms = millis(); millis_t ms = millis();
#endif #endif
// Loop through all extruders // Loop through all extruders
for (int e = 0; e < EXTRUDERS; e++) { for (int e = 0; e < EXTRUDERS; e++) {
#ifdef THERMAL_PROTECTION_HOTENDS #if ENABLED(THERMAL_PROTECTION_HOTENDS)
thermal_runaway_protection(&thermal_runaway_state_machine[e], &thermal_runaway_timer[e], current_temperature[e], target_temperature[e], e, THERMAL_PROTECTION_PERIOD, THERMAL_PROTECTION_HYSTERESIS); thermal_runaway_protection(&thermal_runaway_state_machine[e], &thermal_runaway_timer[e], current_temperature[e], target_temperature[e], e, THERMAL_PROTECTION_PERIOD, THERMAL_PROTECTION_HYSTERESIS);
#endif #endif
@ -615,7 +615,7 @@ void manage_heater() {
soft_pwm[e] = current_temperature[e] > minttemp[e] && current_temperature[e] < maxttemp[e] ? (int)pid_output >> 1 : 0; soft_pwm[e] = current_temperature[e] > minttemp[e] && current_temperature[e] < maxttemp[e] ? (int)pid_output >> 1 : 0;
// Check if the temperature is failing to increase // Check if the temperature is failing to increase
#ifdef THERMAL_PROTECTION_HOTENDS #if ENABLED(THERMAL_PROTECTION_HOTENDS)
// Is it time to check this extruder's heater? // Is it time to check this extruder's heater?
if (watch_heater_next_ms[e] && ms > watch_heater_next_ms[e]) { if (watch_heater_next_ms[e] && ms > watch_heater_next_ms[e]) {
@ -632,7 +632,7 @@ void manage_heater() {
#endif // THERMAL_PROTECTION_HOTENDS #endif // THERMAL_PROTECTION_HOTENDS
#ifdef TEMP_SENSOR_1_AS_REDUNDANT #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
if (fabs(current_temperature[0] - redundant_temperature) > MAX_REDUNDANT_TEMP_SENSOR_DIFF) { if (fabs(current_temperature[0] - redundant_temperature) > MAX_REDUNDANT_TEMP_SENSOR_DIFF) {
_temp_error(0, PSTR(MSG_EXTRUDER_SWITCHED_OFF), PSTR(MSG_ERR_REDUNDANT_TEMP)); _temp_error(0, PSTR(MSG_EXTRUDER_SWITCHED_OFF), PSTR(MSG_ERR_REDUNDANT_TEMP));
} }
@ -648,7 +648,7 @@ void manage_heater() {
#endif #endif
// Control the extruder rate based on the width sensor // Control the extruder rate based on the width sensor
#ifdef FILAMENT_SENSOR #if ENABLED(FILAMENT_SENSOR)
if (filament_sensor) { if (filament_sensor) {
meas_shift_index = delay_index1 - meas_delay_cm; meas_shift_index = delay_index1 - meas_delay_cm;
if (meas_shift_index < 0) meas_shift_index += MAX_MEASUREMENT_DELAY + 1; //loop around buffer if needed if (meas_shift_index < 0) meas_shift_index += MAX_MEASUREMENT_DELAY + 1; //loop around buffer if needed
@ -662,23 +662,23 @@ void manage_heater() {
} }
#endif //FILAMENT_SENSOR #endif //FILAMENT_SENSOR
#ifndef PIDTEMPBED #if DISABLED(PIDTEMPBED)
if (ms < next_bed_check_ms) return; if (ms < next_bed_check_ms) return;
next_bed_check_ms = ms + BED_CHECK_INTERVAL; next_bed_check_ms = ms + BED_CHECK_INTERVAL;
#endif #endif
#if TEMP_SENSOR_BED != 0 #if TEMP_SENSOR_BED != 0
#ifdef THERMAL_PROTECTION_BED #if ENABLED(THERMAL_PROTECTION_BED)
thermal_runaway_protection(&thermal_runaway_bed_state_machine, &thermal_runaway_bed_timer, current_temperature_bed, target_temperature_bed, -1, THERMAL_PROTECTION_BED_PERIOD, THERMAL_PROTECTION_BED_HYSTERESIS); thermal_runaway_protection(&thermal_runaway_bed_state_machine, &thermal_runaway_bed_timer, current_temperature_bed, target_temperature_bed, -1, THERMAL_PROTECTION_BED_PERIOD, THERMAL_PROTECTION_BED_HYSTERESIS);
#endif #endif
#ifdef PIDTEMPBED #if ENABLED(PIDTEMPBED)
float pid_output = get_pid_output_bed(); float pid_output = get_pid_output_bed();
soft_pwm_bed = current_temperature_bed > BED_MINTEMP && current_temperature_bed < BED_MAXTEMP ? (int)pid_output >> 1 : 0; soft_pwm_bed = current_temperature_bed > BED_MINTEMP && current_temperature_bed < BED_MAXTEMP ? (int)pid_output >> 1 : 0;
#elif defined(BED_LIMIT_SWITCHING) #elif ENABLED(BED_LIMIT_SWITCHING)
// Check if temperature is within the correct band // Check if temperature is within the correct band
if (current_temperature_bed > BED_MINTEMP && current_temperature_bed < BED_MAXTEMP) { if (current_temperature_bed > BED_MINTEMP && current_temperature_bed < BED_MAXTEMP) {
if (current_temperature_bed >= target_temperature_bed + BED_HYSTERESIS) if (current_temperature_bed >= target_temperature_bed + BED_HYSTERESIS)
@ -707,7 +707,7 @@ void manage_heater() {
// Derived from RepRap FiveD extruder::getTemperature() // Derived from RepRap FiveD extruder::getTemperature()
// For hot end temperature measurement. // For hot end temperature measurement.
static float analog2temp(int raw, uint8_t e) { static float analog2temp(int raw, uint8_t e) {
#ifdef TEMP_SENSOR_1_AS_REDUNDANT #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
if (e > EXTRUDERS) if (e > EXTRUDERS)
#else #else
if (e >= EXTRUDERS) if (e >= EXTRUDERS)
@ -720,7 +720,7 @@ static float analog2temp(int raw, uint8_t e) {
return 0.0; return 0.0;
} }
#ifdef HEATER_0_USES_MAX6675 #if ENABLED(HEATER_0_USES_MAX6675)
if (e == 0) return 0.25 * raw; if (e == 0) return 0.25 * raw;
#endif #endif
@ -750,7 +750,7 @@ static float analog2temp(int raw, uint8_t e) {
// Derived from RepRap FiveD extruder::getTemperature() // Derived from RepRap FiveD extruder::getTemperature()
// For bed temperature measurement. // For bed temperature measurement.
static float analog2tempBed(int raw) { static float analog2tempBed(int raw) {
#ifdef BED_USES_THERMISTOR #if ENABLED(BED_USES_THERMISTOR)
float celsius = 0; float celsius = 0;
byte i; byte i;
@ -778,14 +778,14 @@ static float analog2tempBed(int raw) {
/* Called to get the raw values into the the actual temperatures. The raw values are created in interrupt context, /* Called to get the raw values into the the actual temperatures. The raw values are created in interrupt context,
and this function is called from normal context as it is too slow to run in interrupts and will block the stepper routine otherwise */ and this function is called from normal context as it is too slow to run in interrupts and will block the stepper routine otherwise */
static void updateTemperaturesFromRawValues() { static void updateTemperaturesFromRawValues() {
#ifdef HEATER_0_USES_MAX6675 #if ENABLED(HEATER_0_USES_MAX6675)
current_temperature_raw[0] = read_max6675(); current_temperature_raw[0] = read_max6675();
#endif #endif
for (uint8_t e = 0; e < EXTRUDERS; e++) { for (uint8_t e = 0; e < EXTRUDERS; e++) {
current_temperature[e] = analog2temp(current_temperature_raw[e], e); current_temperature[e] = analog2temp(current_temperature_raw[e], e);
} }
current_temperature_bed = analog2tempBed(current_temperature_bed_raw); current_temperature_bed = analog2tempBed(current_temperature_bed_raw);
#ifdef TEMP_SENSOR_1_AS_REDUNDANT #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
redundant_temperature = analog2temp(redundant_temperature_raw, 1); redundant_temperature = analog2temp(redundant_temperature_raw, 1);
#endif #endif
#if HAS_FILAMENT_SENSOR #if HAS_FILAMENT_SENSOR
@ -800,7 +800,7 @@ static void updateTemperaturesFromRawValues() {
} }
#ifdef FILAMENT_SENSOR #if ENABLED(FILAMENT_SENSOR)
// Convert raw Filament Width to millimeters // Convert raw Filament Width to millimeters
float analog2widthFil() { float analog2widthFil() {
@ -834,11 +834,11 @@ void tp_init() {
for (int e = 0; e < EXTRUDERS; e++) { for (int e = 0; e < EXTRUDERS; e++) {
// populate with the first value // populate with the first value
maxttemp[e] = maxttemp[0]; maxttemp[e] = maxttemp[0];
#ifdef PIDTEMP #if ENABLED(PIDTEMP)
temp_iState_min[e] = 0.0; temp_iState_min[e] = 0.0;
temp_iState_max[e] = PID_INTEGRAL_DRIVE_MAX / PID_PARAM(Ki,e); temp_iState_max[e] = PID_INTEGRAL_DRIVE_MAX / PID_PARAM(Ki,e);
#endif //PIDTEMP #endif //PIDTEMP
#ifdef PIDTEMPBED #if ENABLED(PIDTEMPBED)
temp_iState_min_bed = 0.0; temp_iState_min_bed = 0.0;
temp_iState_max_bed = PID_BED_INTEGRAL_DRIVE_MAX / bedKi; temp_iState_max_bed = PID_BED_INTEGRAL_DRIVE_MAX / bedKi;
#endif //PIDTEMPBED #endif //PIDTEMPBED
@ -861,17 +861,17 @@ void tp_init() {
#endif #endif
#if HAS_FAN #if HAS_FAN
SET_OUTPUT(FAN_PIN); SET_OUTPUT(FAN_PIN);
#ifdef FAST_PWM_FAN #if ENABLED(FAST_PWM_FAN)
setPwmFrequency(FAN_PIN, 1); // No prescaling. Pwm frequency = F_CPU/256/8 setPwmFrequency(FAN_PIN, 1); // No prescaling. Pwm frequency = F_CPU/256/8
#endif #endif
#ifdef FAN_SOFT_PWM #if ENABLED(FAN_SOFT_PWM)
soft_pwm_fan = fanSpeedSoftPwm / 2; soft_pwm_fan = fanSpeedSoftPwm / 2;
#endif #endif
#endif #endif
#ifdef HEATER_0_USES_MAX6675 #if ENABLED(HEATER_0_USES_MAX6675)
#ifndef SDSUPPORT #if DISABLED(SDSUPPORT)
OUT_WRITE(SCK_PIN, LOW); OUT_WRITE(SCK_PIN, LOW);
OUT_WRITE(MOSI_PIN, HIGH); OUT_WRITE(MOSI_PIN, HIGH);
OUT_WRITE(MISO_PIN, HIGH); OUT_WRITE(MISO_PIN, HIGH);
@ -1004,7 +1004,7 @@ void tp_init() {
#endif //BED_MAXTEMP #endif //BED_MAXTEMP
} }
#ifdef THERMAL_PROTECTION_HOTENDS #if ENABLED(THERMAL_PROTECTION_HOTENDS)
/** /**
* Start Heating Sanity Check for hotends that are below * Start Heating Sanity Check for hotends that are below
* their target temperature by a configurable margin. * their target temperature by a configurable margin.
@ -1020,7 +1020,7 @@ void tp_init() {
} }
#endif #endif
#if defined(THERMAL_PROTECTION_HOTENDS) || defined(THERMAL_PROTECTION_BED) #if ENABLED(THERMAL_PROTECTION_HOTENDS) || ENABLED(THERMAL_PROTECTION_BED)
void thermal_runaway_protection(TRState *state, millis_t *timer, float temperature, float target_temperature, int heater_id, int period_seconds, int hysteresis_degc) { void thermal_runaway_protection(TRState *state, millis_t *timer, float temperature, float target_temperature, int heater_id, int period_seconds, int hysteresis_degc) {
@ -1115,7 +1115,7 @@ void disable_all_heaters() {
#endif #endif
} }
#ifdef HEATER_0_USES_MAX6675 #if ENABLED(HEATER_0_USES_MAX6675)
#define MAX6675_HEAT_INTERVAL 250u #define MAX6675_HEAT_INTERVAL 250u
static millis_t next_max6675_ms = 0; static millis_t next_max6675_ms = 0;
int max6675_temp = 2000; int max6675_temp = 2000;
@ -1196,11 +1196,11 @@ static unsigned long raw_temp_value[4] = { 0 };
static unsigned long raw_temp_bed_value = 0; static unsigned long raw_temp_bed_value = 0;
static void set_current_temp_raw() { static void set_current_temp_raw() {
#if HAS_TEMP_0 && !defined(HEATER_0_USES_MAX6675) #if HAS_TEMP_0 && DISABLED(HEATER_0_USES_MAX6675)
current_temperature_raw[0] = raw_temp_value[0]; current_temperature_raw[0] = raw_temp_value[0];
#endif #endif
#if HAS_TEMP_1 #if HAS_TEMP_1
#ifdef TEMP_SENSOR_1_AS_REDUNDANT #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
redundant_temperature_raw = raw_temp_value[1]; redundant_temperature_raw = raw_temp_value[1];
#else #else
current_temperature_raw[1] = raw_temp_value[1]; current_temperature_raw[1] = raw_temp_value[1];
@ -1230,7 +1230,7 @@ ISR(TIMER0_COMPB_vect) {
static unsigned char pwm_count = BIT(SOFT_PWM_SCALE); static unsigned char pwm_count = BIT(SOFT_PWM_SCALE);
// Static members for each heater // Static members for each heater
#ifdef SLOW_PWM_HEATERS #if ENABLED(SLOW_PWM_HEATERS)
static unsigned char slow_pwm_count = 0; static unsigned char slow_pwm_count = 0;
#define ISR_STATICS(n) \ #define ISR_STATICS(n) \
static unsigned char soft_pwm_ ## n; \ static unsigned char soft_pwm_ ## n; \
@ -1242,7 +1242,7 @@ ISR(TIMER0_COMPB_vect) {
// Statics per heater // Statics per heater
ISR_STATICS(0); ISR_STATICS(0);
#if (EXTRUDERS > 1) || defined(HEATERS_PARALLEL) #if (EXTRUDERS > 1) || ENABLED(HEATERS_PARALLEL)
ISR_STATICS(1); ISR_STATICS(1);
#if EXTRUDERS > 2 #if EXTRUDERS > 2
ISR_STATICS(2); ISR_STATICS(2);
@ -1259,7 +1259,7 @@ ISR(TIMER0_COMPB_vect) {
static unsigned long raw_filwidth_value = 0; static unsigned long raw_filwidth_value = 0;
#endif #endif
#ifndef SLOW_PWM_HEATERS #if DISABLED(SLOW_PWM_HEATERS)
/** /**
* standard PWM modulation * standard PWM modulation
*/ */
@ -1287,7 +1287,7 @@ ISR(TIMER0_COMPB_vect) {
soft_pwm_BED = soft_pwm_bed; soft_pwm_BED = soft_pwm_bed;
WRITE_HEATER_BED(soft_pwm_BED > 0 ? 1 : 0); WRITE_HEATER_BED(soft_pwm_BED > 0 ? 1 : 0);
#endif #endif
#ifdef FAN_SOFT_PWM #if ENABLED(FAN_SOFT_PWM)
soft_pwm_fan = fanSpeedSoftPwm / 2; soft_pwm_fan = fanSpeedSoftPwm / 2;
WRITE_FAN(soft_pwm_fan > 0 ? 1 : 0); WRITE_FAN(soft_pwm_fan > 0 ? 1 : 0);
#endif #endif
@ -1308,7 +1308,7 @@ ISR(TIMER0_COMPB_vect) {
if (soft_pwm_BED < pwm_count) WRITE_HEATER_BED(0); if (soft_pwm_BED < pwm_count) WRITE_HEATER_BED(0);
#endif #endif
#ifdef FAN_SOFT_PWM #if ENABLED(FAN_SOFT_PWM)
if (soft_pwm_fan < pwm_count) WRITE_FAN(0); if (soft_pwm_fan < pwm_count) WRITE_FAN(0);
#endif #endif
@ -1385,7 +1385,7 @@ ISR(TIMER0_COMPB_vect) {
PWM_OFF_ROUTINE(BED); // BED PWM_OFF_ROUTINE(BED); // BED
#endif #endif
#ifdef FAN_SOFT_PWM #if ENABLED(FAN_SOFT_PWM)
if (pwm_count == 0) { if (pwm_count == 0) {
soft_pwm_fan = fanSpeedSoftPwm / 2; soft_pwm_fan = fanSpeedSoftPwm / 2;
WRITE_FAN(soft_pwm_fan > 0 ? 1 : 0); WRITE_FAN(soft_pwm_fan > 0 ? 1 : 0);
@ -1540,7 +1540,7 @@ ISR(TIMER0_COMPB_vect) {
for (int i = 0; i < 4; i++) raw_temp_value[i] = 0; for (int i = 0; i < 4; i++) raw_temp_value[i] = 0;
raw_temp_bed_value = 0; raw_temp_bed_value = 0;
#if HAS_TEMP_0 && !defined(HEATER_0_USES_MAX6675) #if HAS_TEMP_0 && DISABLED(HEATER_0_USES_MAX6675)
#if HEATER_0_RAW_LO_TEMP > HEATER_0_RAW_HI_TEMP #if HEATER_0_RAW_LO_TEMP > HEATER_0_RAW_HI_TEMP
#define GE0 <= #define GE0 <=
#else #else
@ -1592,7 +1592,7 @@ ISR(TIMER0_COMPB_vect) {
} // temp_count >= OVERSAMPLENR } // temp_count >= OVERSAMPLENR
#ifdef BABYSTEPPING #if ENABLED(BABYSTEPPING)
for (uint8_t axis = X_AXIS; axis <= Z_AXIS; axis++) { for (uint8_t axis = X_AXIS; axis <= Z_AXIS; axis++) {
int curTodo = babystepsTodo[axis]; //get rid of volatile for performance int curTodo = babystepsTodo[axis]; //get rid of volatile for performance
@ -1608,7 +1608,7 @@ ISR(TIMER0_COMPB_vect) {
#endif //BABYSTEPPING #endif //BABYSTEPPING
} }
#ifdef PIDTEMP #if ENABLED(PIDTEMP)
// Apply the scale factors to the PID values // Apply the scale factors to the PID values
float scalePID_i(float i) { return i * PID_dT; } float scalePID_i(float i) { return i * PID_dT; }
float unscalePID_i(float i) { return i / PID_dT; } float unscalePID_i(float i) { return i / PID_dT; }

View File

@ -23,7 +23,7 @@
#include "Marlin.h" #include "Marlin.h"
#include "planner.h" #include "planner.h"
#ifdef PID_ADD_EXTRUSION_RATE #if ENABLED(PID_ADD_EXTRUSION_RATE)
#include "stepper.h" #include "stepper.h"
#endif #endif
@ -31,7 +31,7 @@
void tp_init(); //initialize the heating void tp_init(); //initialize the heating
void manage_heater(); //it is critical that this is called periodically. void manage_heater(); //it is critical that this is called periodically.
#ifdef FILAMENT_SENSOR #if ENABLED(FILAMENT_SENSOR)
// For converting raw Filament Width to milimeters // For converting raw Filament Width to milimeters
float analog2widthFil(); float analog2widthFil();
@ -43,13 +43,13 @@ void manage_heater(); //it is critical that this is called periodically.
// do not use these routines and variables outside of temperature.cpp // do not use these routines and variables outside of temperature.cpp
extern int target_temperature[4]; extern int target_temperature[4];
extern float current_temperature[4]; extern float current_temperature[4];
#ifdef SHOW_TEMP_ADC_VALUES #if ENABLED(SHOW_TEMP_ADC_VALUES)
extern int current_temperature_raw[4]; extern int current_temperature_raw[4];
extern int current_temperature_bed_raw; extern int current_temperature_bed_raw;
#endif #endif
extern int target_temperature_bed; extern int target_temperature_bed;
extern float current_temperature_bed; extern float current_temperature_bed;
#ifdef TEMP_SENSOR_1_AS_REDUNDANT #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
extern float redundant_temperature; extern float redundant_temperature;
#endif #endif
@ -57,9 +57,9 @@ extern float current_temperature_bed;
extern unsigned char soft_pwm_bed; extern unsigned char soft_pwm_bed;
#endif #endif
#ifdef PIDTEMP #if ENABLED(PIDTEMP)
#ifdef PID_PARAMS_PER_EXTRUDER #if ENABLED(PID_PARAMS_PER_EXTRUDER)
extern float Kp[EXTRUDERS], Ki[EXTRUDERS], Kd[EXTRUDERS], Kc[EXTRUDERS]; // one param per extruder extern float Kp[EXTRUDERS], Ki[EXTRUDERS], Kd[EXTRUDERS], Kc[EXTRUDERS]; // one param per extruder
#define PID_PARAM(param,e) param[e] // use macro to point to array value #define PID_PARAM(param,e) param[e] // use macro to point to array value
#else #else
@ -73,11 +73,11 @@ extern float current_temperature_bed;
#endif #endif
#ifdef PIDTEMPBED #if ENABLED(PIDTEMPBED)
extern float bedKp,bedKi,bedKd; extern float bedKp,bedKi,bedKd;
#endif #endif
#ifdef BABYSTEPPING #if ENABLED(BABYSTEPPING)
extern volatile int babystepsTodo[3]; extern volatile int babystepsTodo[3];
#endif #endif
@ -88,7 +88,7 @@ extern float current_temperature_bed;
FORCE_INLINE float degHotend(uint8_t extruder) { return current_temperature[extruder]; } FORCE_INLINE float degHotend(uint8_t extruder) { return current_temperature[extruder]; }
FORCE_INLINE float degBed() { return current_temperature_bed; } FORCE_INLINE float degBed() { return current_temperature_bed; }
#ifdef SHOW_TEMP_ADC_VALUES #if ENABLED(SHOW_TEMP_ADC_VALUES)
FORCE_INLINE float rawHotendTemp(uint8_t extruder) { return current_temperature_raw[extruder]; } FORCE_INLINE float rawHotendTemp(uint8_t extruder) { return current_temperature_raw[extruder]; }
FORCE_INLINE float rawBedTemp() { return current_temperature_bed_raw; } FORCE_INLINE float rawBedTemp() { return current_temperature_bed_raw; }
#endif #endif
@ -96,13 +96,13 @@ FORCE_INLINE float degBed() { return current_temperature_bed; }
FORCE_INLINE float degTargetHotend(uint8_t extruder) { return target_temperature[extruder]; } FORCE_INLINE float degTargetHotend(uint8_t extruder) { return target_temperature[extruder]; }
FORCE_INLINE float degTargetBed() { return target_temperature_bed; } FORCE_INLINE float degTargetBed() { return target_temperature_bed; }
#ifdef THERMAL_PROTECTION_HOTENDS #if ENABLED(THERMAL_PROTECTION_HOTENDS)
void start_watching_heater(int e=0); void start_watching_heater(int e=0);
#endif #endif
FORCE_INLINE void setTargetHotend(const float &celsius, uint8_t extruder) { FORCE_INLINE void setTargetHotend(const float &celsius, uint8_t extruder) {
target_temperature[extruder] = celsius; target_temperature[extruder] = celsius;
#ifdef THERMAL_PROTECTION_HOTENDS #if ENABLED(THERMAL_PROTECTION_HOTENDS)
start_watching_heater(extruder); start_watching_heater(extruder);
#endif #endif
} }
@ -147,7 +147,7 @@ void setExtruderAutoFanState(int pin, bool state);
void checkExtruderAutoFans(); void checkExtruderAutoFans();
FORCE_INLINE void autotempShutdown() { FORCE_INLINE void autotempShutdown() {
#ifdef AUTOTEMP #if ENABLED(AUTOTEMP)
if (autotemp_enabled) { if (autotemp_enabled) {
autotemp_enabled = false; autotemp_enabled = false;
if (degTargetHotend(active_extruder) > autotemp_min) if (degTargetHotend(active_extruder) > autotemp_min)