Browse Source

Merge pull request #6309 from thinkyhead/rc_fix_minimum_pulse

Fix MINIMUM_STEPPER_PULSE calculations
Scott Lahteine 8 years ago
parent
commit
944218f7da
7 changed files with 297 additions and 210 deletions
  1. 52
    52
      Marlin/Marlin.h
  2. 28
    28
      Marlin/Marlin_main.cpp
  3. 43
    2
      Marlin/macros.h
  4. 46
    46
      Marlin/planner.cpp
  5. 1
    1
      Marlin/servo.h
  6. 127
    74
      Marlin/stepper.cpp
  7. 0
    7
      Marlin/ultralcd_st7920_u8glib_rrd.h

+ 52
- 52
Marlin/Marlin.h View File

60
 #endif
60
 #endif
61
 
61
 
62
 #if HAS_X2_ENABLE
62
 #if HAS_X2_ENABLE
63
-  #define  enable_x() do{ X_ENABLE_WRITE( X_ENABLE_ON); X2_ENABLE_WRITE( X_ENABLE_ON); }while(0)
64
-  #define disable_x() do{ X_ENABLE_WRITE(!X_ENABLE_ON); X2_ENABLE_WRITE(!X_ENABLE_ON); axis_known_position[X_AXIS] = false; }while(0)
63
+  #define  enable_X() do{ X_ENABLE_WRITE( X_ENABLE_ON); X2_ENABLE_WRITE( X_ENABLE_ON); }while(0)
64
+  #define disable_X() do{ X_ENABLE_WRITE(!X_ENABLE_ON); X2_ENABLE_WRITE(!X_ENABLE_ON); axis_known_position[X_AXIS] = false; }while(0)
65
 #elif HAS_X_ENABLE
65
 #elif HAS_X_ENABLE
66
-  #define  enable_x() X_ENABLE_WRITE( X_ENABLE_ON)
67
-  #define disable_x() do{ X_ENABLE_WRITE(!X_ENABLE_ON); axis_known_position[X_AXIS] = false; }while(0)
66
+  #define  enable_X() X_ENABLE_WRITE( X_ENABLE_ON)
67
+  #define disable_X() do{ X_ENABLE_WRITE(!X_ENABLE_ON); axis_known_position[X_AXIS] = false; }while(0)
68
 #else
68
 #else
69
-  #define  enable_x() NOOP
70
-  #define disable_x() NOOP
69
+  #define  enable_X() NOOP
70
+  #define disable_X() NOOP
71
 #endif
71
 #endif
72
 
72
 
73
 #if HAS_Y2_ENABLE
73
 #if HAS_Y2_ENABLE
74
-  #define  enable_y() do{ Y_ENABLE_WRITE( Y_ENABLE_ON); Y2_ENABLE_WRITE(Y_ENABLE_ON); }while(0)
75
-  #define disable_y() do{ Y_ENABLE_WRITE(!Y_ENABLE_ON); Y2_ENABLE_WRITE(!Y_ENABLE_ON); axis_known_position[Y_AXIS] = false; }while(0)
74
+  #define  enable_Y() do{ Y_ENABLE_WRITE( Y_ENABLE_ON); Y2_ENABLE_WRITE(Y_ENABLE_ON); }while(0)
75
+  #define disable_Y() do{ Y_ENABLE_WRITE(!Y_ENABLE_ON); Y2_ENABLE_WRITE(!Y_ENABLE_ON); axis_known_position[Y_AXIS] = false; }while(0)
76
 #elif HAS_Y_ENABLE
76
 #elif HAS_Y_ENABLE
77
-  #define  enable_y() Y_ENABLE_WRITE( Y_ENABLE_ON)
78
-  #define disable_y() do{ Y_ENABLE_WRITE(!Y_ENABLE_ON); axis_known_position[Y_AXIS] = false; }while(0)
77
+  #define  enable_Y() Y_ENABLE_WRITE( Y_ENABLE_ON)
78
+  #define disable_Y() do{ Y_ENABLE_WRITE(!Y_ENABLE_ON); axis_known_position[Y_AXIS] = false; }while(0)
79
 #else
79
 #else
80
-  #define  enable_y() NOOP
81
-  #define disable_y() NOOP
80
+  #define  enable_Y() NOOP
81
+  #define disable_Y() NOOP
82
 #endif
82
 #endif
83
 
83
 
84
 #if HAS_Z2_ENABLE
84
 #if HAS_Z2_ENABLE
85
-  #define  enable_z() do{ Z_ENABLE_WRITE( Z_ENABLE_ON); Z2_ENABLE_WRITE(Z_ENABLE_ON); }while(0)
86
-  #define disable_z() do{ Z_ENABLE_WRITE(!Z_ENABLE_ON); Z2_ENABLE_WRITE(!Z_ENABLE_ON); axis_known_position[Z_AXIS] = false; }while(0)
85
+  #define  enable_Z() do{ Z_ENABLE_WRITE( Z_ENABLE_ON); Z2_ENABLE_WRITE(Z_ENABLE_ON); }while(0)
86
+  #define disable_Z() do{ Z_ENABLE_WRITE(!Z_ENABLE_ON); Z2_ENABLE_WRITE(!Z_ENABLE_ON); axis_known_position[Z_AXIS] = false; }while(0)
87
 #elif HAS_Z_ENABLE
87
 #elif HAS_Z_ENABLE
88
-  #define  enable_z() Z_ENABLE_WRITE( Z_ENABLE_ON)
89
-  #define disable_z() do{ Z_ENABLE_WRITE(!Z_ENABLE_ON); axis_known_position[Z_AXIS] = false; }while(0)
88
+  #define  enable_Z() Z_ENABLE_WRITE( Z_ENABLE_ON)
89
+  #define disable_Z() do{ Z_ENABLE_WRITE(!Z_ENABLE_ON); axis_known_position[Z_AXIS] = false; }while(0)
90
 #else
90
 #else
91
-  #define  enable_z() NOOP
92
-  #define disable_z() NOOP
91
+  #define  enable_Z() NOOP
92
+  #define disable_Z() NOOP
93
 #endif
93
 #endif
94
 
94
 
95
 #if ENABLED(MIXING_EXTRUDER)
95
 #if ENABLED(MIXING_EXTRUDER)
98
    * Mixing steppers synchronize their enable (and direction) together
98
    * Mixing steppers synchronize their enable (and direction) together
99
    */
99
    */
100
   #if MIXING_STEPPERS > 3
100
   #if MIXING_STEPPERS > 3
101
-    #define  enable_e0() { E0_ENABLE_WRITE( E_ENABLE_ON); E1_ENABLE_WRITE( E_ENABLE_ON); E2_ENABLE_WRITE( E_ENABLE_ON); E3_ENABLE_WRITE( E_ENABLE_ON); }
102
-    #define disable_e0() { E0_ENABLE_WRITE(!E_ENABLE_ON); E1_ENABLE_WRITE(!E_ENABLE_ON); E2_ENABLE_WRITE(!E_ENABLE_ON); E3_ENABLE_WRITE(!E_ENABLE_ON); }
101
+    #define  enable_E0() { E0_ENABLE_WRITE( E_ENABLE_ON); E1_ENABLE_WRITE( E_ENABLE_ON); E2_ENABLE_WRITE( E_ENABLE_ON); E3_ENABLE_WRITE( E_ENABLE_ON); }
102
+    #define disable_E0() { E0_ENABLE_WRITE(!E_ENABLE_ON); E1_ENABLE_WRITE(!E_ENABLE_ON); E2_ENABLE_WRITE(!E_ENABLE_ON); E3_ENABLE_WRITE(!E_ENABLE_ON); }
103
   #elif MIXING_STEPPERS > 2
103
   #elif MIXING_STEPPERS > 2
104
-    #define  enable_e0() { E0_ENABLE_WRITE( E_ENABLE_ON); E1_ENABLE_WRITE( E_ENABLE_ON); E2_ENABLE_WRITE( E_ENABLE_ON); }
105
-    #define disable_e0() { E0_ENABLE_WRITE(!E_ENABLE_ON); E1_ENABLE_WRITE(!E_ENABLE_ON); E2_ENABLE_WRITE(!E_ENABLE_ON); }
104
+    #define  enable_E0() { E0_ENABLE_WRITE( E_ENABLE_ON); E1_ENABLE_WRITE( E_ENABLE_ON); E2_ENABLE_WRITE( E_ENABLE_ON); }
105
+    #define disable_E0() { E0_ENABLE_WRITE(!E_ENABLE_ON); E1_ENABLE_WRITE(!E_ENABLE_ON); E2_ENABLE_WRITE(!E_ENABLE_ON); }
106
   #else
106
   #else
107
-    #define  enable_e0() { E0_ENABLE_WRITE( E_ENABLE_ON); E1_ENABLE_WRITE( E_ENABLE_ON); }
108
-    #define disable_e0() { E0_ENABLE_WRITE(!E_ENABLE_ON); E1_ENABLE_WRITE(!E_ENABLE_ON); }
107
+    #define  enable_E0() { E0_ENABLE_WRITE( E_ENABLE_ON); E1_ENABLE_WRITE( E_ENABLE_ON); }
108
+    #define disable_E0() { E0_ENABLE_WRITE(!E_ENABLE_ON); E1_ENABLE_WRITE(!E_ENABLE_ON); }
109
   #endif
109
   #endif
110
-  #define  enable_e1() NOOP
111
-  #define disable_e1() NOOP
112
-  #define  enable_e2() NOOP
113
-  #define disable_e2() NOOP
114
-  #define  enable_e3() NOOP
115
-  #define disable_e3() NOOP
116
-  #define  enable_e4() NOOP
117
-  #define disable_e4() NOOP
110
+  #define  enable_E1() NOOP
111
+  #define disable_E1() NOOP
112
+  #define  enable_E2() NOOP
113
+  #define disable_E2() NOOP
114
+  #define  enable_E3() NOOP
115
+  #define disable_E3() NOOP
116
+  #define  enable_E4() NOOP
117
+  #define disable_E4() NOOP
118
 
118
 
119
 #else // !MIXING_EXTRUDER
119
 #else // !MIXING_EXTRUDER
120
 
120
 
121
   #if HAS_E0_ENABLE
121
   #if HAS_E0_ENABLE
122
-    #define  enable_e0() E0_ENABLE_WRITE( E_ENABLE_ON)
123
-    #define disable_e0() E0_ENABLE_WRITE(!E_ENABLE_ON)
122
+    #define  enable_E0() E0_ENABLE_WRITE( E_ENABLE_ON)
123
+    #define disable_E0() E0_ENABLE_WRITE(!E_ENABLE_ON)
124
   #else
124
   #else
125
-    #define  enable_e0() NOOP
126
-    #define disable_e0() NOOP
125
+    #define  enable_E0() NOOP
126
+    #define disable_E0() NOOP
127
   #endif
127
   #endif
128
 
128
 
129
   #if E_STEPPERS > 1 && HAS_E1_ENABLE
129
   #if E_STEPPERS > 1 && HAS_E1_ENABLE
130
-    #define  enable_e1() E1_ENABLE_WRITE( E_ENABLE_ON)
131
-    #define disable_e1() E1_ENABLE_WRITE(!E_ENABLE_ON)
130
+    #define  enable_E1() E1_ENABLE_WRITE( E_ENABLE_ON)
131
+    #define disable_E1() E1_ENABLE_WRITE(!E_ENABLE_ON)
132
   #else
132
   #else
133
-    #define  enable_e1() NOOP
134
-    #define disable_e1() NOOP
133
+    #define  enable_E1() NOOP
134
+    #define disable_E1() NOOP
135
   #endif
135
   #endif
136
 
136
 
137
   #if E_STEPPERS > 2 && HAS_E2_ENABLE
137
   #if E_STEPPERS > 2 && HAS_E2_ENABLE
138
-    #define  enable_e2() E2_ENABLE_WRITE( E_ENABLE_ON)
139
-    #define disable_e2() E2_ENABLE_WRITE(!E_ENABLE_ON)
138
+    #define  enable_E2() E2_ENABLE_WRITE( E_ENABLE_ON)
139
+    #define disable_E2() E2_ENABLE_WRITE(!E_ENABLE_ON)
140
   #else
140
   #else
141
-    #define  enable_e2() NOOP
142
-    #define disable_e2() NOOP
141
+    #define  enable_E2() NOOP
142
+    #define disable_E2() NOOP
143
   #endif
143
   #endif
144
 
144
 
145
   #if E_STEPPERS > 3 && HAS_E3_ENABLE
145
   #if E_STEPPERS > 3 && HAS_E3_ENABLE
146
-    #define  enable_e3() E3_ENABLE_WRITE( E_ENABLE_ON)
147
-    #define disable_e3() E3_ENABLE_WRITE(!E_ENABLE_ON)
146
+    #define  enable_E3() E3_ENABLE_WRITE( E_ENABLE_ON)
147
+    #define disable_E3() E3_ENABLE_WRITE(!E_ENABLE_ON)
148
   #else
148
   #else
149
-    #define  enable_e3() NOOP
150
-    #define disable_e3() NOOP
149
+    #define  enable_E3() NOOP
150
+    #define disable_E3() NOOP
151
   #endif
151
   #endif
152
 
152
 
153
   #if E_STEPPERS > 4 && HAS_E4_ENABLE
153
   #if E_STEPPERS > 4 && HAS_E4_ENABLE
154
-    #define  enable_e4() E4_ENABLE_WRITE( E_ENABLE_ON)
155
-    #define disable_e4() E4_ENABLE_WRITE(!E_ENABLE_ON)
154
+    #define  enable_E4() E4_ENABLE_WRITE( E_ENABLE_ON)
155
+    #define disable_E4() E4_ENABLE_WRITE(!E_ENABLE_ON)
156
   #else
156
   #else
157
-    #define  enable_e4() NOOP
158
-    #define disable_e4() NOOP
157
+    #define  enable_E4() NOOP
158
+    #define disable_E4() NOOP
159
   #endif
159
   #endif
160
 
160
 
161
 #endif // !MIXING_EXTRUDER
161
 #endif // !MIXING_EXTRUDER

+ 28
- 28
Marlin/Marlin_main.cpp View File

6489
     }
6489
     }
6490
     else {
6490
     else {
6491
       stepper.synchronize();
6491
       stepper.synchronize();
6492
-      if (code_seen('X')) disable_x();
6493
-      if (code_seen('Y')) disable_y();
6494
-      if (code_seen('Z')) disable_z();
6492
+      if (code_seen('X')) disable_X();
6493
+      if (code_seen('Y')) disable_Y();
6494
+      if (code_seen('Z')) disable_Z();
6495
       #if ((E0_ENABLE_PIN != X_ENABLE_PIN) && (E1_ENABLE_PIN != Y_ENABLE_PIN)) // Only enable on boards that have seperate ENABLE_PINS
6495
       #if ((E0_ENABLE_PIN != X_ENABLE_PIN) && (E1_ENABLE_PIN != Y_ENABLE_PIN)) // Only enable on boards that have seperate ENABLE_PINS
6496
         if (code_seen('E')) disable_e_steppers();
6496
         if (code_seen('E')) disable_e_steppers();
6497
       #endif
6497
       #endif
10888
 }
10888
 }
10889
 
10889
 
10890
 void enable_all_steppers() {
10890
 void enable_all_steppers() {
10891
-  enable_x();
10892
-  enable_y();
10893
-  enable_z();
10894
-  enable_e0();
10895
-  enable_e1();
10896
-  enable_e2();
10897
-  enable_e3();
10898
-  enable_e4();
10891
+  enable_X();
10892
+  enable_Y();
10893
+  enable_Z();
10894
+  enable_E0();
10895
+  enable_E1();
10896
+  enable_E2();
10897
+  enable_E3();
10898
+  enable_E4();
10899
 }
10899
 }
10900
 
10900
 
10901
 void disable_e_steppers() {
10901
 void disable_e_steppers() {
10902
-  disable_e0();
10903
-  disable_e1();
10904
-  disable_e2();
10905
-  disable_e3();
10906
-  disable_e4();
10902
+  disable_E0();
10903
+  disable_E1();
10904
+  disable_E2();
10905
+  disable_E3();
10906
+  disable_E4();
10907
 }
10907
 }
10908
 
10908
 
10909
 void disable_all_steppers() {
10909
 void disable_all_steppers() {
10910
-  disable_x();
10911
-  disable_y();
10912
-  disable_z();
10910
+  disable_X();
10911
+  disable_Y();
10912
+  disable_Z();
10913
   disable_e_steppers();
10913
   disable_e_steppers();
10914
 }
10914
 }
10915
 
10915
 
11011
   if (M600_TEST && stepper_inactive_time && ELAPSED(ms, previous_cmd_ms + stepper_inactive_time)
11011
   if (M600_TEST && stepper_inactive_time && ELAPSED(ms, previous_cmd_ms + stepper_inactive_time)
11012
       && !ignore_stepper_queue && !planner.blocks_queued()) {
11012
       && !ignore_stepper_queue && !planner.blocks_queued()) {
11013
     #if ENABLED(DISABLE_INACTIVE_X)
11013
     #if ENABLED(DISABLE_INACTIVE_X)
11014
-      disable_x();
11014
+      disable_X();
11015
     #endif
11015
     #endif
11016
     #if ENABLED(DISABLE_INACTIVE_Y)
11016
     #if ENABLED(DISABLE_INACTIVE_Y)
11017
-      disable_y();
11017
+      disable_Y();
11018
     #endif
11018
     #endif
11019
     #if ENABLED(DISABLE_INACTIVE_Z)
11019
     #if ENABLED(DISABLE_INACTIVE_Z)
11020
-      disable_z();
11020
+      disable_Z();
11021
     #endif
11021
     #endif
11022
     #if ENABLED(DISABLE_INACTIVE_E)
11022
     #if ENABLED(DISABLE_INACTIVE_E)
11023
       disable_e_steppers();
11023
       disable_e_steppers();
11080
       bool oldstatus;
11080
       bool oldstatus;
11081
       #if ENABLED(SWITCHING_EXTRUDER)
11081
       #if ENABLED(SWITCHING_EXTRUDER)
11082
         oldstatus = E0_ENABLE_READ;
11082
         oldstatus = E0_ENABLE_READ;
11083
-        enable_e0();
11083
+        enable_E0();
11084
       #else // !SWITCHING_EXTRUDER
11084
       #else // !SWITCHING_EXTRUDER
11085
         switch (active_extruder) {
11085
         switch (active_extruder) {
11086
           case 0:
11086
           case 0:
11087
             oldstatus = E0_ENABLE_READ;
11087
             oldstatus = E0_ENABLE_READ;
11088
-            enable_e0();
11088
+            enable_E0();
11089
             break;
11089
             break;
11090
           #if E_STEPPERS > 1
11090
           #if E_STEPPERS > 1
11091
             case 1:
11091
             case 1:
11092
               oldstatus = E1_ENABLE_READ;
11092
               oldstatus = E1_ENABLE_READ;
11093
-              enable_e1();
11093
+              enable_E1();
11094
               break;
11094
               break;
11095
             #if E_STEPPERS > 2
11095
             #if E_STEPPERS > 2
11096
               case 2:
11096
               case 2:
11097
                 oldstatus = E2_ENABLE_READ;
11097
                 oldstatus = E2_ENABLE_READ;
11098
-                enable_e2();
11098
+                enable_E2();
11099
                 break;
11099
                 break;
11100
               #if E_STEPPERS > 3
11100
               #if E_STEPPERS > 3
11101
                 case 3:
11101
                 case 3:
11102
                   oldstatus = E3_ENABLE_READ;
11102
                   oldstatus = E3_ENABLE_READ;
11103
-                  enable_e3();
11103
+                  enable_E3();
11104
                   break;
11104
                   break;
11105
                 #if E_STEPPERS > 4
11105
                 #if E_STEPPERS > 4
11106
                   case 4:
11106
                   case 4:
11107
                     oldstatus = E4_ENABLE_READ;
11107
                     oldstatus = E4_ENABLE_READ;
11108
-                    enable_e4();
11108
+                    enable_E4();
11109
                     break;
11109
                     break;
11110
                 #endif // E_STEPPERS > 4
11110
                 #endif // E_STEPPERS > 4
11111
               #endif // E_STEPPERS > 3
11111
               #endif // E_STEPPERS > 3

+ 43
- 2
Marlin/macros.h View File

36
   #define CRITICAL_SECTION_END    SREG = _sreg;
36
   #define CRITICAL_SECTION_END    SREG = _sreg;
37
 #endif
37
 #endif
38
 
38
 
39
-// Clock speed factor
40
-#define CYCLES_PER_MICROSECOND (F_CPU / 1000000UL) // 16 or 20
39
+// Clock speed factors
40
+#define CYCLES_PER_MICROSECOND (F_CPU / 1000000L) // 16 or 20
41
+#define INT0_PRESCALER 8
42
+
43
+// Highly granular delays for step pulses, etc.
44
+#define DELAY_0_NOP NOOP
45
+#define DELAY_1_NOP __asm__("nop\n\t")
46
+#define DELAY_2_NOP DELAY_1_NOP; DELAY_1_NOP
47
+#define DELAY_3_NOP DELAY_1_NOP; DELAY_2_NOP
48
+#define DELAY_4_NOP DELAY_1_NOP; DELAY_3_NOP
49
+#define DELAY_5_NOP DELAY_1_NOP; DELAY_4_NOP
50
+
51
+#define DELAY_NOPS(X) \
52
+  switch (X) { \
53
+    case 20: DELAY_1_NOP; case 19: DELAY_1_NOP; \
54
+    case 18: DELAY_1_NOP; case 17: DELAY_1_NOP; \
55
+    case 16: DELAY_1_NOP; case 15: DELAY_1_NOP; \
56
+    case 14: DELAY_1_NOP; case 13: DELAY_1_NOP; \
57
+    case 12: DELAY_1_NOP; case 11: DELAY_1_NOP; \
58
+    case 10: DELAY_1_NOP; case 9:  DELAY_1_NOP; \
59
+    case 8:  DELAY_1_NOP; case 7:  DELAY_1_NOP; \
60
+    case 6:  DELAY_1_NOP; case 5:  DELAY_1_NOP; \
61
+    case 4:  DELAY_1_NOP; case 3:  DELAY_1_NOP; \
62
+    case 2:  DELAY_1_NOP; case 1:  DELAY_1_NOP; \
63
+  }
64
+
65
+#define DELAY_10_NOP DELAY_5_NOP;  DELAY_5_NOP
66
+#define DELAY_20_NOP DELAY_10_NOP; DELAY_10_NOP
67
+
68
+#if CYCLES_PER_MICROSECOND == 16
69
+  #define DELAY_1US DELAY_10_NOP; DELAY_5_NOP; DELAY_1_NOP
70
+#else
71
+  #define DELAY_1US DELAY_20_NOP
72
+#endif
73
+#define DELAY_2US  DELAY_1US; DELAY_1US
74
+#define DELAY_3US  DELAY_1US; DELAY_2US
75
+#define DELAY_4US  DELAY_1US; DELAY_3US
76
+#define DELAY_5US  DELAY_1US; DELAY_4US
77
+#define DELAY_6US  DELAY_1US; DELAY_5US
78
+#define DELAY_7US  DELAY_1US; DELAY_6US
79
+#define DELAY_8US  DELAY_1US; DELAY_7US
80
+#define DELAY_9US  DELAY_1US; DELAY_8US
81
+#define DELAY_10US DELAY_1US; DELAY_9US
41
 
82
 
42
 // Remove compiler warning on an unused variable
83
 // Remove compiler warning on an unused variable
43
 #define UNUSED(x) (void) (x)
84
 #define UNUSED(x) (void) (x)

+ 46
- 46
Marlin/planner.cpp View File

441
     }
441
     }
442
   }
442
   }
443
   #if ENABLED(DISABLE_X)
443
   #if ENABLED(DISABLE_X)
444
-    if (!axis_active[X_AXIS]) disable_x();
444
+    if (!axis_active[X_AXIS]) disable_X();
445
   #endif
445
   #endif
446
   #if ENABLED(DISABLE_Y)
446
   #if ENABLED(DISABLE_Y)
447
-    if (!axis_active[Y_AXIS]) disable_y();
447
+    if (!axis_active[Y_AXIS]) disable_Y();
448
   #endif
448
   #endif
449
   #if ENABLED(DISABLE_Z)
449
   #if ENABLED(DISABLE_Z)
450
-    if (!axis_active[Z_AXIS]) disable_z();
450
+    if (!axis_active[Z_AXIS]) disable_Z();
451
   #endif
451
   #endif
452
   #if ENABLED(DISABLE_E)
452
   #if ENABLED(DISABLE_E)
453
     if (!axis_active[E_AXIS]) disable_e_steppers();
453
     if (!axis_active[E_AXIS]) disable_e_steppers();
832
   //enable active axes
832
   //enable active axes
833
   #if CORE_IS_XY
833
   #if CORE_IS_XY
834
     if (block->steps[A_AXIS] || block->steps[B_AXIS]) {
834
     if (block->steps[A_AXIS] || block->steps[B_AXIS]) {
835
-      enable_x();
836
-      enable_y();
835
+      enable_X();
836
+      enable_Y();
837
     }
837
     }
838
     #if DISABLED(Z_LATE_ENABLE)
838
     #if DISABLED(Z_LATE_ENABLE)
839
-      if (block->steps[Z_AXIS]) enable_z();
839
+      if (block->steps[Z_AXIS]) enable_Z();
840
     #endif
840
     #endif
841
   #elif CORE_IS_XZ
841
   #elif CORE_IS_XZ
842
     if (block->steps[A_AXIS] || block->steps[C_AXIS]) {
842
     if (block->steps[A_AXIS] || block->steps[C_AXIS]) {
843
-      enable_x();
844
-      enable_z();
843
+      enable_X();
844
+      enable_Z();
845
     }
845
     }
846
-    if (block->steps[Y_AXIS]) enable_y();
846
+    if (block->steps[Y_AXIS]) enable_Y();
847
   #elif CORE_IS_YZ
847
   #elif CORE_IS_YZ
848
     if (block->steps[B_AXIS] || block->steps[C_AXIS]) {
848
     if (block->steps[B_AXIS] || block->steps[C_AXIS]) {
849
-      enable_y();
850
-      enable_z();
849
+      enable_Y();
850
+      enable_Z();
851
     }
851
     }
852
-    if (block->steps[X_AXIS]) enable_x();
852
+    if (block->steps[X_AXIS]) enable_X();
853
   #else
853
   #else
854
-    if (block->steps[X_AXIS]) enable_x();
855
-    if (block->steps[Y_AXIS]) enable_y();
854
+    if (block->steps[X_AXIS]) enable_X();
855
+    if (block->steps[Y_AXIS]) enable_Y();
856
     #if DISABLED(Z_LATE_ENABLE)
856
     #if DISABLED(Z_LATE_ENABLE)
857
-      if (block->steps[Z_AXIS]) enable_z();
857
+      if (block->steps[Z_AXIS]) enable_Z();
858
     #endif
858
     #endif
859
   #endif
859
   #endif
860
 
860
 
868
 
868
 
869
       switch(extruder) {
869
       switch(extruder) {
870
         case 0:
870
         case 0:
871
-          enable_e0();
871
+          enable_E0();
872
           #if ENABLED(DUAL_X_CARRIAGE)
872
           #if ENABLED(DUAL_X_CARRIAGE)
873
             if (extruder_duplication_enabled) {
873
             if (extruder_duplication_enabled) {
874
-              enable_e1();
874
+              enable_E1();
875
               g_uc_extruder_last_move[1] = (BLOCK_BUFFER_SIZE) * 2;
875
               g_uc_extruder_last_move[1] = (BLOCK_BUFFER_SIZE) * 2;
876
             }
876
             }
877
           #endif
877
           #endif
878
           g_uc_extruder_last_move[0] = (BLOCK_BUFFER_SIZE) * 2;
878
           g_uc_extruder_last_move[0] = (BLOCK_BUFFER_SIZE) * 2;
879
           #if EXTRUDERS > 1
879
           #if EXTRUDERS > 1
880
-            if (g_uc_extruder_last_move[1] == 0) disable_e1();
880
+            if (g_uc_extruder_last_move[1] == 0) disable_E1();
881
             #if EXTRUDERS > 2
881
             #if EXTRUDERS > 2
882
-              if (g_uc_extruder_last_move[2] == 0) disable_e2();
882
+              if (g_uc_extruder_last_move[2] == 0) disable_E2();
883
               #if EXTRUDERS > 3
883
               #if EXTRUDERS > 3
884
-                if (g_uc_extruder_last_move[3] == 0) disable_e3();
884
+                if (g_uc_extruder_last_move[3] == 0) disable_E3();
885
                 #if EXTRUDERS > 4
885
                 #if EXTRUDERS > 4
886
-                  if (g_uc_extruder_last_move[4] == 0) disable_e4();
886
+                  if (g_uc_extruder_last_move[4] == 0) disable_E4();
887
                 #endif // EXTRUDERS > 4
887
                 #endif // EXTRUDERS > 4
888
               #endif // EXTRUDERS > 3
888
               #endif // EXTRUDERS > 3
889
             #endif // EXTRUDERS > 2
889
             #endif // EXTRUDERS > 2
891
         break;
891
         break;
892
         #if EXTRUDERS > 1
892
         #if EXTRUDERS > 1
893
           case 1:
893
           case 1:
894
-            enable_e1();
894
+            enable_E1();
895
             g_uc_extruder_last_move[1] = (BLOCK_BUFFER_SIZE) * 2;
895
             g_uc_extruder_last_move[1] = (BLOCK_BUFFER_SIZE) * 2;
896
-            if (g_uc_extruder_last_move[0] == 0) disable_e0();
896
+            if (g_uc_extruder_last_move[0] == 0) disable_E0();
897
             #if EXTRUDERS > 2
897
             #if EXTRUDERS > 2
898
-              if (g_uc_extruder_last_move[2] == 0) disable_e2();
898
+              if (g_uc_extruder_last_move[2] == 0) disable_E2();
899
               #if EXTRUDERS > 3
899
               #if EXTRUDERS > 3
900
-                if (g_uc_extruder_last_move[3] == 0) disable_e3();
900
+                if (g_uc_extruder_last_move[3] == 0) disable_E3();
901
                 #if EXTRUDERS > 4
901
                 #if EXTRUDERS > 4
902
-                  if (g_uc_extruder_last_move[4] == 0) disable_e4();
902
+                  if (g_uc_extruder_last_move[4] == 0) disable_E4();
903
                 #endif // EXTRUDERS > 4
903
                 #endif // EXTRUDERS > 4
904
               #endif // EXTRUDERS > 3
904
               #endif // EXTRUDERS > 3
905
             #endif // EXTRUDERS > 2
905
             #endif // EXTRUDERS > 2
906
           break;
906
           break;
907
           #if EXTRUDERS > 2
907
           #if EXTRUDERS > 2
908
             case 2:
908
             case 2:
909
-              enable_e2();
909
+              enable_E2();
910
               g_uc_extruder_last_move[2] = (BLOCK_BUFFER_SIZE) * 2;
910
               g_uc_extruder_last_move[2] = (BLOCK_BUFFER_SIZE) * 2;
911
-              if (g_uc_extruder_last_move[0] == 0) disable_e0();
912
-              if (g_uc_extruder_last_move[1] == 0) disable_e1();
911
+              if (g_uc_extruder_last_move[0] == 0) disable_E0();
912
+              if (g_uc_extruder_last_move[1] == 0) disable_E1();
913
               #if EXTRUDERS > 3
913
               #if EXTRUDERS > 3
914
-                if (g_uc_extruder_last_move[3] == 0) disable_e3();
914
+                if (g_uc_extruder_last_move[3] == 0) disable_E3();
915
                 #if EXTRUDERS > 4
915
                 #if EXTRUDERS > 4
916
-                  if (g_uc_extruder_last_move[4] == 0) disable_e4();
916
+                  if (g_uc_extruder_last_move[4] == 0) disable_E4();
917
                 #endif
917
                 #endif
918
               #endif
918
               #endif
919
             break;
919
             break;
920
             #if EXTRUDERS > 3
920
             #if EXTRUDERS > 3
921
               case 3:
921
               case 3:
922
-                enable_e3();
922
+                enable_E3();
923
                 g_uc_extruder_last_move[3] = (BLOCK_BUFFER_SIZE) * 2;
923
                 g_uc_extruder_last_move[3] = (BLOCK_BUFFER_SIZE) * 2;
924
-                if (g_uc_extruder_last_move[0] == 0) disable_e0();
925
-                if (g_uc_extruder_last_move[1] == 0) disable_e1();
926
-                if (g_uc_extruder_last_move[2] == 0) disable_e2();
924
+                if (g_uc_extruder_last_move[0] == 0) disable_E0();
925
+                if (g_uc_extruder_last_move[1] == 0) disable_E1();
926
+                if (g_uc_extruder_last_move[2] == 0) disable_E2();
927
                 #if EXTRUDERS > 4
927
                 #if EXTRUDERS > 4
928
-                  if (g_uc_extruder_last_move[4] == 0) disable_e4();
928
+                  if (g_uc_extruder_last_move[4] == 0) disable_E4();
929
                 #endif
929
                 #endif
930
               break;
930
               break;
931
               #if EXTRUDERS > 4
931
               #if EXTRUDERS > 4
932
                 case 4:
932
                 case 4:
933
-                  enable_e4();
933
+                  enable_E4();
934
                   g_uc_extruder_last_move[4] = (BLOCK_BUFFER_SIZE) * 2;
934
                   g_uc_extruder_last_move[4] = (BLOCK_BUFFER_SIZE) * 2;
935
-                  if (g_uc_extruder_last_move[0] == 0) disable_e0();
936
-                  if (g_uc_extruder_last_move[1] == 0) disable_e1();
937
-                  if (g_uc_extruder_last_move[2] == 0) disable_e2();
938
-                  if (g_uc_extruder_last_move[3] == 0) disable_e3();
935
+                  if (g_uc_extruder_last_move[0] == 0) disable_E0();
936
+                  if (g_uc_extruder_last_move[1] == 0) disable_E1();
937
+                  if (g_uc_extruder_last_move[2] == 0) disable_E2();
938
+                  if (g_uc_extruder_last_move[3] == 0) disable_E3();
939
                 break;
939
                 break;
940
               #endif // EXTRUDERS > 4
940
               #endif // EXTRUDERS > 4
941
             #endif // EXTRUDERS > 3
941
             #endif // EXTRUDERS > 3
943
         #endif // EXTRUDERS > 1
943
         #endif // EXTRUDERS > 1
944
       }
944
       }
945
     #else
945
     #else
946
-      enable_e0();
947
-      enable_e1();
948
-      enable_e2();
949
-      enable_e3();
950
-      enable_e4();
946
+      enable_E0();
947
+      enable_E1();
948
+      enable_E2();
949
+      enable_E3();
950
+      enable_E4();
951
     #endif
951
     #endif
952
   }
952
   }
953
 
953
 

+ 1
- 1
Marlin/servo.h View File

82
 
82
 
83
 // Say which 16 bit timers can be used and in what order
83
 // Say which 16 bit timers can be used and in what order
84
 #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
84
 #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
85
-  //#define _useTimer1
85
+  //#define _useTimer1 // Timer 1 is used by the stepper ISR
86
   #define _useTimer3
86
   #define _useTimer3
87
   #define _useTimer4
87
   #define _useTimer4
88
   #if !HAS_MOTOR_CURRENT_PWM
88
   #if !HAS_MOTOR_CURRENT_PWM

+ 127
- 74
Marlin/stepper.cpp View File

428
 
428
 
429
       #if ENABLED(Z_LATE_ENABLE)
429
       #if ENABLED(Z_LATE_ENABLE)
430
         if (current_block->steps[Z_AXIS] > 0) {
430
         if (current_block->steps[Z_AXIS] > 0) {
431
-          enable_z();
431
+          enable_Z();
432
           _NEXT_ISR(2000); // Run at slow speed - 1 KHz
432
           _NEXT_ISR(2000); // Run at slow speed - 1 KHz
433
           _ENABLE_ISRs(); // re-enable ISRs
433
           _ENABLE_ISRs(); // re-enable ISRs
434
           return;
434
           return;
460
 
460
 
461
   // Take multiple steps per interrupt (For high speed moves)
461
   // Take multiple steps per interrupt (For high speed moves)
462
   bool all_steps_done = false;
462
   bool all_steps_done = false;
463
-  for (int8_t i = 0; i < step_loops; i++) {
463
+  for (uint8_t i = step_loops; i--;) {
464
     #if ENABLED(LIN_ADVANCE)
464
     #if ENABLED(LIN_ADVANCE)
465
 
465
 
466
       counter_E += current_block->steps[E_AXIS];
466
       counter_E += current_block->steps[E_AXIS];
530
         _APPLY_STEP(AXIS)(_INVERT_STEP_PIN(AXIS),0); \
530
         _APPLY_STEP(AXIS)(_INVERT_STEP_PIN(AXIS),0); \
531
       }
531
       }
532
 
532
 
533
-    #define CYCLES_EATEN_BY_CODE 240
533
+    #if HAS_X_STEP
534
+      #define _COUNT_STEPPERS_1 1
535
+    #else
536
+      #define _COUNT_STEPPERS_1 0
537
+    #endif
538
+    #if HAS_Y_STEP
539
+      #define _COUNT_STEPPERS_2 _COUNT_STEPPERS_1 + 1
540
+    #else
541
+      #define _COUNT_STEPPERS_2 _COUNT_STEPPERS_1
542
+    #endif
543
+    #if HAS_Z_STEP
544
+      #define _COUNT_STEPPERS_3 _COUNT_STEPPERS_2 + 1
545
+    #else
546
+      #define _COUNT_STEPPERS_3 _COUNT_STEPPERS_2
547
+    #endif
548
+    #if DISABLED(ADVANCE) && DISABLED(LIN_ADVANCE)
549
+      #define _COUNT_STEPPERS_4 _COUNT_STEPPERS_3 + 1
550
+    #else
551
+      #define _COUNT_STEPPERS_4 _COUNT_STEPPERS_3
552
+    #endif
553
+
554
+    #define CYCLES_EATEN_XYZE ((_COUNT_STEPPERS_4) * 5)
555
+    #define EXTRA_CYCLES_XYZE (STEP_PULSE_CYCLES - (CYCLES_EATEN_XYZE))
534
 
556
 
535
-    // If a minimum pulse time was specified get the CPU clock
536
-    #if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_CODE
557
+    // If a minimum pulse time was specified get the timer 0 value
558
+    // which increments every 4µs on 16MHz and every 3.2µs on 20MHz.
559
+    // Two or 3 counts of TCNT0 should be a sufficient delay.
560
+    #if EXTRA_CYCLES_XYZE > 20
537
       uint32_t pulse_start = TCNT0;
561
       uint32_t pulse_start = TCNT0;
538
     #endif
562
     #endif
539
 
563
 
564
       #endif
588
       #endif
565
     #endif // !ADVANCE && !LIN_ADVANCE
589
     #endif // !ADVANCE && !LIN_ADVANCE
566
 
590
 
567
-    // For a minimum pulse time wait before stopping pulses
568
-    #if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_CODE
569
-      while ((uint32_t)(TCNT0 - pulse_start) < STEP_PULSE_CYCLES - CYCLES_EATEN_BY_CODE) { /* nada */ }
591
+    // For minimum pulse time wait before stopping pulses
592
+    #if EXTRA_CYCLES_XYZE > 20
593
+      while (EXTRA_CYCLES_XYZE > (uint32_t)(TCNT0 - pulse_start) * (INT0_PRESCALER)) { /* nada */ }
594
+      pulse_start = TCNT0;
595
+    #elif EXTRA_CYCLES_XYZE > 0
596
+      DELAY_NOPS(EXTRA_CYCLES_XYZE);
570
     #endif
597
     #endif
571
 
598
 
572
     #if HAS_X_STEP
599
     #if HAS_X_STEP
601
       all_steps_done = true;
628
       all_steps_done = true;
602
       break;
629
       break;
603
     }
630
     }
604
-  }
631
+
632
+    // For minimum pulse time wait before stopping pulses
633
+    #if EXTRA_CYCLES_XYZE > 20
634
+      if (i) while (EXTRA_CYCLES_XYZE > (uint32_t)(TCNT0 - pulse_start) * (INT0_PRESCALER)) { /* nada */ }
635
+    #elif EXTRA_CYCLES_XYZE > 0
636
+      if (i) DELAY_NOPS(EXTRA_CYCLES_XYZE);
637
+    #endif
638
+
639
+  } // steps_loop
605
 
640
 
606
   #if ENABLED(LIN_ADVANCE)
641
   #if ENABLED(LIN_ADVANCE)
607
     if (current_block->use_advance_lead) {
642
     if (current_block->use_advance_lead) {
765
 
800
 
766
 #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
801
 #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
767
 
802
 
803
+  #define CYCLES_EATEN_E (E_STEPPERS * 5)
804
+  #define EXTRA_CYCLES_E (STEP_PULSE_CYCLES - (CYCLES_EATEN_E))
805
+
768
   // Timer interrupt for E. e_steps is set in the main routine;
806
   // Timer interrupt for E. e_steps is set in the main routine;
769
 
807
 
770
   void Stepper::advance_isr() {
808
   void Stepper::advance_isr() {
794
       #endif
832
       #endif
795
     #endif
833
     #endif
796
 
834
 
797
-    #define CYCLES_EATEN_BY_E 60
798
-
799
     // Step all E steppers that have steps
835
     // Step all E steppers that have steps
800
-    for (uint8_t i = 0; i < step_loops; i++) {
836
+    for (uint8_t i = step_loops; i--;) {
801
 
837
 
802
-      #if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_E
838
+      #if EXTRA_CYCLES_E > 20
803
         uint32_t pulse_start = TCNT0;
839
         uint32_t pulse_start = TCNT0;
804
       #endif
840
       #endif
805
 
841
 
814
         #endif
850
         #endif
815
       #endif
851
       #endif
816
 
852
 
817
-      // For a minimum pulse time wait before stopping pulses
818
-      #if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_E
819
-        while ((uint32_t)(TCNT0 - pulse_start) < STEP_PULSE_CYCLES - CYCLES_EATEN_BY_E) { /* nada */ }
853
+      // For minimum pulse time wait before stopping pulses
854
+      #if EXTRA_CYCLES_E > 20
855
+        while (EXTRA_CYCLES_E > (uint32_t)(TCNT0 - pulse_start) * (INT0_PRESCALER)) { /* nada */ }
856
+        pulse_start = TCNT0;
857
+      #elif EXTRA_CYCLES_E > 0
858
+        DELAY_NOPS(EXTRA_CYCLES_E);
820
       #endif
859
       #endif
821
 
860
 
822
       STOP_E_PULSE(0);
861
       STOP_E_PULSE(0);
829
           #endif
868
           #endif
830
         #endif
869
         #endif
831
       #endif
870
       #endif
832
-    }
833
 
871
 
872
+      // For minimum pulse time wait before looping
873
+      #if EXTRA_CYCLES_E > 20
874
+        if (i) while (EXTRA_CYCLES_E > (uint32_t)(TCNT0 - pulse_start) * (INT0_PRESCALER)) { /* nada */ }
875
+      #elif EXTRA_CYCLES_E > 0
876
+        if (i) DELAY_NOPS(EXTRA_CYCLES_E);
877
+      #endif
878
+
879
+    } // steps_loop
834
   }
880
   }
835
 
881
 
836
   void Stepper::advance_isr_scheduler() {
882
   void Stepper::advance_isr_scheduler() {
986
 
1032
 
987
   #define _STEP_INIT(AXIS) AXIS ##_STEP_INIT
1033
   #define _STEP_INIT(AXIS) AXIS ##_STEP_INIT
988
   #define _WRITE_STEP(AXIS, HIGHLOW) AXIS ##_STEP_WRITE(HIGHLOW)
1034
   #define _WRITE_STEP(AXIS, HIGHLOW) AXIS ##_STEP_WRITE(HIGHLOW)
989
-  #define _DISABLE(axis) disable_## axis()
1035
+  #define _DISABLE(AXIS) disable_## AXIS()
990
 
1036
 
991
-  #define AXIS_INIT(axis, AXIS, PIN) \
1037
+  #define AXIS_INIT(AXIS, PIN) \
992
     _STEP_INIT(AXIS); \
1038
     _STEP_INIT(AXIS); \
993
     _WRITE_STEP(AXIS, _INVERT_STEP_PIN(PIN)); \
1039
     _WRITE_STEP(AXIS, _INVERT_STEP_PIN(PIN)); \
994
-    _DISABLE(axis)
1040
+    _DISABLE(AXIS)
995
 
1041
 
996
-  #define E_AXIS_INIT(NUM) AXIS_INIT(e## NUM, E## NUM, E)
1042
+  #define E_AXIS_INIT(NUM) AXIS_INIT(E## NUM, E)
997
 
1043
 
998
   // Init Step Pins
1044
   // Init Step Pins
999
   #if HAS_X_STEP
1045
   #if HAS_X_STEP
1001
       X2_STEP_INIT;
1047
       X2_STEP_INIT;
1002
       X2_STEP_WRITE(INVERT_X_STEP_PIN);
1048
       X2_STEP_WRITE(INVERT_X_STEP_PIN);
1003
     #endif
1049
     #endif
1004
-    AXIS_INIT(x, X, X);
1050
+    AXIS_INIT(X, X);
1005
   #endif
1051
   #endif
1006
 
1052
 
1007
   #if HAS_Y_STEP
1053
   #if HAS_Y_STEP
1009
       Y2_STEP_INIT;
1055
       Y2_STEP_INIT;
1010
       Y2_STEP_WRITE(INVERT_Y_STEP_PIN);
1056
       Y2_STEP_WRITE(INVERT_Y_STEP_PIN);
1011
     #endif
1057
     #endif
1012
-    AXIS_INIT(y, Y, Y);
1058
+    AXIS_INIT(Y, Y);
1013
   #endif
1059
   #endif
1014
 
1060
 
1015
   #if HAS_Z_STEP
1061
   #if HAS_Z_STEP
1017
       Z2_STEP_INIT;
1063
       Z2_STEP_INIT;
1018
       Z2_STEP_WRITE(INVERT_Z_STEP_PIN);
1064
       Z2_STEP_WRITE(INVERT_Z_STEP_PIN);
1019
     #endif
1065
     #endif
1020
-    AXIS_INIT(z, Z, Z);
1066
+    AXIS_INIT(Z, Z);
1021
   #endif
1067
   #endif
1022
 
1068
 
1023
   #if HAS_E0_STEP
1069
   #if HAS_E0_STEP
1056
   ENABLE_STEPPER_DRIVER_INTERRUPT();
1102
   ENABLE_STEPPER_DRIVER_INTERRUPT();
1057
 
1103
 
1058
   #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
1104
   #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
1059
-
1060
-    for (int i = 0; i < E_STEPPERS; i++) {
1061
-      e_steps[i] = 0;
1062
-      #if ENABLED(LIN_ADVANCE)
1063
-        current_adv_steps[i] = 0;
1064
-      #endif
1065
-    }
1066
-
1067
-  #endif // ADVANCE or LIN_ADVANCE
1105
+    ZERO(e_steps);
1106
+    #if ENABLED(LIN_ADVANCE)
1107
+      ZERO(current_adv_steps);
1108
+    #endif
1109
+  #endif // ADVANCE || LIN_ADVANCE
1068
 
1110
 
1069
   endstops.enable(true); // Start with endstops active. After homing they can be disabled
1111
   endstops.enable(true); // Start with endstops active. After homing they can be disabled
1070
   sei();
1112
   sei();
1235
 
1277
 
1236
 #if ENABLED(BABYSTEPPING)
1278
 #if ENABLED(BABYSTEPPING)
1237
 
1279
 
1238
-  #define CYCLES_EATEN_BY_BABYSTEP 60
1280
+  #if ENABLED(DELTA)
1281
+    #define CYCLES_EATEN_BABYSTEP (2 * 15)
1282
+  #else
1283
+    #define CYCLES_EATEN_BABYSTEP 0
1284
+  #endif
1285
+  #define EXTRA_CYCLES_BABYSTEP (STEP_PULSE_CYCLES - (CYCLES_EATEN_BABYSTEP))
1239
 
1286
 
1240
-  #define _ENABLE(axis) enable_## axis()
1287
+  #define _ENABLE(AXIS) enable_## AXIS()
1241
   #define _READ_DIR(AXIS) AXIS ##_DIR_READ
1288
   #define _READ_DIR(AXIS) AXIS ##_DIR_READ
1242
   #define _INVERT_DIR(AXIS) INVERT_## AXIS ##_DIR
1289
   #define _INVERT_DIR(AXIS) INVERT_## AXIS ##_DIR
1243
   #define _APPLY_DIR(AXIS, INVERT) AXIS ##_APPLY_DIR(INVERT, true)
1290
   #define _APPLY_DIR(AXIS, INVERT) AXIS ##_APPLY_DIR(INVERT, true)
1244
 
1291
 
1245
-  #if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_BABYSTEP
1292
+  #if EXTRA_CYCLES_BABYSTEP > 20
1246
     #define _SAVE_START (pulse_start = TCNT0)
1293
     #define _SAVE_START (pulse_start = TCNT0)
1247
-    #define _PULSE_WAIT while ((uint32_t)(TCNT0 - pulse_start) < STEP_PULSE_CYCLES - CYCLES_EATEN_BY_BABYSTEP) { /* nada */ }
1294
+    #define _PULSE_WAIT while (EXTRA_CYCLES_BABYSTEP > (uint32_t)(TCNT0 - pulse_start) * (INT0_PRESCALER)) { /* nada */ }
1248
   #else
1295
   #else
1249
     #define _SAVE_START NOOP
1296
     #define _SAVE_START NOOP
1250
-    #define _PULSE_WAIT NOOP
1297
+    #if EXTRA_CYCLES_BABYSTEP > 0
1298
+      #define _PULSE_WAIT DELAY_NOPS(EXTRA_CYCLES_BABYSTEP)
1299
+    #elif STEP_PULSE_CYCLES > 0
1300
+      #define _PULSE_WAIT NOOP
1301
+    #elif ENABLED(DELTA)
1302
+      #define _PULSE_WAIT delayMicroseconds(2);
1303
+    #else
1304
+      #define _PULSE_WAIT delayMicroseconds(4);
1305
+    #endif
1251
   #endif
1306
   #endif
1252
 
1307
 
1253
-  #define START_BABYSTEP_AXIS(AXIS, INVERT) { \
1254
-      old_dir = _READ_DIR(AXIS); \
1255
-      _SAVE_START; \
1308
+  #define BABYSTEP_AXIS(AXIS, INVERT) {                     \
1309
+      const uint8_t old_dir = _READ_DIR(AXIS);              \
1310
+      _ENABLE(AXIS);                                        \
1311
+      _SAVE_START;                                          \
1256
       _APPLY_DIR(AXIS, _INVERT_DIR(AXIS)^direction^INVERT); \
1312
       _APPLY_DIR(AXIS, _INVERT_DIR(AXIS)^direction^INVERT); \
1257
-      _APPLY_STEP(AXIS)(!_INVERT_STEP_PIN(AXIS), true); \
1258
-    }
1259
-
1260
-  #define STOP_BABYSTEP_AXIS(AXIS) { \
1261
-      _PULSE_WAIT; \
1262
-      _APPLY_STEP(AXIS)(_INVERT_STEP_PIN(AXIS), true); \
1263
-      _APPLY_DIR(AXIS, old_dir); \
1313
+      _APPLY_STEP(AXIS)(!_INVERT_STEP_PIN(AXIS), true);     \
1314
+      _PULSE_WAIT;                                          \
1315
+      _APPLY_STEP(AXIS)(_INVERT_STEP_PIN(AXIS), true);      \
1316
+      _APPLY_DIR(AXIS, old_dir);                            \
1264
     }
1317
     }
1265
 
1318
 
1266
   // MUST ONLY BE CALLED BY AN ISR,
1319
   // MUST ONLY BE CALLED BY AN ISR,
1268
   void Stepper::babystep(const AxisEnum axis, const bool direction) {
1321
   void Stepper::babystep(const AxisEnum axis, const bool direction) {
1269
     cli();
1322
     cli();
1270
     uint8_t old_dir;
1323
     uint8_t old_dir;
1271
-    #if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_BABYSTEP
1324
+
1325
+    #if EXTRA_CYCLES_BABYSTEP > 20
1272
       uint32_t pulse_start;
1326
       uint32_t pulse_start;
1273
     #endif
1327
     #endif
1274
 
1328
 
1275
     switch (axis) {
1329
     switch (axis) {
1276
 
1330
 
1277
-      case X_AXIS:
1278
-        _ENABLE(x);
1279
-        START_BABYSTEP_AXIS(X, false);
1280
-        STOP_BABYSTEP_AXIS(X);
1281
-        break;
1331
+      #if ENABLED(BABYSTEP_XY)
1282
 
1332
 
1283
-      case Y_AXIS:
1284
-        _ENABLE(y);
1285
-        START_BABYSTEP_AXIS(Y, false);
1286
-        STOP_BABYSTEP_AXIS(Y);
1287
-        break;
1333
+        case X_AXIS:
1334
+          BABYSTEP_AXIS(X, false);
1335
+          break;
1336
+
1337
+        case Y_AXIS:
1338
+          BABYSTEP_AXIS(Y, false);
1339
+          break;
1340
+
1341
+      #endif
1288
 
1342
 
1289
       case Z_AXIS: {
1343
       case Z_AXIS: {
1290
 
1344
 
1291
         #if DISABLED(DELTA)
1345
         #if DISABLED(DELTA)
1292
 
1346
 
1293
-          _ENABLE(z);
1294
-          START_BABYSTEP_AXIS(Z, BABYSTEP_INVERT_Z);
1295
-          STOP_BABYSTEP_AXIS(Z);
1347
+          BABYSTEP_AXIS(Z, BABYSTEP_INVERT_Z);
1296
 
1348
 
1297
         #else // DELTA
1349
         #else // DELTA
1298
 
1350
 
1299
           bool z_direction = direction ^ BABYSTEP_INVERT_Z;
1351
           bool z_direction = direction ^ BABYSTEP_INVERT_Z;
1300
 
1352
 
1301
-          enable_x();
1302
-          enable_y();
1303
-          enable_z();
1353
+          enable_X();
1354
+          enable_Y();
1355
+          enable_Z();
1356
+
1304
           uint8_t old_x_dir_pin = X_DIR_READ,
1357
           uint8_t old_x_dir_pin = X_DIR_READ,
1305
                   old_y_dir_pin = Y_DIR_READ,
1358
                   old_y_dir_pin = Y_DIR_READ,
1306
                   old_z_dir_pin = Z_DIR_READ;
1359
                   old_z_dir_pin = Z_DIR_READ;
1307
-          //setup new step
1360
+
1308
           X_DIR_WRITE(INVERT_X_DIR ^ z_direction);
1361
           X_DIR_WRITE(INVERT_X_DIR ^ z_direction);
1309
           Y_DIR_WRITE(INVERT_Y_DIR ^ z_direction);
1362
           Y_DIR_WRITE(INVERT_Y_DIR ^ z_direction);
1310
           Z_DIR_WRITE(INVERT_Z_DIR ^ z_direction);
1363
           Z_DIR_WRITE(INVERT_Z_DIR ^ z_direction);
1311
-          //perform step
1312
-          #if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_BABYSTEP
1313
-            pulse_start = TCNT0;
1314
-          #endif
1364
+
1365
+          _SAVE_START;
1366
+
1315
           X_STEP_WRITE(!INVERT_X_STEP_PIN);
1367
           X_STEP_WRITE(!INVERT_X_STEP_PIN);
1316
           Y_STEP_WRITE(!INVERT_Y_STEP_PIN);
1368
           Y_STEP_WRITE(!INVERT_Y_STEP_PIN);
1317
           Z_STEP_WRITE(!INVERT_Z_STEP_PIN);
1369
           Z_STEP_WRITE(!INVERT_Z_STEP_PIN);
1318
-          #if STEP_PULSE_CYCLES > CYCLES_EATEN_BY_BABYSTEP
1319
-            while ((uint32_t)(TCNT0 - pulse_start) < STEP_PULSE_CYCLES - CYCLES_EATEN_BY_BABYSTEP) { /* nada */ }
1320
-          #endif
1370
+
1371
+          _PULSE_WAIT;
1372
+
1321
           X_STEP_WRITE(INVERT_X_STEP_PIN);
1373
           X_STEP_WRITE(INVERT_X_STEP_PIN);
1322
           Y_STEP_WRITE(INVERT_Y_STEP_PIN);
1374
           Y_STEP_WRITE(INVERT_Y_STEP_PIN);
1323
           Z_STEP_WRITE(INVERT_Z_STEP_PIN);
1375
           Z_STEP_WRITE(INVERT_Z_STEP_PIN);
1324
-          //get old pin state back.
1376
+
1377
+          // Restore direction bits
1325
           X_DIR_WRITE(old_x_dir_pin);
1378
           X_DIR_WRITE(old_x_dir_pin);
1326
           Y_DIR_WRITE(old_y_dir_pin);
1379
           Y_DIR_WRITE(old_y_dir_pin);
1327
           Z_DIR_WRITE(old_z_dir_pin);
1380
           Z_DIR_WRITE(old_z_dir_pin);

+ 0
- 7
Marlin/ultralcd_st7920_u8glib_rrd.h View File

43
 //set optimization so ARDUINO optimizes this file
43
 //set optimization so ARDUINO optimizes this file
44
 #pragma GCC optimize (3)
44
 #pragma GCC optimize (3)
45
 
45
 
46
-#define DELAY_0_NOP  NOOP
47
-#define DELAY_1_NOP  __asm__("nop\n\t")
48
-#define DELAY_2_NOP  __asm__("nop\n\t" "nop\n\t")
49
-#define DELAY_3_NOP  __asm__("nop\n\t" "nop\n\t" "nop\n\t")
50
-#define DELAY_4_NOP  __asm__("nop\n\t" "nop\n\t" "nop\n\t" "nop\n\t")
51
-
52
-
53
 // If you want you can define your own set of delays in Configuration.h
46
 // If you want you can define your own set of delays in Configuration.h
54
 //#define ST7920_DELAY_1 DELAY_0_NOP
47
 //#define ST7920_DELAY_1 DELAY_0_NOP
55
 //#define ST7920_DELAY_2 DELAY_0_NOP
48
 //#define ST7920_DELAY_2 DELAY_0_NOP

Loading…
Cancel
Save