TMC2130 feedrate and acceleration limitation - separate profiles for normal and stealth mode

This commit is contained in:
Robert Pelnar 2018-07-19 18:56:01 +02:00
parent c3e28b490c
commit 2ce210a8bb
5 changed files with 96 additions and 25 deletions

View file

@ -56,8 +56,8 @@ void Config_StoreSettings(uint16_t offset, uint8_t level)
int i = offset;
EEPROM_WRITE_VAR(i,ver); // invalidate data first
EEPROM_WRITE_VAR(i,axis_steps_per_unit);
EEPROM_WRITE_VAR(i,max_feedrate);
EEPROM_WRITE_VAR(i,max_acceleration_units_per_sq_second);
EEPROM_WRITE_VAR(i,max_feedrate_normal);
EEPROM_WRITE_VAR(i,max_acceleration_units_per_sq_second_normal);
EEPROM_WRITE_VAR(i,acceleration);
EEPROM_WRITE_VAR(i,retract_acceleration);
EEPROM_WRITE_VAR(i,minimumfeedrate);
@ -126,12 +126,9 @@ void Config_StoreSettings(uint16_t offset, uint8_t level)
}
#endif //LIN_ADVANCE
/* MYSERIAL.print("Top address used:\n");
MYSERIAL.print(i);
MYSERIAL.print("; (0x");
MYSERIAL.print(i, HEX);
MYSERIAL.println(")");
*/
EEPROM_WRITE_VAR(i,max_feedrate_silent);
EEPROM_WRITE_VAR(i,max_acceleration_units_per_sq_second_silent);
char ver2[4]=EEPROM_VERSION;
i=offset;
EEPROM_WRITE_VAR(i,ver2); // validate data
@ -144,10 +141,30 @@ void Config_StoreSettings(uint16_t offset, uint8_t level)
#ifndef DISABLE_M503
void Config_PrintSettings(uint8_t level)
{ // Always have this function, even with EEPROM_SETTINGS disabled, the current values will be shown
#ifdef TMC2130
printf_P(PSTR(
"%SSteps per unit:\n%S M92 X%.2f Y%.2f Z%.2f E%.2f\n"
"%SMaximum feedrates - normal (mm/s):\n%S M203 X%.2f Y%.2f Z%.2f E%.2f\n"
"%SMaximum feedrates - stealth (mm/s):\n%S M203 X%.2f Y%.2f Z%.2f E%.2f\n"
"%SMaximum acceleration - normal (mm/s2):\n%S M201 X%lu Y%lu Z%lu E%lu\n"
"%SMaximum acceleration - stealth (mm/s2):\n%S M201 X%lu Y%lu Z%lu E%lu\n"
"%SAcceleration: S=acceleration, T=retract acceleration\n%S M204 S%.2f T%.2f\n"
"%SAdvanced variables: S=Min feedrate (mm/s), T=Min travel feedrate (mm/s), B=minimum segment time (ms), X=maximum XY jerk (mm/s), Z=maximum Z jerk (mm/s), E=maximum E jerk (mm/s)\n%S M205 S%.2f T%.2f B%.2f X%.2f Y%.2f Z%.2f E%.2f\n"
"%SHome offset (mm):\n%S M206 X%.2f Y%.2f Z%.2f\n"
),
echomagic, echomagic, axis_steps_per_unit[X_AXIS], axis_steps_per_unit[Y_AXIS], axis_steps_per_unit[Z_AXIS], axis_steps_per_unit[E_AXIS],
echomagic, echomagic, max_feedrate_normal[X_AXIS], max_feedrate_normal[Y_AXIS], max_feedrate_normal[Z_AXIS], max_feedrate_normal[E_AXIS],
echomagic, echomagic, max_feedrate_silent[X_AXIS], max_feedrate_silent[Y_AXIS], max_feedrate_silent[Z_AXIS], max_feedrate_silent[E_AXIS],
echomagic, echomagic, max_acceleration_units_per_sq_second_normal[X_AXIS], max_acceleration_units_per_sq_second_normal[Y_AXIS], max_acceleration_units_per_sq_second_normal[Z_AXIS], max_acceleration_units_per_sq_second_normal[E_AXIS],
echomagic, echomagic, max_acceleration_units_per_sq_second_silent[X_AXIS], max_acceleration_units_per_sq_second_silent[Y_AXIS], max_acceleration_units_per_sq_second_silent[Z_AXIS], max_acceleration_units_per_sq_second_silent[E_AXIS],
echomagic, echomagic, acceleration, retract_acceleration,
echomagic, echomagic, minimumfeedrate, mintravelfeedrate, minsegmenttime, max_jerk[X_AXIS], max_jerk[Y_AXIS], max_jerk[Z_AXIS], max_jerk[E_AXIS],
echomagic, echomagic, add_homing[X_AXIS], add_homing[Y_AXIS], add_homing[Z_AXIS]
#else //TMC2130
printf_P(PSTR(
"%SSteps per unit:\n%S M92 X%.2f Y%.2f Z%.2f E%.2f\n"
"%SMaximum feedrates (mm/s):\n%S M203 X%.2f Y%.2f Z%.2f E%.2f\n"
"%SMaximum Acceleration (mm/s2):\n%S M201 X%.2f Y%.2f Z%.2f E%.2f\n"
"%SMaximum acceleration (mm/s2):\n%S M201 X%lu Y%lu Z%lu E%lu\n"
"%SAcceleration: S=acceleration, T=retract acceleration\n%S M204 S%.2f T%.2f\n"
"%SAdvanced variables: S=Min feedrate (mm/s), T=Min travel feedrate (mm/s), B=minimum segment time (ms), X=maximum XY jerk (mm/s), Z=maximum Z jerk (mm/s), E=maximum E jerk (mm/s)\n%S M205 S%.2f T%.2f B%.2f X%.2f Y%.2f Z%.2f E%.2f\n"
"%SHome offset (mm):\n%S M206 X%.2f Y%.2f Z%.2f\n"
@ -158,6 +175,7 @@ void Config_PrintSettings(uint8_t level)
echomagic, echomagic, acceleration, retract_acceleration,
echomagic, echomagic, minimumfeedrate, mintravelfeedrate, minsegmenttime, max_jerk[X_AXIS], max_jerk[Y_AXIS], max_jerk[Z_AXIS], max_jerk[E_AXIS],
echomagic, echomagic, add_homing[X_AXIS], add_homing[Y_AXIS], add_homing[Z_AXIS]
#endif //TMC2130
);
#ifdef PIDTEMP
printf_P(PSTR("%SPID settings:\n%S M301 P%.2f I%.2f D%.2f\n"),
@ -219,11 +237,10 @@ bool Config_RetrieveSettings(uint16_t offset, uint8_t level)
{
// version number match
EEPROM_READ_VAR(i,axis_steps_per_unit);
EEPROM_READ_VAR(i,max_feedrate);
EEPROM_READ_VAR(i,max_acceleration_units_per_sq_second);
EEPROM_READ_VAR(i,max_feedrate_normal);
EEPROM_READ_VAR(i,max_acceleration_units_per_sq_second_normal);
// steps per sq second need to be updated to agree with the units per sq second (as they are what is used in the planner)
reset_acceleration_rates();
EEPROM_READ_VAR(i,acceleration);
EEPROM_READ_VAR(i,retract_acceleration);
@ -293,6 +310,11 @@ bool Config_RetrieveSettings(uint16_t offset, uint8_t level)
#endif //LIN_ADVANCE
calculate_extruder_multipliers();
EEPROM_READ_VAR(i,max_feedrate_silent);
EEPROM_READ_VAR(i,max_acceleration_units_per_sq_second_silent);
reset_acceleration_rates();
// Call updatePID (similar to when we have processed M301)
updatePID();
SERIAL_ECHO_START;
@ -321,14 +343,18 @@ void Config_ResetDefault()
float tmp1[]=DEFAULT_AXIS_STEPS_PER_UNIT;
float tmp2[]=DEFAULT_MAX_FEEDRATE;
long tmp3[]=DEFAULT_MAX_ACCELERATION;
float tmp4[]=DEFAULT_MAX_FEEDRATE_SILENT;
long tmp5[]=DEFAULT_MAX_ACCELERATION_SILENT;
for (short i=0;i<4;i++)
{
axis_steps_per_unit[i]=tmp1[i];
max_feedrate[i]=tmp2[i];
max_acceleration_units_per_sq_second[i]=tmp3[i];
max_feedrate_normal[i]=tmp2[i];
max_acceleration_units_per_sq_second_normal[i]=tmp3[i];
max_feedrate_silent[i]=tmp4[i];
max_acceleration_units_per_sq_second_silent[i]=tmp5[i];
}
// steps per sq second need to be updated to agree with the units per sq second
// steps per sq second need to be updated to agree with the units per sq second
reset_acceleration_rates();
acceleration=DEFAULT_ACCELERATION;

View file

@ -1378,7 +1378,6 @@ void setup()
#ifdef TMC2130
uint8_t silentMode = eeprom_read_byte((uint8_t*)EEPROM_SILENT);
if (silentMode == 0xff) silentMode = 0;
// tmc2130_mode = silentMode?TMC2130_MODE_SILENT:TMC2130_MODE_NORMAL;
tmc2130_mode = TMC2130_MODE_NORMAL;
uint8_t crashdet = eeprom_read_byte((uint8_t*)EEPROM_CRASH_DET);
if (crashdet && !farm_mode)
@ -1432,6 +1431,7 @@ void setup()
#ifdef TMC2130
tmc2130_mode = silentMode?TMC2130_MODE_SILENT:TMC2130_MODE_NORMAL;
update_mode_profile();
tmc2130_init();
#endif //TMC2130
@ -2600,6 +2600,7 @@ void force_high_power_mode(bool start_high_power_section) {
st_synchronize();
cli();
tmc2130_mode = (start_high_power_section == true) ? TMC2130_MODE_NORMAL : TMC2130_MODE_SILENT;
update_mode_profile();
tmc2130_init();
// 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.
@ -6910,6 +6911,7 @@ Sigma_Exit:
case 914: // M914 Set normal mode
{
tmc2130_mode = TMC2130_MODE_NORMAL;
update_mode_profile();
tmc2130_init();
}
break;
@ -6917,6 +6919,7 @@ Sigma_Exit:
case 915: // M915 Set silent mode
{
tmc2130_mode = TMC2130_MODE_SILENT;
update_mode_profile();
tmc2130_init();
}
break;

View file

@ -72,9 +72,20 @@
//===========================================================================
unsigned long minsegmenttime;
float max_feedrate[NUM_AXIS]; // set the max speeds
// Use M203 to override by software
float max_feedrate_normal[NUM_AXIS]; // max speeds for normal mode
float max_feedrate_silent[NUM_AXIS]; // max speeds for silent mode
float* max_feedrate = max_feedrate_normal;
// Use M92 to override by software
float axis_steps_per_unit[NUM_AXIS];
unsigned long max_acceleration_units_per_sq_second[NUM_AXIS]; // Use M201 to override by software
// Use M201 to override by software
unsigned long max_acceleration_units_per_sq_second_normal[NUM_AXIS];
unsigned long max_acceleration_units_per_sq_second_silent[NUM_AXIS];
unsigned long* max_acceleration_units_per_sq_second = max_acceleration_units_per_sq_second_normal;
float minimumfeedrate;
float acceleration; // Normal acceleration mm/s^2 THIS IS THE DEFAULT ACCELERATION for all moves. M204 SXXXX
float retract_acceleration; // mm/s^2 filament pull-pack and push-forward while standing still in the other axis M204 TXXXX
@ -1283,11 +1294,28 @@ void set_extrude_min_temp(float temp)
void reset_acceleration_rates()
{
for(int8_t i=0; i < NUM_AXIS; i++)
{
axis_steps_per_sqr_second[i] = max_acceleration_units_per_sq_second[i] * axis_steps_per_unit[i];
}
}
unsigned char number_of_blocks() {
#ifdef TMC2130
void update_mode_profile()
{
if (tmc2130_mode == TMC2130_MODE_NORMAL)
{
max_feedrate = max_feedrate_normal;
max_acceleration_units_per_sq_second = max_acceleration_units_per_sq_second_normal;
}
else if (tmc2130_mode == TMC2130_MODE_SILENT)
{
max_feedrate = max_feedrate_silent;
max_acceleration_units_per_sq_second = max_acceleration_units_per_sq_second_silent;
}
reset_acceleration_rates();
}
#endif //TMC2130
unsigned char number_of_blocks()
{
return (block_buffer_head + BLOCK_BUFFER_SIZE - block_buffer_tail) & (BLOCK_BUFFER_SIZE - 1);
}
#ifdef PLANNER_DIAGNOSTICS

View file

@ -159,9 +159,20 @@ void plan_set_e_position(const float &e);
void check_axes_activity();
extern unsigned long minsegmenttime;
extern float max_feedrate[NUM_AXIS]; // set the max speeds
// Use M203 to override by software
extern float max_feedrate_normal[NUM_AXIS];
extern float max_feedrate_silent[NUM_AXIS];
extern float* max_feedrate;
// Use M92 to override by software
extern float axis_steps_per_unit[NUM_AXIS];
extern unsigned long max_acceleration_units_per_sq_second[NUM_AXIS]; // Use M201 to override by software
// Use M201 to override by software
extern unsigned long max_acceleration_units_per_sq_second_normal[NUM_AXIS];
extern unsigned long max_acceleration_units_per_sq_second_silent[NUM_AXIS];
extern unsigned long* max_acceleration_units_per_sq_second;
extern float minimumfeedrate;
extern float acceleration; // Normal acceleration mm/s^2 THIS IS THE DEFAULT ACCELERATION for all moves. M204 SXXXX
extern float retract_acceleration; // mm/s^2 filament pull-pack and push-forward while standing still in the other axis M204 TXXXX
@ -241,6 +252,8 @@ void set_extrude_min_temp(float temp);
void reset_acceleration_rates();
#endif
void update_mode_profile();
unsigned char number_of_blocks();
// #define PLANNER_DIAGNOSTICS

View file

@ -4066,8 +4066,9 @@ static void lcd_silent_mode_set() {
// MYSERIAL.print("standstill OK");
// else
// MYSERIAL.print("standstill NG!");
cli();
cli();
tmc2130_mode = (SilentModeMenu != SILENT_MODE_NORMAL)?TMC2130_MODE_SILENT:TMC2130_MODE_NORMAL;
update_mode_profile();
tmc2130_init();
// We may have missed a stepper timer interrupt due to the time spent in tmc2130_init.
// Be safe than sorry, reset the stepper timer before re-enabling interrupts.