Fix TMC gcode commands

This commit is contained in:
teemuatlut 2017-12-29 21:38:08 +02:00
parent 99516572b1
commit 9d923c6c03
7 changed files with 76 additions and 75 deletions

View file

@ -35,56 +35,6 @@
bool report_tmc_status = false;
char extended_axis_codes[11][3] = { "X", "X2", "Y", "Y2", "Z", "Z2", "E0", "E1", "E2", "E3", "E4" };
template<typename TMC>
void tmc_get_current(TMC &st, const char name[]) {
SERIAL_ECHO(name);
SERIAL_ECHOPGM(" axis driver current: ");
SERIAL_ECHOLN(st.getCurrent());
}
template<typename TMC>
void tmc_set_current(TMC &st, const char name[], const int mA) {
st.setCurrent(mA, R_SENSE, HOLD_MULTIPLIER);
tmc_get_current(st, name);
}
template<typename TMC>
void tmc_report_otpw(TMC &st, const char name[]) {
SERIAL_ECHO(name);
SERIAL_ECHOPGM(" axis temperature prewarn triggered: ");
serialprintPGM(st.getOTPW() ? PSTR("true") : PSTR("false"));
SERIAL_EOL();
}
template<typename TMC>
void tmc_clear_otpw(TMC &st, const char name[]) {
st.clear_otpw();
SERIAL_ECHO(name);
SERIAL_ECHOLNPGM(" prewarn flag cleared");
}
template<typename TMC>
void tmc_get_pwmthrs(TMC &st, const char name[], const uint16_t spmm) {
SERIAL_ECHO(name);
SERIAL_ECHOPGM(" stealthChop max speed set to ");
SERIAL_ECHOLN(12650000UL * st.microsteps() / (256 * st.TPWMTHRS() * spmm));
}
template<typename TMC>
void tmc_set_pwmthrs(TMC &st, const char name[], const int32_t thrs, const uint32_t spmm) {
st.TPWMTHRS(12650000UL * st.microsteps() / (256 * thrs * spmm));
tmc_get_pwmthrs(st, name, spmm);
}
template<typename TMC>
void tmc_get_sgt(TMC &st, const char name[]) {
SERIAL_ECHO(name);
SERIAL_ECHOPGM(" driver homing sensitivity set to ");
MYSERIAL.println(st.sgt(), DEC);
}
template<typename TMC>
void tmc_set_sgt(TMC &st, const char name[], const int8_t sgt_val) {
st.sgt(sgt_val);
tmc_get_sgt(st, name);
}
/*
* Check for over temperature or short to ground error flags.
* Report and log warning of overtemperature condition.

View file

@ -29,27 +29,58 @@
extern bool report_tmc_status;
extern char extended_axis_codes[11][3];
enum TMC_AxisEnum {
TMC_X, TMC_X2, TMC_Y, TMC_Y2, TMC_Z, TMC_Z2,
TMC_E0, TMC_E1, TMC_E2, TMC_E3, TMC_E4
};
template<typename TMC>
void tmc_get_current(TMC &st, const char name[]);
void tmc_get_current(TMC &st, const char name[]) {
SERIAL_ECHO(name);
SERIAL_ECHOPGM(" axis driver current: ");
SERIAL_ECHOLN(st.getCurrent());
}
template<typename TMC>
void tmc_set_current(TMC &st, const char name[], const int mA);
void tmc_set_current(TMC &st, const char name[], const int mA) {
st.setCurrent(mA, R_SENSE, HOLD_MULTIPLIER);
tmc_get_current(st, name);
}
template<typename TMC>
void tmc_report_otpw(TMC &st, const char name[]);
void tmc_report_otpw(TMC &st, const char name[]) {
SERIAL_ECHO(name);
SERIAL_ECHOPGM(" axis temperature prewarn triggered: ");
serialprintPGM(st.getOTPW() ? PSTR("true") : PSTR("false"));
SERIAL_EOL();
}
template<typename TMC>
void tmc_clear_otpw(TMC &st, const char name[]);
void tmc_clear_otpw(TMC &st, const char name[]) {
st.clear_otpw();
SERIAL_ECHO(name);
SERIAL_ECHOLNPGM(" prewarn flag cleared");
}
template<typename TMC>
void tmc_get_pwmthrs(TMC &st, const char name[], const uint16_t spmm);
void tmc_get_pwmthrs(TMC &st, const char name[], const uint16_t spmm) {
SERIAL_ECHO(name);
SERIAL_ECHOPGM(" stealthChop max speed set to ");
SERIAL_ECHOLN(12650000UL * st.microsteps() / (256 * st.TPWMTHRS() * spmm));
}
template<typename TMC>
void tmc_set_pwmthrs(TMC &st, const char name[], const int32_t thrs, const uint32_t spmm);
void tmc_set_pwmthrs(TMC &st, const char name[], const int32_t thrs, const uint32_t spmm) {
st.TPWMTHRS(12650000UL * st.microsteps() / (256 * thrs * spmm));
tmc_get_pwmthrs(st, name, spmm);
}
template<typename TMC>
void tmc_get_sgt(TMC &st, const char name[]);
void tmc_get_sgt(TMC &st, const char name[]) {
SERIAL_ECHO(name);
SERIAL_ECHOPGM(" driver homing sensitivity set to ");
MYSERIAL.println(st.sgt(), DEC);
}
template<typename TMC>
void tmc_set_sgt(TMC &st, const char name[], const int8_t sgt_val);
void tmc_set_sgt(TMC &st, const char name[], const int8_t sgt_val) {
st.sgt(sgt_val);
tmc_get_sgt(st, name);
}
void _M122();
void monitor_tmc_driver();

View file

@ -334,6 +334,6 @@ void _M122() {
}
// We need to call M122 from monitor_tmc_driver() as well but GcodeSuite::M122 is private.
inline void GcodeSuite::M122() { _M122(); }
void GcodeSuite::M122() { _M122(); }
#endif // TMC_DEBUG

View file

@ -33,7 +33,7 @@
* M906: Set motor current in milliamps using axis codes X, Y, Z, E
* Report driver currents when no axis specified
*/
inline void GcodeSuite::M906() {
void GcodeSuite::M906() {
uint16_t values[XYZE];
LOOP_XYZE(i)
values[i] = parser.intval(axis_codes[i]);

View file

@ -28,12 +28,13 @@
#include "../../../feature/tmc_util.h"
#include "../../../module/stepper_indirection.h"
#include "../../../module/planner.h"
#include "../../queue.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() {
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
@ -51,7 +52,7 @@ inline void GcodeSuite::M911() {
/**
* M912: Clear TMC stepper driver overtemperature pre-warn flag held by the library
*/
inline void GcodeSuite::M912() {
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))
@ -78,7 +79,7 @@ inline void GcodeSuite::M912() {
* M913: Set HYBRID_THRESHOLD speed.
*/
#if ENABLED(HYBRID_THRESHOLD)
inline void GcodeSuite::M913() {
void GcodeSuite::M913() {
uint16_t values[XYZE];
LOOP_XYZE(i)
values[i] = parser.intval(axis_codes[i]);
@ -137,7 +138,7 @@ inline void GcodeSuite::M912() {
* M914: Set SENSORLESS_HOMING sensitivity.
*/
#if ENABLED(SENSORLESS_HOMING)
inline void GcodeSuite::M914() {
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]);
@ -160,8 +161,8 @@ inline void GcodeSuite::M912() {
/**
* TMC Z axis calibration routine
*/
#if ENABLED(TMC_Z_CALIBRATION) && (Z_IS_TRINAMIC || Z2_IS_TRINAMIC)
inline void GcodeSuite::M915() {
#if ENABLED(TMC_Z_CALIBRATION)
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;
@ -170,25 +171,33 @@ inline void GcodeSuite::M912() {
return;
}
#if Z_IS_TRINAMIC
uint16_t Z_current_1 = stepperZ.getCurrent();
uint16_t Z2_current_1 = stepperZ.getCurrent();
stepperZ.setCurrent(_rms, R_SENSE, HOLD_MULTIPLIER);
#endif
#if Z2_IS_TRINAMIC
uint16_t Z2_current_1 = stepperZ2.getCurrent();
stepperZ2.setCurrent(_rms, R_SENSE, HOLD_MULTIPLIER);
#endif
SERIAL_ECHOPAIR("\nCalibration current: Z", _rms);
soft_endstops_enabled = false;
do_blocking_move_to_z(Z_MAX_POS+_z);
#if Z_IS_TRINAMIC
stepperZ.setCurrent(Z_current_1, R_SENSE, HOLD_MULTIPLIER);
#endif
#if Z2_IS_TRINAMIC
stepperZ2.setCurrent(Z2_current_1, R_SENSE, HOLD_MULTIPLIER);
#endif
do_blocking_move_to_z(Z_MAX_POS);
soft_endstops_enabled = true;
SERIAL_ECHOLNPGM("\nHoming Z because we lost steps");
home_z_safely();
enqueue_and_echo_commands_P(PSTR("G28 Z"));
}
#endif

View file

@ -659,8 +659,10 @@ void GcodeSuite::process_parsed_command() {
#endif
#endif
#if HAVE_TRINAMIC
#if HAS_TRINAMIC
#if ENABLED(TMC_DEBUG)
case 122: M122(); break;
#endif
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
@ -670,6 +672,9 @@ void GcodeSuite::process_parsed_command() {
#if ENABLED(SENSORLESS_HOMING)
case 914: M914(); break; // M914: Set SENSORLESS_HOMING sensitivity.
#endif
#if ENABLED(TMC_Z_CALIBRATION)
case 915: M915(); break; // M915: TMC Z axis calibration.
#endif
#endif
#if HAS_MICROSTEPS

View file

@ -1491,6 +1491,12 @@ static_assert(1 >= 0
#error "Enable STEALTHCHOP to use HYBRID_THRESHOLD."
#endif
#include "../feature/tmc_macros.h"
#if ENABLED(TMC_Z_CALIBRATION) && !Z_IS_TRINAMIC && !Z2_IS_TRINAMIC
#error "TMC_Z_CALIBRATION requires at least one TMC driver on Z axis"
#endif
/**
* Make sure HAVE_L6470DRIVER is warranted
*/