This repository has been archived by the owner on Jan 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
### Releases v1.0.3 1. Restructure code. 2. Fix example. 3. Enhance README.
- Loading branch information
1 parent
2683921
commit 7e7995c
Showing
16 changed files
with
1,541 additions
and
784 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,52 @@ | ||
/************************************************ | ||
* examples/Argument_None.ino | ||
* For ESP8266 boards | ||
* Written by Khoi Hoang | ||
* | ||
* Built by Khoi Hoang https://github.com/khoih-prog/ESP32TimerInterrupt | ||
* Licensed under MIT license | ||
* Version: v1.0.1 | ||
* | ||
* Notes: | ||
* Special design is necessary to share data between interrupt code and the rest of your program. | ||
* Variables usually need to be "volatile" types. Volatile tells the compiler to avoid optimizations that assume | ||
* variable can not spontaneously change. Because your function may change variables while your program is using them, | ||
* the compiler needs this hint. But volatile alone is often not enough. | ||
* When accessing shared variables, usually interrupts must be disabled. Even with volatile, | ||
* if the interrupt changes a multi-byte variable between a sequence of instructions, it can be read incorrectly. | ||
* If your data is multiple variables, such as an array and a count, usually interrupts need to be disabled | ||
* or the entire sequence of your code which accesses the data. | ||
* | ||
************************************************/ | ||
/**************************************************************************************************************************** | ||
Argument_None.ino | ||
For ESP8266 boards | ||
Written by Khoi Hoang | ||
Built by Khoi Hoang https://github.com/khoih-prog/ESP8266TimerInterrupt | ||
Licensed under MIT license | ||
Version: 1.0.3 | ||
The ESP8266 timers are badly designed, using only 23-bit counter along with maximum 256 prescaler. They're only better than UNO / Mega. | ||
The ESP8266 has two hardware timers, but timer0 has been used for WiFi and it's not advisable to use. Only timer1 is available. | ||
The timer1's 23-bit counter terribly can count only up to 8,388,607. So the timer1 maximum interval is very short. | ||
Using 256 prescaler, maximum timer1 interval is only 26.843542 seconds !!! | ||
Now with these new 16 ISR-based timers, the maximum interval is practically unlimited (limited only by unsigned long miliseconds) | ||
The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers | ||
Therefore, their executions are not blocked by bad-behaving functions / tasks. | ||
This important feature is absolutely necessary for mission-critical tasks. | ||
Based on SimpleTimer - A timer library for Arduino. | ||
Author: [email protected] | ||
Copyright (c) 2010 OTTOTECNICA Italy | ||
Based on BlynkTimer.h | ||
Author: Volodymyr Shymanskyy | ||
Version Modified By Date Comments | ||
------- ----------- ---------- ----------- | ||
1.0.0 K Hoang 23/11/2019 Initial coding | ||
1.0.1 K Hoang 25/11/2019 New release fixing compiler error | ||
1.0.2 K.Hoang 26/11/2019 Permit up to 16 super-long-time, super-accurate ISR-based timers to avoid being blocked | ||
1.0.3 K.Hoang 17/05/2020 Restructure code. Fix example. Enhance README. | ||
*****************************************************************************************************************************/ | ||
|
||
/* Notes: | ||
Special design is necessary to share data between interrupt code and the rest of your program. | ||
Variables usually need to be "volatile" types. Volatile tells the compiler to avoid optimizations that assume | ||
variable can not spontaneously change. Because your function may change variables while your program is using them, | ||
the compiler needs this hint. But volatile alone is often not enough. | ||
When accessing shared variables, usually interrupts must be disabled. Even with volatile, | ||
if the interrupt changes a multi-byte variable between a sequence of instructions, it can be read incorrectly. | ||
If your data is multiple variables, such as an array and a count, usually interrupts need to be disabled | ||
or the entire sequence of your code which accesses the data. | ||
*/ | ||
|
||
#if !defined(ESP8266) | ||
#error This code is designed to run on ESP8266 and ESP8266-based boards! Please check your Tools->Board setting. | ||
#endif | ||
|
||
//These define's must be placed at the beginning before #include "ESP8266TimerInterrupt.h" | ||
#define TIMER_INTERRUPT_DEBUG 1 | ||
|
||
|
@@ -40,17 +69,17 @@ void ICACHE_RAM_ATTR TimerHandler(void) | |
pinMode(LED_BUILTIN, OUTPUT); | ||
} | ||
|
||
#if (TIMER_INTERRUPT_DEBUG > 0) | ||
#if (TIMER_INTERRUPT_DEBUG > 0) | ||
Serial.println("Delta ms = " + String(millis() - lastMillis)); | ||
lastMillis = millis(); | ||
#endif | ||
#endif | ||
|
||
//timer interrupt toggles pin LED_BUILTIN | ||
digitalWrite(LED_BUILTIN, toggle); | ||
toggle = !toggle; | ||
} | ||
|
||
#define TIMER_INTERVAL_MS 1000 | ||
#define TIMER_INTERVAL_MS 1000 | ||
|
||
// Init ESP32 timer 0 | ||
ESP8266Timer ITimer; | ||
|
@@ -59,8 +88,10 @@ ESP8266Timer ITimer; | |
void setup() | ||
{ | ||
Serial.begin(115200); | ||
Serial.println("\nStarting"); | ||
while (!Serial); | ||
|
||
Serial.println("\nStarting Argument_None"); | ||
|
||
// Interval in microsecs | ||
if (ITimer.attachInterruptInterval(TIMER_INTERVAL_MS * 1000, TimerHandler)) | ||
{ | ||
|
@@ -74,5 +105,5 @@ void setup() | |
|
||
void loop() | ||
{ | ||
|
||
} |
Oops, something went wrong.