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:
Nils Hasenbanck 2018-10-04 05:33:24 +02:00 committed by Scott Lahteine
parent 8daadd2c8c
commit fcf6d127fd
2 changed files with 14 additions and 19 deletions

View file

@ -71,7 +71,7 @@ bool timers_initialised[NUM_HARDWARE_TIMERS] = {false};
void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) { void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
if (!timers_initialised[timer_num]) { 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; temp_prescaler = TEMP_TIMER_PRESCALE - 1;
switch (timer_num) { switch (timer_num) {
case STEP_TIMER_NUM: case STEP_TIMER_NUM:

View file

@ -33,14 +33,12 @@
#define FORCE_INLINE __attribute__((always_inline)) inline #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 #define HAL_TIMER_TYPE_MAX 0xFFFF
#ifdef STM32F0xx #ifdef STM32F0xx
#define HAL_TIMER_RATE (HAL_RCC_GetSysClockFreq()) // frequency of timer peripherals #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 STEP_TIMER 16 #define STEP_TIMER 16
#define TEMP_TIMER 17 #define TEMP_TIMER 17
@ -48,8 +46,6 @@
#elif defined STM32F1xx #elif defined STM32F1xx
#define HAL_TIMER_RATE (HAL_RCC_GetPCLK2Freq()) // frequency of timer peripherals #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 STEP_TIMER 4 #define STEP_TIMER 4
#define TEMP_TIMER 2 #define TEMP_TIMER 2
@ -57,8 +53,6 @@
#elif defined STM32F4xx #elif defined STM32F4xx
#define HAL_TIMER_RATE (HAL_RCC_GetPCLK2Freq()) // frequency of timer peripherals #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 STEP_TIMER 4 #define STEP_TIMER 4
#define TEMP_TIMER 5 #define TEMP_TIMER 5
@ -66,8 +60,6 @@
#elif defined STM32F7xx #elif defined STM32F7xx
#define HAL_TIMER_RATE (HAL_RCC_GetSysClockFreq()/2) // frequency of timer peripherals #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 STEP_TIMER 5 #define STEP_TIMER 5
#define TEMP_TIMER 7 #define TEMP_TIMER 7
@ -82,12 +74,15 @@
#define TEMP_TIMER_NUM 1 // index of timer to use for temperature #define TEMP_TIMER_NUM 1 // index of timer to use for temperature
#define PULSE_TIMER_NUM STEP_TIMER_NUM #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 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
#define PULSE_TIMER_RATE STEPPER_TIMER_RATE // frequency of pulse timer
#define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE #define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE
#define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US #define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US