|
@@ -56,7 +56,23 @@
|
56
|
56
|
// Estimate the amount of time the Stepper ISR will take to execute
|
57
|
57
|
//
|
58
|
58
|
|
|
59
|
+/**
|
|
60
|
+ * The method of calculating these cycle-constants is unclear.
|
|
61
|
+ * Most of them are no longer used directly for pulse timing, and exist
|
|
62
|
+ * only to estimate a maximum step rate based on the user's configuration.
|
|
63
|
+ * As 32-bit processors continue to diverge, maintaining cycle counts
|
|
64
|
+ * will become increasingly difficult and error-prone.
|
|
65
|
+ */
|
|
66
|
+
|
59
|
67
|
#ifdef CPU_32_BIT
|
|
68
|
+ /**
|
|
69
|
+ * Duration of START_TIMED_PULSE
|
|
70
|
+ *
|
|
71
|
+ * ...as measured on an LPC1768 with a scope and converted to cycles.
|
|
72
|
+ * Not applicable to other 32-bit processors, but as long as others
|
|
73
|
+ * take longer, pulses will be longer. For example the SKR Pro
|
|
74
|
+ * (stm32f407zgt6) requires ~60 cyles.
|
|
75
|
+ */
|
60
|
76
|
#define TIMER_READ_ADD_AND_STORE_CYCLES 34UL
|
61
|
77
|
|
62
|
78
|
// The base ISR takes 792 cycles
|
|
@@ -86,6 +102,7 @@
|
86
|
102
|
#define ISR_STEPPER_CYCLES 16UL
|
87
|
103
|
|
88
|
104
|
#else
|
|
105
|
+ // Cycles to perform actions in START_TIMED_PULSE
|
89
|
106
|
#define TIMER_READ_ADD_AND_STORE_CYCLES 13UL
|
90
|
107
|
|
91
|
108
|
// The base ISR takes 752 cycles
|
|
@@ -157,17 +174,13 @@
|
157
|
174
|
#define MIN_STEPPER_PULSE_CYCLES _MIN_STEPPER_PULSE_CYCLES(1UL)
|
158
|
175
|
#endif
|
159
|
176
|
|
160
|
|
-// Calculate the minimum ticks of the PULSE timer that must elapse with the step pulse enabled
|
161
|
|
-// adding the "start stepper pulse" code section execution cycles to account for that not all
|
162
|
|
-// pulses start at the beginning of the loop, so an extra time must be added to compensate so
|
163
|
|
-// the last generated pulse (usually the extruder stepper) has the right length
|
|
177
|
+// Calculate the minimum pulse times (high and low)
|
164
|
178
|
#if MINIMUM_STEPPER_PULSE && MAXIMUM_STEPPER_RATE
|
165
|
179
|
constexpr uint32_t _MIN_STEP_PERIOD_NS = 1000000000UL / MAXIMUM_STEPPER_RATE;
|
166
|
180
|
constexpr uint32_t _MIN_PULSE_HIGH_NS = 1000UL * MINIMUM_STEPPER_PULSE;
|
167
|
181
|
constexpr uint32_t _MIN_PULSE_LOW_NS = _MAX((_MIN_STEP_PERIOD_NS - _MIN(_MIN_STEP_PERIOD_NS, _MIN_PULSE_HIGH_NS)), _MIN_PULSE_HIGH_NS);
|
168
|
182
|
#elif MINIMUM_STEPPER_PULSE
|
169
|
183
|
// Assume 50% duty cycle
|
170
|
|
- constexpr uint32_t _MIN_STEP_PERIOD_NS = 1000000000UL / MAXIMUM_STEPPER_RATE;
|
171
|
184
|
constexpr uint32_t _MIN_PULSE_HIGH_NS = 1000UL * MINIMUM_STEPPER_PULSE;
|
172
|
185
|
constexpr uint32_t _MIN_PULSE_LOW_NS = _MIN_PULSE_HIGH_NS;
|
173
|
186
|
#elif MAXIMUM_STEPPER_RATE
|
|
@@ -178,11 +191,6 @@
|
178
|
191
|
#error "Expected at least one of MINIMUM_STEPPER_PULSE or MAXIMUM_STEPPER_RATE to be defined"
|
179
|
192
|
#endif
|
180
|
193
|
|
181
|
|
-// TODO: NS_TO_PULSE_TIMER_TICKS has some rounding issues:
|
182
|
|
-// 1. PULSE_TIMER_TICKS_PER_US rounds to an integer, which loses 20% of the count for a 2.5 MHz pulse tick (such as for LPC1768)
|
183
|
|
-// 2. The math currently rounds down to the closes tick. Perhaps should round up.
|
184
|
|
-constexpr uint32_t NS_TO_PULSE_TIMER_TICKS(uint32_t NS) { return PULSE_TIMER_TICKS_PER_US * (NS) / 1000UL; }
|
185
|
|
-#define CYCLES_TO_NS(CYC) (1000UL * (CYC) / ((F_CPU) / 1000000))
|
186
|
194
|
|
187
|
195
|
// But the user could be enforcing a minimum time, so the loop time is
|
188
|
196
|
#define ISR_LOOP_CYCLES (ISR_LOOP_BASE_CYCLES + _MAX(MIN_STEPPER_PULSE_CYCLES, MIN_ISR_LOOP_CYCLES))
|