Crashdetection + configuration file.
This commit is contained in:
parent
10cd30b9c6
commit
df1aa85526
6 changed files with 136 additions and 35 deletions
|
@ -115,7 +115,7 @@ const bool Z_MIN_ENDSTOP_INVERTING = false; // set to true to invert the logic o
|
|||
#define TMC2130_PWM_FREQ_X 2 // PWMCONF
|
||||
|
||||
#define TMC2130_PWM_GRAD_Y 4 // PWMCONF
|
||||
#define TMC2130_PWM_AMPL_Y 210 // PWMCONF
|
||||
#define TMC2130_PWM_AMPL_Y 215 // PWMCONF
|
||||
#define TMC2130_PWM_AUTO_Y 1 // PWMCONF
|
||||
#define TMC2130_PWM_FREQ_Y 2 // PWMCONF
|
||||
|
||||
|
@ -137,19 +137,19 @@ 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 239 // TCOOLTHRS - coolstep treshold
|
||||
#define TMC2130_TCOOLTHRS 500 // TCOOLTHRS - coolstep treshold
|
||||
|
||||
#define TMC2130_SG_HOMING 1 // stallguard homing
|
||||
//#define TMC2130_SG_HOMING_SW_XY 1 // stallguard "software" homing for XY axes
|
||||
#define TMC2130_SG_HOMING_SW_Z 1 // stallguard "software" homing for Z axis
|
||||
#define TMC2130_SG_THRS_X 0 // stallguard sensitivity for X axis
|
||||
#define TMC2130_SG_THRS_Y 0 // stallguard sensitivity for Y axis
|
||||
#define TMC2130_SG_THRS_Z 2 // stallguard sensitivity for Z axis
|
||||
#define TMC2130_SG_THRS_X 4 // stallguard sensitivity for X axis
|
||||
#define TMC2130_SG_THRS_Y 4 // stallguard sensitivity for Y axis
|
||||
#define TMC2130_SG_THRS_Z 3 // stallguard sensitivity for Z axis
|
||||
#define TMC2130_SG_DELTA 128 // stallguard delta [usteps] (minimum usteps before stallguard readed - SW homing)
|
||||
|
||||
//new settings is possible for vsense = 1, running current value > 31 set vsense to zero and shift both currents by 1 bit right (Z axis only)
|
||||
#define TMC2130_CURRENTS_H {3, 3, 5, 8} // default holding currents for all axes
|
||||
#define TMC2130_CURRENTS_R {13, 13, 20, 20} // default running currents for all axes
|
||||
#define TMC2130_CURRENTS_R {13, 31, 20, 22} // default running currents for all axes
|
||||
|
||||
//#define TMC2130_DEBUG
|
||||
//#define TMC2130_DEBUG_WR
|
||||
|
|
|
@ -583,7 +583,7 @@ void fsensor_restore_print_and_continue()
|
|||
}
|
||||
|
||||
|
||||
bool fsensor_enabled = true;
|
||||
bool fsensor_enabled = false;
|
||||
bool fsensor_ignore_error = true;
|
||||
bool fsensor_M600 = false;
|
||||
long fsensor_prev_pos_e = 0;
|
||||
|
@ -6964,6 +6964,26 @@ void restore_print_from_eeprom() {
|
|||
|
||||
//extern uint32_t sdpos_atomic;
|
||||
|
||||
void crashdet_enable()
|
||||
{
|
||||
tmc2130_sg_stop_on_crash = true;
|
||||
}
|
||||
|
||||
void crashdet_disable()
|
||||
{
|
||||
tmc2130_sg_stop_on_crash = false;
|
||||
}
|
||||
|
||||
void crashdet_stop_and_save_print()
|
||||
{
|
||||
stop_and_save_print_to_ram(10, 0); //XY - no change, Z 10mm up, E - no change
|
||||
}
|
||||
|
||||
void crashdet_restore_print_and_continue()
|
||||
{
|
||||
restore_print_from_ram_and_continue(0); //XYZ = orig, E - no change
|
||||
}
|
||||
|
||||
bool saved_printing = false;
|
||||
uint32_t saved_sdpos = 0;
|
||||
float saved_pos[4] = {0, 0, 0, 0};
|
||||
|
|
|
@ -94,11 +94,13 @@ static bool check_endstops = true;
|
|||
|
||||
static bool check_z_endstop = false;
|
||||
|
||||
int8_t SilentMode;
|
||||
int8_t SilentMode = 0;
|
||||
|
||||
volatile long count_position[NUM_AXIS] = { 0, 0, 0, 0};
|
||||
volatile signed char count_direction[NUM_AXIS] = { 1, 1, 1, 1};
|
||||
|
||||
uint8_t LastStepMask = 0;
|
||||
|
||||
#ifdef LIN_ADVANCE
|
||||
|
||||
uint16_t ADV_NEVER = 65535;
|
||||
|
@ -390,6 +392,8 @@ void isr() {
|
|||
}
|
||||
}
|
||||
|
||||
LastStepMask = 0;
|
||||
|
||||
if (current_block != NULL) {
|
||||
// Set directions TO DO This should be done once during init of trapezoid. Endstops -> interrupt
|
||||
out_bits = current_block->direction_bits;
|
||||
|
@ -623,6 +627,7 @@ void isr() {
|
|||
counter_x += current_block->steps_x;
|
||||
if (counter_x > 0) {
|
||||
WRITE(X_STEP_PIN, !INVERT_X_STEP_PIN);
|
||||
LastStepMask |= X_AXIS_MASK;
|
||||
#ifdef DEBUG_XSTEP_DUP_PIN
|
||||
WRITE(DEBUG_XSTEP_DUP_PIN,!INVERT_X_STEP_PIN);
|
||||
#endif //DEBUG_XSTEP_DUP_PIN
|
||||
|
@ -637,6 +642,7 @@ void isr() {
|
|||
counter_y += current_block->steps_y;
|
||||
if (counter_y > 0) {
|
||||
WRITE(Y_STEP_PIN, !INVERT_Y_STEP_PIN);
|
||||
LastStepMask |= Y_AXIS_MASK;
|
||||
#ifdef DEBUG_YSTEP_DUP_PIN
|
||||
WRITE(DEBUG_YSTEP_DUP_PIN,!INVERT_Y_STEP_PIN);
|
||||
#endif //DEBUG_YSTEP_DUP_PIN
|
||||
|
@ -660,7 +666,7 @@ void isr() {
|
|||
counter_z += current_block->steps_z;
|
||||
if (counter_z > 0) {
|
||||
WRITE(Z_STEP_PIN, !INVERT_Z_STEP_PIN);
|
||||
|
||||
LastStepMask |= Z_AXIS_MASK;
|
||||
#ifdef Z_DUAL_STEPPER_DRIVERS
|
||||
WRITE(Z2_STEP_PIN, !INVERT_Z_STEP_PIN);
|
||||
#endif
|
||||
|
@ -772,7 +778,9 @@ void isr() {
|
|||
plan_discard_current_block();
|
||||
}
|
||||
}
|
||||
check_fans();
|
||||
#ifdef TMC2130
|
||||
tmc2130_st_isr(LastStepMask);
|
||||
#endif //TMC2130
|
||||
}
|
||||
|
||||
#ifdef LIN_ADVANCE
|
||||
|
@ -1149,6 +1157,7 @@ void babystep(const uint8_t axis,const bool direction)
|
|||
|
||||
//perform step
|
||||
WRITE(X_STEP_PIN, !INVERT_X_STEP_PIN);
|
||||
LastStepMask |= X_AXIS_MASK;
|
||||
#ifdef DEBUG_XSTEP_DUP_PIN
|
||||
WRITE(DEBUG_XSTEP_DUP_PIN,!INVERT_X_STEP_PIN);
|
||||
#endif //DEBUG_XSTEP_DUP_PIN
|
||||
|
@ -1174,6 +1183,7 @@ void babystep(const uint8_t axis,const bool direction)
|
|||
|
||||
//perform step
|
||||
WRITE(Y_STEP_PIN, !INVERT_Y_STEP_PIN);
|
||||
LastStepMask |= Y_AXIS_MASK;
|
||||
#ifdef DEBUG_YSTEP_DUP_PIN
|
||||
WRITE(DEBUG_YSTEP_DUP_PIN,!INVERT_Y_STEP_PIN);
|
||||
#endif //DEBUG_YSTEP_DUP_PIN
|
||||
|
@ -1202,6 +1212,7 @@ void babystep(const uint8_t axis,const bool direction)
|
|||
#endif
|
||||
//perform step
|
||||
WRITE(Z_STEP_PIN, !INVERT_Z_STEP_PIN);
|
||||
LastStepMask |= Z_AXIS_MASK;
|
||||
#ifdef Z_DUAL_STEPPER_DRIVERS
|
||||
WRITE(Z2_STEP_PIN, !INVERT_Z_STEP_PIN);
|
||||
#endif
|
||||
|
@ -1387,7 +1398,3 @@ void microstep_readings()
|
|||
SERIAL_PROTOCOLLN( digitalRead(E1_MS2_PIN));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
extern float current_position[4];
|
||||
extern void st_get_position_xy(long &x, long &y);
|
||||
extern long st_get_position(uint8_t axis);
|
||||
extern void crashdet_stop_and_save_print();
|
||||
|
||||
//chipselect pins
|
||||
uint8_t tmc2130_cs[4] = { X_TMC2130_CS, Y_TMC2130_CS, Z_TMC2130_CS, E0_TMC2130_CS };
|
||||
|
@ -25,7 +26,7 @@ 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[3] = {0, 0, 0};
|
||||
uint8_t tmc2130_axis_stalled[4] = {0, 0, 0, 0};
|
||||
|
||||
//pwm_ampl
|
||||
uint8_t tmc2130_pwm_ampl[2] = {TMC2130_PWM_AMPL_X, TMC2130_PWM_AMPL_Y};
|
||||
|
@ -37,12 +38,17 @@ uint8_t tmc2130_pwm_auto[2] = {TMC2130_PWM_AUTO_X, TMC2130_PWM_AUTO_Y};
|
|||
uint8_t tmc2130_pwm_freq[2] = {TMC2130_PWM_FREQ_X, TMC2130_PWM_FREQ_Y};
|
||||
|
||||
|
||||
uint8_t tmc2131_axis_sg_thr[3] = {TMC2130_SG_THRS_X, TMC2130_SG_THRS_Y, TMC2130_SG_THRS_Z};
|
||||
uint8_t tmc2131_axis_sg_thr[4] = {TMC2130_SG_THRS_X, TMC2130_SG_THRS_Y, TMC2130_SG_THRS_Z, 0};
|
||||
|
||||
uint32_t tmc2131_axis_sg_pos[3] = {0, 0, 0};
|
||||
uint32_t tmc2131_axis_sg_pos[4] = {0, 0, 0, 0};
|
||||
|
||||
uint8_t sg_homing_axes_mask = 0x00;
|
||||
|
||||
bool tmc2130_sg_stop_on_crash = false;
|
||||
bool tmc2130_sg_crash = false;
|
||||
uint8_t tmc2130_diag_mask = 0x00;
|
||||
|
||||
|
||||
bool skip_debug_msg = false;
|
||||
|
||||
//TMC2130 registers
|
||||
|
@ -130,6 +136,7 @@ void tmc2130_init()
|
|||
// tmc2130_wr_CHOPCONF(tmc2130_cs[i], 3, 5, 1, 0, 0, 0, 0, 2, 1, 0, 0, 0, mres, TMC2130_INTPOL_XY, 0, 0);
|
||||
// tmc2130_wr(tmc2130_cs[i], TMC2130_REG_IHOLD_IRUN, 0x000f0000 | ((tmc2130_current_r[i] & 0x1f) << 8) | (tmc2130_current_h[i] & 0x1f));
|
||||
tmc2130_wr(tmc2130_cs[i], TMC2130_REG_TPOWERDOWN, 0x00000000);
|
||||
tmc2130_wr(tmc2130_cs[i], TMC2130_REG_COOLCONF, (((uint32_t)tmc2131_axis_sg_thr[i]) << 16) | ((uint32_t)1 << 24));
|
||||
tmc2130_wr(tmc2130_cs[i], TMC2130_REG_GCONF, (tmc2130_mode == TMC2130_MODE_SILENT)?TMC2130_GCONF_SILENT:TMC2130_GCONF_SGSENS);
|
||||
tmc2130_wr(tmc2130_cs[i], TMC2130_REG_TCOOLTHRS, (tmc2130_mode == TMC2130_MODE_SILENT)?0:TMC2130_TCOOLTHRS);
|
||||
tmc2130_wr_PWMCONF(tmc2130_cs[i], tmc2130_pwm_ampl[i], tmc2130_pwm_grad[i], tmc2130_pwm_freq[i], tmc2130_pwm_auto[i], 0, 0);
|
||||
|
@ -162,6 +169,35 @@ void tmc2130_init()
|
|||
}
|
||||
}
|
||||
|
||||
uint8_t tmc2130_sample_diag()
|
||||
{
|
||||
uint8_t mask = 0;
|
||||
if (READ(X_TMC2130_DIAG)) mask |= X_AXIS_MASK;
|
||||
if (READ(Y_TMC2130_DIAG)) mask |= Y_AXIS_MASK;
|
||||
// if (READ(Z_TMC2130_DIAG)) mask |= Z_AXIS_MASK;
|
||||
// if (READ(E0_TMC2130_DIAG)) mask |= E_AXIS_MASK;
|
||||
return mask;
|
||||
}
|
||||
|
||||
void tmc2130_st_isr(uint8_t last_step_mask)
|
||||
{
|
||||
bool error = false;
|
||||
uint8_t diag_mask = tmc2130_sample_diag();
|
||||
for (uint8_t axis = X_AXIS; axis <= Y_AXIS; axis++)
|
||||
{
|
||||
uint8_t mask = (X_AXIS_MASK << axis);
|
||||
if ((diag_mask & mask) && !(tmc2130_diag_mask & mask))
|
||||
error = true;
|
||||
}
|
||||
tmc2130_diag_mask = diag_mask;
|
||||
if (sg_homing_axes_mask == 0)
|
||||
if (tmc2130_sg_stop_on_crash && error)
|
||||
{
|
||||
tmc2130_sg_crash = true;
|
||||
crashdet_stop_and_save_print();
|
||||
}
|
||||
}
|
||||
|
||||
void tmc2130_update_sg_axis(uint8_t axis)
|
||||
{
|
||||
if (!tmc2130_axis_stalled[axis])
|
||||
|
@ -251,7 +287,7 @@ void tmc2130_home_enter(uint8_t axes_mask)
|
|||
tmc2130_axis_stalled[axis] = false;
|
||||
//Configuration to spreadCycle
|
||||
tmc2130_wr(cs, TMC2130_REG_GCONF, TMC2130_GCONF_NORMAL);
|
||||
tmc2130_wr(cs, TMC2130_REG_COOLCONF, ((unsigned long)tmc2131_axis_sg_thr[axis]) << 16);
|
||||
tmc2130_wr(cs, TMC2130_REG_COOLCONF, (((uint32_t)tmc2131_axis_sg_thr[axis]) << 16) | ((uint32_t)1 << 24));
|
||||
tmc2130_wr(cs, TMC2130_REG_TCOOLTHRS, TMC2130_TCOOLTHRS);
|
||||
#ifndef TMC2130_SG_HOMING_SW_XY
|
||||
if (mask & (X_AXIS_MASK | Y_AXIS_MASK))
|
||||
|
|
|
@ -9,15 +9,21 @@ extern uint8_t tmc2130_mode;
|
|||
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[3];
|
||||
extern uint8_t tmc2130_axis_stalled[4];
|
||||
|
||||
extern uint8_t tmc2131_axis_sg_thr[4];
|
||||
|
||||
extern bool tmc2130_sg_stop_on_crash;
|
||||
extern bool tmc2130_sg_crash;
|
||||
|
||||
extern uint8_t tmc2131_axis_sg_thr[3];
|
||||
|
||||
#define TMC2130_MODE_NORMAL 0
|
||||
#define TMC2130_MODE_SILENT 1
|
||||
|
||||
//initialize tmc2130
|
||||
extern void tmc2130_init();
|
||||
//check diag pins (called from stepper isr)
|
||||
extern void tmc2130_st_isr(uint8_t last_step_mask);
|
||||
//update stall guard (called from st_synchronize inside the loop)
|
||||
extern bool tmc2130_update_sg();
|
||||
//temperature watching (called from )
|
||||
|
|
|
@ -106,9 +106,15 @@ int8_t SDscrool = 0;
|
|||
int8_t SilentModeMenu = 0;
|
||||
|
||||
int8_t FSensorStateMenu = 0;
|
||||
|
||||
int8_t CrashDetectMenu = 0;
|
||||
|
||||
extern void fsensor_enable();
|
||||
extern void fsensor_disable();
|
||||
|
||||
extern void crashdet_enable();
|
||||
extern void crashdet_disable();
|
||||
|
||||
|
||||
#ifdef SNMM
|
||||
uint8_t snmm_extruder = 0;
|
||||
|
@ -166,7 +172,8 @@ extern bool powersupply;
|
|||
static void lcd_main_menu();
|
||||
static void lcd_tune_menu();
|
||||
static void lcd_prepare_menu();
|
||||
static void lcd_move_menu();
|
||||
//static void lcd_move_menu();
|
||||
static void lcd_crash_menu();
|
||||
static void lcd_settings_menu();
|
||||
static void lcd_calibration_menu();
|
||||
static void lcd_language_menu();
|
||||
|
@ -2520,18 +2527,6 @@ void EEPROM_read(int pos, uint8_t* value, uint8_t size)
|
|||
} while (--size);
|
||||
}
|
||||
|
||||
static void lcd_fsensor_state_set()
|
||||
{
|
||||
if (!FSensorStateMenu==0) {
|
||||
fsensor_disable();
|
||||
}else{
|
||||
fsensor_enable();
|
||||
}
|
||||
FSensorStateMenu = !FSensorStateMenu;
|
||||
lcd_goto_menu(lcd_settings_menu, 7);
|
||||
|
||||
}
|
||||
|
||||
static void lcd_silent_mode_set() {
|
||||
SilentModeMenu = !SilentModeMenu;
|
||||
eeprom_update_byte((unsigned char *)EEPROM_SILENT, SilentModeMenu);
|
||||
|
@ -2545,6 +2540,19 @@ static void lcd_silent_mode_set() {
|
|||
digipot_init();
|
||||
lcd_goto_menu(lcd_settings_menu, 7);
|
||||
}
|
||||
|
||||
static void lcd_crash_mode_set()
|
||||
{
|
||||
if (!CrashDetectMenu==0) {
|
||||
crashdet_disable();
|
||||
}else{
|
||||
crashdet_enable();
|
||||
}
|
||||
CrashDetectMenu = !CrashDetectMenu;
|
||||
lcd_goto_menu(lcd_settings_menu, 7);
|
||||
|
||||
}
|
||||
|
||||
static void lcd_set_lang(unsigned char lang) {
|
||||
lang_selected = lang;
|
||||
firstrun = 1;
|
||||
|
@ -2555,6 +2563,18 @@ static void lcd_set_lang(unsigned char lang) {
|
|||
langsel = LANGSEL_ACTIVE;
|
||||
}
|
||||
|
||||
static void lcd_fsensor_state_set()
|
||||
{
|
||||
if (!FSensorStateMenu==0) {
|
||||
fsensor_disable();
|
||||
}else{
|
||||
fsensor_enable();
|
||||
}
|
||||
FSensorStateMenu = !FSensorStateMenu;
|
||||
lcd_goto_menu(lcd_settings_menu, 7);
|
||||
|
||||
}
|
||||
|
||||
void lcd_force_language_selection() {
|
||||
eeprom_update_byte((unsigned char *)EEPROM_LANG, LANG_ID_FORCE_SELECTION);
|
||||
}
|
||||
|
@ -2721,6 +2741,10 @@ void lcd_toshiba_flash_air_compatibility_toggle()
|
|||
eeprom_update_byte((uint8_t*)EEPROM_TOSHIBA_FLASH_AIR_COMPATIBLITY, card.ToshibaFlashAir_isEnabled());
|
||||
}
|
||||
|
||||
static void lcd_crash_menu()
|
||||
{
|
||||
}
|
||||
|
||||
static void lcd_settings_menu()
|
||||
{
|
||||
EEPROM_read(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu));
|
||||
|
@ -2744,12 +2768,20 @@ static void lcd_settings_menu()
|
|||
MENU_ITEM(function, MSG_FSENSOR_ON, lcd_fsensor_state_set);
|
||||
}
|
||||
|
||||
if ((SilentModeMenu == 0) || (farm_mode) ) {
|
||||
if (SilentModeMenu == 0) {
|
||||
MENU_ITEM(function, MSG_SILENT_MODE_OFF, lcd_silent_mode_set);
|
||||
} else {
|
||||
MENU_ITEM(function, MSG_SILENT_MODE_ON, lcd_silent_mode_set);
|
||||
}
|
||||
|
||||
if (SilentModeMenu == 0) {
|
||||
if (CrashDetectMenu == 0) {
|
||||
MENU_ITEM(function, MSG_CRASHDETECT_OFF, lcd_crash_mode_set);
|
||||
} else {
|
||||
MENU_ITEM(function, MSG_CRASHDETECT_ON, lcd_crash_mode_set);
|
||||
}
|
||||
}
|
||||
|
||||
if (!isPrintPaused && !homing_flag)
|
||||
{
|
||||
MENU_ITEM(submenu, MSG_BABYSTEP_Z, lcd_babystep_z);
|
||||
|
|
Loading…
Reference in a new issue