Преглед изворни кода

Merge pull request #9152 from thinkyhead/bf2_anti_stutter

[2.0.x] Ensure smooth printer movements
Scott Lahteine пре 7 година
родитељ
комит
3ae41e5f7f
No account linked to committer's email address

+ 1
- 0
Marlin/src/HAL/HAL_AVR/HAL_AVR.h Прегледај датотеку

@@ -139,6 +139,7 @@ extern "C" {
139 139
 
140 140
 #define ENABLE_STEPPER_DRIVER_INTERRUPT()  SBI(TIMSK1, OCIE1A)
141 141
 #define DISABLE_STEPPER_DRIVER_INTERRUPT() CBI(TIMSK1, OCIE1A)
142
+#define STEPPER_ISR_ENABLED() TEST(TIMSK1, OCIE1A)
142 143
 
143 144
 #define ENABLE_TEMPERATURE_INTERRUPT()  SBI(TIMSK0, OCIE0B)
144 145
 #define DISABLE_TEMPERATURE_INTERRUPT() CBI(TIMSK0, OCIE0B)

+ 9
- 4
Marlin/src/HAL/HAL_DUE/HAL_timers_Due.cpp Прегледај датотеку

@@ -112,23 +112,28 @@ void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
112 112
 }
113 113
 
114 114
 void HAL_timer_enable_interrupt(const uint8_t timer_num) {
115
-  const tTimerConfig *pConfig = &TimerConfig[timer_num];
115
+  const tTimerConfig * const pConfig = &TimerConfig[timer_num];
116 116
   pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_IER = TC_IER_CPCS;
117 117
 }
118 118
 
119 119
 void HAL_timer_disable_interrupt(const uint8_t timer_num) {
120
-  const tTimerConfig *pConfig = &TimerConfig[timer_num];
120
+  const tTimerConfig * const pConfig = &TimerConfig[timer_num];
121 121
   pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_IDR = TC_IDR_CPCS;
122 122
 }
123 123
 
124
+void HAL_timer_interrupt_enabled(const uint8_t timer_num) {
125
+  const tTimerConfig * const pConfig = &TimerConfig[timer_num];
126
+  return pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_IER == TC_IER_CPCS;
127
+}
128
+
124 129
 #if 0
125 130
   void HAL_timer_set_count(const uint8_t timer_num, const uint32_t count) {
126
-    const tTimerConfig *pConfig = &TimerConfig[timer_num];
131
+    const tTimerConfig * const pConfig = &TimerConfig[timer_num];
127 132
     TC_SetRC(pConfig->pTimerRegs, pConfig->channel, count);
128 133
   }
129 134
 
130 135
   void HAL_timer_isr_prologue(const uint8_t timer_num) {
131
-    const tTimerConfig *pConfig = &TimerConfig[timer_num];
136
+    const tTimerConfig * const pConfig = &TimerConfig[timer_num];
132 137
     TC_GetStatus(pConfig->pTimerRegs, pConfig->channel);
133 138
   }
134 139
 #endif

+ 7
- 5
Marlin/src/HAL/HAL_DUE/HAL_timers_Due.h Прегледај датотеку

@@ -55,6 +55,7 @@ typedef uint32_t hal_timer_t;
55 55
 
56 56
 #define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM)
57 57
 #define DISABLE_STEPPER_DRIVER_INTERRUPT()  HAL_timer_disable_interrupt(STEP_TIMER_NUM)
58
+#define STEPPER_ISR_ENABLED() HAL_timer_interrupt_enabled(STEP_TIMER_NUM)
58 59
 
59 60
 #define ENABLE_TEMPERATURE_INTERRUPT()  HAL_timer_enable_interrupt(TEMP_TIMER_NUM)
60 61
 #define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
@@ -91,32 +92,33 @@ extern const tTimerConfig TimerConfig[];
91 92
 void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
92 93
 
93 94
 FORCE_INLINE static void HAL_timer_set_count(const uint8_t timer_num, const hal_timer_t count) {
94
-  const tTimerConfig *pConfig = &TimerConfig[timer_num];
95
+  const tTimerConfig * const pConfig = &TimerConfig[timer_num];
95 96
   pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_RC = count;
96 97
 }
97 98
 
98 99
 FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
99
-  const tTimerConfig *pConfig = &TimerConfig[timer_num];
100
+  const tTimerConfig * const pConfig = &TimerConfig[timer_num];
100 101
   return pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_RC;
101 102
 }
102 103
 
103 104
 FORCE_INLINE static void HAL_timer_set_current_count(const uint8_t timer_num, const hal_timer_t count) {
104
-  const tTimerConfig *pConfig = &TimerConfig[timer_num];
105
+  const tTimerConfig * const pConfig = &TimerConfig[timer_num];
105 106
   pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_CV = count;
106 107
 }
107 108
 
108 109
 FORCE_INLINE static hal_timer_t HAL_timer_get_current_count(const uint8_t timer_num) {
109
-  const tTimerConfig *pConfig = &TimerConfig[timer_num];
110
+  const tTimerConfig * const pConfig = &TimerConfig[timer_num];
110 111
   return pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_CV;
111 112
 }
112 113
 
113 114
 void HAL_timer_enable_interrupt(const uint8_t timer_num);
114 115
 void HAL_timer_disable_interrupt(const uint8_t timer_num);
116
+bool HAL_timer_interrupt_enabled(const uint8_t timer_num);
115 117
 
116 118
 //void HAL_timer_isr_prologue(const uint8_t timer_num);
117 119
 
118 120
 FORCE_INLINE static void HAL_timer_isr_prologue(const uint8_t timer_num) {
119
-  const tTimerConfig *pConfig = &TimerConfig[timer_num];
121
+  const tTimerConfig * const pConfig = &TimerConfig[timer_num];
120 122
   // Reading the status register clears the interrupt flag
121 123
   pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_SR;
122 124
 }

+ 8
- 0
Marlin/src/HAL/HAL_LPC1768/HAL_timers.cpp Прегледај датотеку

@@ -75,6 +75,14 @@ void HAL_timer_disable_interrupt(const uint8_t timer_num) {
75 75
   }
76 76
 }
77 77
 
78
+bool HAL_timer_interrupt_enabled(const uint8_t timer_num) {
79
+  switch (timer_num) {
80
+    case 0: return NVIC_GetActive(TIMER0_IRQn);
81
+    case 1: return NVIC_GetActive(TIMER1_IRQn);
82
+  }
83
+  return false;
84
+}
85
+
78 86
 void HAL_timer_isr_prologue(const uint8_t timer_num) {
79 87
   switch (timer_num) {
80 88
     case 0: SBI(LPC_TIM0->IR, 0); break; // Clear the Interrupt

+ 3
- 0
Marlin/src/HAL/HAL_LPC1768/HAL_timers.h Прегледај датотеку

@@ -58,6 +58,8 @@ typedef uint32_t hal_timer_t;
58 58
 
59 59
 #define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM)
60 60
 #define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM)
61
+#define STEPPER_ISR_ENABLED() HAL_timer_interrupt_enabled(STEP_TIMER_NUM)
62
+
61 63
 #define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM)
62 64
 #define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
63 65
 
@@ -125,6 +127,7 @@ FORCE_INLINE static hal_timer_t HAL_timer_get_current_count(const uint8_t timer_
125 127
 
126 128
 void HAL_timer_enable_interrupt(const uint8_t timer_num);
127 129
 void HAL_timer_disable_interrupt(const uint8_t timer_num);
130
+bool HAL_timer_interrupt_enabled(const uint8_t timer_num);
128 131
 void HAL_timer_isr_prologue(const uint8_t timer_num);
129 132
 
130 133
 #endif // _HAL_TIMERS_DUE_H

+ 11
- 3
Marlin/src/HAL/HAL_STM32F1/HAL_timers_Stm32f1.cpp Прегледај датотеку

@@ -93,7 +93,7 @@ const tTimerConfig TimerConfig [NUM_HARDWARE_TIMERS] = {
93 93
  * TODO: Calculate Timer prescale value, so we get the 32bit to adjust
94 94
  */
95 95
 
96
-void HAL_timer_start(uint8_t timer_num, uint32_t frequency) {
96
+void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
97 97
   nvic_irq_num irq_num;
98 98
   switch (timer_num) {
99 99
     case 1: irq_num = NVIC_TIMER1_CC; break;
@@ -135,7 +135,7 @@ void HAL_timer_start(uint8_t timer_num, uint32_t frequency) {
135 135
   }
136 136
 }
137 137
 
138
-void HAL_timer_enable_interrupt(uint8_t timer_num) {
138
+void HAL_timer_enable_interrupt(const uint8_t timer_num) {
139 139
   switch (timer_num) {
140 140
     case STEP_TIMER_NUM:
141 141
       timer_enable_irq(STEP_TIMER_DEV, STEP_TIMER_CHAN);
@@ -148,7 +148,7 @@ void HAL_timer_enable_interrupt(uint8_t timer_num) {
148 148
   }
149 149
 }
150 150
 
151
-void HAL_timer_disable_interrupt(uint8_t timer_num) {
151
+void HAL_timer_disable_interrupt(const uint8_t timer_num) {
152 152
   switch (timer_num) {
153 153
     case STEP_TIMER_NUM:
154 154
       timer_disable_irq(STEP_TIMER_DEV, STEP_TIMER_CHAN);
@@ -161,4 +161,12 @@ void HAL_timer_disable_interrupt(uint8_t timer_num) {
161 161
   }
162 162
 }
163 163
 
164
+bool HAL_timer_interrupt_enabled(const uint8_t timer_num) {
165
+  switch (timer_num) {
166
+    case STEP_TIMER_NUM: return bool(TIM_DIER(STEP_TIMER_DEV) & STEP_TIMER_CHAN);
167
+    case TEMP_TIMER_NUM: return bool(TIM_DIER(TEMP_TIMER_DEV) & TEMP_TIMER_CHAN);
168
+  }
169
+  return false;
170
+}
171
+
164 172
 #endif // __STM32F1__

+ 5
- 5
Marlin/src/HAL/HAL_STM32F1/HAL_timers_Stm32f1.h Прегледај датотеку

@@ -62,8 +62,6 @@ typedef uint16_t hal_timer_t;
62 62
 #define STEP_TIMER_DEV TIMER_DEV(STEP_TIMER_NUM)
63 63
 #define TEMP_TIMER_DEV TIMER_DEV(TEMP_TIMER_NUM)
64 64
 
65
-
66
-
67 65
 //STM32_HAVE_TIMER(n);
68 66
 
69 67
 #define HAL_TIMER_RATE         (F_CPU)  // frequency of timers peripherals
@@ -79,6 +77,7 @@ typedef uint16_t hal_timer_t;
79 77
 
80 78
 #define ENABLE_STEPPER_DRIVER_INTERRUPT() timer_enable_irq(STEP_TIMER_DEV, STEP_TIMER_CHAN)
81 79
 #define DISABLE_STEPPER_DRIVER_INTERRUPT() timer_disable_irq(STEP_TIMER_DEV, STEP_TIMER_CHAN)
80
+#define STEPPER_ISR_ENABLED() HAL_timer_interrupt_enabled(STEP_TIMER_NUM)
82 81
 
83 82
 #define ENABLE_TEMPERATURE_INTERRUPT() timer_enable_irq(TEMP_TIMER_DEV, TEMP_TIMER_CHAN)
84 83
 #define DISABLE_TEMPERATURE_INTERRUPT() timer_disable_irq(TEMP_TIMER_DEV, TEMP_TIMER_CHAN)
@@ -113,9 +112,10 @@ static HardwareTimer TempTimer(TEMP_TIMER_NUM);
113 112
 // Public functions
114 113
 // --------------------------------------------------------------------------
115 114
 
116
-void HAL_timer_start(uint8_t timer_num, uint32_t frequency);
117
-void HAL_timer_enable_interrupt(uint8_t timer_num);
118
-void HAL_timer_disable_interrupt(uint8_t timer_num);
115
+void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
116
+void HAL_timer_enable_interrupt(const uint8_t timer_num);
117
+void HAL_timer_disable_interrupt(const uint8_t timer_num);
118
+bool HAL_timer_interrupt_enabled(const uint8_t timer_num);
119 119
 
120 120
 /**
121 121
  * NOTE: By default libmaple sets ARPE = 1, which means the Auto reload register is preloaded (will only update with an update event)

+ 8
- 0
Marlin/src/HAL/HAL_TEENSY35_36/HAL_timers_Teensy.cpp Прегледај датотеку

@@ -67,6 +67,14 @@ void HAL_timer_disable_interrupt(const uint8_t timer_num) {
67 67
   }
68 68
 }
69 69
 
70
+bool HAL_timer_interrupt_enabled(const uint8_t timer_num) {
71
+  switch (timer_num) {
72
+    case 0: return NVIC_IS_ENABLED(IRQ_FTM0);
73
+    case 1: return NVIC_IS_ENABLED(IRQ_FTM1);
74
+  }
75
+  return false;
76
+}
77
+
70 78
 void HAL_timer_isr_prologue(const uint8_t timer_num) {
71 79
   switch(timer_num) {
72 80
     case 0:

+ 3
- 1
Marlin/src/HAL/HAL_TEENSY35_36/HAL_timers_Teensy.h Прегледај датотеку

@@ -68,6 +68,8 @@ typedef uint32_t hal_timer_t;
68 68
 
69 69
 #define ENABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_enable_interrupt(STEP_TIMER_NUM)
70 70
 #define DISABLE_STEPPER_DRIVER_INTERRUPT() HAL_timer_disable_interrupt(STEP_TIMER_NUM)
71
+#define STEPPER_ISR_ENABLED() HAL_timer_interrupt_enabled(STEP_TIMER_NUM)
72
+
71 73
 #define ENABLE_TEMPERATURE_INTERRUPT() HAL_timer_enable_interrupt(TEMP_TIMER_NUM)
72 74
 #define DISABLE_TEMPERATURE_INTERRUPT() HAL_timer_disable_interrupt(TEMP_TIMER_NUM)
73 75
 
@@ -110,8 +112,8 @@ FORCE_INLINE static hal_timer_t HAL_timer_get_current_count(const uint8_t timer_
110 112
 
111 113
 void HAL_timer_enable_interrupt(const uint8_t timer_num);
112 114
 void HAL_timer_disable_interrupt(const uint8_t timer_num);
115
+bool HAL_timer_interrupt_enabled(const uint8_t timer_num);
113 116
 
114 117
 void HAL_timer_isr_prologue(const uint8_t timer_num);
115 118
 
116 119
 #endif // _HAL_TIMERS_TEENSY_H
117
-

+ 0
- 19
Marlin/src/core/serial.h Прегледај датотеку

@@ -61,25 +61,6 @@ enum DebugFlags {
61 61
   };
62 62
 #endif
63 63
 
64
-//todo: HAL: breaks encapsulation
65
-// For AVR only, define a serial interface based on configuration
66
-#ifdef __AVR__
67
-  #ifdef USBCON
68
-    #include <HardwareSerial.h>
69
-    #if ENABLED(BLUETOOTH)
70
-      #define MYSERIAL0 bluetoothSerial
71
-    #else
72
-      #define MYSERIAL0 Serial
73
-    #endif // BLUETOOTH
74
-  #else
75
-    #include "../HAL/HAL_AVR/MarlinSerial.h"
76
-    #define MYSERIAL0 customizedSerial
77
-  #endif
78
-#elif defined(ARDUINO_ARCH_SAM)
79
-  // To pull the Serial port definitions and overrides
80
-  #include "../HAL/HAL_DUE/MarlinSerial_Due.h"
81
-#endif
82
-
83 64
 extern uint8_t marlin_debug_flags;
84 65
 #define DEBUGGING(F) (marlin_debug_flags & (DEBUG_## F))
85 66
 

+ 5
- 6
Marlin/src/module/planner.cpp Прегледај датотеку

@@ -1352,7 +1352,9 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE], float fr_mm_s, const
1352 1352
 
1353 1353
   // Initialize block entry speed. Compute based on deceleration to user-defined MINIMUM_PLANNER_SPEED.
1354 1354
   const float v_allowable = max_allowable_speed(-block->acceleration, MINIMUM_PLANNER_SPEED, block->millimeters);
1355
-  block->entry_speed = min(vmax_junction, v_allowable);
1355
+  // If stepper ISR is disabled, this indicates buffer_segment wants to add a split block.
1356
+  // In this case start with the max. allowed speed to avoid an interrupted first move.
1357
+  block->entry_speed = STEPPER_ISR_ENABLED() ? MINIMUM_PLANNER_SPEED : min(vmax_junction, v_allowable);
1356 1358
 
1357 1359
   // Initialize planner efficiency flags
1358 1360
   // Set flag if block will always reach maximum junction speed regardless of entry/exit speeds.
@@ -1362,7 +1364,7 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE], float fr_mm_s, const
1362 1364
   // block nominal speed limits both the current and next maximum junction speeds. Hence, in both
1363 1365
   // the reverse and forward planners, the corresponding block junction speed will always be at the
1364 1366
   // the maximum junction speed and may always be ignored for any speed reduction checks.
1365
-  block->flag |= BLOCK_FLAG_RECALCULATE | (block->nominal_speed <= v_allowable ? BLOCK_FLAG_NOMINAL_LENGTH : 0);
1367
+  block->flag |= block->nominal_speed <= v_allowable ? BLOCK_FLAG_RECALCULATE | BLOCK_FLAG_NOMINAL_LENGTH : BLOCK_FLAG_RECALCULATE;
1366 1368
 
1367 1369
   // Update previous path unit_vector and nominal speed
1368 1370
   COPY(previous_speed, current_speed);
@@ -1382,7 +1384,7 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE], float fr_mm_s, const
1382 1384
      *                                      In that case, the retract and move will be executed together.
1383 1385
      *                                      This leads to too many advance steps due to a huge e_acceleration.
1384 1386
      *                                      The math is good, but we must avoid retract moves with advance!
1385
-     * lin_dist_e > 0                     : Extruder is running forward (e.g., for "Wipe while retracting" (Slic3r) or "Combing" (Cura) moves)
1387
+     * lin_dist_e > 0                       : Extruder is running forward (e.g., for "Wipe while retracting" (Slic3r) or "Combing" (Cura) moves)
1386 1388
      */
1387 1389
     block->use_advance_lead =  esteps && (block->steps[X_AXIS] || block->steps[Y_AXIS])
1388 1390
                             && extruder_advance_k
@@ -1398,9 +1400,6 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE], float fr_mm_s, const
1398 1400
 
1399 1401
   #endif // LIN_ADVANCE
1400 1402
 
1401
-  const float bnsr = 1.0 / block->nominal_speed;
1402
-  calculate_trapezoid_for_block(block, block->entry_speed * bnsr, safe_speed * bnsr);
1403
-
1404 1403
   // Move buffer head
1405 1404
   block_buffer_head = next_buffer_head;
1406 1405
 

+ 10
- 0
Marlin/src/module/planner.h Прегледај датотеку

@@ -534,6 +534,16 @@ class Planner {
534 534
     static block_t* get_current_block() {
535 535
       if (blocks_queued()) {
536 536
         block_t * const block = &block_buffer[block_buffer_tail];
537
+
538
+        // If the block has no trapezoid calculated, it's unsafe to execute.
539
+        if (movesplanned() > 1) {
540
+          const block_t * const next = &block_buffer[next_block_index(block_buffer_tail)];
541
+          if (TEST(block->flag, BLOCK_BIT_RECALCULATE) || TEST(next->flag, BLOCK_BIT_RECALCULATE))
542
+            return NULL;
543
+        }
544
+        else if (TEST(block->flag, BLOCK_BIT_RECALCULATE))
545
+          return NULL;
546
+
537 547
         #if ENABLED(ULTRA_LCD)
538 548
           block_buffer_runtime_us -= block->segment_time_us; // We can't be sure how long an active block will take, so don't count it.
539 549
         #endif

Loading…
Откажи
Сачувај