From cf5db434e6e6bf1c3b263897e3c36b5c166c609d Mon Sep 17 00:00:00 2001 From: Joakim Gebart Date: Thu, 13 Aug 2015 20:59:26 +0200 Subject: [PATCH] cpu/kinetis_common: periph/timer, read PIT value before stopping Reading CVAL after stopping timer seem to return zero. Ref. manual states: "The counter period can be restarted, by first disabling, and then enabling the timer with TCTRLn[TEN]", but does not state whether the reset of CVAL happens on TEN 0->1 transition, or 1->0 transtion. Empirical evidence suggests the latter is the implemented behaviour. --- cpu/kinetis_common/timer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cpu/kinetis_common/timer.c b/cpu/kinetis_common/timer.c index b5770722f0..f8baf62545 100644 --- a/cpu/kinetis_common/timer.c +++ b/cpu/kinetis_common/timer.c @@ -149,8 +149,8 @@ int timer_set_absolute(tim_t dev, int channel, unsigned int value) #if TIMER_0_EN case TIMER_0: - pit_timer_stop(TIMER_0_COUNTER_CH); cu_timer[dev].counter32b = pit_timer_read(dev, TIMER_0_COUNTER_CH); + pit_timer_stop(TIMER_0_COUNTER_CH); cu_timer[dev].diff = value - cu_timer[dev].counter32b; TIMER_DEV->CHANNEL[TIMER_0_COUNTER_CH].LDVAL = cu_timer[dev].diff; pit_timer_start(TIMER_0_COUNTER_CH); @@ -159,8 +159,8 @@ int timer_set_absolute(tim_t dev, int channel, unsigned int value) #if TIMER_1_EN case TIMER_1: - pit_timer_stop(TIMER_1_COUNTER_CH); cu_timer[dev].counter32b = pit_timer_read(dev, TIMER_1_COUNTER_CH); + pit_timer_stop(TIMER_1_COUNTER_CH); cu_timer[dev].diff = value - cu_timer[dev].counter32b; TIMER_DEV->CHANNEL[TIMER_1_COUNTER_CH].LDVAL = cu_timer[dev].diff; pit_timer_start(TIMER_1_COUNTER_CH);