You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Marlin/src/gcode/feature/digipot/M907-M910.cpp
+58-32Lines changed: 58 additions & 32 deletions
Original file line number
Diff line number
Diff line change
@@ -40,66 +40,86 @@
40
40
41
41
/**
42
42
* M907: Set digital trimpot motor current using axis codes X [Y] [Z] [I] [J] [K] [U] [V] [W] [E]
43
-
* B<current> - Special case for 4th (E) axis
44
-
* S<current> - Special case to set first 3 axes
43
+
* B<current> - Special case for E1 (Requires DIGIPOTSS_PIN or DIGIPOT_MCP4018 or DIGIPOT_MCP4451)
44
+
* C<current> - Special case for E2 (Requires DIGIPOTSS_PIN or DIGIPOT_MCP4018 or DIGIPOT_MCP4451)
45
+
* S<current> - Set current in mA for all axes (Requires DIGIPOTSS_PIN or DIGIPOT_MCP4018 or DIGIPOT_MCP4451), or
46
+
* Set percentage of max current for all axes (Requires HAS_DIGIPOT_DAC)
45
47
*/
46
48
voidGcodeSuite::M907() {
47
49
#if HAS_MOTOR_CURRENT_SPI
48
50
49
51
if (!parser.seen("BS" LOGICAL_AXES_STRING))
50
52
returnM907_report();
51
53
52
-
LOOP_LOGICAL_AXES(i) if (parser.seenval(IAXIS_CHAR(i))) stepper.set_digipot_current(i, parser.value_int());
53
-
if (parser.seenval('B')) stepper.set_digipot_current(4, parser.value_int());
54
-
if (parser.seenval('S')) LOOP_LE_N(i, 4) stepper.set_digipot_current(i, parser.value_int());
54
+
if (parser.seenval('S')) LOOP_L_N(i, MOTOR_CURRENT_COUNT) stepper.set_digipot_current(i, parser.value_int());
55
+
LOOP_LOGICAL_AXES(i) if (parser.seenval(IAXIS_CHAR(i))) stepper.set_digipot_current(i, parser.value_int()); // X Y Z (I J K U V W) E (map to drivers according to DIGIPOT_CHANNELS. Default with NUM_AXES 3: map X Y Z E to X Y Z E0)
56
+
// Additional extruders use B,C.
57
+
// TODO: Change these parameters because 'E' is used and D should be reserved for debugging. B<index>?
58
+
#if E_STEPPERS >= 2
59
+
if (parser.seenval('B')) stepper.set_digipot_current(E_AXIS + 1, parser.value_int());
60
+
#if E_STEPPERS >= 3
61
+
if (parser.seenval('C')) stepper.set_digipot_current(E_AXIS + 2, parser.value_int());
if (parser.seenval('Z')) stepper.set_digipot_current(1, parser.value_int());
79
-
#endif
80
-
#if PIN_EXISTS(MOTOR_CURRENT_PWM_E)
81
-
if (parser.seenval('E')) stepper.set_digipot_current(2, parser.value_int());
82
101
#endif
83
102
84
103
#endif// HAS_MOTOR_CURRENT_PWM
85
104
86
105
#if HAS_MOTOR_CURRENT_I2C
87
106
// this one uses actual amps in floating point
88
-
LOOP_LOGICAL_AXES(i) if (parser.seenval(IAXIS_CHAR(i))) digipot_i2c.set_current(i, parser.value_float());
89
-
// Additional extruders use B,C,D for channels 4,5,6.
90
-
// TODO: Change these parameters because 'E' is used. B<index>?
91
-
#if HAS_EXTRUDERS
92
-
for (uint8_t i = E_AXIS + 1; i < DIGIPOT_I2C_NUM_CHANNELS; i++)
107
+
if (parser.seenval('S')) LOOP_L_N(q, DIGIPOT_I2C_NUM_CHANNELS) digipot_i2c.set_current(q, parser.value_float());
108
+
LOOP_LOGICAL_AXES(i) if (parser.seenval(IAXIS_CHAR(i))) digipot_i2c.set_current(i, parser.value_float()); // X Y Z (I J K U V W) E (map to drivers according to pots adresses. Default with NUM_AXES 3 X Y Z E: map to X Y Z E0)
109
+
// Additional extruders use B,C,D.
110
+
// TODO: Change these parameters because 'E' is used and because 'D' should be reserved for debugging. B<index>?
111
+
#if E_STEPPERS >= 2
112
+
for (uint8_t i = E_AXIS + 1; i < _MAX(DIGIPOT_I2C_NUM_CHANNELS, (NUM_AXES + 3)); i++)
93
113
if (parser.seenval('B' + i - (E_AXIS + 1))) digipot_i2c.set_current(i, parser.value_float());
LOOP_LOGICAL_AXES(i) if (parser.seenval(IAXIS_CHAR(i))) stepper_dac.set_current_percent(i, parser.value_float());
122
+
LOOP_LOGICAL_AXES(i) if (parser.seenval(IAXIS_CHAR(i))) stepper_dac.set_current_percent(i, parser.value_float());// X Y Z (I J K U V W) E (map to drivers according to DAC_STEPPER_ORDER. Default with NUM_AXES 3: X Y Z E map to X Y Z E0)
103
123
#endif
104
124
}
105
125
@@ -119,8 +139,14 @@ void GcodeSuite::M907() {
119
139
SERIAL_CHAR('', IAXIS_CHAR(q));
120
140
SERIAL_ECHO(stepper.motor_current_setting[q]);
121
141
}
122
-
SERIAL_CHAR('', 'B'); // B (maps to E1 by default)
123
-
SERIAL_ECHOLN(stepper.motor_current_setting[4]);
142
+
#if E_STEPPERS >= 2
143
+
SERIAL_ECHOPGM_P(PSTR(" B"), stepper.motor_current_setting[E_AXIS + 1] // B (maps to E1 with NUM_AXES 3 according to DIGIPOT_CHANNELS)
144
+
#if E_STEPPERS >= 3
145
+
, PSTR(" C"), stepper.motor_current_setting[E_AXIS + 2] // C (mapping to E2 must be defined by DIGIPOT_CHANNELS)
0 commit comments