|
@ -67,7 +67,7 @@ typedef uint16_t hal_timer_t; |
|
|
#define HAL_TIMER_RATE (F_CPU) // frequency of timers peripherals
|
|
|
#define HAL_TIMER_RATE (F_CPU) // frequency of timers peripherals
|
|
|
#define STEPPER_TIMER_PRESCALE 18 // prescaler for setting stepper timer, 4Mhz
|
|
|
#define STEPPER_TIMER_PRESCALE 18 // prescaler for setting stepper timer, 4Mhz
|
|
|
#define HAL_STEPPER_TIMER_RATE (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE) // frequency of stepper timer (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE)
|
|
|
#define HAL_STEPPER_TIMER_RATE (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE) // frequency of stepper timer (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE)
|
|
|
#define HAL_TICKS_PER_US ((HAL_STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per us
|
|
|
#define HAL_TICKS_PER_US ((HAL_STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs
|
|
|
|
|
|
|
|
|
#define PULSE_TIMER_NUM STEP_TIMER_NUM |
|
|
#define PULSE_TIMER_NUM STEP_TIMER_NUM |
|
|
#define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE |
|
|
#define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE |
|
@ -75,6 +75,8 @@ typedef uint16_t hal_timer_t; |
|
|
#define TEMP_TIMER_PRESCALE 1000 // prescaler for setting Temp timer, 72Khz
|
|
|
#define TEMP_TIMER_PRESCALE 1000 // prescaler for setting Temp timer, 72Khz
|
|
|
#define TEMP_TIMER_FREQUENCY 100 // temperature interrupt frequency
|
|
|
#define TEMP_TIMER_FREQUENCY 100 // temperature interrupt frequency
|
|
|
|
|
|
|
|
|
|
|
|
#define STEP_TIMER_MIN_INTERVAL 8 // minimum time in µs between stepper interrupts
|
|
|
|
|
|
|
|
|
#define ENABLE_STEPPER_DRIVER_INTERRUPT() timer_enable_irq(STEP_TIMER_DEV, STEP_TIMER_CHAN) |
|
|
#define ENABLE_STEPPER_DRIVER_INTERRUPT() timer_enable_irq(STEP_TIMER_DEV, STEP_TIMER_CHAN) |
|
|
#define DISABLE_STEPPER_DRIVER_INTERRUPT() timer_disable_irq(STEP_TIMER_DEV, STEP_TIMER_CHAN) |
|
|
#define DISABLE_STEPPER_DRIVER_INTERRUPT() timer_disable_irq(STEP_TIMER_DEV, STEP_TIMER_CHAN) |
|
|
#define STEPPER_ISR_ENABLED() HAL_timer_interrupt_enabled(STEP_TIMER_NUM) |
|
|
#define STEPPER_ISR_ENABLED() HAL_timer_interrupt_enabled(STEP_TIMER_NUM) |
|
@ -152,6 +154,11 @@ FORCE_INLINE static hal_timer_t HAL_timer_get_compare(const uint8_t timer_num) { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
FORCE_INLINE static void HAL_timer_restrain(const uint8_t timer_num, const uint16_t interval_µs) { |
|
|
|
|
|
const hal_timer_t mincmp = HAL_timer_get_count(timer_num) + interval_µs * HAL_TICKS_PER_US; |
|
|
|
|
|
if (HAL_timer_get_compare(timer_num) < mincmp) HAL_timer_set_compare(timer_num, mincmp); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
FORCE_INLINE static void HAL_timer_isr_prologue(const uint8_t timer_num) { |
|
|
FORCE_INLINE static void HAL_timer_isr_prologue(const uint8_t timer_num) { |
|
|
switch (timer_num) { |
|
|
switch (timer_num) { |
|
|
case STEP_TIMER_NUM: |
|
|
case STEP_TIMER_NUM: |
|
|