[2.0.x] TMC driver update (#8769)

This commit is contained in:
teemuatlut
2017-12-15 23:03:14 +02:00
committed by Scott Lahteine
parent 09d13f186f
commit 0cd1e91056
62 changed files with 4185 additions and 2051 deletions

View File

@ -45,8 +45,8 @@
#endif
;
#if ENABLED(HAVE_TMC2130)
#include "../../feature/tmc2130.h"
#if HAS_TRINAMIC
#include "../../feature/tmc_util.h"
#endif
/**
@ -77,6 +77,11 @@
tmc2130_init(); // Settings only stick when the driver has power
#endif
#if ENABLED(HAVE_TMC2208)
delay(100);
tmc2208_init();
#endif
powersupply_on = true;
#if ENABLED(ULTIPANEL)

View File

@ -0,0 +1,342 @@
/**
* Marlin 3D Printer Firmware
* Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "../../../inc/MarlinConfig.h"
#if ENABLED(TMC_DEBUG)
#include "../../gcode.h"
#include "../../../feature/tmc_util.h"
#include "../../../module/stepper_indirection.h"
#include "../../../module/planner.h"
enum TMC_debug_enum {
TMC_CODES,
TMC_ENABLED,
TMC_CURRENT,
TMC_RMS_CURRENT,
TMC_MAX_CURRENT,
TMC_IRUN,
TMC_IHOLD,
TMC_CS_ACTUAL,
TMC_PWM_SCALE,
TMC_VSENSE,
TMC_STEALTHCHOP,
TMC_MICROSTEPS,
TMC_TSTEP,
TMC_TPWMTHRS,
TMC_TPWMTHRS_MMS,
TMC_OTPW,
TMC_OTPW_TRIGGERED,
TMC_TOFF,
TMC_TBL,
TMC_HEND,
TMC_HSTRT,
TMC_SGT
};
enum TMC_drv_status_enum {
TMC_DRV_CODES,
TMC_STST,
TMC_OLB,
TMC_OLA,
TMC_S2GB,
TMC_S2GA,
TMC_DRV_OTPW,
TMC_OT,
TMC_STALLGUARD,
TMC_DRV_CS_ACTUAL,
TMC_FSACTIVE,
TMC_SG_RESULT,
TMC_DRV_STATUS_HEX,
TMC_T157,
TMC_T150,
TMC_T143,
TMC_T120,
TMC_STEALTH,
TMC_S2VSB,
TMC_S2VSA
};
static void drv_status_print_hex(const char name[], const uint32_t drv_status) {
SERIAL_ECHO(name);
SERIAL_ECHOPGM(" = 0x");
for(int B=24; B>=8; B-=8){
MYSERIAL.print((drv_status>>(B+4))&0xF, HEX);
MYSERIAL.print((drv_status>>B)&0xF, HEX);
MYSERIAL.print(':');
}
MYSERIAL.print((drv_status>>4)&0xF, HEX);
MYSERIAL.print((drv_status)&0xF, HEX);
SERIAL_EOL();
}
#if ENABLED(HAVE_TMC2130)
static void tmc_status(TMC2130Stepper &st, const TMC_debug_enum i) {
switch(i) {
case TMC_PWM_SCALE: MYSERIAL.print(st.PWM_SCALE(), DEC); break;
case TMC_TSTEP: SERIAL_ECHO(st.TSTEP()); break;
case TMC_SGT: MYSERIAL.print(st.sgt(), DEC); break;
case TMC_STEALTHCHOP: serialprintPGM(st.stealthChop() ? PSTR("true") : PSTR("false")); break;
default: break;
}
}
static void tmc_parse_drv_status(TMC2130Stepper &st, const TMC_drv_status_enum i) {
switch(i) {
case TMC_STALLGUARD: if (st.stallguard()) SERIAL_ECHOPGM("X"); break;
case TMC_SG_RESULT: MYSERIAL.print(st.sg_result(), DEC); break;
case TMC_FSACTIVE: if (st.fsactive()) SERIAL_ECHOPGM("X"); break;
default: break;
}
}
#endif
#if ENABLED(HAVE_TMC2208)
static void tmc_status(TMC2208Stepper &st, const TMC_debug_enum i) {
switch(i) {
case TMC_TSTEP:
{
uint32_t data = 0;
st.TSTEP(&data);
MYSERIAL.print(data);
break;
}
case TMC_PWM_SCALE: MYSERIAL.print(st.pwm_scale_sum(), DEC); break;
case TMC_STEALTHCHOP: serialprintPGM(st.stealth() ? PSTR("true") : PSTR("false")); break;
case TMC_S2VSA: if (st.s2vsa()) SERIAL_ECHOPGM("X"); break;
case TMC_S2VSB: if (st.s2vsb()) SERIAL_ECHOPGM("X"); break;
default: break;
}
}
static void tmc_parse_drv_status(TMC2208Stepper &st, const TMC_drv_status_enum i) {
switch(i) {
case TMC_T157: if (st.t157()) SERIAL_ECHOPGM("X"); break;
case TMC_T150: if (st.t150()) SERIAL_ECHOPGM("X"); break;
case TMC_T143: if (st.t143()) SERIAL_ECHOPGM("X"); break;
case TMC_T120: if (st.t120()) SERIAL_ECHOPGM("X"); break;
default: break;
}
}
#endif
template <typename TMC>
static void tmc_status(TMC &st, TMC_AxisEnum axis, const TMC_debug_enum i, const float spmm) {
SERIAL_ECHO('\t');
switch(i) {
case TMC_CODES: SERIAL_ECHO(extended_axis_codes[axis]); break;
case TMC_ENABLED: serialprintPGM(st.isEnabled() ? PSTR("true") : PSTR("false")); break;
case TMC_CURRENT: SERIAL_ECHO(st.getCurrent()); break;
case TMC_RMS_CURRENT: MYSERIAL.print(st.rms_current()); break;
case TMC_MAX_CURRENT: MYSERIAL.print((float)st.rms_current()*1.41, 0); break;
case TMC_IRUN:
MYSERIAL.print(st.irun(), DEC);
SERIAL_ECHOPGM("/31");
break;
case TMC_IHOLD:
MYSERIAL.print(st.ihold(), DEC);
SERIAL_ECHOPGM("/31");
break;
case TMC_CS_ACTUAL:
MYSERIAL.print(st.cs_actual(), DEC);
SERIAL_ECHOPGM("/31");
break;
case TMC_VSENSE: serialprintPGM(st.vsense() ? PSTR("1=.18") : PSTR("0=.325")); break;
case TMC_MICROSTEPS: SERIAL_ECHO(st.microsteps()); break;
case TMC_TPWMTHRS:
{
uint32_t tpwmthrs_val = st.TPWMTHRS();
SERIAL_ECHO(tpwmthrs_val);
}
break;
case TMC_TPWMTHRS_MMS:
{
uint32_t tpwmthrs_val = st.TPWMTHRS();
tpwmthrs_val ? SERIAL_ECHO(12650000UL * st.microsteps() / (256 * tpwmthrs_val * spmm)) : SERIAL_ECHO('-');
}
break;
case TMC_OTPW: serialprintPGM(st.otpw() ? PSTR("true") : PSTR("false")); break;
case TMC_OTPW_TRIGGERED: serialprintPGM(st.getOTPW() ? PSTR("true") : PSTR("false")); break;
case TMC_TOFF: MYSERIAL.print(st.toff(), DEC); break;
case TMC_TBL: MYSERIAL.print(st.blank_time(), DEC); break;
case TMC_HEND: MYSERIAL.print(st.hysterisis_end(), DEC); break;
case TMC_HSTRT: MYSERIAL.print(st.hysterisis_start(), DEC); break;
default: tmc_status(st, i); break;
}
}
template <typename TMC>
static void tmc_parse_drv_status(TMC &st, TMC_AxisEnum axis, const TMC_drv_status_enum i) {
SERIAL_ECHOPGM("\t");
switch(i) {
case TMC_DRV_CODES: SERIAL_ECHO(extended_axis_codes[axis]); break;
case TMC_STST: if (st.stst()) SERIAL_ECHOPGM("X"); break;
case TMC_OLB: if (st.olb()) SERIAL_ECHOPGM("X"); break;
case TMC_OLA: if (st.ola()) SERIAL_ECHOPGM("X"); break;
case TMC_S2GB: if (st.s2gb()) SERIAL_ECHOPGM("X"); break;
case TMC_S2GA: if (st.s2ga()) SERIAL_ECHOPGM("X"); break;
case TMC_DRV_OTPW: if (st.otpw()) SERIAL_ECHOPGM("X"); break;
case TMC_OT: if (st.ot()) SERIAL_ECHOPGM("X"); break;
case TMC_DRV_CS_ACTUAL: MYSERIAL.print(st.cs_actual(), DEC); break;
case TMC_DRV_STATUS_HEX:drv_status_print_hex(extended_axis_codes[axis], st.DRV_STATUS()); break;
default: tmc_parse_drv_status(st, i); break;
}
}
static void tmc_debug_loop(const TMC_debug_enum i) {
#if X_IS_TRINAMIC
tmc_status(stepperX, TMC_X, i, planner.axis_steps_per_mm[X_AXIS]);
#endif
#if X2_IS_TRINAMIC
tmc_status(stepperX2, TMC_X2, i, planner.axis_steps_per_mm[X_AXIS]);
#endif
#if Y_IS_TRINAMIC
tmc_status(stepperY, TMC_Y, i, planner.axis_steps_per_mm[Y_AXIS]);
#endif
#if Y2_IS_TRINAMIC
tmc_status(stepperY2, TMC_Y2, i, planner.axis_steps_per_mm[Y_AXIS]);
#endif
#if Z_IS_TRINAMIC
tmc_status(stepperZ, TMC_Z, i, planner.axis_steps_per_mm[Z_AXIS]);
#endif
#if Z2_IS_TRINAMIC
tmc_status(stepperZ2, TMC_Z2, i, planner.axis_steps_per_mm[Z_AXIS]);
#endif
#if E0_IS_TRINAMIC
tmc_status(stepperE0, TMC_E0, i, planner.axis_steps_per_mm[E_AXIS]);
#endif
#if E1_IS_TRINAMIC
tmc_status(stepperE1, TMC_E1, i, planner.axis_steps_per_mm[E_AXIS+1]);
#endif
#if E2_IS_TRINAMIC
tmc_status(stepperE2, TMC_E2, i, planner.axis_steps_per_mm[E_AXIS+2]);
#endif
#if E3_IS_TRINAMIC
tmc_status(stepperE3, TMC_E3, i, planner.axis_steps_per_mm[E_AXIS+3]);
#endif
#if E4_IS_TRINAMIC
tmc_status(stepperE4, TMC_E4, i, planner.axis_steps_per_mm[E_AXIS+4]);
#endif
SERIAL_EOL();
}
static void drv_status_loop(const TMC_drv_status_enum i) {
#if X_IS_TRINAMIC
tmc_parse_drv_status(stepperX, TMC_X, i);
#endif
#if X2_IS_TRINAMIC
tmc_parse_drv_status(stepperX2, TMC_X2, i);
#endif
#if Y_IS_TRINAMIC
tmc_parse_drv_status(stepperY, TMC_Y, i);
#endif
#if Y2_IS_TRINAMIC
tmc_parse_drv_status(stepperY2, TMC_Y2, i);
#endif
#if Z_IS_TRINAMIC
tmc_parse_drv_status(stepperZ, TMC_Z, i);
#endif
#if Z2_IS_TRINAMIC
tmc_parse_drv_status(stepperZ2, TMC_Z2, i);
#endif
#if E0_IS_TRINAMIC
tmc_parse_drv_status(stepperE0, TMC_E0, i);
#endif
#if E1_IS_TRINAMIC
tmc_parse_drv_status(stepperE1, TMC_E1, i);
#endif
#if E2_IS_TRINAMIC
tmc_parse_drv_status(stepperE2, TMC_E2, i);
#endif
#if E3_IS_TRINAMIC
tmc_parse_drv_status(stepperE3, TMC_E3, i);
#endif
#if E4_IS_TRINAMIC
tmc_parse_drv_status(stepperE4, TMC_E4, i);
#endif
SERIAL_EOL();
}
void _M122() {
if (parser.seen('S')) {
if (parser.value_bool()) {
SERIAL_ECHOLNPGM("axis:pwm_scale |status_response|");
report_tmc_status = true;
} else
report_tmc_status = false;
} else {
SERIAL_ECHOPGM("\t"); tmc_debug_loop(TMC_CODES);
SERIAL_ECHOPGM("Enabled\t"); tmc_debug_loop(TMC_ENABLED);
SERIAL_ECHOPGM("Set current"); tmc_debug_loop(TMC_CURRENT);
SERIAL_ECHOPGM("RMS current"); tmc_debug_loop(TMC_RMS_CURRENT);
SERIAL_ECHOPGM("MAX current"); tmc_debug_loop(TMC_MAX_CURRENT);
SERIAL_ECHOPGM("Run current"); tmc_debug_loop(TMC_IRUN);
SERIAL_ECHOPGM("Hold current"); tmc_debug_loop(TMC_IHOLD);
SERIAL_ECHOPGM("CS actual\t"); tmc_debug_loop(TMC_CS_ACTUAL);
SERIAL_ECHOPGM("PWM scale"); tmc_debug_loop(TMC_PWM_SCALE);
SERIAL_ECHOPGM("vsense\t"); tmc_debug_loop(TMC_VSENSE);
SERIAL_ECHOPGM("stealthChop"); tmc_debug_loop(TMC_STEALTHCHOP);
SERIAL_ECHOPGM("msteps\t"); tmc_debug_loop(TMC_MICROSTEPS);
SERIAL_ECHOPGM("tstep\t"); tmc_debug_loop(TMC_TSTEP);
SERIAL_ECHOPGM("pwm\nthreshold\t"); tmc_debug_loop(TMC_TPWMTHRS);
SERIAL_ECHOPGM("[mm/s]\t"); tmc_debug_loop(TMC_TPWMTHRS_MMS);
SERIAL_ECHOPGM("OT prewarn"); tmc_debug_loop(TMC_OTPW);
SERIAL_ECHOPGM("OT prewarn has\nbeen triggered"); tmc_debug_loop(TMC_OTPW_TRIGGERED);
SERIAL_ECHOPGM("off time\t"); tmc_debug_loop(TMC_TOFF);
SERIAL_ECHOPGM("blank time"); tmc_debug_loop(TMC_TBL);
SERIAL_ECHOPGM("hysterisis\n-end\t"); tmc_debug_loop(TMC_HEND);
SERIAL_ECHOPGM("-start\t"); tmc_debug_loop(TMC_HSTRT);
SERIAL_ECHOPGM("Stallguard thrs"); tmc_debug_loop(TMC_SGT);
SERIAL_ECHOPGM("DRVSTATUS"); drv_status_loop(TMC_DRV_CODES);
#if ENABLED(HAVE_TMC2130)
SERIAL_ECHOPGM("stallguard\t"); drv_status_loop(TMC_STALLGUARD);
SERIAL_ECHOPGM("sg_result\t"); drv_status_loop(TMC_SG_RESULT);
SERIAL_ECHOPGM("fsactive\t"); drv_status_loop(TMC_FSACTIVE);
#endif
SERIAL_ECHOPGM("stst\t"); drv_status_loop(TMC_STST);
SERIAL_ECHOPGM("olb\t"); drv_status_loop(TMC_OLB);
SERIAL_ECHOPGM("ola\t"); drv_status_loop(TMC_OLA);
SERIAL_ECHOPGM("s2gb\t"); drv_status_loop(TMC_S2GB);
SERIAL_ECHOPGM("s2ga\t"); drv_status_loop(TMC_S2GA);
SERIAL_ECHOPGM("otpw\t"); drv_status_loop(TMC_DRV_OTPW);
SERIAL_ECHOPGM("ot\t"); drv_status_loop(TMC_OT);
#if ENABLED(HAVE_TMC2208)
SERIAL_ECHOPGM("157C\t"); drv_status_loop(TMC_T157);
SERIAL_ECHOPGM("150C\t"); drv_status_loop(TMC_T150);
SERIAL_ECHOPGM("143C\t"); drv_status_loop(TMC_T143);
SERIAL_ECHOPGM("120C\t"); drv_status_loop(TMC_T120);
SERIAL_ECHOPGM("s2vsa\t"); drv_status_loop(TMC_S2VSA);
SERIAL_ECHOPGM("s2vsb\t"); drv_status_loop(TMC_S2VSB);
#endif
SERIAL_ECHOLNPGM("Driver registers:");drv_status_loop(TMC_DRV_STATUS_HEX);
}
}
// We need to call M122 from monitor_tmc_driver() as well but GcodeSuite::M122 is private.
inline void GcodeSuite::M122() { _M122(); }
#endif // TMC_DEBUG

View File

@ -22,54 +22,67 @@
#include "../../../inc/MarlinConfig.h"
#if ENABLED(HAVE_TMC2130)
#if HAS_TRINAMIC
#include "../../gcode.h"
#include "../../../feature/tmc2130.h"
#include "../../../feature/tmc_util.h"
#include "../../../module/stepper_indirection.h"
inline void tmc2130_get_current(TMC2130Stepper &st, const char name) {
SERIAL_CHAR(name);
SERIAL_ECHOPGM(" axis driver current: ");
SERIAL_ECHOLN(st.getCurrent());
}
inline void tmc2130_set_current(TMC2130Stepper &st, const char name, const int mA) {
st.setCurrent(mA, R_SENSE, HOLD_MULTIPLIER);
tmc2130_get_current(st, name);
}
#include "../../../module/planner.h"
/**
* M906: Set motor current in milliamps using axis codes X, Y, Z, E
* Report driver currents when no axis specified
*
* S1: Enable automatic current control
* S0: Disable
*/
void GcodeSuite::M906() {
inline void GcodeSuite::M906() {
uint16_t values[XYZE];
LOOP_XYZE(i)
values[i] = parser.intval(axis_codes[i]);
#if ENABLED(X_IS_TMC2130)
if (values[X_AXIS]) tmc2130_set_current(stepperX, 'X', values[X_AXIS]);
else tmc2130_get_current(stepperX, 'X');
#if X_IS_TRINAMIC
if (values[X_AXIS]) tmc_set_current(stepperX, extended_axis_codes[TMC_X], values[X_AXIS]);
else tmc_get_current(stepperX, extended_axis_codes[TMC_X]);
#endif
#if ENABLED(Y_IS_TMC2130)
if (values[Y_AXIS]) tmc2130_set_current(stepperY, 'Y', values[Y_AXIS]);
else tmc2130_get_current(stepperY, 'Y');
#if X2_IS_TRINAMIC
if (values[X_AXIS]) tmc_set_current(stepperX2, extended_axis_codes[TMC_X2], values[X_AXIS]);
else tmc_get_current(stepperX2, extended_axis_codes[TMC_X2]);
#endif
#if ENABLED(Z_IS_TMC2130)
if (values[Z_AXIS]) tmc2130_set_current(stepperZ, 'Z', values[Z_AXIS]);
else tmc2130_get_current(stepperZ, 'Z');
#if Y_IS_TRINAMIC
if (values[Y_AXIS]) tmc_set_current(stepperY, extended_axis_codes[TMC_Y], values[Y_AXIS]);
else tmc_get_current(stepperY, extended_axis_codes[TMC_Y]);
#endif
#if ENABLED(E0_IS_TMC2130)
if (values[E_AXIS]) tmc2130_set_current(stepperE0, 'E', values[E_AXIS]);
else tmc2130_get_current(stepperE0, 'E');
#if Y2_IS_TRINAMIC
if (values[Y_AXIS]) tmc_set_current(stepperY2, extended_axis_codes[TMC_Y2], values[Y_AXIS]);
else tmc_get_current(stepperY2, extended_axis_codes[TMC_Y2]);
#endif
#if Z_IS_TRINAMIC
if (values[Z_AXIS]) tmc_set_current(stepperZ, extended_axis_codes[TMC_Z], values[Z_AXIS]);
else tmc_get_current(stepperZ, extended_axis_codes[TMC_Z]);
#endif
#if Z2_IS_TRINAMIC
if (values[Z_AXIS]) tmc_set_current(stepperZ2, extended_axis_codes[TMC_Z2], values[Z_AXIS]);
else tmc_get_current(stepperZ2, extended_axis_codes[TMC_Z2]);
#endif
#if E0_IS_TRINAMIC
if (values[E_AXIS]) tmc_set_current(stepperE0, extended_axis_codes[TMC_E0], values[E_AXIS]);
else tmc_get_current(stepperE0, extended_axis_codes[TMC_E0]);
#endif
#if E1_IS_TRINAMIC
if (values[E_AXIS]) tmc_set_current(stepperE1, extended_axis_codes[TMC_E1], values[E_AXIS]);
else tmc_get_current(stepperE1, extended_axis_codes[TMC_E1]);
#endif
#if E2_IS_TRINAMIC
if (values[E_AXIS]) tmc_set_current(stepperE2, extended_axis_codes[TMC_E2], values[E_AXIS]);
else tmc_get_current(stepperE2, extended_axis_codes[TMC_E2]);
#endif
#if E3_IS_TRINAMIC
if (values[E_AXIS]) tmc_set_current(stepperE3, extended_axis_codes[TMC_E3], values[E_AXIS]);
else tmc_get_current(stepperE3, extended_axis_codes[TMC_E3]);
#endif
#if E4_IS_TRINAMIC
if (values[E_AXIS]) tmc_set_current(stepperE4, extended_axis_codes[TMC_E4], values[E_AXIS]);
else tmc_get_current(stepperE4, extended_axis_codes[TMC_E4]);
#endif
#if ENABLED(AUTOMATIC_CURRENT_CONTROL)
if (parser.seen('S')) auto_current_control = parser.value_bool();
#endif
}
#endif // HAVE_TMC2130
#endif // HAS_TRINAMIC

View File

@ -1,155 +0,0 @@
/**
* Marlin 3D Printer Firmware
* Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "../../../inc/MarlinConfig.h"
#if ENABLED(HAVE_TMC2130)
#include "../../gcode.h"
#include "../../../feature/tmc2130.h"
#include "../../../module/stepper_indirection.h"
inline void tmc2130_report_otpw(TMC2130Stepper &st, const char name) {
SERIAL_CHAR(name);
SERIAL_ECHOPGM(" axis temperature prewarn triggered: ");
serialprintPGM(st.getOTPW() ? PSTR("true") : PSTR("false"));
SERIAL_EOL();
}
/**
* M911: Report TMC2130 stepper driver overtemperature pre-warn flag
* The flag is held by the library and persist until manually cleared by M912
*/
void GcodeSuite::M911() {
const bool reportX = parser.seen('X'), reportY = parser.seen('Y'), reportZ = parser.seen('Z'), reportE = parser.seen('E'),
reportAll = (!reportX && !reportY && !reportZ && !reportE) || (reportX && reportY && reportZ && reportE);
#if ENABLED(X_IS_TMC2130)
if (reportX || reportAll) tmc2130_report_otpw(stepperX, 'X');
#endif
#if ENABLED(Y_IS_TMC2130)
if (reportY || reportAll) tmc2130_report_otpw(stepperY, 'Y');
#endif
#if ENABLED(Z_IS_TMC2130)
if (reportZ || reportAll) tmc2130_report_otpw(stepperZ, 'Z');
#endif
#if ENABLED(E0_IS_TMC2130)
if (reportE || reportAll) tmc2130_report_otpw(stepperE0, 'E');
#endif
}
inline void tmc2130_clear_otpw(TMC2130Stepper &st, const char name) {
st.clear_otpw();
SERIAL_CHAR(name);
SERIAL_ECHOLNPGM(" prewarn flag cleared");
}
/**
* M912: Clear TMC2130 stepper driver overtemperature pre-warn flag held by the library
*/
void GcodeSuite::M912() {
const bool clearX = parser.seen('X'), clearY = parser.seen('Y'), clearZ = parser.seen('Z'), clearE = parser.seen('E'),
clearAll = (!clearX && !clearY && !clearZ && !clearE) || (clearX && clearY && clearZ && clearE);
#if ENABLED(X_IS_TMC2130)
if (clearX || clearAll) tmc2130_clear_otpw(stepperX, 'X');
#endif
#if ENABLED(Y_IS_TMC2130)
if (clearY || clearAll) tmc2130_clear_otpw(stepperY, 'Y');
#endif
#if ENABLED(Z_IS_TMC2130)
if (clearZ || clearAll) tmc2130_clear_otpw(stepperZ, 'Z');
#endif
#if ENABLED(E0_IS_TMC2130)
if (clearE || clearAll) tmc2130_clear_otpw(stepperE0, 'E');
#endif
}
#if ENABLED(HYBRID_THRESHOLD)
#include "../../../module/planner.h"
inline void tmc2130_get_pwmthrs(TMC2130Stepper &st, const char name, const uint16_t spmm) {
SERIAL_CHAR(name);
SERIAL_ECHOPGM(" stealthChop max speed set to ");
SERIAL_ECHOLN(12650000UL * st.microsteps() / (256 * st.stealth_max_speed() * spmm));
}
inline void tmc2130_set_pwmthrs(TMC2130Stepper &st, const char name, const int32_t thrs, const uint32_t spmm) {
st.stealth_max_speed(12650000UL * st.microsteps() / (256 * thrs * spmm));
tmc2130_get_pwmthrs(st, name, spmm);
}
/**
* M913: Set HYBRID_THRESHOLD speed.
*/
void GcodeSuite::M913() {
uint16_t values[XYZE];
LOOP_XYZE(i)
values[i] = parser.intval(axis_codes[i]);
#if ENABLED(X_IS_TMC2130)
if (values[X_AXIS]) tmc2130_set_pwmthrs(stepperX, 'X', values[X_AXIS], planner.axis_steps_per_mm[X_AXIS]);
else tmc2130_get_pwmthrs(stepperX, 'X', planner.axis_steps_per_mm[X_AXIS]);
#endif
#if ENABLED(Y_IS_TMC2130)
if (values[Y_AXIS]) tmc2130_set_pwmthrs(stepperY, 'Y', values[Y_AXIS], planner.axis_steps_per_mm[Y_AXIS]);
else tmc2130_get_pwmthrs(stepperY, 'Y', planner.axis_steps_per_mm[Y_AXIS]);
#endif
#if ENABLED(Z_IS_TMC2130)
if (values[Z_AXIS]) tmc2130_set_pwmthrs(stepperZ, 'Z', values[Z_AXIS], planner.axis_steps_per_mm[Z_AXIS]);
else tmc2130_get_pwmthrs(stepperZ, 'Z', planner.axis_steps_per_mm[Z_AXIS]);
#endif
#if ENABLED(E0_IS_TMC2130)
if (values[E_AXIS]) tmc2130_set_pwmthrs(stepperE0, 'E', values[E_AXIS], planner.axis_steps_per_mm[E_AXIS]);
else tmc2130_get_pwmthrs(stepperE0, 'E', planner.axis_steps_per_mm[E_AXIS]);
#endif
}
#endif // HYBRID_THRESHOLD
#if ENABLED(SENSORLESS_HOMING)
inline void tmc2130_get_sgt(TMC2130Stepper &st, const char name) {
SERIAL_CHAR(name);
SERIAL_ECHOPGM(" driver homing sensitivity set to ");
SERIAL_ECHOLN(st.sgt());
}
inline void tmc2130_set_sgt(TMC2130Stepper &st, const char name, const int8_t sgt_val) {
st.sgt(sgt_val);
tmc2130_get_sgt(st, name);
}
/**
* M914: Set SENSORLESS_HOMING sensitivity.
*/
void GcodeSuite::M914() {
#if ENABLED(X_IS_TMC2130)
if (parser.seen(axis_codes[X_AXIS])) tmc2130_set_sgt(stepperX, 'X', parser.value_int());
else tmc2130_get_sgt(stepperX, 'X');
#endif
#if ENABLED(Y_IS_TMC2130)
if (parser.seen(axis_codes[Y_AXIS])) tmc2130_set_sgt(stepperY, 'Y', parser.value_int());
else tmc2130_get_sgt(stepperY, 'Y');
#endif
}
#endif // SENSORLESS_HOMING
#endif // HAVE_TMC2130

View File

@ -0,0 +1,195 @@
/**
* Marlin 3D Printer Firmware
* Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "../../../inc/MarlinConfig.h"
#if HAS_TRINAMIC
#include "../../gcode.h"
#include "../../../feature/tmc_util.h"
#include "../../../module/stepper_indirection.h"
#include "../../../module/planner.h"
/**
* M911: Report TMC stepper driver overtemperature pre-warn flag
* The flag is held by the library and persist until manually cleared by M912
*/
inline void GcodeSuite::M911() {
#if ENABLED(X_IS_TMC2130) || (ENABLED(X_IS_TMC2208) && PIN_EXISTS(X_SERIAL_RX)) || ENABLED(IS_TRAMS)
tmc_report_otpw(stepperX, extended_axis_codes[TMC_X]);
#endif
#if ENABLED(Y_IS_TMC2130) || (ENABLED(Y_IS_TMC2208) && PIN_EXISTS(Y_SERIAL_RX)) || ENABLED(IS_TRAMS)
tmc_report_otpw(stepperY, extended_axis_codes[TMC_Y]);
#endif
#if ENABLED(Z_IS_TMC2130) || (ENABLED(Z_IS_TMC2208) && PIN_EXISTS(Z_SERIAL_RX)) || ENABLED(IS_TRAMS)
tmc_report_otpw(stepperZ, extended_axis_codes[TMC_Z]);
#endif
#if ENABLED(E0_IS_TMC2130) || (ENABLED(E0_IS_TMC2208) && PIN_EXISTS(E0_SERIAL_RX)) || ENABLED(IS_TRAMS)
tmc_report_otpw(stepperE0, extended_axis_codes[TMC_E0]);
#endif
}
/**
* M912: Clear TMC stepper driver overtemperature pre-warn flag held by the library
*/
inline void GcodeSuite::M912() {
const bool clearX = parser.seen(axis_codes[X_AXIS]), clearY = parser.seen(axis_codes[Y_AXIS]), clearZ = parser.seen(axis_codes[Z_AXIS]), clearE = parser.seen(axis_codes[E_AXIS]),
clearAll = (!clearX && !clearY && !clearZ && !clearE) || (clearX && clearY && clearZ && clearE);
#if ENABLED(X_IS_TMC2130) || ENABLED(IS_TRAMS) || (ENABLED(X_IS_TMC2208) && PIN_EXISTS(X_SERIAL_RX))
if (clearX || clearAll) tmc_clear_otpw(stepperX, extended_axis_codes[TMC_X]);
#endif
#if ENABLED(X2_IS_TMC2130) || (ENABLED(X2_IS_TMC2208) && PIN_EXISTS(X_SERIAL_RX))
if (clearX || clearAll) tmc_clear_otpw(stepperX, extended_axis_codes[TMC_X]);
#endif
#if ENABLED(Y_IS_TMC2130) || (ENABLED(Y_IS_TMC2208) && PIN_EXISTS(Y_SERIAL_RX))
if (clearY || clearAll) tmc_clear_otpw(stepperY, extended_axis_codes[TMC_Y]);
#endif
#if ENABLED(Z_IS_TMC2130) || (ENABLED(Z_IS_TMC2208) && PIN_EXISTS(Z_SERIAL_RX))
if (clearZ || clearAll) tmc_clear_otpw(stepperZ, extended_axis_codes[TMC_Z]);
#endif
#if ENABLED(E0_IS_TMC2130) || (ENABLED(E0_IS_TMC2208) && PIN_EXISTS(E0_SERIAL_RX))
if (clearE || clearAll) tmc_clear_otpw(stepperE0, extended_axis_codes[TMC_E0]);
#endif
}
/**
* M913: Set HYBRID_THRESHOLD speed.
*/
#if ENABLED(HYBRID_THRESHOLD)
inline void GcodeSuite::M913() {
uint16_t values[XYZE];
LOOP_XYZE(i)
values[i] = parser.intval(axis_codes[i]);
#if X_IS_TRINAMIC
if (values[X_AXIS]) tmc_set_pwmthrs(stepperX, extended_axis_codes[TMC_X], values[X_AXIS], planner.axis_steps_per_mm[X_AXIS]);
else tmc_get_pwmthrs(stepperX, extended_axis_codes[TMC_X], planner.axis_steps_per_mm[X_AXIS]);
#endif
#if X2_IS_TRINAMIC
if (values[X_AXIS]) tmc_set_pwmthrs(stepperX2, extended_axis_codes[TMC_X2], values[X_AXIS], planner.axis_steps_per_mm[X_AXIS]);
else tmc_get_pwmthrs(stepperX, extended_axis_codes[TMC_X2], planner.axis_steps_per_mm[X_AXIS]);
#endif
#if Y_IS_TRINAMIC
if (values[Y_AXIS]) tmc_set_pwmthrs(stepperY, extended_axis_codes[TMC_Y], values[Y_AXIS], planner.axis_steps_per_mm[Y_AXIS]);
else tmc_get_pwmthrs(stepperY, extended_axis_codes[TMC_Y], planner.axis_steps_per_mm[Y_AXIS]);
#endif
#if Y2_IS_TRINAMIC
if (values[Y_AXIS]) tmc_set_pwmthrs(stepperY2, extended_axis_codes[TMC_Y2], values[Y_AXIS], planner.axis_steps_per_mm[Y_AXIS]);
else tmc_get_pwmthrs(stepperY, extended_axis_codes[TMC_Y2], planner.axis_steps_per_mm[Y_AXIS]);
#endif
#if Z_IS_TRINAMIC
if (values[Z_AXIS]) tmc_set_pwmthrs(stepperZ, extended_axis_codes[TMC_Z], values[Z_AXIS], planner.axis_steps_per_mm[Z_AXIS]);
else tmc_get_pwmthrs(stepperZ, extended_axis_codes[TMC_Z], planner.axis_steps_per_mm[Z_AXIS]);
#endif
#if Z2_IS_TRINAMIC
if (values[Z_AXIS]) tmc_set_pwmthrs(stepperZ2, extended_axis_codes[TMC_Z2], values[Z_AXIS], planner.axis_steps_per_mm[Z_AXIS]);
else tmc_get_pwmthrs(stepperZ, extended_axis_codes[TMC_Z2], planner.axis_steps_per_mm[Z_AXIS]);
#endif
#if E0_IS_TRINAMIC
if (values[E_AXIS]) tmc_set_pwmthrs(stepperE0, extended_axis_codes[TMC_E0], values[E_AXIS], planner.axis_steps_per_mm[E_AXIS]);
else tmc_get_pwmthrs(stepperE0, extended_axis_codes[TMC_E0], planner.axis_steps_per_mm[E_AXIS]);
#endif
#if E1_IS_TRINAMIC
if (values[E_AXIS]) tmc_set_pwmthrs(stepperE1, extended_axis_codes[TMC_E1], values[E_AXIS], planner.axis_steps_per_mm[E_AXIS]);
else tmc_get_pwmthrs(stepperE1, extended_axis_codes[TMC_E1], planner.axis_steps_per_mm[E_AXIS]);
#endif
#if E2_IS_TRINAMIC
if (values[E_AXIS]) tmc_set_pwmthrs(stepperE2, extended_axis_codes[TMC_E2], values[E_AXIS], planner.axis_steps_per_mm[E_AXIS]);
else tmc_get_pwmthrs(stepperE2, extended_axis_codes[TMC_E2], planner.axis_steps_per_mm[E_AXIS]);
#endif
#if E3_IS_TRINAMIC
if (values[E_AXIS]) tmc_set_pwmthrs(stepperE3, extended_axis_codes[TMC_E3], values[E_AXIS], planner.axis_steps_per_mm[E_AXIS]);
else tmc_get_pwmthrs(stepperE3, extended_axis_codes[TMC_E3], planner.axis_steps_per_mm[E_AXIS]);
#endif
#if E4_IS_TRINAMIC
if (values[E_AXIS]) tmc_set_pwmthrs(stepperE4, extended_axis_codes[TMC_E4], values[E_AXIS], planner.axis_steps_per_mm[E_AXIS]);
else tmc_get_pwmthrs(stepperE4, extended_axis_codes[TMC_E4], planner.axis_steps_per_mm[E_AXIS]);
#endif
}
#endif // HYBRID_THRESHOLD
/**
* M914: Set SENSORLESS_HOMING sensitivity.
*/
#if ENABLED(SENSORLESS_HOMING)
inline void GcodeSuite::M914() {
#if ENABLED(X_IS_TMC2130) || ENABLED(IS_TRAMS)
if (parser.seen(axis_codes[X_AXIS])) tmc_set_sgt(stepperX, extended_axis_codes[TMC_X], parser.value_int());
else tmc_get_sgt(stepperX, extended_axis_codes[TMC_X]);
#endif
#if ENABLED(X2_IS_TMC2130)
if (parser.seen(axis_codes[X_AXIS])) tmc_set_sgt(stepperX2, extended_axis_codes[TMC_X2], parser.value_int());
else tmc_get_sgt(stepperX2, extended_axis_codes[TMC_X2]);
#endif
#if ENABLED(Y_IS_TMC2130) || ENABLED(IS_TRAMS)
if (parser.seen(axis_codes[Y_AXIS])) tmc_set_sgt(stepperY, extended_axis_codes[TMC_Y], parser.value_int());
else tmc_get_sgt(stepperY, extended_axis_codes[TMC_Y]);
#endif
#if ENABLED(Y2_IS_TMC2130)
if (parser.seen(axis_codes[Y_AXIS])) tmc_set_sgt(stepperY2, extended_axis_codes[TMC_Y2], parser.value_int());
else tmc_get_sgt(stepperY2, extended_axis_codes[TMC_Y2]);
#endif
}
#endif // SENSORLESS_HOMING
/**
* TMC Z axis calibration routine
*/
#if ENABLED(TMC_Z_CALIBRATION) && (Z_IS_TRINAMIC || Z2_IS_TRINAMIC)
inline void GcodeSuite::M915() {
uint16_t _rms = parser.seenval('S') ? parser.value_int() : CALIBRATION_CURRENT;
uint16_t _z = parser.seenval('Z') ? parser.value_int() : CALIBRATION_EXTRA_HEIGHT;
if (!axis_known_position[Z_AXIS]) {
SERIAL_ECHOLNPGM("\nPlease home Z axis first");
return;
}
uint16_t Z_current_1 = stepperZ.getCurrent();
uint16_t Z2_current_1 = stepperZ.getCurrent();
stepperZ.setCurrent(_rms, R_SENSE, HOLD_MULTIPLIER);
stepperZ2.setCurrent(_rms, R_SENSE, HOLD_MULTIPLIER);
SERIAL_ECHOPAIR("\nCalibration current: Z", _rms);
soft_endstops_enabled = false;
do_blocking_move_to_z(Z_MAX_POS+_z);
stepperZ.setCurrent(Z_current_1, R_SENSE, HOLD_MULTIPLIER);
stepperZ2.setCurrent(Z2_current_1, R_SENSE, HOLD_MULTIPLIER);
do_blocking_move_to_z(Z_MAX_POS);
soft_endstops_enabled = true;
SERIAL_ECHOLNPGM("\nHoming Z because we lost steps");
home_z_safely();
}
#endif
#endif // HAS_TRINAMIC

View File

@ -657,7 +657,8 @@ void GcodeSuite::process_parsed_command() {
#endif
#endif
#if ENABLED(HAVE_TMC2130)
#if HAVE_TRINAMIC
case 122: M122(); break;
case 906: M906(); break; // M906: Set motor current in milliamps using axis codes X, Y, Z, E
case 911: M911(); break; // M911: Report TMC2130 prewarn triggered flags
case 912: M912(); break; // M912: Clear TMC2130 prewarn triggered flags

View File

@ -130,6 +130,7 @@
* M119 - Report endstops status.
* M120 - Enable endstops detection.
* M121 - Disable endstops detection.
* M122 - Debug stepper (Requires HAVE_TMC2130 or HAVE_TMC2208)
* M125 - Save current position and move to filament change position. (Requires PARK_HEAD_ON_PAUSE)
* M126 - Solenoid Air Valve Open. (Requires BARICUDA)
* M127 - Solenoid Air Valve Closed. (Requires BARICUDA)
@ -218,8 +219,8 @@
* M908 - Control digital trimpot directly. (Requires DAC_STEPPER_CURRENT or DIGIPOTSS_PIN)
* M909 - Print digipot/DAC current value. (Requires DAC_STEPPER_CURRENT)
* M910 - Commit digipot/DAC value to external EEPROM via I2C. (Requires DAC_STEPPER_CURRENT)
* M911 - Report stepper driver overtemperature pre-warn condition. (Requires HAVE_TMC2130)
* M912 - Clear stepper driver overtemperature pre-warn condition flag. (Requires HAVE_TMC2130)
* M911 - Report stepper driver overtemperature pre-warn condition. (Requires HAVE_TMC2130 or HAVE_TMC2208)
* M912 - Clear stepper driver overtemperature pre-warn condition flag. (Requires HAVE_TMC2130 or HAVE_TMC2208)
* M913 - Set HYBRID_THRESHOLD speed. (Requires HYBRID_THRESHOLD)
* M914 - Set SENSORLESS_HOMING sensitivity. (Requires SENSORLESS_HOMING)
*
@ -727,7 +728,10 @@ private:
static void M900();
#endif
#if ENABLED(HAVE_TMC2130)
#if HAS_TRINAMIC
#if ENABLED(TMC_DEBUG)
static void M122();
#endif
static void M906();
static void M911();
static void M912();
@ -737,6 +741,9 @@ private:
#if ENABLED(SENSORLESS_HOMING)
static void M914();
#endif
#if ENABLED(TMC_Z_CALIBRATION)
static void M915();
#endif
#endif
#if HAS_DIGIPOTSS || HAS_MOTOR_CURRENT_PWM || ENABLED(DIGIPOT_I2C) || ENABLED(DAC_STEPPER_CURRENT)