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

Commit 0cf9906

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 80e3572 commit 0cf9906

22 files changed

+894
-259
lines changed

README.md

+332-221
Large diffs are not rendered by default.

examples/Argument_None/Argument_None.ino

+10-9
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 04/11/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 complex examples. Bump up version to sync with other TimerInterrupt Libraries
2829
*****************************************************************************************************************************/
2930

3031
/*
@@ -40,25 +41,25 @@
4041
*/
4142

4243
#if !( defined(CORE_TEENSY) || defined(TEENSYDUINO) )
43-
#error This code is designed to run on Teensy platform! Please check your Tools->Board setting.
44+
#error This code is designed to run on Teensy platform! Please check your Tools->Board setting.
4445
#endif
4546

4647
// These define's must be placed at the beginning before #include "TeensyTimerInterrupt.h"
47-
// Don't define Teensy_TEENSY_TIMER_INTERRUPT_DEBUG > 2. Only for special ISR debugging only. Can hang the system.
48-
#define TEENSY_TIMER_INTERRUPT_DEBUG 1
48+
// Don't define Teensy_TEENSY_TIMER_INTERRUPT_DEBUG > 0. Only for special ISR debugging only. Can hang the system.
49+
#define TEENSY_TIMER_INTERRUPT_DEBUG 0
4950

5051
#include "TeensyTimerInterrupt.h"
5152

5253
#ifndef LED_BUILTIN
53-
#define LED_BUILTIN 13
54+
#define LED_BUILTIN 13
5455
#endif
5556

5657
#ifndef LED_BLUE
57-
#define LED_BLUE 2
58+
#define LED_BLUE 2
5859
#endif
5960

6061
#ifndef LED_RED
61-
#define LED_RED 3
62+
#define LED_RED 3
6263
#endif
6364

6465

@@ -100,9 +101,9 @@ void setup()
100101
while (!Serial);
101102

102103
delay(100);
103-
104+
104105
Serial.println("\nStarting Argument_None on " + String(BOARD_NAME));
105-
Serial.println("Version : " + String(TEENSY_TIMER_INTERRUPT_VERSION));
106+
Serial.println(TEENSY_TIMER_INTERRUPT_VERSION);
106107
Serial.println("CPU Frequency = " + String(F_CPU / 1000000) + " MHz");
107108

108109
// Interval in microsecs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
/****************************************************************************************************************************
2+
Change_Interval.ino
3+
For Teensy boards
4+
Written by Khoi Hoang
5+
6+
Built by Khoi Hoang https://github.com/khoih-prog/Teensy_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 Teensy 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.1.1
23+
24+
Version Modified By Date Comments
25+
------- ----------- ---------- -----------
26+
1.0.0 K Hoang 04/11/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 complex examples. 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(CORE_TEENSY) || defined(TEENSYDUINO) )
44+
#error This code is designed to run on Teensy platform! Please check your Tools->Board setting.
45+
#endif
46+
47+
// These define's must be placed at the beginning before #include "TeensyTimerInterrupt.h"
48+
// Don't define Teensy_TEENSY_TIMER_INTERRUPT_DEBUG > 0. Only for special ISR debugging only. Can hang the system.
49+
#define TEENSY_TIMER_INTERRUPT_DEBUG 0
50+
51+
#include "TeensyTimerInterrupt.h"
52+
53+
#ifndef LED_BUILTIN
54+
#define LED_BUILTIN 13
55+
#endif
56+
57+
#ifndef LED_BLUE
58+
#define LED_BLUE 2
59+
#endif
60+
61+
#ifndef LED_RED
62+
# define LED_RED 3
63+
#endif
64+
65+
// For Teensy 4.0/4.1, F_BUS_ACTUAL = 150 MHz => max period is only 55922 us (~17.9 Hz)
66+
67+
#define TIMER_INTERVAL_MS 10
68+
69+
volatile uint32_t TimerCount = 0;
70+
71+
// You can select Teensy Hardware Timer from TEENSY_TIMER_1 or TEENSY_TIMER_3
72+
73+
// Init Teensy timer TEENSY_TIMER_1
74+
TeensyTimer ITimer(TEENSY_TIMER_1);
75+
76+
void printResult(uint32_t currTime)
77+
{
78+
Serial.printf("Time = %ld, TimerCount = %lu\n", currTime, TimerCount);
79+
}
80+
81+
void TimerHandler(void)
82+
{
83+
static bool toggle = false;
84+
85+
// Flag for checking to be sure ISR is working as SErial.print is not OK here in ISR
86+
TimerCount++;
87+
88+
//timer interrupt toggles pin LED_BUILTIN
89+
digitalWrite(LED_BUILTIN, toggle);
90+
toggle = !toggle;
91+
}
92+
93+
void setup()
94+
{
95+
pinMode(LED_BUILTIN, OUTPUT);
96+
97+
Serial.begin(115200);
98+
while (!Serial);
99+
100+
delay(100);
101+
102+
Serial.printf("\nStarting Change_Interval on %s\n", BOARD_NAME);
103+
Serial.println(TEENSY_TIMER_INTERRUPT_VERSION);
104+
Serial.println("CPU Frequency = " + String(F_CPU / 1000000) + " MHz");
105+
106+
// Interval in microsecs
107+
if (ITimer.attachInterruptInterval(TIMER_INTERVAL_MS * 1000, TimerHandler))
108+
{
109+
Serial.printf("Starting ITimer OK, millis() = %ld\n", millis());
110+
}
111+
else
112+
Serial.println("Can't set ITimer. Select another freq. or timer");
113+
}
114+
115+
#define CHECK_INTERVAL_MS 10000L
116+
#define CHANGE_INTERVAL_MS 20000L
117+
118+
void loop()
119+
{
120+
static uint32_t lastTime = 0;
121+
static uint32_t lastChangeTime = 0;
122+
static uint32_t currTime;
123+
static uint32_t multFactor = 0;
124+
125+
currTime = millis();
126+
127+
if (currTime - lastTime > CHECK_INTERVAL_MS)
128+
{
129+
printResult(currTime);
130+
lastTime = currTime;
131+
132+
if (currTime - lastChangeTime > CHANGE_INTERVAL_MS)
133+
{
134+
//setInterval(unsigned long interval, timerCallback callback)
135+
multFactor = (multFactor + 1) % 2;
136+
137+
ITimer.setInterval(TIMER_INTERVAL_MS * 1000 * (multFactor + 1), TimerHandler);
138+
139+
Serial.printf("Changing Interval, Timer = %lu\n", TIMER_INTERVAL_MS * (multFactor + 1));
140+
141+
lastChangeTime = currTime;
142+
}
143+
}
144+
}

examples/ISR_16_Timers_Array/ISR_16_Timers_Array.ino

+3-2
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 04/11/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 complex examples. Bump up version to sync with other TimerInterrupt Libraries
2829
*****************************************************************************************************************************/
2930
/*
3031
Notes:
@@ -412,7 +413,7 @@ void setup()
412413
while (!Serial);
413414

414415
Serial.println("\nStarting ISR_16_Timers_Array on " + String(BOARD_NAME));
415-
Serial.println("Version : " + String(TEENSY_TIMER_INTERRUPT_VERSION));
416+
Serial.println(TEENSY_TIMER_INTERRUPT_VERSION);
416417
Serial.println("CPU Frequency = " + String(F_CPU / 1000000) + " MHz");
417418

418419
// Interval in microsecs

0 commit comments

Comments
 (0)