Skip to content
This repository was archived by the owner on Jan 29, 2023. It is now read-only.

change variable period from unsigned long to float #7

Merged
merged 1 commit into from
Oct 8, 2021
Merged
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
20 changes: 10 additions & 10 deletions src/SAMDTimerInterrupt.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class SAMDTimerInterrupt
timerCallback _callback; // pointer to the callback function
float _frequency; // Timer frequency

unsigned long _period;
float _period;
int _prescaler;
int _compareValue;

Expand All @@ -186,7 +186,7 @@ class SAMDTimerInterrupt
// No params and duration now. To be addes in the future by adding similar functions here or to SAMD-hal-timer.c
bool setFrequency(float frequency, timerCallback callback)
{
_period = (unsigned long) (1000000.0f / frequency);
_period = (1000000.0f / frequency);

if (_timerNumber == TIMER_TC3)
{
Expand Down Expand Up @@ -300,7 +300,7 @@ class SAMDTimerInterrupt

private:

void setPeriod_TIMER_TC3(unsigned long period)
void setPeriod_TIMER_TC3(float period)
{
uint32_t TC_CTRLA_PRESCALER_DIVN;

Expand Down Expand Up @@ -364,7 +364,7 @@ class SAMDTimerInterrupt
TC3->COUNT16.CTRLA.reg |= TC_CTRLA_PRESCALER_DIVN;
TC3_wait_for_sync();

_compareValue = (int)(TIMER_HZ / (_prescaler/((float)period / 1000000))) - 1;
_compareValue = (int)(TIMER_HZ / (_prescaler/(period / 1000000.0))) - 1;

// Make sure the count is in a proportional position to where it was
// to prevent any jitter or disconnect when changing the compare value.
Expand Down Expand Up @@ -455,7 +455,7 @@ class SAMDTimerInterrupt
float _frequency; // Timer frequency
//uint32_t _timerCount; // count to activate timer

unsigned long _period;
float _period;
int _prescaler;
int _compareValue;

Expand Down Expand Up @@ -485,7 +485,7 @@ class SAMDTimerInterrupt
// No params and duration now. To be addes in the future by adding similar functions here or to SAMD-hal-timer.c
bool setFrequency(float frequency, timerCallback callback)
{
_period = (unsigned long) (1000000.0f / frequency);
_period = (1000000.0f / frequency);

TISR_LOGDEBUG3(F("_period ="), _period, F(", frequency ="), frequency);

Expand Down Expand Up @@ -656,7 +656,7 @@ class SAMDTimerInterrupt

private:

void setPeriod_TIMER_TC3(unsigned long period)
void setPeriod_TIMER_TC3(float period)
{
TcCount16* _Timer = (TcCount16*) _SAMDTimer;

Expand Down Expand Up @@ -730,7 +730,7 @@ class SAMDTimerInterrupt

while (_Timer->STATUS.bit.SYNCBUSY == 1);

_compareValue = (int)(TIMER_HZ / (_prescaler / ((float)period / 1000000))) - 1;
_compareValue = (int)(TIMER_HZ / (_prescaler / (period / 1000000.0))) - 1;


// Make sure the count is in a proportional position to where it was
Expand All @@ -744,7 +744,7 @@ class SAMDTimerInterrupt
TISR_LOGDEBUG1(F("_compareValue ="), _compareValue);
}

void setPeriod_TIMER_TCC(unsigned long period)
void setPeriod_TIMER_TCC(float period)
{
Tcc* _Timer = (Tcc*) _SAMDTimer;

Expand Down Expand Up @@ -814,7 +814,7 @@ class SAMDTimerInterrupt
_prescaler = 1;
}

_compareValue = (int)(TIMER_HZ / (_prescaler / ((float)period / 1000000))) - 1;
_compareValue = (int)(TIMER_HZ / (_prescaler / (period / 1000000))) - 1;

_Timer->PER.reg = _compareValue;

Expand Down
20 changes: 10 additions & 10 deletions src_cpp/SAMDTimerInterrupt.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class SAMDTimerInterrupt
timerCallback _callback; // pointer to the callback function
float _frequency; // Timer frequency

unsigned long _period;
float _period;
int _prescaler;
int _compareValue;

Expand All @@ -186,7 +186,7 @@ class SAMDTimerInterrupt
// No params and duration now. To be addes in the future by adding similar functions here or to SAMD-hal-timer.c
bool setFrequency(float frequency, timerCallback callback)
{
_period = (unsigned long) (1000000.0f / frequency);
_period = (1000000.0f / frequency);

if (_timerNumber == TIMER_TC3)
{
Expand Down Expand Up @@ -300,7 +300,7 @@ class SAMDTimerInterrupt

private:

void setPeriod_TIMER_TC3(unsigned long period)
void setPeriod_TIMER_TC3(float period)
{
uint32_t TC_CTRLA_PRESCALER_DIVN;

Expand Down Expand Up @@ -364,7 +364,7 @@ class SAMDTimerInterrupt
TC3->COUNT16.CTRLA.reg |= TC_CTRLA_PRESCALER_DIVN;
TC3_wait_for_sync();

_compareValue = (int)(TIMER_HZ / (_prescaler/((float)period / 1000000))) - 1;
_compareValue = (int)(TIMER_HZ / (_prescaler/(period / 1000000.0))) - 1;

// Make sure the count is in a proportional position to where it was
// to prevent any jitter or disconnect when changing the compare value.
Expand Down Expand Up @@ -455,7 +455,7 @@ class SAMDTimerInterrupt
float _frequency; // Timer frequency
//uint32_t _timerCount; // count to activate timer

unsigned long _period;
float _period;
int _prescaler;
int _compareValue;

Expand Down Expand Up @@ -485,7 +485,7 @@ class SAMDTimerInterrupt
// No params and duration now. To be addes in the future by adding similar functions here or to SAMD-hal-timer.c
bool setFrequency(float frequency, timerCallback callback)
{
_period = (unsigned long) (1000000.0f / frequency);
_period = (1000000.0f / frequency);

TISR_LOGDEBUG3(F("_period ="), _period, F(", frequency ="), frequency);

Expand Down Expand Up @@ -656,7 +656,7 @@ class SAMDTimerInterrupt

private:

void setPeriod_TIMER_TC3(unsigned long period)
void setPeriod_TIMER_TC3(float period)
{
TcCount16* _Timer = (TcCount16*) _SAMDTimer;

Expand Down Expand Up @@ -730,7 +730,7 @@ class SAMDTimerInterrupt

while (_Timer->STATUS.bit.SYNCBUSY == 1);

_compareValue = (int)(TIMER_HZ / (_prescaler / ((float)period / 1000000))) - 1;
_compareValue = (int)(TIMER_HZ / (_prescaler / (period / 1000000.0))) - 1;


// Make sure the count is in a proportional position to where it was
Expand All @@ -744,7 +744,7 @@ class SAMDTimerInterrupt
TISR_LOGDEBUG1(F("_compareValue ="), _compareValue);
}

void setPeriod_TIMER_TCC(unsigned long period)
void setPeriod_TIMER_TCC(float period)
{
Tcc* _Timer = (Tcc*) _SAMDTimer;

Expand Down Expand Up @@ -814,7 +814,7 @@ class SAMDTimerInterrupt
_prescaler = 1;
}

_compareValue = (int)(TIMER_HZ / (_prescaler / ((float)period / 1000000))) - 1;
_compareValue = (int)(TIMER_HZ / (_prescaler / (period / 1000000.0))) - 1;

_Timer->PER.reg = _compareValue;

Expand Down
20 changes: 10 additions & 10 deletions src_h/SAMDTimerInterrupt.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class SAMDTimerInterrupt
timerCallback _callback; // pointer to the callback function
float _frequency; // Timer frequency

unsigned long _period;
float _period;
int _prescaler;
int _compareValue;

Expand All @@ -186,7 +186,7 @@ class SAMDTimerInterrupt
// No params and duration now. To be addes in the future by adding similar functions here or to SAMD-hal-timer.c
bool setFrequency(float frequency, timerCallback callback)
{
_period = (unsigned long) (1000000.0f / frequency);
_period = (1000000.0f / frequency);

if (_timerNumber == TIMER_TC3)
{
Expand Down Expand Up @@ -300,7 +300,7 @@ class SAMDTimerInterrupt

private:

void setPeriod_TIMER_TC3(unsigned long period)
void setPeriod_TIMER_TC3(float period)
{
uint32_t TC_CTRLA_PRESCALER_DIVN;

Expand Down Expand Up @@ -364,7 +364,7 @@ class SAMDTimerInterrupt
TC3->COUNT16.CTRLA.reg |= TC_CTRLA_PRESCALER_DIVN;
TC3_wait_for_sync();

_compareValue = (int)(TIMER_HZ / (_prescaler/((float)period / 1000000))) - 1;
_compareValue = (int)(TIMER_HZ / (_prescaler/(period / 1000000.0))) - 1;

// Make sure the count is in a proportional position to where it was
// to prevent any jitter or disconnect when changing the compare value.
Expand Down Expand Up @@ -455,7 +455,7 @@ class SAMDTimerInterrupt
float _frequency; // Timer frequency
//uint32_t _timerCount; // count to activate timer

unsigned long _period;
float _period;
int _prescaler;
int _compareValue;

Expand Down Expand Up @@ -485,7 +485,7 @@ class SAMDTimerInterrupt
// No params and duration now. To be addes in the future by adding similar functions here or to SAMD-hal-timer.c
bool setFrequency(float frequency, timerCallback callback)
{
_period = (unsigned long) (1000000.0f / frequency);
_period = (1000000.0f / frequency);

TISR_LOGDEBUG3(F("_period ="), _period, F(", frequency ="), frequency);

Expand Down Expand Up @@ -656,7 +656,7 @@ class SAMDTimerInterrupt

private:

void setPeriod_TIMER_TC3(unsigned long period)
void setPeriod_TIMER_TC3(float period)
{
TcCount16* _Timer = (TcCount16*) _SAMDTimer;

Expand Down Expand Up @@ -730,7 +730,7 @@ class SAMDTimerInterrupt

while (_Timer->STATUS.bit.SYNCBUSY == 1);

_compareValue = (int)(TIMER_HZ / (_prescaler / ((float)period / 1000000))) - 1;
_compareValue = (int)(TIMER_HZ / (_prescaler / (period / 1000000.0))) - 1;


// Make sure the count is in a proportional position to where it was
Expand All @@ -744,7 +744,7 @@ class SAMDTimerInterrupt
TISR_LOGDEBUG1(F("_compareValue ="), _compareValue);
}

void setPeriod_TIMER_TCC(unsigned long period)
void setPeriod_TIMER_TCC(float period)
{
Tcc* _Timer = (Tcc*) _SAMDTimer;

Expand Down Expand Up @@ -814,7 +814,7 @@ class SAMDTimerInterrupt
_prescaler = 1;
}

_compareValue = (int)(TIMER_HZ / (_prescaler / ((float)period / 1000000))) - 1;
_compareValue = (int)(TIMER_HZ / (_prescaler / (period / 1000000.0))) - 1;

_Timer->PER.reg = _compareValue;

Expand Down