Переглянути джерело

EXPERIMENTAL integrated BABYSTEPPING (#16829)

Scott Lahteine 4 роки тому
джерело
коміт
64a81f887a
Аккаунт користувача з таким Email не знайдено

+ 1
- 0
Marlin/Configuration_adv.h Переглянути файл

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

+ 4
- 0
Marlin/src/feature/babystep.cpp Переглянути файл

117
   #if ENABLED(BABYSTEP_ALWAYS_AVAILABLE)
117
   #if ENABLED(BABYSTEP_ALWAYS_AVAILABLE)
118
     gcode.reset_stepper_timeout();
118
     gcode.reset_stepper_timeout();
119
   #endif
119
   #endif
120
+
121
+  #if ENABLED(INTEGRATED_BABYSTEPPING)
122
+    if (has_steps()) stepper.initiateBabystepping();
123
+  #endif
120
 }
124
 }
121
 
125
 
122
 #endif // BABYSTEPPING
126
 #endif // BABYSTEPPING

+ 13
- 1
Marlin/src/feature/babystep.h Переглянути файл

23
 
23
 
24
 #include "../inc/MarlinConfigPre.h"
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
 #if IS_CORE || EITHER(BABYSTEP_XY, I2C_POSITION_ENCODERS)
34
 #if IS_CORE || EITHER(BABYSTEP_XY, I2C_POSITION_ENCODERS)
27
   #define BS_TODO_AXIS(A) A
35
   #define BS_TODO_AXIS(A) A
28
 #else
36
 #else
56
   static void add_steps(const AxisEnum axis, const int16_t distance);
64
   static void add_steps(const AxisEnum axis, const int16_t distance);
57
   static void add_mm(const AxisEnum axis, const float &mm);
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
   // apply accumulated babysteps to the axes.
73
   // apply accumulated babysteps to the axes.
62
   //
74
   //
63
   static inline void task() {
75
   static inline void task() {

+ 42
- 3
Marlin/src/module/stepper.cpp Переглянути файл

217
 
217
 
218
 #endif // LIN_ADVANCE
218
 #endif // LIN_ADVANCE
219
 
219
 
220
+#if ENABLED(INTEGRATED_BABYSTEPPING)
221
+  uint32_t Stepper::nextBabystepISR = BABYSTEP_NEVER;
222
+#endif
223
+
220
 int32_t Stepper::ticks_nominal = -1;
224
 int32_t Stepper::ticks_nominal = -1;
221
 #if DISABLED(S_CURVE_ACCELERATION)
225
 #if DISABLED(S_CURVE_ACCELERATION)
222
   uint32_t Stepper::acc_step_rate; // needed for deceleration start point
226
   uint32_t Stepper::acc_step_rate; // needed for deceleration start point
1358
       if (!nextAdvanceISR) nextAdvanceISR = advance_isr();          // 0 = Do Linear Advance E Stepper pulses
1362
       if (!nextAdvanceISR) nextAdvanceISR = advance_isr();          // 0 = Do Linear Advance E Stepper pulses
1359
     #endif
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
     // ^== Time critical. NOTHING besides pulse generation should be above here!!!
1370
     // ^== Time critical. NOTHING besides pulse generation should be above here!!!
1362
 
1371
 
1363
     if (!nextMainISR) nextMainISR = block_phase_isr();  // Manage acc/deceleration, get next block
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
     // Get the interval to the next ISR call
1382
     // Get the interval to the next ISR call
1366
     const uint32_t interval = _MIN(
1383
     const uint32_t interval = _MIN(
1367
-      nextMainISR                                       // Time until the next Stepper ISR
1384
+      nextMainISR                                       // Time until the next Pulse / Block phase
1368
       #if ENABLED(LIN_ADVANCE)
1385
       #if ENABLED(LIN_ADVANCE)
1369
         , nextAdvanceISR                                // Come back early for Linear Advance?
1386
         , nextAdvanceISR                                // Come back early for Linear Advance?
1370
       #endif
1387
       #endif
1388
+      #if ENABLED(INTEGRATED_BABYSTEPPING)
1389
+        , nextBabystepISR                               // Come back early for Babystepping?
1390
+      #endif
1371
       , uint32_t(HAL_TIMER_TYPE_MAX)                    // Come back in a very long time
1391
       , uint32_t(HAL_TIMER_TYPE_MAX)                    // Come back in a very long time
1372
     );
1392
     );
1373
 
1393
 
1384
       if (nextAdvanceISR != LA_ADV_NEVER) nextAdvanceISR -= interval;
1404
       if (nextAdvanceISR != LA_ADV_NEVER) nextAdvanceISR -= interval;
1385
     #endif
1405
     #endif
1386
 
1406
 
1407
+    #if ENABLED(INTEGRATED_BABYSTEPPING)
1408
+      if (nextBabystepISR != BABYSTEP_NEVER) nextBabystepISR -= interval;
1409
+    #endif
1410
+
1387
     /**
1411
     /**
1388
      * This needs to avoid a race-condition caused by interleaving
1412
      * This needs to avoid a race-condition caused by interleaving
1389
      * of interrupts required by both the LA and Stepper algorithms.
1413
      * of interrupts required by both the LA and Stepper algorithms.
2043
 
2067
 
2044
 #endif // LIN_ADVANCE
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
 // Check if the given block is busy or not - Must not be called from ISR contexts
2080
 // Check if the given block is busy or not - Must not be called from ISR contexts
2047
 // The current_block could change in the middle of the read by an Stepper ISR, so
2081
 // The current_block could change in the middle of the read by an Stepper ISR, so
2048
 // we must explicitly prevent that!
2082
 // we must explicitly prevent that!
2511
   // MUST ONLY BE CALLED BY AN ISR,
2545
   // MUST ONLY BE CALLED BY AN ISR,
2512
   // No other ISR should ever interrupt this!
2546
   // No other ISR should ever interrupt this!
2513
   void Stepper::babystep(const AxisEnum axis, const bool direction) {
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
     switch (axis) {
2553
     switch (axis) {
2517
 
2554
 
2594
       default: break;
2631
       default: break;
2595
     }
2632
     }
2596
 
2633
 
2597
-    sei();
2634
+    #if DISABLED(INTEGRATED_BABYSTEPPING)
2635
+      sei();
2636
+    #endif
2598
   }
2637
   }
2599
 
2638
 
2600
 #endif // BABYSTEPPING
2639
 #endif // BABYSTEPPING

+ 16
- 0
Marlin/src/module/stepper.h Переглянути файл

329
       static bool LA_use_advance_lead;
329
       static bool LA_use_advance_lead;
330
     #endif
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
     static int32_t ticks_nominal;
337
     static int32_t ticks_nominal;
333
     #if DISABLED(S_CURVE_ACCELERATION)
338
     #if DISABLED(S_CURVE_ACCELERATION)
334
       static uint32_t acc_step_rate; // needed for deceleration start point
339
       static uint32_t acc_step_rate; // needed for deceleration start point
383
       FORCE_INLINE static void initiateLA() { nextAdvanceISR = 0; }
388
       FORCE_INLINE static void initiateLA() { nextAdvanceISR = 0; }
384
     #endif
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
     // Check if the given block is busy or not - Must not be called from ISR contexts
402
     // Check if the given block is busy or not - Must not be called from ISR contexts
387
     static bool is_block_busy(const block_t* const block);
403
     static bool is_block_busy(const block_t* const block);
388
 
404
 

+ 2
- 2
Marlin/src/module/temperature.cpp Переглянути файл

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

Завантаження…
Відмінити
Зберегти