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

Commit 1d1ea84

Browse files
authored
v1.101 using float for interval
### Releases v1.10.1 1. Using `float` instead of `ulong` for interval 2. Prevent overflow of SAMD51 TCx by flagging error
1 parent f56782b commit 1d1ea84

File tree

10 files changed

+56
-32
lines changed

10 files changed

+56
-32
lines changed

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ While software timer, **programmed for 2s, is activated after 7.937s !!!**. Then
617617

618618
```
619619
Starting ISR_Timer_Complex_WiFiNINA on SAMD_NANO_33_IOT
620-
SAMDTimerInterrupt v1.10.0
620+
SAMDTimerInterrupt v1.10.1
621621
CPU Frequency = 48 MHz
622622
[TISR] SAMDTimerInterrupt: F_CPU (MHz) = 48 , TIMER_HZ = 48
623623
[TISR] TC_Timer::startTimer _Timer = 0x 42002c00 , TC3 = 0x 42002c00
@@ -682,7 +682,7 @@ The following is the sample terminal output when running example [**TimerInterru
682682

683683
```
684684
Starting TimerInterruptTest on ITSYBITSY_M4
685-
SAMDTimerInterrupt v1.10.0
685+
SAMDTimerInterrupt v1.10.1
686686
CPU Frequency = 48 MHz
687687
[TISR] SAMDTimerInterrupt: F_CPU (MHz) = 120 , TIMER_HZ = 48
688688
[TISR] TC_Timer::startTimer _Timer = 0x 0x4101c000 , TC3 = 0x 0x4101c000
@@ -760,7 +760,7 @@ The following is the sample terminal output when running example [**Argument_Non
760760

761761
```
762762
Starting Argument_None on SAMD_NANO_33_IOT
763-
SAMDTimerInterrupt v1.10.0
763+
SAMDTimerInterrupt v1.10.1
764764
CPU Frequency = 48 MHz
765765
[TISR] SAMDTimerInterrupt: F_CPU (MHz) = 48 , TIMER_HZ = 48
766766
[TISR] TC_Timer::startTimer _Timer = 0x 42002c00 , TC3 = 0x 42002c00
@@ -810,7 +810,7 @@ In this example, 16 independent ISR Timers are used, yet utilized just one Hardw
810810

811811
```
812812
Starting ISR_16_Timers_Array on SAMD_NANO_33_IOT
813-
SAMDTimerInterrupt v1.10.0
813+
SAMDTimerInterrupt v1.10.1
814814
CPU Frequency = 48 MHz
815815
[TISR] SAMDTimerInterrupt: F_CPU (MHz) = 48 , TIMER_HZ = 48
816816
[TISR] TC_Timer::startTimer _Timer = 0x 42002c00 , TC3 = 0x 42002c00
@@ -934,7 +934,7 @@ The following is the sample terminal output when running example [Change_Interva
934934

935935
```
936936
Starting Change_Interval on SAMD_NANO_33_IOT
937-
SAMDTimerInterrupt v1.10.0
937+
SAMDTimerInterrupt v1.10.1
938938
CPU Frequency = 48 MHz
939939
[TISR] SAMDTimerInterrupt: F_CPU (MHz) = 48 , TIMER_HZ = 48
940940
[TISR] TC_Timer::startTimer _Timer = 0x 42002c00 , TC3 = 0x 42002c00
@@ -998,7 +998,7 @@ The following is the sample terminal output when running example [RepeatedAttach
998998

999999
```
10001000
Starting RepeatedAttachInterrupt_uS on SEEED_XIAO_M0
1001-
SAMDTimerInterrupt v1.10.0
1001+
SAMDTimerInterrupt v1.10.1
10021002
CPU Frequency = 48 MHz
10031003
[TISR] _period = 19995 , frequency = 50.01
10041004
[TISR] SAMDTimerInterrupt: F_CPU (MHz) = 48 , TIMER_HZ = 48
@@ -1065,7 +1065,7 @@ The following is the sample terminal output when running example [SAMD21_MultiTi
10651065

10661066
```
10671067
Starting SAMD21_MultiTimers on SAMD_NANO_33_IOT
1068-
SAMDTimerInterrupt v1.10.0
1068+
SAMDTimerInterrupt v1.10.1
10691069
CPU Frequency = 48 MHz
10701070
[TISR] _period = 20000.00 , frequency = 50.00
10711071
[TISR] _timerNumber = 0
@@ -1181,6 +1181,7 @@ Submit issues to: [SAMD_TimerInterrupt issues](https://github.com/khoih-prog/SAM
11811181
13. Add functions `attachInterruptInterval_MS()` and `setInterval_MS()`
11821182
14. Avoid conflict with Servo library. Check [Cannot use TimerInterrupt_Generic Library in the same time than Servo Library #11](https://github.com/khoih-prog/TimerInterrupt_Generic/discussions/11)
11831183
15. Prevent overflow of TCx by flagging error
1184+
16. Using float instead of ulong for interval
11841185

11851186
---
11861187
---

changelog.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
## Table of Contents
1313

1414
* [Changelog](#changelog)
15+
* [Releases v1.10.1](#releases-v1101)
1516
* [Releases v1.10.0](#releases-v1100)
1617
* [Releases v1.9.0](#releases-v190)
1718
* [Releases v1.8.0](#releases-v180)
@@ -32,10 +33,15 @@
3233

3334
## Changelog
3435

36+
### Releases v1.10.1
37+
38+
1. Using float instead of ulong for interval
39+
2. Prevent overflow of SAMD51 TCx by flagging error
40+
3541
### Releases v1.10.0
3642

3743
1. Avoid conflict with Servo library. Check [Cannot use TimerInterrupt_Generic Library in the same time than Servo Library #11](https://github.com/khoih-prog/TimerInterrupt_Generic/discussions/11)
38-
2. Prevent overflow of TCx by flagging error
44+
2. Prevent overflow of SAMD21 TCx by flagging error
3945
3. Modify all examples
4046
4. Update `Packages_Patches`
4147

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "SAMD_TimerInterrupt",
3-
"version": "1.10.0",
3+
"version": "1.10.1",
44
"keywords": "timing, device, control, timer, interrupt, hardware, isr, isr-based, hardware-timer, isr-timer, isr-based-timer, mission-critical, accuracy, precise, non-blocking, samd, samd21, samd51, nano-33-iot",
55
"description": "This library enables you to use Interrupt from Hardware Timers on SAMD-based boards. It now supports 16 ISR-based timers, while consuming only 1 Hardware Timer. Timers' interval is very long (ulong millisecs). The most important feature is they're ISR-based timers. Therefore, their executions are not blocked by bad-behaving functions or tasks. This important feature is absolutely necessary for mission-critical tasks. These hardware timers, using interrupt, still work even if other functions are blocking. Moreover, they are much more precise (certainly depending on clock frequency accuracy) than other software timers using millis() or micros(). That's necessary if you need to measure some data requiring better accuracy. SAMD21 now can use 6 Timers",
66
"authors":

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=SAMD_TimerInterrupt
2-
version=1.10.0
2+
version=1.10.1
33
author=Khoi Hoang <[email protected]>
44
maintainer=Khoi Hoang <[email protected]>
55
sentence=This library enables you to use Interrupt from Hardware Timers on SAMD-based boards such as SAMD21 Nano-33-IoT, Adafruit SAMD51 Itsy-Bitsy M4, SeeedStudio XIAO, Sparkfun SAMD51_MICROMOD, etc.

src/SAMDTimerInterrupt.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
Based on BlynkTimer.h
1717
Author: Volodymyr Shymanskyy
1818
19-
Version: 1.10.0
19+
Version: 1.10.1
2020
2121
Version Modified By Date Comments
2222
------- ----------- ---------- -----------
@@ -33,6 +33,7 @@
3333
1.8.0 K.Hoang 07/05/2022 Scrap the buggy code in v1.7.0 for TC3
3434
1.9.0 K.Hoang 08/05/2022 Add TC4, TC5, TCC1 and TCC2 Timers to SAMD21
3535
1.10.0 K.Hoang 29/09/2022 Avoid conflict with Servo library. Modify all examples. Prevent overflow of TCx
36+
1.10.1 K.Hoang 30/09/2022 Using float instead of ulong for interval. Prevent overflow of SAMD51 TCx
3637
*****************************************************************************************************************************/
3738
/*
3839
SAMD21

src/SAMDTimerInterrupt.hpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
Copyright (c) 2010 OTTOTECNICA Italy
1616
Based on BlynkTimer.h
1717
Author: Volodymyr Shymanskyy
18-
19-
Version: 1.10.0
18+
19+
Version: 1.10.1
2020
2121
Version Modified By Date Comments
2222
------- ----------- ---------- -----------
@@ -33,6 +33,7 @@
3333
1.8.0 K.Hoang 07/05/2022 Scrap the buggy code in v1.7.0 for TC3
3434
1.9.0 K.Hoang 08/05/2022 Add TC4, TC5, TCC1 and TCC2 Timers to SAMD21
3535
1.10.0 K.Hoang 29/09/2022 Avoid conflict with Servo library. Modify all examples. Prevent overflow of TCx
36+
1.10.1 K.Hoang 30/09/2022 Using float instead of ulong for interval. Prevent overflow of SAMD51 TCx
3637
*****************************************************************************************************************************/
3738
/*
3839
SAMD21
@@ -155,13 +156,13 @@
155156
#include "Arduino.h"
156157

157158
#ifndef SAMD_TIMER_INTERRUPT_VERSION
158-
#define SAMD_TIMER_INTERRUPT_VERSION "SAMDTimerInterrupt v1.10.0"
159+
#define SAMD_TIMER_INTERRUPT_VERSION "SAMDTimerInterrupt v1.10.1"
159160

160161
#define SAMD_TIMER_INTERRUPT_VERSION_MAJOR 1
161162
#define SAMD_TIMER_INTERRUPT_VERSION_MINOR 10
162-
#define SAMD_TIMER_INTERRUPT_VERSION_PATCH 0
163+
#define SAMD_TIMER_INTERRUPT_VERSION_PATCH 1
163164

164-
#define SAMD_TIMER_INTERRUPT_VERSION_INT 1010000
165+
#define SAMD_TIMER_INTERRUPT_VERSION_INT 1010001
165166
#endif
166167

167168
#include "TimerInterrupt_Generic_Debug.h"
@@ -245,7 +246,7 @@ class SAMDTimerInterrupt
245246

246247
// interval (in microseconds) and duration (in milliseconds). Duration = 0 or not specified => run indefinitely
247248
// No params and duration now. To be added in the future by adding similar functions here or to SAMD-hal-timer.c
248-
bool setInterval(const unsigned long& interval, timerCallback callback)
249+
bool setInterval(const float& interval, timerCallback callback)
249250
{
250251
return setFrequency((float) (1000000.0f / interval), callback);
251252
}
@@ -254,7 +255,7 @@ class SAMDTimerInterrupt
254255

255256
// interval (in milliseconds) and duration (in milliseconds). Duration = 0 or not specified => run indefinitely
256257
// No params and duration now. To be added in the future by adding similar functions here or to SAMD-hal-timer.c
257-
bool setInterval_MS(const unsigned long& interval, timerCallback callback)
258+
bool setInterval_MS(const float& interval, timerCallback callback)
258259
{
259260
return setFrequency((float) (1000.0f / interval), callback);
260261
}
@@ -270,7 +271,7 @@ class SAMDTimerInterrupt
270271

271272
// interval (in microseconds) and duration (in milliseconds). Duration = 0 or not specified => run indefinitely
272273
// No params and duration now. To be added in the future by adding similar functions here or to SAMD-hal-timer.c
273-
bool attachInterruptInterval(const unsigned long& interval, timerCallback callback)
274+
bool attachInterruptInterval(const float& interval, timerCallback callback)
274275
{
275276
return setFrequency( (float) ( 1000000.0f / interval), callback);
276277
}
@@ -279,7 +280,7 @@ class SAMDTimerInterrupt
279280

280281
// interval (in milliseconds) and duration (in milliseconds). Duration = 0 or not specified => run indefinitely
281282
// No params and duration now. To be added in the future by adding similar functions here or to SAMD-hal-timer.c
282-
bool attachInterruptInterval_MS(const unsigned long& interval, timerCallback callback)
283+
bool attachInterruptInterval_MS(const float& interval, timerCallback callback)
283284
{
284285
return setFrequency( (float) ( 1000.0f / interval), callback);
285286
}
@@ -545,7 +546,7 @@ class SAMDTimerInterrupt
545546

546547
// interval (in microseconds) and duration (in milliseconds). Duration = 0 or not specified => run indefinitely
547548
// No params and duration now. To be added in the future by adding similar functions here or to SAMD-hal-timer.c
548-
bool setInterval(const unsigned long& interval, timerCallback callback)
549+
bool setInterval(const float& interval, timerCallback callback)
549550
{
550551
return setFrequency((float) (1000000.0f / interval), callback);
551552
}
@@ -554,7 +555,7 @@ class SAMDTimerInterrupt
554555

555556
// interval (in milliseconds) and duration (in milliseconds). Duration = 0 or not specified => run indefinitely
556557
// No params and duration now. To be added in the future by adding similar functions here or to SAMD-hal-timer.c
557-
bool setInterval_MS(const unsigned long& interval, timerCallback callback)
558+
bool setInterval_MS(const float& interval, timerCallback callback)
558559
{
559560
return setFrequency((float) (1000.0f / interval), callback);
560561
}
@@ -570,7 +571,7 @@ class SAMDTimerInterrupt
570571

571572
// interval (in microseconds) and duration (in milliseconds). Duration = 0 or not specified => run indefinitely
572573
// No params and duration now. To be added in the future by adding similar functions here or to SAMD-hal-timer.c
573-
bool attachInterruptInterval(const unsigned long& interval, timerCallback callback)
574+
bool attachInterruptInterval(const float& interval, timerCallback callback)
574575
{
575576
return setFrequency( (float) ( 1000000.0f / interval), callback);
576577
}
@@ -579,7 +580,7 @@ class SAMDTimerInterrupt
579580

580581
// interval (in milliseconds) and duration (in milliseconds). Duration = 0 or not specified => run indefinitely
581582
// No params and duration now. To be added in the future by adding similar functions here or to SAMD-hal-timer.c
582-
bool attachInterruptInterval_MS(const unsigned long& interval, timerCallback callback)
583+
bool attachInterruptInterval_MS(const float& interval, timerCallback callback)
583584
{
584585
return setFrequency( (float) ( 1000.0f / interval), callback);
585586
}

src/SAMDTimerInterrupt_Impl.h

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
Copyright (c) 2010 OTTOTECNICA Italy
1616
Based on BlynkTimer.h
1717
Author: Volodymyr Shymanskyy
18-
19-
Version: 1.10.0
18+
19+
Version: 1.10.1
2020
2121
Version Modified By Date Comments
2222
------- ----------- ---------- -----------
@@ -33,6 +33,7 @@
3333
1.8.0 K.Hoang 07/05/2022 Scrap the buggy code in v1.7.0 for TC3
3434
1.9.0 K.Hoang 08/05/2022 Add TC4, TC5, TCC1 and TCC2 Timers to SAMD21
3535
1.10.0 K.Hoang 29/09/2022 Avoid conflict with Servo library. Modify all examples. Prevent overflow of TCx
36+
1.10.1 K.Hoang 30/09/2022 Using float instead of ulong for interval. Prevent overflow of SAMD51 TCx
3637
*****************************************************************************************************************************/
3738
/*
3839
SAMD21
@@ -84,6 +85,16 @@
8485
{
8586
TISR_LOGWARN3(F("SAMDTimerInterrupt: F_CPU (MHz) ="), F_CPU/1000000, F(", TIMER_HZ ="), TIMER_HZ/1000000);
8687
TISR_LOGWARN3(F("TC_Timer::startTimer _Timer = 0x"), String((uint32_t) _SAMDTimer, HEX), F(", TC3 = 0x"), String((uint32_t) TC3, HEX));
88+
89+
// maxPermittedPeriod = 1,398,101.33us for 48MHz timer clock
90+
float maxPermittedPeriod = (65536.0f * 1024) / (TIMER_HZ / 1000000.0f );
91+
92+
if (_period > maxPermittedPeriod )
93+
{
94+
TISR_LOGERROR3(F("Max permissible _period (us) ="), maxPermittedPeriod, F(", current _period (us) ="), _period);
95+
96+
return false;
97+
}
8798

8899
// Enable the TC bus clock, use clock generator 0
89100
GCLK->PCHCTRL[TC3_GCLK_ID].reg = GCLK_PCHCTRL_GEN_GCLK1_Val | (1 << GCLK_PCHCTRL_CHEN_Pos);
@@ -108,7 +119,7 @@
108119
TC3_callback = callback;
109120

110121
setPeriod_TIMER_TC3(_period);
111-
122+
112123
return true;
113124
}
114125
else
@@ -273,12 +284,13 @@
273284
{
274285
TISR_LOGDEBUG1(F("_timerNumber ="), _timerNumber);
275286

276-
// maxPermittedPeriod = 1,398,101.33us for 48MHz clock
277-
float maxPermittedPeriod = (65536.0f * 1024) / (F_CPU / 1000000.0f );
287+
// maxPermittedPeriod = 1,398,101.33us for 48MHz timer clock
288+
float maxPermittedPeriod = (65536.0f * 1024) / (TIMER_HZ / 1000000.0f );
278289

279290
if (_period > maxPermittedPeriod )
280291
{
281292
TISR_LOGERROR3(F("Max permissible _period (us) ="), maxPermittedPeriod, F(", current _period (us) ="), _period);
293+
282294
return false;
283295
}
284296

src/SAMD_ISR_Timer-Impl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
Based on BlynkTimer.h
2020
Author: Volodymyr Shymanskyy
2121
22-
Version: 1.10.0
22+
Version: 1.10.1
2323
2424
Version Modified By Date Comments
2525
------- ----------- ---------- -----------
@@ -36,6 +36,7 @@
3636
1.8.0 K.Hoang 07/05/2022 Scrap the buggy code in v1.7.0 for TC3
3737
1.9.0 K.Hoang 08/05/2022 Add TC4, TC5, TCC1 and TCC2 Timers to SAMD21
3838
1.10.0 K.Hoang 29/09/2022 Avoid conflict with Servo library. Modify all examples. Prevent overflow of TCx
39+
1.10.1 K.Hoang 30/09/2022 Using float instead of ulong for interval. Prevent overflow of SAMD51 TCx
3940
*****************************************************************************************************************************/
4041

4142
#pragma once

src/SAMD_ISR_Timer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
Based on BlynkTimer.h
2020
Author: Volodymyr Shymanskyy
2121
22-
Version: 1.10.0
22+
Version: 1.10.1
2323
2424
Version Modified By Date Comments
2525
------- ----------- ---------- -----------
@@ -36,6 +36,7 @@
3636
1.8.0 K.Hoang 07/05/2022 Scrap the buggy code in v1.7.0 for TC3
3737
1.9.0 K.Hoang 08/05/2022 Add TC4, TC5, TCC1 and TCC2 Timers to SAMD21
3838
1.10.0 K.Hoang 29/09/2022 Avoid conflict with Servo library. Modify all examples. Prevent overflow of TCx
39+
1.10.1 K.Hoang 30/09/2022 Using float instead of ulong for interval. Prevent overflow of SAMD51 TCx
3940
*****************************************************************************************************************************/
4041

4142
#pragma once

src/SAMD_ISR_Timer.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
Based on BlynkTimer.h
2020
Author: Volodymyr Shymanskyy
2121
22-
Version: 1.10.0
22+
Version: 1.10.1
2323
2424
Version Modified By Date Comments
2525
------- ----------- ---------- -----------
@@ -36,6 +36,7 @@
3636
1.8.0 K.Hoang 07/05/2022 Scrap the buggy code in v1.7.0 for TC3
3737
1.9.0 K.Hoang 08/05/2022 Add TC4, TC5, TCC1 and TCC2 Timers to SAMD21
3838
1.10.0 K.Hoang 29/09/2022 Avoid conflict with Servo library. Modify all examples. Prevent overflow of TCx
39+
1.10.1 K.Hoang 30/09/2022 Using float instead of ulong for interval. Prevent overflow of SAMD51 TCx
3940
*****************************************************************************************************************************/
4041

4142
#pragma once

0 commit comments

Comments
 (0)