diff --git a/include/arch/arduino-nano/driver/counter.h b/include/arch/arduino-nano/driver/counter.h index d387a354861653e833c12e4956b50e03ed2fc57f..9105219f9377735dc6920c751221dee1c0b13420 100644 --- a/include/arch/arduino-nano/driver/counter.h +++ b/include/arch/arduino-nano/driver/counter.h @@ -6,7 +6,8 @@ class Counter { Counter(const Counter ©); public: - uint8_t overflowed; + uint16_t value; + volatile uint8_t overflowed; Counter() : overflowed(0) {} @@ -14,13 +15,13 @@ class Counter { overflowed = 0; TCNT1 = 0; TCCR1A = 0; - TCCR1B = _BV(CS10); + TCCR1B = _BV(CS10); // no prescaler TIMSK1 = _BV(TOIE1); } - inline uint16_t stop() { + inline void stop() { TCCR1B = 0; - return TCNT1; + value = TCNT1; } }; diff --git a/src/arch/arduino-nano/driver/counter.cc b/src/arch/arduino-nano/driver/counter.cc index 4e629836cf4768b89d02305fb28f712c10dcf5cf..894a882b5b74df4b7a6b5239cae0ce7318439b56 100644 --- a/src/arch/arduino-nano/driver/counter.cc +++ b/src/arch/arduino-nano/driver/counter.cc @@ -1,5 +1,9 @@ #include "driver/counter.h" +#if defined(TIMER_S) || defined(WITH_LOOP) +#warn "timer/loop and counter are mutually exclusive. Expect odd behaviour." +#endif + Counter counter; ISR(TIMER1_OVF_vect)