First attempt at adding TMC Driver support. May need some cleanup.
This commit is contained in:
@ -461,6 +461,67 @@ const unsigned int dropsegments=5; //everything with less than this number of st
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
/******************************************************************************\
|
||||
* enable this section if you have TMC26X motor drivers.
|
||||
* you need to import the TMC26XStepper library into the arduino IDE for this
|
||||
******************************************************************************/
|
||||
|
||||
#define HAVE_TMCDRIVER
|
||||
#ifdef HAVE_TMCDRIVER
|
||||
|
||||
#define X_IS_TMC
|
||||
#define X_MAX_CURRENT 2000 //in mA
|
||||
#define X_SENSE_RESISTOR 91 //in mOhms
|
||||
#define X_MICROSTEPS 16 //number of microsteps
|
||||
|
||||
// #define X2_IS_TMC
|
||||
#define X2_MAX_CURRENT 2000 //in mA
|
||||
#define X2_SENSE_RESISTOR 91 //in mOhms
|
||||
#define X2_MICROSTEPS 16 //number of microsteps
|
||||
|
||||
#define Y_IS_TMC
|
||||
#define Y_MAX_CURRENT 2000 //in mA
|
||||
#define Y_SENSE_RESISTOR 91 //in mOhms
|
||||
#define Y_MICROSTEPS 16 //number of microsteps
|
||||
|
||||
// #define Y2_IS_TMC
|
||||
#define Y2_MAX_CURRENT 2000 //in mA
|
||||
#define Y2_SENSE_RESISTOR 91 //in mOhms
|
||||
#define Y2_MICROSTEPS 16 //number of microsteps
|
||||
|
||||
#define Z_IS_TMC
|
||||
#define Z_MAX_CURRENT 2000 //in mA
|
||||
#define Z_SENSE_RESISTOR 91 //in mOhms
|
||||
#define Z_MICROSTEPS 16 //number of microsteps
|
||||
|
||||
// #define Z2_IS_TMC
|
||||
#define Z2_MAX_CURRENT 2000 //in mA
|
||||
#define Z2_SENSE_RESISTOR 91 //in mOhms
|
||||
#define Z2_MICROSTEPS 16 //number of microsteps
|
||||
|
||||
#define E0_IS_TMC
|
||||
#define E0_MAX_CURRENT 2000 //in mA
|
||||
#define E0_SENSE_RESISTOR 91 //in mOhms
|
||||
#define E0_MICROSTEPS 16 //number of microsteps
|
||||
|
||||
#define E1_IS_TMC
|
||||
#define E1_MAX_CURRENT 2000 //in mA
|
||||
#define E1_SENSE_RESISTOR 91 //in mOhms
|
||||
#define E1_MICROSTEPS 16 //number of microsteps
|
||||
|
||||
// #define E2_IS_TMC
|
||||
#define E2_MAX_CURRENT 2000 //in mA
|
||||
#define E2_SENSE_RESISTOR 91 //in mOhms
|
||||
#define E2_MICROSTEPS 16 //number of microsteps
|
||||
|
||||
// #define E3_IS_TMC
|
||||
#define E3_MAX_CURRENT 2000 //in mA
|
||||
#define E3_SENSE_RESISTOR 91 //in mOhms
|
||||
#define E3_MICROSTEPS 16 //number of microsteps
|
||||
|
||||
#endif
|
||||
|
||||
//===========================================================================
|
||||
//============================= Define Defines ============================
|
||||
//===========================================================================
|
||||
|
@ -54,3 +54,8 @@
|
||||
#if defined(DIGIPOT_I2C)
|
||||
#include <Wire.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_TMCDRIVER
|
||||
#include <SPI.h>
|
||||
#include <TMC26XStepper.h>
|
||||
#endif
|
||||
|
@ -33,7 +33,6 @@
|
||||
#include <SPI.h>
|
||||
#endif
|
||||
|
||||
|
||||
//===========================================================================
|
||||
//=============================public variables ============================
|
||||
//===========================================================================
|
||||
@ -88,6 +87,37 @@ static bool check_endstops = true;
|
||||
volatile long count_position[NUM_AXIS] = { 0, 0, 0, 0};
|
||||
volatile signed char count_direction[NUM_AXIS] = { 1, 1, 1, 1};
|
||||
|
||||
// Stepper objects of TMC steppers are used
|
||||
#ifdef X_IS_TMC
|
||||
TMC26XStepper stepperX(200,X_ENABLE_PIN,X_STEP_PIN,X_DIR_PIN,X_MAX_CURRENT,X_SENSE_RESISTOR);
|
||||
#endif
|
||||
#ifdef X2_IS_TMC
|
||||
TMC26XStepper stepperX2(200,X2_ENABLE_PIN,X2_STEP_PIN,X2_DIR_PIN,X2_MAX_CURRENT,X2_SENSE_RESISTOR);
|
||||
#endif
|
||||
#ifdef Y_IS_TMC
|
||||
TMC26XStepper stepperY(200,Y_ENABLE_PIN,Y_STEP_PIN,Y_DIR_PIN,Y_MAX_CURRENT,Y_SENSE_RESISTOR);
|
||||
#endif
|
||||
#ifdef Y2_IS_TMC
|
||||
TMC26XStepper stepperY2(200,Y2_ENABLE_PIN,Y2_STEP_PIN,Y2_DIR_PIN,Y2_MAX_CURRENT,Y2_SENSE_RESISTOR);
|
||||
#endif
|
||||
#ifdef Z_IS_TMC
|
||||
TMC26XStepper stepperZ(200,Z_ENABLE_PIN,Z_STEP_PIN,Z_DIR_PIN,Z_MAX_CURRENT,Z_SENSE_RESISTOR);
|
||||
#endif
|
||||
#ifdef Z2_IS_TMC
|
||||
TMC26XStepper stepperZ2(200,Z2_ENABLE_PIN,Z2_STEP_PIN,Z2_DIR_PIN,Z2_MAX_CURRENT,Z2_SENSE_RESISTOR);
|
||||
#endif
|
||||
#ifdef E0_IS_TMC
|
||||
TMC26XStepper stepperE0(200,E0_ENABLE_PIN,E0_STEP_PIN,E0_DIR_PIN,E0_MAX_CURRENT,E0_SENSE_RESISTOR);
|
||||
#endif
|
||||
#ifdef E1_IS_TMC
|
||||
TMC26XStepper stepperE1(200,E1_ENABLE_PIN,E1_STEP_PIN,E1_DIR_PIN,E1_MAX_CURRENT,E1_SENSE_RESISTOR);
|
||||
#endif
|
||||
#ifdef E2_IS_TMC
|
||||
TMC26XStepper stepperE2(200,E2_ENABLE_PIN,E2_STEP_PIN,E2_DIR_PIN,E2_MAX_CURRENT,E2_SENSE_RESISTOR);
|
||||
#endif
|
||||
#ifdef E3_IS_TMC
|
||||
TMC26XStepper stepperE3(200,E3_ENABLE_PIN,E3_STEP_PIN,E3_DIR_PIN,E3_MAX_CURRENT,E3_SENSE_RESISTOR);
|
||||
#endif
|
||||
//===========================================================================
|
||||
//=============================functions ============================
|
||||
//===========================================================================
|
||||
@ -838,6 +868,11 @@ void st_init()
|
||||
digipot_init(); //Initialize Digipot Motor Current
|
||||
microstep_init(); //Initialize Microstepping Pins
|
||||
|
||||
// initialise TMC Steppers
|
||||
#ifdef HAVE_TMCDRIVER
|
||||
tmc_init();
|
||||
#endif
|
||||
|
||||
//Initialize Dir Pins
|
||||
#if defined(X_DIR_PIN) && X_DIR_PIN > -1
|
||||
X_DIR_INIT;
|
||||
@ -1386,3 +1421,48 @@ void microstep_readings()
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef HAVE_TMCDRIVER
|
||||
void tmc_init()
|
||||
{
|
||||
#ifdef X_IS_TMC
|
||||
stepperX.setMicrosteps(X_MICROSTEPS);
|
||||
stepperX.start();
|
||||
#endif
|
||||
#ifdef X2_IS_TMC
|
||||
stepperX2.setMicrosteps(X2_MICROSTEPS);
|
||||
stepperX2.start();
|
||||
#endif
|
||||
#ifdef Y_IS_TMC
|
||||
stepperY.setMicrosteps(Y_MICROSTEPS);
|
||||
stepperY.start();
|
||||
#endif
|
||||
#ifdef Y2_IS_TMC
|
||||
stepperY2.setMicrosteps(Y2_MICROSTEPS);
|
||||
stepperY2.start();
|
||||
#endif
|
||||
#ifdef Z_IS_TMC
|
||||
stepperZ.setMicrosteps(Z_MICROSTEPS);
|
||||
stepperZ.start();
|
||||
#endif
|
||||
#ifdef Z2_IS_TMC
|
||||
stepperZ2.setMicrosteps(Z2_MICROSTEPS);
|
||||
stepperZ2.start();
|
||||
#endif
|
||||
#ifdef E0_IS_TMC
|
||||
stepperE0.setMicrosteps(E0_MICROSTEPS);
|
||||
stepperE0.start();
|
||||
#endif
|
||||
#ifdef E1_IS_TMC
|
||||
stepperE1.setMicrosteps(E1_MICROSTEPS);
|
||||
stepperE1.start();
|
||||
#endif
|
||||
#ifdef E2_IS_TMC
|
||||
stepperE2.setMicrosteps(E2_MICROSTEPS);
|
||||
stepperE2.start();
|
||||
#endif
|
||||
#ifdef E3_IS_TMC
|
||||
stepperE3.setMicrosteps(E3_MICROSTEPS);
|
||||
stepperE3.start();
|
||||
#endif
|
||||
}
|
||||
#endif
|
@ -24,6 +24,11 @@
|
||||
#include "planner.h"
|
||||
#include "stepper_indirection.h"
|
||||
|
||||
#ifdef HAVE_TMCDRIVER
|
||||
#include <SPI.h>
|
||||
#include <TMC26XStepper.h>
|
||||
#endif
|
||||
|
||||
#if EXTRUDERS > 3
|
||||
#define WRITE_E_STEP(v) { if(current_block->active_extruder == 3) { E3_STEP_WRITE(v); } else { if(current_block->active_extruder == 2) { E2_STEP_WRITE(v); } else { if(current_block->active_extruder == 1) { E1_STEP_WRITE(v); } else { E0_STEP_WRITE(v); }}}}
|
||||
#define NORM_E_DIR() { if(current_block->active_extruder == 3) { E3_DIR_WRITE( !INVERT_E3_DIR); } else { if(current_block->active_extruder == 2) { E2_DIR_WRITE(!INVERT_E2_DIR); } else { if(current_block->active_extruder == 1) { E1_DIR_WRITE(!INVERT_E1_DIR); } else { E0_DIR_WRITE(!INVERT_E0_DIR); }}}}
|
||||
@ -101,6 +106,39 @@ void microstep_readings();
|
||||
void babystep(const uint8_t axis,const bool direction); // perform a short step with a single stepper motor, outside of any convention
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef HAVE_TMCDRIVER
|
||||
void tmc_init();
|
||||
|
||||
#ifdef X_IS_TMC
|
||||
extern TMC26XStepper stepperX;
|
||||
#endif
|
||||
#ifdef X2_IS_TMC
|
||||
extern TMC26XStepper stepperX2;
|
||||
#endif
|
||||
#ifdef Y_IS_TMC
|
||||
extern TMC26XStepper stepperY;
|
||||
#endif
|
||||
#ifdef Y2_IS_TMC
|
||||
extern TMC26XStepper stepperY2;
|
||||
#endif
|
||||
#ifdef Z_IS_TMC
|
||||
extern TMC26XStepper stepperZ;
|
||||
#endif
|
||||
#ifdef Z2_IS_TMC
|
||||
extern TMC26XStepper stepperZ2;
|
||||
#endif
|
||||
#ifdef E0_IS_TMC
|
||||
extern TMC26XStepper stepperE0;
|
||||
#endif
|
||||
#ifdef E1_IS_TMC
|
||||
extern TMC26XStepper stepperE1;
|
||||
#endif
|
||||
#ifdef E2_IS_TMC
|
||||
extern TMC26XStepper stepperE2;
|
||||
#endif
|
||||
#ifdef E3_IS_TMC
|
||||
extern TMC26XStepper stepperE3;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -152,5 +152,111 @@
|
||||
#define E3_ENABLE_WRITE(STATE) WRITE(E3_ENABLE_PIN,STATE)
|
||||
#define E3_ENABLE_READ READ(E3_ENABLE_PIN)
|
||||
|
||||
//////////////////////////////////
|
||||
// Pin redefines for TMC drivers.
|
||||
// TMC26X drivers have step and dir on normal pins, but everything else via SPI
|
||||
//////////////////////////////////
|
||||
#ifdef HAVE_TMCDRIVER
|
||||
#ifdef X_IS_TMC
|
||||
#undef X_ENABLE_INIT
|
||||
#define X_ENABLE_INIT
|
||||
|
||||
#undef X_ENABLE_WRITE
|
||||
#define X_ENABLE_WRITE(STATE) stepperX.setEnabled(STATE)
|
||||
|
||||
#undef X_ENABLE_READ
|
||||
#define X_ENABLE_READ stepperX.isEnabled()
|
||||
#endif
|
||||
#ifdef X2_IS_TMC
|
||||
#undef X2_ENABLE_INIT
|
||||
#define X2_ENABLE_INIT
|
||||
|
||||
#undef X2_ENABLE_WRITE
|
||||
#define X2_ENABLE_WRITE(STATE) stepperX2.setEnabled(STATE)
|
||||
|
||||
#undef X2_ENABLE_READ
|
||||
#define X2_ENABLE_READ stepperX2.isEnabled()
|
||||
#endif
|
||||
#ifdef Y_IS_TMC
|
||||
#undef Y_ENABLE_INIT
|
||||
#define Y_ENABLE_INIT
|
||||
|
||||
#undef Y_ENABLE_WRITE
|
||||
#define Y_ENABLE_WRITE(STATE) stepperY.setEnabled(STATE)
|
||||
|
||||
#undef Y_ENABLE_READ
|
||||
#define Y_ENABLE_READ stepperY.isEnabled()
|
||||
#endif
|
||||
#ifdef Y2_IS_TMC
|
||||
#undef Y2_ENABLE_INIT
|
||||
#define Y2_ENABLE_INIT
|
||||
|
||||
#undef Y2_ENABLE_WRITE
|
||||
#define Y2_ENABLE_WRITE(STATE) stepperY2.setEnabled(STATE)
|
||||
|
||||
#undef Y2_ENABLE_READ
|
||||
#define Y2_ENABLE_READ stepperY2.isEnabled()
|
||||
#endif
|
||||
#ifdef Z_IS_TMC
|
||||
#undef Z_ENABLE_INIT
|
||||
#define Z_ENABLE_INIT
|
||||
|
||||
#undef Z_ENABLE_WRITE
|
||||
#define Z_ENABLE_WRITE(STATE) stepperZ.setEnabled(STATE)
|
||||
|
||||
#undef Z_ENABLE_READ
|
||||
#define Z_ENABLE_READ stepperZ.isEnabled()
|
||||
#endif
|
||||
#ifdef Z2_IS_TMC
|
||||
#undef Z2_ENABLE_INIT
|
||||
#define Z2_ENABLE_INIT
|
||||
|
||||
#undef Z2_ENABLE_WRITE
|
||||
#define Z2_ENABLE_WRITE(STATE) stepperZ2.setEnabled(STATE)
|
||||
|
||||
#undef Z2_ENABLE_READ
|
||||
#define Z2_ENABLE_READ stepperZ2.isEnabled()
|
||||
#endif
|
||||
#ifdef E0_IS_TMC
|
||||
#undef E0_ENABLE_INIT
|
||||
#define E0_ENABLE_INIT
|
||||
|
||||
#undef E0_ENABLE_WRITE
|
||||
#define E0_ENABLE_WRITE(STATE) stepperE0.setEnabled(STATE)
|
||||
|
||||
#undef E0_ENABLE_READ
|
||||
#define E0_ENABLE_READ stepperE0.isEnabled()
|
||||
#endif
|
||||
#ifdef E1_IS_TMC
|
||||
#undef E1_ENABLE_INIT
|
||||
#define E1_ENABLE_INIT
|
||||
|
||||
#undef E1_ENABLE_WRITE
|
||||
#define E1_ENABLE_WRITE(STATE) stepperE1.setEnabled(STATE)
|
||||
|
||||
#undef E1_ENABLE_READ
|
||||
#define E1_ENABLE_READ stepperE1.isEnabled()
|
||||
#endif
|
||||
#ifdef E2_IS_TMC
|
||||
#undef E2_ENABLE_INIT
|
||||
#define E2_ENABLE_INIT
|
||||
|
||||
#undef E2_ENABLE_WRITE
|
||||
#define E2_ENABLE_WRITE(STATE) stepperE2.setEnabled(STATE)
|
||||
|
||||
#undef E2_ENABLE_READ
|
||||
#define E2_ENABLE_READ stepperE2.isEnabled()
|
||||
#endif
|
||||
#ifdef E3_IS_TMC
|
||||
#undef E3_ENABLE_INIT
|
||||
#define E3_ENABLE_INIT
|
||||
|
||||
#undef E3_ENABLE_WRITE
|
||||
#define E3_ENABLE_WRITE(STATE) stepperE3.setEnabled(STATE)
|
||||
|
||||
#undef E3_ENABLE_READ
|
||||
#define E3_ENABLE_READ stepperE3.isEnabled()
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user