mirror of
https://github.com/MarlinFirmware/Marlin.git
synced 2024-11-26 21:36:21 +00:00
💥 Update Motor Current G-codes for extra axes (#23975)
This commit is contained in:
parent
5ccdc9ced7
commit
543bbf02fc
@ -59,7 +59,7 @@ int StepperDAC::init() {
|
||||
}
|
||||
|
||||
void StepperDAC::set_current_value(const uint8_t channel, uint16_t val) {
|
||||
if (!dac_present) return;
|
||||
if (!(dac_present && channel < LOGICAL_AXES)) return;
|
||||
|
||||
NOMORE(val, uint16_t(DAC_STEPPER_MAX));
|
||||
|
||||
@ -84,13 +84,11 @@ void StepperDAC::print_values() {
|
||||
if (!dac_present) return;
|
||||
SERIAL_ECHO_MSG("Stepper current values in % (Amps):");
|
||||
SERIAL_ECHO_START();
|
||||
SERIAL_ECHOPGM_P(SP_X_LBL, dac_perc(X_AXIS), PSTR(" ("), dac_amps(X_AXIS), PSTR(")"));
|
||||
#if HAS_Y_AXIS
|
||||
SERIAL_ECHOPGM_P(SP_Y_LBL, dac_perc(Y_AXIS), PSTR(" ("), dac_amps(Y_AXIS), PSTR(")"));
|
||||
#endif
|
||||
#if HAS_Z_AXIS
|
||||
SERIAL_ECHOPGM_P(SP_Z_LBL, dac_perc(Z_AXIS), PSTR(" ("), dac_amps(Z_AXIS), PSTR(")"));
|
||||
#endif
|
||||
LOOP_LOGICAL_AXES(a) {
|
||||
SERIAL_CHAR(' ', IAXIS_CHAR(a), ':');
|
||||
SERIAL_ECHO(dac_perc(a));
|
||||
SERIAL_ECHOPGM_P(PSTR(" ("), dac_amps(AxisEnum(a)), PSTR(")"));
|
||||
}
|
||||
#if HAS_EXTRUDERS
|
||||
SERIAL_ECHOLNPGM_P(SP_E_LBL, dac_perc(E_AXIS), PSTR(" ("), dac_amps(E_AXIS), PSTR(")"));
|
||||
#endif
|
||||
|
@ -79,7 +79,7 @@ void GcodeSuite::G34() {
|
||||
stepper.set_digipot_current(Z_AXIS, target_current);
|
||||
#elif HAS_MOTOR_CURRENT_PWM
|
||||
const uint16_t target_current = parser.intval('S', GANTRY_CALIBRATION_CURRENT);
|
||||
const uint32_t previous_current = stepper.motor_current_setting[Z_AXIS];
|
||||
const uint32_t previous_current = stepper.motor_current_setting[1]; // Z
|
||||
stepper.set_digipot_current(1, target_current);
|
||||
#elif HAS_MOTOR_CURRENT_DAC
|
||||
const float target_current = parser.floatval('S', GANTRY_CALIBRATION_CURRENT);
|
||||
|
@ -40,8 +40,10 @@
|
||||
|
||||
/**
|
||||
* M907: Set digital trimpot motor current using axis codes X [Y] [Z] [I] [J] [K] [E]
|
||||
* B<current> - Special case for 4th (E) axis
|
||||
* S<current> - Special case to set first 3 axes
|
||||
* B<current> - Special case for E1 (Requires DIGIPOTSS_PIN or DIGIPOT_MCP4018 or DIGIPOT_MCP4451)
|
||||
* C<current> - Special case for E2 (Requires DIGIPOTSS_PIN or DIGIPOT_MCP4018 or DIGIPOT_MCP4451)
|
||||
* S<current> - Set current in mA for all axes (Requires DIGIPOTSS_PIN or DIGIPOT_MCP4018 or DIGIPOT_MCP4451), or
|
||||
* Set percentage of max current for all axes (Requires HAS_DIGIPOT_DAC)
|
||||
*/
|
||||
void GcodeSuite::M907() {
|
||||
#if HAS_MOTOR_CURRENT_SPI
|
||||
@ -49,14 +51,27 @@ void GcodeSuite::M907() {
|
||||
if (!parser.seen("BS" LOGICAL_AXES_STRING))
|
||||
return M907_report();
|
||||
|
||||
LOOP_LOGICAL_AXES(i) if (parser.seenval(IAXIS_CHAR(i))) stepper.set_digipot_current(i, parser.value_int());
|
||||
if (parser.seenval('B')) stepper.set_digipot_current(4, parser.value_int());
|
||||
if (parser.seenval('S')) LOOP_LE_N(i, 4) stepper.set_digipot_current(i, parser.value_int());
|
||||
if (parser.seenval('S')) LOOP_L_N(i, MOTOR_CURRENT_COUNT) stepper.set_digipot_current(i, parser.value_int());
|
||||
LOOP_LOGICAL_AXES(i) if (parser.seenval(IAXIS_CHAR(i))) stepper.set_digipot_current(i, parser.value_int()); // X Y Z (I J K) E (map to drivers according to DIGIPOT_CHANNELS. Default with NUM_AXES 3: map X Y Z E to X Y Z E0)
|
||||
// Additional extruders use B,C.
|
||||
// TODO: Change these parameters because 'E' is used and D should be reserved for debugging. B<index>?
|
||||
#if E_STEPPERS >= 2
|
||||
if (parser.seenval('B')) stepper.set_digipot_current(E_AXIS + 1, parser.value_int());
|
||||
#if E_STEPPERS >= 3
|
||||
if (parser.seenval('C')) stepper.set_digipot_current(E_AXIS + 2, parser.value_int());
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#elif HAS_MOTOR_CURRENT_PWM
|
||||
|
||||
if (!parser.seen(
|
||||
#if ANY_PIN(MOTOR_CURRENT_PWM_X, MOTOR_CURRENT_PWM_Y, MOTOR_CURRENT_PWM_XY, MOTOR_CURRENT_PWM_I, MOTOR_CURRENT_PWM_J, MOTOR_CURRENT_PWM_K)
|
||||
#define HAS_X_Y_XY_I_J_K 1
|
||||
#endif
|
||||
|
||||
#if HAS_X_Y_XY_I_J_K || ANY_PIN(MOTOR_CURRENT_PWM_E, MOTOR_CURRENT_PWM_Z)
|
||||
|
||||
if (!parser.seen("S"
|
||||
#if HAS_X_Y_XY_I_J_K
|
||||
"XY" SECONDARY_AXIS_GANG("I", "J", "K")
|
||||
#endif
|
||||
#if PIN_EXISTS(MOTOR_CURRENT_PWM_Z)
|
||||
@ -67,7 +82,9 @@ void GcodeSuite::M907() {
|
||||
#endif
|
||||
)) return M907_report();
|
||||
|
||||
#if ANY_PIN(MOTOR_CURRENT_PWM_X, MOTOR_CURRENT_PWM_Y, MOTOR_CURRENT_PWM_XY, MOTOR_CURRENT_PWM_I, MOTOR_CURRENT_PWM_J, MOTOR_CURRENT_PWM_K)
|
||||
if (parser.seenval('S')) LOOP_L_N(a, MOTOR_CURRENT_COUNT) stepper.set_digipot_current(a, parser.value_int());
|
||||
|
||||
#if HAS_X_Y_XY_I_J_K
|
||||
if (LINEAR_AXIS_GANG(
|
||||
parser.seenval('X'), || parser.seenval('Y'), || false,
|
||||
|| parser.seenval('I'), || parser.seenval('J'), || parser.seenval('K')
|
||||
@ -80,15 +97,18 @@ void GcodeSuite::M907() {
|
||||
if (parser.seenval('E')) stepper.set_digipot_current(2, parser.value_int());
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif // HAS_MOTOR_CURRENT_PWM
|
||||
|
||||
#if HAS_MOTOR_CURRENT_I2C
|
||||
// this one uses actual amps in floating point
|
||||
LOOP_LOGICAL_AXES(i) if (parser.seenval(IAXIS_CHAR(i))) digipot_i2c.set_current(i, parser.value_float());
|
||||
// Additional extruders use B,C,D for channels 4,5,6.
|
||||
// TODO: Change these parameters because 'E' is used. B<index>?
|
||||
#if HAS_EXTRUDERS
|
||||
for (uint8_t i = E_AXIS + 1; i < DIGIPOT_I2C_NUM_CHANNELS; i++)
|
||||
if (parser.seenval('S')) LOOP_L_N(q, DIGIPOT_I2C_NUM_CHANNELS) digipot_i2c.set_current(q, parser.value_float());
|
||||
LOOP_LOGICAL_AXES(i) if (parser.seenval(IAXIS_CHAR(i))) digipot_i2c.set_current(i, parser.value_float()); // X Y Z (I J K) E (map to drivers according to pots adresses. Default with NUM_AXES 3 X Y Z E: map to X Y Z E0)
|
||||
// Additional extruders use B,C,D.
|
||||
// TODO: Change these parameters because 'E' is used and because 'D' should be reserved for debugging. B<index>?
|
||||
#if E_STEPPERS >= 2
|
||||
for (uint8_t i = E_AXIS + 1; i < _MAX(DIGIPOT_I2C_NUM_CHANNELS, (NUM_AXES + 3)); i++)
|
||||
if (parser.seenval('B' + i - (E_AXIS + 1))) digipot_i2c.set_current(i, parser.value_float());
|
||||
#endif
|
||||
#endif
|
||||
@ -96,9 +116,9 @@ void GcodeSuite::M907() {
|
||||
#if HAS_MOTOR_CURRENT_DAC
|
||||
if (parser.seenval('S')) {
|
||||
const float dac_percent = parser.value_float();
|
||||
LOOP_LE_N(i, 4) stepper_dac.set_current_percent(i, dac_percent);
|
||||
LOOP_LOGICAL_AXES(i) stepper_dac.set_current_percent(i, dac_percent);
|
||||
}
|
||||
LOOP_LOGICAL_AXES(i) if (parser.seenval(IAXIS_CHAR(i))) stepper_dac.set_current_percent(i, parser.value_float());
|
||||
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) E (map to drivers according to DAC_STEPPER_ORDER. Default with NUM_AXES 3: X Y Z E map to X Y Z E0)
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -118,8 +138,14 @@ void GcodeSuite::M907() {
|
||||
SERIAL_CHAR(' ', IAXIS_CHAR(q));
|
||||
SERIAL_ECHO(stepper.motor_current_setting[q]);
|
||||
}
|
||||
SERIAL_CHAR(' ', 'B'); // B (maps to E1 by default)
|
||||
SERIAL_ECHOLN(stepper.motor_current_setting[4]);
|
||||
#if E_STEPPERS >= 2
|
||||
SERIAL_ECHOPGM_P(PSTR(" B"), stepper.motor_current_setting[E_AXIS + 1] // B (maps to E1 with NUM_AXES 3 according to DIGIPOT_CHANNELS)
|
||||
#if E_STEPPERS >= 3
|
||||
, PSTR(" C"), stepper.motor_current_setting[E_AXIS + 2] // C (mapping to E2 must be defined by DIGIPOT_CHANNELS)
|
||||
#endif
|
||||
);
|
||||
#endif
|
||||
SERIAL_EOL();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -187,10 +187,15 @@ void GcodeSuite::M569_report(const bool forReplay/*=true*/) {
|
||||
if (TERN0(Z3_HAS_STEALTHCHOP, stepperZ3.get_stored_stealthChop())) { say_M569(forReplay, F("I2 Z"), true); }
|
||||
if (TERN0(Z4_HAS_STEALTHCHOP, stepperZ4.get_stored_stealthChop())) { say_M569(forReplay, F("I3 Z"), true); }
|
||||
|
||||
if (TERN0( I_HAS_STEALTHCHOP, stepperI.get_stored_stealthChop())) { say_M569(forReplay, FPSTR(SP_I_STR), true); }
|
||||
if (TERN0( J_HAS_STEALTHCHOP, stepperJ.get_stored_stealthChop())) { say_M569(forReplay, FPSTR(SP_J_STR), true); }
|
||||
if (TERN0( K_HAS_STEALTHCHOP, stepperK.get_stored_stealthChop())) { say_M569(forReplay, FPSTR(SP_K_STR), true); }
|
||||
|
||||
#if HAS_I_AXIS
|
||||
if (TERN0(I_HAS_STEALTHCHOP, stepperI.get_stored_stealthChop())) { say_M569(forReplay, FPSTR(SP_I_STR), true); }
|
||||
#endif
|
||||
#if HAS_J_AXIS
|
||||
if (TERN0(J_HAS_STEALTHCHOP, stepperJ.get_stored_stealthChop())) { say_M569(forReplay, FPSTR(SP_J_STR), true); }
|
||||
#endif
|
||||
#if HAS_K_AXIS
|
||||
if (TERN0(K_HAS_STEALTHCHOP, stepperK.get_stored_stealthChop())) { say_M569(forReplay, FPSTR(SP_K_STR), true); }
|
||||
#endif
|
||||
if (TERN0(E0_HAS_STEALTHCHOP, stepperE0.get_stored_stealthChop())) { say_M569(forReplay, F("T0 E"), true); }
|
||||
if (TERN0(E1_HAS_STEALTHCHOP, stepperE1.get_stored_stealthChop())) { say_M569(forReplay, F("T1 E"), true); }
|
||||
if (TERN0(E2_HAS_STEALTHCHOP, stepperE2.get_stored_stealthChop())) { say_M569(forReplay, F("T2 E"), true); }
|
||||
|
@ -447,7 +447,15 @@ typedef struct SettingsDataStruct {
|
||||
// HAS_MOTOR_CURRENT_PWM
|
||||
//
|
||||
#ifndef MOTOR_CURRENT_COUNT
|
||||
#define MOTOR_CURRENT_COUNT LINEAR_AXES
|
||||
#if HAS_MOTOR_CURRENT_PWM
|
||||
#define MOTOR_CURRENT_COUNT 3
|
||||
#elif HAS_MOTOR_CURRENT_DAC
|
||||
#define MOTOR_CURRENT_COUNT LOGICAL_AXES
|
||||
#elif HAS_MOTOR_CURRENT_I2C
|
||||
#define MOTOR_CURRENT_COUNT DIGIPOT_I2C_NUM_CHANNELS
|
||||
#else // HAS_MOTOR_CURRENT_SPI
|
||||
#define MOTOR_CURRENT_COUNT DISTINCT_AXES
|
||||
#endif
|
||||
#endif
|
||||
uint32_t motor_current_setting[MOTOR_CURRENT_COUNT]; // M907 X Z E ...
|
||||
|
||||
|
@ -3222,7 +3222,7 @@ void Stepper::report_positions() {
|
||||
if (!initialized) return;
|
||||
LOOP_L_N(i, COUNT(motor_current_setting)) {
|
||||
switch (i) {
|
||||
#if ANY_PIN(MOTOR_CURRENT_PWM_XY, MOTOR_CURRENT_PWM_X, MOTOR_CURRENT_PWM_Y)
|
||||
#if ANY_PIN(MOTOR_CURRENT_PWM_XY, MOTOR_CURRENT_PWM_X, MOTOR_CURRENT_PWM_Y, MOTOR_CURRENT_PWM_I, MOTOR_CURRENT_PWM_J, MOTOR_CURRENT_PWM_K, MOTOR_CURRENT_PWM_U, MOTOR_CURRENT_PWM_V, MOTOR_CURRENT_PWM_W)
|
||||
case 0:
|
||||
#endif
|
||||
#if PIN_EXISTS(MOTOR_CURRENT_PWM_Z)
|
||||
@ -3270,6 +3270,24 @@ void Stepper::report_positions() {
|
||||
#if PIN_EXISTS(MOTOR_CURRENT_PWM_XY)
|
||||
_WRITE_CURRENT_PWM(XY);
|
||||
#endif
|
||||
#if PIN_EXISTS(MOTOR_CURRENT_PWM_I)
|
||||
_WRITE_CURRENT_PWM(I);
|
||||
#endif
|
||||
#if PIN_EXISTS(MOTOR_CURRENT_PWM_J)
|
||||
_WRITE_CURRENT_PWM(J);
|
||||
#endif
|
||||
#if PIN_EXISTS(MOTOR_CURRENT_PWM_K)
|
||||
_WRITE_CURRENT_PWM(K);
|
||||
#endif
|
||||
#if PIN_EXISTS(MOTOR_CURRENT_PWM_U)
|
||||
_WRITE_CURRENT_PWM(U);
|
||||
#endif
|
||||
#if PIN_EXISTS(MOTOR_CURRENT_PWM_V)
|
||||
_WRITE_CURRENT_PWM(V);
|
||||
#endif
|
||||
#if PIN_EXISTS(MOTOR_CURRENT_PWM_W)
|
||||
_WRITE_CURRENT_PWM(W);
|
||||
#endif
|
||||
break;
|
||||
case 1:
|
||||
#if PIN_EXISTS(MOTOR_CURRENT_PWM_Z)
|
||||
@ -3319,6 +3337,24 @@ void Stepper::report_positions() {
|
||||
#if PIN_EXISTS(MOTOR_CURRENT_PWM_XY)
|
||||
INIT_CURRENT_PWM(XY);
|
||||
#endif
|
||||
#if PIN_EXISTS(MOTOR_CURRENT_PWM_I)
|
||||
INIT_CURRENT_PWM(I);
|
||||
#endif
|
||||
#if PIN_EXISTS(MOTOR_CURRENT_PWM_J)
|
||||
INIT_CURRENT_PWM(J);
|
||||
#endif
|
||||
#if PIN_EXISTS(MOTOR_CURRENT_PWM_K)
|
||||
INIT_CURRENT_PWM(K);
|
||||
#endif
|
||||
#if PIN_EXISTS(MOTOR_CURRENT_PWM_U)
|
||||
INIT_CURRENT_PWM(U);
|
||||
#endif
|
||||
#if PIN_EXISTS(MOTOR_CURRENT_PWM_V)
|
||||
INIT_CURRENT_PWM(V);
|
||||
#endif
|
||||
#if PIN_EXISTS(MOTOR_CURRENT_PWM_W)
|
||||
INIT_CURRENT_PWM(W);
|
||||
#endif
|
||||
#if PIN_EXISTS(MOTOR_CURRENT_PWM_Z)
|
||||
INIT_CURRENT_PWM(Z);
|
||||
#endif
|
||||
|
@ -318,7 +318,7 @@ class Stepper {
|
||||
#ifndef MOTOR_CURRENT_PWM_FREQUENCY
|
||||
#define MOTOR_CURRENT_PWM_FREQUENCY 31400
|
||||
#endif
|
||||
#define MOTOR_CURRENT_COUNT LINEAR_AXES
|
||||
#define MOTOR_CURRENT_COUNT 3
|
||||
#elif HAS_MOTOR_CURRENT_SPI
|
||||
static constexpr uint32_t digipot_count[] = DIGIPOT_MOTOR_CURRENT;
|
||||
#define MOTOR_CURRENT_COUNT COUNT(Stepper::digipot_count)
|
||||
|
Loading…
Reference in New Issue
Block a user