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

Commit 55ccb01

Browse files
authored
v1.1.1
### Releases v1.1.1 1. Add example [**Change_Interval**](examples/Change_Interval) and [**ISR_16_Timers_Array_Complex**](examples/ISR_16_Timers_Array_Complex) 2. Bump up version to sync with other TimerInterrupt Libraries. Modify Version String.
1 parent 1ac4cba commit 55ccb01

File tree

24 files changed

+684
-40
lines changed

24 files changed

+684
-40
lines changed

.gitignore

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Prerequisites
2+
*.d
3+
4+
# Compiled Object files
5+
*.slo
6+
*.lo
7+
*.o
8+
*.obj
9+
10+
# Precompiled Headers
11+
*.gch
12+
*.pch
13+
14+
# Compiled Dynamic libraries
15+
*.so
16+
*.dylib
17+
*.dll
18+
19+
# Fortran module files
20+
*.mod
21+
*.smod
22+
23+
# Compiled Static libraries
24+
*.lai
25+
*.la
26+
*.a
27+
*.lib
28+
29+
# Executables
30+
*.exe
31+
*.out
32+
*.app

README.md

Lines changed: 87 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ The catch is **your function is now part of an ISR (Interrupt Service Routine),
4444
---
4545
---
4646

47+
### Releases v1.1.1
48+
49+
1. Add example [**Change_Interval**](examples/Change_Interval) and [**ISR_16_Timers_Array_Complex**](examples/ISR_16_Timers_Array_Complex)
50+
2. Bump up version to sync with other TimerInterrupt Libraries. Modify Version String.
51+
4752
### Releases v1.0.1
4853

4954
1. Add complicated example [ISR_16_Timers_Array](examples/ISR_16_Timers_Array) utilizing and demonstrating the full usage of 16 independent ISR Timers.
@@ -63,7 +68,7 @@ The catch is **your function is now part of an ISR (Interrupt Service Routine),
6368
---
6469
---
6570

66-
## Prerequisite
71+
## Prerequisites
6772

6873
1. [`Arduino IDE 1.8.13+` for Arduino](https://www.arduino.cc/en/Main/Software)
6974
2. [`Arduino SAMD core v1.8.9+`](https://www.arduino.cc/en/Guide/ArduinoM0) for SAMD ARM Cortex-M0+ boards (Nano 33 IoT, etc.).
@@ -101,7 +106,7 @@ Another way to install is to:
101106

102107
1. Install [VS Code](https://code.visualstudio.com/)
103108
2. Install [PlatformIO](https://platformio.org/platformio-ide)
104-
3. Install [**SAMD_TimerInterrupt** library](https://platformio.org/lib/show/11396/SAMD_TimerInterrupt) by using [Library Manager](https://platformio.org/lib/show/11396/SAMD_TimerInterrupt/installation). Search for **SAMD_TimerInterrupt** in [Platform.io Author's Libraries](https://platformio.org/lib/search?query=author:%22Khoi%20Hoang%22)
109+
3. Install [**SAMD_TimerInterrupt** library](https://platformio.org/lib/show/11396/SAMD_TimerInterrupt) or [**SAMD_TimerInterrupt** library](https://platformio.org/lib/show/11396/SAMD_TimerInterrupt) by using [Library Manager](https://platformio.org/lib/show/11412/SAMD_TimerInterrupt/installation). Search for **SAMD_TimerInterrupt** in [Platform.io Author's Libraries](https://platformio.org/lib/search?query=author:%22Khoi%20Hoang%22)
105110
4. Use included [platformio.ini](platformio/platformio.ini) file from examples to ensure that all dependent libraries will installed automatically. Please visit documentation for the other options and examples at [Project Configuration File](https://docs.platformio.org/page/projectconf.html)
106111

107112
---
@@ -383,7 +388,9 @@ void setup()
383388
7. [SwitchDebounce](examples/SwitchDebounce)
384389
8. [TimerInterruptTest](examples/TimerInterruptTest)
385390
9. [TimerInterruptLEDDemo](examples/TimerInterruptLEDDemo)
386-
391+
10. [**Change_Interval**](examples/Change_Interval). New
392+
11. [**ISR_16_Timers_Array_Complex**](examples/ISR_16_Timers_Array_Complex). New
393+
387394

388395
---
389396
---
@@ -591,7 +598,8 @@ void setup()
591598
while (!Serial);
592599
593600
Serial.println("\nStarting ISR_Timer_Complex_WiFiNINA on " + String(BOARD_NAME));
594-
Serial.println("Version : " + String(SAMD_TIMER_INTERRUPT_VERSION));
601+
Serial.println(SAMD_TIMER_INTERRUPT_VERSION);
602+
Serial.println("CPU Frequency = " + String(F_CPU / 1000000) + " MHz");
595603
596604
// You need this timer for non-critical tasks. Avoid abusing ISR if not absolutely necessary.
597605
blynkTimer.setInterval(BLYNK_TIMER_MS, blynkDoingSomething2s);
@@ -664,7 +672,8 @@ While software timer, **programmed for 2s, is activated after 7.937s !!!**. Then
664672

665673
```
666674
Starting ISR_Timer_Complex_WiFiNINA on SAMD_NANO_33_IOT
667-
Version : 1.0.1
675+
SAMDTimerInterrupt v1.1.1
676+
CPU Frequency = 48 MHz
668677
F_CPU (MHz) = 48, TIMER_HZ = 48
669678
TC_Timer::startTimer _Timer = 0x42002c00, TC3 = 0x42002c00
670679
Starting ITimer OK, millis() = 810
@@ -726,7 +735,8 @@ blynkDoingSomething2s: Delta programmed ms = 2000, actual = 3002
726735

727736
```
728737
Starting TimerInterruptTest on ITSYBITSY_M4
729-
Version : 1.0.1
738+
SAMDTimerInterrupt v1.1.1
739+
CPU Frequency = 48 MHz
730740
F_CPU (MHz) = 120, TIMER_HZ = 48
731741
TC_Timer::startTimer _Timer = 0x4101c000, TC3 = 0x4101c000
732742
Starting ITimer1 OK, millis() = 1820
@@ -801,7 +811,8 @@ ITimer0: millis() = 91018, delta = 1000
801811

802812
```
803813
Starting Argument_None on SAMD_NANO_33_IOT
804-
Version : 1.0.1
814+
SAMDTimerInterrupt v1.1.1
815+
CPU Frequency = 48 MHz
805816
F_CPU (MHz) = 48, TIMER_HZ = 48
806817
TC_Timer::startTimer _Timer = 0x42002c00, TC3 = 0x42002c00
807818
Starting ITimer1 OK, millis() = 910
@@ -846,7 +857,8 @@ In this example, 16 independent ISR Timers are used, yet utilized just one Hardw
846857

847858
```
848859
Starting ISR_16_Timers_Array on SAMD_NANO_33_IOT
849-
Version : 1.0.1
860+
SAMDTimerInterrupt v1.1.1
861+
CPU Frequency = 48 MHz
850862
CPU Frequency = 48 MHz
851863
F_CPU (MHz) = 48, TIMER_HZ = 48
852864
TC_Timer::startTimer _Timer = 0x42002c00, TC3 = 0x42002c00
@@ -961,9 +973,76 @@ simpleTimerDoingSomething2s: Delta programmed ms = 2000, actual = 10000
961973
3s: Delta ms = 3000, ms = 34421
962974
11s: Delta ms = 11000, ms = 34421
963975
```
976+
977+
---
978+
979+
5. The following is the sample terminal output when running example [Change_Interval](examples/Change_Interval) to demonstrate how to change Timer Interval on-the-fly
980+
981+
```
982+
Starting Change_Interval on SAMD_NANO_33_IOT
983+
SAMDTimerInterrupt v1.1.1
984+
CPU Frequency = 48 MHz
985+
F_CPU (MHz) = 48, TIMER_HZ = 48
986+
TC_Timer::startTimer _Timer = 0x42002c00, TC3 = 0x42002c00
987+
Starting ITimer OK, millis() = 1131
988+
Time = 10001, TimerCount = 17
989+
Time = 20002, TimerCount = 37
990+
F_CPU (MHz) = 48, TIMER_HZ = 48
991+
TC_Timer::startTimer _Timer = 0x42002c00, TC3 = 0x42002c00
992+
Changing Interval, Timer = 1000
993+
Time = 30003, TimerCount = 47
994+
Time = 40004, TimerCount = 57
995+
F_CPU (MHz) = 48, TIMER_HZ = 48
996+
TC_Timer::startTimer _Timer = 0x42002c00, TC3 = 0x42002c00
997+
Changing Interval, Timer = 500
998+
Time = 50005, TimerCount = 77
999+
Time = 60006, TimerCount = 97
1000+
F_CPU (MHz) = 48, TIMER_HZ = 48
1001+
TC_Timer::startTimer _Timer = 0x42002c00, TC3 = 0x42002c00
1002+
Changing Interval, Timer = 1000
1003+
Time = 70007, TimerCount = 107
1004+
Time = 80008, TimerCount = 117
1005+
F_CPU (MHz) = 48, TIMER_HZ = 48
1006+
TC_Timer::startTimer _Timer = 0x42002c00, TC3 = 0x42002c00
1007+
Changing Interval, Timer = 500
1008+
Time = 90009, TimerCount = 137
1009+
Time = 100010, TimerCount = 157
1010+
F_CPU (MHz) = 48, TIMER_HZ = 48
1011+
TC_Timer::startTimer _Timer = 0x42002c00, TC3 = 0x42002c00
1012+
Changing Interval, Timer = 1000
1013+
Time = 110011, TimerCount = 167
1014+
Time = 120012, TimerCount = 177
1015+
F_CPU (MHz) = 48, TIMER_HZ = 48
1016+
TC_Timer::startTimer _Timer = 0x42002c00, TC3 = 0x42002c00
1017+
Changing Interval, Timer = 500
1018+
Time = 130013, TimerCount = 197
1019+
Time = 140014, TimerCount = 217
1020+
F_CPU (MHz) = 48, TIMER_HZ = 48
1021+
TC_Timer::startTimer _Timer = 0x42002c00, TC3 = 0x42002c00
1022+
Changing Interval, Timer = 1000
1023+
Time = 150015, TimerCount = 227
1024+
Time = 160016, TimerCount = 237
1025+
F_CPU (MHz) = 48, TIMER_HZ = 48
1026+
TC_Timer::startTimer _Timer = 0x42002c00, TC3 = 0x42002c00
1027+
Changing Interval, Timer = 500
1028+
Time = 170017, TimerCount = 257
1029+
Time = 180018, TimerCount = 277
1030+
F_CPU (MHz) = 48, TIMER_HZ = 48
1031+
TC_Timer::startTimer _Timer = 0x42002c00, TC3 = 0x42002c00
1032+
Changing Interval, Timer = 1000
1033+
Time = 190019, TimerCount = 287
1034+
Time = 200020, TimerCount = 297
1035+
1036+
```
1037+
9641038
---
9651039
---
9661040

1041+
### Releases v1.1.1
1042+
1043+
1. Add example [**Change_Interval**](examples/Change_Interval) and [**ISR_16_Timers_Array_Complex**](examples/ISR_16_Timers_Array_Complex)
1044+
2. Bump up version to sync with other TimerInterrupt Libraries. Modify Version String.
1045+
9671046
### Releases v1.0.1
9681047

9691048
1. Add complicated example [ISR_16_Timers_Array](examples/ISR_16_Timers_Array) utilizing and demonstrating the full usage of 16 independent ISR Timers.

examples/Argument_None/Argument_None.ino

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@
1919
Based on BlynkTimer.h
2020
Author: Volodymyr Shymanskyy
2121
22-
Version: 1.0.1
22+
Version: 1.1.1
2323
2424
Version Modified By Date Comments
2525
------- ----------- ---------- -----------
2626
1.0.0 K Hoang 30/10/2020 Initial coding
2727
1.0.1 K Hoang 06/11/2020 Add complicated example ISR_16_Timers_Array using all 16 independent ISR Timers.
28+
1.1.1 K.Hoang 06/12/2020 Add Change_Interval example. Bump up version to sync with other TimerInterrupt Libraries
2829
*****************************************************************************************************************************/
2930

3031
/*
@@ -152,7 +153,8 @@ void setup()
152153
delay(100);
153154

154155
Serial.println("\nStarting Argument_None on " + String(BOARD_NAME));
155-
Serial.println("Version : " + String(SAMD_TIMER_INTERRUPT_VERSION));
156+
Serial.println(SAMD_TIMER_INTERRUPT_VERSION);
157+
Serial.println("CPU Frequency = " + String(F_CPU / 1000000) + " MHz");
156158

157159
// Interval in microsecs
158160
if (ITimer0.attachInterruptInterval(TIMER0_INTERVAL_MS * 1000, TimerHandler0))
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
/****************************************************************************************************************************
2+
Change_Interval.ino
3+
For SAMD boards
4+
Written by Khoi Hoang
5+
6+
Built by Khoi Hoang https://github.com/khoih-prog/SAMD_TimerInterrupt
7+
Licensed under MIT license
8+
9+
Now even you use all these new 16 ISR-based timers,with their maximum interval practically unlimited (limited only by
10+
unsigned long miliseconds), you just consume only one SAMD timer and avoid conflicting with other cores' tasks.
11+
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
12+
Therefore, their executions are not blocked by bad-behaving functions / tasks.
13+
This important feature is absolutely necessary for mission-critical tasks.
14+
15+
Based on SimpleTimer - A timer library for Arduino.
16+
17+
Copyright (c) 2010 OTTOTECNICA Italy
18+
19+
Based on BlynkTimer.h
20+
Author: Volodymyr Shymanskyy
21+
22+
Version: 1.1.1
23+
24+
Version Modified By Date Comments
25+
------- ----------- ---------- -----------
26+
1.0.0 K Hoang 30/10/2020 Initial coding
27+
1.0.1 K Hoang 06/11/2020 Add complicated example ISR_16_Timers_Array using all 16 independent ISR Timers.
28+
1.1.1 K.Hoang 06/12/2020 Add Change_Interval example. Bump up version to sync with other TimerInterrupt Libraries
29+
*****************************************************************************************************************************/
30+
31+
/*
32+
Notes:
33+
Special design is necessary to share data between interrupt code and the rest of your program.
34+
Variables usually need to be "volatile" types. Volatile tells the compiler to avoid optimizations that assume
35+
variable can not spontaneously change. Because your function may change variables while your program is using them,
36+
the compiler needs this hint. But volatile alone is often not enough.
37+
When accessing shared variables, usually interrupts must be disabled. Even with volatile,
38+
if the interrupt changes a multi-byte variable between a sequence of instructions, it can be read incorrectly.
39+
If your data is multiple variables, such as an array and a count, usually interrupts need to be disabled
40+
or the entire sequence of your code which accesses the data.
41+
*/
42+
43+
#if !( defined(ARDUINO_SAMD_ZERO) || defined(ARDUINO_SAMD_MKR1000) || defined(ARDUINO_SAMD_MKRWIFI1010) \
44+
|| defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_SAMD_MKRFox1200) || defined(ARDUINO_SAMD_MKRWAN1300) || defined(ARDUINO_SAMD_MKRWAN1310) \
45+
|| defined(ARDUINO_SAMD_MKRGSM1400) || defined(ARDUINO_SAMD_MKRNB1500) || defined(ARDUINO_SAMD_MKRVIDOR4000) || defined(__SAMD21G18A__) \
46+
|| defined(ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS) || defined(__SAMD21E18A__) || defined(__SAMD51__) || defined(__SAMD51J20A__) || defined(__SAMD51J19A__) \
47+
|| defined(__SAMD51G19A__) || defined(__SAMD51P19A__) || defined(__SAMD21G18A__) )
48+
#error This code is designed to run on SAMD21/SAMD51 platform! Please check your Tools->Board setting.
49+
#endif
50+
51+
// These define's must be placed at the beginning before #include "SAMDTimerInterrupt.h"
52+
// Don't define SAMD_TIMER_INTERRUPT_DEBUG > 2. Only for special ISR debugging only. Can hang the system.
53+
#define SAMD_TIMER_INTERRUPT_DEBUG 1
54+
55+
#include "SAMDTimerInterrupt.h"
56+
57+
//#ifndef LED_BUILTIN
58+
// #define LED_BUILTIN 13
59+
//#endif
60+
61+
#define TIMER_INTERVAL_MS 500 //1000
62+
63+
volatile uint32_t TimerCount = 0;
64+
65+
// Depending on the board, you can select SAMD21 Hardware Timer from TC3-TCC
66+
// SAMD21 Hardware Timer from TC3 or TCC
67+
// SAMD51 Hardware Timer only TC3
68+
69+
// Init SAMD timer TIMER_TC3
70+
SAMDTimer ITimer(TIMER_TC3);
71+
72+
void printResult(uint32_t currTime)
73+
{
74+
Serial.println("Time = " + String(currTime) + ", TimerCount = " + String(TimerCount));
75+
}
76+
77+
void TimerHandler(void)
78+
{
79+
static bool toggle = false;
80+
81+
// Flag for checking to be sure ISR is working as SErial.print is not OK here in ISR
82+
TimerCount++;
83+
84+
//timer interrupt toggles pin LED_BUILTIN
85+
digitalWrite(LED_BUILTIN, toggle);
86+
toggle = !toggle;
87+
}
88+
89+
void setup()
90+
{
91+
pinMode(LED_BUILTIN, OUTPUT);
92+
93+
Serial.begin(115200);
94+
while (!Serial);
95+
96+
delay(100);
97+
98+
Serial.println("\nStarting Change_Interval on " + String(BOARD_NAME));
99+
Serial.println(SAMD_TIMER_INTERRUPT_VERSION);
100+
Serial.println("CPU Frequency = " + String(F_CPU / 1000000) + " MHz");
101+
102+
// Interval in microsecs
103+
if (ITimer.attachInterruptInterval(TIMER_INTERVAL_MS * 1000, TimerHandler))
104+
{
105+
Serial.println("Starting ITimer OK, millis() = " + String(millis()));
106+
}
107+
else
108+
Serial.println("Can't set ITimer. Select another freq. or timer");
109+
}
110+
111+
#define CHECK_INTERVAL_MS 10000L
112+
#define CHANGE_INTERVAL_MS 20000L
113+
114+
void loop()
115+
{
116+
static uint32_t lastTime = 0;
117+
static uint32_t lastChangeTime = 0;
118+
static uint32_t currTime;
119+
static uint32_t multFactor = 0;
120+
121+
currTime = millis();
122+
123+
if (currTime - lastTime > CHECK_INTERVAL_MS)
124+
{
125+
printResult(currTime);
126+
lastTime = currTime;
127+
128+
if (currTime - lastChangeTime > CHANGE_INTERVAL_MS)
129+
{
130+
//setInterval(unsigned long interval, timerCallback callback)
131+
multFactor = (multFactor + 1) % 2;
132+
133+
ITimer.setInterval(TIMER_INTERVAL_MS * 1000 * (multFactor + 1), TimerHandler);
134+
135+
Serial.println("Changing Interval, Timer = " + String(TIMER_INTERVAL_MS * (multFactor + 1)));
136+
137+
lastChangeTime = currTime;
138+
}
139+
}
140+
}

examples/ISR_16_Timers_Array/ISR_16_Timers_Array.ino

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@
1919
Based on BlynkTimer.h
2020
Author: Volodymyr Shymanskyy
2121
22-
Version: 1.0.1
22+
Version: 1.1.1
2323
2424
Version Modified By Date Comments
2525
------- ----------- ---------- -----------
2626
1.0.0 K Hoang 30/10/2020 Initial coding
2727
1.0.1 K Hoang 06/11/2020 Add complicated example ISR_16_Timers_Array using all 16 independent ISR Timers.
28+
1.1.1 K.Hoang 06/12/2020 Add Change_Interval example. Bump up version to sync with other TimerInterrupt Libraries
2829
*****************************************************************************************************************************/
2930
/*
3031
Notes:
@@ -425,7 +426,7 @@ void setup()
425426
while (!Serial);
426427

427428
Serial.println("\nStarting ISR_16_Timers_Array on " + String(BOARD_NAME));
428-
Serial.println("Version : " + String(SAMD_TIMER_INTERRUPT_VERSION));
429+
Serial.println(SAMD_TIMER_INTERRUPT_VERSION);
429430
Serial.println("CPU Frequency = " + String(F_CPU / 1000000) + " MHz");
430431

431432
// Interval in microsecs

0 commit comments

Comments
 (0)