2016-03-25 06:19:46 +00:00
|
|
|
/**
|
2016-03-24 18:01:20 +00:00
|
|
|
* 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/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-03-25 06:19:46 +00:00
|
|
|
/**
|
2017-03-07 05:00:43 +00:00
|
|
|
* stepper_indirection.cpp
|
|
|
|
*
|
|
|
|
* Stepper motor driver indirection to allow some stepper functions to
|
|
|
|
* be done via SPI/I2c instead of direct pin manipulation.
|
|
|
|
*
|
|
|
|
* Part of Marlin
|
|
|
|
*
|
|
|
|
* Copyright (c) 2015 Dominik Wenger
|
|
|
|
*/
|
2015-02-26 11:57:46 +00:00
|
|
|
|
|
|
|
#include "stepper_indirection.h"
|
2016-07-25 01:54:24 +00:00
|
|
|
|
2016-07-26 06:04:19 +00:00
|
|
|
#include "MarlinConfig.h"
|
2015-02-26 11:57:46 +00:00
|
|
|
|
2016-11-07 20:46:01 +00:00
|
|
|
//
|
|
|
|
// TMC26X Driver objects and inits
|
|
|
|
//
|
2018-03-13 07:09:27 +00:00
|
|
|
#if ENABLED(HAVE_TMC26X)
|
2015-07-31 05:28:11 +00:00
|
|
|
#include <SPI.h>
|
|
|
|
#include <TMC26XStepper.h>
|
2015-02-26 11:57:46 +00:00
|
|
|
|
2018-03-18 23:33:56 +00:00
|
|
|
#define _TMC26X_DEFINE(ST) TMC26XStepper stepper##ST(200, ST##_ENABLE_PIN, ST##_STEP_PIN, ST##_DIR_PIN, ST##_MAX_CURRENT, ST##_SENSE_RESISTOR)
|
2017-03-07 05:00:43 +00:00
|
|
|
|
2018-03-13 07:09:27 +00:00
|
|
|
#if ENABLED(X_IS_TMC26X)
|
2018-03-18 23:33:56 +00:00
|
|
|
_TMC26X_DEFINE(X);
|
2015-07-31 05:28:11 +00:00
|
|
|
#endif
|
2018-03-13 07:09:27 +00:00
|
|
|
#if ENABLED(X2_IS_TMC26X)
|
2018-03-18 23:33:56 +00:00
|
|
|
_TMC26X_DEFINE(X2);
|
2015-07-31 05:28:11 +00:00
|
|
|
#endif
|
2018-03-13 07:09:27 +00:00
|
|
|
#if ENABLED(Y_IS_TMC26X)
|
2018-03-18 23:33:56 +00:00
|
|
|
_TMC26X_DEFINE(Y);
|
2015-07-31 05:28:11 +00:00
|
|
|
#endif
|
2018-03-13 07:09:27 +00:00
|
|
|
#if ENABLED(Y2_IS_TMC26X)
|
2018-03-18 23:33:56 +00:00
|
|
|
_TMC26X_DEFINE(Y2);
|
2015-07-31 05:28:11 +00:00
|
|
|
#endif
|
2018-03-13 07:09:27 +00:00
|
|
|
#if ENABLED(Z_IS_TMC26X)
|
2018-03-18 23:33:56 +00:00
|
|
|
_TMC26X_DEFINE(Z);
|
2015-07-31 05:28:11 +00:00
|
|
|
#endif
|
2018-03-13 07:09:27 +00:00
|
|
|
#if ENABLED(Z2_IS_TMC26X)
|
2018-03-18 23:33:56 +00:00
|
|
|
_TMC26X_DEFINE(Z2);
|
2015-07-31 05:28:11 +00:00
|
|
|
#endif
|
2018-03-13 07:09:27 +00:00
|
|
|
#if ENABLED(E0_IS_TMC26X)
|
2018-03-18 23:33:56 +00:00
|
|
|
_TMC26X_DEFINE(E0);
|
2015-07-31 05:28:11 +00:00
|
|
|
#endif
|
2018-03-13 07:09:27 +00:00
|
|
|
#if ENABLED(E1_IS_TMC26X)
|
2018-03-18 23:33:56 +00:00
|
|
|
_TMC26X_DEFINE(E1);
|
2015-07-31 05:28:11 +00:00
|
|
|
#endif
|
2018-03-13 07:09:27 +00:00
|
|
|
#if ENABLED(E2_IS_TMC26X)
|
2018-03-18 23:33:56 +00:00
|
|
|
_TMC26X_DEFINE(E2);
|
2015-07-31 05:28:11 +00:00
|
|
|
#endif
|
2018-03-13 07:09:27 +00:00
|
|
|
#if ENABLED(E3_IS_TMC26X)
|
2018-03-18 23:33:56 +00:00
|
|
|
_TMC26X_DEFINE(E3);
|
2015-07-31 05:28:11 +00:00
|
|
|
#endif
|
2018-03-13 07:09:27 +00:00
|
|
|
#if ENABLED(E4_IS_TMC26X)
|
2018-03-18 23:33:56 +00:00
|
|
|
_TMC26X_DEFINE(E4);
|
2017-04-09 08:23:05 +00:00
|
|
|
#endif
|
2015-02-27 11:43:23 +00:00
|
|
|
|
2018-03-18 23:33:56 +00:00
|
|
|
#define _TMC26X_INIT(A) do{ \
|
2017-03-04 11:17:39 +00:00
|
|
|
stepper##A.setMicrosteps(A##_MICROSTEPS); \
|
|
|
|
stepper##A.start(); \
|
2017-03-07 05:00:43 +00:00
|
|
|
}while(0)
|
2016-11-07 20:46:01 +00:00
|
|
|
|
2018-03-18 23:33:56 +00:00
|
|
|
void tmc26x_init_to_defaults() {
|
2018-03-13 07:09:27 +00:00
|
|
|
#if ENABLED(X_IS_TMC26X)
|
2018-03-18 23:33:56 +00:00
|
|
|
_TMC26X_INIT(X);
|
2016-11-07 20:46:01 +00:00
|
|
|
#endif
|
2018-03-13 07:09:27 +00:00
|
|
|
#if ENABLED(X2_IS_TMC26X)
|
2018-03-18 23:33:56 +00:00
|
|
|
_TMC26X_INIT(X2);
|
2016-11-07 20:46:01 +00:00
|
|
|
#endif
|
2018-03-13 07:09:27 +00:00
|
|
|
#if ENABLED(Y_IS_TMC26X)
|
2018-03-18 23:33:56 +00:00
|
|
|
_TMC26X_INIT(Y);
|
2016-11-07 20:46:01 +00:00
|
|
|
#endif
|
2018-03-13 07:09:27 +00:00
|
|
|
#if ENABLED(Y2_IS_TMC26X)
|
2018-03-18 23:33:56 +00:00
|
|
|
_TMC26X_INIT(Y2);
|
2016-11-07 20:46:01 +00:00
|
|
|
#endif
|
2018-03-13 07:09:27 +00:00
|
|
|
#if ENABLED(Z_IS_TMC26X)
|
2018-03-18 23:33:56 +00:00
|
|
|
_TMC26X_INIT(Z);
|
2016-11-07 20:46:01 +00:00
|
|
|
#endif
|
2018-03-13 07:09:27 +00:00
|
|
|
#if ENABLED(Z2_IS_TMC26X)
|
2018-03-18 23:33:56 +00:00
|
|
|
_TMC26X_INIT(Z2);
|
2016-11-07 20:46:01 +00:00
|
|
|
#endif
|
2018-03-13 07:09:27 +00:00
|
|
|
#if ENABLED(E0_IS_TMC26X)
|
2018-03-18 23:33:56 +00:00
|
|
|
_TMC26X_INIT(E0);
|
2016-11-07 20:46:01 +00:00
|
|
|
#endif
|
2018-03-13 07:09:27 +00:00
|
|
|
#if ENABLED(E1_IS_TMC26X)
|
2018-03-18 23:33:56 +00:00
|
|
|
_TMC26X_INIT(E1);
|
2016-11-07 20:46:01 +00:00
|
|
|
#endif
|
2018-03-13 07:09:27 +00:00
|
|
|
#if ENABLED(E2_IS_TMC26X)
|
2018-03-18 23:33:56 +00:00
|
|
|
_TMC26X_INIT(E2);
|
2016-11-07 20:46:01 +00:00
|
|
|
#endif
|
2018-03-13 07:09:27 +00:00
|
|
|
#if ENABLED(E3_IS_TMC26X)
|
2018-03-18 23:33:56 +00:00
|
|
|
_TMC26X_INIT(E3);
|
2016-11-07 20:46:01 +00:00
|
|
|
#endif
|
2018-03-13 07:09:27 +00:00
|
|
|
#if ENABLED(E4_IS_TMC26X)
|
2018-03-18 23:33:56 +00:00
|
|
|
_TMC26X_INIT(E4);
|
2017-04-09 08:23:05 +00:00
|
|
|
#endif
|
2016-11-07 20:46:01 +00:00
|
|
|
}
|
2018-03-13 07:09:27 +00:00
|
|
|
#endif // HAVE_TMC26X
|
2016-11-07 20:46:01 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// TMC2130 Driver objects and inits
|
|
|
|
//
|
2017-03-07 05:00:43 +00:00
|
|
|
#if ENABLED(HAVE_TMC2130)
|
2016-11-07 20:35:14 +00:00
|
|
|
|
2016-09-14 06:48:47 +00:00
|
|
|
#include <SPI.h>
|
2017-03-07 05:00:43 +00:00
|
|
|
#include <TMC2130Stepper.h>
|
2017-12-15 21:02:39 +00:00
|
|
|
#include "planner.h"
|
2017-04-15 03:44:08 +00:00
|
|
|
#include "enum.h"
|
2016-09-14 06:48:47 +00:00
|
|
|
|
2018-03-23 22:00:25 +00:00
|
|
|
#if TMC2130STEPPER_VERSION < 0x020201
|
|
|
|
#error "Update TMC2130Stepper library to 2.2.1 or newer."
|
|
|
|
#endif
|
|
|
|
|
2018-02-02 09:56:08 +00:00
|
|
|
#if ENABLED(TMC_USE_SW_SPI)
|
|
|
|
#define _TMC2130_DEFINE(ST) TMC2130Stepper stepper##ST(ST##_ENABLE_PIN, ST##_DIR_PIN, ST##_STEP_PIN, ST##_CS_PIN, TMC_SW_MOSI, TMC_SW_MISO, TMC_SW_SCK)
|
|
|
|
#else
|
|
|
|
#define _TMC2130_DEFINE(ST) TMC2130Stepper stepper##ST(ST##_ENABLE_PIN, ST##_DIR_PIN, ST##_STEP_PIN, ST##_CS_PIN)
|
|
|
|
#endif
|
|
|
|
|
2017-03-07 05:00:43 +00:00
|
|
|
// Stepper objects of TMC2130 steppers used
|
2016-11-07 20:35:14 +00:00
|
|
|
#if ENABLED(X_IS_TMC2130)
|
2017-03-07 05:00:43 +00:00
|
|
|
_TMC2130_DEFINE(X);
|
2016-11-07 20:35:14 +00:00
|
|
|
#endif
|
|
|
|
#if ENABLED(X2_IS_TMC2130)
|
2017-03-07 05:00:43 +00:00
|
|
|
_TMC2130_DEFINE(X2);
|
2016-11-07 20:35:14 +00:00
|
|
|
#endif
|
|
|
|
#if ENABLED(Y_IS_TMC2130)
|
2017-03-07 05:00:43 +00:00
|
|
|
_TMC2130_DEFINE(Y);
|
2016-11-07 20:35:14 +00:00
|
|
|
#endif
|
|
|
|
#if ENABLED(Y2_IS_TMC2130)
|
2017-03-07 05:00:43 +00:00
|
|
|
_TMC2130_DEFINE(Y2);
|
2016-11-07 20:35:14 +00:00
|
|
|
#endif
|
|
|
|
#if ENABLED(Z_IS_TMC2130)
|
2017-03-07 05:00:43 +00:00
|
|
|
_TMC2130_DEFINE(Z);
|
2016-11-07 20:35:14 +00:00
|
|
|
#endif
|
|
|
|
#if ENABLED(Z2_IS_TMC2130)
|
2017-03-07 05:00:43 +00:00
|
|
|
_TMC2130_DEFINE(Z2);
|
2016-11-07 20:35:14 +00:00
|
|
|
#endif
|
|
|
|
#if ENABLED(E0_IS_TMC2130)
|
2017-03-07 05:00:43 +00:00
|
|
|
_TMC2130_DEFINE(E0);
|
2016-11-07 20:35:14 +00:00
|
|
|
#endif
|
|
|
|
#if ENABLED(E1_IS_TMC2130)
|
2017-03-07 05:00:43 +00:00
|
|
|
_TMC2130_DEFINE(E1);
|
2016-11-07 20:35:14 +00:00
|
|
|
#endif
|
|
|
|
#if ENABLED(E2_IS_TMC2130)
|
2017-03-07 05:00:43 +00:00
|
|
|
_TMC2130_DEFINE(E2);
|
2016-11-07 20:35:14 +00:00
|
|
|
#endif
|
|
|
|
#if ENABLED(E3_IS_TMC2130)
|
2017-03-07 05:00:43 +00:00
|
|
|
_TMC2130_DEFINE(E3);
|
2016-11-07 20:35:14 +00:00
|
|
|
#endif
|
2017-04-09 08:23:05 +00:00
|
|
|
#if ENABLED(E4_IS_TMC2130)
|
|
|
|
_TMC2130_DEFINE(E4);
|
|
|
|
#endif
|
2016-11-07 20:35:14 +00:00
|
|
|
|
2017-03-07 05:00:43 +00:00
|
|
|
// Use internal reference voltage for current calculations. This is the default.
|
|
|
|
// Following values from Trinamic's spreadsheet with values for a NEMA17 (42BYGHW609)
|
2017-04-15 03:44:08 +00:00
|
|
|
// https://www.trinamic.com/products/integrated-circuits/details/tmc2130/
|
2018-03-18 23:33:56 +00:00
|
|
|
void tmc2130_init(TMC2130Stepper &st, const uint16_t mA, const uint16_t microsteps, const uint32_t thrs, const float spmm) {
|
2017-03-07 05:00:43 +00:00
|
|
|
st.begin();
|
2018-03-18 23:33:56 +00:00
|
|
|
st.setCurrent(mA, R_SENSE, HOLD_MULTIPLIER);
|
2017-03-07 05:00:43 +00:00
|
|
|
st.microsteps(microsteps);
|
2017-12-15 21:02:39 +00:00
|
|
|
st.blank_time(24);
|
2017-04-15 03:44:08 +00:00
|
|
|
st.off_time(5); // Only enables the driver if used with stealthChop
|
2017-03-07 05:00:43 +00:00
|
|
|
st.interpolate(INTERPOLATE);
|
2017-04-15 03:44:08 +00:00
|
|
|
st.power_down_delay(128); // ~2s until driver lowers to hold current
|
2018-03-16 02:01:45 +00:00
|
|
|
st.hysteresis_start(3);
|
|
|
|
st.hysteresis_end(2);
|
2017-04-15 03:44:08 +00:00
|
|
|
st.diag1_active_high(1); // For sensorless homing
|
2017-03-07 05:00:43 +00:00
|
|
|
#if ENABLED(STEALTHCHOP)
|
2017-04-15 03:44:08 +00:00
|
|
|
st.stealth_freq(1); // f_pwm = 2/683 f_clk
|
|
|
|
st.stealth_autoscale(1);
|
|
|
|
st.stealth_gradient(5);
|
|
|
|
st.stealth_amplitude(255);
|
2017-03-07 05:00:43 +00:00
|
|
|
st.stealthChop(1);
|
2017-04-15 03:44:08 +00:00
|
|
|
#if ENABLED(HYBRID_THRESHOLD)
|
2017-12-15 21:02:39 +00:00
|
|
|
st.stealth_max_speed(12650000UL*microsteps/(256*thrs*spmm));
|
|
|
|
#else
|
|
|
|
UNUSED(thrs);
|
|
|
|
UNUSED(spmm);
|
2017-04-15 03:44:08 +00:00
|
|
|
#endif
|
|
|
|
#elif ENABLED(SENSORLESS_HOMING)
|
|
|
|
st.coolstep_min_speed(1024UL * 1024UL - 1UL);
|
2017-03-07 05:00:43 +00:00
|
|
|
#endif
|
2017-12-15 21:02:39 +00:00
|
|
|
st.GSTAT(); // Clear GSTAT
|
2017-03-07 05:00:43 +00:00
|
|
|
}
|
|
|
|
|
2018-03-18 23:33:56 +00:00
|
|
|
#define _TMC2130_INIT(ST, SPMM) tmc2130_init(stepper##ST, ST##_CURRENT, ST##_MICROSTEPS, ST##_HYBRID_THRESHOLD, SPMM)
|
2017-03-07 05:00:43 +00:00
|
|
|
|
2018-03-18 23:33:56 +00:00
|
|
|
void tmc2130_init_to_defaults() {
|
2016-11-07 20:35:14 +00:00
|
|
|
#if ENABLED(X_IS_TMC2130)
|
2017-12-15 21:02:39 +00:00
|
|
|
_TMC2130_INIT( X, planner.axis_steps_per_mm[X_AXIS]);
|
2016-11-07 20:35:14 +00:00
|
|
|
#endif
|
|
|
|
#if ENABLED(X2_IS_TMC2130)
|
2017-12-15 21:02:39 +00:00
|
|
|
_TMC2130_INIT(X2, planner.axis_steps_per_mm[X_AXIS]);
|
2016-11-07 20:35:14 +00:00
|
|
|
#endif
|
|
|
|
#if ENABLED(Y_IS_TMC2130)
|
2017-12-15 21:02:39 +00:00
|
|
|
_TMC2130_INIT( Y, planner.axis_steps_per_mm[Y_AXIS]);
|
2016-11-07 20:35:14 +00:00
|
|
|
#endif
|
|
|
|
#if ENABLED(Y2_IS_TMC2130)
|
2017-12-15 21:02:39 +00:00
|
|
|
_TMC2130_INIT(Y2, planner.axis_steps_per_mm[Y_AXIS]);
|
2016-11-07 20:35:14 +00:00
|
|
|
#endif
|
|
|
|
#if ENABLED(Z_IS_TMC2130)
|
2017-12-15 21:02:39 +00:00
|
|
|
_TMC2130_INIT( Z, planner.axis_steps_per_mm[Z_AXIS]);
|
2016-11-07 20:35:14 +00:00
|
|
|
#endif
|
|
|
|
#if ENABLED(Z2_IS_TMC2130)
|
2017-12-15 21:02:39 +00:00
|
|
|
_TMC2130_INIT(Z2, planner.axis_steps_per_mm[Z_AXIS]);
|
2016-11-07 20:35:14 +00:00
|
|
|
#endif
|
|
|
|
#if ENABLED(E0_IS_TMC2130)
|
2017-12-15 21:02:39 +00:00
|
|
|
_TMC2130_INIT(E0, planner.axis_steps_per_mm[E_AXIS]);
|
2016-11-07 20:35:14 +00:00
|
|
|
#endif
|
|
|
|
#if ENABLED(E1_IS_TMC2130)
|
2017-12-15 21:02:39 +00:00
|
|
|
{ constexpr int extruder = 1; _TMC2130_INIT(E1, planner.axis_steps_per_mm[E_AXIS_N]); }
|
2016-11-07 20:35:14 +00:00
|
|
|
#endif
|
|
|
|
#if ENABLED(E2_IS_TMC2130)
|
2017-12-15 21:02:39 +00:00
|
|
|
{ constexpr int extruder = 2; _TMC2130_INIT(E2, planner.axis_steps_per_mm[E_AXIS_N]); }
|
2016-11-07 20:35:14 +00:00
|
|
|
#endif
|
|
|
|
#if ENABLED(E3_IS_TMC2130)
|
2017-12-15 21:02:39 +00:00
|
|
|
{ constexpr int extruder = 3; _TMC2130_INIT(E3, planner.axis_steps_per_mm[E_AXIS_N]); }
|
2016-11-07 20:35:14 +00:00
|
|
|
#endif
|
2017-04-09 08:23:05 +00:00
|
|
|
#if ENABLED(E4_IS_TMC2130)
|
2017-12-15 21:02:39 +00:00
|
|
|
{ constexpr int extruder = 4; _TMC2130_INIT(E4, planner.axis_steps_per_mm[E_AXIS_N]); }
|
2017-04-09 08:23:05 +00:00
|
|
|
#endif
|
2017-03-07 05:00:43 +00:00
|
|
|
|
2018-03-18 23:33:56 +00:00
|
|
|
#if ENABLED(SENSORLESS_HOMING)
|
|
|
|
#define TMC_INIT_SGT(P,Q) stepper##Q.sgt(P##_HOMING_SENSITIVITY);
|
|
|
|
#ifdef X_HOMING_SENSITIVITY
|
|
|
|
#if ENABLED(X_IS_TMC2130) || ENABLED(IS_TRAMS)
|
|
|
|
stepperX.sgt(X_HOMING_SENSITIVITY);
|
|
|
|
#endif
|
|
|
|
#if ENABLED(X2_IS_TMC2130)
|
|
|
|
stepperX2.sgt(X_HOMING_SENSITIVITY);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#ifdef Y_HOMING_SENSITIVITY
|
|
|
|
#if ENABLED(Y_IS_TMC2130) || ENABLED(IS_TRAMS)
|
|
|
|
stepperY.sgt(Y_HOMING_SENSITIVITY);
|
|
|
|
#endif
|
|
|
|
#if ENABLED(Y2_IS_TMC2130)
|
|
|
|
stepperY2.sgt(Y_HOMING_SENSITIVITY);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#ifdef Z_HOMING_SENSITIVITY
|
|
|
|
#if ENABLED(Z_IS_TMC2130) || ENABLED(IS_TRAMS)
|
|
|
|
stepperZ.sgt(Z_HOMING_SENSITIVITY);
|
|
|
|
#endif
|
|
|
|
#if ENABLED(Z2_IS_TMC2130)
|
|
|
|
stepperZ2.sgt(Z_HOMING_SENSITIVITY);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#endif
|
2016-11-07 20:35:14 +00:00
|
|
|
}
|
2018-03-18 23:33:56 +00:00
|
|
|
|
2017-03-07 05:00:43 +00:00
|
|
|
#endif // HAVE_TMC2130
|
2016-11-07 20:35:14 +00:00
|
|
|
|
2017-12-15 21:02:39 +00:00
|
|
|
//
|
|
|
|
// TMC2208 Driver objects and inits
|
|
|
|
//
|
|
|
|
#if ENABLED(HAVE_TMC2208)
|
|
|
|
|
2018-02-23 18:33:14 +00:00
|
|
|
#undef HardwareSerial_h // undo Marlin trickery
|
2017-12-15 21:02:39 +00:00
|
|
|
#include <SoftwareSerial.h>
|
|
|
|
#include <HardwareSerial.h>
|
|
|
|
#include <TMC2208Stepper.h>
|
|
|
|
#include "planner.h"
|
|
|
|
|
2018-03-23 22:00:25 +00:00
|
|
|
#if TMC2208STEPPER_VERSION < 0x000101
|
|
|
|
#error "Update TMC2208Stepper library to 0.1.1 or newer."
|
|
|
|
#endif
|
|
|
|
|
2017-12-15 21:02:39 +00:00
|
|
|
#define _TMC2208_DEFINE_HARDWARE(ST) TMC2208Stepper stepper##ST(&ST##_HARDWARE_SERIAL)
|
2018-01-22 15:25:11 +00:00
|
|
|
#define _TMC2208_DEFINE_SOFTWARE(ST) SoftwareSerial ST##_HARDWARE_SERIAL = SoftwareSerial(ST##_SERIAL_RX_PIN, ST##_SERIAL_TX_PIN); \
|
2018-01-23 19:58:16 +00:00
|
|
|
TMC2208Stepper stepper##ST(&ST##_HARDWARE_SERIAL, ST##_SERIAL_RX_PIN > -1)
|
2017-12-15 21:02:39 +00:00
|
|
|
|
|
|
|
// Stepper objects of TMC2208 steppers used
|
|
|
|
#if ENABLED(X_IS_TMC2208)
|
2018-01-22 15:25:11 +00:00
|
|
|
#ifdef X_HARDWARE_SERIAL
|
2017-12-15 21:02:39 +00:00
|
|
|
_TMC2208_DEFINE_HARDWARE(X);
|
|
|
|
#else
|
|
|
|
_TMC2208_DEFINE_SOFTWARE(X);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#if ENABLED(X2_IS_TMC2208)
|
2018-01-22 15:25:11 +00:00
|
|
|
#ifdef X2_HARDWARE_SERIAL
|
2017-12-15 21:02:39 +00:00
|
|
|
_TMC2208_DEFINE_HARDWARE(X2);
|
|
|
|
#else
|
|
|
|
_TMC2208_DEFINE_SOFTWARE(X2);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#if ENABLED(Y_IS_TMC2208)
|
2018-01-22 15:25:11 +00:00
|
|
|
#ifdef Y_HARDWARE_SERIAL
|
2017-12-15 21:02:39 +00:00
|
|
|
_TMC2208_DEFINE_HARDWARE(Y);
|
|
|
|
#else
|
|
|
|
_TMC2208_DEFINE_SOFTWARE(Y);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#if ENABLED(Y2_IS_TMC2208)
|
2018-01-22 15:25:11 +00:00
|
|
|
#ifdef Y2_HARDWARE_SERIAL
|
2017-12-15 21:02:39 +00:00
|
|
|
_TMC2208_DEFINE_HARDWARE(Y2);
|
|
|
|
#else
|
|
|
|
_TMC2208_DEFINE_SOFTWARE(Y2);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#if ENABLED(Z_IS_TMC2208)
|
2018-01-22 15:25:11 +00:00
|
|
|
#ifdef Z_HARDWARE_SERIAL
|
2017-12-15 21:02:39 +00:00
|
|
|
_TMC2208_DEFINE_HARDWARE(Z);
|
|
|
|
#else
|
|
|
|
_TMC2208_DEFINE_SOFTWARE(Z);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#if ENABLED(Z2_IS_TMC2208)
|
2018-01-22 15:25:11 +00:00
|
|
|
#ifdef Z2_HARDWARE_SERIAL
|
2017-12-15 21:02:39 +00:00
|
|
|
_TMC2208_DEFINE_HARDWARE(Z2);
|
|
|
|
#else
|
|
|
|
_TMC2208_DEFINE_SOFTWARE(Z2);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#if ENABLED(E0_IS_TMC2208)
|
2018-01-22 15:25:11 +00:00
|
|
|
#ifdef E0_HARDWARE_SERIAL
|
2017-12-15 21:02:39 +00:00
|
|
|
_TMC2208_DEFINE_HARDWARE(E0);
|
|
|
|
#else
|
|
|
|
_TMC2208_DEFINE_SOFTWARE(E0);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#if ENABLED(E1_IS_TMC2208)
|
2018-01-22 15:25:11 +00:00
|
|
|
#ifdef E1_HARDWARE_SERIAL
|
2017-12-15 21:02:39 +00:00
|
|
|
_TMC2208_DEFINE_HARDWARE(E1);
|
|
|
|
#else
|
|
|
|
_TMC2208_DEFINE_SOFTWARE(E1);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#if ENABLED(E2_IS_TMC2208)
|
2018-01-22 15:25:11 +00:00
|
|
|
#ifdef E2_HARDWARE_SERIAL
|
2017-12-15 21:02:39 +00:00
|
|
|
_TMC2208_DEFINE_HARDWARE(E2);
|
|
|
|
#else
|
|
|
|
_TMC2208_DEFINE_SOFTWARE(E2);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#if ENABLED(E3_IS_TMC2208)
|
2018-01-22 15:25:11 +00:00
|
|
|
#ifdef E3_HARDWARE_SERIAL
|
2017-12-15 21:02:39 +00:00
|
|
|
_TMC2208_DEFINE_HARDWARE(E3);
|
|
|
|
#else
|
|
|
|
_TMC2208_DEFINE_SOFTWARE(E3);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#if ENABLED(E4_IS_TMC2208)
|
2018-01-22 15:25:11 +00:00
|
|
|
#ifdef E4_HARDWARE_SERIAL
|
2017-12-15 21:02:39 +00:00
|
|
|
_TMC2208_DEFINE_HARDWARE(E4);
|
|
|
|
#else
|
|
|
|
_TMC2208_DEFINE_SOFTWARE(E4);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void tmc2208_serial_begin() {
|
2018-01-22 15:25:11 +00:00
|
|
|
#if ENABLED(X_IS_TMC2208)
|
|
|
|
X_HARDWARE_SERIAL.begin(115200);
|
2017-12-15 21:02:39 +00:00
|
|
|
#endif
|
2018-01-22 15:25:11 +00:00
|
|
|
#if ENABLED(X2_IS_TMC2208)
|
|
|
|
X2_HARDWARE_SERIAL.begin(115200);
|
2017-12-15 21:02:39 +00:00
|
|
|
#endif
|
2018-01-22 15:25:11 +00:00
|
|
|
#if ENABLED(Y_IS_TMC2208)
|
|
|
|
Y_HARDWARE_SERIAL.begin(115200);
|
2017-12-15 21:02:39 +00:00
|
|
|
#endif
|
2018-01-22 15:25:11 +00:00
|
|
|
#if ENABLED(Y2_IS_TMC2208)
|
|
|
|
Y2_HARDWARE_SERIAL.begin(115200);
|
2017-12-15 21:02:39 +00:00
|
|
|
#endif
|
2018-01-22 15:25:11 +00:00
|
|
|
#if ENABLED(Z_IS_TMC2208)
|
|
|
|
Z_HARDWARE_SERIAL.begin(115200);
|
2017-12-15 21:02:39 +00:00
|
|
|
#endif
|
2018-01-22 15:25:11 +00:00
|
|
|
#if ENABLED(Z2_IS_TMC2208)
|
|
|
|
Z2_HARDWARE_SERIAL.begin(115200);
|
2017-12-15 21:02:39 +00:00
|
|
|
#endif
|
2018-01-22 15:25:11 +00:00
|
|
|
#if ENABLED(E0_IS_TMC2208)
|
|
|
|
E0_HARDWARE_SERIAL.begin(115200);
|
2017-12-15 21:02:39 +00:00
|
|
|
#endif
|
2018-01-22 15:25:11 +00:00
|
|
|
#if ENABLED(E1_IS_TMC2208)
|
|
|
|
E1_HARDWARE_SERIAL.begin(115200);
|
2017-12-15 21:02:39 +00:00
|
|
|
#endif
|
2018-01-22 15:25:11 +00:00
|
|
|
#if ENABLED(E2_IS_TMC2208)
|
|
|
|
E2_HARDWARE_SERIAL.begin(115200);
|
2017-12-15 21:02:39 +00:00
|
|
|
#endif
|
2018-01-22 15:25:11 +00:00
|
|
|
#if ENABLED(E3_IS_TMC2208)
|
|
|
|
E3_HARDWARE_SERIAL.begin(115200);
|
2017-12-15 21:02:39 +00:00
|
|
|
#endif
|
2018-01-22 15:25:11 +00:00
|
|
|
#if ENABLED(E4_IS_TMC2208)
|
|
|
|
E4_HARDWARE_SERIAL.begin(115200);
|
2017-12-15 21:02:39 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use internal reference voltage for current calculations. This is the default.
|
|
|
|
// Following values from Trinamic's spreadsheet with values for a NEMA17 (42BYGHW609)
|
2018-03-18 23:33:56 +00:00
|
|
|
void tmc2208_init(TMC2208Stepper &st, const uint16_t mA, const uint16_t microsteps, const uint32_t thrs, const float spmm) {
|
2017-12-15 21:02:39 +00:00
|
|
|
st.pdn_disable(true); // Use UART
|
|
|
|
st.mstep_reg_select(true); // Select microsteps with UART
|
|
|
|
st.I_scale_analog(false);
|
2018-03-18 23:33:56 +00:00
|
|
|
st.rms_current(mA, HOLD_MULTIPLIER, R_SENSE);
|
2017-12-15 21:02:39 +00:00
|
|
|
st.microsteps(microsteps);
|
|
|
|
st.blank_time(24);
|
|
|
|
st.toff(5);
|
|
|
|
st.intpol(INTERPOLATE);
|
|
|
|
st.TPOWERDOWN(128); // ~2s until driver lowers to hold current
|
2018-03-16 02:01:45 +00:00
|
|
|
st.hysteresis_start(3);
|
|
|
|
st.hysteresis_end(2);
|
2017-12-15 21:02:39 +00:00
|
|
|
#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);
|
|
|
|
}
|
|
|
|
|
2018-03-18 23:33:56 +00:00
|
|
|
#define _TMC2208_INIT(ST, SPMM) tmc2208_init(stepper##ST, ST##_CURRENT, ST##_MICROSTEPS, ST##_HYBRID_THRESHOLD, SPMM)
|
2017-12-15 21:02:39 +00:00
|
|
|
|
2018-03-18 23:33:56 +00:00
|
|
|
void tmc2208_init_to_defaults() {
|
2017-12-15 21:02:39 +00:00
|
|
|
#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
|
|
|
|
}
|
2018-03-18 23:33:56 +00:00
|
|
|
|
2017-12-15 21:02:39 +00:00
|
|
|
#endif // HAVE_TMC2208
|
2016-09-14 06:48:47 +00:00
|
|
|
|
2018-03-18 23:33:56 +00:00
|
|
|
void restore_stepper_drivers() {
|
|
|
|
#if X_IS_TRINAMIC
|
|
|
|
stepperX.push();
|
|
|
|
#endif
|
|
|
|
#if X2_IS_TRINAMIC
|
|
|
|
stepperX2.push();
|
|
|
|
#endif
|
|
|
|
#if Y_IS_TRINAMIC
|
|
|
|
stepperY.push();
|
|
|
|
#endif
|
|
|
|
#if Y2_IS_TRINAMIC
|
|
|
|
stepperY2.push();
|
|
|
|
#endif
|
|
|
|
#if Z_IS_TRINAMIC
|
|
|
|
stepperZ.push();
|
|
|
|
#endif
|
|
|
|
#if Z2_IS_TRINAMIC
|
|
|
|
stepperZ2.push();
|
|
|
|
#endif
|
|
|
|
#if E0_IS_TRINAMIC
|
|
|
|
stepperE0.push();
|
|
|
|
#endif
|
|
|
|
#if E1_IS_TRINAMIC
|
|
|
|
stepperE1.push();
|
|
|
|
#endif
|
|
|
|
#if E2_IS_TRINAMIC
|
|
|
|
stepperE2.push();
|
|
|
|
#endif
|
|
|
|
#if E3_IS_TRINAMIC
|
|
|
|
stepperE3.push();
|
|
|
|
#endif
|
|
|
|
#if E4_IS_TRINAMIC
|
|
|
|
stepperE4.push();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void reset_stepper_drivers() {
|
|
|
|
#if ENABLED(HAVE_TMC26X)
|
|
|
|
tmc26x_init_to_defaults();
|
|
|
|
#endif
|
|
|
|
#if ENABLED(HAVE_TMC2130)
|
|
|
|
tmc2130_init_to_defaults();
|
|
|
|
#endif
|
|
|
|
#if ENABLED(HAVE_TMC2208)
|
|
|
|
tmc2208_init_to_defaults();
|
|
|
|
#endif
|
|
|
|
#ifdef TMC_ADV
|
|
|
|
TMC_ADV()
|
|
|
|
#endif
|
|
|
|
#if ENABLED(HAVE_L6470DRIVER)
|
|
|
|
L6470_init_to_defaults();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-11-07 20:46:01 +00:00
|
|
|
//
|
2015-02-27 11:43:23 +00:00
|
|
|
// L6470 Driver objects and inits
|
2016-11-07 20:46:01 +00:00
|
|
|
//
|
2015-07-31 05:28:11 +00:00
|
|
|
#if ENABLED(HAVE_L6470DRIVER)
|
2016-11-07 20:46:01 +00:00
|
|
|
|
2015-10-03 06:08:58 +00:00
|
|
|
#include <SPI.h>
|
|
|
|
#include <L6470.h>
|
2015-02-27 11:43:23 +00:00
|
|
|
|
2017-03-07 05:00:43 +00:00
|
|
|
#define _L6470_DEFINE(ST) L6470 stepper##ST(ST##_ENABLE_PIN)
|
|
|
|
|
2016-11-07 20:46:01 +00:00
|
|
|
// L6470 Stepper objects
|
2015-07-31 05:28:11 +00:00
|
|
|
#if ENABLED(X_IS_L6470)
|
2017-03-07 05:00:43 +00:00
|
|
|
_L6470_DEFINE(X);
|
2015-07-31 05:28:11 +00:00
|
|
|
#endif
|
|
|
|
#if ENABLED(X2_IS_L6470)
|
2017-03-07 05:00:43 +00:00
|
|
|
_L6470_DEFINE(X2);
|
2015-07-31 05:28:11 +00:00
|
|
|
#endif
|
|
|
|
#if ENABLED(Y_IS_L6470)
|
2017-03-07 05:00:43 +00:00
|
|
|
_L6470_DEFINE(Y);
|
2015-07-31 05:28:11 +00:00
|
|
|
#endif
|
|
|
|
#if ENABLED(Y2_IS_L6470)
|
2017-03-07 05:00:43 +00:00
|
|
|
_L6470_DEFINE(Y2);
|
2015-07-31 05:28:11 +00:00
|
|
|
#endif
|
|
|
|
#if ENABLED(Z_IS_L6470)
|
2017-03-07 05:00:43 +00:00
|
|
|
_L6470_DEFINE(Z);
|
2015-07-31 05:28:11 +00:00
|
|
|
#endif
|
|
|
|
#if ENABLED(Z2_IS_L6470)
|
2017-03-07 05:00:43 +00:00
|
|
|
_L6470_DEFINE(Z2);
|
2015-07-31 05:28:11 +00:00
|
|
|
#endif
|
|
|
|
#if ENABLED(E0_IS_L6470)
|
2017-03-07 05:00:43 +00:00
|
|
|
_L6470_DEFINE(E0);
|
2015-07-31 05:28:11 +00:00
|
|
|
#endif
|
|
|
|
#if ENABLED(E1_IS_L6470)
|
2017-03-07 05:00:43 +00:00
|
|
|
_L6470_DEFINE(E1);
|
2015-07-31 05:28:11 +00:00
|
|
|
#endif
|
|
|
|
#if ENABLED(E2_IS_L6470)
|
2017-03-07 05:00:43 +00:00
|
|
|
_L6470_DEFINE(E2);
|
2015-07-31 05:28:11 +00:00
|
|
|
#endif
|
|
|
|
#if ENABLED(E3_IS_L6470)
|
2017-03-07 05:00:43 +00:00
|
|
|
_L6470_DEFINE(E3);
|
2015-10-03 06:08:58 +00:00
|
|
|
#endif
|
2017-04-09 08:23:05 +00:00
|
|
|
#if ENABLED(E4_IS_L6470)
|
|
|
|
_L6470_DEFINE(E4);
|
|
|
|
#endif
|
2016-11-07 20:46:01 +00:00
|
|
|
|
|
|
|
#define _L6470_INIT(A) do{ \
|
2017-12-31 03:53:56 +00:00
|
|
|
stepper##A.init(); \
|
2016-11-07 20:46:01 +00:00
|
|
|
stepper##A.softFree(); \
|
|
|
|
stepper##A.setMicroSteps(A##_MICROSTEPS); \
|
|
|
|
stepper##A.setOverCurrent(A##_OVERCURRENT); \
|
|
|
|
stepper##A.setStallCurrent(A##_STALLCURRENT); \
|
2017-06-15 20:17:41 +00:00
|
|
|
}while(0)
|
2016-11-07 20:46:01 +00:00
|
|
|
|
2018-03-18 23:33:56 +00:00
|
|
|
void L6470_init_to_defaults() {
|
2016-11-07 20:46:01 +00:00
|
|
|
#if ENABLED(X_IS_L6470)
|
|
|
|
_L6470_INIT(X);
|
|
|
|
#endif
|
|
|
|
#if ENABLED(X2_IS_L6470)
|
|
|
|
_L6470_INIT(X2);
|
|
|
|
#endif
|
|
|
|
#if ENABLED(Y_IS_L6470)
|
|
|
|
_L6470_INIT(Y);
|
|
|
|
#endif
|
|
|
|
#if ENABLED(Y2_IS_L6470)
|
|
|
|
_L6470_INIT(Y2);
|
|
|
|
#endif
|
|
|
|
#if ENABLED(Z_IS_L6470)
|
|
|
|
_L6470_INIT(Z);
|
|
|
|
#endif
|
|
|
|
#if ENABLED(Z2_IS_L6470)
|
|
|
|
_L6470_INIT(Z2);
|
|
|
|
#endif
|
|
|
|
#if ENABLED(E0_IS_L6470)
|
|
|
|
_L6470_INIT(E0);
|
|
|
|
#endif
|
|
|
|
#if ENABLED(E1_IS_L6470)
|
|
|
|
_L6470_INIT(E1);
|
|
|
|
#endif
|
|
|
|
#if ENABLED(E2_IS_L6470)
|
|
|
|
_L6470_INIT(E2);
|
|
|
|
#endif
|
|
|
|
#if ENABLED(E3_IS_L6470)
|
|
|
|
_L6470_INIT(E3);
|
|
|
|
#endif
|
2017-04-09 08:23:05 +00:00
|
|
|
#if ENABLED(E4_IS_L6470)
|
|
|
|
_L6470_INIT(E4);
|
|
|
|
#endif
|
2016-11-07 20:46:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // HAVE_L6470DRIVER
|