Skip to content

Commit 70e11b9

Browse files
Refactor Z axis full-step movement to G88 command
Moved Z axis full-step positioning logic from M88 to G88 command. Extracted movement code into a new move_z_to_next_fullstep() function, updated references in power_panic and LCD menu, and removed the old M88 implementation.
1 parent 12be8ac commit 70e11b9

File tree

5 files changed

+25
-33
lines changed

5 files changed

+25
-33
lines changed

Firmware/Marlin_main.cpp

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4606,15 +4606,15 @@ void process_commands()
46064606
calibration_status_set(CALIBRATION_STATUS_LIVE_ADJUST);
46074607
break;
46084608

4609-
/*!
4610-
### G88 - Reserved <a href="https://reprap.org/wiki/G-code#G88:_Reserved">G88: Reserved</a>
46114609

4612-
Currently has no effect.
4610+
/*!
4611+
### G88 - Move Z axis to next full-step position
46134612
*/
46144613

4615-
// Prusa3D specific: Don't know what it is for, it is in V2Calibration.gcode
4616-
46174614
case 88:
4615+
if (axis_known_position[Z_AXIS]) {
4616+
move_z_to_next_fullstep();
4617+
}
46184618
break;
46194619

46204620

@@ -5707,22 +5707,6 @@ void process_commands()
57075707
break;
57085708
#endif
57095709

5710-
/*!
5711-
### M88 - Move Z axis to a full-step position
5712-
*/
5713-
#ifdef TMC2130
5714-
case 88:
5715-
if (axis_known_position[Z_AXIS]) {
5716-
float target_z = current_position[Z_AXIS] + float(1024 - tmc2130_rd_MSCNT(Z_AXIS)) / (tmc2130_get_res(Z_AXIS) * cs.axis_steps_per_mm[Z_AXIS]) + 0.16f;
5717-
if (target_z <= max_pos[Z_AXIS]) {
5718-
current_position[Z_AXIS] = target_z;
5719-
plan_buffer_line_curposXYZE(homing_feedrate[Z_AXIS]/60);
5720-
st_synchronize();
5721-
}
5722-
}
5723-
break;
5724-
#endif
5725-
57265710
/*!
57275711
### M92 - Set Axis steps-per-unit <a href="https://reprap.org/wiki/G-code#M92:_Set_axis_steps_per_unit">M92: Set axis_steps_per_unit</a>
57285712
Allows programming of steps per unit (usually mm) for motor drives. These values are reset to firmware defaults on power on, unless saved to EEPROM if available (M500 in Marlin)

Firmware/power_panic.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -135,17 +135,7 @@ void uvlo_() {
135135
st_synchronize();
136136
disable_e0();
137137

138-
// Read out the current Z motor microstep counter to move the axis up towards
139-
// a full step before powering off. NOTE: we need to ensure to schedule more
140-
// than "dropsegments" steps in order to move (this is always the case here
141-
// due to UVLO_Z_AXIS_SHIFT being used)
142-
uint16_t z_res = tmc2130_get_res(Z_AXIS);
143-
uint16_t z_microsteps = tmc2130_rd_MSCNT(Z_AXIS);
144-
current_position[Z_AXIS] += float(1024 - z_microsteps)
145-
/ (z_res * cs.axis_steps_per_mm[Z_AXIS])
146-
+ UVLO_Z_AXIS_SHIFT;
147-
plan_buffer_line_curposXYZE(homing_feedrate[Z_AXIS]/60);
148-
st_synchronize();
138+
move_z_to_next_fullstep();
149139
poweroff_z();
150140

151141
// Write the file position.

Firmware/stepper.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,22 @@ void invert_z_endstop(bool endstop_invert)
250250
z_endstop_invert = endstop_invert;
251251
}
252252

253+
void move_z_to_next_fullstep() {
254+
#ifdef TMC2130
255+
// Read out the current Z motor microstep counter to move the axis up towards
256+
// a full step before powering off. NOTE: we need to ensure to schedule more
257+
// than "dropsegments" steps in order to move (this is always the case here
258+
// due to UVLO_Z_AXIS_SHIFT being used)
259+
uint16_t z_res = tmc2130_get_res(Z_AXIS);
260+
uint16_t z_microsteps = tmc2130_rd_MSCNT(Z_AXIS);
261+
current_position[Z_AXIS] += float(1024 - z_microsteps)
262+
/ (z_res * cs.axis_steps_per_mm[Z_AXIS])
263+
+ UVLO_Z_AXIS_SHIFT;
264+
plan_buffer_line_curposXYZE(homing_feedrate[Z_AXIS]/60);
265+
st_synchronize();
266+
#endif
267+
}
268+
253269
// __________________________
254270
// /| |\ _________________ ^
255271
// / | | \ /| |\ |

Firmware/stepper.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ bool enable_endstops(bool check); // Enable/disable endstop checking. Return the
6767
bool enable_z_endstop(bool check);
6868
void invert_z_endstop(bool endstop_invert);
6969

70+
void move_z_to_next_fullstep(); //Move Z axis up to the next fullstep
71+
7072
void checkStepperErrors(); //Print errors detected by the stepper
7173

7274
extern block_t *current_block; // A pointer to the block currently being traced

Firmware/ultralcd.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4526,7 +4526,7 @@ static void lcd_calibration_menu()
45264526
}
45274527
MENU_ITEM_GCODE_P(_T(MSG_AUTO_HOME), G28W);
45284528
if (axis_known_position[Z_AXIS]) {
4529-
MENU_ITEM_GCODE_P(_T(MSG_FULLSTEP_Z), PSTR("M88"));
4529+
MENU_ITEM_GCODE_P(_T(MSG_FULLSTEP_Z), PSTR("G88"));
45304530
}
45314531
#ifdef TMC2130
45324532
MENU_ITEM_FUNCTION_P(_T(MSG_BELTTEST), lcd_belttest_v);

0 commit comments

Comments
 (0)