[2.0.x] TMC driver update (#8769)
This commit is contained in:
committed by
Scott Lahteine
parent
09d13f186f
commit
0cd1e91056
@ -36,13 +36,13 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#define EEPROM_VERSION "V46"
|
||||
#define EEPROM_VERSION "V47"
|
||||
|
||||
// Change EEPROM version if these are changed:
|
||||
#define EEPROM_OFFSET 100
|
||||
|
||||
/**
|
||||
* V46 EEPROM Layout:
|
||||
* V47 EEPROM Layout:
|
||||
*
|
||||
* 100 Version (char x4)
|
||||
* 104 EEPROM CRC16 (uint16_t)
|
||||
@ -154,6 +154,10 @@
|
||||
* 578 M906 E3 Stepper E3 current (uint16_t)
|
||||
* 580 M906 E4 Stepper E4 current (uint16_t)
|
||||
*
|
||||
* SENSORLESS HOMING 4 bytes
|
||||
* 580 M914 X Stepper X and X2 threshold (int16_t)
|
||||
* 582 M914 Y Stepper Y and Y2 threshold (int16_t)
|
||||
*
|
||||
* LIN_ADVANCE: 8 bytes
|
||||
* 582 M900 K extruder_advance_k (float)
|
||||
* 586 M900 WHD advance_ed_ratio (float)
|
||||
@ -542,70 +546,70 @@ void MarlinSettings::postprocess() {
|
||||
EEPROM_WRITE(dummy);
|
||||
}
|
||||
|
||||
// Save TMC2130 Configuration, and placeholder values
|
||||
// Save TMC2130 or TMC2208 Configuration, and placeholder values
|
||||
uint16_t val;
|
||||
#if ENABLED(HAVE_TMC2130)
|
||||
#if ENABLED(X_IS_TMC2130)
|
||||
#if HAS_TRINAMIC
|
||||
#if X_IS_TRINAMIC
|
||||
val = stepperX.getCurrent();
|
||||
#else
|
||||
val = 0;
|
||||
#endif
|
||||
EEPROM_WRITE(val);
|
||||
#if ENABLED(Y_IS_TMC2130)
|
||||
#if Y_IS_TRINAMIC
|
||||
val = stepperY.getCurrent();
|
||||
#else
|
||||
val = 0;
|
||||
#endif
|
||||
EEPROM_WRITE(val);
|
||||
#if ENABLED(Z_IS_TMC2130)
|
||||
#if Z_IS_TRINAMIC
|
||||
val = stepperZ.getCurrent();
|
||||
#else
|
||||
val = 0;
|
||||
#endif
|
||||
EEPROM_WRITE(val);
|
||||
#if ENABLED(X2_IS_TMC2130)
|
||||
#if X2_IS_TRINAMIC
|
||||
val = stepperX2.getCurrent();
|
||||
#else
|
||||
val = 0;
|
||||
#endif
|
||||
EEPROM_WRITE(val);
|
||||
#if ENABLED(Y2_IS_TMC2130)
|
||||
#if Y2_IS_TRINAMIC
|
||||
val = stepperY2.getCurrent();
|
||||
#else
|
||||
val = 0;
|
||||
#endif
|
||||
EEPROM_WRITE(val);
|
||||
#if ENABLED(Z2_IS_TMC2130)
|
||||
#if Z2_IS_TRINAMIC
|
||||
val = stepperZ2.getCurrent();
|
||||
#else
|
||||
val = 0;
|
||||
#endif
|
||||
EEPROM_WRITE(val);
|
||||
#if ENABLED(E0_IS_TMC2130)
|
||||
#if E0_IS_TRINAMIC
|
||||
val = stepperE0.getCurrent();
|
||||
#else
|
||||
val = 0;
|
||||
#endif
|
||||
EEPROM_WRITE(val);
|
||||
#if ENABLED(E1_IS_TMC2130)
|
||||
#if E1_IS_TRINAMIC
|
||||
val = stepperE1.getCurrent();
|
||||
#else
|
||||
val = 0;
|
||||
#endif
|
||||
EEPROM_WRITE(val);
|
||||
#if ENABLED(E2_IS_TMC2130)
|
||||
#if E2_IS_TRINAMIC
|
||||
val = stepperE2.getCurrent();
|
||||
#else
|
||||
val = 0;
|
||||
#endif
|
||||
EEPROM_WRITE(val);
|
||||
#if ENABLED(E3_IS_TMC2130)
|
||||
#if E3_IS_TRINAMIC
|
||||
val = stepperE3.getCurrent();
|
||||
#else
|
||||
val = 0;
|
||||
#endif
|
||||
EEPROM_WRITE(val);
|
||||
#if ENABLED(E4_IS_TMC2130)
|
||||
#if E4_IS_TRINAMIC
|
||||
val = stepperE4.getCurrent();
|
||||
#else
|
||||
val = 0;
|
||||
@ -616,6 +620,28 @@ void MarlinSettings::postprocess() {
|
||||
for (uint8_t q = 11; q--;) EEPROM_WRITE(val);
|
||||
#endif
|
||||
|
||||
//
|
||||
// TMC2130 Sensorless homing threshold
|
||||
//
|
||||
int16_t thrs;
|
||||
#if ENABLED(SENSORLESS_HOMING)
|
||||
#if ENABLED(X_IS_TMC2130)
|
||||
thrs = stepperX.sgt();
|
||||
#else
|
||||
thrs = 0;
|
||||
#endif
|
||||
EEPROM_WRITE(thrs);
|
||||
#if ENABLED(Y_IS_TMC2130)
|
||||
thrs = stepperY.sgt();
|
||||
#else
|
||||
thrs = 0;
|
||||
#endif
|
||||
EEPROM_WRITE(thrs);
|
||||
#else
|
||||
thrs = 0;
|
||||
for (uint8_t q = 2; q--;) EEPROM_WRITE(thrs);
|
||||
#endif
|
||||
|
||||
//
|
||||
// Linear Advance
|
||||
//
|
||||
@ -1014,55 +1040,80 @@ void MarlinSettings::postprocess() {
|
||||
//
|
||||
|
||||
uint16_t val;
|
||||
#if ENABLED(HAVE_TMC2130)
|
||||
#if HAS_TRINAMIC
|
||||
EEPROM_READ(val);
|
||||
#if ENABLED(X_IS_TMC2130)
|
||||
#if X_IS_TRINAMIC
|
||||
stepperX.setCurrent(val, R_SENSE, HOLD_MULTIPLIER);
|
||||
#endif
|
||||
EEPROM_READ(val);
|
||||
#if ENABLED(Y_IS_TMC2130)
|
||||
#if Y_IS_TRINAMIC
|
||||
stepperY.setCurrent(val, R_SENSE, HOLD_MULTIPLIER);
|
||||
#endif
|
||||
EEPROM_READ(val);
|
||||
#if ENABLED(Z_IS_TMC2130)
|
||||
#if Z_IS_TRINAMIC
|
||||
stepperZ.setCurrent(val, R_SENSE, HOLD_MULTIPLIER);
|
||||
#endif
|
||||
EEPROM_READ(val);
|
||||
#if ENABLED(X2_IS_TMC2130)
|
||||
#if X2_IS_TRINAMIC
|
||||
stepperX2.setCurrent(val, R_SENSE, HOLD_MULTIPLIER);
|
||||
#endif
|
||||
EEPROM_READ(val);
|
||||
#if ENABLED(Y2_IS_TMC2130)
|
||||
#if Y2_IS_TRINAMIC
|
||||
stepperY2.setCurrent(val, R_SENSE, HOLD_MULTIPLIER);
|
||||
#endif
|
||||
EEPROM_READ(val);
|
||||
#if ENABLED(Z2_IS_TMC2130)
|
||||
#if Z2_IS_TRINAMIC
|
||||
stepperZ2.setCurrent(val, R_SENSE, HOLD_MULTIPLIER);
|
||||
#endif
|
||||
EEPROM_READ(val);
|
||||
#if ENABLED(E0_IS_TMC2130)
|
||||
#if E0_IS_TRINAMIC
|
||||
stepperE0.setCurrent(val, R_SENSE, HOLD_MULTIPLIER);
|
||||
#endif
|
||||
EEPROM_READ(val);
|
||||
#if ENABLED(E1_IS_TMC2130)
|
||||
#if E1_IS_TRINAMIC
|
||||
stepperE1.setCurrent(val, R_SENSE, HOLD_MULTIPLIER);
|
||||
#endif
|
||||
EEPROM_READ(val);
|
||||
#if ENABLED(E2_IS_TMC2130)
|
||||
#if E2_IS_TRINAMIC
|
||||
stepperE2.setCurrent(val, R_SENSE, HOLD_MULTIPLIER);
|
||||
#endif
|
||||
EEPROM_READ(val);
|
||||
#if ENABLED(E3_IS_TMC2130)
|
||||
#if E3_IS_TRINAMIC
|
||||
stepperE3.setCurrent(val, R_SENSE, HOLD_MULTIPLIER);
|
||||
#endif
|
||||
EEPROM_READ(val);
|
||||
#if ENABLED(E4_IS_TMC2130)
|
||||
#if E4_IS_TRINAMIC
|
||||
stepperE4.setCurrent(val, R_SENSE, HOLD_MULTIPLIER);
|
||||
#endif
|
||||
#else
|
||||
for (uint8_t q = 11; q--;) EEPROM_READ(val);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* TMC2130 Sensorless homing threshold.
|
||||
* X and X2 use the same value
|
||||
* Y and Y2 use the same value
|
||||
*/
|
||||
int16_t thrs;
|
||||
#if ENABLED(SENSORLESS_HOMING)
|
||||
EEPROM_READ(thrs);
|
||||
#if ENABLED(X_IS_TMC2130)
|
||||
stepperX.sgt(thrs);
|
||||
#endif
|
||||
#if ENABLED(X2_IS_TMC2130)
|
||||
stepperX2.sgt(thrs);
|
||||
#endif
|
||||
EEPROM_READ(thrs);
|
||||
#if ENABLED(Y_IS_TMC2130)
|
||||
stepperY.sgt(thrs);
|
||||
#endif
|
||||
#if ENABLED(Y2_IS_TMC2130)
|
||||
stepperY2.sgt(thrs);
|
||||
#endif
|
||||
#else
|
||||
for (uint8_t q = 0; q < 2; q++) EEPROM_READ(thrs);
|
||||
#endif
|
||||
|
||||
//
|
||||
// Linear Advance
|
||||
//
|
||||
@ -1451,36 +1502,52 @@ void MarlinSettings::reset() {
|
||||
#endif
|
||||
);
|
||||
|
||||
#if ENABLED(HAVE_TMC2130)
|
||||
#if X_IS_TRINAMIC
|
||||
stepperX.setCurrent(X_CURRENT, R_SENSE, HOLD_MULTIPLIER);
|
||||
#endif
|
||||
#if Y_IS_TRINAMIC
|
||||
stepperY.setCurrent(Y_CURRENT, R_SENSE, HOLD_MULTIPLIER);
|
||||
#endif
|
||||
#if Z_IS_TRINAMIC
|
||||
stepperZ.setCurrent(Z_CURRENT, R_SENSE, HOLD_MULTIPLIER);
|
||||
#endif
|
||||
#if X2_IS_TRINAMIC
|
||||
stepperX2.setCurrent(X2_CURRENT, R_SENSE, HOLD_MULTIPLIER);
|
||||
#endif
|
||||
#if Y2_IS_TRINAMIC
|
||||
stepperY2.setCurrent(Y2_CURRENT, R_SENSE, HOLD_MULTIPLIER);
|
||||
#endif
|
||||
#if Z2_IS_TRINAMIC
|
||||
stepperZ2.setCurrent(Z2_CURRENT, R_SENSE, HOLD_MULTIPLIER);
|
||||
#endif
|
||||
#if E0_IS_TRINAMIC
|
||||
stepperE0.setCurrent(E0_CURRENT, R_SENSE, HOLD_MULTIPLIER);
|
||||
#endif
|
||||
#if E1_IS_TRINAMIC
|
||||
stepperE1.setCurrent(E1_CURRENT, R_SENSE, HOLD_MULTIPLIER);
|
||||
#endif
|
||||
#if E2_IS_TRINAMIC
|
||||
stepperE2.setCurrent(E2_CURRENT, R_SENSE, HOLD_MULTIPLIER);
|
||||
#endif
|
||||
#if E3_IS_TRINAMIC
|
||||
stepperE3.setCurrent(E3_CURRENT, R_SENSE, HOLD_MULTIPLIER);
|
||||
#endif
|
||||
#if E4_IS_TRINAMIC
|
||||
stepperE4.setCurrent(E4_CURRENT, R_SENSE, HOLD_MULTIPLIER);
|
||||
#endif
|
||||
|
||||
#if ENABLED(SENSORLESS_HOMING)
|
||||
#if ENABLED(X_IS_TMC2130)
|
||||
stepperX.setCurrent(X_CURRENT, R_SENSE, HOLD_MULTIPLIER);
|
||||
#endif
|
||||
#if ENABLED(Y_IS_TMC2130)
|
||||
stepperY.setCurrent(Y_CURRENT, R_SENSE, HOLD_MULTIPLIER);
|
||||
#endif
|
||||
#if ENABLED(Z_IS_TMC2130)
|
||||
stepperZ.setCurrent(Z_CURRENT, R_SENSE, HOLD_MULTIPLIER);
|
||||
stepperX.sgt(X_HOMING_SENSITIVITY);
|
||||
#endif
|
||||
#if ENABLED(X2_IS_TMC2130)
|
||||
stepperX2.setCurrent(X2_CURRENT, R_SENSE, HOLD_MULTIPLIER);
|
||||
stepperX2.sgt(X_HOMING_SENSITIVITY);
|
||||
#endif
|
||||
#if ENABLED(Y_IS_TMC2130)
|
||||
stepperY.sgt(Y_HOMING_SENSITIVITY);
|
||||
#endif
|
||||
#if ENABLED(Y2_IS_TMC2130)
|
||||
stepperY2.setCurrent(Y2_CURRENT, R_SENSE, HOLD_MULTIPLIER);
|
||||
#endif
|
||||
#if ENABLED(Z2_IS_TMC2130)
|
||||
stepperZ2.setCurrent(Z2_CURRENT, R_SENSE, HOLD_MULTIPLIER);
|
||||
#endif
|
||||
#if ENABLED(E0_IS_TMC2130)
|
||||
stepperE0.setCurrent(E0_CURRENT, R_SENSE, HOLD_MULTIPLIER);
|
||||
#endif
|
||||
#if ENABLED(E1_IS_TMC2130)
|
||||
stepperE1.setCurrent(E1_CURRENT, R_SENSE, HOLD_MULTIPLIER);
|
||||
#endif
|
||||
#if ENABLED(E2_IS_TMC2130)
|
||||
stepperE2.setCurrent(E2_CURRENT, R_SENSE, HOLD_MULTIPLIER);
|
||||
#endif
|
||||
#if ENABLED(E3_IS_TMC2130)
|
||||
stepperE3.setCurrent(E3_CURRENT, R_SENSE, HOLD_MULTIPLIER);
|
||||
stepperY2.sgt(Y_HOMING_SENSITIVITY);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@ -1959,35 +2026,63 @@ void MarlinSettings::reset() {
|
||||
}
|
||||
CONFIG_ECHO_START;
|
||||
SERIAL_ECHO(" M906");
|
||||
#if ENABLED(X_IS_TMC2130) || ENABLED(X_IS_TMC2208)
|
||||
SERIAL_ECHOPAIR(" X ", stepperX.getCurrent());
|
||||
#endif
|
||||
#if ENABLED(Y_IS_TMC2130) || ENABLED(Y_IS_TMC2208)
|
||||
SERIAL_ECHOPAIR(" Y ", stepperY.getCurrent());
|
||||
#endif
|
||||
#if ENABLED(Z_IS_TMC2130) || ENABLED(Z_IS_TMC2208)
|
||||
SERIAL_ECHOPAIR(" Z ", stepperZ.getCurrent());
|
||||
#endif
|
||||
#if ENABLED(X2_IS_TMC2130) || ENABLED(X2_IS_TMC2208)
|
||||
SERIAL_ECHOPAIR(" X2 ", stepperX2.getCurrent());
|
||||
#endif
|
||||
#if ENABLED(Y2_IS_TMC2130) || ENABLED(Y2_IS_TMC2208)
|
||||
SERIAL_ECHOPAIR(" Y2 ", stepperY2.getCurrent());
|
||||
#endif
|
||||
#if ENABLED(Z2_IS_TMC2130) || ENABLED(Z2_IS_TMC2208)
|
||||
SERIAL_ECHOPAIR(" Z2 ", stepperZ2.getCurrent());
|
||||
#endif
|
||||
#if ENABLED(E0_IS_TMC2130) || ENABLED(E0_IS_TMC2208)
|
||||
SERIAL_ECHOPAIR(" E0 ", stepperE0.getCurrent());
|
||||
#endif
|
||||
#if ENABLED(E1_IS_TMC2130) || ENABLED(E1_IS_TMC2208)
|
||||
SERIAL_ECHOPAIR(" E1 ", stepperE1.getCurrent());
|
||||
#endif
|
||||
#if ENABLED(E2_IS_TMC2130) || ENABLED(E2_IS_TMC2208)
|
||||
SERIAL_ECHOPAIR(" E2 ", stepperE2.getCurrent());
|
||||
#endif
|
||||
#if ENABLED(E3_IS_TMC2130) || ENABLED(E3_IS_TMC2208)
|
||||
SERIAL_ECHOPAIR(" E3 ", stepperE3.getCurrent());
|
||||
#endif
|
||||
#if ENABLED(E4_IS_TMC2130) || ENABLED(E4_IS_TMC2208)
|
||||
SERIAL_ECHOPAIR(" E4 ", stepperE4.getCurrent());
|
||||
#endif
|
||||
SERIAL_EOL();
|
||||
#endif
|
||||
|
||||
/**
|
||||
* TMC2130 Sensorless homing thresholds
|
||||
*/
|
||||
#if ENABLED(HAVE_TMC2130) && ENABLED(SENSORLESS_HOMING)
|
||||
if (!forReplay) {
|
||||
CONFIG_ECHO_START;
|
||||
SERIAL_ECHOLNPGM("Sensorless homing threshold:");
|
||||
}
|
||||
CONFIG_ECHO_START;
|
||||
SERIAL_ECHO(" M914");
|
||||
#if ENABLED(X_IS_TMC2130)
|
||||
SERIAL_ECHOPAIR(" X", stepperX.getCurrent());
|
||||
#endif
|
||||
#if ENABLED(Y_IS_TMC2130)
|
||||
SERIAL_ECHOPAIR(" Y", stepperY.getCurrent());
|
||||
#endif
|
||||
#if ENABLED(Z_IS_TMC2130)
|
||||
SERIAL_ECHOPAIR(" Z", stepperZ.getCurrent());
|
||||
SERIAL_ECHOPAIR(" X", stepperX.sgt());
|
||||
#endif
|
||||
#if ENABLED(X2_IS_TMC2130)
|
||||
SERIAL_ECHOPAIR(" X2", stepperX2.getCurrent());
|
||||
SERIAL_ECHOPAIR(" X2 ", stepperX2.sgt());
|
||||
#endif
|
||||
#if ENABLED(Y2_IS_TMC2130)
|
||||
SERIAL_ECHOPAIR(" Y2", stepperY2.getCurrent());
|
||||
#if ENABLED(Y_IS_TMC2130)
|
||||
SERIAL_ECHOPAIR(" Y", stepperY.sgt());
|
||||
#endif
|
||||
#if ENABLED(Z2_IS_TMC2130)
|
||||
SERIAL_ECHOPAIR(" Z2", stepperZ2.getCurrent());
|
||||
#endif
|
||||
#if ENABLED(E0_IS_TMC2130)
|
||||
SERIAL_ECHOPAIR(" E0", stepperE0.getCurrent());
|
||||
#endif
|
||||
#if ENABLED(E1_IS_TMC2130)
|
||||
SERIAL_ECHOPAIR(" E1", stepperE1.getCurrent());
|
||||
#endif
|
||||
#if ENABLED(E2_IS_TMC2130)
|
||||
SERIAL_ECHOPAIR(" E2", stepperE2.getCurrent());
|
||||
#endif
|
||||
#if ENABLED(E3_IS_TMC2130)
|
||||
SERIAL_ECHOPAIR(" E3", stepperE3.getCurrent());
|
||||
#if ENABLED(X2_IS_TMC2130)
|
||||
SERIAL_ECHOPAIR(" Y2 ", stepperY2.sgt());
|
||||
#endif
|
||||
SERIAL_EOL();
|
||||
#endif
|
||||
|
@ -52,7 +52,7 @@
|
||||
#endif
|
||||
|
||||
#if ENABLED(SENSORLESS_HOMING)
|
||||
#include "../feature/tmc2130.h"
|
||||
#include "../feature/tmc_util.h"
|
||||
#endif
|
||||
|
||||
#define XYZ_CONSTS(type, array, CONFIG) const PROGMEM type array##_P[XYZ] = { X_##CONFIG, Y_##CONFIG, Z_##CONFIG }
|
||||
@ -1172,10 +1172,10 @@ void homeaxis(const AxisEnum axis) {
|
||||
// Disable stealthChop if used. Enable diag1 pin on driver.
|
||||
#if ENABLED(SENSORLESS_HOMING)
|
||||
#if ENABLED(X_IS_TMC2130)
|
||||
if (axis == X_AXIS) tmc2130_sensorless_homing(stepperX);
|
||||
if (axis == X_AXIS) tmc_sensorless_homing(stepperX);
|
||||
#endif
|
||||
#if ENABLED(Y_IS_TMC2130)
|
||||
if (axis == Y_AXIS) tmc2130_sensorless_homing(stepperY);
|
||||
if (axis == Y_AXIS) tmc_sensorless_homing(stepperY);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@ -1282,10 +1282,10 @@ void homeaxis(const AxisEnum axis) {
|
||||
// Re-enable stealthChop if used. Disable diag1 pin on driver.
|
||||
#if ENABLED(SENSORLESS_HOMING)
|
||||
#if ENABLED(X_IS_TMC2130)
|
||||
if (axis == X_AXIS) tmc2130_sensorless_homing(stepperX, false);
|
||||
if (axis == X_AXIS) tmc_sensorless_homing(stepperX, false);
|
||||
#endif
|
||||
#if ENABLED(Y_IS_TMC2130)
|
||||
if (axis == Y_AXIS) tmc2130_sensorless_homing(stepperY, false);
|
||||
if (axis == Y_AXIS) tmc_sensorless_homing(stepperY, false);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
@ -954,6 +954,16 @@ void Stepper::init() {
|
||||
tmc2130_init();
|
||||
#endif
|
||||
|
||||
// Init TMC2208 Steppers
|
||||
#if ENABLED(HAVE_TMC2208)
|
||||
tmc2208_init();
|
||||
#endif
|
||||
|
||||
// TRAMS, TMC2130 and TMC2208 advanced settings
|
||||
#if HAS_TRINAMIC
|
||||
TMC_ADV()
|
||||
#endif
|
||||
|
||||
// Init L6470 Steppers
|
||||
#if ENABLED(HAVE_L6470DRIVER)
|
||||
L6470_init();
|
||||
|
@ -129,6 +129,7 @@
|
||||
|
||||
#include <SPI.h>
|
||||
#include <TMC2130Stepper.h>
|
||||
#include "planner.h"
|
||||
#include "../core/enum.h"
|
||||
|
||||
#define _TMC2130_DEFINE(ST) TMC2130Stepper stepper##ST(ST##_ENABLE_PIN, ST##_DIR_PIN, ST##_STEP_PIN, ST##_CS_PIN)
|
||||
@ -171,17 +172,17 @@
|
||||
// Use internal reference voltage for current calculations. This is the default.
|
||||
// Following values from Trinamic's spreadsheet with values for a NEMA17 (42BYGHW609)
|
||||
// https://www.trinamic.com/products/integrated-circuits/details/tmc2130/
|
||||
void tmc2130_init(TMC2130Stepper &st, const uint16_t microsteps, const uint32_t thrs, const float &spmm) {
|
||||
void tmc2130_init(TMC2130Stepper &st, const uint16_t microsteps, const uint32_t thrs, const float spmm) {
|
||||
st.begin();
|
||||
st.setCurrent(st.getCurrent(), R_SENSE, HOLD_MULTIPLIER);
|
||||
st.microsteps(microsteps);
|
||||
st.blank_time(36);
|
||||
st.blank_time(24);
|
||||
st.off_time(5); // Only enables the driver if used with stealthChop
|
||||
st.interpolate(INTERPOLATE);
|
||||
st.power_down_delay(128); // ~2s until driver lowers to hold current
|
||||
st.hysterisis_start(0); // HSTRT = 1
|
||||
st.hysterisis_low(1); // HEND = -2
|
||||
st.diag1_active_high(0); // For sensorless homing
|
||||
st.hysterisis_start(3);
|
||||
st.hysterisis_end(2);
|
||||
st.diag1_active_high(1); // For sensorless homing
|
||||
#if ENABLED(STEALTHCHOP)
|
||||
st.stealth_freq(1); // f_pwm = 2/683 f_clk
|
||||
st.stealth_autoscale(1);
|
||||
@ -189,61 +190,261 @@
|
||||
st.stealth_amplitude(255);
|
||||
st.stealthChop(1);
|
||||
#if ENABLED(HYBRID_THRESHOLD)
|
||||
st.stealth_max_speed(12650000UL*st.microsteps()/(256*thrs*spmm));
|
||||
st.stealth_max_speed(12650000UL*microsteps/(256*thrs*spmm));
|
||||
#else
|
||||
UNUSED(thrs);
|
||||
UNUSED(spmm);
|
||||
#endif
|
||||
#elif ENABLED(SENSORLESS_HOMING)
|
||||
st.coolstep_min_speed(1024UL * 1024UL - 1UL);
|
||||
#endif
|
||||
st.GSTAT(); // Clear GSTAT
|
||||
}
|
||||
|
||||
#define _TMC2130_INIT(ST, SPMM) tmc2130_init(stepper##ST, ST##_MICROSTEPS, ST##_HYBRID_THRESHOLD, SPMM)
|
||||
|
||||
void tmc2130_init() {
|
||||
constexpr float steps_per_mm[] = DEFAULT_AXIS_STEPS_PER_UNIT;
|
||||
#if ENABLED(X_IS_TMC2130)
|
||||
_TMC2130_INIT( X, steps_per_mm[X_AXIS]);
|
||||
#if ENABLED(SENSORLESS_HOMING)
|
||||
stepperX.sg_stall_value(X_HOMING_SENSITIVITY);
|
||||
#endif
|
||||
_TMC2130_INIT( X, planner.axis_steps_per_mm[X_AXIS]);
|
||||
#endif
|
||||
#if ENABLED(X2_IS_TMC2130)
|
||||
_TMC2130_INIT(X2, steps_per_mm[X_AXIS]);
|
||||
_TMC2130_INIT(X2, planner.axis_steps_per_mm[X_AXIS]);
|
||||
#endif
|
||||
#if ENABLED(Y_IS_TMC2130)
|
||||
_TMC2130_INIT( Y, steps_per_mm[Y_AXIS]);
|
||||
#if ENABLED(SENSORLESS_HOMING)
|
||||
stepperY.sg_stall_value(Y_HOMING_SENSITIVITY);
|
||||
#endif
|
||||
_TMC2130_INIT( Y, planner.axis_steps_per_mm[Y_AXIS]);
|
||||
#endif
|
||||
#if ENABLED(Y2_IS_TMC2130)
|
||||
_TMC2130_INIT(Y2, steps_per_mm[Y_AXIS]);
|
||||
_TMC2130_INIT(Y2, planner.axis_steps_per_mm[Y_AXIS]);
|
||||
#endif
|
||||
#if ENABLED(Z_IS_TMC2130)
|
||||
_TMC2130_INIT( Z, steps_per_mm[Z_AXIS]);
|
||||
_TMC2130_INIT( Z, planner.axis_steps_per_mm[Z_AXIS]);
|
||||
#endif
|
||||
#if ENABLED(Z2_IS_TMC2130)
|
||||
_TMC2130_INIT(Z2, steps_per_mm[Z_AXIS]);
|
||||
_TMC2130_INIT(Z2, planner.axis_steps_per_mm[Z_AXIS]);
|
||||
#endif
|
||||
#if ENABLED(E0_IS_TMC2130)
|
||||
_TMC2130_INIT(E0, steps_per_mm[E_AXIS]);
|
||||
_TMC2130_INIT(E0, planner.axis_steps_per_mm[E_AXIS]);
|
||||
#endif
|
||||
#if ENABLED(E1_IS_TMC2130)
|
||||
{ constexpr int extruder = 1; _TMC2130_INIT(E1, steps_per_mm[E_AXIS_N]); }
|
||||
{ constexpr int extruder = 1; _TMC2130_INIT(E1, planner.axis_steps_per_mm[E_AXIS_N]); }
|
||||
#endif
|
||||
#if ENABLED(E2_IS_TMC2130)
|
||||
{ constexpr int extruder = 2; _TMC2130_INIT(E2, steps_per_mm[E_AXIS_N]); }
|
||||
{ constexpr int extruder = 2; _TMC2130_INIT(E2, planner.axis_steps_per_mm[E_AXIS_N]); }
|
||||
#endif
|
||||
#if ENABLED(E3_IS_TMC2130)
|
||||
{ constexpr int extruder = 3; _TMC2130_INIT(E3, steps_per_mm[E_AXIS_N]); }
|
||||
{ constexpr int extruder = 3; _TMC2130_INIT(E3, planner.axis_steps_per_mm[E_AXIS_N]); }
|
||||
#endif
|
||||
#if ENABLED(E4_IS_TMC2130)
|
||||
{ constexpr int extruder = 4; _TMC2130_INIT(E4, steps_per_mm[E_AXIS_N]); }
|
||||
{ constexpr int extruder = 4; _TMC2130_INIT(E4, planner.axis_steps_per_mm[E_AXIS_N]); }
|
||||
#endif
|
||||
|
||||
TMC2130_ADV()
|
||||
}
|
||||
#endif // HAVE_TMC2130
|
||||
|
||||
//
|
||||
// TMC2208 Driver objects and inits
|
||||
//
|
||||
#if ENABLED(HAVE_TMC2208)
|
||||
|
||||
#include <SoftwareSerial.h>
|
||||
#include <HardwareSerial.h>
|
||||
#include <TMC2208Stepper.h>
|
||||
#include "planner.h"
|
||||
|
||||
#define _TMC2208_DEFINE_HARDWARE(ST) TMC2208Stepper stepper##ST(&ST##_HARDWARE_SERIAL)
|
||||
#define _TMC2208_DEFINE_SOFTWARE(ST) SoftwareSerial stepper##ST##_serial = SoftwareSerial(ST##_SERIAL_RX_PIN, ST##_SERIAL_TX_PIN); \
|
||||
TMC2208Stepper stepper##ST(&stepper##ST##_serial, ST##_SERIAL_RX_PIN > -1)
|
||||
|
||||
// Stepper objects of TMC2208 steppers used
|
||||
#if ENABLED(X_IS_TMC2208)
|
||||
#if defined(X_HARDWARE_SERIAL)
|
||||
_TMC2208_DEFINE_HARDWARE(X);
|
||||
#else
|
||||
_TMC2208_DEFINE_SOFTWARE(X);
|
||||
#endif
|
||||
#endif
|
||||
#if ENABLED(X2_IS_TMC2208)
|
||||
#if defined(X2_HARDWARE_SERIAL)
|
||||
_TMC2208_DEFINE_HARDWARE(X2);
|
||||
#else
|
||||
_TMC2208_DEFINE_SOFTWARE(X2);
|
||||
#endif
|
||||
#endif
|
||||
#if ENABLED(Y_IS_TMC2208)
|
||||
#if defined(Y_HARDWARE_SERIAL)
|
||||
_TMC2208_DEFINE_HARDWARE(Y);
|
||||
#else
|
||||
_TMC2208_DEFINE_SOFTWARE(Y);
|
||||
#endif
|
||||
#endif
|
||||
#if ENABLED(Y2_IS_TMC2208)
|
||||
#if defined(Y2_HARDWARE_SERIAL)
|
||||
_TMC2208_DEFINE_HARDWARE(Y2);
|
||||
#else
|
||||
_TMC2208_DEFINE_SOFTWARE(Y2);
|
||||
#endif
|
||||
#endif
|
||||
#if ENABLED(Z_IS_TMC2208)
|
||||
#if defined(Z_HARDWARE_SERIAL)
|
||||
_TMC2208_DEFINE_HARDWARE(Z);
|
||||
#else
|
||||
_TMC2208_DEFINE_SOFTWARE(Z);
|
||||
#endif
|
||||
#endif
|
||||
#if ENABLED(Z2_IS_TMC2208)
|
||||
#if defined(Z2_HARDWARE_SERIAL)
|
||||
_TMC2208_DEFINE_HARDWARE(Z2);
|
||||
#else
|
||||
_TMC2208_DEFINE_SOFTWARE(Z2);
|
||||
#endif
|
||||
#endif
|
||||
#if ENABLED(E0_IS_TMC2208)
|
||||
#if defined(E0_HARDWARE_SERIAL)
|
||||
_TMC2208_DEFINE_HARDWARE(E0);
|
||||
#else
|
||||
_TMC2208_DEFINE_SOFTWARE(E0);
|
||||
#endif
|
||||
#endif
|
||||
#if ENABLED(E1_IS_TMC2208)
|
||||
#if defined(E1_HARDWARE_SERIAL)
|
||||
_TMC2208_DEFINE_HARDWARE(E1);
|
||||
#else
|
||||
_TMC2208_DEFINE_SOFTWARE(E1);
|
||||
#endif
|
||||
#endif
|
||||
#if ENABLED(E2_IS_TMC2208)
|
||||
#if defined(E2_HARDWARE_SERIAL)
|
||||
_TMC2208_DEFINE_HARDWARE(E2);
|
||||
#else
|
||||
_TMC2208_DEFINE_SOFTWARE(E2);
|
||||
#endif
|
||||
#endif
|
||||
#if ENABLED(E3_IS_TMC2208)
|
||||
#if defined(E3_HARDWARE_SERIAL)
|
||||
_TMC2208_DEFINE_HARDWARE(E3);
|
||||
#else
|
||||
_TMC2208_DEFINE_SOFTWARE(E3);
|
||||
#endif
|
||||
#endif
|
||||
#if ENABLED(E4_IS_TMC2208)
|
||||
#if defined(E4_HARDWARE_SERIAL)
|
||||
_TMC2208_DEFINE_HARDWARE(E4);
|
||||
#else
|
||||
_TMC2208_DEFINE_SOFTWARE(E4);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
void tmc2208_serial_begin() {
|
||||
#if ENABLED(X_IS_TMC2208) && defined(X_HARDWARE_SERIAL)
|
||||
X_HARDWARE_SERIAL.begin(250000);
|
||||
#endif
|
||||
#if ENABLED(X2_IS_TMC2208) && defined(X2_HARDWARE_SERIAL)
|
||||
X2_HARDWARE_SERIAL.begin(250000);
|
||||
#endif
|
||||
#if ENABLED(Y_IS_TMC2208) && defined(Y_HARDWARE_SERIAL)
|
||||
Y_HARDWARE_SERIAL.begin(250000);
|
||||
#endif
|
||||
#if ENABLED(Y2_IS_TMC2208) && defined(Y2_HARDWARE_SERIAL)
|
||||
Y2_HARDWARE_SERIAL.begin(250000);
|
||||
#endif
|
||||
#if ENABLED(Z_IS_TMC2208) && defined(Z_HARDWARE_SERIAL)
|
||||
Z_HARDWARE_SERIAL.begin(250000);
|
||||
#endif
|
||||
#if ENABLED(Z2_IS_TMC2208) && defined(Z2_HARDWARE_SERIAL)
|
||||
Z2_HARDWARE_SERIAL.begin(250000);
|
||||
#endif
|
||||
#if ENABLED(E0_IS_TMC2208) && defined(E0_HARDWARE_SERIAL)
|
||||
E0_HARDWARE_SERIAL.begin(250000);
|
||||
#endif
|
||||
#if ENABLED(E1_IS_TMC2208) && defined(E1_HARDWARE_SERIAL)
|
||||
E1_HARDWARE_SERIAL.begin(250000);
|
||||
#endif
|
||||
#if ENABLED(E2_IS_TMC2208) && defined(E2_HARDWARE_SERIAL)
|
||||
E2_HARDWARE_SERIAL.begin(250000);
|
||||
#endif
|
||||
#if ENABLED(E3_IS_TMC2208) && defined(E3_HARDWARE_SERIAL)
|
||||
E3_HARDWARE_SERIAL.begin(250000);
|
||||
#endif
|
||||
#if ENABLED(E4_IS_TMC2208) && defined(E4_HARDWARE_SERIAL)
|
||||
E4_HARDWARE_SERIAL.begin(250000);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Use internal reference voltage for current calculations. This is the default.
|
||||
// Following values from Trinamic's spreadsheet with values for a NEMA17 (42BYGHW609)
|
||||
void tmc2208_init(TMC2208Stepper &st, const uint16_t microsteps, const uint32_t thrs, const float spmm) {
|
||||
st.pdn_disable(true); // Use UART
|
||||
st.mstep_reg_select(true); // Select microsteps with UART
|
||||
st.I_scale_analog(false);
|
||||
st.rms_current(st.getCurrent(), HOLD_MULTIPLIER, R_SENSE);
|
||||
st.microsteps(microsteps);
|
||||
st.blank_time(24);
|
||||
st.toff(5);
|
||||
st.intpol(INTERPOLATE);
|
||||
st.TPOWERDOWN(128); // ~2s until driver lowers to hold current
|
||||
st.hysterisis_start(3);
|
||||
st.hysterisis_end(2);
|
||||
#if ENABLED(STEALTHCHOP)
|
||||
st.pwm_lim(12);
|
||||
st.pwm_reg(8);
|
||||
st.pwm_autograd(1);
|
||||
st.pwm_autoscale(1);
|
||||
st.pwm_freq(1);
|
||||
st.pwm_grad(14);
|
||||
st.pwm_ofs(36);
|
||||
st.en_spreadCycle(false);
|
||||
#if ENABLED(HYBRID_THRESHOLD)
|
||||
st.TPWMTHRS(12650000UL*microsteps/(256*thrs*spmm));
|
||||
#else
|
||||
UNUSED(thrs);
|
||||
UNUSED(spmm);
|
||||
#endif
|
||||
#else
|
||||
st.en_spreadCycle(true);
|
||||
#endif
|
||||
st.GSTAT(0b111); // Clear
|
||||
delay(200);
|
||||
}
|
||||
|
||||
#define _TMC2208_INIT(ST, SPMM) tmc2208_init(stepper##ST, ST##_MICROSTEPS, ST##_HYBRID_THRESHOLD, SPMM)
|
||||
|
||||
void tmc2208_init() {
|
||||
#if ENABLED(X_IS_TMC2208)
|
||||
_TMC2208_INIT(X, planner.axis_steps_per_mm[X_AXIS]);
|
||||
#endif
|
||||
#if ENABLED(X2_IS_TMC2208)
|
||||
_TMC2208_INIT(X2, planner.axis_steps_per_mm[X_AXIS]);
|
||||
#endif
|
||||
#if ENABLED(Y_IS_TMC2208)
|
||||
_TMC2208_INIT(Y, planner.axis_steps_per_mm[Y_AXIS]);
|
||||
#endif
|
||||
#if ENABLED(Y2_IS_TMC2208)
|
||||
_TMC2208_INIT(Y2, planner.axis_steps_per_mm[Y_AXIS]);
|
||||
#endif
|
||||
#if ENABLED(Z_IS_TMC2208)
|
||||
_TMC2208_INIT(Z, planner.axis_steps_per_mm[Z_AXIS]);
|
||||
#endif
|
||||
#if ENABLED(Z2_IS_TMC2208)
|
||||
_TMC2208_INIT(Z2, planner.axis_steps_per_mm[Z_AXIS]);
|
||||
#endif
|
||||
#if ENABLED(E0_IS_TMC2208)
|
||||
_TMC2208_INIT(E0, planner.axis_steps_per_mm[E_AXIS]);
|
||||
#endif
|
||||
#if ENABLED(E1_IS_TMC2208)
|
||||
{ constexpr int extruder = 1; _TMC2208_INIT(E1, planner.axis_steps_per_mm[E_AXIS_N]); }
|
||||
#endif
|
||||
#if ENABLED(E2_IS_TMC2208)
|
||||
{ constexpr int extruder = 2; _TMC2208_INIT(E2, planner.axis_steps_per_mm[E_AXIS_N]); }
|
||||
#endif
|
||||
#if ENABLED(E3_IS_TMC2208)
|
||||
{ constexpr int extruder = 3; _TMC2208_INIT(E3, planner.axis_steps_per_mm[E_AXIS_N]); }
|
||||
#endif
|
||||
#if ENABLED(E4_IS_TMC2208)
|
||||
{ constexpr int extruder = 4; _TMC2208_INIT(E4, planner.axis_steps_per_mm[E_AXIS_N]); }
|
||||
#endif
|
||||
}
|
||||
#endif // HAVE_TMC2208
|
||||
|
||||
|
||||
//
|
||||
// L6470 Driver objects and inits
|
||||
|
@ -58,6 +58,12 @@
|
||||
void tmc2130_init();
|
||||
#endif
|
||||
|
||||
#if ENABLED(HAVE_TMC2208)
|
||||
#include <TMC2208Stepper.h>
|
||||
void tmc2208_serial_begin();
|
||||
void tmc2208_init();
|
||||
#endif
|
||||
|
||||
// L6470 has STEP on normal pins, but DIR/ENABLE via SPI
|
||||
#if ENABLED(HAVE_L6470DRIVER)
|
||||
#include <SPI.h>
|
||||
@ -83,6 +89,8 @@
|
||||
#else
|
||||
#if ENABLED(HAVE_TMC2130) && ENABLED(X_IS_TMC2130)
|
||||
extern TMC2130Stepper stepperX;
|
||||
#elif ENABLED(HAVE_TMC2208) && ENABLED(X_IS_TMC2208)
|
||||
extern TMC2208Stepper stepperX;
|
||||
#endif
|
||||
#define X_ENABLE_INIT SET_OUTPUT(X_ENABLE_PIN)
|
||||
#define X_ENABLE_WRITE(STATE) WRITE(X_ENABLE_PIN,STATE)
|
||||
@ -114,6 +122,8 @@
|
||||
#else
|
||||
#if ENABLED(HAVE_TMC2130) && ENABLED(Y_IS_TMC2130)
|
||||
extern TMC2130Stepper stepperY;
|
||||
#elif ENABLED(HAVE_TMC2208) && ENABLED(Y_IS_TMC2208)
|
||||
extern TMC2208Stepper stepperY;
|
||||
#endif
|
||||
#define Y_ENABLE_INIT SET_OUTPUT(Y_ENABLE_PIN)
|
||||
#define Y_ENABLE_WRITE(STATE) WRITE(Y_ENABLE_PIN,STATE)
|
||||
@ -145,6 +155,8 @@
|
||||
#else
|
||||
#if ENABLED(HAVE_TMC2130) && ENABLED(Z_IS_TMC2130)
|
||||
extern TMC2130Stepper stepperZ;
|
||||
#elif ENABLED(HAVE_TMC2208) && ENABLED(Z_IS_TMC2208)
|
||||
extern TMC2208Stepper stepperZ;
|
||||
#endif
|
||||
#define Z_ENABLE_INIT SET_OUTPUT(Z_ENABLE_PIN)
|
||||
#define Z_ENABLE_WRITE(STATE) WRITE(Z_ENABLE_PIN,STATE)
|
||||
@ -177,6 +189,8 @@
|
||||
#else
|
||||
#if ENABLED(HAVE_TMC2130) && ENABLED(X2_IS_TMC2130)
|
||||
extern TMC2130Stepper stepperX2;
|
||||
#elif ENABLED(HAVE_TMC2208) && ENABLED(X2_IS_TMC2208)
|
||||
extern TMC2208Stepper stepperX2;
|
||||
#endif
|
||||
#define X2_ENABLE_INIT SET_OUTPUT(X2_ENABLE_PIN)
|
||||
#define X2_ENABLE_WRITE(STATE) WRITE(X2_ENABLE_PIN,STATE)
|
||||
@ -210,6 +224,8 @@
|
||||
#else
|
||||
#if ENABLED(HAVE_TMC2130) && ENABLED(Y2_IS_TMC2130)
|
||||
extern TMC2130Stepper stepperY2;
|
||||
#elif ENABLED(HAVE_TMC2208) && ENABLED(Y2_IS_TMC2208)
|
||||
extern TMC2208Stepper stepperY2;
|
||||
#endif
|
||||
#define Y2_ENABLE_INIT SET_OUTPUT(Y2_ENABLE_PIN)
|
||||
#define Y2_ENABLE_WRITE(STATE) WRITE(Y2_ENABLE_PIN,STATE)
|
||||
@ -243,6 +259,8 @@
|
||||
#else
|
||||
#if ENABLED(HAVE_TMC2130) && ENABLED(Z2_IS_TMC2130)
|
||||
extern TMC2130Stepper stepperZ2;
|
||||
#elif ENABLED(HAVE_TMC2208) && ENABLED(Z2_IS_TMC2208)
|
||||
extern TMC2208Stepper stepperZ2;
|
||||
#endif
|
||||
#define Z2_ENABLE_INIT SET_OUTPUT(Z2_ENABLE_PIN)
|
||||
#define Z2_ENABLE_WRITE(STATE) WRITE(Z2_ENABLE_PIN,STATE)
|
||||
@ -275,6 +293,8 @@
|
||||
#else
|
||||
#if ENABLED(HAVE_TMC2130) && ENABLED(E0_IS_TMC2130)
|
||||
extern TMC2130Stepper stepperE0;
|
||||
#elif ENABLED(HAVE_TMC2208) && ENABLED(E0_IS_TMC2208)
|
||||
extern TMC2208Stepper stepperE0;
|
||||
#endif
|
||||
#define E0_ENABLE_INIT SET_OUTPUT(E0_ENABLE_PIN)
|
||||
#define E0_ENABLE_WRITE(STATE) WRITE(E0_ENABLE_PIN,STATE)
|
||||
@ -306,6 +326,8 @@
|
||||
#else
|
||||
#if ENABLED(HAVE_TMC2130) && ENABLED(E1_IS_TMC2130)
|
||||
extern TMC2130Stepper stepperE1;
|
||||
#elif ENABLED(HAVE_TMC2208) && ENABLED(E1_IS_TMC2208)
|
||||
extern TMC2208Stepper stepperE1;
|
||||
#endif
|
||||
#define E1_ENABLE_INIT SET_OUTPUT(E1_ENABLE_PIN)
|
||||
#define E1_ENABLE_WRITE(STATE) WRITE(E1_ENABLE_PIN,STATE)
|
||||
@ -337,6 +359,8 @@
|
||||
#else
|
||||
#if ENABLED(HAVE_TMC2130) && ENABLED(E2_IS_TMC2130)
|
||||
extern TMC2130Stepper stepperE2;
|
||||
#elif ENABLED(HAVE_TMC2208) && ENABLED(E2_IS_TMC2208)
|
||||
extern TMC2208Stepper stepperE2;
|
||||
#endif
|
||||
#define E2_ENABLE_INIT SET_OUTPUT(E2_ENABLE_PIN)
|
||||
#define E2_ENABLE_WRITE(STATE) WRITE(E2_ENABLE_PIN,STATE)
|
||||
@ -368,6 +392,8 @@
|
||||
#else
|
||||
#if ENABLED(HAVE_TMC2130) && ENABLED(E3_IS_TMC2130)
|
||||
extern TMC2130Stepper stepperE3;
|
||||
#elif ENABLED(HAVE_TMC2208) && ENABLED(E3_IS_TMC2208)
|
||||
extern TMC2208Stepper stepperE3;
|
||||
#endif
|
||||
#define E3_ENABLE_INIT SET_OUTPUT(E3_ENABLE_PIN)
|
||||
#define E3_ENABLE_WRITE(STATE) WRITE(E3_ENABLE_PIN,STATE)
|
||||
@ -399,6 +425,8 @@
|
||||
#else
|
||||
#if ENABLED(HAVE_TMC2130) && ENABLED(E4_IS_TMC2130)
|
||||
extern TMC2130Stepper stepperE4;
|
||||
#elif ENABLED(HAVE_TMC2208) && ENABLED(E4_IS_TMC2208)
|
||||
extern TMC2208Stepper stepperE4;
|
||||
#endif
|
||||
#define E4_ENABLE_INIT SET_OUTPUT(E4_ENABLE_PIN)
|
||||
#define E4_ENABLE_WRITE(STATE) WRITE(E4_ENABLE_PIN,STATE)
|
||||
|
Reference in New Issue
Block a user