Skip to content

setFrequency restarts the already running timer after chaniging the f… #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions DueTimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 2 additions & 0 deletions DueTimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down