|
@@ -124,7 +124,7 @@ extern "C" {
|
124
|
124
|
|
125
|
125
|
#define STEP_TIMER_NUM 1
|
126
|
126
|
#define TEMP_TIMER_NUM 0
|
127
|
|
-#define PULSE_TIMER_NUM TEMP_TIMER_NUM
|
|
127
|
+#define PULSE_TIMER_NUM STEP_TIMER_NUM
|
128
|
128
|
|
129
|
129
|
#define HAL_STEPPER_TIMER_RATE HAL_TIMER_RATE
|
130
|
130
|
#define HAL_TICKS_PER_US ((HAL_STEPPER_TIMER_RATE) / 1000000) // Cannot be of type double
|
|
@@ -139,7 +139,7 @@ extern "C" {
|
139
|
139
|
#define TIMER_OCR_0 OCR0A
|
140
|
140
|
#define TIMER_COUNTER_0 TCNT0
|
141
|
141
|
|
142
|
|
-#define PULSE_TIMER_PRESCALE 8
|
|
142
|
+#define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE
|
143
|
143
|
|
144
|
144
|
#define ENABLE_STEPPER_DRIVER_INTERRUPT() SBI(TIMSK1, OCIE1A)
|
145
|
145
|
#define DISABLE_STEPPER_DRIVER_INTERRUPT() CBI(TIMSK1, OCIE1A)
|
|
@@ -149,7 +149,36 @@ extern "C" {
|
149
|
149
|
#define DISABLE_TEMPERATURE_INTERRUPT() CBI(TIMSK0, OCIE0B)
|
150
|
150
|
#define TEMPERATURE_ISR_ENABLED() TEST(TIMSK0, OCIE0B)
|
151
|
151
|
|
152
|
|
-#define HAL_timer_start(timer_num, frequency)
|
|
152
|
+FORCE_INLINE void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
|
|
153
|
+ UNUSED(frequency);
|
|
154
|
+ switch (timer_num) {
|
|
155
|
+ case STEP_TIMER_NUM:
|
|
156
|
+ // waveform generation = 0100 = CTC
|
|
157
|
+ SET_WGM(1, CTC_OCRnA);
|
|
158
|
+
|
|
159
|
+ // output mode = 00 (disconnected)
|
|
160
|
+ SET_COMA(1, NORMAL);
|
|
161
|
+
|
|
162
|
+ // Set the timer pre-scaler
|
|
163
|
+ // Generally we use a divider of 8, resulting in a 2MHz timer
|
|
164
|
+ // frequency on a 16MHz MCU. If you are going to change this, be
|
|
165
|
+ // sure to regenerate speed_lookuptable.h with
|
|
166
|
+ // create_speed_lookuptable.py
|
|
167
|
+ SET_CS(1, PRESCALER_8); // CS 2 = 1/8 prescaler
|
|
168
|
+
|
|
169
|
+ // Init Stepper ISR to 122 Hz for quick starting
|
|
170
|
+ // (F_CPU) / (STEPPER_TIMER_PRESCALE) / frequency
|
|
171
|
+ OCR1A = 0x4000;
|
|
172
|
+ TCNT1 = 0;
|
|
173
|
+ break;
|
|
174
|
+
|
|
175
|
+ case TEMP_TIMER_NUM:
|
|
176
|
+ // Use timer0 for temperature measurement
|
|
177
|
+ // Interleave temperature interrupt with millies interrupt
|
|
178
|
+ OCR0B = 128;
|
|
179
|
+ break;
|
|
180
|
+ }
|
|
181
|
+}
|
153
|
182
|
|
154
|
183
|
#define _CAT(a, ...) a ## __VA_ARGS__
|
155
|
184
|
#define HAL_timer_set_compare(timer, compare) (_CAT(TIMER_OCR_, timer) = compare)
|