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

Commit 88fb548

Browse files
authored
Merge pull request #7 from generationmake/period_to_float
change variable period from unsigned long to float
2 parents b7b0faf + 34d460f commit 88fb548

File tree

3 files changed

+30
-30
lines changed

3 files changed

+30
-30
lines changed

src/SAMDTimerInterrupt.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ class SAMDTimerInterrupt
160160
timerCallback _callback; // pointer to the callback function
161161
float _frequency; // Timer frequency
162162

163-
unsigned long _period;
163+
float _period;
164164
int _prescaler;
165165
int _compareValue;
166166

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

191191
if (_timerNumber == TIMER_TC3)
192192
{
@@ -300,7 +300,7 @@ class SAMDTimerInterrupt
300300

301301
private:
302302

303-
void setPeriod_TIMER_TC3(unsigned long period)
303+
void setPeriod_TIMER_TC3(float period)
304304
{
305305
uint32_t TC_CTRLA_PRESCALER_DIVN;
306306

@@ -364,7 +364,7 @@ class SAMDTimerInterrupt
364364
TC3->COUNT16.CTRLA.reg |= TC_CTRLA_PRESCALER_DIVN;
365365
TC3_wait_for_sync();
366366

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

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

458-
unsigned long _period;
458+
float _period;
459459
int _prescaler;
460460
int _compareValue;
461461

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

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

@@ -656,7 +656,7 @@ class SAMDTimerInterrupt
656656

657657
private:
658658

659-
void setPeriod_TIMER_TC3(unsigned long period)
659+
void setPeriod_TIMER_TC3(float period)
660660
{
661661
TcCount16* _Timer = (TcCount16*) _SAMDTimer;
662662

@@ -730,7 +730,7 @@ class SAMDTimerInterrupt
730730

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

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

735735

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

747-
void setPeriod_TIMER_TCC(unsigned long period)
747+
void setPeriod_TIMER_TCC(float period)
748748
{
749749
Tcc* _Timer = (Tcc*) _SAMDTimer;
750750

@@ -814,7 +814,7 @@ class SAMDTimerInterrupt
814814
_prescaler = 1;
815815
}
816816

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

819819
_Timer->PER.reg = _compareValue;
820820

src_cpp/SAMDTimerInterrupt.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ class SAMDTimerInterrupt
160160
timerCallback _callback; // pointer to the callback function
161161
float _frequency; // Timer frequency
162162

163-
unsigned long _period;
163+
float _period;
164164
int _prescaler;
165165
int _compareValue;
166166

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

191191
if (_timerNumber == TIMER_TC3)
192192
{
@@ -300,7 +300,7 @@ class SAMDTimerInterrupt
300300

301301
private:
302302

303-
void setPeriod_TIMER_TC3(unsigned long period)
303+
void setPeriod_TIMER_TC3(float period)
304304
{
305305
uint32_t TC_CTRLA_PRESCALER_DIVN;
306306

@@ -364,7 +364,7 @@ class SAMDTimerInterrupt
364364
TC3->COUNT16.CTRLA.reg |= TC_CTRLA_PRESCALER_DIVN;
365365
TC3_wait_for_sync();
366366

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

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

458-
unsigned long _period;
458+
float _period;
459459
int _prescaler;
460460
int _compareValue;
461461

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

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

@@ -656,7 +656,7 @@ class SAMDTimerInterrupt
656656

657657
private:
658658

659-
void setPeriod_TIMER_TC3(unsigned long period)
659+
void setPeriod_TIMER_TC3(float period)
660660
{
661661
TcCount16* _Timer = (TcCount16*) _SAMDTimer;
662662

@@ -730,7 +730,7 @@ class SAMDTimerInterrupt
730730

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

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

735735

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

747-
void setPeriod_TIMER_TCC(unsigned long period)
747+
void setPeriod_TIMER_TCC(float period)
748748
{
749749
Tcc* _Timer = (Tcc*) _SAMDTimer;
750750

@@ -814,7 +814,7 @@ class SAMDTimerInterrupt
814814
_prescaler = 1;
815815
}
816816

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

819819
_Timer->PER.reg = _compareValue;
820820

src_h/SAMDTimerInterrupt.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ class SAMDTimerInterrupt
160160
timerCallback _callback; // pointer to the callback function
161161
float _frequency; // Timer frequency
162162

163-
unsigned long _period;
163+
float _period;
164164
int _prescaler;
165165
int _compareValue;
166166

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

191191
if (_timerNumber == TIMER_TC3)
192192
{
@@ -300,7 +300,7 @@ class SAMDTimerInterrupt
300300

301301
private:
302302

303-
void setPeriod_TIMER_TC3(unsigned long period)
303+
void setPeriod_TIMER_TC3(float period)
304304
{
305305
uint32_t TC_CTRLA_PRESCALER_DIVN;
306306

@@ -364,7 +364,7 @@ class SAMDTimerInterrupt
364364
TC3->COUNT16.CTRLA.reg |= TC_CTRLA_PRESCALER_DIVN;
365365
TC3_wait_for_sync();
366366

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

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

458-
unsigned long _period;
458+
float _period;
459459
int _prescaler;
460460
int _compareValue;
461461

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

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

@@ -656,7 +656,7 @@ class SAMDTimerInterrupt
656656

657657
private:
658658

659-
void setPeriod_TIMER_TC3(unsigned long period)
659+
void setPeriod_TIMER_TC3(float period)
660660
{
661661
TcCount16* _Timer = (TcCount16*) _SAMDTimer;
662662

@@ -730,7 +730,7 @@ class SAMDTimerInterrupt
730730

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

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

735735

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

747-
void setPeriod_TIMER_TCC(unsigned long period)
747+
void setPeriod_TIMER_TCC(float period)
748748
{
749749
Tcc* _Timer = (Tcc*) _SAMDTimer;
750750

@@ -814,7 +814,7 @@ class SAMDTimerInterrupt
814814
_prescaler = 1;
815815
}
816816

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

819819
_Timer->PER.reg = _compareValue;
820820

0 commit comments

Comments
 (0)