diff options
author | Keith Packard <keithp@keithp.com> | 2012-06-01 19:35:33 -0700 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2012-06-01 19:35:33 -0700 |
commit | ab85337aa942cb73a08bd3b783771179773b9a67 (patch) | |
tree | c7649f9f0dd32e7e4894f81b091a7252279009b1 | |
parent | ff4f3a56e09d595abbe32293cbdf1fe368633c49 (diff) |
altos: Timers clock base depends on perhipheral bus prescalers too
For some weird reason, a non-unity perhipheral bus clock scaler
affects the base of the various timers; this left the 100Hz tick
running at 200Hz.
Signed-off-by: Keith Packard <keithp@keithp.com>
-rw-r--r-- | src/stm/ao_timer.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/stm/ao_timer.c b/src/stm/ao_timer.c index 099a0ece..0c44f352 100644 --- a/src/stm/ao_timer.c +++ b/src/stm/ao_timer.c @@ -69,7 +69,19 @@ 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) |