mirror of
https://github.com/MarlinFirmware/Marlin.git
synced 2026-01-03 13:20:32 -07:00
🧑💻 HAS_MOTOR_CURRENT_PWM_Z
This commit is contained in:
parent
99b790cc92
commit
59423da42f
6 changed files with 88 additions and 48 deletions
|
|
@ -56,16 +56,12 @@
|
|||
#else
|
||||
#define G2_PWM_Y 0
|
||||
#endif
|
||||
#if PIN_EXISTS(MOTOR_CURRENT_PWM_Z)
|
||||
#if HAS_MOTOR_CURRENT_PWM_Z
|
||||
#define G2_PWM_Z 1
|
||||
#else
|
||||
#define G2_PWM_Z 0
|
||||
#endif
|
||||
#if HAS_MOTOR_CURRENT_PWM_E
|
||||
#define G2_PWM_E 1
|
||||
#else
|
||||
#define G2_PWM_E 0
|
||||
#endif
|
||||
#define G2_PWM_E HAS_MOTOR_CURRENT_PWM_E
|
||||
#define G2_MASK_X(V) (G2_PWM_X * (V))
|
||||
#define G2_MASK_Y(V) (G2_PWM_Y * (V))
|
||||
#define G2_MASK_Z(V) (G2_PWM_Z * (V))
|
||||
|
|
@ -80,17 +76,22 @@ PWM_map ISR_table[NUM_PWMS] = PWM_MAP_INIT;
|
|||
|
||||
void Stepper::digipot_init() {
|
||||
|
||||
#if PIN_EXISTS(MOTOR_CURRENT_PWM_X)
|
||||
OUT_WRITE(MOTOR_CURRENT_PWM_X_PIN, 0); // init pins
|
||||
#if G2_PWM_X
|
||||
OUT_WRITE(MOTOR_CURRENT_PWM_X_PIN, LOW); // init pins
|
||||
#endif
|
||||
#if PIN_EXISTS(MOTOR_CURRENT_PWM_Y)
|
||||
OUT_WRITE(MOTOR_CURRENT_PWM_Y_PIN, 0);
|
||||
#if G2_PWM_Y
|
||||
OUT_WRITE(MOTOR_CURRENT_PWM_Y_PIN, LOW);
|
||||
#endif
|
||||
#if G2_PWM_Z
|
||||
OUT_WRITE(MOTOR_CURRENT_PWM_Z_PIN, 0);
|
||||
OUT_WRITE(MOTOR_CURRENT_PWM_Z_PIN, LOW);
|
||||
#endif
|
||||
#if G2_PWM_E
|
||||
OUT_WRITE(MOTOR_CURRENT_PWM_E_PIN, 0);
|
||||
#if PIN_EXISTS(MOTOR_CURRENT_PWM_E)
|
||||
OUT_WRITE(MOTOR_CURRENT_PWM_E_PIN, LOW);
|
||||
#endif
|
||||
#if PIN_EXISTS(MOTOR_CURRENT_PWM_E0)
|
||||
OUT_WRITE(MOTOR_CURRENT_PWM_E0_PIN, LOW);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define WPKEY (0x50574D << 8) // “PWM” in ASCII
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@
|
|||
* Set percentage of max current for all axes (Requires HAS_DIGIPOT_DAC)
|
||||
*/
|
||||
void GcodeSuite::M907() {
|
||||
|
||||
#if HAS_MOTOR_CURRENT_SPI
|
||||
|
||||
if (!parser.seen("BS" STR_AXES_LOGICAL))
|
||||
|
|
@ -56,8 +57,9 @@ void GcodeSuite::M907() {
|
|||
for (uint8_t i = 0; i < MOTOR_CURRENT_COUNT; ++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)
|
||||
// X Y Z I J K U V W E
|
||||
// Map to drivers according to pots addresses.
|
||||
// Default with NUM_AXES 3: map X Y Z E to X Y Z E0.
|
||||
LOOP_LOGICAL_AXES(i)
|
||||
if (parser.seenval(IAXIS_CHAR(i)))
|
||||
stepper.set_digipot_current(i, parser.value_int());
|
||||
|
|
@ -83,56 +85,88 @@ void GcodeSuite::M907() {
|
|||
#define HAS_X_Y_XY_I_J_K_U_V_W 1
|
||||
#endif
|
||||
|
||||
#if HAS_X_Y_XY_I_J_K_U_V_W || HAS_MOTOR_CURRENT_PWM_E || PIN_EXISTS(MOTOR_CURRENT_PWM_Z)
|
||||
#if ANY(HAS_X_Y_XY_I_J_K_U_V_W, HAS_MOTOR_CURRENT_PWM_E, HAS_MOTOR_CURRENT_PWM_Z)
|
||||
|
||||
if (!parser.seen("S"
|
||||
#if HAS_X_Y_XY_I_J_K_U_V_W
|
||||
NUM_AXIS_GANG("X", "Y",, "I", "J", "K", "U", "V", "W")
|
||||
#endif
|
||||
#if PIN_EXISTS(MOTOR_CURRENT_PWM_Z)
|
||||
"Z"
|
||||
#endif
|
||||
TERN_(HAS_MOTOR_CURRENT_PWM_Z, "Z")
|
||||
TERN_(HAS_MOTOR_CURRENT_PWM_E, "E")
|
||||
)) return M907_report();
|
||||
|
||||
if (parser.seenval('S')) for (uint8_t a = 0; a < MOTOR_CURRENT_COUNT; ++a) stepper.set_digipot_current(a, parser.value_int());
|
||||
// S<current> - Set all stepper current to the same value
|
||||
if (parser.seenval('S')) {
|
||||
const int16_t v = parser.value_int();
|
||||
for (uint8_t a = 0; a < MOTOR_CURRENT_COUNT; ++a)
|
||||
stepper.set_digipot_current(a, v);
|
||||
}
|
||||
|
||||
#if HAS_X_Y_XY_I_J_K_U_V_W
|
||||
if (NUM_AXIS_GANG(
|
||||
parser.seenval('X'), || parser.seenval('Y'), || false,
|
||||
|| parser.seenval('I'), || parser.seenval('J'), || parser.seenval('K'),
|
||||
|| parser.seenval('U'), || parser.seenval('V'), || parser.seenval('W')
|
||||
)) stepper.set_digipot_current(0, parser.value_int());
|
||||
#endif
|
||||
#if PIN_EXISTS(MOTOR_CURRENT_PWM_Z)
|
||||
if (parser.seenval('Z')) stepper.set_digipot_current(1, parser.value_int());
|
||||
#endif
|
||||
#if HAS_MOTOR_CURRENT_PWM_E
|
||||
if (parser.seenval('E')) stepper.set_digipot_current(2, parser.value_int());
|
||||
#endif
|
||||
// X Y I J K U V W - All aliases to set the current for "most axes."
|
||||
// Only the value of the last given parameter is used.
|
||||
if (ENABLED(HAS_X_Y_XY_I_J_K_U_V_W) && NUM_AXIS_GANG(
|
||||
parser.seenval('X'), || parser.seenval('Y'), || false,
|
||||
|| parser.seenval('I'), || parser.seenval('J'), || parser.seenval('K'),
|
||||
|| parser.seenval('U'), || parser.seenval('V'), || parser.seenval('W')
|
||||
))
|
||||
stepper.set_digipot_current(0, parser.value_int());
|
||||
|
||||
// Z<current> - Set the current just for the Z axis
|
||||
if (TERN0(HAS_MOTOR_CURRENT_PWM_Z, parser.seenval('Z')))
|
||||
stepper.set_digipot_current(1, parser.value_int());
|
||||
|
||||
// Z<current> - Set the current just for the Extruder
|
||||
if (TERN0(HAS_MOTOR_CURRENT_PWM_E, parser.seenval('E')))
|
||||
stepper.set_digipot_current(2, parser.value_int());
|
||||
|
||||
#endif
|
||||
|
||||
#endif // HAS_MOTOR_CURRENT_PWM
|
||||
|
||||
#if HAS_MOTOR_CURRENT_I2C
|
||||
// this one uses actual amps in floating point
|
||||
if (parser.seenval('S')) for (uint8_t q = 0; q < DIGIPOT_I2C_NUM_CHANNELS; ++q) 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 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)
|
||||
// This current driver takes actual Amps in floating point
|
||||
// rather than milli-amps or some scalar unit.
|
||||
|
||||
// S<current> - Set the same current in Amps on all channels
|
||||
if (parser.seenval('S')) {
|
||||
const float v = parser.value_float();
|
||||
for (uint8_t q = 0; q < DIGIPOT_I2C_NUM_CHANNELS; ++q)
|
||||
digipot_i2c.set_current(q, v);
|
||||
}
|
||||
|
||||
// X Y Z I J K U V W E
|
||||
// Map to drivers according to pots addresses.
|
||||
// Default with NUM_AXES 3: map X Y Z E to X Y Z E0.
|
||||
LOOP_LOGICAL_AXES(i)
|
||||
if (parser.seenval(IAXIS_CHAR(i)))
|
||||
digipot_i2c.set_current(i, parser.value_float());
|
||||
|
||||
// Additional extruders use B,C,D.
|
||||
// TODO: Change these parameters because 'E' is used and because 'D' should be reserved for debugging. B<index>?
|
||||
// TODO: Make parameters work like other axis-specific / stepper-specific. See above.
|
||||
#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());
|
||||
if (parser.seenval('B' + i - (E_AXIS + 1)))
|
||||
digipot_i2c.set_current(i, parser.value_float());
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif // HAS_MOTOR_CURRENT_I2C
|
||||
|
||||
#if HAS_MOTOR_CURRENT_DAC
|
||||
|
||||
// S<current> - Set the same current percentage on all axes
|
||||
if (parser.seenval('S')) {
|
||||
const float dac_percent = parser.value_float();
|
||||
LOOP_LOGICAL_AXES(i) 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()); // 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)
|
||||
|
||||
// X Y Z I J K U V W E
|
||||
// Map to drivers according to pots addresses.
|
||||
// Default with NUM_AXES 3: map X Y Z E to X Y Z E0.
|
||||
LOOP_LOGICAL_AXES(i)
|
||||
if (parser.seenval(IAXIS_CHAR(i)))
|
||||
stepper_dac.set_current_percent(i, parser.value_float());
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
@ -144,8 +178,10 @@ void GcodeSuite::M907() {
|
|||
report_heading_etc(forReplay, F(STR_STEPPER_MOTOR_CURRENTS));
|
||||
#if HAS_MOTOR_CURRENT_PWM
|
||||
SERIAL_ECHOLNPGM_P( // PWM-based has 3 values:
|
||||
PSTR(" M907 X"), stepper.motor_current_setting[0] // X, Y, (I, J, K, U, V, W)
|
||||
, SP_Z_STR, stepper.motor_current_setting[1] // Z
|
||||
PSTR(" M907 X"), stepper.motor_current_setting[0] // X, Y, (I, J, K, U, V, W)
|
||||
#if HAS_MOTOR_CURRENT_PWM_Z
|
||||
, SP_Z_STR, stepper.motor_current_setting[1] // Z
|
||||
#endif
|
||||
#if HAS_MOTOR_CURRENT_PWM_E
|
||||
, SP_E_STR, stepper.motor_current_setting[2] // E
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -2993,7 +2993,10 @@
|
|||
#if ANY_PIN(MOTOR_CURRENT_PWM_E, MOTOR_CURRENT_PWM_E0, MOTOR_CURRENT_PWM_E1)
|
||||
#define HAS_MOTOR_CURRENT_PWM_E 1
|
||||
#endif
|
||||
#if HAS_MOTOR_CURRENT_PWM_E || ANY_PIN(MOTOR_CURRENT_PWM_X, MOTOR_CURRENT_PWM_Y, MOTOR_CURRENT_PWM_XY, MOTOR_CURRENT_PWM_Z, MOTOR_CURRENT_PWM_I, MOTOR_CURRENT_PWM_J, MOTOR_CURRENT_PWM_K, MOTOR_CURRENT_PWM_U, MOTOR_CURRENT_PWM_V, MOTOR_CURRENT_PWM_W)
|
||||
#if PIN_EXISTS(MOTOR_CURRENT_PWM_Z)
|
||||
#define HAS_MOTOR_CURRENT_PWM_Z 1
|
||||
#endif
|
||||
#if HAS_MOTOR_CURRENT_PWM_Z || HAS_MOTOR_CURRENT_PWM_E || 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, MOTOR_CURRENT_PWM_U, MOTOR_CURRENT_PWM_V, MOTOR_CURRENT_PWM_W)
|
||||
#define HAS_MOTOR_CURRENT_PWM 1
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ void menu_backlash();
|
|||
#if ANY_PIN(MOTOR_CURRENT_PWM_XY, MOTOR_CURRENT_PWM_X, MOTOR_CURRENT_PWM_Y)
|
||||
EDIT_CURRENT_PWM(STR_A STR_B, 0);
|
||||
#endif
|
||||
#if PIN_EXISTS(MOTOR_CURRENT_PWM_Z)
|
||||
#if HAS_MOTOR_CURRENT_PWM_Z
|
||||
EDIT_CURRENT_PWM(STR_C, 1);
|
||||
#endif
|
||||
#if HAS_MOTOR_CURRENT_PWM_E
|
||||
|
|
|
|||
|
|
@ -3654,7 +3654,7 @@ void Stepper::report_positions() {
|
|||
#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)
|
||||
#if HAS_MOTOR_CURRENT_PWM_Z
|
||||
case 1:
|
||||
#endif
|
||||
#if HAS_MOTOR_CURRENT_PWM_E
|
||||
|
|
@ -3719,7 +3719,7 @@ void Stepper::report_positions() {
|
|||
#endif
|
||||
break;
|
||||
case 1:
|
||||
#if PIN_EXISTS(MOTOR_CURRENT_PWM_Z)
|
||||
#if HAS_MOTOR_CURRENT_PWM_Z
|
||||
_WRITE_CURRENT_PWM(Z);
|
||||
#endif
|
||||
break;
|
||||
|
|
@ -3784,7 +3784,7 @@ void Stepper::report_positions() {
|
|||
#if PIN_EXISTS(MOTOR_CURRENT_PWM_W)
|
||||
INIT_CURRENT_PWM(W);
|
||||
#endif
|
||||
#if PIN_EXISTS(MOTOR_CURRENT_PWM_Z)
|
||||
#if HAS_MOTOR_CURRENT_PWM_Z
|
||||
INIT_CURRENT_PWM(Z);
|
||||
#endif
|
||||
#if PIN_EXISTS(MOTOR_CURRENT_PWM_E)
|
||||
|
|
|
|||
|
|
@ -1119,7 +1119,7 @@
|
|||
#if PIN_EXISTS(MOTOR_CURRENT_PWM_XY)
|
||||
REPORT_NAME_DIGITAL(__LINE__, MOTOR_CURRENT_PWM_XY_PIN)
|
||||
#endif
|
||||
#if PIN_EXISTS(MOTOR_CURRENT_PWM_Z)
|
||||
#if HAS_MOTOR_CURRENT_PWM_Z
|
||||
REPORT_NAME_DIGITAL(__LINE__, MOTOR_CURRENT_PWM_Z_PIN)
|
||||
#endif
|
||||
#if PIN_EXISTS(MOTOR_CURRENT_PWM_I)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue