You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 29, 2023. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+25-8Lines changed: 25 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,19 +1,18 @@
1
-
# Arduino TimerInterrupt Library
1
+
# Arduino TimerInterrupt Library (now included in Arduino Library Manager)
2
2
3
3
This library enables you to use Interrupt from Hardware Timers on an Arduino, such as Nano, UNO, Mega, etc.
4
4
5
5
Why do we need this Hardware Timer Interrupt?
6
6
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().
9
8
10
9
So your function might not be executed, and the result would be disastrous.
11
10
12
11
You'd prefer to have your function called, no matter what happening with other functions (busy loop, bug, etc.).
13
12
14
13
The correct choice is to use a Hardware Timer with Interrupt to call your function.
15
14
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.
17
16
18
17
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.
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.
28
27
29
28
## Installation
30
-
1. Navigate to (https://github.com/khoih-prog/TimerInterrupt/releases) page.
29
+
1. Navigate to (https://github.com/khoih-prog/TimerInterrupt) page.
31
30
2. Download the latest release `TimerInterrupt-master.zip`.
32
31
3. Extract the zip file to `TimerInterrupt-master` directory
33
32
4. Copy whole folder to Arduino libraries' directory such as `.Arduino/libraries/TimerInterrupt-master`.
34
33
34
+
You now can also use Arduino Library Manager to install. Search for `TimerInterrupt`.
35
+
35
36
## More useful Information
36
37
37
38
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.
51
52
4. Timer3, Timer4, Timer5:
52
53
Timer 3,4,5 are only available on Arduino Mega boards. These timers are all 16bit timers.
53
54
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
+
54
70
## Supported Arduino Boards
55
71
- Arduino Uno / Mega / Leonardo / Duemilanove / Diecimila / LilyPad / Mini / Fio / Nano etc.
0 commit comments