Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
MarlinKimbra
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
machinery
MarlinKimbra
Commits
03152a21
Commit
03152a21
authored
Sep 03, 2015
by
MagoKimbra
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add PID_EXTRUSION_RATE
parent
c9fc2819
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
193 additions
and
88 deletions
+193
-88
changelog.md
Documentation/changelog.md
+1
-0
Configuration_Feature.h
MarlinKimbra/Configuration_Feature.h
+5
-0
Marlin_main.cpp
MarlinKimbra/Marlin_main.cpp
+27
-4
Marlin_main.h
MarlinKimbra/Marlin_main.h
+4
-1
configuration_store.cpp
MarlinKimbra/configuration_store.cpp
+56
-31
language.h
MarlinKimbra/language.h
+2
-0
temperature.cpp
MarlinKimbra/temperature.cpp
+96
-50
temperature.h
MarlinKimbra/temperature.h
+2
-2
No files found.
Documentation/changelog.md
View file @
03152a21
### Version 4.2.0
*
Add PID Extrusion Rate Kc in percent.
*
New configuration systems (Now you can create a separate file with all configuration and use it in you FW update)
*
New namings for file
*
Added more documentation inside configuration file
...
...
MarlinKimbra/Configuration_Feature.h
View file @
03152a21
...
...
@@ -169,11 +169,16 @@
// is more then PID_FUNCTIONAL_RANGE then the PID will be shut off and the heater will be set to min/max.
#define PID_FUNCTIONAL_RANGE 10 // degC
#define PID_INTEGRAL_DRIVE_MAX PID_MAX // Limit for the integral term
// this adds an experimental additional term to the heating power, proportional to the extrusion speed.
// if Kc is chosen well, the additional required power due to increased melting should be compensated.
//#define PID_ADD_EXTRUSION_RATE
#define LPQ_MAX_LEN 50
// HotEnd{HE0,HE1,HE2,HE3}
#define DEFAULT_Kp {40, 40, 40, 40} // Kp for E0, E1, E2, E3
#define DEFAULT_Ki {07, 07, 07, 07} // Ki for E0, E1, E2, E3
#define DEFAULT_Kd {60, 60, 60, 60} // Kd for E0, E1, E2, E3
#define DEFAULT_Kc {100, 100, 100, 100} // heating power = Kc * (e_speed)
/***********************************************************************/
...
...
MarlinKimbra/Marlin_main.cpp
View file @
03152a21
...
...
@@ -195,7 +195,7 @@
* M250 - Set LCD contrast C<contrast value> (value 0..63)
* M280 - Set servo position absolute. P: servo index, S: angle or microseconds
* M300 - Play beep sound S<frequency Hz> P<duration ms>
* M301 - Set PID parameters P I
and D
* M301 - Set PID parameters P I
D and C
* M302 - Allow cold extrudes, or set the minimum extrude S<temperature>.
* M303 - PID relay autotune S<temperature> sets the target temperature. (default target temperature = 150C)
* M304 - Set bed PID parameters P I and D
...
...
@@ -489,6 +489,10 @@ unsigned long printer_usage_seconds;
boolean
chdkActive
=
false
;
#endif
#if ENABLED(PIDTEMP) && ENABLED(PID_ADD_EXTRUSION_RATE)
int
lpq_len
=
20
;
#endif
//===========================================================================
//================================ Functions ================================
//===========================================================================
...
...
@@ -5899,25 +5903,44 @@ inline void gcode_M226() {
#if ENABLED(PIDTEMP)
/**
* M301: Set PID parameters P I D
* M301: Set PID parameters P I D (and optionally C, L)
*
* P[float] Kp term
* I[float] Ki term (unscaled)
* D[float] Kd term (unscaled)
*
* With PID_ADD_EXTRUSION_RATE:
*
* C[float] Kc term
* L[float] LPQ length
*/
inline
void
gcode_M301
()
{
// multi-hotend PID patch: M301 updates or prints a single hotend's PID values
// default behaviour (omitting E parameter) is to update for hotend 0 only
int
e
=
code_seen
(
'
E
'
)
?
code_value
()
:
0
;
// hotend being updated
int
e
=
code_seen
(
'
H
'
)
?
code_value
()
:
0
;
// hotend being updated
if
(
e
<
HOTENDS
)
{
// catch bad input value
if
(
code_seen
(
'P'
))
PID_PARAM
(
Kp
,
e
)
=
code_value
();
if
(
code_seen
(
'I'
))
PID_PARAM
(
Ki
,
e
)
=
scalePID_i
(
code_value
());
if
(
code_seen
(
'D'
))
PID_PARAM
(
Kd
,
e
)
=
scalePID_d
(
code_value
());
#if ENABLED(PID_ADD_EXTRUSION_RATE)
if
(
code_seen
(
'C'
))
PID_PARAM
(
Kc
,
e
)
=
code_value
();
if
(
code_seen
(
'L'
))
lpq_len
=
code_value
();
NOMORE
(
lpq_len
,
LPQ_MAX_LEN
);
#endif
updatePID
();
ECHO_SMV
(
OK
,
"e:"
,
e
);
ECHO_MV
(
" p:"
,
PID_PARAM
(
Kp
,
e
));
ECHO_MV
(
" i:"
,
unscalePID_i
(
PID_PARAM
(
Ki
,
e
)));
ECHO_EMV
(
" d:"
,
unscalePID_d
(
PID_PARAM
(
Kd
,
e
)));
ECHO_MV
(
" d:"
,
unscalePID_d
(
PID_PARAM
(
Kd
,
e
)));
#if ENABLED(PID_ADD_EXTRUSION_RATE)
ECHO_MV
(
" c:"
,
PID_PARAM
(
Kc
,
e
));
#endif
ECHO_E
;
}
else
{
ECHO_LM
(
ER
,
MSG_INVALID_EXTRUDER
);
...
...
MarlinKimbra/Marlin_main.h
View file @
03152a21
...
...
@@ -10,7 +10,6 @@ void idle(bool ignore_stepper_queue = false);
void
manage_inactivity
(
bool
ignore_stepper_queue
=
false
);
void
FlushSerialRequestResend
();
void
ok_to_send
();
...
...
@@ -172,6 +171,10 @@ extern int fanSpeed;
extern
void
IDLE_OOZING_retract
(
bool
retracting
);
#endif
#if ENABLED(PIDTEMP) && ENABLED(PID_ADD_EXTRUSION_RATE)
extern
int
lpq_len
;
#endif
#if ENABLED(FWRETRACT)
extern
bool
autoretract_enabled
;
extern
bool
retracted
[
EXTRUDERS
];
// extruder[n].retracted
...
...
MarlinKimbra/configuration_store.cpp
View file @
03152a21
...
...
@@ -29,10 +29,10 @@
*
*/
#define EEPROM_VERSION "V2
4
"
#define EEPROM_VERSION "V2
5
"
/**
* V2
4
EEPROM Layout:
* V2
5
EEPROM Layout:
*
* ver
* M92 XYZ E0 ... axis_steps_per_unit X,Y,Z,E0 ... (per extruder)
...
...
@@ -77,10 +77,11 @@
* M145 S2 F gumPreheatFanSpeed
*
* PIDTEMP:
* M301 E0 PID Kp[0], Ki[0], Kd[0]
* M301 E1 PID Kp[1], Ki[1], Kd[1]
* M301 E2 PID Kp[2], Ki[2], Kd[2]
* M301 E3 PID Kp[3], Ki[3], Kd[3]
* M301 E0 PIDC Kp[0], Ki[0], Kd[0], Kc[0]
* M301 E1 PIDC Kp[1], Ki[1], Kd[1], Kc[1]
* M301 E2 PIDC Kp[2], Ki[2], Kd[2], Kc[2]
* M301 E3 PIDC Kp[3], Ki[3], Kd[3], Kc[3]
* M301 L lpq_len
*
* PIDTEMPBED:
* M304 PID bedKp, bedKi, bedKd
...
...
@@ -199,13 +200,19 @@ void Config_StoreSettings() {
EEPROM_WRITE_VAR
(
i
,
gumPreheatFanSpeed
);
#if ENABLED(PIDTEMP)
for
(
int
e
=
0
;
e
<
HOTENDS
;
e
++
)
{
EEPROM_WRITE_VAR
(
i
,
PID_PARAM
(
Kp
,
e
));
EEPROM_WRITE_VAR
(
i
,
PID_PARAM
(
Ki
,
e
));
EEPROM_WRITE_VAR
(
i
,
PID_PARAM
(
Kd
,
e
));
for
(
int
h
=
0
;
h
<
HOTENDS
;
h
++
)
{
EEPROM_WRITE_VAR
(
i
,
PID_PARAM
(
Kp
,
h
));
EEPROM_WRITE_VAR
(
i
,
PID_PARAM
(
Ki
,
h
));
EEPROM_WRITE_VAR
(
i
,
PID_PARAM
(
Kd
,
h
));
EEPROM_WRITE_VAR
(
i
,
PID_PARAM
(
Kc
,
h
));
}
#endif
#if DISABLED(PID_ADD_EXTRUSION_RATE)
int
lpq_len
=
20
;
#endif
EEPROM_WRITE_VAR
(
i
,
lpq_len
);
#if ENABLED(PIDTEMPBED)
EEPROM_WRITE_VAR
(
i
,
bedKp
);
EEPROM_WRITE_VAR
(
i
,
bedKi
);
...
...
@@ -336,13 +343,19 @@ void Config_RetrieveSettings() {
EEPROM_READ_VAR
(
i
,
gumPreheatFanSpeed
);
#if ENABLED(PIDTEMP)
for
(
int8_t
e
=
0
;
e
<
HOTENDS
;
e
++
)
{
EEPROM_READ_VAR
(
i
,
PID_PARAM
(
Kp
,
e
));
EEPROM_READ_VAR
(
i
,
PID_PARAM
(
Ki
,
e
));
EEPROM_READ_VAR
(
i
,
PID_PARAM
(
Kd
,
e
));
for
(
int8_t
h
=
0
;
h
<
HOTENDS
;
h
++
)
{
EEPROM_READ_VAR
(
i
,
PID_PARAM
(
Kp
,
h
));
EEPROM_READ_VAR
(
i
,
PID_PARAM
(
Ki
,
h
));
EEPROM_READ_VAR
(
i
,
PID_PARAM
(
Kd
,
h
));
EEPROM_READ_VAR
(
i
,
PID_PARAM
(
Kc
,
h
));
}
#endif // PIDTEMP
#if DISABLED(PID_ADD_EXTRUSION_RATE)
int
lpq_len
;
#endif
EEPROM_READ_VAR
(
i
,
lpq_len
);
#if ENABLED(PIDTEMPBED)
EEPROM_READ_VAR
(
i
,
bedKp
);
EEPROM_READ_VAR
(
i
,
bedKi
);
...
...
@@ -420,14 +433,15 @@ void Config_ResetDefault() {
float
tmp6
[]
=
DEFAULT_Kp
;
float
tmp7
[]
=
DEFAULT_Ki
;
float
tmp8
[]
=
DEFAULT_Kd
;
float
tmp9
[]
=
DEFAULT_Kc
;
#endif // PIDTEMP
#if ENABLED(HOTEND_OFFSET_X) && ENABLED(HOTEND_OFFSET_Y)
float
tmp
9
[]
=
HOTEND_OFFSET_X
;
float
tmp1
0
[]
=
HOTEND_OFFSET_Y
;
float
tmp
10
[]
=
HOTEND_OFFSET_X
;
float
tmp1
1
[]
=
HOTEND_OFFSET_Y
;
#else
float
tmp9
[]
=
{
0
};
float
tmp10
[]
=
{
0
};
float
tmp11
[]
=
{
0
};
#endif
for
(
int8_t
i
=
0
;
i
<
3
+
EXTRUDERS
;
i
++
)
{
...
...
@@ -459,14 +473,14 @@ void Config_ResetDefault() {
else
max_e_jerk
[
i
]
=
tmp5
[
max_i
-
1
];
#if HOTENDS > 1
max_i
=
sizeof
(
tmp
9
)
/
sizeof
(
*
tmp9
);
max_i
=
sizeof
(
tmp
10
)
/
sizeof
(
*
tmp10
);
if
(
i
<
max_i
)
hotend_offset
[
X_AXIS
][
i
]
=
tmp
9
[
i
];
hotend_offset
[
X_AXIS
][
i
]
=
tmp
10
[
i
];
else
hotend_offset
[
X_AXIS
][
i
]
=
0
;
max_i
=
sizeof
(
tmp1
0
)
/
sizeof
(
*
tmp10
);
max_i
=
sizeof
(
tmp1
1
)
/
sizeof
(
*
tmp11
);
if
(
i
<
max_i
)
hotend_offset
[
Y_AXIS
][
i
]
=
tmp1
0
[
i
];
hotend_offset
[
Y_AXIS
][
i
]
=
tmp1
1
[
i
];
else
hotend_offset
[
Y_AXIS
][
i
]
=
0
;
#endif // HOTENDS > 1
...
...
@@ -535,11 +549,15 @@ void Config_ResetDefault() {
#endif
#if ENABLED(PIDTEMP)
for
(
int8_t
e
=
0
;
e
<
HOTENDS
;
e
++
)
{
Kp
[
e
]
=
tmp6
[
e
];
Ki
[
e
]
=
scalePID_i
(
tmp7
[
e
]);
Kd
[
e
]
=
scalePID_d
(
tmp8
[
e
]);
for
(
int8_t
h
=
0
;
h
<
HOTENDS
;
h
++
)
{
Kp
[
h
]
=
tmp6
[
h
];
Ki
[
h
]
=
scalePID_i
(
tmp7
[
h
]);
Kd
[
h
]
=
scalePID_d
(
tmp8
[
h
]);
Kc
[
h
]
=
tmp9
[
h
];
}
#if ENABLED(PID_ADD_EXTRUSION_RATE)
lpq_len
=
20
;
// default last-position-queue size
#endif
// call updatePID (similar to when we have processed M301)
updatePID
();
#endif // PIDTEMP
...
...
@@ -752,12 +770,19 @@ void Config_ResetDefault() {
ECHO_LM
(
DB
,
"PID settings:"
);
}
#if ENABLED(PIDTEMP)
for
(
int
e
=
0
;
e
<
HOTENDS
;
e
++
)
{
ECHO_SMV
(
DB
,
" M301 E"
,
e
);
ECHO_MV
(
" P"
,
PID_PARAM
(
Kp
,
e
));
ECHO_MV
(
" I"
,
unscalePID_i
(
PID_PARAM
(
Ki
,
e
)));
ECHO_EMV
(
" D"
,
unscalePID_d
(
PID_PARAM
(
Kd
,
e
)));
for
(
int
h
=
0
;
h
<
HOTENDS
;
h
++
)
{
ECHO_SMV
(
DB
,
" M301 H"
,
h
);
ECHO_MV
(
" P"
,
PID_PARAM
(
Kp
,
h
));
ECHO_MV
(
" I"
,
unscalePID_i
(
PID_PARAM
(
Ki
,
h
)));
ECHO_MV
(
" D"
,
unscalePID_d
(
PID_PARAM
(
Kd
,
h
)));
#if ENABLED(PID_ADD_EXTRUSION_RATE)
ECHO_MV
(
" C"
,
PID_PARAM
(
Kc
,
h
));
#endif
ECHO_E
;
}
#if ENABLED(PID_ADD_EXTRUSION_RATE)
ECHO_SMV
(
DB
,
" M301 L"
,
lpq_len
);
#endif
#endif
#if ENABLED(PIDTEMPBED)
ECHO_SMV
(
DB
,
" M304 P"
,
bedKp
);
// for compatibility with hosts, only echos values for E0
...
...
MarlinKimbra/language.h
View file @
03152a21
...
...
@@ -179,6 +179,7 @@
#define MSG_KP " Kp: "
#define MSG_KI " Ki: "
#define MSG_KD " Kd: "
#define MSG_KC " Kc: "
#define MSG_B "B:"
#define MSG_T "T:"
#define MSG_AT "@:"
...
...
@@ -191,6 +192,7 @@
#define MSG_PID_DEBUG_PTERM " pTerm "
#define MSG_PID_DEBUG_ITERM " iTerm "
#define MSG_PID_DEBUG_DTERM " dTerm "
#define MSG_PID_DEBUG_CTERM " cTerm "
#define MSG_INVALID_EXTRUDER_NUM " - Invalid extruder number !"
#define MSG_HEATER_BED "bed"
...
...
MarlinKimbra/temperature.cpp
View file @
03152a21
...
...
@@ -123,6 +123,12 @@ static volatile bool temp_meas_ready = false;
static
float
pTerm
[
HOTENDS
];
static
float
iTerm
[
HOTENDS
];
static
float
dTerm
[
HOTENDS
];
#if ENABLED(PID_ADD_EXTRUSION_RATE)
static
float
cTerm
[
HOTENDS
];
static
long
last_position
[
EXTRUDERS
];
static
long
lpq
[
LPQ_MAX_LEN
];
static
int
lpq_ptr
=
0
;
#endif
//int output;
static
float
pid_error
[
HOTENDS
];
static
float
temp_iState_min
[
HOTENDS
];
...
...
@@ -160,7 +166,7 @@ static unsigned char soft_pwm[HOTENDS];
#endif
#if ENABLED(PIDTEMP)
float
Kp
[
HOTENDS
],
Ki
[
HOTENDS
],
Kd
[
HOTENDS
];
float
Kp
[
HOTENDS
],
Ki
[
HOTENDS
],
Kd
[
HOTENDS
]
,
Kc
[
HOTENDS
]
;
#endif //PIDTEMP
// Init min and max temp with extreme values to prevent false errors during startup
...
...
@@ -390,8 +396,8 @@ void autotempShutdown() {
void
updatePID
()
{
#if ENABLED(PIDTEMP)
for
(
int
e
=
0
;
e
<
HOTENDS
;
e
++
)
{
temp_iState_max
[
e
]
=
PID_INTEGRAL_DRIVE_MAX
/
PID_PARAM
(
Ki
,
e
);
for
(
int
h
=
0
;
h
<
HOTENDS
;
h
++
)
{
temp_iState_max
[
h
]
=
PID_INTEGRAL_DRIVE_MAX
/
PID_PARAM
(
Ki
,
h
);
}
#endif
#if ENABLED(PIDTEMPBED)
...
...
@@ -484,13 +490,13 @@ void checkExtruderAutoFans() {
//
// Temperature Error Handlers
//
inline
void
_temp_error
(
int
e
,
const
char
*
serial_msg
,
const
char
*
lcd_msg
)
{
inline
void
_temp_error
(
int
h
,
const
char
*
serial_msg
,
const
char
*
lcd_msg
)
{
static
bool
killed
=
false
;
if
(
IsRunning
())
{
ECHO_S
(
ER
);
PS_PGM
(
serial_msg
);
ECHO_M
(
MSG_STOPPED_HEATER
);
if
(
e
>=
0
)
ECHO_EV
((
int
)
e
);
else
ECHO_EM
(
MSG_HEATER_BED
);
if
(
h
>=
0
)
ECHO_EV
((
int
)
h
);
else
ECHO_EM
(
MSG_HEATER_BED
);
#if ENABLED(ULTRA_LCD)
lcd_setalertstatuspgm
(
lcd_msg
);
#endif
...
...
@@ -506,63 +512,97 @@ inline void _temp_error(int e, const char *serial_msg, const char *lcd_msg) {
#endif
}
void
max_temp_error
(
uint8_t
e
)
{
_temp_error
(
e
,
PSTR
(
MSG_T_MAXTEMP
),
PSTR
(
MSG_ERR_MAXTEMP
));
void
max_temp_error
(
uint8_t
h
)
{
_temp_error
(
h
,
PSTR
(
MSG_T_MAXTEMP
),
PSTR
(
MSG_ERR_MAXTEMP
));
}
void
min_temp_error
(
uint8_t
e
)
{
_temp_error
(
e
,
PSTR
(
MSG_T_MINTEMP
),
PSTR
(
MSG_ERR_MINTEMP
));
void
min_temp_error
(
uint8_t
h
)
{
_temp_error
(
h
,
PSTR
(
MSG_T_MINTEMP
),
PSTR
(
MSG_ERR_MINTEMP
));
}
float
get_pid_output
(
int
e
)
{
float
get_pid_output
(
int
h
)
{
float
pid_output
;
#if ENABLED(PIDTEMP)
#if ENABLED(PID_OPENLOOP)
pid_output
=
constrain
(
target_temperature
[
e
],
0
,
PID_MAX
);
pid_output
=
constrain
(
target_temperature
[
h
],
0
,
PID_MAX
);
#else
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
];
temp_dState
[
e
]
=
current_temperature
[
e
];
if
(
pid_error
[
e
]
>
PID_FUNCTIONAL_RANGE
)
{
pid_error
[
h
]
=
target_temperature
[
h
]
-
current_temperature
[
h
];
dTerm
[
h
]
=
K2
*
PID_PARAM
(
Kd
,
h
)
*
(
current_temperature
[
h
]
-
temp_dState
[
h
])
+
K1
*
dTerm
[
h
];
temp_dState
[
h
]
=
current_temperature
[
h
];
if
(
pid_error
[
h
]
>
PID_FUNCTIONAL_RANGE
)
{
pid_output
=
BANG_MAX
;
pid_reset
[
e
]
=
true
;
pid_reset
[
h
]
=
true
;
}
else
if
(
pid_error
[
e
]
<
-
PID_FUNCTIONAL_RANGE
||
target_temperature
[
e
]
==
0
)
{
else
if
(
pid_error
[
h
]
<
-
PID_FUNCTIONAL_RANGE
||
target_temperature
[
h
]
==
0
)
{
pid_output
=
0
;
pid_reset
[
e
]
=
true
;
pid_reset
[
h
]
=
true
;
}
else
{
if
(
pid_reset
[
e
])
{
temp_iState
[
e
]
=
0.0
;
pid_reset
[
e
]
=
false
;
if
(
pid_reset
[
h
])
{
temp_iState
[
h
]
=
0.0
;
pid_reset
[
h
]
=
false
;
}
pTerm
[
h
]
=
PID_PARAM
(
Kp
,
h
)
*
pid_error
[
h
];
temp_iState
[
h
]
+=
pid_error
[
h
];
temp_iState
[
h
]
=
constrain
(
temp_iState
[
h
],
temp_iState_min
[
h
],
temp_iState_max
[
h
]);
iTerm
[
h
]
=
PID_PARAM
(
Ki
,
h
)
*
temp_iState
[
h
];
pid_output
=
pTerm
[
h
]
+
iTerm
[
h
]
-
dTerm
[
h
];
#if ENABLED(PID_ADD_EXTRUSION_RATE)
cTerm
[
h
]
=
0
;
#if ENABLED(SINGLENOZZLE)
long
e_position
=
st_get_position
(
E_AXIS
);
if
(
e_position
>
last_position
[
active_extruder
])
{
lpq
[
lpq_ptr
++
]
=
e_position
-
last_position
[
active_extruder
];
last_position
[
active_extruder
]
=
e_position
;
}
else
{
lpq
[
lpq_ptr
++
]
=
0
;
}
if
(
lpq_ptr
>=
lpq_len
)
lpq_ptr
=
0
;
cTerm
[
0
]
=
(
lpq
[
lpq_ptr
]
/
axis_steps_per_unit
[
E_AXIS
+
active_extruder
])
*
Kc
[
0
];
pid_output
+=
cTerm
[
0
]
/
100.0
;
#else
if
(
h
==
active_extruder
)
{
long
e_position
=
st_get_position
(
E_AXIS
);
if
(
e_position
>
last_position
[
h
])
{
lpq
[
lpq_ptr
++
]
=
e_position
-
last_position
[
h
];
last_position
[
h
]
=
e_position
;
}
else
{
lpq
[
lpq_ptr
++
]
=
0
;
}
if
(
lpq_ptr
>=
lpq_len
)
lpq_ptr
=
0
;
cTerm
[
h
]
=
(
lpq
[
lpq_ptr
]
/
axis_steps_per_unit
[
E_AXIS
+
active_extruder
])
*
Kc
[
h
];
pid_output
+=
cTerm
[
h
]
/
100.0
;
}
pTerm
[
e
]
=
PID_PARAM
(
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
]
=
PID_PARAM
(
Ki
,
e
)
*
temp_iState
[
e
];
#endif // SINGLENOZZLE
#endif // PID_ADD_EXTRUSION_RATE
pid_output
=
pTerm
[
e
]
+
iTerm
[
e
]
-
dTerm
[
e
];
if
(
pid_output
>
PID_MAX
)
{
if
(
pid_error
[
e
]
>
0
)
temp_iState
[
e
]
-=
pid_error
[
e
];
// conditional un-integration
if
(
pid_error
[
h
]
>
0
)
temp_iState
[
h
]
-=
pid_error
[
h
];
// conditional un-integration
pid_output
=
PID_MAX
;
}
else
if
(
pid_output
<
0
)
{
if
(
pid_error
[
e
]
<
0
)
temp_iState
[
e
]
-=
pid_error
[
e
];
// conditional un-integration
if
(
pid_error
[
h
]
<
0
)
temp_iState
[
h
]
-=
pid_error
[
h
];
// conditional un-integration
pid_output
=
0
;
}
}
#endif //PID_OPENLOOP
#endif //
PID_OPENLOOP
#if ENABLED(PID_DEBUG)
ECHO_SMV
(
DB
,
MSG_PID_DEBUG
,
e
);
ECHO_MV
(
MSG_PID_DEBUG_INPUT
,
current_temperature
[
e
]);
ECHO_SMV
(
DB
,
MSG_PID_DEBUG
,
h
);
ECHO_MV
(
MSG_PID_DEBUG_INPUT
,
current_temperature
[
h
]);
ECHO_MV
(
MSG_PID_DEBUG_OUTPUT
,
pid_output
);
ECHO_MV
(
MSG_PID_DEBUG_PTERM
,
pTerm
[
e
]);
ECHO_MV
(
MSG_PID_DEBUG_ITERM
,
iTerm
[
e
]);
ECHO_EMV
(
MSG_PID_DEBUG_DTERM
,
dTerm
[
e
]);
#endif //PID_DEBUG
ECHO_MV
(
MSG_PID_DEBUG_PTERM
,
pTerm
[
h
]);
ECHO_MV
(
MSG_PID_DEBUG_ITERM
,
iTerm
[
h
]);
ECHO_MV
(
MSG_PID_DEBUG_DTERM
,
dTerm
[
h
]);
#if ENABLED(PID_ADD_EXTRUSION_RATE)
ECHO_MV
(
MSG_PID_DEBUG_CTERM
,
cTerm
[
h
]);
#endif
ECHO_E
;
#endif // PID_DEBUG
#else
/* PID off */
pid_output
=
(
current_temperature
[
e
]
<
target_temperature
[
e
])
?
PID_MAX
:
0
;
pid_output
=
(
current_temperature
[
h
]
<
target_temperature
[
h
])
?
PID_MAX
:
0
;
#endif
return
pid_output
;
...
...
@@ -632,30 +672,30 @@ void manage_heater() {
#endif
// Loop through all hotends
for
(
int
e
=
0
;
e
<
HOTENDS
;
e
++
)
{
for
(
int
h
=
0
;
h
<
HOTENDS
;
h
++
)
{
#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
[
h
],
&
thermal_runaway_timer
[
h
],
current_temperature
[
h
],
target_temperature
[
h
],
h
,
THERMAL_PROTECTION_PERIOD
,
THERMAL_PROTECTION_HYSTERESIS
);
#endif
float
pid_output
=
get_pid_output
(
e
);
float
pid_output
=
get_pid_output
(
h
);
// Check if temperature is within the correct range
soft_pwm
[
e
]
=
current_temperature
[
e
]
>
minttemp
[
e
]
&&
current_temperature
[
e
]
<
maxttemp
[
e
]
?
(
int
)
pid_output
>>
1
:
0
;
soft_pwm
[
h
]
=
current_temperature
[
h
]
>
minttemp
[
h
]
&&
current_temperature
[
h
]
<
maxttemp
[
h
]
?
(
int
)
pid_output
>>
1
:
0
;
// Check if the temperature is failing to increase
#if ENABLED(THERMAL_PROTECTION_HOTENDS)
// 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
[
h
]
&&
ms
>
watch_heater_next_ms
[
h
])
{
// Has it failed to increase enough?
if
(
degHotend
(
e
)
<
watch_target_temp
[
e
])
{
if
(
degHotend
(
h
)
<
watch_target_temp
[
h
])
{
// Stop!
_temp_error
(
e
,
PSTR
(
MSG_T_HEATING_FAILED
),
PSTR
(
MSG_HEATING_FAILED_LCD
));
_temp_error
(
h
,
PSTR
(
MSG_T_HEATING_FAILED
),
PSTR
(
MSG_HEATING_FAILED_LCD
));
}
else
{
// Start again if the target is still far off
start_watching_heater
(
e
);
start_watching_heater
(
h
);
}
}
...
...
@@ -828,8 +868,8 @@ static void updateTemperaturesFromRawValues() {
#if ENABLED(HEATER_0_USES_MAX6675)
current_temperature_raw
[
0
]
=
read_max6675
();
#endif
for
(
uint8_t
e
=
0
;
e
<
HOTENDS
;
e
++
)
{
current_temperature
[
e
]
=
analog2temp
(
current_temperature_raw
[
e
],
e
);
for
(
uint8_t
h
=
0
;
h
<
HOTENDS
;
h
++
)
{
current_temperature
[
h
]
=
analog2temp
(
current_temperature_raw
[
h
],
h
);
}
current_temperature_bed
=
analog2tempBed
(
current_temperature_bed_raw
);
#if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
...
...
@@ -932,12 +972,12 @@ void tp_init() {
#endif
// Finish init of mult hotends arrays
for
(
int
e
=
0
;
e
<
HOTENDS
;
e
++
)
{
for
(
int
h
=
0
;
h
<
HOTENDS
;
h
++
)
{
// populate with the first value
maxttemp
[
e
]
=
maxttemp
[
0
];
maxttemp
[
h
]
=
maxttemp
[
0
];
#if ENABLED(PIDTEMP)
temp_iState_min
[
e
]
=
0.0
;
temp_iState_max
[
e
]
=
PID_INTEGRAL_DRIVE_MAX
/
PID_PARAM
(
Ki
,
e
);
temp_iState_min
[
h
]
=
0.0
;
temp_iState_max
[
h
]
=
PID_INTEGRAL_DRIVE_MAX
/
PID_PARAM
(
Ki
,
h
);
#endif //PIDTEMP
#if ENABLED(PIDTEMPBED)
temp_iState_min_bed
=
0.0
;
...
...
@@ -945,6 +985,12 @@ void tp_init() {
#endif // PIDTEMPBED
}
#if ENABLED(PID_ADD_EXTRUSION_RATE)
for
(
int
e
=
0
;
e
<
EXTRUDERS
;
e
++
)
{
last_position
[
e
]
=
0
;
}
#endif
#if HAS(HEATER_0)
SET_OUTPUT
(
HEATER_0_PIN
);
#endif
...
...
MarlinKimbra/temperature.h
View file @
03152a21
...
...
@@ -62,12 +62,12 @@ extern float current_temperature_bed;
#endif
#if ENABLED(PIDTEMP)
extern
float
Kp
[
HOTENDS
],
Ki
[
HOTENDS
],
Kd
[
HOTENDS
];
extern
float
Kp
[
HOTENDS
],
Ki
[
HOTENDS
],
Kd
[
HOTENDS
]
,
Kc
[
HOTENDS
]
;
#define PID_PARAM(param, e) param[e] // use macro to point to array value
#endif
#if ENABLED(PIDTEMPBED)
extern
float
bedKp
,
bedKi
,
bedKd
;
extern
float
bedKp
,
bedKi
,
bedKd
;
#endif
#if ENABLED(PIDTEMP) || ENABLED(PIDTEMPBED)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment