Skip to content

Commit

Permalink
Merge pull request prusa3d#4053 from vintagepc/2477-redux
Browse files Browse the repository at this point in the history
prusa3d#2477 Improved M-code control for stealth mode/normal mode
  • Loading branch information
3d-gussner authored Jul 27, 2023
2 parents ce141a2 + a2eafc5 commit 07d7bfa
Show file tree
Hide file tree
Showing 4 changed files with 202 additions and 140 deletions.
2 changes: 2 additions & 0 deletions Firmware/Marlin.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ void manage_inactivity(bool ignore_stepper_queue=false);
#define enable_z() poweron_z()
#define disable_z() poweroff_z()
#else
extern bool bEnableForce_z; // Used by ultralcd stealth toggle
void init_force_z();
void check_force_z();
void enable_force_z();
Expand Down Expand Up @@ -440,6 +441,7 @@ extern int8_t busy_state;
#define FORCE_HIGH_POWER_END force_high_power_mode(false)

void force_high_power_mode(bool start_high_power_section);
void change_power_mode_live(uint8_t mode);

#endif //TMC2130

Expand Down
85 changes: 62 additions & 23 deletions Firmware/Marlin_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2409,25 +2409,30 @@ void retract(bool retracting, bool swapretract = false) {


#ifdef TMC2130
void force_high_power_mode(bool start_high_power_section) {
#ifdef PSU_Delta
if (start_high_power_section == true) enable_force_z();
#endif //PSU_Delta
uint8_t silent;
silent = eeprom_read_byte((uint8_t*)EEPROM_SILENT);
if (silent == 1) {
//we are in silent mode, set to normal mode to enable crash detection

// Wait for the planner queue to drain and for the stepper timer routine to reach an idle state.
void change_power_mode_live(uint8_t mode)
{
// Wait for the planner queue to drain and for the stepper timer routine to reach an idle state.
st_synchronize();
cli();
tmc2130_mode = (start_high_power_section == true) ? TMC2130_MODE_NORMAL : TMC2130_MODE_SILENT;
tmc2130_mode = mode;
update_mode_profile();
tmc2130_init(TMCInitParams(FarmOrUserECool()));
// We may have missed a stepper timer interrupt due to the time spent in the tmc2130_init() routine.
// Be safe than sorry, reset the stepper timer before re-enabling interrupts.
st_reset_timer();
sei();
}

void force_high_power_mode(bool start_high_power_section) {
#ifdef PSU_Delta
if (start_high_power_section == true) enable_force_z();
#endif //PSU_Delta
uint8_t silent;
silent = eeprom_read_byte((uint8_t*)EEPROM_SILENT);
if (silent == 1 || tmc2130_mode == TMC2130_MODE_SILENT) {
//we are in silent mode, set to normal mode to enable crash detection
change_power_mode_live((start_high_power_section == true) ? TMC2130_MODE_NORMAL : TMC2130_MODE_SILENT);
}
}
#endif //TMC2130
Expand Down Expand Up @@ -8172,30 +8177,64 @@ SERIAL_PROTOCOLPGM("\n\n");
}
break;

/*!
#endif // TMC2130_SERVICE_CODES_M910_M918
/*!
### M914 - Set TMC2130 normal mode <a href="https://reprap.org/wiki/G-code#M914:_Set_TMC2130_normal_mode">M914: Set TMC2130 normal mode</a>
Not active in default, only if `TMC2130_SERVICE_CODES_M910_M918` is defined in source code.
Updates EEPROM only if "P" is given, otherwise temporary (lasts until reset or motor idle timeout)
#### Usage

M914 [ P | R ]

#### Parameters
- `P` - Make the mode change permanent (write to EEPROM)
- `R` - Revert to EEPROM value
*/
case 914:
{
tmc2130_mode = TMC2130_MODE_NORMAL;
update_mode_profile();
tmc2130_init(TMCInitParams(false, FarmOrUserECool()));
}
break;

/*!
### M915 - Set TMC2130 silent mode <a href="https://reprap.org/wiki/G-code#M915:_Set_TMC2130_silent_mode">M915: Set TMC2130 silent mode</a>
Not active in default, only if `TMC2130_SERVICE_CODES_M910_M918` is defined in source code.
Updates EEPROM only if "P" is given, otherwise temporary (lasts until reset or motor idle timeout)
#### Usage

M915 [ P | R ]

#### Parameters
- `P` - Make the mode change permanent (write to EEPROM)
- `R` - Revert to EEPROM value
*/
#ifdef TMC2130
case 914:
case 915:
{
tmc2130_mode = TMC2130_MODE_SILENT;
update_mode_profile();
tmc2130_init(TMCInitParams(false, FarmOrUserECool()));
uint8_t newMode = (mcode_in_progress==914) ? TMC2130_MODE_NORMAL : TMC2130_MODE_SILENT;
//printf_P(_n("tmc2130mode/smm/eep: %d %d %d %d"),tmc2130_mode,SilentModeMenu,eeprom_read_byte((uint8_t*)EEPROM_SILENT), bEnableForce_z);
if (code_seen('R'))
{
newMode = eeprom_read_byte((uint8_t*)EEPROM_SILENT);
}
else if (code_seen('P'))
{
uint8_t newMenuMode = (mcode_in_progress==914) ? SILENT_MODE_NORMAL : SILENT_MODE_STEALTH;
eeprom_update_byte((unsigned char *)EEPROM_SILENT, newMenuMode);
SilentModeMenu = newMenuMode;
//printf_P(_n("tmc2130mode/smm/eep: %d %d %d %d"),tmc2130_mode,SilentModeMenu,eeprom_read_byte((uint8_t*)EEPROM_SILENT), bEnableForce_z);
}

if (tmc2130_mode != newMode
#ifdef PSU_Delta
|| !bEnableForce_z
#endif
)
{
#ifdef PSU_Delta
enable_force_z();
#endif
change_power_mode_live(newMode);
}
}
break;

#endif // TMC2130
#ifdef TMC2130_SERVICE_CODES_M910_M918
/*!
### M916 - Set TMC2130 Stallguard sensitivity threshold <a href="https://reprap.org/wiki/G-code#M916:_Set_TMC2130_Stallguard_sensitivity_threshold">M916: Set TMC2130 Stallguard sensitivity threshold</a>
Not active in default, only if `TMC2130_SERVICE_CODES_M910_M918` is defined in source code.
Expand Down
11 changes: 8 additions & 3 deletions Firmware/mesh_bed_calibration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,12 @@ bool find_bed_induction_sensor_point_z(float minimum_z, uint8_t n_iter, int
bool high_deviation_occured = false;
bedPWMDisabled = 1;
#ifdef TMC2130
FORCE_HIGH_POWER_START;
bool bHighPowerForced = false;
if (tmc2130_mode == TMC2130_MODE_SILENT)
{
FORCE_HIGH_POWER_START;
bHighPowerForced = true;
}
#endif
//printf_P(PSTR("Min. Z: %f\n"), minimum_z);
#ifdef SUPPORT_VERBOSITY
Expand Down Expand Up @@ -1047,7 +1052,7 @@ bool find_bed_induction_sensor_point_z(float minimum_z, uint8_t n_iter, int
enable_z_endstop(endstop_z_enabled);
// SERIAL_ECHOLNPGM("find_bed_induction_sensor_point_z 3");
#ifdef TMC2130
FORCE_HIGH_POWER_END;
if (bHighPowerForced) FORCE_HIGH_POWER_END;
#endif
bedPWMDisabled = 0;
return true;
Expand All @@ -1057,7 +1062,7 @@ bool find_bed_induction_sensor_point_z(float minimum_z, uint8_t n_iter, int
enable_endstops(endstops_enabled);
enable_z_endstop(endstop_z_enabled);
#ifdef TMC2130
FORCE_HIGH_POWER_END;
if (bHighPowerForced) FORCE_HIGH_POWER_END;
#endif
bedPWMDisabled = 0;
return false;
Expand Down
Loading

0 comments on commit 07d7bfa

Please sign in to comment.