Browse Source

EXPERIMENTAL integrated BABYSTEPPING (#16829)

Scott Lahteine 4 years ago
parent
commit
64a81f887a
No account linked to committer's email address

+ 1
- 0
Marlin/Configuration_adv.h View File

@@ -1447,6 +1447,7 @@
1447 1447
  */
1448 1448
 //#define BABYSTEPPING
1449 1449
 #if ENABLED(BABYSTEPPING)
1450
+  //#define INTEGRATED_BABYSTEPPING         // EXPERIMENTAL integration of babystepping into the Stepper ISR
1450 1451
   //#define BABYSTEP_WITHOUT_HOMING
1451 1452
   //#define BABYSTEP_XY                     // Also enable X/Y Babystepping. Not supported on DELTA!
1452 1453
   #define BABYSTEP_INVERT_Z false           // Change if Z babysteps should go the other way

+ 4
- 0
Marlin/src/feature/babystep.cpp View File

@@ -117,6 +117,10 @@ void Babystep::add_steps(const AxisEnum axis, const int16_t distance) {
117 117
   #if ENABLED(BABYSTEP_ALWAYS_AVAILABLE)
118 118
     gcode.reset_stepper_timeout();
119 119
   #endif
120
+
121
+  #if ENABLED(INTEGRATED_BABYSTEPPING)
122
+    if (has_steps()) stepper.initiateBabystepping();
123
+  #endif
120 124
 }
121 125
 
122 126
 #endif // BABYSTEPPING

+ 13
- 1
Marlin/src/feature/babystep.h View File

@@ -23,6 +23,14 @@
23 23
 
24 24
 #include "../inc/MarlinConfigPre.h"
25 25
 
26
+#if ENABLED(INTEGRATED_BABYSTEPPING)
27
+  #define BABYSTEPS_PER_SEC 1000UL
28
+  #define BABYSTEP_TICKS ((STEPPER_TIMER_RATE) / (BABYSTEPS_PER_SEC))
29
+#else
30
+  #define BABYSTEPS_PER_SEC 976UL
31
+  #define BABYSTEP_TICKS ((TEMP_TIMER_RATE) / (BABYSTEPS_PER_SEC))
32
+#endif
33
+
26 34
 #if IS_CORE || EITHER(BABYSTEP_XY, I2C_POSITION_ENCODERS)
27 35
   #define BS_TODO_AXIS(A) A
28 36
 #else
@@ -56,8 +64,12 @@ public:
56 64
   static void add_steps(const AxisEnum axis, const int16_t distance);
57 65
   static void add_mm(const AxisEnum axis, const float &mm);
58 66
 
67
+  static inline bool has_steps() {
68
+    return steps[BS_TODO_AXIS(X_AXIS)] || steps[BS_TODO_AXIS(Y_AXIS)] || steps[BS_TODO_AXIS(Z_AXIS)];
69
+  }
70
+
59 71
   //
60
-  // Called by the Temperature ISR to
72
+  // Called by the Temperature or Stepper ISR to
61 73
   // apply accumulated babysteps to the axes.
62 74
   //
63 75
   static inline void task() {

+ 42
- 3
Marlin/src/module/stepper.cpp View File

@@ -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

+ 16
- 0
Marlin/src/module/stepper.h View File

@@ -329,6 +329,11 @@ class Stepper {
329 329
       static bool LA_use_advance_lead;
330 330
     #endif
331 331
 
332
+    #if ENABLED(INTEGRATED_BABYSTEPPING)
333
+      static constexpr uint32_t BABYSTEP_NEVER = 0xFFFFFFFF;
334
+      static uint32_t nextBabystepISR;
335
+    #endif
336
+
332 337
     static int32_t ticks_nominal;
333 338
     #if DISABLED(S_CURVE_ACCELERATION)
334 339
       static uint32_t acc_step_rate; // needed for deceleration start point
@@ -383,6 +388,17 @@ class Stepper {
383 388
       FORCE_INLINE static void initiateLA() { nextAdvanceISR = 0; }
384 389
     #endif
385 390
 
391
+    #if ENABLED(INTEGRATED_BABYSTEPPING)
392
+      // The Babystepping ISR phase
393
+      static uint32_t babystepping_isr();
394
+      FORCE_INLINE static void initiateBabystepping() {
395
+        if (nextBabystepISR == BABYSTEP_NEVER) {
396
+          nextBabystepISR = 0;
397
+          wake_up();
398
+        }
399
+      }
400
+    #endif
401
+
386 402
     // Check if the given block is busy or not - Must not be called from ISR contexts
387 403
     static bool is_block_busy(const block_t* const block);
388 404
 

+ 2
- 2
Marlin/src/module/temperature.cpp View File

@@ -69,7 +69,7 @@
69 69
   #include "stepper.h"
70 70
 #endif
71 71
 
72
-#if ENABLED(BABYSTEPPING)
72
+#if ENABLED(BABYSTEPPING) && DISABLED(INTEGRATED_BABYSTEPPING)
73 73
   #include "../feature/babystep.h"
74 74
 #endif
75 75
 
@@ -3010,7 +3010,7 @@ void Temperature::tick() {
3010 3010
   // Additional ~1KHz Tasks
3011 3011
   //
3012 3012
 
3013
-  #if ENABLED(BABYSTEPPING)
3013
+  #if ENABLED(BABYSTEPPING) && DISABLED(INTEGRATED_BABYSTEPPING)
3014 3014
     babystep.task();
3015 3015
   #endif
3016 3016
 

Loading…
Cancel
Save