diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index dc00e4b7..0c1a6384 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -1316,6 +1316,8 @@ void loop() manage_inactivity(); checkHitEndstops(); lcd_update(); + + tmc2130_check_overtemp(); } void get_command() @@ -6092,4 +6094,4 @@ void bed_analysis(float x_dimension, float y_dimension, int x_points_num, int y_ } -#endif \ No newline at end of file +#endif diff --git a/Firmware/SdBaseFile.cpp b/Firmware/SdBaseFile.cpp index dbcf77fb..be04ab1a 100644 --- a/Firmware/SdBaseFile.cpp +++ b/Firmware/SdBaseFile.cpp @@ -294,7 +294,7 @@ bool SdBaseFile::getFilename(char* name) { return true; } //------------------------------------------------------------------------------ -void SdBaseFile::getpos(fpos_t* pos) { +void SdBaseFile::getpos(filepos_t* pos) { pos->position = curPosition_; pos->cluster = curCluster_; } @@ -925,7 +925,7 @@ bool SdBaseFile::openRoot(SdVolume* vol) { * \return The byte if no error and not at eof else -1; */ int SdBaseFile::peek() { - fpos_t pos; + filepos_t pos; getpos(&pos); int c = read(); if (c >= 0) setpos(&pos); @@ -1492,7 +1492,7 @@ bool SdBaseFile::seekSet(uint32_t pos) { return false; } //------------------------------------------------------------------------------ -void SdBaseFile::setpos(fpos_t* pos) { +void SdBaseFile::setpos(filepos_t* pos) { curPosition_ = pos->position; curCluster_ = pos->cluster; } diff --git a/Firmware/SdBaseFile.h b/Firmware/SdBaseFile.h index dea299a6..ab73bf63 100644 --- a/Firmware/SdBaseFile.h +++ b/Firmware/SdBaseFile.h @@ -35,12 +35,12 @@ * \brief internal type for istream * do not use in user apps */ -struct fpos_t { +struct filepos_t { /** stream position */ uint32_t position; /** cluster for position */ uint32_t cluster; - fpos_t() : position(0), cluster(0) {} + filepos_t() : position(0), cluster(0) {} }; // use the gnu style oflag in open() @@ -196,11 +196,11 @@ class SdBaseFile { /** get position for streams * \param[out] pos struct to receive position */ - void getpos(fpos_t* pos); + void getpos(filepos_t* pos); /** set position for streams * \param[out] pos struct with value for new position */ - void setpos(fpos_t* pos); + void setpos(filepos_t* pos); //---------------------------------------------------------------------------- bool close(); bool contiguousRange(uint32_t* bgnBlock, uint32_t* endBlock); diff --git a/Firmware/pins.h b/Firmware/pins.h index 21975700..355c5951 100644 --- a/Firmware/pins.h +++ b/Firmware/pins.h @@ -385,10 +385,6 @@ #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 diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index c54848b9..1743d5e3 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -633,6 +633,61 @@ ISR(TIMER1_COMPA_vect) } } #ifdef HAVE_TMC2130_DRIVERS + uint32_t tmc2130_read(uint8_t chipselect, uint8_t address) + { + uint32_t val32; + uint8_t val0; + uint8_t val1; + uint8_t val2; + uint8_t val3; + uint8_t val4; + + //datagram1 - read request (address + dummy write) + SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE3)); + digitalWrite(chipselect,LOW); + SPI.transfer(address); + SPI.transfer(0); + SPI.transfer(0); + SPI.transfer(0); + SPI.transfer(0); + digitalWrite(chipselect, HIGH); + SPI.endTransaction(); + + //datagram2 - response + SPI.beginTransaction(SPISettings(1000000, 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(); + +#ifdef TMC_DBG_READS + MYSERIAL.print("SPIRead 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); +#endif + + val32 = (uint32_t)val1<<24 | (uint32_t)val2<<16 | (uint32_t)val3<<8 | (uint32_t)val4; + +#ifdef TMC_DBG_READS + MYSERIAL.print(" 0x"); + MYSERIAL.println(val32,HEX); +#endif + return val32; + } + void tmc2130_write(uint8_t chipselect, uint8_t address,uint8_t wval1,uint8_t wval2,uint8_t wval3,uint8_t wval4) { uint32_t val32; @@ -738,6 +793,36 @@ ISR(TIMER1_COMPA_vect) { 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(); + } + } #endif //HAVE_TMC2130_DRIVERS diff --git a/Firmware/stepper.h b/Firmware/stepper.h index f39fa601..a56a341a 100644 --- a/Firmware/stepper.h +++ b/Firmware/stepper.h @@ -88,6 +88,10 @@ void digipot_current(uint8_t driver, int current); void microstep_init(); void microstep_readings(); +#ifdef HAVE_TMC2130_DRIVERS +void tmc2130_check_overtemp(); +#endif + #ifdef BABYSTEPPING void babystep(const uint8_t axis,const bool direction); // perform a short step with a single stepper motor, outside of any convention #endif diff --git a/Firmware/variants/1_75mm_MK2-EINY01-E3Dv6full.h b/Firmware/variants/1_75mm_MK2-EINY01-E3Dv6full.h index 854e3ebe..3fde7ba4 100644 --- a/Firmware/variants/1_75mm_MK2-EINY01-E3Dv6full.h +++ b/Firmware/variants/1_75mm_MK2-EINY01-E3Dv6full.h @@ -24,7 +24,7 @@ *------------------------------------*/ // Steps per unit {X,Y,Z,E} -#define DEFAULT_AXIS_STEPS_PER_UNIT {100,100,3200/8,161.3*16} +#define DEFAULT_AXIS_STEPS_PER_UNIT {100,100,3200/8,161.3} // Endstop inverting const bool X_MIN_ENDSTOP_INVERTING = false; // set to true to invert the logic of the endstop. @@ -186,8 +186,8 @@ const bool Z_MIN_ENDSTOP_INVERTING = false; // set to true to invert the logic o // Motor Current settings for RAMBo mini PWM value = MotorCurrentSetting * 255 / range #if MOTHERBOARD == 102 || MOTHERBOARD == 302 || MOTHERBOARD == 300 #define MOTOR_CURRENT_PWM_RANGE 2000 -#define DEFAULT_PWM_MOTOR_CURRENT {270, 830, 450} // {XY,Z,E} -#define DEFAULT_PWM_MOTOR_CURRENT_LOUD {540, 830, 500} // {XY,Z,E} +#define DEFAULT_PWM_MOTOR_CURRENT {650, 750, 750} // {XY,Z,E} +#define DEFAULT_PWM_MOTOR_CURRENT_LOUD {650, 750, 750} // {XY,Z,E} #endif /*------------------------------------