@@ -217,6 +217,10 @@ uint32_t Stepper::advance_divisor = 0,
217
217
218
218
#endif // LIN_ADVANCE
219
219
220
+ #if ENABLED(INTEGRATED_BABYSTEPPING)
221
+ uint32_t Stepper::nextBabystepISR = BABYSTEP_NEVER;
222
+ #endif
223
+
220
224
int32_t Stepper::ticks_nominal = -1 ;
221
225
#if DISABLED(S_CURVE_ACCELERATION)
222
226
uint32_t Stepper::acc_step_rate; // needed for deceleration start point
@@ -1358,16 +1362,32 @@ void Stepper::isr() {
1358
1362
if (!nextAdvanceISR) nextAdvanceISR = advance_isr (); // 0 = Do Linear Advance E Stepper pulses
1359
1363
#endif
1360
1364
1365
+ #if ENABLED(INTEGRATED_BABYSTEPPING)
1366
+ const bool do_babystep = (nextBabystepISR == 0 ); // 0 = Do Babystepping (XY)Z pulses
1367
+ if (do_babystep) nextBabystepISR = babystepping_isr ();
1368
+ #endif
1369
+
1361
1370
// ^== Time critical. NOTHING besides pulse generation should be above here!!!
1362
1371
1363
1372
if (!nextMainISR) nextMainISR = block_phase_isr (); // Manage acc/deceleration, get next block
1364
1373
1374
+ #if ENABLED(INTEGRATED_BABYSTEPPING)
1375
+ if (do_babystep) // Avoid ANY stepping too soon after baby-stepping
1376
+ NOLESS (nextMainISR, (BABYSTEP_TICKS) / 8 ) // FULL STOP for 125µs after a baby-step
1377
+
1378
+ if (nextBabystepISR != BABYSTEP_NEVER) // Avoid baby-stepping too close to axis Stepping
1379
+ NOLESS (nextBabystepISR, nextMainISR / 2 ) // TODO: Only look at axes enabled for baby-stepping
1380
+ #endif
1381
+
1365
1382
// Get the interval to the next ISR call
1366
1383
const uint32_t interval = _MIN (
1367
- nextMainISR // Time until the next Stepper ISR
1384
+ nextMainISR // Time until the next Pulse / Block phase
1368
1385
#if ENABLED(LIN_ADVANCE)
1369
1386
, nextAdvanceISR // Come back early for Linear Advance?
1370
1387
#endif
1388
+ #if ENABLED(INTEGRATED_BABYSTEPPING)
1389
+ , nextBabystepISR // Come back early for Babystepping?
1390
+ #endif
1371
1391
, uint32_t (HAL_TIMER_TYPE_MAX) // Come back in a very long time
1372
1392
);
1373
1393
@@ -1384,6 +1404,10 @@ void Stepper::isr() {
1384
1404
if (nextAdvanceISR != LA_ADV_NEVER) nextAdvanceISR -= interval;
1385
1405
#endif
1386
1406
1407
+ #if ENABLED(INTEGRATED_BABYSTEPPING)
1408
+ if (nextBabystepISR != BABYSTEP_NEVER) nextBabystepISR -= interval;
1409
+ #endif
1410
+
1387
1411
/* *
1388
1412
* This needs to avoid a race-condition caused by interleaving
1389
1413
* of interrupts required by both the LA and Stepper algorithms.
@@ -2043,6 +2067,16 @@ uint32_t Stepper::block_phase_isr() {
2043
2067
2044
2068
#endif // LIN_ADVANCE
2045
2069
2070
+ #if ENABLED(INTEGRATED_BABYSTEPPING)
2071
+
2072
+ // Timer interrupt for baby-stepping
2073
+ uint32_t Stepper::babystepping_isr () {
2074
+ babystep.task ();
2075
+ return babystep.has_steps () ? BABYSTEP_TICKS : BABYSTEP_NEVER;
2076
+ }
2077
+
2078
+ #endif
2079
+
2046
2080
// Check if the given block is busy or not - Must not be called from ISR contexts
2047
2081
// The current_block could change in the middle of the read by an Stepper ISR, so
2048
2082
// we must explicitly prevent that!
@@ -2511,7 +2545,10 @@ void Stepper::report_positions() {
2511
2545
// MUST ONLY BE CALLED BY AN ISR,
2512
2546
// No other ISR should ever interrupt this!
2513
2547
void Stepper::babystep (const AxisEnum axis, const bool direction) {
2514
- cli ();
2548
+
2549
+ #if DISABLED(INTEGRATED_BABYSTEPPING)
2550
+ cli ();
2551
+ #endif
2515
2552
2516
2553
switch (axis) {
2517
2554
@@ -2594,7 +2631,9 @@ void Stepper::report_positions() {
2594
2631
default : break ;
2595
2632
}
2596
2633
2597
- sei ();
2634
+ #if DISABLED(INTEGRATED_BABYSTEPPING)
2635
+ sei ();
2636
+ #endif
2598
2637
}
2599
2638
2600
2639
#endif // BABYSTEPPING
0 commit comments