瀏覽代碼

Fix SAMD51 Step Timer (#17692)

Giuliano Zaro 5 年之前
父節點
當前提交
d7f90c36df
沒有連結到貢獻者的電子郵件帳戶。
共有 2 個檔案被更改,包括 7 行新增6 行删除
  1. 4
    3
      Marlin/src/HAL/SAMD51/timers.cpp
  2. 3
    3
      Marlin/src/HAL/SAMD51/timers.h

+ 4
- 3
Marlin/src/HAL/SAMD51/timers.cpp 查看文件

121
     tc->COUNT32.CTRLA.bit.SWRST = true;
121
     tc->COUNT32.CTRLA.bit.SWRST = true;
122
     SYNC(tc->COUNT32.SYNCBUSY.bit.SWRST);
122
     SYNC(tc->COUNT32.SYNCBUSY.bit.SWRST);
123
 
123
 
124
-    // Wave mode, reset counter on overflow on 0 (I use count down to prevent double buffer use)
124
+    // Wave mode, reset counter on compare match
125
     tc->COUNT32.WAVE.reg = TC_WAVE_WAVEGEN_MFRQ;
125
     tc->COUNT32.WAVE.reg = TC_WAVE_WAVEGEN_MFRQ;
126
     tc->COUNT32.CTRLA.reg = TC_CTRLA_MODE_COUNT32 | TC_CTRLA_PRESCALER_DIV1;
126
     tc->COUNT32.CTRLA.reg = TC_CTRLA_MODE_COUNT32 | TC_CTRLA_PRESCALER_DIV1;
127
-    tc->COUNT32.CTRLBSET.reg = TC_CTRLBCLR_DIR;
127
+    tc->COUNT32.CTRLBCLR.reg = TC_CTRLBCLR_DIR;
128
     SYNC(tc->COUNT32.SYNCBUSY.bit.CTRLB);
128
     SYNC(tc->COUNT32.SYNCBUSY.bit.CTRLB);
129
 
129
 
130
     // Set compare value
130
     // Set compare value
131
-    tc->COUNT32.COUNT.reg = tc->COUNT32.CC[0].reg = (HAL_TIMER_RATE) / frequency;
131
+    tc->COUNT32.CC[0].reg = (HAL_TIMER_RATE) / frequency;
132
+    tc->COUNT32.COUNT.reg = 0;
132
 
133
 
133
     // Enable interrupt on compare
134
     // Enable interrupt on compare
134
     tc->COUNT32.INTFLAG.reg = TC_INTFLAG_OVF;   // reset pending interrupt
135
     tc->COUNT32.INTFLAG.reg = TC_INTFLAG_OVF;   // reset pending interrupt

+ 3
- 3
Marlin/src/HAL/SAMD51/timers.h 查看文件

97
 FORCE_INLINE static void HAL_timer_set_compare(const uint8_t timer_num, const hal_timer_t compare) {
97
 FORCE_INLINE static void HAL_timer_set_compare(const uint8_t timer_num, const hal_timer_t compare) {
98
   // Should never be called with timer RTC_TIMER_NUM
98
   // Should never be called with timer RTC_TIMER_NUM
99
   Tc * const tc = TimerConfig[timer_num].pTc;
99
   Tc * const tc = TimerConfig[timer_num].pTc;
100
-  tc->COUNT32.CC[0].reg = HAL_TIMER_TYPE_MAX - compare;
100
+  tc->COUNT32.CC[0].reg = compare;
101
 }
101
 }
102
 
102
 
103
 FORCE_INLINE static hal_timer_t HAL_timer_get_compare(const uint8_t timer_num) {
103
 FORCE_INLINE static hal_timer_t HAL_timer_get_compare(const uint8_t timer_num) {
104
   // Should never be called with timer RTC_TIMER_NUM
104
   // Should never be called with timer RTC_TIMER_NUM
105
   Tc * const tc = TimerConfig[timer_num].pTc;
105
   Tc * const tc = TimerConfig[timer_num].pTc;
106
-  return (hal_timer_t)(HAL_TIMER_TYPE_MAX - tc->COUNT32.CC[0].reg);
106
+  return (hal_timer_t)tc->COUNT32.CC[0].reg;
107
 }
107
 }
108
 
108
 
109
 FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
109
 FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
111
   Tc * const tc = TimerConfig[timer_num].pTc;
111
   Tc * const tc = TimerConfig[timer_num].pTc;
112
   tc->COUNT32.CTRLBSET.reg = TC_CTRLBCLR_CMD_READSYNC;
112
   tc->COUNT32.CTRLBSET.reg = TC_CTRLBCLR_CMD_READSYNC;
113
   SYNC(tc->COUNT32.SYNCBUSY.bit.CTRLB || tc->COUNT32.SYNCBUSY.bit.COUNT);
113
   SYNC(tc->COUNT32.SYNCBUSY.bit.CTRLB || tc->COUNT32.SYNCBUSY.bit.COUNT);
114
-  return HAL_TIMER_TYPE_MAX - tc->COUNT32.COUNT.reg;
114
+  return tc->COUNT32.COUNT.reg;
115
 }
115
 }
116
 
116
 
117
 void HAL_timer_enable_interrupt(const uint8_t timer_num);
117
 void HAL_timer_enable_interrupt(const uint8_t timer_num);

Loading…
取消
儲存