Browse Source

Allow setting current timer counter

Scott Lahteine 7 years ago
parent
commit
6149b82119

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

100
 
100
 
101
 
101
 
102
 // timers
102
 // timers
103
-#define STEP_TIMER_NUM          OCR1A
104
-#define TEMP_TIMER_NUM          0
105
-#define TEMP_TIMER_FREQUENCY    (F_CPU / 64.0 / 256.0)
106
-
107
 #define HAL_TIMER_RATE          ((F_CPU) / 8)    // i.e., 2MHz or 2.5MHz
103
 #define HAL_TIMER_RATE          ((F_CPU) / 8)    // i.e., 2MHz or 2.5MHz
104
+#define HAL_TICKS_PER_US        ((HAL_STEPPER_TIMER_RATE) / 1000000) // Cannot be of type double
105
+
106
+#define TEMP_TIMER_FREQUENCY    ((F_CPU) / 64.0 / 256.0)
107
+
108
 #define HAL_STEPPER_TIMER_RATE  HAL_TIMER_RATE
108
 #define HAL_STEPPER_TIMER_RATE  HAL_TIMER_RATE
109
 #define STEPPER_TIMER_PRESCALE  8
109
 #define STEPPER_TIMER_PRESCALE  8
110
-#define HAL_TICKS_PER_US        ((HAL_STEPPER_TIMER_RATE) / 1000000) // Cannot be of type double
111
 
110
 
112
-#define PULSE_TIMER_NUM         TEMP_TIMER_NUM
111
+#define STEP_TIMER_NUM          1
112
+#define TIMER_OCR_1             OCR1A
113
+#define TIMER_COUNTER_1         TCNT1
114
+
115
+#define TEMP_TIMER_NUM          0
116
+#define TIMER_OCR_0             OCR0A
113
 #define TIMER_COUNTER_0         TCNT0
117
 #define TIMER_COUNTER_0         TCNT0
118
+
119
+#define PULSE_TIMER_NUM         TEMP_TIMER_NUM
114
 #define PULSE_TIMER_PRESCALE    8
120
 #define PULSE_TIMER_PRESCALE    8
115
 
121
 
116
 #define ENABLE_STEPPER_DRIVER_INTERRUPT()  SBI(TIMSK1, OCIE1A)
122
 #define ENABLE_STEPPER_DRIVER_INTERRUPT()  SBI(TIMSK1, OCIE1A)
119
 #define ENABLE_TEMPERATURE_INTERRUPT()  SBI(TIMSK0, OCIE0B)
125
 #define ENABLE_TEMPERATURE_INTERRUPT()  SBI(TIMSK0, OCIE0B)
120
 #define DISABLE_TEMPERATURE_INTERRUPT() CBI(TIMSK0, OCIE0B)
126
 #define DISABLE_TEMPERATURE_INTERRUPT() CBI(TIMSK0, OCIE0B)
121
 
127
 
122
-//void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
123
-#define HAL_timer_start(timer_num,frequency)
124
-
125
-#define HAL_timer_get_count(timer) timer
126
-
127
-//void HAL_timer_set_count(const uint8_t timer_num, const uint16_t count);
128
-#define HAL_timer_set_count(timer, count) timer = (count)
128
+#define HAL_timer_start(timer_num, frequency)
129
 
129
 
130
-#define HAL_timer_get_current_count(timer) timer
130
+#define _CAT(a, ...) a ## __VA_ARGS__
131
+#define HAL_timer_set_count(timer, count) (_CAT(TIMER_OCR_, timer) = count)
132
+#define HAL_timer_get_count(timer) _CAT(TIMER_OCR_, timer)
133
+#define HAL_timer_set_current_count(timer, count) (_CAT(TIMER_COUNTER_, timer) = count)
134
+#define HAL_timer_get_current_count(timer) _CAT(TIMER_COUNTER_, timer)
131
 
135
 
132
-//void HAL_timer_isr_prologue(const uint8_t timer_num);
133
 #define HAL_timer_isr_prologue(timer_num)
136
 #define HAL_timer_isr_prologue(timer_num)
134
 
137
 
135
 #define HAL_STEP_TIMER_ISR ISR(TIMER1_COMPA_vect)
138
 #define HAL_STEP_TIMER_ISR ISR(TIMER1_COMPA_vect)

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

100
   return pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_RC;
100
   return pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_RC;
101
 }
101
 }
102
 
102
 
103
+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
+  pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_CV = count;
106
+}
107
+
103
 FORCE_INLINE static hal_timer_t HAL_timer_get_current_count(const uint8_t timer_num) {
108
 FORCE_INLINE static hal_timer_t HAL_timer_get_current_count(const uint8_t timer_num) {
104
   const tTimerConfig *pConfig = &TimerConfig[timer_num];
109
   const tTimerConfig *pConfig = &TimerConfig[timer_num];
105
   return pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_CV;
110
   return pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_CV;

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

103
   return 0;
103
   return 0;
104
 }
104
 }
105
 
105
 
106
+FORCE_INLINE static void HAL_timer_set_current_count(const uint8_t timer_num, const hal_timer_t count) {
107
+  switch (timer_num) {
108
+    case 0: LPC_TIM0->TC = count; break;
109
+    case 1: LPC_TIM1->TC = count; break;
110
+  }
111
+}
112
+
106
 FORCE_INLINE static hal_timer_t HAL_timer_get_current_count(const uint8_t timer_num) {
113
 FORCE_INLINE static hal_timer_t HAL_timer_get_current_count(const uint8_t timer_num) {
107
   switch (timer_num) {
114
   switch (timer_num) {
108
     case 0: return LPC_TIM0->TC;
115
     case 0: return LPC_TIM0->TC;

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

144
   return temp;
144
   return temp;
145
 }
145
 }
146
 
146
 
147
+FORCE_INLINE static void HAL_timer_set_current_count(const uint8_t timer_num, const hal_timer_t count) {
148
+  switch (timer_num) {
149
+    case STEP_TIMER_NUM: StepperTimer.setCount(count); break;
150
+    case TEMP_TIMER_NUM: TempTimer.setCount(count); break;
151
+  }
152
+}
153
+
147
 FORCE_INLINE static hal_timer_t HAL_timer_get_current_count(const uint8_t timer_num) {
154
 FORCE_INLINE static hal_timer_t HAL_timer_get_current_count(const uint8_t timer_num) {
148
   hal_timer_t temp;
155
   hal_timer_t temp;
149
   switch (timer_num) {
156
   switch (timer_num) {
160
   return temp;
167
   return temp;
161
 }
168
 }
162
 
169
 
163
-
164
 //void HAL_timer_isr_prologue (const uint8_t timer_num);
170
 //void HAL_timer_isr_prologue (const uint8_t timer_num);
165
 
171
 
166
 FORCE_INLINE static void HAL_timer_isr_prologue(const uint8_t timer_num) {
172
 FORCE_INLINE static void HAL_timer_isr_prologue(const uint8_t timer_num) {

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

93
   return 0;
93
   return 0;
94
 }
94
 }
95
 
95
 
96
+FORCE_INLINE static void HAL_timer_set_current_count(const uint8_t timer_num, const hal_timer_t count) {
97
+  switch (timer_num) {
98
+    case 0: FTM0_CNT = count;
99
+    case 1: FTM1_CNT = count;
100
+  }
101
+}
102
+
96
 FORCE_INLINE static hal_timer_t HAL_timer_get_current_count(const uint8_t timer_num) {
103
 FORCE_INLINE static hal_timer_t HAL_timer_get_current_count(const uint8_t timer_num) {
97
   switch (timer_num) {
104
   switch (timer_num) {
98
     case 0: return FTM0_CNT;
105
     case 0: return FTM0_CNT;

Loading…
Cancel
Save