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

Commit 6fe3dee

Browse files
authored
v1.1.1
### Releases v1.1.1 1. Add [**Change_Interval**](examples/Change_Interval) example to show how to change TimerInterval on-the-fly 2. Add Version String
1 parent 15f11cc commit 6fe3dee

23 files changed

+289
-34
lines changed

README.md

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ The catch is **your function is now part of an ISR (Interrupt Service Routine),
4242
---
4343
---
4444

45+
### Releases v1.1.1
46+
47+
1. Add [**Change_Interval**](examples/Change_Interval) example to show how to change TimerInterval on-the-fly
48+
2. Add Version String
49+
4550
### Releases v1.1.0
4651

4752
1. Restore cpp code besides Impl.h code to use if Multiple-Definition linker error.
@@ -64,7 +69,7 @@ The catch is **your function is now part of an ISR (Interrupt Service Routine),
6469
---
6570
---
6671

67-
## Prerequisite
72+
## Prerequisites
6873

6974
1. [`Arduino IDE 1.8.13+`](https://www.arduino.cc/en/Main/Software)
7075
2. [`ESP8266 core 2.7.4+`](https://github.com/esp8266/Arduino#installing-with-boards-manager) for ESP8266 boards.
@@ -92,7 +97,7 @@ Another way to install is to:
9297

9398
1. Install [VS Code](https://code.visualstudio.com/)
9499
2. Install [PlatformIO](https://platformio.org/platformio-ide)
95-
3. Install [**ESP8266TimerInterrupt** library](https://platformio.org/lib/show/6901/ESP8266TimerInterrupt) by using [Library Manager](https://platformio.org/lib/show/6901/ESP8266TimerInterrupt/installation). Search for **ESP8266TimerInterrupt** in [Platform.io Author's Libraries](https://platformio.org/lib/search?query=author:%22Khoi%20Hoang%22)
100+
3. Install [**ESP8266TimerInterrupt** library](https://platformio.org/lib/show/11385/ESP8266TimerInterrupt) or [**ESP8266TimerInterrupt** library](https://platformio.org/lib/show/6901/ESP8266TimerInterrupt) by using [Library Manager](https://platformio.org/lib/show/11385/ESP8266TimerInterrupt/installation). Search for **ESP8266TimerInterrupt** in [Platform.io Author's Libraries](https://platformio.org/lib/search?query=author:%22Khoi%20Hoang%22)
96101
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)
97102

98103
---
@@ -188,6 +193,7 @@ Please have a look at [ESP8266TimerInterrupt Issue 8: **ESP8266Timer and PWM -->
188193
8. [RPM_Measure](examples/RPM_Measure)
189194
9. [SwitchDebounce](examples/SwitchDebounce)
190195
10. [TimerInterruptTest](examples/TimerInterruptTest)
196+
11. [**Change_Interval**](examples/Change_Interval). New.
191197

192198
---
193199
---
@@ -333,6 +339,7 @@ void setup()
333339
delay(200);
334340

335341
Serial.println("\nStarting ISR_Timer_Complex on " + String(ARDUINO_BOARD));
342+
Serial.println(ESP8266_TIMER_INTERRUPT_VERSION);
336343
Serial.println("CPU Frequency = " + String(F_CPU / 1000000) + " MHz");
337344

338345
// Interval in microsecs
@@ -405,6 +412,7 @@ While software timer, **programmed for 2s, is activated after 4.258s !!!**
405412
406413
```
407414
Starting ISR_Timer_Complex on ESP8266_NODEMCU
415+
ESP8266TimerInterrupt v1.1.1
408416
CPU Frequency = 160 MHz
409417
ESP8266TimerInterrupt: _fre = 312500.00, _count = 15625
410418
Starting ITimer OK, millis() = 64
@@ -450,6 +458,7 @@ doingSomething10s: Delta ms = 10000
450458
451459
```
452460
Starting TimerInterruptTest on ESP8266_NODEMCU
461+
ESP8266TimerInterrupt v1.1.1
453462
CPU Frequency = 160 MHz
454463
ESP8266TimerInterrupt: _fre = 312500.00, _count = 312500
455464
Starting ITimer OK, millis() = 262
@@ -473,9 +482,51 @@ Delta ms = 1000
473482

474483
```
475484
485+
---
486+
487+
3. 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
488+
489+
```
490+
Starting Change_Interval on ESP8266_NODEMCU
491+
ESP8266TimerInterrupt v1.1.1
492+
CPU Frequency = 160 MHz
493+
Starting ITimer OK, millis() = 162
494+
Time = 10001, TimerCount = 19
495+
Time = 20002, TimerCount = 39
496+
Changing Interval, Timer = 1000
497+
Time = 30003, TimerCount = 49
498+
Time = 40004, TimerCount = 59
499+
Changing Interval, Timer = 500
500+
Time = 50005, TimerCount = 79
501+
Time = 60006, TimerCount = 99
502+
Changing Interval, Timer = 1000
503+
Time = 70007, TimerCount = 109
504+
Time = 80008, TimerCount = 119
505+
Changing Interval, Timer = 500
506+
Time = 90009, TimerCount = 139
507+
Time = 100010, TimerCount = 159
508+
Changing Interval, Timer = 1000
509+
Time = 110011, TimerCount = 169
510+
Time = 120012, TimerCount = 179
511+
Changing Interval, Timer = 500
512+
Time = 130013, TimerCount = 199
513+
Time = 140014, TimerCount = 219
514+
Changing Interval, Timer = 1000
515+
Time = 150015, TimerCount = 229
516+
Time = 160016, TimerCount = 239
517+
Changing Interval, Timer = 500
518+
Time = 170017, TimerCount = 259
519+
Time = 180018, TimerCount = 279
520+
```
521+
476522
---
477523
---
478524
525+
### Releases v1.1.1
526+
527+
1. Add [**Change_Interval**](examples/Change_Interval) example to show how to change TimerInterval on-the-fly
528+
2. Add Version String
529+
479530
### Releases v1.1.0
480531
481532
1. Restore cpp code besides Impl.h code to use if Multiple-Definition linker error.

examples/Argument_None/Argument_None.ino

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
Based on BlynkTimer.h
2424
Author: Volodymyr Shymanskyy
2525
26-
Version: 1.1.0
26+
Version: 1.1.1
2727
2828
Version Modified By Date Comments
2929
------- ----------- ---------- -----------
@@ -32,6 +32,7 @@
3232
1.0.2 K.Hoang 26/11/2019 Permit up to 16 super-long-time, super-accurate ISR-based timers to avoid being blocked
3333
1.0.3 K.Hoang 17/05/2020 Restructure code. Fix example. Enhance README.
3434
1.1.0 K.Hoang 27/10/2020 Restore cpp code besides Impl.h code to use if Multiple-Definition linker error.
35+
1.1.1 K.Hoang 06/12/2020 Add Version String and Change_Interval example to show how to change TimerInterval
3536
*****************************************************************************************************************************/
3637

3738
/* Notes:
@@ -55,7 +56,7 @@
5556
#include "ESP8266TimerInterrupt.h"
5657

5758
#ifndef LED_BUILTIN
58-
#define LED_BUILTIN 2 // Pin D4 mapped to pin GPIO2/TXD1 of ESP8266, NodeMCU and WeMoS, control on-board LED
59+
#define LED_BUILTIN 2 // Pin D4 mapped to pin GPIO2/TXD1 of ESP8266, NodeMCU and WeMoS, control on-board LED
5960
#endif
6061

6162
volatile uint32_t lastMillis = 0;
@@ -83,7 +84,7 @@ void ICACHE_RAM_ATTR TimerHandler(void)
8384

8485
#define TIMER_INTERVAL_MS 1000
8586

86-
// Init ESP32 timer 0
87+
// Init ESP8266Timer
8788
ESP8266Timer ITimer;
8889

8990

@@ -95,6 +96,7 @@ void setup()
9596
delay(200);
9697

9798
Serial.println("\nStarting Argument_None on " + String(ARDUINO_BOARD));
99+
Serial.println(ESP8266_TIMER_INTERRUPT_VERSION);
98100
Serial.println("CPU Frequency = " + String(F_CPU / 1000000) + " MHz");
99101

100102
// Interval in microsecs
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
/****************************************************************************************************************************
2+
Change_Interval.ino
3+
For NRF52 boards using mbed-RTOS such as Nano-33-BLE
4+
Written by Khoi Hoang
5+
6+
Built by Khoi Hoang https://github.com/khoih-prog/NRF52_MBED_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 NRF52 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+
Author: mromani@ottotecnica.com
17+
Copyright (c) 2010 OTTOTECNICA Italy
18+
19+
Based on BlynkTimer.h
20+
Author: Volodymyr Shymanskyy
21+
22+
Version: 1.0.2
23+
24+
Version Modified By Date Comments
25+
------- ----------- ---------- -----------
26+
1.0.1 K Hoang 22/11/2020 Initial coding and sync with NRF52_TimerInterrupt
27+
1.0.2 K Hoang 23/11/2020 Add and optimize examples
28+
*****************************************************************************************************************************/
29+
30+
/*
31+
Notes:
32+
Special design is necessary to share data between interrupt code and the rest of your program.
33+
Variables usually need to be "volatile" types. Volatile tells the compiler to avoid optimizations that assume
34+
variable can not spontaneously change. Because your function may change variables while your program is using them,
35+
the compiler needs this hint. But volatile alone is often not enough.
36+
When accessing shared variables, usually interrupts must be disabled. Even with volatile,
37+
if the interrupt changes a multi-byte variable between a sequence of instructions, it can be read incorrectly.
38+
If your data is multiple variables, such as an array and a count, usually interrupts need to be disabled
39+
or the entire sequence of your code which accesses the data.
40+
*/
41+
42+
#if !( ARDUINO_ARCH_NRF52840 && TARGET_NAME == ARDUINO_NANO33BLE )
43+
#error This code is designed to run on nRF52-based Nano-33-BLE boards using mbed-RTOS platform! Please check your Tools->Board setting.
44+
#endif
45+
46+
// These define's must be placed at the beginning before #include "NRF52TimerInterrupt.h"
47+
// For Nano33-BLE, don't use Serial.print() in ISR as system will definitely hang.
48+
#define NRF52_MBED_TIMER_INTERRUPT_DEBUG 0
49+
50+
#include "NRF52_MBED_TimerInterrupt.h"
51+
52+
//#ifndef LED_BUILTIN
53+
// #define LED_BUILTIN D13
54+
//#endif
55+
56+
#ifndef LED_BLUE_PIN
57+
#define LED_BLUE_PIN D7
58+
#endif
59+
60+
#ifndef LED_RED_PIN
61+
#define LED_RED_PIN D8
62+
#endif
63+
64+
#define TIMER0_INTERVAL_MS 500 //1000
65+
#define TIMER1_INTERVAL_MS 2000
66+
67+
volatile uint32_t Timer0Count = 0;
68+
volatile uint32_t Timer1Count = 0;
69+
70+
// Depending on the board, you can select NRF52 Hardware Timer from NRF_TIMER_1,NRF_TIMER_3,NRF_TIMER_4 (1,3 and 4)
71+
// If you select the already-used NRF_TIMER_0 or NRF_TIMER_2, it'll be auto modified to use NRF_TIMER_1
72+
73+
// Init NRF52 timer NRF_TIMER1
74+
NRF52_MBED_Timer ITimer0(NRF_TIMER_4);
75+
76+
// Init NRF52 timer NRF_TIMER3
77+
NRF52_MBED_Timer ITimer1(NRF_TIMER_3);
78+
79+
void printResult(uint32_t currTime)
80+
{
81+
Serial.printf("Time = %ld, Timer0Count = %lu, , Timer1Count = %lu\n", currTime, Timer0Count, Timer1Count);
82+
}
83+
84+
void TimerHandler0(void)
85+
{
86+
static bool toggle0 = false;
87+
88+
// Flag for checking to be sure ISR is working as SErial.print is not OK here in ISR
89+
Timer0Count++;
90+
91+
//timer interrupt toggles pin LED_BUILTIN
92+
digitalWrite(LED_BUILTIN, toggle0);
93+
toggle0 = !toggle0;
94+
}
95+
96+
void TimerHandler1(void)
97+
{
98+
static bool toggle1 = false;
99+
100+
// Flag for checking to be sure ISR is working as Serial.print is not OK here in ISR
101+
Timer1Count++;
102+
103+
//timer interrupt toggles outputPin
104+
digitalWrite(LED_BLUE_PIN, toggle1);
105+
toggle1 = !toggle1;
106+
}
107+
108+
void setup()
109+
{
110+
pinMode(LED_BUILTIN, OUTPUT);
111+
pinMode(LED_BLUE_PIN, OUTPUT);
112+
113+
Serial.begin(115200);
114+
while (!Serial);
115+
116+
delay(100);
117+
118+
Serial.printf("\nStarting Change_Interval on %s\n", BOARD_NAME);
119+
Serial.printf("Version : v%s\n", NRF52_MBED_TIMER_INTERRUPT_VERSION);
120+
121+
// Interval in microsecs
122+
if (ITimer0.attachInterruptInterval(TIMER0_INTERVAL_MS * 1000, TimerHandler0))
123+
{
124+
Serial.printf("Starting ITimer0 OK, millis() = %ld\n", millis());
125+
}
126+
else
127+
Serial.println("Can't set ITimer0. Select another freq. or timer");
128+
129+
// Interval in microsecs
130+
if (ITimer1.attachInterruptInterval(TIMER1_INTERVAL_MS * 1000, TimerHandler1))
131+
{
132+
Serial.printf("Starting ITimer1 OK, millis() = %ld\n", millis());
133+
}
134+
else
135+
Serial.println("Can't set ITimer1. Select another freq. or timer");
136+
}
137+
138+
#define CHECK_INTERVAL_MS 10000L
139+
#define CHANGE_INTERVAL_MS 20000L
140+
141+
void loop()
142+
{
143+
static uint32_t lastTime = 0;
144+
static uint32_t lastChangeTime = 0;
145+
static uint32_t currTime;
146+
static uint32_t multFactor = 0;
147+
148+
currTime = millis();
149+
150+
if (currTime - lastTime > CHECK_INTERVAL_MS)
151+
{
152+
printResult(currTime);
153+
lastTime = currTime;
154+
155+
if (currTime - lastChangeTime > CHANGE_INTERVAL_MS)
156+
{
157+
//setInterval(unsigned long interval, timerCallback callback)
158+
multFactor = (multFactor + 1) % 2;
159+
160+
ITimer0.setInterval(TIMER0_INTERVAL_MS * 1000 * (multFactor + 1), TimerHandler0);
161+
ITimer1.setInterval(TIMER1_INTERVAL_MS * 1000 * (multFactor + 1), TimerHandler1);
162+
163+
Serial.printf("Changing Interval, Timer0 = %lu, Timer1 = %lu\n", TIMER0_INTERVAL_MS * (multFactor + 1), TIMER1_INTERVAL_MS * (multFactor + 1));
164+
165+
lastChangeTime = currTime;
166+
}
167+
}
168+
}

examples/ISR_RPM_Measure/ISR_RPM_Measure.ino

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
Based on BlynkTimer.h
2424
Author: Volodymyr Shymanskyy
2525
26-
Version: 1.1.0
26+
Version: 1.1.1
2727
2828
Version Modified By Date Comments
2929
------- ----------- ---------- -----------
@@ -32,6 +32,7 @@
3232
1.0.2 K.Hoang 26/11/2019 Permit up to 16 super-long-time, super-accurate ISR-based timers to avoid being blocked
3333
1.0.3 K.Hoang 17/05/2020 Restructure code. Fix example. Enhance README.
3434
1.1.0 K.Hoang 27/10/2020 Restore cpp code besides Impl.h code to use if Multiple-Definition linker error.
35+
1.1.1 K.Hoang 06/12/2020 Add Version String and Change_Interval example to show how to change TimerInterval
3536
*****************************************************************************************************************************/
3637

3738
/* Notes:
@@ -143,6 +144,7 @@ void setup()
143144
delay(200);
144145

145146
Serial.println("\nStarting ISR_RPM_Measure on " + String(ARDUINO_BOARD));
147+
Serial.println(ESP8266_TIMER_INTERRUPT_VERSION);
146148
Serial.println("CPU Frequency = " + String(F_CPU / 1000000) + " MHz");
147149

148150
// Interval in microsecs

examples/ISR_Switch/ISR_Switch.ino

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
Based on BlynkTimer.h
2424
Author: Volodymyr Shymanskyy
2525
26-
Version: 1.1.0
26+
Version: 1.1.1
2727
2828
Version Modified By Date Comments
2929
------- ----------- ---------- -----------
@@ -32,6 +32,7 @@
3232
1.0.2 K.Hoang 26/11/2019 Permit up to 16 super-long-time, super-accurate ISR-based timers to avoid being blocked
3333
1.0.3 K.Hoang 17/05/2020 Restructure code. Fix example. Enhance README.
3434
1.1.0 K.Hoang 27/10/2020 Restore cpp code besides Impl.h code to use if Multiple-Definition linker error.
35+
1.1.1 K.Hoang 06/12/2020 Add Version String and Change_Interval example to show how to change TimerInterval
3536
*****************************************************************************************************************************/
3637
/* Notes:
3738
Special design is necessary to share data between interrupt code and the rest of your program.
@@ -87,9 +88,11 @@ char auth[] = "****";
8788
char ssid[] = "****";
8889
char pass[] = "****";
8990

90-
// These define's must be placed at the beginning before #include "ESP8266TimerInterrupt.h"
91-
// Don't define TIMER_INTERRUPT_DEBUG > 2. Only for special ISR debugging only. Can hang the system.
92-
#define TIMER_INTERRUPT_DEBUG 1
91+
//These define's must be placed at the beginning before #include "ESP8266TimerInterrupt.h"
92+
// Don't define TIMER_INTERRUPT_DEBUG > 0. Only for special ISR debugging only. Can hang the system.
93+
#define TIMER_INTERRUPT_DEBUG 0
94+
95+
#include "ESP8266TimerInterrupt.h"
9396

9497
#define DEBOUNCE_TIME 25
9598
#define LONG_BUTTON_PRESS_TIME_MS 100
@@ -252,6 +255,7 @@ void setup()
252255
delay(200);
253256

254257
Serial.println("\nStarting ISR_Switch on " + String(ARDUINO_BOARD));
258+
Serial.println(ESP8266_TIMER_INTERRUPT_VERSION);
255259
Serial.println("CPU Frequency = " + String(F_CPU / 1000000) + " MHz");
256260

257261
LampState = false;

0 commit comments

Comments
 (0)