From 40fae26d753e1b7744a94f75decbe80e2a13c1db Mon Sep 17 00:00:00 2001 From: Robert Pelnar Date: Tue, 26 Sep 2017 12:22:58 +0200 Subject: [PATCH] Silent / Hight Power mode switching - wait for standstill parameter tunning: PWM_GRAD, PWM_AMPL TCOOLTHRS (XY) --- Firmware/Configuration_prusa.h | 14 ++++++++------ Firmware/tmc2130.cpp | 30 ++++++++++++++++++++++++++++++ Firmware/tmc2130.h | 1 + Firmware/ultralcd.cpp | 4 ++++ 4 files changed, 43 insertions(+), 6 deletions(-) diff --git a/Firmware/Configuration_prusa.h b/Firmware/Configuration_prusa.h index c4001fd1..214cc00a 100644 --- a/Firmware/Configuration_prusa.h +++ b/Firmware/Configuration_prusa.h @@ -112,13 +112,13 @@ const bool Z_MIN_ENDSTOP_INVERTING = false; // set to true to invert the logic o #define TMC2130_INTPOL_Z 1 // extrapolate 256 for Z axis #define TMC2130_INTPOL_E 1 // extrapolate 256 for E axis -#define TMC2130_PWM_GRAD_X 4 // PWMCONF -#define TMC2130_PWM_AMPL_X 210 // PWMCONF +#define TMC2130_PWM_GRAD_X 8 // PWMCONF +#define TMC2130_PWM_AMPL_X 220 // PWMCONF #define TMC2130_PWM_AUTO_X 1 // PWMCONF #define TMC2130_PWM_FREQ_X 2 // PWMCONF -#define TMC2130_PWM_GRAD_Y 4 // PWMCONF -#define TMC2130_PWM_AMPL_Y 215 // PWMCONF +#define TMC2130_PWM_GRAD_Y 8 // PWMCONF +#define TMC2130_PWM_AMPL_Y 225 // PWMCONF #define TMC2130_PWM_AUTO_Y 1 // PWMCONF #define TMC2130_PWM_FREQ_Y 2 // PWMCONF @@ -140,8 +140,10 @@ const bool Z_MIN_ENDSTOP_INVERTING = false; // set to true to invert the logic o #define TMC2130_TPWMTHRS 0 // TPWMTHRS - Sets the switching speed threshold based on TSTEP from stealthChop to spreadCycle mode #define TMC2130_THIGH 0 // THIGH - unused -#define TMC2130_TCOOLTHRS_X 450 // TCOOLTHRS - coolstep treshold -#define TMC2130_TCOOLTHRS_Y 450 // TCOOLTHRS - coolstep treshold +//#define TMC2130_TCOOLTHRS_X 450 // TCOOLTHRS - coolstep treshold +//#define TMC2130_TCOOLTHRS_Y 450 // TCOOLTHRS - coolstep treshold +#define TMC2130_TCOOLTHRS_X 430 // TCOOLTHRS - coolstep treshold +#define TMC2130_TCOOLTHRS_Y 430 // TCOOLTHRS - coolstep treshold #define TMC2130_TCOOLTHRS_Z 500 // TCOOLTHRS - coolstep treshold #define TMC2130_TCOOLTHRS_E 500 // TCOOLTHRS - coolstep treshold diff --git a/Firmware/tmc2130.cpp b/Firmware/tmc2130.cpp index e80b141b..5673cebf 100644 --- a/Firmware/tmc2130.cpp +++ b/Firmware/tmc2130.cpp @@ -429,17 +429,46 @@ void tmc2130_home_restart(uint8_t axis) tmc2130_axis_stalled[axis] = false; } +bool tmc2130_wait_standstill_xy(int timeout) +{ +// MYSERIAL.println("tmc2130_wait_standstill_xy"); + bool standstill = false; + while (!standstill && (timeout > 0)) + { + uint32_t drv_status_x = 0; + uint32_t drv_status_y = 0; + tmc2130_rd(tmc2130_cs[X_AXIS], TMC2130_REG_DRV_STATUS, &drv_status_x); + tmc2130_rd(tmc2130_cs[Y_AXIS], TMC2130_REG_DRV_STATUS, &drv_status_y); +/* MYSERIAL.print(timeout, 10); + MYSERIAL.println(' '); + MYSERIAL.print(drv_status_x, 16); + MYSERIAL.println(' '); + MYSERIAL.print(drv_status_y, 16); + MYSERIAL.println('#');*/ + standstill = (drv_status_x & 0x80000000) && (drv_status_y & 0x80000000); + tmc2130_check_overtemp(); + timeout--; + } + return standstill; +} + + void tmc2130_check_overtemp() { const static char TMC_OVERTEMP_MSG[] PROGMEM = "TMC DRIVER OVERTEMP "; static uint32_t checktime = 0; if (millis() - checktime > 1000 ) { +// MYSERIAL.print("DRV_STATUS "); for (int i = 0; i < 4; i++) { uint32_t drv_status = 0; skip_debug_msg = true; tmc2130_rd(tmc2130_cs[i], TMC2130_REG_DRV_STATUS, &drv_status); +/* MYSERIAL.print(i, DEC); + MYSERIAL.print(' '); + MYSERIAL.print(drv_status, 16);*/ + if (drv_status & ((uint32_t)1 << 26)) { // BIT 26 - over temp prewarning ~120C (+-20C) SERIAL_ERRORRPGM(TMC_OVERTEMP_MSG); @@ -450,6 +479,7 @@ void tmc2130_check_overtemp() } } +// MYSERIAL.println('#'); checktime = millis(); tmc2130_sg_change = true; } diff --git a/Firmware/tmc2130.h b/Firmware/tmc2130.h index b76732b9..01d52da2 100644 --- a/Firmware/tmc2130.h +++ b/Firmware/tmc2130.h @@ -52,6 +52,7 @@ extern uint16_t tmc2130_rd_MSCNT(uint8_t cs); extern void tmc2130_home_pause(uint8_t axis); extern void tmc2130_home_resume(uint8_t axis); +extern bool tmc2130_wait_standstill_xy(int timeout); #endif //TMC2130_H \ No newline at end of file diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index b2c628b5..1d1765ab 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -2533,6 +2533,10 @@ static void lcd_silent_mode_set() { eeprom_update_byte((unsigned char *)EEPROM_SILENT, SilentModeMenu); #ifdef TMC2130 st_synchronize(); + if (tmc2130_wait_standstill_xy(100)) + MYSERIAL.print("standstill OK"); + else + MYSERIAL.print("standstill NG!"); cli(); tmc2130_mode = SilentModeMenu?TMC2130_MODE_SILENT:TMC2130_MODE_NORMAL; tmc2130_init();