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

Commit d3249cb

Browse files
authored
Add files via upload
1 parent 5a40ef1 commit d3249cb

File tree

19 files changed

+3167
-56
lines changed

19 files changed

+3167
-56
lines changed

README.md

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
# Arduino TimerInterrupt Library
1+
# Arduino TimerInterrupt Library (now included in Arduino Library Manager)
22

33
This library enables you to use Interrupt from Hardware Timers on an Arduino, such as Nano, UNO, Mega, etc.
44

55
Why do we need this Hardware Timer Interrupt?
66

7-
Imagine you have a system with a mission-critical function, measuring water level and control the sump pump or doing something much more important.
8-
You normally use a software timer to poll, or even place the function in loop(). But what if another function is blocking the loop() or setup().
7+
Imagine you have a system with a mission-critical function, measuring water level and control the sump pump or doing something much more important. You normally use a software timer to poll, or even place the function in loop(). But what if another function is blocking the loop() or setup().
98

109
So your function might not be executed, and the result would be disastrous.
1110

1211
You'd prefer to have your function called, no matter what happening with other functions (busy loop, bug, etc.).
1312

1413
The correct choice is to use a Hardware Timer with Interrupt to call your function.
1514

16-
These hardware timers, using interrupt, still works even if other functions is blocking. Moreover, they are much more precise (certainly depending on clock frequency accurary) than other software timers using millis() or micros(). That's necessary if you need to measure some data with better accuracy.
15+
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.
1716

1817
Functions using normal software timers, relying on loop() and calling millis(), won't work if the loop() or setup() is blocked by certain operation. For example, certain function is blocking while it's connecting to WiFi or some services.
1918

@@ -27,11 +26,13 @@ https://www.arduino.cc/reference/en/language/functions/external-interrupts/attac
2726
2. Typically global variables are used to pass data between an ISR and the main program. To make sure variables shared between an ISR and the main program are updated correctly, declare them as volatile.
2827

2928
## Installation
30-
1. Navigate to (https://github.com/khoih-prog/TimerInterrupt/releases) page.
29+
1. Navigate to (https://github.com/khoih-prog/TimerInterrupt) page.
3130
2. Download the latest release `TimerInterrupt-master.zip`.
3231
3. Extract the zip file to `TimerInterrupt-master` directory
3332
4. Copy whole folder to Arduino libraries' directory such as `.Arduino/libraries/TimerInterrupt-master`.
3433

34+
You now can also use Arduino Library Manager to install. Search for `TimerInterrupt`.
35+
3536
## More useful Information
3637

3738
From https://www.robotshop.com/community/forum/t/arduino-101-timers-and-interrupts/13072
@@ -51,6 +52,21 @@ In the Arduino work the tone() function uses Timer2.
5152
4. Timer3, Timer4, Timer5:
5253
Timer 3,4,5 are only available on Arduino Mega boards. These timers are all 16bit timers.
5354

55+
## New from v1.0.2
56+
57+
Now with these new `16 ISR-based timers`, the maximum interval is practically unlimited (limited only by unsigned long miliseconds)
58+
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
59+
Therefore, their executions are not blocked by bad-behaving functions / tasks.
60+
This important feature is absolutely necessary for mission-critical tasks.
61+
62+
The `ISR_Timer_Complex` example will demonstrate the nearly perfect accuracy compared to software timers by printing the actual
63+
elapsed millisecs of each type of timers.
64+
Being ISR-based timers, their executions are not blocked by bad-behaving functions / tasks, such as connecting to WiFi, Internet
65+
and Blynk services. You can also have many `(up to 16)` timers to use.
66+
This non-being-blocked important feature is absolutely necessary for mission-critical tasks.
67+
You'll see blynkTimer Software is blocked while system is connecting to WiFi / Internet / Blynk, as well as by blocking task
68+
in loop(), using delay() function as an example. The elapsed time then is very unaccurate
69+
5470
## Supported Arduino Boards
5571
- Arduino Uno / Mega / Leonardo / Duemilanove / Diecimila / LilyPad / Mini / Fio / Nano etc.
5672
- Teensy 1.0 / 1.0++ / 2.0 / 2++ / 3.0 / 3.1 / Teensy-LC;
@@ -151,21 +167,22 @@ void loop()
151167
```
152168
## TO DO
153169

154-
1. Similar library for ESP8266 and ESP32
170+
1. Similar library for ESP32
171+
2. Search for bug and improvement.
155172

156173

157174
## DONE
158175

159-
For current version v1.0.1
176+
For current version v1.0.2
160177

161178
1. Longer Interval for timers.
162179
2. Reduce code size if use less timers. Eliminate compiler warnings.
163180
3. Now supporting complex object pointer-type argument.
181+
3. 16 hardware-initiated software-enabled timers while using only 1 hardware timer.
164182
4. Fix some bugs in v1.0.0
165183
5. Add more examples.
166184

167185

168-
169186
## Contributing
170187
If you want to contribute to this project:
171188
- Report bugs and errors

examples/Argument_Complex/Argument_Complex.ino

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
/************************************************
2-
* TimerInterruptTest.ino
1+
/****************************************************************************************************************************
2+
* examples/Argument_Complex.ino
33
* For Arduino AVR boards
44
* Written by Khoi Hoang
55
*
66
* Built by Khoi Hoang https://github.com/khoih-prog/TimerInterrupt
77
* Licensed under MIT license
8-
* Version: v1.0.1
8+
* Version: v1.0.2
9+
*
10+
* Now we can use these new 16 ISR-based timers, while consuming only 1 hardware Timer.
11+
* Their independently-selected, maximum interval is practically unlimited (limited only by unsigned long miliseconds)
12+
* The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
13+
* Therefore, their executions are not blocked by bad-behaving functions / tasks.
14+
* This important feature is absolutely necessary for mission-critical tasks.
915
*
1016
* Notes:
1117
* Special design is necessary to share data between interrupt code and the rest of your program.
@@ -16,8 +22,13 @@
1622
* if the interrupt changes a multi-byte variable between a sequence of instructions, it can be read incorrectly.
1723
* If your data is multiple variables, such as an array and a count, usually interrupts need to be disabled
1824
* or the entire sequence of your code which accesses the data.
19-
*
20-
************************************************/
25+
*
26+
* Version Modified By Date Comments
27+
* ------- ----------- ---------- -----------
28+
* 1.0.0 K Hoang 23/11/2019 Initial coding
29+
* 1.0.1 K Hoang 25/11/2019 New release fixing compiler error
30+
* 1.0.2 K.Hoang 28/11/2019 Permit up to 16 super-long-time, super-accurate ISR-based timers to avoid being blocked
31+
*****************************************************************************************************************************/
2132
//These define's must be placed at the beginning before #include "TimerInterrupt.h"
2233
#define TIMER_INTERRUPT_DEBUG 0
2334

examples/Argument_None/Argument_None.ino

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
/************************************************
1+
/****************************************************************************************************************************
22
* examples/Argument_None.ino
33
* For Arduino AVR boards
44
* Written by Khoi Hoang
55
*
66
* Built by Khoi Hoang https://github.com/khoih-prog/TimerInterrupt
77
* Licensed under MIT license
8-
* Version: v1.0.1
8+
* Version: v1.0.2
9+
*
10+
* Now we can use these new 16 ISR-based timers, while consuming only 1 hardware Timer.
11+
* Their independently-selected, maximum interval is practically unlimited (limited only by unsigned long miliseconds)
12+
* The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
13+
* Therefore, their executions are not blocked by bad-behaving functions / tasks.
14+
* This important feature is absolutely necessary for mission-critical tasks.
915
*
1016
* Notes:
1117
* Special design is necessary to share data between interrupt code and the rest of your program.
@@ -17,7 +23,12 @@
1723
* If your data is multiple variables, such as an array and a count, usually interrupts need to be disabled
1824
* or the entire sequence of your code which accesses the data.
1925
*
20-
************************************************/
26+
* Version Modified By Date Comments
27+
* ------- ----------- ---------- -----------
28+
* 1.0.0 K Hoang 23/11/2019 Initial coding
29+
* 1.0.1 K Hoang 25/11/2019 New release fixing compiler error
30+
* 1.0.2 K.Hoang 28/11/2019 Permit up to 16 super-long-time, super-accurate ISR-based timers to avoid being blocked
31+
*****************************************************************************************************************************/
2132
//These define's must be placed at the beginning before #include "TimerInterrupt.h"
2233
#define TIMER_INTERRUPT_DEBUG 0
2334

examples/Argument_Simple/Argument_Simple.ino

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
/************************************************
1+
/****************************************************************************************************************************
22
* examples/Argument_Simple.ino
33
* For Arduino AVR boards
44
* Written by Khoi Hoang
55
*
66
* Built by Khoi Hoang https://github.com/khoih-prog/TimerInterrupt
77
* Licensed under MIT license
8-
* Version: v1.0.1
8+
* Version: v1.0.2
9+
*
10+
* Now we can use these new 16 ISR-based timers, while consuming only 1 hardware Timer.
11+
* Their independently-selected, maximum interval is practically unlimited (limited only by unsigned long miliseconds)
12+
* The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
13+
* Therefore, their executions are not blocked by bad-behaving functions / tasks.
14+
* This important feature is absolutely necessary for mission-critical tasks.
915
*
1016
* Notes:
1117
* Special design is necessary to share data between interrupt code and the rest of your program.
@@ -17,7 +23,12 @@
1723
* If your data is multiple variables, such as an array and a count, usually interrupts need to be disabled
1824
* or the entire sequence of your code which accesses the data.
1925
*
20-
************************************************/
26+
* Version Modified By Date Comments
27+
* ------- ----------- ---------- -----------
28+
* 1.0.0 K Hoang 23/11/2019 Initial coding
29+
* 1.0.1 K Hoang 25/11/2019 New release fixing compiler error
30+
* 1.0.2 K.Hoang 28/11/2019 Permit up to 16 super-long-time, super-accurate ISR-based timers to avoid being blocked
31+
*****************************************************************************************************************************/
2132
//These define's must be placed at the beginning before #include "TimerInterrupt.h"
2233
#define TIMER_INTERRUPT_DEBUG 0
2334

examples/ISR_RPM_Measure/ISR_RPM_Measure.ino

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
/************************************************
1+
/****************************************************************************************************************************
22
* RPM_Measure.ino
33
* For Arduino AVR boards
44
* Written by Khoi Hoang
55
*
66
* Built by Khoi Hoang https://github.com/khoih-prog/TimerInterrupt
77
* Licensed under MIT license
8-
* Version: v1.0.1
8+
* Version: v1.0.2
9+
*
10+
* Now we can use these new 16 ISR-based timers, while consuming only 1 hardware Timer.
11+
* Their independently-selected, maximum interval is practically unlimited (limited only by unsigned long miliseconds)
12+
* The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers
13+
* Therefore, their executions are not blocked by bad-behaving functions / tasks.
14+
* This important feature is absolutely necessary for mission-critical tasks.
915
*
1016
* Notes:
1117
* Special design is necessary to share data between interrupt code and the rest of your program.
@@ -17,7 +23,12 @@
1723
* If your data is multiple variables, such as an array and a count, usually interrupts need to be disabled
1824
* or the entire sequence of your code which accesses the data.
1925
*
20-
************************************************/
26+
* Version Modified By Date Comments
27+
* ------- ----------- ---------- -----------
28+
* 1.0.0 K Hoang 23/11/2019 Initial coding
29+
* 1.0.1 K Hoang 25/11/2019 New release fixing compiler error
30+
* 1.0.2 K.Hoang 28/11/2019 Permit up to 16 super-long-time, super-accurate ISR-based timers to avoid being blocked
31+
*****************************************************************************************************************************/
2132
/* RPM Measuring uses high frequency hardware timer 1Hz == 1ms) to measure the time from of one rotation, in ms
2233
* then convert to RPM. One rotation is detected by reading the state of a magnetic REED SW or IR LED Sensor
2334
* Asssuming LOW is active.

0 commit comments

Comments
 (0)