|
|
@ -34,6 +34,16 @@ |
|
|
|
#include "temperature.h" |
|
|
|
#include "watchdog.h" |
|
|
|
|
|
|
|
#if EXTRUDERS > 3 |
|
|
|
# error Unsupported number of extruders |
|
|
|
#elif EXTRUDERS > 2 |
|
|
|
# define ARRAY_BY_EXTRUDERS(v1, v2, v3) { v1, v2, v3 } |
|
|
|
#elif EXTRUDERS > 1 |
|
|
|
# define ARRAY_BY_EXTRUDERS(v1, v2, v3) { v1, v2 } |
|
|
|
#else |
|
|
|
# define ARRAY_BY_EXTRUDERS(v1, v2, v3) { v1 } |
|
|
|
#endif |
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//=============================public variables============================
|
|
|
|
//===========================================================================
|
|
|
@ -45,9 +55,9 @@ int current_temperature_bed_raw = 0; |
|
|
|
float current_temperature_bed = 0; |
|
|
|
|
|
|
|
#ifdef PIDTEMP |
|
|
|
float Kp=DEFAULT_Kp; |
|
|
|
float Ki=(DEFAULT_Ki*PID_dT); |
|
|
|
float Kd=(DEFAULT_Kd/PID_dT); |
|
|
|
float Kp[EXTRUDERS] = ARRAY_BY_EXTRUDERS(DEFAULT_Kp, DEFAULT_Kp_E1, DEFAULT_Kp_E2); |
|
|
|
float Ki[EXTRUDERS] = ARRAY_BY_EXTRUDERS(DEFAULT_Ki*PID_dT, DEFAULT_Ki_E1*PID_dT, DEFAULT_Ki_E2*PID_dT); |
|
|
|
float Kd[EXTRUDERS] = ARRAY_BY_EXTRUDERS(DEFAULT_Kd/PID_dT, DEFAULT_Kd_E1/PID_dT, DEFAULT_Kd_E2/PID_dT); |
|
|
|
#ifdef PID_ADD_EXTRUSION_RATE |
|
|
|
float Kc=DEFAULT_Kc; |
|
|
|
#endif |
|
|
@ -102,15 +112,7 @@ static volatile bool temp_meas_ready = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if EXTRUDERS > 3 |
|
|
|
# error Unsupported number of extruders |
|
|
|
#elif EXTRUDERS > 2 |
|
|
|
# define ARRAY_BY_EXTRUDERS(v1, v2, v3) { v1, v2, v3 } |
|
|
|
#elif EXTRUDERS > 1 |
|
|
|
# define ARRAY_BY_EXTRUDERS(v1, v2, v3) { v1, v2 } |
|
|
|
#else |
|
|
|
# define ARRAY_BY_EXTRUDERS(v1, v2, v3) { v1 } |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
// Init min and max temp with extreme values to prevent false errors during startup
|
|
|
|
static int minttemp_raw[EXTRUDERS] = ARRAY_BY_EXTRUDERS( HEATER_0_RAW_LO_TEMP , HEATER_1_RAW_LO_TEMP , HEATER_2_RAW_LO_TEMP ); |
|
|
@ -292,7 +294,7 @@ void updatePID() |
|
|
|
{ |
|
|
|
#ifdef PIDTEMP |
|
|
|
for(int e = 0; e < EXTRUDERS; e++) { |
|
|
|
temp_iState_max[e] = PID_INTEGRAL_DRIVE_MAX / Ki; |
|
|
|
temp_iState_max[e] = PID_INTEGRAL_DRIVE_MAX / Ki[e]; |
|
|
|
} |
|
|
|
#endif |
|
|
|
#ifdef PIDTEMPBED |
|
|
@ -337,14 +339,14 @@ void manage_heater() |
|
|
|
temp_iState[e] = 0.0; |
|
|
|
pid_reset[e] = false; |
|
|
|
} |
|
|
|
pTerm[e] = Kp * pid_error[e]; |
|
|
|
pTerm[e] = Kp[e] * pid_error[e]; |
|
|
|
temp_iState[e] += pid_error[e]; |
|
|
|
temp_iState[e] = constrain(temp_iState[e], temp_iState_min[e], temp_iState_max[e]); |
|
|
|
iTerm[e] = Ki * temp_iState[e]; |
|
|
|
iTerm[e] = Ki[e] * temp_iState[e]; |
|
|
|
|
|
|
|
//K1 defined in Configuration.h in the PID settings
|
|
|
|
#define K2 (1.0-K1) |
|
|
|
dTerm[e] = (Kd * (pid_input - temp_dState[e]))*K2 + (K1 * dTerm[e]); |
|
|
|
dTerm[e] = (Kd[e] * (pid_input - temp_dState[e]))*K2 + (K1 * dTerm[e]); |
|
|
|
temp_dState[e] = pid_input; |
|
|
|
|
|
|
|
pid_output = constrain(pTerm[e] + iTerm[e] - dTerm[e], 0, PID_MAX); |
|
|
@ -577,7 +579,7 @@ void tp_init() |
|
|
|
maxttemp[e] = maxttemp[0]; |
|
|
|
#ifdef PIDTEMP |
|
|
|
temp_iState_min[e] = 0.0; |
|
|
|
temp_iState_max[e] = PID_INTEGRAL_DRIVE_MAX / Ki; |
|
|
|
temp_iState_max[e] = PID_INTEGRAL_DRIVE_MAX / Ki[e]; |
|
|
|
#endif //PIDTEMP
|
|
|
|
#ifdef PIDTEMPBED |
|
|
|
temp_iState_min_bed = 0.0; |
|
|
|