STM32 timer simplification (#11995)
Prescalers aren't calculated for the given target frequency. Stepper timer should run at 2 Mhz and temperature timer at 72 Khz.
This commit is contained in:
parent
8daadd2c8c
commit
fcf6d127fd
@ -71,7 +71,7 @@ bool timers_initialised[NUM_HARDWARE_TIMERS] = {false};
|
||||
void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
|
||||
|
||||
if (!timers_initialised[timer_num]) {
|
||||
constexpr uint32_t step_prescaler = STEPPER_TIMER_PRESCALE - 1,
|
||||
uint32_t step_prescaler = STEPPER_TIMER_PRESCALE - 1,
|
||||
temp_prescaler = TEMP_TIMER_PRESCALE - 1;
|
||||
switch (timer_num) {
|
||||
case STEP_TIMER_NUM:
|
||||
|
@ -33,41 +33,33 @@
|
||||
|
||||
#define FORCE_INLINE __attribute__((always_inline)) inline
|
||||
|
||||
#define hal_timer_t uint32_t // TODO: One is 16-bit, one 32-bit - does this need to be checked?
|
||||
#define hal_timer_t uint32_t
|
||||
#define HAL_TIMER_TYPE_MAX 0xFFFF
|
||||
|
||||
#ifdef STM32F0xx
|
||||
|
||||
#define HAL_TIMER_RATE (HAL_RCC_GetSysClockFreq()) // frequency of timer peripherals
|
||||
#define TEMP_TIMER_PRESCALE 666 // prescaler for setting temperature timer, 72Khz
|
||||
#define STEPPER_TIMER_PRESCALE 24 // prescaler for setting stepper timer, 2Mhz
|
||||
#define HAL_TIMER_RATE (HAL_RCC_GetSysClockFreq()) // frequency of timer peripherals
|
||||
|
||||
#define STEP_TIMER 16
|
||||
#define TEMP_TIMER 17
|
||||
|
||||
#elif defined STM32F1xx
|
||||
|
||||
#define HAL_TIMER_RATE (HAL_RCC_GetPCLK2Freq()) // frequency of timer peripherals
|
||||
#define TEMP_TIMER_PRESCALE 1000 // prescaler for setting temperature timer, 72Khz
|
||||
#define STEPPER_TIMER_PRESCALE 36 // prescaler for setting stepper timer, 2Mhz.
|
||||
#define HAL_TIMER_RATE (HAL_RCC_GetPCLK2Freq()) // frequency of timer peripherals
|
||||
|
||||
#define STEP_TIMER 4
|
||||
#define TEMP_TIMER 2
|
||||
|
||||
#elif defined STM32F4xx
|
||||
|
||||
#define HAL_TIMER_RATE (HAL_RCC_GetPCLK2Freq()) // frequency of timer peripherals
|
||||
#define TEMP_TIMER_PRESCALE 2333 // prescaler for setting temperature timer, 72Khz
|
||||
#define STEPPER_TIMER_PRESCALE 84 // prescaler for setting stepper timer, 2Mhz
|
||||
#define HAL_TIMER_RATE (HAL_RCC_GetPCLK2Freq()) // frequency of timer peripherals
|
||||
|
||||
#define STEP_TIMER 4
|
||||
#define TEMP_TIMER 5
|
||||
|
||||
#elif defined STM32F7xx
|
||||
|
||||
#define HAL_TIMER_RATE (HAL_RCC_GetSysClockFreq()/2) // frequency of timer peripherals
|
||||
#define TEMP_TIMER_PRESCALE 1500 // prescaler for setting temperature timer, 72Khz
|
||||
#define STEPPER_TIMER_PRESCALE 54 // prescaler for setting stepper timer, 2Mhz.
|
||||
#define HAL_TIMER_RATE (HAL_RCC_GetSysClockFreq()/2) // frequency of timer peripherals
|
||||
|
||||
#define STEP_TIMER 5
|
||||
#define TEMP_TIMER 7
|
||||
@ -82,13 +74,16 @@
|
||||
#define TEMP_TIMER_NUM 1 // index of timer to use for temperature
|
||||
#define PULSE_TIMER_NUM STEP_TIMER_NUM
|
||||
|
||||
#define STEPPER_TIMER_RATE (HAL_TIMER_RATE / STEPPER_TIMER_PRESCALE) // frequency of stepper timer
|
||||
#define TEMP_TIMER_RATE 72000 // 72 Khz
|
||||
#define TEMP_TIMER_PRESCALE ((HAL_TIMER_RATE)/(TEMP_TIMER_RATE))
|
||||
#define TEMP_TIMER_FREQUENCY 1000
|
||||
|
||||
#define STEPPER_TIMER_RATE 2000000 // 2 Mhz
|
||||
#define STEPPER_TIMER_PRESCALE ((HAL_TIMER_RATE)/(STEPPER_TIMER_RATE))
|
||||
#define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // stepper timer ticks per µs
|
||||
|
||||
#define TEMP_TIMER_FREQUENCY 1000 // temperature interrupt frequency
|
||||
|
||||
#define PULSE_TIMER_RATE STEPPER_TIMER_RATE // frequency of pulse timer
|
||||
#define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE
|
||||
#define PULSE_TIMER_RATE STEPPER_TIMER_RATE
|
||||
#define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE
|
||||
#define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US
|
||||
|
||||
#define __TIMER_DEV(X) TIM##X
|
||||
|
Loading…
Reference in New Issue
Block a user