From 56b433ef2756f0fdf7b0e92eaf9f6b16079b9268 Mon Sep 17 00:00:00 2001 From: iddq Date: Mon, 14 Nov 2022 12:09:55 +0100 Subject: [PATCH] setFrequency restarts the already running timer after chaniging the frequency. --- DueTimer.cpp | 7 +++++++ DueTimer.h | 2 ++ 2 files changed, 9 insertions(+) diff --git a/DueTimer.cpp b/DueTimer.cpp index 1eacd72..2776868 100644 --- a/DueTimer.cpp +++ b/DueTimer.cpp @@ -127,6 +127,8 @@ DueTimer& DueTimer::start(double microseconds){ NVIC_EnableIRQ(Timers[timer].irq); TC_Start(Timers[timer].tc, Timers[timer].channel); + + _running = 1; return *this; } @@ -139,6 +141,8 @@ DueTimer& DueTimer::stop(void){ NVIC_DisableIRQ(Timers[timer].irq); TC_Stop(Timers[timer].tc, Timers[timer].channel); + + _running = 0; return *this; } @@ -237,6 +241,9 @@ DueTimer& DueTimer::setFrequency(double frequency){ // ... and disable all others. t.tc->TC_CHANNEL[t.channel].TC_IDR=~TC_IER_CPCS; + if (_running) + start(); + return *this; } diff --git a/DueTimer.h b/DueTimer.h index f0b54e6..d334287 100644 --- a/DueTimer.h +++ b/DueTimer.h @@ -44,6 +44,8 @@ class DueTimer // Represents the timer id (index for the array of Timer structs) const unsigned short timer; + int _running = 0; + // Stores the object timer frequency // (allows to access current timer period and frequency): static double _frequency[NUM_TIMERS];