Pārlūkot izejas kodu

Fix SAMD51 Step Timer (#17692)

Giuliano Zaro 5 gadus atpakaļ
vecāks
revīzija
d7f90c36df
Revīzijas autora e-pasta adrese nav piesaistīta nevienam kontam
2 mainītis faili ar 7 papildinājumiem un 6 dzēšanām
  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 Parādīt failu

@@ -121,14 +121,15 @@ void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
121 121
     tc->COUNT32.CTRLA.bit.SWRST = true;
122 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 125
     tc->COUNT32.WAVE.reg = TC_WAVE_WAVEGEN_MFRQ;
126 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 128
     SYNC(tc->COUNT32.SYNCBUSY.bit.CTRLB);
129 129
 
130 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 134
     // Enable interrupt on compare
134 135
     tc->COUNT32.INTFLAG.reg = TC_INTFLAG_OVF;   // reset pending interrupt

+ 3
- 3
Marlin/src/HAL/SAMD51/timers.h Parādīt failu

@@ -97,13 +97,13 @@ void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
97 97
 FORCE_INLINE static void HAL_timer_set_compare(const uint8_t timer_num, const hal_timer_t compare) {
98 98
   // Should never be called with timer RTC_TIMER_NUM
99 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 103
 FORCE_INLINE static hal_timer_t HAL_timer_get_compare(const uint8_t timer_num) {
104 104
   // Should never be called with timer RTC_TIMER_NUM
105 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 109
 FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
@@ -111,7 +111,7 @@ FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
111 111
   Tc * const tc = TimerConfig[timer_num].pTc;
112 112
   tc->COUNT32.CTRLBSET.reg = TC_CTRLBCLR_CMD_READSYNC;
113 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 117
 void HAL_timer_enable_interrupt(const uint8_t timer_num);

Notiek ielāde…
Atcelt
Saglabāt