Skip to content

Commit

Permalink
Allow PID_DEBUG to be turned on and off (MarlinFirmware#17284)
Browse files Browse the repository at this point in the history
M303 D will now toggle activation of PID_DEBUG output.   This allows the debug capability to be built into the firmware, but turned on and off as needed.
  • Loading branch information
Roxy-3D authored and mathom committed Apr 16, 2020
1 parent a07bab8 commit fd53090
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@
#if ENABLED(PIDTEMP)
//#define PID_EDIT_MENU // Add PID editing to the "Advanced Settings" menu. (~700 bytes of PROGMEM)
//#define PID_AUTOTUNE_MENU // Add PID auto-tuning to the "Advanced Settings" menu. (~250 bytes of PROGMEM)
//#define PID_DEBUG // Sends debug data to the serial port.
//#define PID_DEBUG // Sends debug data to the serial port. Use M303 D to toggle activation.
//#define PID_OPENLOOP 1 // Puts PID in open loop. M104/M140 sets the output power from 0 to PID_MAX
//#define SLOW_PWM_HEATERS // PWM with very low frequency (roughly 0.125Hz=8s) and minimum state time of approximately 1s useful for heaters driven by a relay
//#define PID_PARAMS_PER_HOTEND // Uses separate PID parameters for each extruder (useful for mismatched extruders)
Expand Down
16 changes: 16 additions & 0 deletions Marlin/src/gcode/temp/M303.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@
* E<extruder> (-1 for the bed) (default 0)
* C<cycles> Minimum 3. Default 5.
* U<bool> with a non-zero value will apply the result to current settings
* D Toggles PID_DEBUG flag. No other action happens even if more parameters are specified.
*/

#if ENABLED(PID_DEBUG)
bool PID_Debug_Flag = 0;
#endif

void GcodeSuite::M303() {
#if ENABLED(PIDTEMPBED)
#define SI H_BED
Expand All @@ -63,6 +69,16 @@ void GcodeSuite::M303() {
const bool u = parser.boolval('U');
const int16_t temp = parser.celsiusval('S', e < 0 ? 70 : 150);

#if ENABLED(PID_DEBUG)
bool d = parser.boolval('D');
if (d) {
PID_Debug_Flag = !PID_Debug_Flag;
SERIAL_ECHOPGM("PID Debug set to: ");
SERIAL_ECHOLN( PID_Debug_Flag );
return;
}
#endif

#if DISABLED(BUSY_WHILE_HEATING)
KEEPALIVE_STATE(NOT_BUSY);
#endif
Expand Down
18 changes: 6 additions & 12 deletions Marlin/src/module/temperature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,9 @@ void Temperature::min_temp_error(const heater_ind_t heater) {
}

#if HOTENDS
#if ENABLED(PID_DEBUG)
extern bool PID_Debug_Flag;
#endif

float Temperature::get_pid_output_hotend(const uint8_t E_NAME) {
const uint8_t ee = HOTEND_INDEX;
Expand Down Expand Up @@ -911,24 +914,15 @@ void Temperature::min_temp_error(const heater_ind_t heater) {
#endif // PID_OPENLOOP

#if ENABLED(PID_DEBUG)
if (ee == active_extruder) {
if (ee == active_extruder && PID_Debug_Flag) {
SERIAL_ECHO_START();
SERIAL_ECHOPAIR(
STR_PID_DEBUG, ee,
STR_PID_DEBUG_INPUT, temp_hotend[ee].celsius,
STR_PID_DEBUG_OUTPUT, pid_output
);
SERIAL_ECHOPAIR(STR_PID_DEBUG, ee, STR_PID_DEBUG_INPUT, temp_hotend[ee].celsius, STR_PID_DEBUG_OUTPUT, pid_output);
#if DISABLED(PID_OPENLOOP)
{
SERIAL_ECHOPAIR(
STR_PID_DEBUG_PTERM, work_pid[ee].Kp,
STR_PID_DEBUG_ITERM, work_pid[ee].Ki,
STR_PID_DEBUG_DTERM, work_pid[ee].Kd
SERIAL_ECHOPAIR( STR_PID_DEBUG_PTERM, work_pid[ee].Kp, STR_PID_DEBUG_ITERM, work_pid[ee].Ki, STR_PID_DEBUG_DTERM, work_pid[ee].Kd
#if ENABLED(PID_EXTRUSION_SCALING)
, STR_PID_DEBUG_CTERM, work_pid[ee].Kc
#endif
);
}
#endif
SERIAL_EOL();
}
Expand Down

0 comments on commit fd53090

Please sign in to comment.