X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fstm%2Fao_timer.c;h=ebe753668e6036cb376bf1d82d5a55de7d53b479;hb=ab379493dbe9923db8e458d2f4e0344df17d331c;hp=099a0ece8a6bbdd92d594ab51984238ca06cc900;hpb=49ac2828510e8b5fcba7e31631dac0580a455011;p=fw%2Faltos diff --git a/src/stm/ao_timer.c b/src/stm/ao_timer.c index 099a0ece..ebe75366 100644 --- a/src/stm/ao_timer.c +++ b/src/stm/ao_timer.c @@ -17,7 +17,7 @@ #include "ao.h" -static volatile __data uint16_t ao_tick_count; +volatile __data uint16_t ao_tick_count; uint16_t ao_time(void) { @@ -69,13 +69,25 @@ ao_timer_set_adc_interval(uint8_t interval) __critical } #endif -#define TIMER_10kHz (AO_PCLK1 / 10000) +/* + * According to the STM clock-configuration, timers run + * twice as fast as the APB1 clock *if* the APB1 prescaler + * is greater than 1. + */ + +#if AO_APB1_PRESCALER > 1 +#define TIMER_23467_SCALER 2 +#else +#define TIMER_23467_SCALER 1 +#endif + +#define TIMER_10kHz ((AO_PCLK1 * TIMER_23467_SCALER) / 10000) void ao_timer_init(void) { stm_nvic_set_enable(STM_ISR_TIM6_POS); - stm_nvic_set_priority(STM_ISR_TIM6_POS, 1); + stm_nvic_set_priority(STM_ISR_TIM6_POS, AO_STM_NVIC_CLOCK_PRIORITY); /* Turn on timer 6 */ stm_rcc.apb1enr |= (1 << STM_RCC_APB1ENR_TIM6EN);