Browse Source

[2.0.x] HAL timer set/get count => set/get compare (#9581)

To reduce confusion over the current timer count vs. the compare (aka "top") value. Caution: this re-uses the function name, changing its meaning.
Scott Lahteine 7 years ago
parent
commit
03d790451f
No account linked to committer's email address

+ 4
- 4
Marlin/src/HAL/HAL_AVR/HAL_AVR.h View File

147
 #define HAL_timer_start(timer_num, frequency)
147
 #define HAL_timer_start(timer_num, frequency)
148
 
148
 
149
 #define _CAT(a, ...) a ## __VA_ARGS__
149
 #define _CAT(a, ...) a ## __VA_ARGS__
150
-#define HAL_timer_set_count(timer, count) (_CAT(TIMER_OCR_, timer) = count)
151
-#define HAL_timer_get_count(timer) _CAT(TIMER_OCR_, timer)
152
-#define HAL_timer_set_current_count(timer, count) (_CAT(TIMER_COUNTER_, timer) = count)
153
-#define HAL_timer_get_current_count(timer) _CAT(TIMER_COUNTER_, timer)
150
+#define HAL_timer_set_compare(timer, compare) (_CAT(TIMER_OCR_, timer) = compare)
151
+#define HAL_timer_get_compare(timer) _CAT(TIMER_OCR_, timer)
152
+#define HAL_timer_set_count(timer, count) (_CAT(TIMER_COUNTER_, timer) = count)
153
+#define HAL_timer_get_count(timer) _CAT(TIMER_COUNTER_, timer)
154
 
154
 
155
 #define HAL_timer_isr_prologue(timer_num)
155
 #define HAL_timer_isr_prologue(timer_num)
156
 
156
 

+ 2
- 2
Marlin/src/HAL/HAL_DUE/HAL_timers_Due.cpp View File

127
 }
127
 }
128
 
128
 
129
 #if 0
129
 #if 0
130
-  void HAL_timer_set_count(const uint8_t timer_num, const uint32_t count) {
130
+  void HAL_timer_set_compare(const uint8_t timer_num, const uint32_t compare) {
131
     const tTimerConfig * const pConfig = &TimerConfig[timer_num];
131
     const tTimerConfig * const pConfig = &TimerConfig[timer_num];
132
-    TC_SetRC(pConfig->pTimerRegs, pConfig->channel, count);
132
+    TC_SetRC(pConfig->pTimerRegs, pConfig->channel, compare);
133
   }
133
   }
134
 
134
 
135
   void HAL_timer_isr_prologue(const uint8_t timer_num) {
135
   void HAL_timer_isr_prologue(const uint8_t timer_num) {

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

91
 
91
 
92
 void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
92
 void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
93
 
93
 
94
-FORCE_INLINE static void HAL_timer_set_count(const uint8_t timer_num, const hal_timer_t count) {
94
+FORCE_INLINE static void HAL_timer_set_compare(const uint8_t timer_num, const hal_timer_t compare) {
95
   const tTimerConfig * const pConfig = &TimerConfig[timer_num];
95
   const tTimerConfig * const pConfig = &TimerConfig[timer_num];
96
-  pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_RC = count;
96
+  pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_RC = compare;
97
 }
97
 }
98
 
98
 
99
-FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
99
+FORCE_INLINE static hal_timer_t HAL_timer_get_compare(const uint8_t timer_num) {
100
   const tTimerConfig * const pConfig = &TimerConfig[timer_num];
100
   const tTimerConfig * const pConfig = &TimerConfig[timer_num];
101
   return pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_RC;
101
   return pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_RC;
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
+FORCE_INLINE static void HAL_timer_set_count(const uint8_t timer_num, const hal_timer_t count) {
105
   const tTimerConfig * const pConfig = &TimerConfig[timer_num];
105
   const tTimerConfig * const pConfig = &TimerConfig[timer_num];
106
   pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_CV = count;
106
   pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_CV = count;
107
 }
107
 }
108
 
108
 
109
-FORCE_INLINE static hal_timer_t HAL_timer_get_current_count(const uint8_t timer_num) {
109
+FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
110
   const tTimerConfig * const pConfig = &TimerConfig[timer_num];
110
   const tTimerConfig * const pConfig = &TimerConfig[timer_num];
111
   return pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_CV;
111
   return pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_CV;
112
 }
112
 }

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

87
 void HAL_timer_init(void);
87
 void HAL_timer_init(void);
88
 void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
88
 void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
89
 
89
 
90
-FORCE_INLINE static void HAL_timer_set_count(const uint8_t timer_num, const hal_timer_t count) {
90
+FORCE_INLINE static void HAL_timer_set_compare(const uint8_t timer_num, const hal_timer_t compare) {
91
   switch (timer_num) {
91
   switch (timer_num) {
92
     case 0:
92
     case 0:
93
-      LPC_TIM0->MR0 = count;
94
-      if (LPC_TIM0->TC > count)
95
-        LPC_TIM0->TC = count - 5; // generate an immediate stepper ISR
93
+      LPC_TIM0->MR0 = compare;
94
+      if (LPC_TIM0->TC > compare)
95
+        LPC_TIM0->TC = compare - 5; // generate an immediate stepper ISR
96
       break;
96
       break;
97
     case 1:
97
     case 1:
98
-      LPC_TIM1->MR0 = count;
99
-      if (LPC_TIM1->TC > count)
100
-        LPC_TIM1->TC = count - 5; // make sure we don't have one extra long period
98
+      LPC_TIM1->MR0 = compare;
99
+      if (LPC_TIM1->TC > compare)
100
+        LPC_TIM1->TC = compare - 5; // make sure we don't have one extra long period
101
       break;
101
       break;
102
   }
102
   }
103
 }
103
 }
104
 
104
 
105
-FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
105
+FORCE_INLINE static hal_timer_t HAL_timer_get_compare(const uint8_t timer_num) {
106
   switch (timer_num) {
106
   switch (timer_num) {
107
     case 0: return LPC_TIM0->MR0;
107
     case 0: return LPC_TIM0->MR0;
108
     case 1: return LPC_TIM1->MR0;
108
     case 1: return LPC_TIM1->MR0;
110
   return 0;
110
   return 0;
111
 }
111
 }
112
 
112
 
113
-FORCE_INLINE static void HAL_timer_set_current_count(const uint8_t timer_num, const hal_timer_t count) {
113
+FORCE_INLINE static void HAL_timer_set_count(const uint8_t timer_num, const hal_timer_t count) {
114
   switch (timer_num) {
114
   switch (timer_num) {
115
     case 0: LPC_TIM0->TC = count; break;
115
     case 0: LPC_TIM0->TC = count; break;
116
     case 1: LPC_TIM1->TC = count; break;
116
     case 1: LPC_TIM1->TC = count; break;
117
   }
117
   }
118
 }
118
 }
119
 
119
 
120
-FORCE_INLINE static hal_timer_t HAL_timer_get_current_count(const uint8_t timer_num) {
120
+FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
121
   switch (timer_num) {
121
   switch (timer_num) {
122
     case 0: return LPC_TIM0->TC;
122
     case 0: return LPC_TIM0->TC;
123
     case 1: return LPC_TIM1->TC;
123
     case 1: return LPC_TIM1->TC;

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

46
 typedef uint16_t hal_timer_t;
46
 typedef uint16_t hal_timer_t;
47
 #define HAL_TIMER_TYPE_MAX 0xFFFF
47
 #define HAL_TIMER_TYPE_MAX 0xFFFF
48
 
48
 
49
-#if defined MCU_STM32F103CB  || defined(MCU_STM32F103C8)
49
+#if defined(MCU_STM32F103CB) || defined(MCU_STM32F103C8)
50
   #define STEP_TIMER_NUM 4 // For C8/CB boards, use timer 4
50
   #define STEP_TIMER_NUM 4 // For C8/CB boards, use timer 4
51
 #else
51
 #else
52
   #define STEP_TIMER_NUM 5 // for other boards, five is fine.
52
   #define STEP_TIMER_NUM 5 // for other boards, five is fine.
82
 #define ENABLE_TEMPERATURE_INTERRUPT() timer_enable_irq(TEMP_TIMER_DEV, TEMP_TIMER_CHAN)
82
 #define ENABLE_TEMPERATURE_INTERRUPT() timer_enable_irq(TEMP_TIMER_DEV, TEMP_TIMER_CHAN)
83
 #define DISABLE_TEMPERATURE_INTERRUPT() timer_disable_irq(TEMP_TIMER_DEV, TEMP_TIMER_CHAN)
83
 #define DISABLE_TEMPERATURE_INTERRUPT() timer_disable_irq(TEMP_TIMER_DEV, TEMP_TIMER_CHAN)
84
 
84
 
85
-#define HAL_timer_get_current_count(timer_num) timer_get_count(TIMER_DEV(timer_num))
86
-#define HAL_timer_set_current_count(timer_num, count) timer_set_count(TIMER_DEV(timer_num), (uint16)count)
85
+#define HAL_timer_get_count(timer_num) timer_get_count(TIMER_DEV(timer_num))
86
+#define HAL_timer_set_count(timer_num, count) timer_set_count(TIMER_DEV(timer_num), (uint16)count)
87
 
87
 
88
 
88
 
89
 #define HAL_ENABLE_ISRs() do { if (thermalManager.in_temp_isr)DISABLE_TEMPERATURE_INTERRUPT(); else ENABLE_TEMPERATURE_INTERRUPT(); ENABLE_STEPPER_DRIVER_INTERRUPT(); } while(0)
89
 #define HAL_ENABLE_ISRs() do { if (thermalManager.in_temp_isr)DISABLE_TEMPERATURE_INTERRUPT(); else ENABLE_TEMPERATURE_INTERRUPT(); ENABLE_STEPPER_DRIVER_INTERRUPT(); } while(0)
128
  * Todo: Look at that possibility later.
128
  * Todo: Look at that possibility later.
129
  */
129
  */
130
 
130
 
131
-FORCE_INLINE static void HAL_timer_set_count(const uint8_t timer_num, const hal_timer_t count) {
132
-  //count = min(count, HAL_TIMER_TYPE_MAX);
131
+FORCE_INLINE static void HAL_timer_set_compare(const uint8_t timer_num, const hal_timer_t compare) {
132
+  //compare = min(compare, HAL_TIMER_TYPE_MAX);
133
   switch (timer_num) {
133
   switch (timer_num) {
134
   case STEP_TIMER_NUM:
134
   case STEP_TIMER_NUM:
135
-    timer_set_compare(STEP_TIMER_DEV, STEP_TIMER_CHAN, count);
135
+    timer_set_compare(STEP_TIMER_DEV, STEP_TIMER_CHAN, compare);
136
     return;
136
     return;
137
   case TEMP_TIMER_NUM:
137
   case TEMP_TIMER_NUM:
138
-    timer_set_compare(TEMP_TIMER_DEV, TEMP_TIMER_CHAN, count);
138
+    timer_set_compare(TEMP_TIMER_DEV, TEMP_TIMER_CHAN, compare);
139
     return;
139
     return;
140
   default:
140
   default:
141
     return;
141
     return;
142
   }
142
   }
143
 }
143
 }
144
 
144
 
145
-FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
145
+FORCE_INLINE static hal_timer_t HAL_timer_get_compare(const uint8_t timer_num) {
146
   switch (timer_num) {
146
   switch (timer_num) {
147
   case STEP_TIMER_NUM:
147
   case STEP_TIMER_NUM:
148
     return timer_get_compare(STEP_TIMER_DEV, STEP_TIMER_CHAN);
148
     return timer_get_compare(STEP_TIMER_DEV, STEP_TIMER_CHAN);

+ 5
- 5
Marlin/src/HAL/HAL_STM32F7/HAL_timers_STM32F7.cpp View File

117
   ((void(*)(void))timerConfig[1].callback)();
117
   ((void(*)(void))timerConfig[1].callback)();
118
 }
118
 }
119
 
119
 
120
-void HAL_timer_set_count(const uint8_t timer_num, const uint32_t count) {
121
-  __HAL_TIM_SetAutoreload(&timerConfig[timer_num].timerdef, count);
120
+void HAL_timer_set_compare(const uint8_t timer_num, const uint32_t compare) {
121
+  __HAL_TIM_SetAutoreload(&timerConfig[timer_num].timerdef, compare);
122
 }
122
 }
123
 
123
 
124
-void HAL_timer_set_current_count(const uint8_t timer_num, const uint32_t count) {
124
+void HAL_timer_set_count(const uint8_t timer_num, const uint32_t count) {
125
   __HAL_TIM_SetAutoreload(&timerConfig[timer_num].timerdef, count);
125
   __HAL_TIM_SetAutoreload(&timerConfig[timer_num].timerdef, count);
126
 }
126
 }
127
 
127
 
133
   HAL_NVIC_DisableIRQ(timerConfig[timer_num].IRQ_Id);
133
   HAL_NVIC_DisableIRQ(timerConfig[timer_num].IRQ_Id);
134
 }
134
 }
135
 
135
 
136
-hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
136
+hal_timer_t HAL_timer_get_compare(const uint8_t timer_num) {
137
   return __HAL_TIM_GetAutoreload(&timerConfig[timer_num].timerdef);
137
   return __HAL_TIM_GetAutoreload(&timerConfig[timer_num].timerdef);
138
 }
138
 }
139
 
139
 
140
-uint32_t HAL_timer_get_current_count(const uint8_t timer_num) {
140
+uint32_t HAL_timer_get_count(const uint8_t timer_num) {
141
   return __HAL_TIM_GetCounter(&timerConfig[timer_num].timerdef);
141
   return __HAL_TIM_GetCounter(&timerConfig[timer_num].timerdef);
142
 }
142
 }
143
 
143
 

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

91
 void HAL_timer_enable_interrupt(const uint8_t timer_num);
91
 void HAL_timer_enable_interrupt(const uint8_t timer_num);
92
 void HAL_timer_disable_interrupt(const uint8_t timer_num);
92
 void HAL_timer_disable_interrupt(const uint8_t timer_num);
93
 
93
 
94
-void HAL_timer_set_count(const uint8_t timer_num, const uint32_t count);
95
-hal_timer_t HAL_timer_get_count(const uint8_t timer_num);
96
-uint32_t HAL_timer_get_current_count(const uint8_t timer_num);
94
+void HAL_timer_set_compare(const uint8_t timer_num, const uint32_t compare);
95
+hal_timer_t HAL_timer_get_compare(const uint8_t timer_num);
96
+uint32_t HAL_timer_get_count(const uint8_t timer_num);
97
 
97
 
98
-void HAL_timer_set_current_count(const uint8_t timer_num, const uint32_t count); // New
99
-/*FORCE_INLINE static void HAL_timer_set_current_count(const uint8_t timer_num, const hal_timer_t count) {
98
+void HAL_timer_set_count(const uint8_t timer_num, const uint32_t count); // New
99
+/*FORCE_INLINE static void HAL_timer_set_count(const uint8_t timer_num, const hal_timer_t count) {
100
   // To do ??
100
   // To do ??
101
 }*/
101
 }*/
102
 
102
 

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

80
 
80
 
81
 void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
81
 void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
82
 
82
 
83
-FORCE_INLINE static void HAL_timer_set_count(const uint8_t timer_num, const hal_timer_t count) {
83
+FORCE_INLINE static void HAL_timer_set_compare(const uint8_t timer_num, const hal_timer_t compare) {
84
   switch (timer_num) {
84
   switch (timer_num) {
85
-    case 0: FTM0_C0V = count; break;
86
-    case 1: FTM1_C0V = count; break;
85
+    case 0: FTM0_C0V = compare; break;
86
+    case 1: FTM1_C0V = compare; break;
87
   }
87
   }
88
 }
88
 }
89
 
89
 
90
-FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
90
+FORCE_INLINE static hal_timer_t HAL_timer_get_compare(const uint8_t timer_num) {
91
   switch (timer_num) {
91
   switch (timer_num) {
92
     case 0: return FTM0_C0V;
92
     case 0: return FTM0_C0V;
93
     case 1: return FTM1_C0V;
93
     case 1: return FTM1_C0V;
95
   return 0;
95
   return 0;
96
 }
96
 }
97
 
97
 
98
-FORCE_INLINE static void HAL_timer_set_current_count(const uint8_t timer_num, const hal_timer_t count) {
98
+FORCE_INLINE static void HAL_timer_set_count(const uint8_t timer_num, const hal_timer_t count) {
99
   switch (timer_num) {
99
   switch (timer_num) {
100
     case 0: FTM0_CNT = count;
100
     case 0: FTM0_CNT = count;
101
     case 1: FTM1_CNT = count;
101
     case 1: FTM1_CNT = count;
102
   }
102
   }
103
 }
103
 }
104
 
104
 
105
-FORCE_INLINE static hal_timer_t HAL_timer_get_current_count(const uint8_t timer_num) {
105
+FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
106
   switch (timer_num) {
106
   switch (timer_num) {
107
     case 0: return FTM0_CNT;
107
     case 0: return FTM0_CNT;
108
     case 1: return FTM1_CNT;
108
     case 1: return FTM1_CNT;

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

371
 
371
 
372
     #if DISABLED(LIN_ADVANCE)
372
     #if DISABLED(LIN_ADVANCE)
373
       #ifdef CPU_32_BIT
373
       #ifdef CPU_32_BIT
374
-        HAL_timer_set_count(STEP_TIMER_NUM, ocr_val);
374
+        HAL_timer_set_compare(STEP_TIMER_NUM, ocr_val);
375
       #else
375
       #else
376
         NOLESS(OCR1A, TCNT1 + 16);
376
         NOLESS(OCR1A, TCNT1 + 16);
377
       #endif
377
       #endif
560
      * 10µs = 160 or 200 cycles.
560
      * 10µs = 160 or 200 cycles.
561
      */
561
      */
562
     #if EXTRA_CYCLES_XYZE > 20
562
     #if EXTRA_CYCLES_XYZE > 20
563
-      hal_timer_t pulse_start = HAL_timer_get_current_count(PULSE_TIMER_NUM);
563
+      hal_timer_t pulse_start = HAL_timer_get_count(PULSE_TIMER_NUM);
564
     #endif
564
     #endif
565
 
565
 
566
     #if HAS_X_STEP
566
     #if HAS_X_STEP
592
 
592
 
593
     // For minimum pulse time wait before stopping pulses
593
     // For minimum pulse time wait before stopping pulses
594
     #if EXTRA_CYCLES_XYZE > 20
594
     #if EXTRA_CYCLES_XYZE > 20
595
-      while (EXTRA_CYCLES_XYZE > (uint32_t)(HAL_timer_get_current_count(PULSE_TIMER_NUM) - pulse_start) * (PULSE_TIMER_PRESCALE)) { /* nada */ }
596
-      pulse_start = HAL_timer_get_current_count(PULSE_TIMER_NUM);
595
+      while (EXTRA_CYCLES_XYZE > (uint32_t)(HAL_timer_get_count(PULSE_TIMER_NUM) - pulse_start) * (PULSE_TIMER_PRESCALE)) { /* nada */ }
596
+      pulse_start = HAL_timer_get_count(PULSE_TIMER_NUM);
597
     #elif EXTRA_CYCLES_XYZE > 0
597
     #elif EXTRA_CYCLES_XYZE > 0
598
       DELAY_NOPS(EXTRA_CYCLES_XYZE);
598
       DELAY_NOPS(EXTRA_CYCLES_XYZE);
599
     #endif
599
     #endif
633
 
633
 
634
     // For minimum pulse time wait after stopping pulses also
634
     // For minimum pulse time wait after stopping pulses also
635
     #if EXTRA_CYCLES_XYZE > 20
635
     #if EXTRA_CYCLES_XYZE > 20
636
-      if (i) while (EXTRA_CYCLES_XYZE > (uint32_t)(HAL_timer_get_current_count(PULSE_TIMER_NUM) - pulse_start) * (PULSE_TIMER_PRESCALE)) { /* nada */ }
636
+      if (i) while (EXTRA_CYCLES_XYZE > (uint32_t)(HAL_timer_get_count(PULSE_TIMER_NUM) - pulse_start) * (PULSE_TIMER_PRESCALE)) { /* nada */ }
637
     #elif EXTRA_CYCLES_XYZE > 0
637
     #elif EXTRA_CYCLES_XYZE > 0
638
       if (i) DELAY_NOPS(EXTRA_CYCLES_XYZE);
638
       if (i) DELAY_NOPS(EXTRA_CYCLES_XYZE);
639
     #endif
639
     #endif
750
   #if DISABLED(LIN_ADVANCE)
750
   #if DISABLED(LIN_ADVANCE)
751
     #ifdef CPU_32_BIT
751
     #ifdef CPU_32_BIT
752
       // Make sure stepper interrupt does not monopolise CPU by adjusting count to give about 8 us room
752
       // Make sure stepper interrupt does not monopolise CPU by adjusting count to give about 8 us room
753
-      hal_timer_t stepper_timer_count = HAL_timer_get_count(STEP_TIMER_NUM),
754
-                  stepper_timer_current_count = HAL_timer_get_current_count(STEP_TIMER_NUM) + 8 * HAL_TICKS_PER_US;
755
-      HAL_timer_set_count(STEP_TIMER_NUM, max(stepper_timer_count, stepper_timer_current_count));
753
+      hal_timer_t stepper_timer_count = HAL_timer_get_compare(STEP_TIMER_NUM),
754
+                  stepper_timer_current_count = HAL_timer_get_count(STEP_TIMER_NUM) + 8 * HAL_TICKS_PER_US;
755
+      HAL_timer_set_compare(STEP_TIMER_NUM, max(stepper_timer_count, stepper_timer_current_count));
756
     #else
756
     #else
757
       NOLESS(OCR1A, TCNT1 + 16);
757
       NOLESS(OCR1A, TCNT1 + 16);
758
     #endif
758
     #endif
814
     for (uint8_t i = step_loops; i--;) {
814
     for (uint8_t i = step_loops; i--;) {
815
 
815
 
816
       #if EXTRA_CYCLES_E > 20
816
       #if EXTRA_CYCLES_E > 20
817
-        hal_timer_t pulse_start = HAL_timer_get_current_count(PULSE_TIMER_NUM);
817
+        hal_timer_t pulse_start = HAL_timer_get_count(PULSE_TIMER_NUM);
818
       #endif
818
       #endif
819
 
819
 
820
       START_E_PULSE(0);
820
       START_E_PULSE(0);
833
 
833
 
834
       // For minimum pulse time wait before stopping pulses
834
       // For minimum pulse time wait before stopping pulses
835
       #if EXTRA_CYCLES_E > 20
835
       #if EXTRA_CYCLES_E > 20
836
-        while (EXTRA_CYCLES_E > (hal_timer_t)(HAL_timer_get_current_count(PULSE_TIMER_NUM) - pulse_start) * (PULSE_TIMER_PRESCALE)) { /* nada */ }
837
-        pulse_start = HAL_timer_get_current_count(PULSE_TIMER_NUM);
836
+        while (EXTRA_CYCLES_E > (hal_timer_t)(HAL_timer_get_count(PULSE_TIMER_NUM) - pulse_start) * (PULSE_TIMER_PRESCALE)) { /* nada */ }
837
+        pulse_start = HAL_timer_get_count(PULSE_TIMER_NUM);
838
       #elif EXTRA_CYCLES_E > 0
838
       #elif EXTRA_CYCLES_E > 0
839
         DELAY_NOPS(EXTRA_CYCLES_E);
839
         DELAY_NOPS(EXTRA_CYCLES_E);
840
       #endif
840
       #endif
855
 
855
 
856
       // For minimum pulse time wait before looping
856
       // For minimum pulse time wait before looping
857
       #if EXTRA_CYCLES_E > 20
857
       #if EXTRA_CYCLES_E > 20
858
-        if (i) while (EXTRA_CYCLES_E > (hal_timer_t)(HAL_timer_get_current_count(PULSE_TIMER_NUM) - pulse_start) * (PULSE_TIMER_PRESCALE)) { /* nada */ }
858
+        if (i) while (EXTRA_CYCLES_E > (hal_timer_t)(HAL_timer_get_count(PULSE_TIMER_NUM) - pulse_start) * (PULSE_TIMER_PRESCALE)) { /* nada */ }
859
       #elif EXTRA_CYCLES_E > 0
859
       #elif EXTRA_CYCLES_E > 0
860
         if (i) DELAY_NOPS(EXTRA_CYCLES_E);
860
         if (i) DELAY_NOPS(EXTRA_CYCLES_E);
861
       #endif
861
       #endif
878
     // Is the next advance ISR scheduled before the next main ISR?
878
     // Is the next advance ISR scheduled before the next main ISR?
879
     if (nextAdvanceISR <= nextMainISR) {
879
     if (nextAdvanceISR <= nextMainISR) {
880
       // Set up the next interrupt
880
       // Set up the next interrupt
881
-      HAL_timer_set_count(STEP_TIMER_NUM, nextAdvanceISR);
881
+      HAL_timer_set_compare(STEP_TIMER_NUM, nextAdvanceISR);
882
       // New interval for the next main ISR
882
       // New interval for the next main ISR
883
       if (nextMainISR) nextMainISR -= nextAdvanceISR;
883
       if (nextMainISR) nextMainISR -= nextAdvanceISR;
884
       // Will call Stepper::advance_isr on the next interrupt
884
       // Will call Stepper::advance_isr on the next interrupt
886
     }
886
     }
887
     else {
887
     else {
888
       // The next main ISR comes first
888
       // The next main ISR comes first
889
-      HAL_timer_set_count(STEP_TIMER_NUM, nextMainISR);
889
+      HAL_timer_set_compare(STEP_TIMER_NUM, nextMainISR);
890
       // New interval for the next advance ISR, if any
890
       // New interval for the next advance ISR, if any
891
       if (nextAdvanceISR && nextAdvanceISR != ADV_NEVER)
891
       if (nextAdvanceISR && nextAdvanceISR != ADV_NEVER)
892
         nextAdvanceISR -= nextMainISR;
892
         nextAdvanceISR -= nextMainISR;
897
     // Don't run the ISR faster than possible
897
     // Don't run the ISR faster than possible
898
     #ifdef CPU_32_BIT
898
     #ifdef CPU_32_BIT
899
       // Make sure stepper interrupt does not monopolise CPU by adjusting count to give about 8 us room
899
       // Make sure stepper interrupt does not monopolise CPU by adjusting count to give about 8 us room
900
-      uint32_t stepper_timer_count = HAL_timer_get_count(STEP_TIMER_NUM),
901
-               stepper_timer_current_count = HAL_timer_get_current_count(STEP_TIMER_NUM) + 8 * HAL_TICKS_PER_US;
902
-      HAL_timer_set_count(STEP_TIMER_NUM, max(stepper_timer_count, stepper_timer_current_count));
900
+      uint32_t stepper_timer_count = HAL_timer_get_compare(STEP_TIMER_NUM),
901
+               stepper_timer_current_count = HAL_timer_get_count(STEP_TIMER_NUM) + 8 * HAL_TICKS_PER_US;
902
+      HAL_timer_set_compare(STEP_TIMER_NUM, max(stepper_timer_count, stepper_timer_current_count));
903
     #else
903
     #else
904
       NOLESS(OCR1A, TCNT1 + 16);
904
       NOLESS(OCR1A, TCNT1 + 16);
905
     #endif
905
     #endif
1304
   #define _APPLY_DIR(AXIS, INVERT) AXIS ##_APPLY_DIR(INVERT, true)
1304
   #define _APPLY_DIR(AXIS, INVERT) AXIS ##_APPLY_DIR(INVERT, true)
1305
 
1305
 
1306
   #if EXTRA_CYCLES_BABYSTEP > 20
1306
   #if EXTRA_CYCLES_BABYSTEP > 20
1307
-    #define _SAVE_START const hal_timer_t pulse_start = HAL_timer_get_current_count(STEP_TIMER_NUM)
1308
-    #define _PULSE_WAIT while (EXTRA_CYCLES_BABYSTEP > (uint32_t)(HAL_timer_get_current_count(STEP_TIMER_NUM) - pulse_start) * (PULSE_TIMER_PRESCALE)) { /* nada */ }
1307
+    #define _SAVE_START const hal_timer_t pulse_start = HAL_timer_get_count(STEP_TIMER_NUM)
1308
+    #define _PULSE_WAIT while (EXTRA_CYCLES_BABYSTEP > (uint32_t)(HAL_timer_get_count(STEP_TIMER_NUM) - pulse_start) * (PULSE_TIMER_PRESCALE)) { /* nada */ }
1309
   #else
1309
   #else
1310
     #define _SAVE_START NOOP
1310
     #define _SAVE_START NOOP
1311
     #if EXTRA_CYCLES_BABYSTEP > 0
1311
     #if EXTRA_CYCLES_BABYSTEP > 0

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

108
                                                  // i.e., the current amount of pressure applied
108
                                                  // i.e., the current amount of pressure applied
109
                                                  // to the spring (=filament).
109
                                                  // to the spring (=filament).
110
     #else
110
     #else
111
-      #define _NEXT_ISR(T) HAL_timer_set_count(STEP_TIMER_NUM, T);
111
+      #define _NEXT_ISR(T) HAL_timer_set_compare(STEP_TIMER_NUM, T);
112
     #endif // LIN_ADVANCE
112
     #endif // LIN_ADVANCE
113
 
113
 
114
     static long acceleration_time, deceleration_time;
114
     static long acceleration_time, deceleration_time;

Loading…
Cancel
Save