Browse Source

Fix stepper pulse timing

Always honor minimum period on stepper pulse generation, and fix timing calculations

Signed-off-by: etagle <ejtagle@hotmail.com>
etagle 7 years ago
parent
commit
a215725df6

+ 12
- 15
Marlin/src/HAL/HAL_AVR/HAL.h View File

@@ -108,10 +108,6 @@ extern "C" {
108 108
   int freeMemory(void);
109 109
 }
110 110
 
111
-// eeprom
112
-//void eeprom_write_byte(unsigned char *pos, unsigned char value);
113
-//unsigned char eeprom_read_byte(unsigned char *pos);
114
-
115 111
 // timers
116 112
 #define HAL_TIMER_RATE          ((F_CPU) / 8)    // i.e., 2MHz or 2.5MHz
117 113
 
@@ -119,20 +115,15 @@ extern "C" {
119 115
 #define TEMP_TIMER_NUM          0
120 116
 #define PULSE_TIMER_NUM         STEP_TIMER_NUM
121 117
 
122
-#define STEPPER_TIMER_RATE      HAL_TIMER_RATE
123
-#define HAL_TICKS_PER_US        ((STEPPER_TIMER_RATE) / 1000000) // Cannot be of type double
124
-#define STEPPER_TIMER_PRESCALE  8
125
-#define STEP_TIMER_MIN_INTERVAL 8 // minimum time in µs between stepper interrupts
126
-
127 118
 #define TEMP_TIMER_FREQUENCY    ((F_CPU) / 64.0 / 256.0)
128 119
 
129
-#define TIMER_OCR_1             OCR1A
130
-#define TIMER_COUNTER_1         TCNT1
131
-
132
-#define TIMER_OCR_0             OCR0A
133
-#define TIMER_COUNTER_0         TCNT0
120
+#define STEPPER_TIMER_RATE      HAL_TIMER_RATE
121
+#define STEPPER_TIMER_PRESCALE  8
122
+#define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // Cannot be of type double
134 123
 
135
-#define PULSE_TIMER_PRESCALE    STEPPER_TIMER_PRESCALE
124
+#define PULSE_TIMER_RATE       STEPPER_TIMER_RATE   // frequency of pulse timer
125
+#define PULSE_TIMER_PRESCALE   STEPPER_TIMER_PRESCALE
126
+#define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US
136 127
 
137 128
 #define ENABLE_STEPPER_DRIVER_INTERRUPT()  SBI(TIMSK1, OCIE1A)
138 129
 #define DISABLE_STEPPER_DRIVER_INTERRUPT() CBI(TIMSK1, OCIE1A)
@@ -173,6 +164,12 @@ FORCE_INLINE void HAL_timer_start(const uint8_t timer_num, const uint32_t freque
173 164
   }
174 165
 }
175 166
 
167
+#define TIMER_OCR_1             OCR1A
168
+#define TIMER_COUNTER_1         TCNT1
169
+
170
+#define TIMER_OCR_0             OCR0A
171
+#define TIMER_COUNTER_0         TCNT0
172
+
176 173
 #define _CAT(a, ...) a ## __VA_ARGS__
177 174
 #define HAL_timer_set_compare(timer, compare) (_CAT(TIMER_OCR_, timer) = compare)
178 175
 #define HAL_timer_restrain(timer, interval_ticks) NOLESS(_CAT(TIMER_OCR_, timer), _CAT(TIMER_COUNTER_, timer) + interval_ticks)

+ 9
- 8
Marlin/src/HAL/HAL_DUE/HAL_timers_Due.h View File

@@ -43,21 +43,22 @@
43 43
 typedef uint32_t hal_timer_t;
44 44
 #define HAL_TIMER_TYPE_MAX 0xFFFFFFFF
45 45
 
46
+#define HAL_TIMER_RATE         ((F_CPU) / 2)    // frequency of timers peripherals
47
+
46 48
 #define STEP_TIMER_NUM 3  // index of timer to use for stepper
47 49
 #define TEMP_TIMER_NUM 4  // index of timer to use for temperature
50
+#define PULSE_TIMER_NUM STEP_TIMER_NUM
48 51
 #define TONE_TIMER_NUM 6  // index of timer to use for beeper tones
49 52
 
50
-#define HAL_TIMER_RATE         ((F_CPU) / 2)    // frequency of timers peripherals
53
+#define TEMP_TIMER_FREQUENCY   1000 // temperature interrupt frequency
51 54
 
52 55
 #define STEPPER_TIMER_RATE     HAL_TIMER_RATE   // frequency of stepper timer (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE)
53
-#define HAL_TICKS_PER_US       ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs
54
-#define STEPPER_TIMER_PRESCALE (CYCLES_PER_MICROSECOND / HAL_TICKS_PER_US)
55
-#define STEP_TIMER_MIN_INTERVAL   8 // minimum time in µs between stepper interrupts
56
-
57
-#define TEMP_TIMER_FREQUENCY   1000 // temperature interrupt frequency
56
+#define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs
57
+#define STEPPER_TIMER_PRESCALE (CYCLES_PER_MICROSECOND / STEPPER_TIMER_TICKS_PER_US)
58 58
 
59
-#define PULSE_TIMER_NUM STEP_TIMER_NUM
60
-#define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE
59
+#define PULSE_TIMER_RATE       STEPPER_TIMER_RATE   // frequency of pulse timer
60
+#define PULSE_TIMER_PRESCALE   STEPPER_TIMER_PRESCALE
61
+#define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US
61 62
 
62 63
 #define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM)
63 64
 #define DISABLE_STEPPER_DRIVER_INTERRUPT()  HAL_timer_disable_interrupt(STEP_TIMER_NUM)

+ 9
- 8
Marlin/src/HAL/HAL_LPC1768/HAL_timers.h View File

@@ -66,22 +66,23 @@
66 66
 typedef uint32_t hal_timer_t;
67 67
 #define HAL_TIMER_TYPE_MAX 0xFFFFFFFF
68 68
 
69
+#define HAL_TIMER_RATE         ((SystemCoreClock) / 4)  // frequency of timers peripherals
70
+
69 71
 #define STEP_TIMER_NUM 0  // Timer Index for Stepper
70 72
 #define TEMP_TIMER_NUM 1  // Timer Index for Temperature
71 73
 #define PULSE_TIMER_NUM STEP_TIMER_NUM
72 74
 #define PWM_TIMER_NUM 3   // Timer Index for PWM
73 75
 
74
-#define HAL_TIMER_RATE         ((SystemCoreClock) / 4)  // frequency of timers peripherals
75
-#define STEPPER_TIMER_RATE     HAL_TIMER_RATE   // frequency of stepper timer (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE)
76
-#define HAL_TICKS_PER_US       ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs
77
-#define STEPPER_TIMER_PRESCALE (CYCLES_PER_MICROSECOND / HAL_TICKS_PER_US)
78
-
79
-#define STEP_TIMER_MIN_INTERVAL   8 // minimum time in µs between stepper interrupts
80
-
81 76
 #define TEMP_TIMER_RATE        1000000
82 77
 #define TEMP_TIMER_FREQUENCY   1000 // temperature interrupt frequency
83 78
 
84
-#define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE
79
+#define STEPPER_TIMER_RATE     HAL_TIMER_RATE   // frequency of stepper timer (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE)
80
+#define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs
81
+#define STEPPER_TIMER_PRESCALE (CYCLES_PER_MICROSECOND / STEPPER_TIMER_TICKS_PER_US)
82
+
83
+#define PULSE_TIMER_RATE       STEPPER_TIMER_RATE   // frequency of pulse timer
84
+#define PULSE_TIMER_PRESCALE   STEPPER_TIMER_PRESCALE
85
+#define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US
85 86
 
86 87
 #define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM)
87 88
 #define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM)

+ 15
- 18
Marlin/src/HAL/HAL_STM32F1/HAL_timers_Stm32f1.h View File

@@ -47,37 +47,34 @@
47 47
 typedef uint16_t hal_timer_t;
48 48
 #define HAL_TIMER_TYPE_MAX 0xFFFF
49 49
 
50
+#define HAL_TIMER_RATE         (F_CPU)  // frequency of timers peripherals
51
+
52
+#define STEP_TIMER_CHAN 1 // Channel of the timer to use for compare and interrupts
53
+#define TEMP_TIMER_CHAN 1 // Channel of the timer to use for compare and interrupts
54
+
50 55
 #if defined(MCU_STM32F103CB) || defined(MCU_STM32F103C8)
51 56
   #define STEP_TIMER_NUM 4 // For C8/CB boards, use timer 4
52 57
 #else
53 58
   #define STEP_TIMER_NUM 5 // for other boards, five is fine.
54 59
 #endif
55
-
56
-#define STEP_TIMER_CHAN 1 // Channel of the timer to use for compare and interrupts
57 60
 #define TEMP_TIMER_NUM 2  // index of timer to use for temperature
58
-#define TEMP_TIMER_CHAN 1 // Channel of the timer to use for compare and interrupts
59 61
 #define PULSE_TIMER_NUM STEP_TIMER_NUM
60 62
 
61
-timer_dev* get_timer_dev(int number);
62
-
63
-#define TIMER_DEV(num) get_timer_dev(num)
64
-
65
-#define STEP_TIMER_DEV TIMER_DEV(STEP_TIMER_NUM)
66
-#define TEMP_TIMER_DEV TIMER_DEV(TEMP_TIMER_NUM)
67
-
68
-//STM32_HAVE_TIMER(n);
63
+#define TEMP_TIMER_PRESCALE     1000 // prescaler for setting Temp timer, 72Khz
64
+#define TEMP_TIMER_FREQUENCY    1000 // temperature interrupt frequency
69 65
 
70
-#define HAL_TIMER_RATE         (F_CPU)  // frequency of timers peripherals
71 66
 #define STEPPER_TIMER_PRESCALE 18             // prescaler for setting stepper timer, 4Mhz
72 67
 #define STEPPER_TIMER_RATE     (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE)   // frequency of stepper timer
73
-#define HAL_TICKS_PER_US       ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs
74
-
75
-#define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE
68
+#define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs
76 69
 
77
-#define TEMP_TIMER_PRESCALE     1000 // prescaler for setting Temp timer, 72Khz
78
-#define TEMP_TIMER_FREQUENCY    1000 // temperature interrupt frequency
70
+#define PULSE_TIMER_RATE       STEPPER_TIMER_RATE   // frequency of pulse timer
71
+#define PULSE_TIMER_PRESCALE   STEPPER_TIMER_PRESCALE
72
+#define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US
79 73
 
80
-#define STEP_TIMER_MIN_INTERVAL    8 // minimum time in µs between stepper interrupts
74
+timer_dev* get_timer_dev(int number);
75
+#define TIMER_DEV(num) get_timer_dev(num)
76
+#define STEP_TIMER_DEV TIMER_DEV(STEP_TIMER_NUM)
77
+#define TEMP_TIMER_DEV TIMER_DEV(TEMP_TIMER_NUM)
81 78
 
82 79
 #define ENABLE_STEPPER_DRIVER_INTERRUPT() timer_enable_irq(STEP_TIMER_DEV, STEP_TIMER_CHAN)
83 80
 #define DISABLE_STEPPER_DRIVER_INTERRUPT() timer_disable_irq(STEP_TIMER_DEV, STEP_TIMER_CHAN)

+ 9
- 8
Marlin/src/HAL/HAL_STM32F4/HAL_timers_STM32F4.h View File

@@ -38,21 +38,22 @@
38 38
 #define hal_timer_t uint32_t  // TODO: One is 16-bit, one 32-bit - does this need to be checked?
39 39
 #define HAL_TIMER_TYPE_MAX 0xFFFF
40 40
 
41
-#define STEP_TIMER_NUM 0  // index of timer to use for stepper
42
-#define TEMP_TIMER_NUM 1  // index of timer to use for temperature
43
-
44 41
 #define HAL_TIMER_RATE         (HAL_RCC_GetSysClockFreq() / 2)  // frequency of timer peripherals
45
-#define STEPPER_TIMER_PRESCALE 54            // was 40,prescaler for setting stepper timer, 2Mhz
46
-#define STEPPER_TIMER_RATE     (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE)   // frequency of stepper timer
47
-#define HAL_TICKS_PER_US       ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs
48 42
 
43
+#define STEP_TIMER_NUM 0  // index of timer to use for stepper
44
+#define TEMP_TIMER_NUM 1  // index of timer to use for temperature
49 45
 #define PULSE_TIMER_NUM STEP_TIMER_NUM
50
-#define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE
51 46
 
52 47
 #define TEMP_TIMER_PRESCALE     1000 // prescaler for setting Temp timer, 72Khz
53 48
 #define TEMP_TIMER_FREQUENCY    1000 // temperature interrupt frequency
54 49
 
55
-#define STEP_TIMER_MIN_INTERVAL    8 // minimum time in µs between stepper interrupts
50
+#define STEPPER_TIMER_PRESCALE 54 // was 40,prescaler for setting stepper timer, 2Mhz
51
+#define STEPPER_TIMER_RATE     (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE)   // frequency of stepper timer
52
+#define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs
53
+
54
+#define PULSE_TIMER_RATE       STEPPER_TIMER_RATE   // frequency of pulse timer
55
+#define PULSE_TIMER_PRESCALE   STEPPER_TIMER_PRESCALE
56
+#define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US
56 57
 
57 58
 #define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM)
58 59
 #define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM)

+ 10
- 9
Marlin/src/HAL/HAL_STM32F7/HAL_timers_STM32F7.h View File

@@ -38,21 +38,22 @@
38 38
 #define hal_timer_t uint32_t  // TODO: One is 16-bit, one 32-bit - does this need to be checked?
39 39
 #define HAL_TIMER_TYPE_MAX 0xFFFF
40 40
 
41
-#define STEP_TIMER_NUM 0  // index of timer to use for stepper
42
-#define TEMP_TIMER_NUM 1  // index of timer to use for temperature
43
-
44 41
 #define HAL_TIMER_RATE         (HAL_RCC_GetSysClockFreq() / 2)  // frequency of timer peripherals
45
-#define STEPPER_TIMER_PRESCALE 54            // was 40,prescaler for setting stepper timer, 2Mhz
46
-#define STEPPER_TIMER_RATE     (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE)   // frequency of stepper timer
47
-#define HAL_TICKS_PER_US       ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs
48 42
 
43
+#define STEP_TIMER_NUM 0  // index of timer to use for stepper
44
+#define TEMP_TIMER_NUM 1  // index of timer to use for temperature
49 45
 #define PULSE_TIMER_NUM STEP_TIMER_NUM
50
-#define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE
51 46
 
52
-#define TEMP_TIMER_PRESCALE     1000 // prescaler for setting Temp timer, 72Khz
53 47
 #define TEMP_TIMER_FREQUENCY    1000 // temperature interrupt frequency
48
+#define TEMP_TIMER_PRESCALE     1000 // prescaler for setting Temp timer, 72Khz
49
+
50
+#define STEPPER_TIMER_PRESCALE 54    // was 40,prescaler for setting stepper timer, 2Mhz
51
+#define STEPPER_TIMER_RATE     (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE)   // frequency of stepper timer
52
+#define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs
54 53
 
55
-#define STEP_TIMER_MIN_INTERVAL    8 // minimum time in µs between stepper interrupts
54
+#define PULSE_TIMER_RATE       STEPPER_TIMER_RATE   // frequency of pulse timer
55
+#define PULSE_TIMER_PRESCALE   STEPPER_TIMER_PRESCALE
56
+#define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US
56 57
 
57 58
 #define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM)
58 59
 #define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM)

+ 12
- 10
Marlin/src/HAL/HAL_TEENSY35_36/HAL_timers_Teensy.h View File

@@ -43,10 +43,6 @@
43 43
 typedef uint32_t hal_timer_t;
44 44
 #define HAL_TIMER_TYPE_MAX 0xFFFFFFFF
45 45
 
46
-#define STEP_TIMER_NUM 0
47
-#define TEMP_TIMER_NUM 1
48
-#define PULSE_TIMER_NUM STEP_TIMER_NUM
49
-
50 46
 #define FTM0_TIMER_PRESCALE 8
51 47
 #define FTM1_TIMER_PRESCALE 4
52 48
 #define FTM0_TIMER_PRESCALE_BITS 0b011
@@ -56,14 +52,20 @@ typedef uint32_t hal_timer_t;
56 52
 #define FTM1_TIMER_RATE (F_BUS / FTM1_TIMER_PRESCALE) // 60MHz / 4 = 15MHz
57 53
 
58 54
 #define HAL_TIMER_RATE         (FTM0_TIMER_RATE)
59
-#define STEPPER_TIMER_RATE     HAL_TIMER_RATE
60
-#define HAL_TICKS_PER_US       ((STEPPER_TIMER_RATE) / 1000000)
61
-#define STEPPER_TIMER_PRESCALE (CYCLES_PER_MICROSECOND / HAL_TICKS_PER_US)
62
-#define STEP_TIMER_MIN_INTERVAL   8 // minimum time in µs between stepper interrupts
63 55
 
64
-#define TEMP_TIMER_FREQUENCY   1000
56
+#define STEP_TIMER_NUM 0
57
+#define TEMP_TIMER_NUM 1
58
+#define PULSE_TIMER_NUM STEP_TIMER_NUM
59
+
60
+#define TEMP_TIMER_FREQUENCY    1000
61
+
62
+#define STEPPER_TIMER_RATE     HAL_TIMER_RATE
63
+#define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000)
64
+#define STEPPER_TIMER_PRESCALE (CYCLES_PER_MICROSECOND / STEPPER_TIMER_TICKS_PER_US)
65 65
 
66
-#define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE
66
+#define PULSE_TIMER_RATE       STEPPER_TIMER_RATE   // frequency of pulse timer
67
+#define PULSE_TIMER_PRESCALE   STEPPER_TIMER_PRESCALE
68
+#define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US
67 69
 
68 70
 #define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM)
69 71
 #define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM)

+ 36
- 27
Marlin/src/module/stepper.cpp View File

@@ -1263,7 +1263,7 @@ void Stepper::isr() {
1263 1263
       #else
1264 1264
         1
1265 1265
       #endif
1266
-      * (HAL_TICKS_PER_US)
1266
+      * (STEPPER_TIMER_TICKS_PER_US)
1267 1267
     );
1268 1268
 
1269 1269
     /**
@@ -1316,10 +1316,10 @@ void Stepper::stepper_pulse_phase_isr() {
1316 1316
   // Just update the value we will get at the end of the loop
1317 1317
   step_events_completed += events_to_do;
1318 1318
 
1319
-  #if MINIMUM_STEPPER_PULSE
1320
-    // Get the timer count and estimate the end of the pulse
1321
-    hal_timer_t pulse_end = HAL_timer_get_count(PULSE_TIMER_NUM) + hal_timer_t((HAL_TICKS_PER_US) * (MINIMUM_STEPPER_PULSE));
1322
-  #endif
1319
+  // Get the timer count and estimate the end of the pulse
1320
+  hal_timer_t pulse_end = HAL_timer_get_count(PULSE_TIMER_NUM) + hal_timer_t(MIN_PULSE_TICKS);
1321
+
1322
+  const hal_timer_t added_step_ticks = ADDED_STEP_TICKS;
1323 1323
 
1324 1324
   // Take multiple steps per interrupt (For high speed moves)
1325 1325
   do {
@@ -1392,10 +1392,11 @@ void Stepper::stepper_pulse_phase_isr() {
1392 1392
     #if MINIMUM_STEPPER_PULSE
1393 1393
       // Just wait for the requested pulse duration
1394 1394
       while (HAL_timer_get_count(PULSE_TIMER_NUM) < pulse_end) { /* nada */ }
1395
-      // Add to the value, the value needed for the pulse end and ensuring the maximum driver rate is enforced
1396
-      pulse_end += hal_timer_t(MIN_STEPPER_PULSE_CYCLES) - hal_timer_t((HAL_TICKS_PER_US) * (MINIMUM_STEPPER_PULSE));
1397 1395
     #endif
1398 1396
 
1397
+    // Add the delay needed to ensure the maximum driver rate is enforced
1398
+    if (signed(added_step_ticks) > 0) pulse_end += hal_timer_t(added_step_ticks);
1399
+
1399 1400
     // Pulse stop
1400 1401
     #if HAS_X_STEP
1401 1402
       PULSE_STOP(X);
@@ -1423,15 +1424,15 @@ void Stepper::stepper_pulse_phase_isr() {
1423 1424
     // Decrement the count of pending pulses to do
1424 1425
     --events_to_do;
1425 1426
 
1426
-    #if MINIMUM_STEPPER_PULSE
1427
-      // For minimum pulse time wait after stopping pulses also
1428
-      if (events_to_do) {
1429
-        // Just wait for the requested pulse duration
1430
-        while (HAL_timer_get_count(PULSE_TIMER_NUM) < pulse_end) { /* nada */ }
1427
+    // For minimum pulse time wait after stopping pulses also
1428
+    if (events_to_do) {
1429
+      // Just wait for the requested pulse duration
1430
+      while (HAL_timer_get_count(PULSE_TIMER_NUM) < pulse_end) { /* nada */ }
1431
+      #if MINIMUM_STEPPER_PULSE
1431 1432
         // Add to the value, the time that the pulse must be active (to be used on the next loop)
1432
-        pulse_end += hal_timer_t((HAL_TICKS_PER_US) * (MINIMUM_STEPPER_PULSE));
1433
-      }
1434
-    #endif
1433
+        pulse_end += hal_timer_t(MIN_PULSE_TICKS);
1434
+      #endif
1435
+    }
1435 1436
 
1436 1437
   } while (events_to_do);
1437 1438
 }
@@ -1810,13 +1811,15 @@ uint32_t Stepper::stepper_block_phase_isr() {
1810 1811
           REV_E_DIR(active_extruder);
1811 1812
       #endif
1812 1813
 
1814
+    // Get the timer count and estimate the end of the pulse
1815
+    hal_timer_t pulse_end = HAL_timer_get_count(PULSE_TIMER_NUM) + hal_timer_t(MIN_PULSE_TICKS);
1816
+
1817
+    const hal_timer_t added_step_ticks = ADDED_STEP_TICKS;
1818
+
1813 1819
     // Step E stepper if we have steps
1814 1820
     while (LA_steps) {
1815 1821
 
1816
-      #if MINIMUM_STEPPER_PULSE
1817
-        hal_timer_t pulse_end = HAL_timer_get_count(PULSE_TIMER_NUM) + hal_timer_t((HAL_TICKS_PER_US) * (MINIMUM_STEPPER_PULSE));
1818
-      #endif
1819
-
1822
+      // Set the STEP pulse ON
1820 1823
       #if ENABLED(MIXING_EXTRUDER)
1821 1824
         MIXING_STEPPERS_LOOP(j) {
1822 1825
           // Step mixing steppers (proportionally)
@@ -1828,15 +1831,18 @@ uint32_t Stepper::stepper_block_phase_isr() {
1828 1831
         E_STEP_WRITE(active_extruder, !INVERT_E_STEP_PIN);
1829 1832
       #endif
1830 1833
 
1834
+      // Enforce a minimum duration for STEP pulse ON
1831 1835
       #if MINIMUM_STEPPER_PULSE
1832 1836
         // Just wait for the requested pulse duration
1833 1837
         while (HAL_timer_get_count(PULSE_TIMER_NUM) < pulse_end) { /* nada */ }
1834
-        // Add to the value, the value needed for the pulse end and ensuring the maximum driver rate is enforced
1835
-        pulse_end += hal_timer_t(MIN_STEPPER_PULSE_CYCLES) - hal_timer_t((HAL_TICKS_PER_US) * (MINIMUM_STEPPER_PULSE));
1836 1838
       #endif
1837 1839
 
1840
+      // Add the delay needed to ensure the maximum driver rate is enforced
1841
+      if (signed(added_step_ticks) > 0) pulse_end += hal_timer_t(added_step_ticks);
1842
+
1838 1843
       LA_steps < 0 ? ++LA_steps : --LA_steps;
1839 1844
 
1845
+      // Set the STEP pulse OFF
1840 1846
       #if ENABLED(MIXING_EXTRUDER)
1841 1847
         MIXING_STEPPERS_LOOP(j) {
1842 1848
           if (delta_error_m[j] >= 0) {
@@ -1848,12 +1854,15 @@ uint32_t Stepper::stepper_block_phase_isr() {
1848 1854
         E_STEP_WRITE(active_extruder, INVERT_E_STEP_PIN);
1849 1855
       #endif
1850 1856
 
1851
-      #if MINIMUM_STEPPER_PULSE
1852
-        // For minimum pulse time wait before looping
1853
-        // Just wait for the requested pulse duration
1854
-        if (LA_steps) while (HAL_timer_get_count(PULSE_TIMER_NUM) < pulse_end) { /* nada */ }
1855
-      #endif
1856
-
1857
+      // For minimum pulse time wait before looping
1858
+      // Just wait for the requested pulse duration
1859
+      if (LA_steps) {
1860
+        while (HAL_timer_get_count(PULSE_TIMER_NUM) < pulse_end) { /* nada */ }
1861
+        #if MINIMUM_STEPPER_PULSE
1862
+          // Add to the value, the time that the pulse must be active (to be used on the next loop)
1863
+          pulse_end += hal_timer_t(MIN_PULSE_TICKS);
1864
+        #endif
1865
+      }
1857 1866
     } // LA_steps
1858 1867
 
1859 1868
     return interval;

Loading…
Cancel
Save