From 1a0aaa326afa8e9b06795755cacea72b464393ad Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Tue, 16 Oct 2018 07:46:59 +0200 Subject: MSP430: Support CPU speed variation in microsecond timer --- src/arch/msp430fr5969lp/arch.cc | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'src/arch') diff --git a/src/arch/msp430fr5969lp/arch.cc b/src/arch/msp430fr5969lp/arch.cc index b5b23b6..28d01a5 100644 --- a/src/arch/msp430fr5969lp/arch.cc +++ b/src/arch/msp430fr5969lp/arch.cc @@ -60,14 +60,26 @@ void Arch::setup(void) #endif #ifdef TIMER_US - // 16MHz/16 -> ~1MHz timer - TA0CTL = TASSEL__SMCLK | ID__8 | MC__CONTINUOUS; - TA0EX0 = 1; +#if F_CPU == 16000000UL + TA0CTL = TASSEL__SMCLK | ID__8 | MC__CONTINUOUS; // /8 + TA0EX0 = 1; // /2 -> /16 +#elif F_CPU == 8000000UL + TA0CTL = TASSEL__SMCLK | ID__8 | MC__CONTINUOUS; // /8 + TA0EX0 = 0; // /1 -> /8 +#elif F_CPU == 4000000UL + TA0CTL = TASSEL__SMCLK | ID__4 | MC__CONTINUOUS; // /4 + TA0EX0 = 0; // /1 -> /8 +#elif F_CPU == 1000000UL + TA0CTL = TASSEL__SMCLK | ID__1 | MC__CONTINUOUS; // /1 + TA0EX0 = 0; // /1 -> /8 +#else +#error Unsupported F_CPU +#endif /* F_CPU */ TA0CTL |= TACLR; -#endif +#endif /* TIMER_US */ #if defined(WITH_LOOP) || defined(TIMER_S) - // 1s per wakeup for loop + // 1s per wakeup for loop. Independent of SMCLK/F_CPU TA1CTL = TASSEL__ACLK | ID__8 | MC__UP; TA1EX0 = 0; TA1CCR0 = 4096; -- cgit v1.2.3