Browse Source

Localize stepper-specific defines

Scott Lahteine 7 years ago
parent
commit
0d79128c8d
3 changed files with 166 additions and 159 deletions
  1. 0
    145
      Marlin/src/inc/Conditionals_post.h
  2. 1
    1
      Marlin/src/module/stepper.cpp
  3. 165
    13
      Marlin/src/module/stepper.h

+ 0
- 145
Marlin/src/inc/Conditionals_post.h View File

1444
   #define USE_EXECUTE_COMMANDS_IMMEDIATE
1444
   #define USE_EXECUTE_COMMANDS_IMMEDIATE
1445
 #endif
1445
 #endif
1446
 
1446
 
1447
-// Calculate a default maximum stepper rate, if not supplied
1448
-#ifndef MAXIMUM_STEPPER_RATE
1449
-  #if MINIMUM_STEPPER_PULSE
1450
-    #define MAXIMUM_STEPPER_RATE (1000000UL / (2UL * (MINIMUM_STEPPER_PULSE)))
1451
-  #else
1452
-    #define MAXIMUM_STEPPER_RATE 500000UL
1453
-  #endif
1454
-#endif
1455
-
1456
-//
1457
-// Estimate the amount of time the ISR will take to execute
1458
-//
1459
-#ifdef CPU_32_BIT
1460
-
1461
-  // The base ISR takes 792 cycles
1462
-  #define ISR_BASE_CYCLES  792UL
1463
-
1464
-  // Linear advance base time is 64 cycles
1465
-  #if ENABLED(LIN_ADVANCE)
1466
-    #define ISR_LA_BASE_CYCLES 64UL
1467
-  #else
1468
-    #define ISR_LA_BASE_CYCLES 0UL
1469
-  #endif
1470
-
1471
-  // S curve interpolation adds 40 cycles
1472
-  #if ENABLED(S_CURVE_ACCELERATION)
1473
-    #define ISR_S_CURVE_CYCLES 40UL
1474
-  #else
1475
-    #define ISR_S_CURVE_CYCLES 0UL
1476
-  #endif
1477
-
1478
-  // Stepper Loop base cycles
1479
-  #define ISR_LOOP_BASE_CYCLES 4UL
1480
-
1481
-  // And each stepper takes 16 cycles
1482
-  #define ISR_STEPPER_CYCLES 16UL
1483
-
1484
-#else
1485
-
1486
-  // The base ISR takes 752 cycles
1487
-  #define ISR_BASE_CYCLES  752UL
1488
-
1489
-  // Linear advance base time is 32 cycles
1490
-  #if ENABLED(LIN_ADVANCE)
1491
-    #define ISR_LA_BASE_CYCLES 32UL
1492
-  #else
1493
-    #define ISR_LA_BASE_CYCLES 0UL
1494
-  #endif
1495
-
1496
-  // S curve interpolation adds 160 cycles
1497
-  #if ENABLED(S_CURVE_ACCELERATION)
1498
-    #define ISR_S_CURVE_CYCLES 160UL
1499
-  #else
1500
-    #define ISR_S_CURVE_CYCLES 0UL
1501
-  #endif
1502
-
1503
-  // Stepper Loop base cycles
1504
-  #define ISR_LOOP_BASE_CYCLES 32UL
1505
-
1506
-  // And each stepper takes 88 cycles
1507
-  #define ISR_STEPPER_CYCLES 88UL
1508
-
1509
-#endif
1510
-
1511
-// For each stepper, we add its time
1512
-#ifdef HAS_X_STEP
1513
-  #define ISR_X_STEPPER_CYCLES ISR_STEPPER_CYCLES
1514
-#else
1515
-  #define ISR_X_STEPPER_CYCLES 0UL
1516
-#endif
1517
-
1518
-// For each stepper, we add its time
1519
-#ifdef HAS_Y_STEP
1520
-  #define ISR_Y_STEPPER_CYCLES ISR_STEPPER_CYCLES
1521
-#else
1522
-  #define ISR_Y_STEPPER_CYCLES 0UL
1523
-#endif
1524
-
1525
-// For each stepper, we add its time
1526
-#ifdef HAS_Z_STEP
1527
-  #define ISR_Z_STEPPER_CYCLES ISR_STEPPER_CYCLES
1528
-#else
1529
-  #define ISR_Z_STEPPER_CYCLES 0UL
1530
-#endif
1531
-
1532
-// E is always interpolated, even for mixing extruders
1533
-#define ISR_E_STEPPER_CYCLES ISR_STEPPER_CYCLES
1534
-
1535
-// If linear advance is disabled, then the loop also handles them
1536
-#if DISABLED(LIN_ADVANCE) && ENABLED(MIXING_EXTRUDER)
1537
-  #define ISR_MIXING_STEPPER_CYCLES ((MIXING_STEPPERS) * ISR_STEPPER_CYCLES)
1538
-#else
1539
-  #define ISR_MIXING_STEPPER_CYCLES  0UL
1540
-#endif
1541
-
1542
-// And the total minimum loop time is, without including the base
1543
-#define MIN_ISR_LOOP_CYCLES (ISR_X_STEPPER_CYCLES + ISR_Y_STEPPER_CYCLES + ISR_Z_STEPPER_CYCLES + ISR_E_STEPPER_CYCLES + ISR_MIXING_STEPPER_CYCLES)
1544
-
1545
-// Calculate the minimum MPU cycles needed per pulse to enforce not surpassing the maximum stepper rate
1546
-#define _MIN_STEPPER_PULSE_CYCLES(N) MAX((F_CPU) / (MAXIMUM_STEPPER_RATE), ((F_CPU) / 500000UL) * (N))
1547
-#if MINIMUM_STEPPER_PULSE
1548
-  #define MIN_STEPPER_PULSE_CYCLES _MIN_STEPPER_PULSE_CYCLES(MINIMUM_STEPPER_PULSE)
1549
-#else
1550
-  #define MIN_STEPPER_PULSE_CYCLES _MIN_STEPPER_PULSE_CYCLES(1)
1551
-#endif
1552
-
1553
-// But the user could be enforcing a minimum time, so the loop time is
1554
-#define ISR_LOOP_CYCLES (ISR_LOOP_BASE_CYCLES + MAX(MIN_STEPPER_PULSE_CYCLES, MIN_ISR_LOOP_CYCLES))
1555
-
1556
-// If linear advance is enabled, then it is handled separately
1557
-#if ENABLED(LIN_ADVANCE)
1558
-
1559
-  // Estimate the minimum LA loop time
1560
-  #if ENABLED(MIXING_EXTRUDER)
1561
-    #define MIN_ISR_LA_LOOP_CYCLES ((MIXING_STEPPERS) * (ISR_STEPPER_CYCLES))
1562
-  #else
1563
-    #define MIN_ISR_LA_LOOP_CYCLES ISR_STEPPER_CYCLES
1564
-  #endif
1565
-
1566
-  // And the real loop time
1567
-  #define ISR_LA_LOOP_CYCLES MAX(MIN_STEPPER_PULSE_CYCLES, MIN_ISR_LA_LOOP_CYCLES)
1568
-
1569
-#else
1570
-  #define ISR_LA_LOOP_CYCLES 0UL
1571
-#endif
1572
-
1573
-// Now estimate the total ISR execution time in cycles given a step per ISR multiplier
1574
-#define ISR_EXECUTION_CYCLES(rate) (((ISR_BASE_CYCLES + ISR_S_CURVE_CYCLES + (ISR_LOOP_CYCLES * rate) + ISR_LA_BASE_CYCLES + ISR_LA_LOOP_CYCLES)) / rate)
1575
-
1576
-// The maximum allowable stepping frequency when doing x128-x1 stepping (in Hz)
1577
-#define MAX_128X_STEP_ISR_FREQUENCY (F_CPU / ISR_EXECUTION_CYCLES(128))
1578
-#define MAX_64X_STEP_ISR_FREQUENCY  (F_CPU / ISR_EXECUTION_CYCLES(64))
1579
-#define MAX_32X_STEP_ISR_FREQUENCY  (F_CPU / ISR_EXECUTION_CYCLES(32))
1580
-#define MAX_16X_STEP_ISR_FREQUENCY  (F_CPU / ISR_EXECUTION_CYCLES(16))
1581
-#define MAX_8X_STEP_ISR_FREQUENCY   (F_CPU / ISR_EXECUTION_CYCLES(8))
1582
-#define MAX_4X_STEP_ISR_FREQUENCY   (F_CPU / ISR_EXECUTION_CYCLES(4))
1583
-#define MAX_2X_STEP_ISR_FREQUENCY   (F_CPU / ISR_EXECUTION_CYCLES(2))
1584
-#define MAX_1X_STEP_ISR_FREQUENCY   (F_CPU / ISR_EXECUTION_CYCLES(1))
1585
-
1586
-// The minimum allowable frequency for step smoothing will be 1/10 of the maximum nominal frequency (in Hz)
1587
-#define MIN_STEP_ISR_FREQUENCY    MAX_1X_STEP_ISR_FREQUENCY
1588
-
1589
-// Disable multiple steps per ISR
1590
-//#define DISABLE_MULTI_STEPPING
1591
-
1592
 #endif // CONDITIONALS_POST_H
1447
 #endif // CONDITIONALS_POST_H

+ 1
- 1
Marlin/src/module/stepper.cpp View File

1664
         uint32_t max_rate = current_block->nominal_rate;  // Get the maximum rate (maximum event speed)
1664
         uint32_t max_rate = current_block->nominal_rate;  // Get the maximum rate (maximum event speed)
1665
         while (max_rate < MIN_STEP_ISR_FREQUENCY) {
1665
         while (max_rate < MIN_STEP_ISR_FREQUENCY) {
1666
           max_rate <<= 1;
1666
           max_rate <<= 1;
1667
-          if (max_rate >= MAX_1X_STEP_ISR_FREQUENCY) break;
1667
+          if (max_rate >= MAX_STEP_ISR_FREQUENCY_1X) break;
1668
           ++oversampling;
1668
           ++oversampling;
1669
         }
1669
         }
1670
         oversampling_factor = oversampling;
1670
         oversampling_factor = oversampling;

+ 165
- 13
Marlin/src/module/stepper.h View File

43
 #ifndef STEPPER_H
43
 #ifndef STEPPER_H
44
 #define STEPPER_H
44
 #define STEPPER_H
45
 
45
 
46
+#include "../inc/MarlinConfig.h"
47
+
48
+// Disable multiple steps per ISR
49
+//#define DISABLE_MULTI_STEPPING
50
+
51
+//
52
+// Estimate the amount of time the Stepper ISR will take to execute
53
+//
54
+
55
+#ifndef MINIMUM_STEPPER_PULSE
56
+  #define MINIMUM_STEPPER_PULSE 0
57
+#endif
58
+
59
+#ifndef MAXIMUM_STEPPER_RATE
60
+  #if MINIMUM_STEPPER_PULSE
61
+    #define MAXIMUM_STEPPER_RATE (1000000UL / (2UL * (MINIMUM_STEPPER_PULSE)))
62
+  #else
63
+    #define MAXIMUM_STEPPER_RATE 500000UL
64
+  #endif
65
+#endif
66
+
67
+#ifdef CPU_32_BIT
68
+
69
+  // The base ISR takes 792 cycles
70
+  #define ISR_BASE_CYCLES  792UL
71
+
72
+  // Linear advance base time is 64 cycles
73
+  #if ENABLED(LIN_ADVANCE)
74
+    #define ISR_LA_BASE_CYCLES 64UL
75
+  #else
76
+    #define ISR_LA_BASE_CYCLES 0UL
77
+  #endif
78
+
79
+  // S curve interpolation adds 40 cycles
80
+  #if ENABLED(S_CURVE_ACCELERATION)
81
+    #define ISR_S_CURVE_CYCLES 40UL
82
+  #else
83
+    #define ISR_S_CURVE_CYCLES 0UL
84
+  #endif
85
+
86
+  // Stepper Loop base cycles
87
+  #define ISR_LOOP_BASE_CYCLES 4UL
88
+
89
+  // And each stepper takes 16 cycles
90
+  #define ISR_STEPPER_CYCLES 16UL
91
+
92
+#else
93
+
94
+  // The base ISR takes 752 cycles
95
+  #define ISR_BASE_CYCLES  752UL
96
+
97
+  // Linear advance base time is 32 cycles
98
+  #if ENABLED(LIN_ADVANCE)
99
+    #define ISR_LA_BASE_CYCLES 32UL
100
+  #else
101
+    #define ISR_LA_BASE_CYCLES 0UL
102
+  #endif
103
+
104
+  // S curve interpolation adds 160 cycles
105
+  #if ENABLED(S_CURVE_ACCELERATION)
106
+    #define ISR_S_CURVE_CYCLES 160UL
107
+  #else
108
+    #define ISR_S_CURVE_CYCLES 0UL
109
+  #endif
110
+
111
+  // Stepper Loop base cycles
112
+  #define ISR_LOOP_BASE_CYCLES 32UL
113
+
114
+  // And each stepper takes 88 cycles
115
+  #define ISR_STEPPER_CYCLES 88UL
116
+
117
+#endif
118
+
119
+// Add time for each stepper
120
+#ifdef HAS_X_STEP
121
+  #define ISR_X_STEPPER_CYCLES ISR_STEPPER_CYCLES
122
+#else
123
+  #define ISR_X_STEPPER_CYCLES 0UL
124
+#endif
125
+#ifdef HAS_Y_STEP
126
+  #define ISR_Y_STEPPER_CYCLES ISR_STEPPER_CYCLES
127
+#else
128
+  #define ISR_Y_STEPPER_CYCLES 0UL
129
+#endif
130
+#ifdef HAS_Z_STEP
131
+  #define ISR_Z_STEPPER_CYCLES ISR_STEPPER_CYCLES
132
+#else
133
+  #define ISR_Z_STEPPER_CYCLES 0UL
134
+#endif
135
+
136
+// E is always interpolated, even for mixing extruders
137
+#define ISR_E_STEPPER_CYCLES ISR_STEPPER_CYCLES
138
+
139
+// If linear advance is disabled, then the loop also handles them
140
+#if DISABLED(LIN_ADVANCE) && ENABLED(MIXING_EXTRUDER)
141
+  #define ISR_MIXING_STEPPER_CYCLES ((MIXING_STEPPERS) * (ISR_STEPPER_CYCLES))
142
+#else
143
+  #define ISR_MIXING_STEPPER_CYCLES  0UL
144
+#endif
145
+
146
+// And the total minimum loop time, not including the base
147
+#define MIN_ISR_LOOP_CYCLES (ISR_X_STEPPER_CYCLES + ISR_Y_STEPPER_CYCLES + ISR_Z_STEPPER_CYCLES + ISR_E_STEPPER_CYCLES + ISR_MIXING_STEPPER_CYCLES)
148
+
149
+// Calculate the minimum MPU cycles needed per pulse to enforce, limited to the max stepper rate
150
+#define _MIN_STEPPER_PULSE_CYCLES(N) max((F_CPU) / (MAXIMUM_STEPPER_RATE), ((F_CPU) / 500000UL) * (N))
151
+#if MINIMUM_STEPPER_PULSE
152
+  #define MIN_STEPPER_PULSE_CYCLES _MIN_STEPPER_PULSE_CYCLES(MINIMUM_STEPPER_PULSE)
153
+#else
154
+  #define MIN_STEPPER_PULSE_CYCLES _MIN_STEPPER_PULSE_CYCLES(1)
155
+#endif
156
+
157
+#define MIN_PULSE_TICKS  ((PULSE_TIMER_TICKS_PER_US) * (MINIMUM_STEPPER_PULSE))
158
+#define ADDED_STEP_TICKS ((MIN_STEPPER_PULSE_CYCLES) / (PULSE_TIMER_PRESCALE) - MIN_PULSE_TICKS)
159
+
160
+// But the user could be enforcing a minimum time, so the loop time is
161
+#define ISR_LOOP_CYCLES (ISR_LOOP_BASE_CYCLES + max(MIN_STEPPER_PULSE_CYCLES, MIN_ISR_LOOP_CYCLES))
162
+
163
+// If linear advance is enabled, then it is handled separately
164
+#if ENABLED(LIN_ADVANCE)
165
+
166
+  // Estimate the minimum LA loop time
167
+  #if ENABLED(MIXING_EXTRUDER)
168
+    #define MIN_ISR_LA_LOOP_CYCLES ((MIXING_STEPPERS) * (ISR_STEPPER_CYCLES))
169
+  #else
170
+    #define MIN_ISR_LA_LOOP_CYCLES ISR_STEPPER_CYCLES
171
+  #endif
172
+
173
+  // And the real loop time
174
+  #define ISR_LA_LOOP_CYCLES max(MIN_STEPPER_PULSE_CYCLES, MIN_ISR_LA_LOOP_CYCLES)
175
+
176
+#else
177
+  #define ISR_LA_LOOP_CYCLES 0UL
178
+#endif
179
+
180
+// Now estimate the total ISR execution time in cycles given a step per ISR multiplier
181
+#define ISR_EXECUTION_CYCLES(R) (((ISR_BASE_CYCLES + ISR_S_CURVE_CYCLES + (ISR_LOOP_CYCLES) * (R) + ISR_LA_BASE_CYCLES + ISR_LA_LOOP_CYCLES)) / (R))
182
+
183
+// The maximum allowable stepping frequency when doing x128-x1 stepping (in Hz)
184
+#define MAX_STEP_ISR_FREQUENCY_128X ((F_CPU) / ISR_EXECUTION_CYCLES(128))
185
+#define MAX_STEP_ISR_FREQUENCY_64X  ((F_CPU) / ISR_EXECUTION_CYCLES(64))
186
+#define MAX_STEP_ISR_FREQUENCY_32X  ((F_CPU) / ISR_EXECUTION_CYCLES(32))
187
+#define MAX_STEP_ISR_FREQUENCY_16X  ((F_CPU) / ISR_EXECUTION_CYCLES(16))
188
+#define MAX_STEP_ISR_FREQUENCY_8X   ((F_CPU) / ISR_EXECUTION_CYCLES(8))
189
+#define MAX_STEP_ISR_FREQUENCY_4X   ((F_CPU) / ISR_EXECUTION_CYCLES(4))
190
+#define MAX_STEP_ISR_FREQUENCY_2X   ((F_CPU) / ISR_EXECUTION_CYCLES(2))
191
+#define MAX_STEP_ISR_FREQUENCY_1X   ((F_CPU) / ISR_EXECUTION_CYCLES(1))
192
+
193
+// The minimum allowable frequency for step smoothing will be 1/10 of the maximum nominal frequency (in Hz)
194
+#define MIN_STEP_ISR_FREQUENCY MAX_STEP_ISR_FREQUENCY_1X
195
+
196
+//
197
+// Stepper class definition
198
+//
199
+
46
 #include "stepper_indirection.h"
200
 #include "stepper_indirection.h"
47
 
201
 
48
 #ifdef __AVR__
202
 #ifdef __AVR__
49
   #include "speed_lookuptable.h"
203
   #include "speed_lookuptable.h"
50
 #endif
204
 #endif
51
 
205
 
52
-#include "../inc/MarlinConfig.h"
53
 #include "../module/planner.h"
206
 #include "../module/planner.h"
54
 #include "../core/language.h"
207
 #include "../core/language.h"
55
 
208
 
56
-class Stepper;
57
-extern Stepper stepper;
58
-
59
 class Stepper {
209
 class Stepper {
60
 
210
 
61
   public:
211
   public:
303
 
453
 
304
         // The stepping frequency limits for each multistepping rate
454
         // The stepping frequency limits for each multistepping rate
305
         static const uint32_t limit[] PROGMEM = {
455
         static const uint32_t limit[] PROGMEM = {
306
-          (  MAX_1X_STEP_ISR_FREQUENCY     ),
307
-          (  MAX_2X_STEP_ISR_FREQUENCY >> 1),
308
-          (  MAX_4X_STEP_ISR_FREQUENCY >> 2),
309
-          (  MAX_8X_STEP_ISR_FREQUENCY >> 3),
310
-          ( MAX_16X_STEP_ISR_FREQUENCY >> 4),
311
-          ( MAX_32X_STEP_ISR_FREQUENCY >> 5),
312
-          ( MAX_64X_STEP_ISR_FREQUENCY >> 6),
313
-          (MAX_128X_STEP_ISR_FREQUENCY >> 7)
456
+          (  MAX_STEP_ISR_FREQUENCY_1X     ),
457
+          (  MAX_STEP_ISR_FREQUENCY_2X >> 1),
458
+          (  MAX_STEP_ISR_FREQUENCY_4X >> 2),
459
+          (  MAX_STEP_ISR_FREQUENCY_8X >> 3),
460
+          ( MAX_STEP_ISR_FREQUENCY_16X >> 4),
461
+          ( MAX_STEP_ISR_FREQUENCY_32X >> 5),
462
+          ( MAX_STEP_ISR_FREQUENCY_64X >> 6),
463
+          (MAX_STEP_ISR_FREQUENCY_128X >> 7)
314
         };
464
         };
315
 
465
 
316
         // Select the proper multistepping
466
         // Select the proper multistepping
321
           ++idx;
471
           ++idx;
322
         };
472
         };
323
       #else
473
       #else
324
-        NOMORE(step_rate, uint32_t(MAX_1X_STEP_ISR_FREQUENCY));
474
+        NOMORE(step_rate, uint32_t(MAX_STEP_ISR_FREQUENCY_1X));
325
       #endif
475
       #endif
326
       *loops = multistep;
476
       *loops = multistep;
327
 
477
 
367
 
517
 
368
 };
518
 };
369
 
519
 
520
+extern Stepper stepper;
521
+
370
 #endif // STEPPER_H
522
 #endif // STEPPER_H

Loading…
Cancel
Save