From f6a8e1df9d7551ba6b3b81b8a342cf159af0028e Mon Sep 17 00:00:00 2001 From: Robert Pelnar Date: Sat, 1 Jul 2017 12:39:16 +0200 Subject: [PATCH 1/2] TMC2130 + software SG homing + LF lineendings + tmc2130 debug M-Codes M910 - tmc2130_init M911 - set holding currents M912 - set running currents M913 - print currents --- Firmware/Configuration.h | 14 +- Firmware/Marlin.h | 6 +- Firmware/Marlin_main.cpp | 122 ++++- Firmware/pat9125.cpp | 148 +++--- Firmware/pat9125.h | 76 ++-- Firmware/stepper.cpp | 56 ++- Firmware/stepper.h | 2 + Firmware/swspi.cpp | 214 ++++----- Firmware/swspi.h | 96 ++-- Firmware/temperature.cpp | 102 ++--- Firmware/temperature.h | 6 +- Firmware/tmc2130.cpp | 422 ++++++++++-------- Firmware/tmc2130.h | 43 +- .../variants/1_75mm_MK2-EINY01-E3Dv6full.h | 52 +-- 14 files changed, 765 insertions(+), 594 deletions(-) diff --git a/Firmware/Configuration.h b/Firmware/Configuration.h index 387b10e1..5a4e3b1b 100644 --- a/Firmware/Configuration.h +++ b/Firmware/Configuration.h @@ -267,10 +267,10 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of #define DISABLE_E false // For all extruders #define DISABLE_INACTIVE_EXTRUDER true //disable only inactive extruders and keep active extruder enabled -#define INVERT_X_DIR false // for Mendel set to false, for Orca set to true +#define INVERT_X_DIR true // for Mendel set to false, for Orca set to true #define INVERT_Y_DIR false // for Mendel set to true, for Orca set to false -#define INVERT_Z_DIR false // for Mendel set to false, for Orca set to true -#define INVERT_E0_DIR true // for direct drive extruder v9 set to true, for geared extruder set to false +#define INVERT_Z_DIR true // for Mendel set to false, for Orca set to true +#define INVERT_E0_DIR false // for direct drive extruder v9 set to true, for geared extruder set to false #define INVERT_E1_DIR false // for direct drive extruder v9 set to true, for geared extruder set to false #define INVERT_E2_DIR false // for direct drive extruder v9 set to true, for geared extruder set to false @@ -424,8 +424,8 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of // #define EXTRUDER_OFFSET_Y {0.0, 5.00} // (in mm) for each extruder, offset of the hotend on the Y axis // The speed change that does not require acceleration (i.e. the software might assume it can be done instantaneously) -#define DEFAULT_XJERK 10.0 // (mm/sec) -#define DEFAULT_YJERK 10.0 // (mm/sec) +#define DEFAULT_XJERK 5.0 // (mm/sec) +#define DEFAULT_YJERK 5.0 // (mm/sec) #define DEFAULT_ZJERK 0.2 // (mm/sec) #define DEFAULT_EJERK 2.5 // (mm/sec) @@ -461,8 +461,8 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of #define SDSUPPORT // Enable SD Card Support in Hardware Console //#define SDSLOW // Use slower SD transfer mode (not normally needed - uncomment if you're getting volume init error) #define SD_CHECK_AND_RETRY // Use CRC checks and retries on the SD communication -#define ENCODER_PULSES_PER_STEP 4 // Increase if you have a high resolution encoder -#define ENCODER_STEPS_PER_MENU_ITEM 1 // Set according to ENCODER_PULSES_PER_STEP or your liking +#define ENCODER_PULSES_PER_STEP 2 // Increase if you have a high resolution encoder +#define ENCODER_STEPS_PER_MENU_ITEM 2 // Set according to ENCODER_PULSES_PER_STEP or your liking //#define ULTIMAKERCONTROLLER //as available from the Ultimaker online store. //#define ULTIPANEL //the UltiPanel as on Thingiverse //#define LCD_FEEDBACK_FREQUENCY_HZ 1000 // this is the tone frequency the buzzer plays when on UI feedback. ie Screen Click diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h index 96f1607c..178b0aca 100644 --- a/Firmware/Marlin.h +++ b/Firmware/Marlin.h @@ -302,9 +302,9 @@ extern unsigned int custom_message_state; extern char snmm_filaments_used; extern unsigned long PingTime; -extern bool fan_state[2]; -extern int fan_edge_counter[2]; -extern int fan_speed[2]; +extern bool fan_state[2]; +extern int fan_edge_counter[2]; +extern int fan_speed[2]; // Handling multiple extruders pins extern uint8_t active_extruder; diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index eabf8a0c..8cf44b73 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -1803,7 +1803,7 @@ static float probe_pt(float x, float y, float z_before) { } #endif // #ifdef ENABLE_AUTO_BED_LEVELING - +/* void homeaxis(int axis) { #define HOMEAXIS_DO(LETTER) \ ((LETTER##_MIN_PIN > -1 && LETTER##_HOME_DIR==-1) || (LETTER##_MAX_PIN > -1 && LETTER##_HOME_DIR==1)) @@ -1814,7 +1814,8 @@ void homeaxis(int axis) { 0) { int axis_home_dir = home_dir(axis); #ifdef HAVE_TMC2130_DRIVERS - tmc2130_st_home_enter(axis); + if ((axis == X_AXIS) || (axis == Y_AXIS)) + tmc2130_home_enter(axis); #endif //HAVE_TMC2130_DRIVERS current_position[axis] = 0; @@ -1832,7 +1833,7 @@ void homeaxis(int axis) { st_synchronize(); destination[axis] = 2*home_retract_mm(axis) * axis_home_dir; - feedrate = homing_feedrate[axis]/2 ; +// feedrate = homing_feedrate[axis]/2 ; plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); st_synchronize(); axis_is_at_home(axis); @@ -1842,11 +1843,93 @@ void homeaxis(int axis) { axis_known_position[axis] = true; #ifdef HAVE_TMC2130_DRIVERS - tmc2130_st_home_enter(axis); + if ((axis == X_AXIS) || (axis == Y_AXIS)) + tmc2130_home_exit(); #endif //HAVE_TMC2130_DRIVERS } } +/**/ +void homeaxis(int axis) { +#define HOMEAXIS_DO(LETTER) \ +((LETTER##_MIN_PIN > -1 && LETTER##_HOME_DIR==-1) || (LETTER##_MAX_PIN > -1 && LETTER##_HOME_DIR==1)) + + if (axis==X_AXIS ? HOMEAXIS_DO(X) : + axis==Y_AXIS ? HOMEAXIS_DO(Y) : + 0) { + int axis_home_dir = home_dir(axis); + +#ifdef HAVE_TMC2130_DRIVERS + tmc2130_home_enter(axis); +#endif + + current_position[axis] = 0; + plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); + + destination[axis] = 1.5 * max_length(axis) * axis_home_dir; + feedrate = homing_feedrate[axis]; + plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); + +// sg_homing_delay = 0; + st_synchronize(); + + current_position[axis] = 0; + plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); + destination[axis] = -home_retract_mm(axis) * axis_home_dir; + plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); +// sg_homing_delay = 0; + st_synchronize(); + + destination[axis] = 2*home_retract_mm(axis) * axis_home_dir; +#ifdef HAVE_TMC2130_DRIVERS + if (tmc2130_didLastHomingStall()) + feedrate = homing_feedrate[axis]; + else +#endif + feedrate = homing_feedrate[axis] / 2; + plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); +// sg_homing_delay = 0; + st_synchronize(); + axis_is_at_home(axis); + destination[axis] = current_position[axis]; + feedrate = 0.0; + endstops_hit_on_purpose(); + axis_known_position[axis] = true; + +#ifdef HAVE_TMC2130_DRIVERS + tmc2130_home_exit(); +#endif + } + else if (axis==Z_AXIS ? HOMEAXIS_DO(Z) : + 0) { + int axis_home_dir = home_dir(axis); + + current_position[axis] = 0; + plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); + + destination[axis] = 1.5 * max_length(axis) * axis_home_dir; + feedrate = homing_feedrate[axis]; + plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); + st_synchronize(); + + current_position[axis] = 0; + plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); + destination[axis] = -home_retract_mm(axis) * axis_home_dir; + plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); + st_synchronize(); + + destination[axis] = 2*home_retract_mm(axis) * axis_home_dir; + feedrate = homing_feedrate[axis]/2 ; + plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feedrate/60, active_extruder); + st_synchronize(); + axis_is_at_home(axis); + destination[axis] = current_position[axis]; + feedrate = 0.0; + endstops_hit_on_purpose(); + axis_known_position[axis] = true; + } +} +/**/ void home_xy() { set_destination_to_current(); @@ -5399,6 +5482,37 @@ case 404: //M404 Enter the nominal filament width (3mm, 1.75mm ) N<3.0> or disp #endif } break; + + case 910: // M910 TMC2130 init + { + tmc2130_init(); + } + break; + + case 911: // M911 Set TMC2130 holding currents + { + if (code_seen('X')) tmc2130_set_current_h(0, code_value()); + if (code_seen('Y')) tmc2130_set_current_h(1, code_value()); + if (code_seen('Z')) tmc2130_set_current_h(2, code_value()); + if (code_seen('E')) tmc2130_set_current_h(3, code_value()); + } + break; + + case 912: // M912 Set TMC2130 running currents + { + if (code_seen('X')) tmc2130_set_current_r(0, code_value()); + if (code_seen('Y')) tmc2130_set_current_r(1, code_value()); + if (code_seen('Z')) tmc2130_set_current_r(2, code_value()); + if (code_seen('E')) tmc2130_set_current_r(3, code_value()); + } + break; + + case 913: // M912 Print TMC2130 currents + { + tmc2130_print_currents(); + } + break; + case 350: // M350 Set microstepping mode. Warning: Steps per unit remains unchanged. S code sets stepping mode for all drivers. { #if defined(X_MS1_PIN) && X_MS1_PIN > -1 diff --git a/Firmware/pat9125.cpp b/Firmware/pat9125.cpp index fefb8335..50a4aea8 100755 --- a/Firmware/pat9125.cpp +++ b/Firmware/pat9125.cpp @@ -1,74 +1,74 @@ -#include "pat9125.h" -#include "swspi.h" - - -#ifdef SWSPI_RPI -// #include - #define DELAY(delay) usleep(delay) -#endif //SWSPI_RPI - -#ifdef SWSPI_AVR - #include "Arduino.h" - #define DELAY(delay) delayMicroseconds(delay) -#endif //SWSPI_AVR - -unsigned char ucPID1 = 0; -unsigned char ucPID2 = 0; -int pat9125_x = 0; -int pat9125_y = 0; - -int pat9125_init(unsigned char xres, unsigned char yres) -{ - swspi_init(); - ucPID1 = pat9125_rd_reg(PAT9125_PID1); - ucPID2 = pat9125_rd_reg(PAT9125_PID2); - if ((ucPID1 != 0x31) || (ucPID2 != 0x91)) - { - return 0; - } - pat9125_wr_reg(PAT9125_RES_X, xres); - pat9125_wr_reg(PAT9125_RES_Y, yres); - return 1; -} - -int pat9125_update() -{ - if ((ucPID1 == 0x31) && (ucPID2 == 0x91)) - { - unsigned char ucMotion = pat9125_rd_reg(PAT9125_MOTION); - if (ucMotion & 0x80) - { - int iDX = pat9125_rd_reg(PAT9125_DELTA_XL); - int iDY = pat9125_rd_reg(PAT9125_DELTA_YL); - if (iDX >= 0x80) iDX = iDX - 256; - if (iDY >= 0x80) iDY = iDY - 256; - pat9125_x += iDX; - pat9125_y += iDY; - return 1; - } - } - return 0; -} - -unsigned char pat9125_rd_reg(unsigned char addr) -{ - swspi_start(); - DELAY(100); - swspi_tx(addr & 0x7f); - DELAY(100); - unsigned char data = swspi_rx(); - swspi_stop(); - DELAY(100); - return data; -} - -void pat9125_wr_reg(unsigned char addr, unsigned char data) -{ - swspi_start(); - DELAY(100); - swspi_tx(addr | 0x80); - DELAY(100); - swspi_tx(data); - swspi_stop(); - DELAY(100); -} +#include "pat9125.h" +#include "swspi.h" + + +#ifdef SWSPI_RPI +// #include + #define DELAY(delay) usleep(delay) +#endif //SWSPI_RPI + +#ifdef SWSPI_AVR + #include "Arduino.h" + #define DELAY(delay) delayMicroseconds(delay) +#endif //SWSPI_AVR + +unsigned char ucPID1 = 0; +unsigned char ucPID2 = 0; +int pat9125_x = 0; +int pat9125_y = 0; + +int pat9125_init(unsigned char xres, unsigned char yres) +{ + swspi_init(); + ucPID1 = pat9125_rd_reg(PAT9125_PID1); + ucPID2 = pat9125_rd_reg(PAT9125_PID2); + if ((ucPID1 != 0x31) || (ucPID2 != 0x91)) + { + return 0; + } + pat9125_wr_reg(PAT9125_RES_X, xres); + pat9125_wr_reg(PAT9125_RES_Y, yres); + return 1; +} + +int pat9125_update() +{ + if ((ucPID1 == 0x31) && (ucPID2 == 0x91)) + { + unsigned char ucMotion = pat9125_rd_reg(PAT9125_MOTION); + if (ucMotion & 0x80) + { + int iDX = pat9125_rd_reg(PAT9125_DELTA_XL); + int iDY = pat9125_rd_reg(PAT9125_DELTA_YL); + if (iDX >= 0x80) iDX = iDX - 256; + if (iDY >= 0x80) iDY = iDY - 256; + pat9125_x += iDX; + pat9125_y += iDY; + return 1; + } + } + return 0; +} + +unsigned char pat9125_rd_reg(unsigned char addr) +{ + swspi_start(); + DELAY(100); + swspi_tx(addr & 0x7f); + DELAY(100); + unsigned char data = swspi_rx(); + swspi_stop(); + DELAY(100); + return data; +} + +void pat9125_wr_reg(unsigned char addr, unsigned char data) +{ + swspi_start(); + DELAY(100); + swspi_tx(addr | 0x80); + DELAY(100); + swspi_tx(data); + swspi_stop(); + DELAY(100); +} diff --git a/Firmware/pat9125.h b/Firmware/pat9125.h index d7600a7b..eecd77a5 100755 --- a/Firmware/pat9125.h +++ b/Firmware/pat9125.h @@ -1,38 +1,38 @@ -#ifndef PAT9125_H -#define PAT9125_H - -//#define PAT9125_RPI -#define PAT9125_AVR - -//PAT9125 registers -#define PAT9125_PID1 0x00 -#define PAT9125_PID2 0x01 -#define PAT9125_MOTION 0x02 -#define PAT9125_DELTA_XL 0x03 -#define PAT9125_DELTA_YL 0x04 -#define PAT9125_MODE 0x05 -#define PAT9125_CONFIG 0x06 -#define PAT9125_WP 0x09 -#define PAT9125_SLEEP1 0x0a -#define PAT9125_SLEEP2 0x0b -#define PAT9125_RES_X 0x0d -#define PAT9125_RES_Y 0x0e -#define PAT9125_DELTA_XYH 0x12 -#define PAT9125_SHUTTER 0x14 -#define PAT9125_FRAME 0x17 -#define PAT9125_ORIENTATION 0x19 - -extern unsigned char ucPID1; -extern unsigned char ucPID2; - -extern int pat9125_x; -extern int pat9125_y; - -int pat9125_init(unsigned char xres, unsigned char yres); -int pat9125_update(); - -unsigned char pat9125_rd_reg(unsigned char addr); -void pat9125_wr_reg(unsigned char addr, unsigned char data); - - -#endif //PAT9125_H +#ifndef PAT9125_H +#define PAT9125_H + +//#define PAT9125_RPI +#define PAT9125_AVR + +//PAT9125 registers +#define PAT9125_PID1 0x00 +#define PAT9125_PID2 0x01 +#define PAT9125_MOTION 0x02 +#define PAT9125_DELTA_XL 0x03 +#define PAT9125_DELTA_YL 0x04 +#define PAT9125_MODE 0x05 +#define PAT9125_CONFIG 0x06 +#define PAT9125_WP 0x09 +#define PAT9125_SLEEP1 0x0a +#define PAT9125_SLEEP2 0x0b +#define PAT9125_RES_X 0x0d +#define PAT9125_RES_Y 0x0e +#define PAT9125_DELTA_XYH 0x12 +#define PAT9125_SHUTTER 0x14 +#define PAT9125_FRAME 0x17 +#define PAT9125_ORIENTATION 0x19 + +extern unsigned char ucPID1; +extern unsigned char ucPID2; + +extern int pat9125_x; +extern int pat9125_y; + +int pat9125_init(unsigned char xres, unsigned char yres); +int pat9125_update(); + +unsigned char pat9125_rd_reg(unsigned char addr); +void pat9125_wr_reg(unsigned char addr, unsigned char data); + + +#endif //PAT9125_H diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index 4cadd180..547671eb 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -83,11 +83,12 @@ static bool old_y_max_endstop=false; static bool old_z_min_endstop=false; static bool old_z_max_endstop=false; -#ifdef SG_HOMING +#ifdef SG_HOMING_SW static bool check_endstops = false; #else static bool check_endstops = true; #endif + static bool check_z_endstop = false; int8_t SilentMode; @@ -403,7 +404,11 @@ ISR(TIMER1_COMPA_vect) { { #if defined(X_MIN_PIN) && X_MIN_PIN > -1 - bool x_min_endstop=(READ(X_MIN_PIN) != X_MIN_ENDSTOP_INVERTING); + #ifndef SG_HOMING_SW + bool x_min_endstop = (READ(X_MIN_PIN) != X_MIN_ENDSTOP_INVERTING); + #else //SG_HOMING_SW + bool x_min_endstop = tmc2130_axis_stalled[X_AXIS]; + #endif //SG_HOMING_SW if(x_min_endstop && old_x_min_endstop && (current_block->steps_x > 0)) { endstops_trigsteps[X_AXIS] = count_position[X_AXIS]; endstop_x_hit=true; @@ -419,7 +424,11 @@ ISR(TIMER1_COMPA_vect) { { #if defined(X_MAX_PIN) && X_MAX_PIN > -1 - bool x_max_endstop=(READ(X_MAX_PIN) != X_MAX_ENDSTOP_INVERTING); + #ifndef SG_HOMING_SW + bool x_max_endstop = (READ(X_MAX_PIN) != X_MAX_ENDSTOP_INVERTING); + #else //SG_HOMING_SW + bool x_max_endstop = tmc2130_axis_stalled[X_AXIS]; + #endif //SG_HOMING_SW if(x_max_endstop && old_x_max_endstop && (current_block->steps_x > 0)){ endstops_trigsteps[X_AXIS] = count_position[X_AXIS]; endstop_x_hit=true; @@ -439,7 +448,11 @@ ISR(TIMER1_COMPA_vect) CHECK_ENDSTOPS { #if defined(Y_MIN_PIN) && Y_MIN_PIN > -1 - bool y_min_endstop=(READ(Y_MIN_PIN) != Y_MIN_ENDSTOP_INVERTING); + #ifndef SG_HOMING_SW + bool y_min_endstop=(READ(Y_MIN_PIN) != Y_MIN_ENDSTOP_INVERTING); + #else //SG_HOMING_SW + bool y_min_endstop = tmc2130_axis_stalled[Y_AXIS]; + #endif //SG_HOMING_SW if(y_min_endstop && old_y_min_endstop && (current_block->steps_y > 0)) { endstops_trigsteps[Y_AXIS] = count_position[Y_AXIS]; endstop_y_hit=true; @@ -453,7 +466,11 @@ ISR(TIMER1_COMPA_vect) CHECK_ENDSTOPS { #if defined(Y_MAX_PIN) && Y_MAX_PIN > -1 - bool y_max_endstop=(READ(Y_MAX_PIN) != Y_MAX_ENDSTOP_INVERTING); + #ifndef SG_HOMING_SW + bool y_max_endstop=(READ(Y_MAX_PIN) != Y_MAX_ENDSTOP_INVERTING); + #else //SG_HOMING_SW + bool y_max_endstop = tmc2130_axis_stalled[Y_AXIS]; + #endif //SG_HOMING_SW if(y_max_endstop && old_y_max_endstop && (current_block->steps_y > 0)){ endstops_trigsteps[Y_AXIS] = count_position[Y_AXIS]; endstop_y_hit=true; @@ -864,15 +881,23 @@ void st_init() // Block until all buffered steps are executed void st_synchronize() { - while( blocks_queued()) { - manage_heater(); - // Vojtech: Don't disable motors inside the planner! - manage_inactivity(true); - lcd_update(); + while(blocks_queued()) + { #ifdef HAVE_TMC2130_DRIVERS - tmc2130_st_synchronize(); + manage_heater(); + // Vojtech: Don't disable motors inside the planner! + if (!tmc2130_update_sg()) + { + manage_inactivity(true); + lcd_update(); + } +#else //HAVE_TMC2130_DRIVERS + manage_heater(); + // Vojtech: Don't disable motors inside the planner! + manage_inactivity(true); + lcd_update(); #endif //HAVE_TMC2130_DRIVERS - } + } } void st_set_position(const long &x, const long &y, const long &z, const long &e) @@ -901,6 +926,13 @@ long st_get_position(uint8_t axis) return count_pos; } +void st_get_position_xy(long &x, long &y) +{ + CRITICAL_SECTION_START; + x = count_position[X_AXIS]; + y = count_position[Y_AXIS]; + CRITICAL_SECTION_END; +} float st_get_position_mm(uint8_t axis) { diff --git a/Firmware/stepper.h b/Firmware/stepper.h index 14192b91..5a09f07a 100644 --- a/Firmware/stepper.h +++ b/Firmware/stepper.h @@ -54,6 +54,8 @@ void st_set_e_position(const long &e); // Get current position in steps long st_get_position(uint8_t axis); +// Get current x and y position in steps +void st_get_position_xy(long &x, long &y); // Get current position in mm float st_get_position_mm(uint8_t axis); diff --git a/Firmware/swspi.cpp b/Firmware/swspi.cpp index ca681e90..1eac73ce 100755 --- a/Firmware/swspi.cpp +++ b/Firmware/swspi.cpp @@ -1,107 +1,107 @@ -#include "swspi.h" - - -#ifdef SWSPI_RPI - #include - #define GPIO_INP(gpio) bcm2835_gpio_fsel(gpio, BCM2835_GPIO_FSEL_INPT) - #define GPIO_OUT(gpio) bcm2835_gpio_fsel(gpio, BCM2835_GPIO_FSEL_OUTP) - #define GPIO_SET(gpio) bcm2835_gpio_write(gpio, HIGH) - #define GPIO_CLR(gpio) bcm2835_gpio_write(gpio, LOW) - #define GPIO_GET(gpio) (bcm2835_gpio_lev(gpio) != LOW) - #define DELAY(delay) usleep(delay) -#endif //SWSPI_RPI - -#ifdef SWSPI_AVR - #include "Arduino.h" - #define GPIO_INP(gpio) pinMode(gpio, INPUT) - #define GPIO_OUT(gpio) pinMode(gpio, OUTPUT) - #define GPIO_SET(gpio) digitalWrite(gpio, HIGH) - #define GPIO_CLR(gpio) digitalWrite(gpio, LOW) - #define GPIO_GET(gpio) (digitalRead(gpio) != LOW) - #define DELAY(delay) delayMicroseconds(delay) -#endif //SWSPI_AVR - -#if (SWSPI_POL != 0) - #define SWSPI_SCK_UP GPIO_CLR(SWSPI_SCK) - #define SWSPI_SCK_DN GPIO_SET(SWSPI_SCK) -#else - #define SWSPI_SCK_UP GPIO_SET(SWSPI_SCK) - #define SWSPI_SCK_DN GPIO_CLR(SWSPI_SCK) -#endif - - -void swspi_init() -{ - GPIO_INP(SWSPI_MISO); - GPIO_OUT(SWSPI_MOSI); - GPIO_OUT(SWSPI_SCK); - GPIO_OUT(SWSPI_CS); - GPIO_CLR(SWSPI_MOSI); - SWSPI_SCK_DN; - GPIO_SET(SWSPI_CS); -} - -#if (SWSPI_MOSI == SWSPI_MISO) - -void swspi_tx(unsigned char tx) -{ - GPIO_OUT(SWSPI_MOSI); - unsigned char i = 0; for (; i < 8; i++) - { - if (tx & 0x80) GPIO_SET(SWSPI_MOSI); - else GPIO_CLR(SWSPI_MOSI); - DELAY(SWSPI_DEL); - SWSPI_SCK_UP; - DELAY(SWSPI_DEL); - SWSPI_SCK_DN; - tx <<= 1; - } -} - -unsigned char swspi_rx() -{ - GPIO_INP(SWSPI_MISO); - unsigned char rx = 0; - unsigned char i = 0; for (; i < 8; i++) - { - rx <<= 1; - DELAY(SWSPI_DEL); - SWSPI_SCK_UP; - DELAY(SWSPI_DEL); - rx |= GPIO_GET(SWSPI_MISO)?1:0; - SWSPI_SCK_DN; - } - return rx; -} - -#else //(SWSPI_MOSI == SWSPI_MISO) - -unsigned char swspi_txrx(unsigned char tx) -{ - unsigned char rx = 0; - unsigned char i = 0; for (; i < 8; i++) - { - rx <<= 1; - if (tx & 0x80) GPIO_SET(SWSPI_MOSI); - else GPIO_CLR(SWSPI_MOSI); - DELAY(SWSPI_DEL); - SWSPI_SCK_UP; - DELAY(SWSPI_DEL); - rx |= GPIO_GET(SWSPI_MISO)?1:0; - SWSPI_SCK_DN; - tx <<= 1; - } - return rx; -} - -#endif //(SWSPI_MOSI == SWSPI_MISO) - -void swspi_start() -{ - GPIO_CLR(SWSPI_CS); -} - -void swspi_stop() -{ - GPIO_SET(SWSPI_CS); -} +#include "swspi.h" + + +#ifdef SWSPI_RPI + #include + #define GPIO_INP(gpio) bcm2835_gpio_fsel(gpio, BCM2835_GPIO_FSEL_INPT) + #define GPIO_OUT(gpio) bcm2835_gpio_fsel(gpio, BCM2835_GPIO_FSEL_OUTP) + #define GPIO_SET(gpio) bcm2835_gpio_write(gpio, HIGH) + #define GPIO_CLR(gpio) bcm2835_gpio_write(gpio, LOW) + #define GPIO_GET(gpio) (bcm2835_gpio_lev(gpio) != LOW) + #define DELAY(delay) usleep(delay) +#endif //SWSPI_RPI + +#ifdef SWSPI_AVR + #include "Arduino.h" + #define GPIO_INP(gpio) pinMode(gpio, INPUT) + #define GPIO_OUT(gpio) pinMode(gpio, OUTPUT) + #define GPIO_SET(gpio) digitalWrite(gpio, HIGH) + #define GPIO_CLR(gpio) digitalWrite(gpio, LOW) + #define GPIO_GET(gpio) (digitalRead(gpio) != LOW) + #define DELAY(delay) delayMicroseconds(delay) +#endif //SWSPI_AVR + +#if (SWSPI_POL != 0) + #define SWSPI_SCK_UP GPIO_CLR(SWSPI_SCK) + #define SWSPI_SCK_DN GPIO_SET(SWSPI_SCK) +#else + #define SWSPI_SCK_UP GPIO_SET(SWSPI_SCK) + #define SWSPI_SCK_DN GPIO_CLR(SWSPI_SCK) +#endif + + +void swspi_init() +{ + GPIO_INP(SWSPI_MISO); + GPIO_OUT(SWSPI_MOSI); + GPIO_OUT(SWSPI_SCK); + GPIO_OUT(SWSPI_CS); + GPIO_CLR(SWSPI_MOSI); + SWSPI_SCK_DN; + GPIO_SET(SWSPI_CS); +} + +#if (SWSPI_MOSI == SWSPI_MISO) + +void swspi_tx(unsigned char tx) +{ + GPIO_OUT(SWSPI_MOSI); + unsigned char i = 0; for (; i < 8; i++) + { + if (tx & 0x80) GPIO_SET(SWSPI_MOSI); + else GPIO_CLR(SWSPI_MOSI); + DELAY(SWSPI_DEL); + SWSPI_SCK_UP; + DELAY(SWSPI_DEL); + SWSPI_SCK_DN; + tx <<= 1; + } +} + +unsigned char swspi_rx() +{ + GPIO_INP(SWSPI_MISO); + unsigned char rx = 0; + unsigned char i = 0; for (; i < 8; i++) + { + rx <<= 1; + DELAY(SWSPI_DEL); + SWSPI_SCK_UP; + DELAY(SWSPI_DEL); + rx |= GPIO_GET(SWSPI_MISO)?1:0; + SWSPI_SCK_DN; + } + return rx; +} + +#else //(SWSPI_MOSI == SWSPI_MISO) + +unsigned char swspi_txrx(unsigned char tx) +{ + unsigned char rx = 0; + unsigned char i = 0; for (; i < 8; i++) + { + rx <<= 1; + if (tx & 0x80) GPIO_SET(SWSPI_MOSI); + else GPIO_CLR(SWSPI_MOSI); + DELAY(SWSPI_DEL); + SWSPI_SCK_UP; + DELAY(SWSPI_DEL); + rx |= GPIO_GET(SWSPI_MISO)?1:0; + SWSPI_SCK_DN; + tx <<= 1; + } + return rx; +} + +#endif //(SWSPI_MOSI == SWSPI_MISO) + +void swspi_start() +{ + GPIO_CLR(SWSPI_CS); +} + +void swspi_stop() +{ + GPIO_SET(SWSPI_CS); +} diff --git a/Firmware/swspi.h b/Firmware/swspi.h index f601acd5..ef93556c 100755 --- a/Firmware/swspi.h +++ b/Firmware/swspi.h @@ -1,48 +1,48 @@ -#ifndef SWSPI_H -#define SWSPI_H - - -//#define SWSPI_RPI -#define SWSPI_AVR - -#ifdef SWSPI_RPI -//#define SWSPI_MISO 9 -#define SWSPI_MISO 10 -#define SWSPI_MOSI 10 -#define SWSPI_SCK 11 -#define SWSPI_CS 7 -#endif //SWSPI_RPI - -#ifdef SWSPI_AVR -#define SWSPI_MISO 16 -#define SWSPI_MOSI 16 -#define SWSPI_SCK 17 -#define SWSPI_CS 20 -#endif //SWSPI_AVR - -#define SWSPI_POL 1 //polarity -#define SWSPI_PHA 0 //phase -#define SWSPI_DOR 0 //data order -#define SWSPI_DEL 100 //delay - - -void swspi_init(); - -#if (SWSPI_MOSI == SWSPI_MISO) - -void swspi_tx(unsigned char tx); -unsigned char swspi_rx(); - -#else //(SWSPI_MOSI == SWSPI_MISO) - -#define swspi_tx swspi_txrx -#define swspi_rx swspi_txrx -unsigned char swspi_txrx(unsigned char tx); - -#endif //(SWSPI_MOSI == SWSPI_MISO) - -void swspi_start(); -void swspi_stop(); - - -#endif //SWSPI_H +#ifndef SWSPI_H +#define SWSPI_H + + +//#define SWSPI_RPI +#define SWSPI_AVR + +#ifdef SWSPI_RPI +//#define SWSPI_MISO 9 +#define SWSPI_MISO 10 +#define SWSPI_MOSI 10 +#define SWSPI_SCK 11 +#define SWSPI_CS 7 +#endif //SWSPI_RPI + +#ifdef SWSPI_AVR +#define SWSPI_MISO 16 +#define SWSPI_MOSI 16 +#define SWSPI_SCK 17 +#define SWSPI_CS 20 +#endif //SWSPI_AVR + +#define SWSPI_POL 1 //polarity +#define SWSPI_PHA 0 //phase +#define SWSPI_DOR 0 //data order +#define SWSPI_DEL 100 //delay + + +void swspi_init(); + +#if (SWSPI_MOSI == SWSPI_MISO) + +void swspi_tx(unsigned char tx); +unsigned char swspi_rx(); + +#else //(SWSPI_MOSI == SWSPI_MISO) + +#define swspi_tx swspi_txrx +#define swspi_rx swspi_txrx +unsigned char swspi_txrx(unsigned char tx); + +#endif //(SWSPI_MOSI == SWSPI_MISO) + +void swspi_start(); +void swspi_stop(); + + +#endif //SWSPI_H diff --git a/Firmware/temperature.cpp b/Firmware/temperature.cpp index b91f5313..3b07b6fe 100644 --- a/Firmware/temperature.cpp +++ b/Firmware/temperature.cpp @@ -405,55 +405,55 @@ void setExtruderAutoFanState(int pin, bool state) analogWrite(pin, newFanSpeed); } -void countFanSpeed() -{ - fan_speed[0] = (fan_edge_counter[0] * (float(250) / (millis() - extruder_autofan_last_check))); - fan_speed[1] = (fan_edge_counter[1] * (float(250) / (millis() - extruder_autofan_last_check))); - - fan_edge_counter[0] = 0; - fan_edge_counter[1] = 0; -} - -void checkFanSpeed() -{ - static unsigned char fan_speed_errors[2] = { 0,0 }; - - if (fan_speed[0] == 0 && current_temperature[0] > EXTRUDER_AUTO_FAN_TEMPERATURE) fan_speed_errors[0]++; - else fan_speed_errors[0] = 0; - - if (fan_speed[1] == 0 && fanSpeed > MIN_PRINT_FAN_SPEED) fan_speed_errors[1]++; - else fan_speed_errors[1] = 0; - - if (fan_speed_errors[0] > 5) fanSpeedError(0); - if (fan_speed_errors[1] > 5) fanSpeedError(1); -} - -void fanSpeedError(unsigned char _fan) { - - if (card.sdprinting) { - card.pauseSDPrint(); - } - - setTargetHotend0(0); - /*lcd_update(); - WRITE(BEEPER, HIGH); - delayMicroseconds(500); - WRITE(BEEPER, LOW); - delayMicroseconds(100);*/ - - - SERIAL_ERROR_START; - switch (_fan) { - case 0: - SERIAL_ERRORLNPGM("ERROR: Extruder fan speed is lower then expected"); - LCD_ALERTMESSAGEPGM("Err: EXTR. FAN ERROR"); - break; - case 1: - SERIAL_ERRORLNPGM("ERROR: Print fan speed is lower then expected"); - LCD_ALERTMESSAGEPGM("Err: PRINT FAN ERROR"); - break; - } -} +void countFanSpeed() +{ + fan_speed[0] = (fan_edge_counter[0] * (float(250) / (millis() - extruder_autofan_last_check))); + fan_speed[1] = (fan_edge_counter[1] * (float(250) / (millis() - extruder_autofan_last_check))); + + fan_edge_counter[0] = 0; + fan_edge_counter[1] = 0; +} + +void checkFanSpeed() +{ + static unsigned char fan_speed_errors[2] = { 0,0 }; + + if (fan_speed[0] == 0 && current_temperature[0] > EXTRUDER_AUTO_FAN_TEMPERATURE) fan_speed_errors[0]++; + else fan_speed_errors[0] = 0; + + if (fan_speed[1] == 0 && fanSpeed > MIN_PRINT_FAN_SPEED) fan_speed_errors[1]++; + else fan_speed_errors[1] = 0; + + if (fan_speed_errors[0] > 5) fanSpeedError(0); + if (fan_speed_errors[1] > 5) fanSpeedError(1); +} + +void fanSpeedError(unsigned char _fan) { + + if (card.sdprinting) { + card.pauseSDPrint(); + } + + setTargetHotend0(0); + /*lcd_update(); + WRITE(BEEPER, HIGH); + delayMicroseconds(500); + WRITE(BEEPER, LOW); + delayMicroseconds(100);*/ + + + SERIAL_ERROR_START; + switch (_fan) { + case 0: + SERIAL_ERRORLNPGM("ERROR: Extruder fan speed is lower then expected"); + LCD_ALERTMESSAGEPGM("Err: EXTR. FAN ERROR"); + break; + case 1: + SERIAL_ERRORLNPGM("ERROR: Print fan speed is lower then expected"); + LCD_ALERTMESSAGEPGM("Err: PRINT FAN ERROR"); + break; + } +} void checkExtruderAutoFans() @@ -628,8 +628,8 @@ void manage_heater() (defined(EXTRUDER_2_AUTO_FAN_PIN) && EXTRUDER_2_AUTO_FAN_PIN > -1) if(millis() - extruder_autofan_last_check > 1000) // only need to check fan state very infrequently { - countFanSpeed(); - checkFanSpeed(); + countFanSpeed(); + checkFanSpeed(); checkExtruderAutoFans(); extruder_autofan_last_check = millis(); } diff --git a/Firmware/temperature.h b/Firmware/temperature.h index ea09f60b..9bc1aa43 100644 --- a/Firmware/temperature.h +++ b/Firmware/temperature.h @@ -207,9 +207,9 @@ void PID_autotune(float temp, int extruder, int ncycles); void setExtruderAutoFanState(int pin, bool state); void checkExtruderAutoFans(); -void countFanSpeed(); -void checkFanSpeed(); -void fanSpeedError(unsigned char _fan); +void countFanSpeed(); +void checkFanSpeed(); +void fanSpeedError(unsigned char _fan); #endif diff --git a/Firmware/tmc2130.cpp b/Firmware/tmc2130.cpp index 8a150559..15b49235 100644 --- a/Firmware/tmc2130.cpp +++ b/Firmware/tmc2130.cpp @@ -5,7 +5,206 @@ #include "tmc2130.h" #include -uint32_t tmc2130_read(uint8_t chipselect, uint8_t address) +//externals for debuging +extern float current_position[4]; +extern void st_get_position_xy(long &x, long &y); + +//chipselect pins +uint8_t tmc2130_cs[4] = { X_TMC2130_CS, Y_TMC2130_CS, Z_TMC2130_CS, E0_TMC2130_CS }; +//holding currents +uint8_t tmc2130_current_h[4] = TMC2130_CURRENTS_H; +//running currents +uint8_t tmc2130_current_r[4] = TMC2130_CURRENTS_R; +//axis stalled flags +uint8_t tmc2130_axis_stalled[4] = {0, 0, 0, 0}; +//last homing stalled +uint8_t tmc2130_LastHomingStalled = 0; + +uint8_t sg_homing_axis = 0xff; +uint8_t sg_homing_delay = 0; + + +uint32_t tmc2130_read(uint8_t cs, uint8_t address); +void tmc2130_write(uint8_t cs, uint8_t address, uint8_t wval1, uint8_t wval2, uint8_t wval3, uint8_t wval4); +uint8_t tmc2130_read8(uint8_t cs, uint8_t address); +uint32_t tmc2130_readRegister(uint8_t cs, uint8_t address); +uint16_t tmc2130_readSG(uint8_t cs); +uint16_t tmc2130_readTStep(uint8_t cs); +void tmc2130_chopconf(uint8_t cs, bool extrapolate256 = 0, uint16_t microstep_resolution = 16); +void tmc2130_PWMconf(uint8_t cs, uint8_t PWMautoScale = PWM_AUTOSCALE, uint8_t PWMfreq = PWM_FREQ, uint8_t PWMgrad = PWM_GRAD, uint8_t PWMampl = PWM_AMPL); +void tmc2130_PWMthreshold(uint8_t cs); +void tmc2130_disable_motor(uint8_t driver); + + +void tmc2130_init() +{ + MYSERIAL.println("tmc2130_init"); + WRITE(X_TMC2130_CS, HIGH); + WRITE(Y_TMC2130_CS, HIGH); + WRITE(Z_TMC2130_CS, HIGH); + WRITE(E0_TMC2130_CS, HIGH); + SET_OUTPUT(X_TMC2130_CS); + SET_OUTPUT(Y_TMC2130_CS); + SET_OUTPUT(Z_TMC2130_CS); + SET_OUTPUT(E0_TMC2130_CS); + SPI.begin(); + for (int i = 0; i < 3; i++) //X Y Z axes + { + tmc2130_write(tmc2130_cs[i], 0x00, 0, 0, 0, 0x04); //address=0x0 GCONF - bit 2 activate stealthChop + tmc2130_write(tmc2130_cs[i], 0x10, 0, 15, tmc2130_current_r[i], tmc2130_current_h[i]); //0x10 IHOLD_IRUN + tmc2130_write(tmc2130_cs[i], 0x11, 0, 0, 0, 0); + tmc2130_PWMconf(tmc2130_cs[i]); //address=0x70 PWM_CONF //reset default=0x00050480 + //tmc2130_PWMthreshold(tmc2130_cs[i]); + tmc2130_chopconf(tmc2130_cs[i], 1, 16); + } + for (int i = 3; i < 4; i++) //E axis + { + tmc2130_write(tmc2130_cs[i], 0x00, 0, 0, 0, 0x00); //address=0x0 GCONF - bit 2 activate stealthChop + tmc2130_write(tmc2130_cs[i], 0x10, 0, 15, tmc2130_current_r[i], tmc2130_current_h[i]); //0x10 IHOLD_IRUN + tmc2130_write(tmc2130_cs[i], 0x11, 0, 0, 0, 0); + tmc2130_chopconf(tmc2130_cs[i], 1, 16); + } +} + +bool tmc2130_update_sg() +{ + if ((sg_homing_axis == X_AXIS) || (sg_homing_axis == Y_AXIS)) + { + uint8_t cs = tmc2130_cs[sg_homing_axis]; + uint16_t tstep = tmc2130_readTStep(cs); + if (tstep < TCOOLTHRS) + { + if(sg_homing_delay < 10) // wait for a few tens microsteps until stallGuard is used //todo: read out microsteps directly, instead of delay counter + sg_homing_delay++; + else + { + uint16_t sg = tmc2130_readSG(cs); + if (sg==0) + { + tmc2130_axis_stalled[sg_homing_axis] = true; + tmc2130_LastHomingStalled = true; + } + else + tmc2130_axis_stalled[sg_homing_axis] = false; + } + } + else + tmc2130_axis_stalled[sg_homing_axis] = false; + return true; + } + else + { + tmc2130_axis_stalled[X_AXIS] = false; + tmc2130_axis_stalled[Y_AXIS] = false; + } + return false; +} + +void tmc2130_check_overtemp() +{ + const static char TMC_OVERTEMP_MSG[] PROGMEM = "TMC DRIVER OVERTEMP "; + static uint32_t checktime = 0; + //drivers_disabled[0] = 1; //TEST + if( millis() - checktime > 1000 ) + { + for(int i = 0; i < 4; i++) + { + uint32_t drv_status = tmc2130_read(tmc2130_cs[i], 0x6F); //0x6F DRV_STATUS + if (drv_status & ((uint32_t)1<<26)) + { // BIT 26 - over temp prewarning ~120C (+-20C) + SERIAL_ERRORRPGM(TMC_OVERTEMP_MSG); + SERIAL_ECHOLN(i); + for(int x = 0; x < 4; x++) tmc2130_disable_motor(x); + kill(TMC_OVERTEMP_MSG); + } + } + checktime = millis(); + } +} + +void tmc2130_home_enter(uint8_t axis) +{ + MYSERIAL.print("tmc2130_home_enter "); + MYSERIAL.println((int)axis); + uint8_t cs = tmc2130_cs[axis]; + sg_homing_axis = axis; + sg_homing_delay = 0; + tmc2130_axis_stalled[X_AXIS] = false; + tmc2130_axis_stalled[Y_AXIS] = false; + //Configuration to spreadCycle + //tmc2130_write(cs, 0x0, 0, 0, 0, 0x01); + tmc2130_write(cs, 0x0, 0, 0, 0, 0x00); + tmc2130_write(cs, 0x6D, 0, (axis == X_AXIS)?SG_THRESHOLD_X:SG_THRESHOLD_Y,0,0); + tmc2130_write(cs, 0x14, 0, 0, 0, TCOOLTHRS); +} + +void tmc2130_home_exit() +{ + MYSERIAL.println("tmc2130_home_exit"); + if ((sg_homing_axis == X_AXIS) || (sg_homing_axis == Y_AXIS)) + { + // Configuration back to stealthChop + tmc2130_write(tmc2130_cs[sg_homing_axis], 0x0, 0, 0, 0, 0x04); + sg_homing_axis = 0xff; + } +} + +extern uint8_t tmc2130_didLastHomingStall() +{ + uint8_t ret = tmc2130_LastHomingStalled; + tmc2130_LastHomingStalled = false; + return ret; +} + +void tmc2130_set_current_h(uint8_t axis, uint8_t current) +{ + MYSERIAL.print("tmc2130_set_current_h "); + MYSERIAL.print((int)axis); + MYSERIAL.print(" "); + MYSERIAL.println((int)current); + if (current > 15) current = 15; //current>15 is unsafe + tmc2130_current_h[axis] = current; + tmc2130_write(tmc2130_cs[axis], 0x10, 0, 15, tmc2130_current_r[axis], tmc2130_current_h[axis]); //0x10 IHOLD_IRUN +} + +void tmc2130_set_current_r(uint8_t axis, uint8_t current) +{ + MYSERIAL.print("tmc2130_set_current_r "); + MYSERIAL.print((int)axis); + MYSERIAL.print(" "); + MYSERIAL.println((int)current); + if (current > 15) current = 15; //current>15 is unsafe + tmc2130_current_r[axis] = current; + tmc2130_write(tmc2130_cs[axis], 0x10, 0, 15, tmc2130_current_r[axis], tmc2130_current_h[axis]); //0x10 IHOLD_IRUN +} + +void tmc2130_print_currents() +{ + MYSERIAL.println("tmc2130_print_currents"); + MYSERIAL.println("\tH\rR"); + + MYSERIAL.print("X\t"); + MYSERIAL.print((int)tmc2130_current_h[0]); + MYSERIAL.print("\t"); + MYSERIAL.println((int)tmc2130_current_r[0]); + + MYSERIAL.print("Y\t"); + MYSERIAL.print((int)tmc2130_current_h[1]); + MYSERIAL.print("\t"); + MYSERIAL.println((int)tmc2130_current_r[1]); + + MYSERIAL.print("Z\t"); + MYSERIAL.print((int)tmc2130_current_h[2]); + MYSERIAL.print("\t"); + MYSERIAL.println((int)tmc2130_current_r[2]); + + MYSERIAL.print("E\t"); + MYSERIAL.print((int)tmc2130_current_h[3]); + MYSERIAL.print("\t"); + MYSERIAL.println((int)tmc2130_current_r[3]); +} + +uint32_t tmc2130_read(uint8_t cs, uint8_t address) { uint32_t val32; uint8_t val0; @@ -15,23 +214,23 @@ uint32_t tmc2130_read(uint8_t chipselect, uint8_t address) uint8_t val4; //datagram1 - read request (address + dummy write) SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE3)); - digitalWrite(chipselect,LOW); + digitalWrite(cs,LOW); SPI.transfer(address); SPI.transfer(0); SPI.transfer(0); SPI.transfer(0); SPI.transfer(0); - digitalWrite(chipselect, HIGH); + digitalWrite(cs, HIGH); SPI.endTransaction(); //datagram2 - response SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE3)); - digitalWrite(chipselect,LOW); + digitalWrite(cs,LOW); val0 = SPI.transfer(0); val1 = SPI.transfer(0); val2 = SPI.transfer(0); val3 = SPI.transfer(0); val4 = SPI.transfer(0); - digitalWrite(chipselect, HIGH); + digitalWrite(cs, HIGH); SPI.endTransaction(); #ifdef TMC_DBG_READS MYSERIAL.print("SPIRead 0x"); @@ -55,7 +254,7 @@ uint32_t tmc2130_read(uint8_t chipselect, uint8_t address) return val32; } -void tmc2130_write(uint8_t chipselect, uint8_t address,uint8_t wval1,uint8_t wval2,uint8_t wval3,uint8_t wval4) +void tmc2130_write(uint8_t cs, uint8_t address,uint8_t wval1,uint8_t wval2,uint8_t wval3,uint8_t wval4) { uint32_t val32; uint8_t val0; @@ -65,23 +264,23 @@ void tmc2130_write(uint8_t chipselect, uint8_t address,uint8_t wval1,uint8_t wva uint8_t val4; //datagram1 - write SPI.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE3)); - digitalWrite(chipselect,LOW); + digitalWrite(cs,LOW); SPI.transfer(address+0x80); SPI.transfer(wval1); SPI.transfer(wval2); SPI.transfer(wval3); SPI.transfer(wval4); - digitalWrite(chipselect, HIGH); + digitalWrite(cs, HIGH); SPI.endTransaction(); //datagram2 - response SPI.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE3)); - digitalWrite(chipselect,LOW); + digitalWrite(cs,LOW); val0 = SPI.transfer(0); val1 = SPI.transfer(0); val2 = SPI.transfer(0); val3 = SPI.transfer(0); val4 = SPI.transfer(0); - digitalWrite(chipselect, HIGH); + digitalWrite(cs, HIGH); SPI.endTransaction(); #ifdef TMC_DBG_WRITE MYSERIAL.print("WriteRead 0x"); @@ -102,66 +301,66 @@ void tmc2130_write(uint8_t chipselect, uint8_t address,uint8_t wval1,uint8_t wva #endif //TMC_DBG_READS } -uint8_t tmc2130_read8(uint8_t chipselect, uint8_t address) +uint8_t tmc2130_read8(uint8_t cs, uint8_t address) { //datagram1 - write SPI.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE3)); - digitalWrite(chipselect,LOW); + digitalWrite(cs,LOW); SPI.transfer(address); SPI.transfer(0x00); SPI.transfer(0x00); SPI.transfer(0x00); SPI.transfer(0x00); - digitalWrite(chipselect, HIGH); + digitalWrite(cs, HIGH); SPI.endTransaction(); uint8_t val0; //datagram2 - response SPI.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE3)); - digitalWrite(chipselect,LOW); + digitalWrite(cs,LOW); val0 = SPI.transfer(0); - digitalWrite(chipselect, HIGH); + digitalWrite(cs, HIGH); SPI.endTransaction(); return val0; } -uint32_t tmc2130_readRegister(uint8_t chipselect, uint8_t address) +uint32_t tmc2130_readRegister(uint8_t cs, uint8_t address) { //datagram1 - write SPI.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE3)); - digitalWrite(chipselect,LOW); + digitalWrite(cs,LOW); SPI.transfer(address); SPI.transfer(0x00); SPI.transfer(0x00); SPI.transfer(0x00); SPI.transfer(0x00); - digitalWrite(chipselect, HIGH); + digitalWrite(cs, HIGH); SPI.endTransaction(); uint32_t val0; //datagram2 - response SPI.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE3)); - digitalWrite(chipselect,LOW); + digitalWrite(cs,LOW); SPI.transfer(0); // ignore status bits val0 = SPI.transfer(0); // MSB val0 = (val0 << 8) | SPI.transfer(0); val0 = (val0 << 8) | SPI.transfer(0); val0 = (val0 << 8) | SPI.transfer(0); //LSB - digitalWrite(chipselect, HIGH); + digitalWrite(cs, HIGH); SPI.endTransaction(); return val0; } -uint16_t tmc2130_readSG(uint8_t chipselect) +uint16_t tmc2130_readSG(uint8_t cs) { uint8_t address = 0x6F; - uint32_t registerValue = tmc2130_readRegister(chipselect, address); + uint32_t registerValue = tmc2130_readRegister(cs, address); uint16_t val0 = registerValue & 0x3ff; return val0; } -uint16_t tmc2130_readTStep(uint8_t chipselect) +uint16_t tmc2130_readTStep(uint8_t cs) { uint8_t address = 0x12; - uint32_t registerValue = tmc2130_readRegister(chipselect, address); + uint32_t registerValue = tmc2130_readRegister(cs, address); uint16_t val0 = 0; if(registerValue & 0x000f0000) val0 = 0xffff; @@ -170,9 +369,9 @@ uint16_t tmc2130_readTStep(uint8_t chipselect) return val0; } -void tmc2130_chopconf(uint8_t cs, bool extrapolate256 = 0, uint16_t microstep_resolution = 16) +void tmc2130_chopconf(uint8_t cs, bool extrapolate256, uint16_t microstep_resolution) { - uint8_t mres=0b0100; + uint8_t mres = 0b0100; if(microstep_resolution == 256) mres = 0b0000; if(microstep_resolution == 128) mres = 0b0001; if(microstep_resolution == 64) mres = 0b0010; @@ -183,182 +382,23 @@ void tmc2130_chopconf(uint8_t cs, bool extrapolate256 = 0, uint16_t microstep_re if(microstep_resolution == 2) mres = 0b0111; if(microstep_resolution == 1) mres = 0b1000; mres |= extrapolate256 << 4; //bit28 intpol - //tmc2130_write(cs,0x6C,mres,0x01,0x00,0xD3); - tmc2130_write(cs,0x6C,mres,0x01,0x00,0xC3); + //tmc2130_write(cs, 0x6C, mres, 0x01, 0x00, 0xD3); + tmc2130_write(cs, 0x6C, mres, 0x01, 0x00, 0xC3); } -void tmc2130_PWMconf(uint8_t cs, uint8_t PWMautoScale = PWM_AUTOSCALE, uint8_t PWMfreq = PWM_FREQ, uint8_t PWMgrad = PWM_GRAD, uint8_t PWMampl = PWM_AMPL) +void tmc2130_PWMconf(uint8_t cs, uint8_t PWMautoScale, uint8_t PWMfreq, uint8_t PWMgrad, uint8_t PWMampl) { - tmc2130_write(cs,0x70,0x00,(PWMautoScale+PWMfreq),PWMgrad,PWMampl); // TMC LJ -> For better readability changed to 0x00 and added PWMautoScale and PWMfreq + tmc2130_write(cs, 0x70, 0x00, (PWMautoScale+PWMfreq), PWMgrad, PWMampl); // TMC LJ -> For better readability changed to 0x00 and added PWMautoScale and PWMfreq } void tmc2130_PWMthreshold(uint8_t cs) { - tmc2130_write(cs,0x13,0x00,0x00,0x00,0x00); // TMC LJ -> Adds possibility to swtich from stealthChop to spreadCycle automatically -} - - -uint8_t st_didLastHomingStall() -{ - uint8_t returnValue = sg_lastHomingStalled; - sg_lastHomingStalled = false; - return returnValue; + tmc2130_write(cs, 0x13, 0x00, 0x00, 0x00, 0x00); // TMC LJ -> Adds possibility to swtich from stealthChop to spreadCycle automatically } void tmc2130_disable_motor(uint8_t driver) { - uint8_t cs[4] = { X_TMC2130_CS, Y_TMC2130_CS, Z_TMC2130_CS, E0_TMC2130_CS }; - tmc2130_write(cs[driver],0x6C,0,01,0,0); -} - -void tmc2130_check_overtemp() -{ - const static char TMC_OVERTEMP_MSG[] PROGMEM = "TMC DRIVER OVERTEMP "; - uint8_t cs[4] = { X_TMC2130_CS, Y_TMC2130_CS, Z_TMC2130_CS, E0_TMC2130_CS }; - static uint32_t checktime = 0; - //drivers_disabled[0] = 1; //TEST - if( millis() - checktime > 1000 ) - { - for(int i=0;i<4;i++) - { - uint32_t drv_status = tmc2130_read(cs[i], 0x6F); //0x6F DRV_STATUS - if (drv_status & ((uint32_t)1<<26)) - { // BIT 26 - over temp prewarning ~120C (+-20C) - SERIAL_ERRORRPGM(TMC_OVERTEMP_MSG); - SERIAL_ECHOLN(i); - for(int x=0; x<4;x++) tmc2130_disable_motor(x); - kill(TMC_OVERTEMP_MSG); - } - } - checktime = millis(); - } -} - -void tmc2130_init() -{ - uint8_t cs[4] = { X_TMC2130_CS, Y_TMC2130_CS, Z_TMC2130_CS, E0_TMC2130_CS }; - // uint8_t current[4] = { 31, 31, 31, 31 }; - // uint8_t current_h[4] = { 12, 12, 12, 12 }; - // uint8_t current_r[4] = { 24, 24, 24, 24 }; - // uint8_t current_r[4] = { 32, 32, 32, 32 }; - // uint8_t current_h[4] = { 14, 14, 14, 14 }; - uint8_t current_h[4] = { 2, 2, 2, 4 }; - uint8_t current_r[4] = { 6, 6, 8, 8 }; - WRITE(X_TMC2130_CS, HIGH); - WRITE(Y_TMC2130_CS, HIGH); - WRITE(Z_TMC2130_CS, HIGH); - WRITE(E0_TMC2130_CS, HIGH); - SET_OUTPUT(X_TMC2130_CS); - SET_OUTPUT(Y_TMC2130_CS); - SET_OUTPUT(Z_TMC2130_CS); - SET_OUTPUT(E0_TMC2130_CS); - SPI.begin(); -/* for(int i=0;i<4;i++) - { - //tmc2130_write(cs[i],0x6C,0b10100,01,00,0xC5); - tmc2130_chopconf(cs[i],1,16); - tmc2130_write(cs[i],0x10,0,15,current_h[i],current_r[i]); //0x10 IHOLD_IRUN - //tmc2130_write(cs[i],0x0,0,0,0,0x05); //address=0x0 GCONF EXT VREF - tmc2130_write(cs[i],0x0,0,0,0,0x05); //address=0x0 GCONF EXT VREF - activate stealthChop - //tmc2130_write(cs[i],0x11,0,0,0,0xA); - - // Uncomment lines below to use a different configuration (pwm_autoscale = 0) for XY axes - if(i==0 || i==1) - tmc2130_PWMconf(cs[i],PWM_AUTOSCALE_XY,PWM_FREQ_XY,PWM_GRAD_XY,PWM_AMPL_XY); //address=0x70 PWM_CONF //reset default=0x00050480 - else - tmc2130_PWMconf(cs[i]); //address=0x70 PWM_CONF //reset default=0x00050480 - tmc2130_PWMthreshold(cs[i]); - } -*/ -#ifdef MK3_TEST1 - for (int i=0;i<4;i++) - { - tmc2130_write(cs[i],0x0,0,0,0,0x00); //address=0x0 GCONF - bit 2 activate stealthChop - tmc2130_write(cs[i],0x10,0,15,current_r[i],current_h[i]); //0x10 IHOLD_IRUN - tmc2130_chopconf(cs[i],0,16); - } -#else //MK3_TEST1 - for (int i=0;i<3;i++) - { - tmc2130_write(cs[i],0x0,0,0,0,0x04); //address=0x0 GCONF - bit 2 activate stealthChop - tmc2130_write(cs[i],0x10,0,15,current_r[i],current_h[i]); //0x10 IHOLD_IRUN - tmc2130_write(cs[i],0x11,0,0,0,0); - tmc2130_PWMconf(cs[i]); //address=0x70 PWM_CONF //reset default=0x00050480 - // tmc2130_PWMthreshold(cs[i]); - tmc2130_chopconf(cs[i],1,16); - } - for (int i=3;i<4;i++) - { - tmc2130_write(cs[i],0x0,0,0,0,0x00); //address=0x0 GCONF - bit 2 activate stealthChop - tmc2130_write(cs[i],0x10,0,15,current_r[i],current_h[i]); //0x10 IHOLD_IRUN - tmc2130_write(cs[i],0x11,0,0,0,0); - tmc2130_chopconf(cs[i],1,16); - } -#endif //MK3_TEST1 -} - -void tmc2130_st_synchronize() -{ - uint8_t delay = 0; - if(sg_homing_axis == X_AXIS || sg_homing_axis == Y_AXIS) - { - uint8_t axis; - if(sg_homing_axis == X_AXIS) - axis = X_TMC2130_CS; - else - axis = Y_TMC2130_CS; - uint16_t tstep = tmc2130_readTStep(axis); - // SERIAL_PROTOCOLLN(tstep); - if(tstep < TCOOLTHRS) - { - if(delay < 255) // wait for a few tens microsteps until stallGuard is used //todo: read out microsteps directly, instead of delay counter - delay++; - else - { - uint16_t sg = tmc2130_readSG(axis); - if(sg==0) - { - sg_axis_stalled[sg_homing_axis] = true; - sg_lastHomingStalled = true; - } - else - sg_axis_stalled[sg_homing_axis] = false; -// SERIAL_PROTOCOLLN(sg); - } - } - else - { - sg_axis_stalled[sg_homing_axis] = false; - delay = 0; - } - } - else - { - sg_axis_stalled[X_AXIS] = false; - sg_axis_stalled[Y_AXIS] = false; - } -} - -void tmc2130_st_home_enter(uint8_t axis) -{ - sg_homing_axis = axis; -// Configuration to spreadCycle -// tmc2130_write((axis == X_AXIS)? X_TMC2130_CS : Y_TMC2130_CS,0x0,0,0,0,0x01); - tmc2130_write((axis == X_AXIS)? X_TMC2130_CS : Y_TMC2130_CS,0x0,0,0,0,0x00); - tmc2130_write((axis == X_AXIS)? X_TMC2130_CS : Y_TMC2130_CS,0x6D,0,(axis == X_AXIS)?SG_THRESHOLD_X:SG_THRESHOLD_Y,0,0); - tmc2130_write((axis == X_AXIS)? X_TMC2130_CS : Y_TMC2130_CS,0x14,0,0,0,TCOOLTHRS); -} - -void tmc2130_st_home_exit() -{ - if ((sg_homing_axis == X_AXIS) || (sg_homing_axis == X_AXIS)) - { - // Configuration back to stealthChop - tmc2130_write((sg_homing_axis == X_AXIS)? X_TMC2130_CS : Y_TMC2130_CS, 0x0, 0, 0, 0, 0x04); - sg_homing_axis = 0xff; - sg_axis_stalled[X_AXIS] = false; - sg_axis_stalled[Y_AXIS] = false; - } + tmc2130_write(tmc2130_cs[driver], 0x6C, 0, 01, 0, 0); } #endif //HAVE_TMC2130_DRIVERS diff --git a/Firmware/tmc2130.h b/Firmware/tmc2130.h index 3d4f1a10..14e7c7e2 100644 --- a/Firmware/tmc2130.h +++ b/Firmware/tmc2130.h @@ -1,26 +1,33 @@ #ifndef TMC2130_H #define TMC2130_H -static uint8_t sg_homing_axis = 0xFF; -static uint8_t sg_axis_stalled[2] = {0, 0}; -static uint8_t sg_lastHomingStalled = false; +//holding and running currents +extern uint8_t tmc2130_current_h[4]; +extern uint8_t tmc2130_current_r[4]; +//flags for axis stall detection +extern uint8_t tmc2130_axis_stalled[4]; -void tmc2130_check_overtemp(); +extern uint8_t sg_homing_delay; -void tmc2130_write(uint8_t chipselect, uint8_t address,uint8_t wval1,uint8_t wval2,uint8_t wval3,uint8_t wval4); -uint8_t tmc2130_read8(uint8_t chipselect, uint8_t address); -uint16_t tmc2130_readSG(uint8_t chipselect); -uint16_t tmc2130_readTStep(uint8_t chipselect); -void tmc2130_PWMconf(uint8_t cs, uint8_t PWMgrad, uint8_t PWMampl); -uint8_t st_didLastHomingStall(); +//initialize tmc2130 +extern void tmc2130_init(); +//update stall guard (called from st_synchronize inside the loop) +extern bool tmc2130_update_sg(); +//temperature watching (called from ) +extern void tmc2130_check_overtemp(); +//enter homing (called from homeaxis before homing starts) +extern void tmc2130_home_enter(uint8_t axis); +//exit homing (called from homeaxis after homing ends) +extern void tmc2130_home_exit(); +// +extern uint8_t tmc2130_didLastHomingStall(); -void tmc2130_st_synchronize(); +//set holding current for any axis (G911) +extern void tmc2130_set_current_h(uint8_t axis, uint8_t current); +//set running current for any axis (G912) +extern void tmc2130_set_current_r(uint8_t axis, uint8_t current); +//print currents +extern void tmc2130_print_currents(); -void tmc2130_st_home_enter(uint8_t axis); - -void tmc2130_st_home_exit(); - -void tmc2130_init(); - -#endif TMC2130_H \ No newline at end of file +#endif //TMC2130_H \ No newline at end of file diff --git a/Firmware/variants/1_75mm_MK2-EINY01-E3Dv6full.h b/Firmware/variants/1_75mm_MK2-EINY01-E3Dv6full.h index de326ede..ae59fcdc 100644 --- a/Firmware/variants/1_75mm_MK2-EINY01-E3Dv6full.h +++ b/Firmware/variants/1_75mm_MK2-EINY01-E3Dv6full.h @@ -6,14 +6,14 @@ *------------------------------------*/ // Printer revision -#define FILAMENT_SIZE "1_75mm_MK2" +#define FILAMENT_SIZE "1_75mm_MK3" #define NOZZLE_TYPE "E3Dv6full" // Developer flag #define DEVELOPER // Printer name -#define CUSTOM_MENDEL_NAME "Prusa i3 MK2" +#define CUSTOM_MENDEL_NAME "Prusa i3 MK3" // Electronics #define MOTHERBOARD BOARD_EINY_0_1a @@ -32,7 +32,7 @@ *------------------------------------*/ // Steps per unit {X,Y,Z,E} -#define DEFAULT_AXIS_STEPS_PER_UNIT {100,100,3200/8,161.3} +#define DEFAULT_AXIS_STEPS_PER_UNIT {100,100,3200/8,140} // Endstop inverting const bool X_MIN_ENDSTOP_INVERTING = false; // set to true to invert the logic of the endstop. @@ -64,10 +64,10 @@ const bool Z_MIN_ENDSTOP_INVERTING = false; // set to true to invert the logic o #define NUM_AXIS 4 // The axis order in all axis related arrays is X, Y, Z, E #define HOMING_FEEDRATE {3000, 3000, 800, 0} // set the homing speeds (mm/min) // 3000 is also valid for stallGuard homing. Valid range: 2200 - 3000 -#define DEFAULT_MAX_FEEDRATE {500, 500, 12, 120} // (mm/sec) -#define DEFAULT_MAX_ACCELERATION {300,300,300,10000} // X, Y, Z, E maximum start speed for accelerated moves. E default values are good for Skeinforge 40+, for older versions raise them a lot. +#define DEFAULT_MAX_FEEDRATE {400, 400, 12, 120} // (mm/sec) +#define DEFAULT_MAX_ACCELERATION {2000,2000,500,10000} // X, Y, Z, E maximum start speed for accelerated moves. E default values are good for Skeinforge 40+, for older versions raise them a lot. -#define DEFAULT_ACCELERATION 1500 // X, Y, Z and E max acceleration in mm/s^2 for printing moves +#define DEFAULT_ACCELERATION 1200 // X, Y, Z and E max acceleration in mm/s^2 for printing moves #define DEFAULT_RETRACT_ACCELERATION 1500 // X, Y, Z and E max acceleration in mm/s^2 for retracts @@ -84,41 +84,17 @@ const bool Z_MIN_ENDSTOP_INVERTING = false; // set to true to invert the logic o #define PWM_AMPL 0xC8 // 0xFF - Sets PWM amplitude to 200 (max is 255) #define PWM_AUTOSCALE 0x04 // 0x04 since writing in PWM_CONF (Activates PWM autoscaling) #define PWM_FREQ 0x01 // 0x01 since writing in PWM_CONF (Sets PWM frequency to 2/683 fCLK) - -// Special configuration for XY axes for operation (during standstill, use same settings as for other axes) //todo -#define PWM_GRAD_XY 156 // 0x0F - Sets gradient - (max 15 with PWM autoscale activated) -#define PWM_AMPL_XY 63 // 0xFF - Sets PWM amplitude to 200 (max is 255) -#define PWM_AUTOSCALE_XY 0x00 // 0x04 since writing in PWM_CONF (Activates PWM autoscaling) -#define PWM_FREQ_XY 0x01 // 0x01 since writing in PWM_CONF (Sets PWM frequency to 2/683 fCLK) - #define PWM_THRS 0x00 // TPWM_THRS - Sets the switching speed threshold based on TSTEP from stealthChop to spreadCycle mode -#define SG_HOMING 1 -#define SG_THRESHOLD 13 -#define TCOOLTHRS 239 +#define SG_HOMING_SW 1 // stallguard "software" homing +//#define SG_HOMING_HW 1 // stallguard "hardware" homing +#define SG_THRESHOLD_X 8 // stallguard sensitivity for X axis +#define SG_THRESHOLD_Y 8 // stallguard sensitivity for Y axis +#define TCOOLTHRS 239 // coolstep treshold -#define TMC_DEBUG - -// PWM register configuration -#define PWM_GRAD 0x08 // 0x0F - Sets gradient - (max 15 with PWM autoscale activated) -#define PWM_AMPL 0xC8 // 0xFF - Sets PWM amplitude to 200 (max is 255) -#define PWM_AUTOSCALE 0x04 // 0x04 since writing in PWM_CONF (Activates PWM autoscaling) -#define PWM_FREQ 0x01 // 0x01 since writing in PWM_CONF (Sets PWM frequency to 2/683 fCLK) - -// Special configuration for XY axes for operation (during standstill, use same settings as for other axes) //todo -#define PWM_GRAD_XY 156 // 0x0F - Sets gradient - (max 15 with PWM autoscale activated) -#define PWM_AMPL_XY 63 // 0xFF - Sets PWM amplitude to 200 (max is 255) -#define PWM_AUTOSCALE_XY 0x00 // 0x04 since writing in PWM_CONF (Activates PWM autoscaling) -#define PWM_FREQ_XY 0x01 // 0x01 since writing in PWM_CONF (Sets PWM frequency to 2/683 fCLK) - -#define PWM_THRS 0x00 // TPWM_THRS - Sets the switching speed threshold based on TSTEP from stealthChop to spreadCycle mode - -#define SG_HOMING 1 -#define SG_THRESHOLD_X 8 -#define SG_THRESHOLD_Y 8 -#define TCOOLTHRS 239 - -#define TMC_DEBUG +#define TMC2130_CURRENTS_H {2, 2, 2, 4} // default holding currents for all axes +#define TMC2130_CURRENTS_R {6, 6, 8, 8} // default running currents for all axes +#define TMC2130_DEBUG //#define TMC_DBG_READS //#define TMC_DBG_WRITE From 4f9a8147a4c428db34d77231710ed02513afb607 Mon Sep 17 00:00:00 2001 From: Robert Pelnar Date: Sat, 1 Jul 2017 17:28:32 +0200 Subject: [PATCH 2/2] renamed EINY 0.1a to EINY 0.3a added EINY 0.4a changed jerk (optimized for MK3 silent mode) --- Firmware/Configuration.h | 6 ++- Firmware/boards.h | 3 +- Firmware/pins.h | 109 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 113 insertions(+), 5 deletions(-) diff --git a/Firmware/Configuration.h b/Firmware/Configuration.h index 5a4e3b1b..90747b83 100644 --- a/Firmware/Configuration.h +++ b/Firmware/Configuration.h @@ -424,8 +424,10 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of // #define EXTRUDER_OFFSET_Y {0.0, 5.00} // (in mm) for each extruder, offset of the hotend on the Y axis // The speed change that does not require acceleration (i.e. the software might assume it can be done instantaneously) -#define DEFAULT_XJERK 5.0 // (mm/sec) -#define DEFAULT_YJERK 5.0 // (mm/sec) +//#define DEFAULT_XJERK 5.0 // (mm/sec) +//#define DEFAULT_YJERK 5.0 // (mm/sec) +#define DEFAULT_XJERK 2.5 // (mm/sec) +#define DEFAULT_YJERK 2.5 // (mm/sec) #define DEFAULT_ZJERK 0.2 // (mm/sec) #define DEFAULT_EJERK 2.5 // (mm/sec) diff --git a/Firmware/boards.h b/Firmware/boards.h index c4566296..a292bed1 100644 --- a/Firmware/boards.h +++ b/Firmware/boards.h @@ -3,7 +3,8 @@ #define BOARD_UNKNOWN -1 -#define BOARD_EINY_0_1a 300 // EINY 0.1a +#define BOARD_EINY_0_4a 299 // EINY 0.4a +#define BOARD_EINY_0_3a 300 // EINY 0.3a #define BOARD_RAMBO 301 // Rambo #define BOARD_RAMBO_MINI_1_3 302 // Rambo-mini 1.3 #define BOARD_RAMBO_MINI_1_0 102 // Rambo-mini 1.0 diff --git a/Firmware/pins.h b/Firmware/pins.h index 1ed3958b..8299b405 100644 --- a/Firmware/pins.h +++ b/Firmware/pins.h @@ -316,10 +316,10 @@ #endif /***************************************************************** -* EINY Rambo Pin Assignments 0.1a +* EINY Rambo Pin Assignments 0.3a ******************************************************************/ #if MOTHERBOARD == 300 -#define ELECTRONICS "EINY_01a" +#define ELECTRONICS "EINY_03a" #define KNOWN_BOARD #ifndef __AVR_ATmega2560__ #error Oops! Make sure you have 'Arduino Mega 2560 or Rambo' selected from the 'Tools -> Boards' menu. @@ -418,10 +418,115 @@ #endif //NEWPANEL #endif //ULTRA_LCD +#endif //MOTHERBOARD == 300 + +/***************************************************************** +* EINY Rambo Pin Assignments 0.4a +******************************************************************/ +#if MOTHERBOARD == 299 +#define ELECTRONICS "EINY_04a" +#define KNOWN_BOARD +#ifndef __AVR_ATmega2560__ +#error Oops! Make sure you have 'Arduino Mega 2560 or Rambo' selected from the 'Tools -> Boards' menu. #endif +#define LARGE_FLASH true +#define HAVE_TMC2130_DRIVERS +#define X_STEP_PIN 37 +#define X_DIR_PIN 49 +#define X_MIN_PIN 12 +#define X_MAX_PIN 30 +#define X_ENABLE_PIN 29 +#define X_MS1_PIN -1 +#define X_MS2_PIN -1 +#define X_TMC2130_CS 41 + +#define Y_STEP_PIN 36 +#define Y_DIR_PIN 48 +#define Y_MIN_PIN 11 +#define Y_MAX_PIN 24 +#define Y_ENABLE_PIN 28 +#define Y_MS1_PIN -1 +#define Y_MS2_PIN -1 +#define Y_TMC2130_CS 39 + +#define Z_STEP_PIN 35 +#define Z_DIR_PIN 47 +#define Z_MIN_PIN 10 +#define Z_MAX_PIN 23 +#define Z_ENABLE_PIN 27 +#define Z_MS1_PIN -1 +#define Z_MS2_PIN -1 +#define Z_TMC2130_CS 67 + +#define HEATER_BED_PIN 4 +#define TEMP_BED_PIN 2 + +#define HEATER_0_PIN 3 +#define TEMP_0_PIN 0 + +#define HEATER_1_PIN 7 +#define TEMP_1_PIN 1 + +#ifdef BARICUDA +#define HEATER_2_PIN 6 +#else +#define HEATER_2_PIN -1 +#endif + +#define TEMP_2_PIN -1 + +#define E0_STEP_PIN 34 +#define E0_DIR_PIN 43 +#define E0_ENABLE_PIN 26 +#define E0_MS1_PIN -1 +#define E0_MS2_PIN -1 +#define E0_TMC2130_CS 66 + +#define MOTOR_CURRENT_PWM_XY_PIN 46 +#define MOTOR_CURRENT_PWM_Z_PIN 45 +#define MOTOR_CURRENT_PWM_E_PIN 44 +#define SDPOWER -1 +#define SDSS 53 +#define LED_PIN 13 +#define FAN_PIN 6 +#define FAN_1_PIN -1 +#define PS_ON_PIN -1 +#define KILL_PIN -1 // 80 with Smart Controller LCD +#define SUICIDE_PIN -1 // PIN that has to be turned on right after start, to keep power flowing. + +#ifdef ULTRA_LCD + +#define KILL_PIN 32 + +#ifdef NEWPANEL + +#define BEEPER 84 // Beeper on AUX-4 +#define LCD_PINS_RS 82 +//#define LCD_PINS_ENABLE 18 +//#define LCD_PINS_D4 19 +#define LCD_PINS_ENABLE 61 +#define LCD_PINS_D4 59 +#define LCD_PINS_D5 70 +#define LCD_PINS_D6 85 +#define LCD_PINS_D7 71 + +//buttons are directly attached using AUX-2 +#define BTN_EN1 72 +#define BTN_EN2 14 +#define BTN_ENC 9 // the click + +#define SDCARDDETECT 15 + +#define TACH_0 81 +#define TACH_1 80 + +#endif //NEWPANEL +#endif //ULTRA_LCD + +#endif //MOTHERBOARD == 300 #ifndef KNOWN_BOARD