|
@@ -338,6 +338,17 @@ xyze_int8_t Stepper::count_direction{0};
|
338
|
338
|
#if DISABLED(MIXING_EXTRUDER)
|
339
|
339
|
#define E_APPLY_STEP(v,Q) E_STEP_WRITE(stepper_extruder, v)
|
340
|
340
|
#endif
|
|
341
|
+#define TIMER_SETUP_NS (CYCLES_TO_NS(TIMER_READ_ADD_AND_STORE_CYCLES))
|
|
342
|
+
|
|
343
|
+#define PULSE_HIGH_TICK_COUNT hal_timer_t(NS_TO_PULSE_TIMER_TICKS(_MIN_PULSE_HIGH_NS - _MIN(_MIN_PULSE_HIGH_NS, TIMER_SETUP_NS)))
|
|
344
|
+#define PULSE_LOW_TICK_COUNT hal_timer_t(NS_TO_PULSE_TIMER_TICKS(_MIN_PULSE_LOW_NS - _MIN(_MIN_PULSE_LOW_NS, TIMER_SETUP_NS)))
|
|
345
|
+
|
|
346
|
+#define START_TIMED_PULSE(DIR) (end_tick_count = HAL_timer_get_count(PULSE_TIMER_NUM) + PULSE_##DIR##_TICK_COUNT)
|
|
347
|
+#define AWAIT_TIMED_PULSE() while (HAL_timer_get_count(PULSE_TIMER_NUM) < end_tick_count) { }
|
|
348
|
+#define START_HIGH_PULSE() START_TIMED_PULSE(HIGH)
|
|
349
|
+#define START_LOW_PULSE() START_TIMED_PULSE(LOW)
|
|
350
|
+#define AWAIT_HIGH_PULSE() AWAIT_TIMED_PULSE()
|
|
351
|
+#define AWAIT_LOW_PULSE() AWAIT_TIMED_PULSE()
|
341
|
352
|
|
342
|
353
|
void Stepper::wake_up() {
|
343
|
354
|
// TCNT1 = 0;
|
|
@@ -1416,47 +1427,50 @@ void Stepper::stepper_pulse_phase_isr() {
|
1416
|
1427
|
// Just update the value we will get at the end of the loop
|
1417
|
1428
|
step_events_completed += events_to_do;
|
1418
|
1429
|
|
1419
|
|
- // Get the timer count and estimate the end of the pulse
|
1420
|
|
- hal_timer_t pulse_end = HAL_timer_get_count(PULSE_TIMER_NUM) + hal_timer_t(MIN_PULSE_TICKS);
|
1421
|
|
-
|
1422
|
|
- const hal_timer_t added_step_ticks = hal_timer_t(ADDED_STEP_TICKS);
|
1423
|
|
-
|
1424
|
1430
|
// Take multiple steps per interrupt (For high speed moves)
|
1425
|
|
- do {
|
|
1431
|
+ bool firstStep = true;
|
|
1432
|
+ xyze_bool_t step_needed{0};
|
|
1433
|
+ hal_timer_t end_tick_count;
|
1426
|
1434
|
|
|
1435
|
+ do {
|
1427
|
1436
|
#define _APPLY_STEP(AXIS) AXIS ##_APPLY_STEP
|
1428
|
1437
|
#define _INVERT_STEP_PIN(AXIS) INVERT_## AXIS ##_STEP_PIN
|
1429
|
1438
|
|
|
1439
|
+ // Determine if pulses are needed
|
|
1440
|
+ #define PULSE_PREP(AXIS) do{ \
|
|
1441
|
+ delta_error[_AXIS(AXIS)] += advance_dividend[_AXIS(AXIS)]; \
|
|
1442
|
+ step_needed[_AXIS(AXIS)] = (delta_error[_AXIS(AXIS)] >= 0); \
|
|
1443
|
+ if (step_needed[_AXIS(AXIS)]) { \
|
|
1444
|
+ count_position[_AXIS(AXIS)] += count_direction[_AXIS(AXIS)]; \
|
|
1445
|
+ delta_error[_AXIS(AXIS)] -= advance_divisor; \
|
|
1446
|
+ } \
|
|
1447
|
+ }while(0)
|
|
1448
|
+
|
1430
|
1449
|
// Start an active pulse, if Bresenham says so, and update position
|
1431
|
1450
|
#define PULSE_START(AXIS) do{ \
|
1432
|
|
- delta_error[_AXIS(AXIS)] += advance_dividend[_AXIS(AXIS)]; \
|
1433
|
|
- if (delta_error[_AXIS(AXIS)] >= 0) { \
|
|
1451
|
+ if (step_needed[_AXIS(AXIS)]) { \
|
1434
|
1452
|
_APPLY_STEP(AXIS)(!_INVERT_STEP_PIN(AXIS), 0); \
|
1435
|
|
- count_position[_AXIS(AXIS)] += count_direction[_AXIS(AXIS)]; \
|
1436
|
1453
|
} \
|
1437
|
1454
|
}while(0)
|
1438
|
1455
|
|
1439
|
1456
|
// Stop an active pulse, if any, and adjust error term
|
1440
|
1457
|
#define PULSE_STOP(AXIS) do { \
|
1441
|
|
- if (delta_error[_AXIS(AXIS)] >= 0) { \
|
1442
|
|
- delta_error[_AXIS(AXIS)] -= advance_divisor; \
|
|
1458
|
+ if (step_needed[_AXIS(AXIS)]) { \
|
1443
|
1459
|
_APPLY_STEP(AXIS)(_INVERT_STEP_PIN(AXIS), 0); \
|
1444
|
1460
|
} \
|
1445
|
1461
|
}while(0)
|
1446
|
1462
|
|
1447
|
|
- // Pulse start
|
|
1463
|
+ // Determine if pulses are needed
|
1448
|
1464
|
#if HAS_X_STEP
|
1449
|
|
- PULSE_START(X);
|
|
1465
|
+ PULSE_PREP(X);
|
1450
|
1466
|
#endif
|
1451
|
1467
|
#if HAS_Y_STEP
|
1452
|
|
- PULSE_START(Y);
|
|
1468
|
+ PULSE_PREP(Y);
|
1453
|
1469
|
#endif
|
1454
|
1470
|
#if HAS_Z_STEP
|
1455
|
|
- PULSE_START(Z);
|
|
1471
|
+ PULSE_PREP(Z);
|
1456
|
1472
|
#endif
|
1457
|
1473
|
|
1458
|
|
- // Pulse Extruders
|
1459
|
|
- // Tick the E axis, correct error term and update position
|
1460
|
1474
|
#if EITHER(LIN_ADVANCE, MIXING_EXTRUDER)
|
1461
|
1475
|
delta_error.e += advance_dividend.e;
|
1462
|
1476
|
if (delta_error.e >= 0) {
|
|
@@ -1465,14 +1479,36 @@ void Stepper::stepper_pulse_phase_isr() {
|
1465
|
1479
|
delta_error.e -= advance_divisor;
|
1466
|
1480
|
// Don't step E here - But remember the number of steps to perform
|
1467
|
1481
|
motor_direction(E_AXIS) ? --LA_steps : ++LA_steps;
|
1468
|
|
- #else // !LIN_ADVANCE && MIXING_EXTRUDER
|
1469
|
|
- // Don't adjust delta_error.e here!
|
1470
|
|
- // Being positive is the criteria for ending the pulse.
|
1471
|
|
- E_STEP_WRITE(mixer.get_next_stepper(), !INVERT_E_STEP_PIN);
|
|
1482
|
+ #else
|
|
1483
|
+ step_needed[E_AXIS] = delta_error.e >= 0;
|
1472
|
1484
|
#endif
|
1473
|
1485
|
}
|
1474
|
|
- #else // !LIN_ADVANCE && !MIXING_EXTRUDER
|
1475
|
|
- #if HAS_E0_STEP
|
|
1486
|
+ #elif HAS_E0_STEP
|
|
1487
|
+ PULSE_PREP(E);
|
|
1488
|
+ #endif
|
|
1489
|
+
|
|
1490
|
+ #if (MINIMUM_STEPPER_PULSE || MAXIMUM_STEPPER_RATE) && DISABLED(I2S_STEPPER_STREAM)
|
|
1491
|
+ if (firstStep)
|
|
1492
|
+ firstStep = false;
|
|
1493
|
+ else
|
|
1494
|
+ AWAIT_LOW_PULSE();
|
|
1495
|
+ #endif
|
|
1496
|
+
|
|
1497
|
+ // Pulse start
|
|
1498
|
+ #if HAS_X_STEP
|
|
1499
|
+ PULSE_START(X);
|
|
1500
|
+ #endif
|
|
1501
|
+ #if HAS_Y_STEP
|
|
1502
|
+ PULSE_START(Y);
|
|
1503
|
+ #endif
|
|
1504
|
+ #if HAS_Z_STEP
|
|
1505
|
+ PULSE_START(Z);
|
|
1506
|
+ #endif
|
|
1507
|
+
|
|
1508
|
+ #if DISABLED(LIN_ADVANCE)
|
|
1509
|
+ #if ENABLED(MIXING_EXTRUDER)
|
|
1510
|
+ if (step_needed[E_AXIS]) E_STEP_WRITE(mixer.get_next_stepper(), !INVERT_E_STEP_PIN);
|
|
1511
|
+ #elif HAS_E0_STEP
|
1476
|
1512
|
PULSE_START(E);
|
1477
|
1513
|
#endif
|
1478
|
1514
|
#endif
|
|
@@ -1482,14 +1518,11 @@ void Stepper::stepper_pulse_phase_isr() {
|
1482
|
1518
|
#endif
|
1483
|
1519
|
|
1484
|
1520
|
// TODO: need to deal with MINIMUM_STEPPER_PULSE over i2s
|
1485
|
|
- #if MINIMUM_STEPPER_PULSE && DISABLED(I2S_STEPPER_STREAM)
|
1486
|
|
- // Just wait for the requested pulse duration
|
1487
|
|
- while (HAL_timer_get_count(PULSE_TIMER_NUM) < pulse_end) { /* nada */ }
|
|
1521
|
+ #if (MINIMUM_STEPPER_PULSE || MAXIMUM_STEPPER_RATE) && DISABLED(I2S_STEPPER_STREAM)
|
|
1522
|
+ START_HIGH_PULSE();
|
|
1523
|
+ AWAIT_HIGH_PULSE();
|
1488
|
1524
|
#endif
|
1489
|
1525
|
|
1490
|
|
- // Add the delay needed to ensure the maximum driver rate is enforced
|
1491
|
|
- if (signed(added_step_ticks) > 0) pulse_end += hal_timer_t(added_step_ticks);
|
1492
|
|
-
|
1493
|
1526
|
// Pulse stop
|
1494
|
1527
|
#if HAS_X_STEP
|
1495
|
1528
|
PULSE_STOP(X);
|
|
@@ -1503,31 +1536,26 @@ void Stepper::stepper_pulse_phase_isr() {
|
1503
|
1536
|
|
1504
|
1537
|
#if DISABLED(LIN_ADVANCE)
|
1505
|
1538
|
#if ENABLED(MIXING_EXTRUDER)
|
|
1539
|
+
|
1506
|
1540
|
if (delta_error.e >= 0) {
|
1507
|
1541
|
delta_error.e -= advance_divisor;
|
1508
|
1542
|
E_STEP_WRITE(mixer.get_stepper(), INVERT_E_STEP_PIN);
|
1509
|
1543
|
}
|
|
1544
|
+
|
1510
|
1545
|
#else // !MIXING_EXTRUDER
|
|
1546
|
+
|
1511
|
1547
|
#if HAS_E0_STEP
|
1512
|
1548
|
PULSE_STOP(E);
|
1513
|
1549
|
#endif
|
1514
|
|
- #endif
|
1515
|
|
- #endif // !LIN_ADVANCE
|
1516
|
1550
|
|
1517
|
|
- // Decrement the count of pending pulses to do
|
1518
|
|
- --events_to_do;
|
|
1551
|
+ #endif // !MIXING_EXTRUDER
|
|
1552
|
+ #endif // !LIN_ADVANCE
|
1519
|
1553
|
|
1520
|
|
- // For minimum pulse time wait after stopping pulses also
|
1521
|
|
- if (events_to_do) {
|
1522
|
|
- // Just wait for the requested pulse duration
|
1523
|
|
- while (HAL_timer_get_count(PULSE_TIMER_NUM) < pulse_end) { /* nada */ }
|
1524
|
|
- #if MINIMUM_STEPPER_PULSE
|
1525
|
|
- // Add to the value, the time that the pulse must be active (to be used on the next loop)
|
1526
|
|
- pulse_end += hal_timer_t(MIN_PULSE_TICKS);
|
1527
|
|
- #endif
|
1528
|
|
- }
|
|
1554
|
+ #if (MINIMUM_STEPPER_PULSE || MAXIMUM_STEPPER_RATE) && DISABLED(I2S_STEPPER_STREAM)
|
|
1555
|
+ if (events_to_do) START_LOW_PULSE();
|
|
1556
|
+ #endif
|
1529
|
1557
|
|
1530
|
|
- } while (events_to_do);
|
|
1558
|
+ } while (--events_to_do);
|
1531
|
1559
|
}
|
1532
|
1560
|
|
1533
|
1561
|
// This is the last half of the stepper interrupt: This one processes and
|
|
@@ -1909,13 +1937,19 @@ uint32_t Stepper::stepper_block_phase_isr() {
|
1909
|
1937
|
DELAY_NS(MINIMUM_STEPPER_POST_DIR_DELAY);
|
1910
|
1938
|
#endif
|
1911
|
1939
|
|
1912
|
|
- // Get the timer count and estimate the end of the pulse
|
1913
|
|
- hal_timer_t pulse_end = HAL_timer_get_count(PULSE_TIMER_NUM) + hal_timer_t(MIN_PULSE_TICKS);
|
1914
|
|
-
|
1915
|
|
- const hal_timer_t added_step_ticks = hal_timer_t(ADDED_STEP_TICKS);
|
|
1940
|
+ //const hal_timer_t added_step_ticks = hal_timer_t(ADDED_STEP_TICKS);
|
1916
|
1941
|
|
1917
|
1942
|
// Step E stepper if we have steps
|
|
1943
|
+ bool firstStep = true;
|
|
1944
|
+ hal_timer_t end_tick_count;
|
|
1945
|
+
|
1918
|
1946
|
while (LA_steps) {
|
|
1947
|
+ #if (MINIMUM_STEPPER_PULSE || MAXIMUM_STEPPER_RATE) && DISABLED(I2S_STEPPER_STREAM)
|
|
1948
|
+ if (firstStep)
|
|
1949
|
+ firstStep = false;
|
|
1950
|
+ else
|
|
1951
|
+ AWAIT_LOW_PULSE();
|
|
1952
|
+ #endif
|
1919
|
1953
|
|
1920
|
1954
|
// Set the STEP pulse ON
|
1921
|
1955
|
#if ENABLED(MIXING_EXTRUDER)
|
|
@@ -1925,16 +1959,16 @@ uint32_t Stepper::stepper_block_phase_isr() {
|
1925
|
1959
|
#endif
|
1926
|
1960
|
|
1927
|
1961
|
// Enforce a minimum duration for STEP pulse ON
|
1928
|
|
- #if MINIMUM_STEPPER_PULSE
|
1929
|
|
- // Just wait for the requested pulse duration
|
1930
|
|
- while (HAL_timer_get_count(PULSE_TIMER_NUM) < pulse_end) { /* nada */ }
|
|
1962
|
+ #if (MINIMUM_STEPPER_PULSE || MAXIMUM_STEPPER_RATE)
|
|
1963
|
+ START_HIGH_PULSE();
|
1931
|
1964
|
#endif
|
1932
|
1965
|
|
1933
|
|
- // Add the delay needed to ensure the maximum driver rate is enforced
|
1934
|
|
- if (signed(added_step_ticks) > 0) pulse_end += hal_timer_t(added_step_ticks);
|
1935
|
|
-
|
1936
|
1966
|
LA_steps < 0 ? ++LA_steps : --LA_steps;
|
1937
|
1967
|
|
|
1968
|
+ #if (MINIMUM_STEPPER_PULSE || MAXIMUM_STEPPER_RATE)
|
|
1969
|
+ AWAIT_HIGH_PULSE();
|
|
1970
|
+ #endif
|
|
1971
|
+
|
1938
|
1972
|
// Set the STEP pulse OFF
|
1939
|
1973
|
#if ENABLED(MIXING_EXTRUDER)
|
1940
|
1974
|
E_STEP_WRITE(mixer.get_stepper(), INVERT_E_STEP_PIN);
|
|
@@ -1944,13 +1978,9 @@ uint32_t Stepper::stepper_block_phase_isr() {
|
1944
|
1978
|
|
1945
|
1979
|
// For minimum pulse time wait before looping
|
1946
|
1980
|
// Just wait for the requested pulse duration
|
1947
|
|
- if (LA_steps) {
|
1948
|
|
- while (HAL_timer_get_count(PULSE_TIMER_NUM) < pulse_end) { /* nada */ }
|
1949
|
|
- #if MINIMUM_STEPPER_PULSE
|
1950
|
|
- // Add to the value, the time that the pulse must be active (to be used on the next loop)
|
1951
|
|
- pulse_end += hal_timer_t(MIN_PULSE_TICKS);
|
1952
|
|
- #endif
|
1953
|
|
- }
|
|
1981
|
+ #if (MINIMUM_STEPPER_PULSE || MAXIMUM_STEPPER_RATE)
|
|
1982
|
+ if (LA_steps) START_LOW_PULSE();
|
|
1983
|
+ #endif
|
1954
|
1984
|
} // LA_steps
|
1955
|
1985
|
|
1956
|
1986
|
return interval;
|