michalprusa 7 роки тому
батько
коміт
cabaec95c8
4 змінених файлів з 269 додано та 8 видалено
  1. 6 6
      Firmware/Configuration.h
  2. 1 1
      Firmware/boards.h
  3. 110 0
      Firmware/pins.h
  4. 152 1
      Firmware/stepper.cpp

+ 6 - 6
Firmware/Configuration.h

@@ -264,10 +264,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_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_X_DIR true    // for Mendel set to false, for Orca set to true
+#define INVERT_Y_DIR true    // for Mendel set to true, for Orca 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
 
@@ -421,8 +421,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)
 

+ 1 - 1
Firmware/boards.h

@@ -3,7 +3,7 @@
 
 #define BOARD_UNKNOWN -1
 
-
+#define BOARD_EINY_0_1a         300 // EINY 0.1a
 #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

+ 110 - 0
Firmware/pins.h

@@ -318,6 +318,116 @@
 
 
 
+/*****************************************************************
+ * EINY Rambo Pin Assignments 0.1a
+ ******************************************************************/
+#if MOTHERBOARD == 300
+#define ELECTRONICS "EINY_01a"
+#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
+//Motor current PWM conversion, PWM value = MotorCurrentSetting * 255 / range
+#define MOTOR_CURRENT_PWM_RANGE 2000
+#define DEFAULT_PWM_MOTOR_CURRENT  {1300, 1300, 1300}
+//#define DEFAULT_PWM_MOTOR_CURRENT  {1100, 1100, 1300}
+#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_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
+
+#endif //NEWPANEL
+#endif //ULTRA_LCD
+
+
+#endif
+
+
+
+
 
 #ifndef KNOWN_BOARD
 #error Unknown MOTHERBOARD value in configuration.h

+ 152 - 1
Firmware/stepper.cpp

@@ -32,7 +32,9 @@
 #if defined(DIGIPOTSS_PIN) && DIGIPOTSS_PIN > -1
 #include <SPI.h>
 #endif
-
+#ifdef HAVE_TMC2130_DRIVERS
+#include <SPI.h>
+#endif
 
 //===========================================================================
 //=============================public variables  ============================
@@ -630,9 +632,158 @@ ISR(TIMER1_COMPA_vect)
     }
   }
 }
+#ifdef HAVE_TMC2130_DRIVERS
+      void tmc2130_write(uint8_t chipselect, uint8_t address,uint8_t wval1,uint8_t wval2,uint8_t wval3,uint8_t wval4)
+      {
+          uint32_t val32;
+          uint8_t val0;
+          uint8_t val1;
+          uint8_t val2;
+          uint8_t val3;
+          uint8_t val4;
+          
+          //datagram1 - write
+          SPI.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE3));
+          digitalWrite(chipselect,LOW);
+          SPI.transfer(address+0x80);
+          SPI.transfer(wval1);
+          SPI.transfer(wval2);
+          SPI.transfer(wval3);
+          SPI.transfer(wval4);
+          digitalWrite(chipselect, HIGH);
+          SPI.endTransaction();
+          
+          //datagram2 - response
+          SPI.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE3));
+          digitalWrite(chipselect,LOW);
+          val0 = SPI.transfer(0);
+          val1 = SPI.transfer(0);
+          val2 = SPI.transfer(0);
+          val3 = SPI.transfer(0);
+          val4 = SPI.transfer(0);
+          digitalWrite(chipselect, HIGH);
+          SPI.endTransaction();
+          
+          MYSERIAL.print("WriteRead 0x");
+          MYSERIAL.print(address,HEX);
+          MYSERIAL.print(" Status:");
+          MYSERIAL.print(val0 & 0b00000111,BIN);
+          MYSERIAL.print("  ");
+          MYSERIAL.print(val1,BIN);
+          MYSERIAL.print("  ");
+          MYSERIAL.print(val2,BIN);
+          MYSERIAL.print("  ");
+          MYSERIAL.print(val3,BIN);
+          MYSERIAL.print("  ");
+          MYSERIAL.print(val4,BIN);
+          
+          val32 = (uint32_t)val1<<24 | (uint32_t)val2<<16 | (uint32_t)val3<<8 | (uint32_t)val4;
+          MYSERIAL.print(" 0x");
+          MYSERIAL.println(val32,HEX);
+      }
+      
+      uint8_t tmc2130_read8(uint8_t chipselect, uint8_t address){
+          
+          
+          //datagram1 - write
+          SPI.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE3));
+          digitalWrite(chipselect,LOW);
+          SPI.transfer(address);
+          SPI.transfer(0x00);
+          SPI.transfer(0x00);
+          SPI.transfer(0x00);
+          SPI.transfer(0x00);
+          digitalWrite(chipselect, HIGH);
+          SPI.endTransaction();
+          
+          uint8_t val0;
+          
+          //datagram2 - response
+          SPI.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE3));
+          digitalWrite(chipselect,LOW);
+          val0 = SPI.transfer(0);
+          digitalWrite(chipselect, HIGH);
+          SPI.endTransaction();
+          
+          return val0;
+          
+          
+      }
+      
+      void tmc2130_chopconf(uint8_t cs, bool extrapolate256 = 0, uint16_t microstep_resolution = 16)
+      {
+          uint8_t mres=0b0100;
+          if(microstep_resolution == 256) mres = 0b0000;
+          if(microstep_resolution == 128) mres = 0b0001;
+          if(microstep_resolution == 64)  mres = 0b0010;
+          if(microstep_resolution == 32)  mres = 0b0011;
+          if(microstep_resolution == 16)  mres = 0b0100;
+          if(microstep_resolution == 8)   mres = 0b0101;
+          if(microstep_resolution == 4)   mres = 0b0110;
+          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);
+      }
+      
+      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)
+      {
+          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
+      }
+      
+#endif //HAVE_TMC2130_DRIVERS
+      
+      void tmc2130_init()
+      {
+#ifdef HAVE_TMC2130_DRIVERS
+          uint8_t cs[4] = { X_TMC2130_CS, Y_TMC2130_CS, Z_TMC2130_CS, E0_TMC2130_CS };
+          uint8_t current[4] = { 31, 31, 31, 31 };
+          
+          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[i],current[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]);
+          }
+          tmc2130_chopconf(cs[3],0,256);
+#endif
+      }
+      
+
+      
 
 void st_init()
 {
+  tmc2130_init(); //Initialize TMC2130 drivers
   digipot_init(); //Initialize Digipot Motor Current
   microstep_init(); //Initialize Microstepping Pins