Browse Source

Fix Babystepping loop (again)

Scott Lahteine 4 years ago
parent
commit
5e197df89a

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

@@ -35,17 +35,17 @@
35 35
 
36 36
 Babystep babystep;
37 37
 
38
-volatile int16_t Babystep::steps[BS_TODO_AXIS(Z_AXIS) + 1];
38
+volatile int16_t Babystep::steps[BS_AXIS_IND(Z_AXIS) + 1];
39 39
 #if ENABLED(BABYSTEP_DISPLAY_TOTAL)
40 40
   int16_t Babystep::axis_total[BS_TOTAL_AXIS(Z_AXIS) + 1];
41 41
 #endif
42 42
 int16_t Babystep::accum;
43 43
 
44 44
 void Babystep::step_axis(const AxisEnum axis) {
45
-  const int16_t curTodo = steps[BS_TODO_AXIS(axis)]; // get rid of volatile for performance
45
+  const int16_t curTodo = steps[BS_AXIS_IND(axis)]; // get rid of volatile for performance
46 46
   if (curTodo) {
47 47
     stepper.do_babystep((AxisEnum)axis, curTodo > 0);
48
-    if (curTodo > 0) steps[BS_TODO_AXIS(axis)]--; else steps[BS_TODO_AXIS(axis)]++;
48
+    if (curTodo > 0) steps[BS_AXIS_IND(axis)]--; else steps[BS_AXIS_IND(axis)]++;
49 49
   }
50 50
 }
51 51
 
@@ -112,7 +112,7 @@ void Babystep::add_steps(const AxisEnum axis, const int16_t distance) {
112 112
     #else
113 113
       BSA_ENABLE(Z_AXIS);
114 114
     #endif
115
-    steps[BS_TODO_AXIS(axis)] += distance;
115
+    steps[BS_AXIS_IND(axis)] += distance;
116 116
   #endif
117 117
   #if ENABLED(BABYSTEP_ALWAYS_AVAILABLE)
118 118
     gcode.reset_stepper_timeout();

+ 7
- 5
Marlin/src/feature/babystep.h View File

@@ -32,9 +32,11 @@
32 32
 #endif
33 33
 
34 34
 #if IS_CORE || EITHER(BABYSTEP_XY, I2C_POSITION_ENCODERS)
35
-  #define BS_TODO_AXIS(A) A
35
+  #define BS_AXIS_IND(A) A
36
+  #define BS_AXIS(I) AxisEnum(I)
36 37
 #else
37
-  #define BS_TODO_AXIS(A) 0
38
+  #define BS_AXIS_IND(A) 0
39
+  #define BS_AXIS(I) Z_AXIS
38 40
 #endif
39 41
 
40 42
 #if ENABLED(BABYSTEP_DISPLAY_TOTAL)
@@ -47,7 +49,7 @@
47 49
 
48 50
 class Babystep {
49 51
 public:
50
-  static volatile int16_t steps[BS_TODO_AXIS(Z_AXIS) + 1];
52
+  static volatile int16_t steps[BS_AXIS_IND(Z_AXIS) + 1];
51 53
   static int16_t accum;                                     // Total babysteps in current edit
52 54
 
53 55
   #if ENABLED(BABYSTEP_DISPLAY_TOTAL)
@@ -65,7 +67,7 @@ public:
65 67
   static void add_mm(const AxisEnum axis, const float &mm);
66 68
 
67 69
   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)];
70
+    return steps[BS_AXIS_IND(X_AXIS)] || steps[BS_AXIS_IND(Y_AXIS)] || steps[BS_AXIS_IND(Z_AXIS)];
69 71
   }
70 72
 
71 73
   //
@@ -73,7 +75,7 @@ public:
73 75
   // apply accumulated babysteps to the axes.
74 76
   //
75 77
   static inline void task() {
76
-    LOOP_LE_N(axis, BS_TODO_AXIS(Z_AXIS)) step_axis((AxisEnum)axis);
78
+    LOOP_LE_N(i, BS_AXIS_IND(Z_AXIS)) step_axis(BS_AXIS(i));
77 79
   }
78 80
 
79 81
 private:

+ 1
- 1
Marlin/src/feature/tmc_util.cpp View File

@@ -1097,7 +1097,7 @@
1097 1097
 
1098 1098
   bool tmc_enable_stallguard(TMC2209Stepper &st) {
1099 1099
     const bool stealthchop_was_enabled = !st.en_spreadCycle();
1100
-    
1100
+
1101 1101
     st.TCOOLTHRS(0xFFFFF);
1102 1102
     st.en_spreadCycle(false);
1103 1103
     return stealthchop_was_enabled;

+ 1
- 1
Marlin/src/gcode/motion/M290.cpp View File

@@ -131,7 +131,7 @@ void GcodeSuite::M290() {
131 131
         #else
132 132
           PSTR("Babystep Z")
133 133
         #endif
134
-        , babystep.axis_total[BS_TODO_AXIS(Z_AXIS)]
134
+        , babystep.axis_total[BS_AXIS_IND(Z_AXIS)]
135 135
       );
136 136
     }
137 137
     #endif

+ 8
- 8
Marlin/src/lcd/extensible_ui/ui_api.cpp View File

@@ -785,7 +785,7 @@ namespace ExtUI {
785 785
     #if HAS_BED_PROBE
786 786
       return probe.offset.z;
787 787
     #elif ENABLED(BABYSTEP_DISPLAY_TOTAL)
788
-      return (planner.steps_to_mm[Z_AXIS] * babystep.axis_total[BS_TODO_AXIS(Z_AXIS)]);
788
+      return (planner.steps_to_mm[Z_AXIS] * babystep.axis_total[BS_AXIS_IND(Z_AXIS)]);
789 789
     #else
790 790
       return 0.0;
791 791
     #endif
@@ -898,11 +898,11 @@ namespace ExtUI {
898 898
     float getPIDValues_Kp(const extruder_t tool) {
899 899
       return PID_PARAM(Kp, tool);
900 900
     }
901
-    
901
+
902 902
     float getPIDValues_Ki(const extruder_t tool) {
903 903
       return unscalePID_i(PID_PARAM(Ki, tool));
904 904
     }
905
-    
905
+
906 906
     float getPIDValues_Kd(const extruder_t tool) {
907 907
       return unscalePID_d(PID_PARAM(Kd, tool));
908 908
     }
@@ -918,27 +918,27 @@ namespace ExtUI {
918 918
       thermalManager.PID_autotune(temp, (heater_ind_t)tool, 8, true);
919 919
     }
920 920
   #endif
921
-  
921
+
922 922
   #if ENABLED(PIDTEMPBED)
923 923
     float getBedPIDValues_Kp() {
924 924
       return thermalManager.temp_bed.pid.Kp;
925 925
     }
926
-    
926
+
927 927
     float getBedPIDValues_Ki() {
928 928
       return unscalePID_i(thermalManager.temp_bed.pid.Ki);
929 929
     }
930
-    
930
+
931 931
     float getBedPIDValues_Kd() {
932 932
       return unscalePID_d(thermalManager.temp_bed.pid.Kd);
933 933
     }
934
-    
934
+
935 935
     void setBedPIDValues(const float p, const float i, const float d) {
936 936
       thermalManager.temp_bed.pid.Kp = p;
937 937
       thermalManager.temp_bed.pid.Ki = scalePID_i(i);
938 938
       thermalManager.temp_bed.pid.Kd = scalePID_d(d);
939 939
       thermalManager.updatePID();
940 940
     }
941
-    
941
+
942 942
     void startBedPIDTune(const float temp) {
943 943
       thermalManager.PID_autotune(temp, H_BED, 4, true);
944 944
     }

+ 1
- 1
Marlin/src/lcd/extensible_ui/ui_api.h View File

@@ -256,7 +256,7 @@ namespace ExtUI {
256 256
     void setPIDValues(const float, const float, const float, extruder_t);
257 257
     void startPIDTune(const float, extruder_t);
258 258
   #endif
259
-  
259
+
260 260
   #if ENABLED(PIDTEMPBED)
261 261
     float getBedPIDValues_Kp();
262 262
     float getBedPIDValues_Ki();

+ 19
- 9
Marlin/src/module/stepper.cpp View File

@@ -81,6 +81,8 @@
81 81
 
82 82
 Stepper stepper; // Singleton
83 83
 
84
+#define BABYSTEPPING_EXTRA_DIR_WAIT
85
+
84 86
 #if HAS_MOTOR_CURRENT_PWM
85 87
   bool Stepper::initialized; // = false
86 88
 #endif
@@ -1367,8 +1369,8 @@ void Stepper::isr() {
1367 1369
     #endif
1368 1370
 
1369 1371
     #if ENABLED(INTEGRATED_BABYSTEPPING)
1370
-      const bool do_babystep = (nextBabystepISR == 0);              // 0 = Do Babystepping (XY)Z pulses
1371
-      if (do_babystep) nextBabystepISR = babystepping_isr();
1372
+      const bool is_babystep = (nextBabystepISR == 0);              // 0 = Do Babystepping (XY)Z pulses
1373
+      if (is_babystep) nextBabystepISR = babystepping_isr();
1372 1374
     #endif
1373 1375
 
1374 1376
     // ^== Time critical. NOTHING besides pulse generation should be above here!!!
@@ -1376,7 +1378,7 @@ void Stepper::isr() {
1376 1378
     if (!nextMainISR) nextMainISR = block_phase_isr();  // Manage acc/deceleration, get next block
1377 1379
 
1378 1380
     #if ENABLED(INTEGRATED_BABYSTEPPING)
1379
-      if (do_babystep)                                  // Avoid ANY stepping too soon after baby-stepping
1381
+      if (is_babystep)                                  // Avoid ANY stepping too soon after baby-stepping
1380 1382
         NOLESS(nextMainISR, (BABYSTEP_TICKS) / 8);      // FULL STOP for 125µs after a baby-step
1381 1383
 
1382 1384
       if (nextBabystepISR != BABYSTEP_NEVER)            // Avoid baby-stepping too close to axis Stepping
@@ -2507,6 +2509,14 @@ void Stepper::report_positions() {
2507 2509
     #endif
2508 2510
   #endif
2509 2511
 
2512
+  #if ENABLED(BABYSTEPPING_EXTRA_DIR_WAIT)
2513
+    #define EXTRA_DIR_WAIT_BEFORE DIR_WAIT_BEFORE
2514
+    #define EXTRA_DIR_WAIT_AFTER  DIR_WAIT_AFTER
2515
+  #else
2516
+    #define EXTRA_DIR_WAIT_BEFORE()
2517
+    #define EXTRA_DIR_WAIT_AFTER()
2518
+  #endif
2519
+
2510 2520
   #if DISABLED(DELTA)
2511 2521
 
2512 2522
     #define BABYSTEP_AXIS(AXIS, INV, DIR) do{           \
@@ -2519,9 +2529,9 @@ void Stepper::report_positions() {
2519 2529
       _APPLY_STEP(AXIS, !_INVERT_STEP_PIN(AXIS), true); \
2520 2530
       _PULSE_WAIT();                                    \
2521 2531
       _APPLY_STEP(AXIS, _INVERT_STEP_PIN(AXIS), true);  \
2522
-      DIR_WAIT_BEFORE();                                \
2532
+      EXTRA_DIR_WAIT_BEFORE();                          \
2523 2533
       _APPLY_DIR(AXIS, old_dir);                        \
2524
-      DIR_WAIT_AFTER();                                 \
2534
+      EXTRA_DIR_WAIT_AFTER();                           \
2525 2535
     }while(0)
2526 2536
 
2527 2537
   #elif IS_CORE
@@ -2539,9 +2549,9 @@ void Stepper::report_positions() {
2539 2549
       _PULSE_WAIT();                                            \
2540 2550
       _APPLY_STEP(A, _INVERT_STEP_PIN(A), true);                \
2541 2551
       _APPLY_STEP(B, _INVERT_STEP_PIN(B), true);                \
2542
-      DIR_WAIT_BEFORE();                                        \
2552
+      EXTRA_DIR_WAIT_BEFORE();                                  \
2543 2553
       _APPLY_DIR(A, old_dir.a); _APPLY_DIR(B, old_dir.b);       \
2544
-      DIR_WAIT_AFTER();                                         \
2554
+      EXTRA_DIR_WAIT_AFTER();                                   \
2545 2555
     }while(0)
2546 2556
 
2547 2557
   #endif
@@ -2620,13 +2630,13 @@ void Stepper::report_positions() {
2620 2630
           Z_STEP_WRITE(INVERT_Z_STEP_PIN);
2621 2631
 
2622 2632
           // Restore direction bits
2623
-          DIR_WAIT_BEFORE();
2633
+          EXTRA_DIR_WAIT_BEFORE();
2624 2634
 
2625 2635
           X_DIR_WRITE(old_dir.x);
2626 2636
           Y_DIR_WRITE(old_dir.y);
2627 2637
           Z_DIR_WRITE(old_dir.z);
2628 2638
 
2629
-          DIR_WAIT_AFTER();
2639
+          EXTRA_DIR_WAIT_AFTER();
2630 2640
 
2631 2641
         #endif
2632 2642
 

+ 7
- 7
Marlin/src/pins/mega/pins_PICA.h View File

@@ -36,8 +36,8 @@
36 36
 /*
37 37
 // Note that these are the "pins" that correspond to the analog inputs on the arduino mega.
38 38
 // These are not the same as the physical pin numbers
39
-  AD0 = 54;   AD1 = 55;   AD2 = 56;   AD3 = 57;   
40
-  AD4 = 58;   AD5 = 59;   AD6 = 60;   AD7 = 61;   
39
+  AD0 = 54;   AD1 = 55;   AD2 = 56;   AD3 = 57;
40
+  AD4 = 58;   AD5 = 59;   AD6 = 60;   AD7 = 61;
41 41
   AD8 = 62;   AD9 = 63;   AD10 = 64;  AD11 = 65;
42 42
   AD12 = 66;  AD13 = 67;  AD14 = 68;  AD15 = 69;
43 43
 */
@@ -61,7 +61,7 @@
61 61
 //
62 62
 #define X_STEP_PIN         55
63 63
 #define X_DIR_PIN          54
64
-#define X_ENABLE_PIN       60     
64
+#define X_ENABLE_PIN       60
65 65
 
66 66
 #define Y_STEP_PIN         57
67 67
 #define Y_DIR_PIN          56
@@ -71,7 +71,7 @@
71 71
 #define Z_DIR_PIN          58
72 72
 #define Z_ENABLE_PIN       62
73 73
 
74
-#define E0_STEP_PIN        67 
74
+#define E0_STEP_PIN        67
75 75
 #define E0_DIR_PIN         24
76 76
 #define E0_ENABLE_PIN      26
77 77
 
@@ -103,10 +103,10 @@
103 103
 #endif
104 104
 
105 105
 #define SDPOWER_PIN        -1
106
-#define LED_PIN            -1 
106
+#define LED_PIN            -1
107 107
 #define PS_ON_PIN          -1
108 108
 #define KILL_PIN           -1
109
-      
109
+
110 110
 #define SSR_PIN             6
111 111
 
112 112
 // SPI for Max6675 or Max31855 Thermocouple
@@ -119,7 +119,7 @@
119 119
 //
120 120
 // SD Support
121 121
 //
122
-#define SD_DETECT_PIN      49 
122
+#define SD_DETECT_PIN      49
123 123
 #define SDSS               53
124 124
 
125 125
 //

Loading…
Cancel
Save