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

Commit 6e77859

Browse files
authored
v1.2.0
### Releases v1.2.0 1. Add better debug feature. 2. Optimize code and examples to reduce RAM usage 3. Add Table of Contents
1 parent e8a6911 commit 6e77859

25 files changed

+1259
-780
lines changed

README.md

Lines changed: 213 additions & 66 deletions
Large diffs are not rendered by default.

examples/Argument_None/Argument_None.ino

Lines changed: 58 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11
/****************************************************************************************************************************
2-
Argument_None.ino
3-
For SAM DUE boards
4-
Written by Khoi Hoang
2+
Argument_None.ino
3+
For SAM DUE boards
4+
Written by Khoi Hoang
55
6-
Built by Khoi Hoang https://github.com/khoih-prog/SAMDUE_TimerInterrupt
7-
Licensed under MIT license
6+
Built by Khoi Hoang https://github.com/khoih-prog/SAMDUE_TimerInterrupt
7+
Licensed under MIT license
88
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 SAM DUE 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.
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 SAM DUE 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.
1414
15-
Based on SimpleTimer - A timer library for Arduino.
16-
17-
Copyright (c) 2010 OTTOTECNICA Italy
15+
Based on SimpleTimer - A timer library for Arduino.
16+
17+
Copyright (c) 2010 OTTOTECNICA Italy
1818
19-
Based on BlynkTimer.h
20-
Author: Volodymyr Shymanskyy
19+
Based on BlynkTimer.h
20+
Author: Volodymyr Shymanskyy
2121
22-
Version: 1.1.1
22+
Version: 1.2.0
2323
24-
Version Modified By Date Comments
25-
------- ----------- ---------- -----------
26-
1.0.1 K Hoang 06/11/2020 Initial coding
27-
1.1.1 K.Hoang 06/12/2020 Add Change_Interval example. Bump up version to sync with other TimerInterrupt Libraries
24+
Version Modified By Date Comments
25+
------- ----------- ---------- -----------
26+
1.0.1 K Hoang 06/11/2020 Initial coding
27+
1.1.1 K.Hoang 06/12/2020 Add Change_Interval example. Bump up version to sync with other TimerInterrupt Libraries
28+
1.2.0 K.Hoang 10/01/2021 Add better debug feature. Optimize code and examples to reduce RAM usage
2829
*****************************************************************************************************************************/
2930

3031
/*
@@ -43,9 +44,12 @@
4344
#error This code is designed to run on SAM DUE board / platform! Please check your Tools->Board setting.
4445
#endif
4546

46-
// These define's must be placed at the beginning before #include "SAMDTimerInterrupt.h"
47-
// Don't define SAMDUE_TIMER_INTERRUPT_DEBUG > 0. Only for special ISR debugging only. Can hang the system.
48-
#define SAMDUE_TIMER_INTERRUPT_DEBUG 1
47+
// These define's must be placed at the beginning before #include "SAMDUETimerInterrupt.h"
48+
// _TIMERINTERRUPT_LOGLEVEL_ from 0 to 4
49+
// Don't define _TIMERINTERRUPT_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system.
50+
// Don't define TIMER_INTERRUPT_DEBUG > 2. Only for special ISR debugging only. Can hang the system.
51+
#define TIMER_INTERRUPT_DEBUG 0
52+
#define _TIMERINTERRUPT_LOGLEVEL_ 0
4953

5054
#include "SAMDUETimerInterrupt.h"
5155

@@ -71,88 +75,94 @@ volatile uint32_t preMillisTimer1 = 0;
7175
volatile uint32_t preMillisTimer2 = 0;
7276
volatile uint32_t preMillisTimer3 = 0;
7377

74-
void TimerHandler0(void)
78+
void TimerHandler0()
7579
{
76-
static bool toggle = false;
80+
static bool toggle0 = false;
7781
static bool started = false;
78-
static uint32_t curMillis = 0;
79-
82+
8083
if (!started)
8184
{
8285
started = true;
8386
pinMode(LED_BUILTIN, OUTPUT);
8487
}
8588

86-
#if (SAMDUE_TIMER_INTERRUPT_DEBUG > 0)
89+
#if (TIMER_INTERRUPT_DEBUG > 0)
90+
static uint32_t curMillis = 0;
91+
8792
curMillis = millis();
8893

8994
if (curMillis > TIMER0_INTERVAL_MS)
9095
{
91-
Serial.println("ITimer0: millis() = " + String(curMillis) + ", delta = " + String(curMillis - preMillisTimer0));
96+
Serial.print("ITimer0: millis() = "); Serial.print(curMillis);
97+
Serial.print(", delta = "); Serial.println(curMillis - preMillisTimer0);
9298
}
9399

94100
preMillisTimer0 = curMillis;
95101
#endif
96102

97103
//timer interrupt toggles pin LED_BUILTIN
98-
digitalWrite(LED_BUILTIN, toggle);
99-
toggle = !toggle;
104+
digitalWrite(LED_BUILTIN, toggle0);
105+
toggle0 = !toggle0;
100106
}
101107

102-
void TimerHandler1(void)
108+
void TimerHandler1()
103109
{
104-
static bool toggle = false;
110+
static bool toggle1 = false;
105111
static bool started = false;
106-
static uint32_t curMillis = 0;
107112

108113
if (!started)
109114
{
110115
started = true;
111116
pinMode(LED_BLUE, OUTPUT);
112117
}
113118

114-
#if (SAMDUE_TIMER_INTERRUPT_DEBUG > 0)
119+
#if (TIMER_INTERRUPT_DEBUG > 0)
120+
static uint32_t curMillis = 0;
121+
115122
curMillis = millis();
116123

117124
if (curMillis > TIMER1_INTERVAL_MS)
118125
{
119-
Serial.println("ITimer1: millis() = " + String(curMillis) + ", delta = " + String(curMillis - preMillisTimer1));
126+
Serial.print("ITimer1: millis() = "); Serial.print(curMillis);
127+
Serial.print(", delta = "); Serial.println(curMillis - preMillisTimer1);
120128
}
121129

122130
preMillisTimer1 = curMillis;
123131
#endif
124132

125133
//timer interrupt toggles outputPin
126-
digitalWrite(LED_BLUE, toggle);
127-
toggle = !toggle;
134+
digitalWrite(LED_BLUE, toggle1);
135+
toggle1 = !toggle1;
128136
}
129137

130-
void TimerHandler2(void)
138+
void TimerHandler2()
131139
{
132-
#if (SAMDUE_TIMER_INTERRUPT_DEBUG > 0)
140+
#if (TIMER_INTERRUPT_DEBUG > 0)
133141
static uint32_t curMillis = 0;
134142

135143
curMillis = millis();
136144

137145
if (curMillis > TIMER2_INTERVAL_MS)
138146
{
139-
Serial.println("ITimer2: millis() = " + String(curMillis) + ", delta = " + String(curMillis - preMillisTimer2));
147+
Serial.print("ITimer2: millis() = "); Serial.print(curMillis);
148+
Serial.print(", delta = "); Serial.println(curMillis - preMillisTimer2);
140149
}
141150

142151
preMillisTimer2 = curMillis;
143152
#endif
144153
}
145154

146-
void TimerHandler3(void)
155+
void TimerHandler3()
147156
{
148-
#if (SAMDUE_TIMER_INTERRUPT_DEBUG > 0)
157+
#if (TIMER_INTERRUPT_DEBUG > 0)
149158
static uint32_t curMillis = 0;
150159

151160
curMillis = millis();
152161

153162
if (curMillis > TIMER3_INTERVAL_MS)
154163
{
155-
Serial.println("ITimer3: millis() = " + String(curMillis) + ", delta = " + String(curMillis - preMillisTimer3));
164+
Serial.print("ITimer3: millis() = "); Serial.print(curMillis);
165+
Serial.print(", delta = "); Serial.println(curMillis - preMillisTimer3);
156166
}
157167

158168
preMillisTimer3 = curMillis;
@@ -167,10 +177,7 @@ uint16_t attachDueInterrupt(double microseconds, timerCallback callback, const c
167177

168178
uint16_t timerNumber = dueTimerInterrupt.getTimerNumber();
169179

170-
Serial.print(TimerName);
171-
Serial.print(" attached to Timer(");
172-
Serial.print(timerNumber);
173-
Serial.println(")");
180+
Serial.print(TimerName); Serial.print(F(" attached to Timer(")); Serial.print(timerNumber); Serial.println(F(")"));
174181

175182
return timerNumber;
176183
}
@@ -182,10 +189,10 @@ void setup()
182189

183190
delay(100);
184191

185-
Serial.println("\nStarting Argument_None on " + String(BOARD_NAME));
192+
Serial.print(F("\nStarting Argument_None on ")); Serial.println(BOARD_NAME);
186193
Serial.println(SAMDUE_TIMER_INTERRUPT_VERSION);
187-
Serial.println("CPU Frequency = " + String(F_CPU / 1000000) + " MHz");
188-
Serial.println("Timer Frequency = " + String(SystemCoreClock / 1000000) + " MHz");
194+
Serial.print(F("CPU Frequency = ")); Serial.print(F_CPU / 1000000); Serial.println(F(" MHz"));
195+
Serial.print(F("Timer Frequency = ")); Serial.print(SystemCoreClock / 1000000); Serial.println(F(" MHz"));
189196

190197
// Interval in microsecs
191198
uint32_t curMillis = millis();

examples/Change_Interval/Change_Interval.ino

Lines changed: 41 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11
/****************************************************************************************************************************
2-
Change_Interval.ino
3-
For SAM DUE boards
4-
Written by Khoi Hoang
2+
Change_Interval.ino
3+
For SAM DUE boards
4+
Written by Khoi Hoang
55
6-
Built by Khoi Hoang https://github.com/khoih-prog/SAMDUE_TimerInterrupt
7-
Licensed under MIT license
6+
Built by Khoi Hoang https://github.com/khoih-prog/SAMDUE_TimerInterrupt
7+
Licensed under MIT license
88
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 SAM DUE 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.
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 SAM DUE 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.
1414
15-
Based on SimpleTimer - A timer library for Arduino.
16-
17-
Copyright (c) 2010 OTTOTECNICA Italy
15+
Based on SimpleTimer - A timer library for Arduino.
16+
17+
Copyright (c) 2010 OTTOTECNICA Italy
1818
19-
Based on BlynkTimer.h
20-
Author: Volodymyr Shymanskyy
19+
Based on BlynkTimer.h
20+
Author: Volodymyr Shymanskyy
2121
22-
Version: 1.1.1
22+
Version: 1.2.0
2323
24-
Version Modified By Date Comments
25-
------- ----------- ---------- -----------
26-
1.0.1 K Hoang 06/11/2020 Initial coding
27-
1.1.1 K.Hoang 06/12/2020 Add Change_Interval example. Bump up version to sync with other TimerInterrupt Libraries
24+
Version Modified By Date Comments
25+
------- ----------- ---------- -----------
26+
1.0.1 K Hoang 06/11/2020 Initial coding
27+
1.1.1 K.Hoang 06/12/2020 Add Change_Interval example. Bump up version to sync with other TimerInterrupt Libraries
28+
1.2.0 K.Hoang 10/01/2021 Add better debug feature. Optimize code and examples to reduce RAM usage
2829
*****************************************************************************************************************************/
2930

3031
/*
@@ -43,9 +44,12 @@
4344
#error This code is designed to run on SAM DUE board / platform! Please check your Tools->Board setting.
4445
#endif
4546

46-
// These define's must be placed at the beginning before #include "SAMDTimerInterrupt.h"
47-
// Don't define SAMDUE_TIMER_INTERRUPT_DEBUG > 0. Only for special ISR debugging only. Can hang the system.
48-
#define SAMDUE_TIMER_INTERRUPT_DEBUG 1
47+
// These define's must be placed at the beginning before #include "SAMDUETimerInterrupt.h"
48+
// _TIMERINTERRUPT_LOGLEVEL_ from 0 to 4
49+
// Don't define _TIMERINTERRUPT_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system.
50+
// Don't define TIMER_INTERRUPT_DEBUG > 2. Only for special ISR debugging only. Can hang the system.
51+
#define TIMER_INTERRUPT_DEBUG 0
52+
#define _TIMERINTERRUPT_LOGLEVEL_ 0
4953

5054
#include "SAMDUETimerInterrupt.h"
5155

@@ -66,13 +70,14 @@
6670

6771
volatile uint32_t Timer0Count = 0;
6872
volatile uint32_t Timer1Count = 0;
69-
7073
void printResult(uint32_t currTime)
7174
{
72-
Serial.println("Time = " + String(currTime) + ", Timer0Count = " + String(Timer0Count) + ", Timer1Count = " + String(Timer1Count));
75+
Serial.print(F("Time = ")); Serial.print(currTime);
76+
Serial.print(F(", Timer0Count = ")); Serial.print(Timer0Count);
77+
Serial.print(F(", Timer1Count = ")); Serial.println(Timer1Count);
7378
}
7479

75-
void TimerHandler0(void)
80+
void TimerHandler0()
7681
{
7782
static bool toggle0 = false;
7883

@@ -84,7 +89,7 @@ void TimerHandler0(void)
8489
toggle0 = !toggle0;
8590
}
8691

87-
void TimerHandler1(void)
92+
void TimerHandler1()
8893
{
8994
static bool toggle1 = false;
9095

@@ -107,10 +112,7 @@ uint16_t attachDueInterrupt(double microseconds, timerCallback callback, const c
107112

108113
uint16_t timerNumber = dueTimerInterrupt.getTimerNumber();
109114

110-
Serial.print(TimerName);
111-
Serial.print(" attached to Timer(");
112-
Serial.print(timerNumber);
113-
Serial.println(")");
115+
Serial.print(TimerName); Serial.print(F(" attached to Timer(")); Serial.print(timerNumber); Serial.println(F(")"));
114116

115117
return timerNumber;
116118
}
@@ -123,10 +125,7 @@ uint16_t updateTimerInterval(uint16_t timerNumberInput, double microseconds, tim
123125

124126
uint16_t timerNumber = dueTimerInterrupt.getTimerNumber();
125127

126-
Serial.print(TimerName);
127-
Serial.print(" attached to Timer(");
128-
Serial.print(timerNumber);
129-
Serial.println(")");
128+
Serial.print(TimerName); Serial.print(F(" attached to Timer(")); Serial.print(timerNumber); Serial.println(F(")"));
130129

131130
return timerNumber;
132131
}
@@ -140,11 +139,11 @@ void setup()
140139
while (!Serial);
141140

142141
delay(100);
143-
144-
Serial.println("\nStarting Change_Interval on " + String(BOARD_NAME));
142+
143+
Serial.print(F("\nStarting Change_Interval on ")); Serial.println(BOARD_NAME);
145144
Serial.println(SAMDUE_TIMER_INTERRUPT_VERSION);
146-
Serial.println("CPU Frequency = " + String(F_CPU / 1000000) + " MHz");
147-
Serial.println("Timer Frequency = " + String(SystemCoreClock / 1000000) + " MHz");
145+
Serial.print(F("CPU Frequency = ")); Serial.print(F_CPU / 1000000); Serial.println(F(" MHz"));
146+
Serial.print(F("Timer Frequency = ")); Serial.print(SystemCoreClock / 1000000); Serial.println(F(" MHz"));
148147

149148
// Interval in microsecs
150149
timerNumber0 = attachDueInterrupt(TIMER0_INTERVAL_MS * 1000, TimerHandler0, "ITimer0");
@@ -175,9 +174,9 @@ void loop()
175174

176175
updateTimerInterval(timerNumber0, TIMER0_INTERVAL_MS * 1000 * (multFactor + 1), TimerHandler0, "ITimer0");
177176
updateTimerInterval(timerNumber1, TIMER1_INTERVAL_MS * 1000 * (multFactor + 1), TimerHandler1, "ITimer1");
178-
179-
Serial.println("Changing Interval, Timer0 = " + String(TIMER0_INTERVAL_MS * (multFactor + 1)) +
180-
", Timer1 = " + String(TIMER1_INTERVAL_MS * (multFactor + 1)));
177+
178+
Serial.print(F("Changing Interval, Timer0 = ")); Serial.print(TIMER0_INTERVAL_MS * (multFactor + 1));
179+
Serial.print(F(", Timer1 = ")); Serial.println(TIMER1_INTERVAL_MS * (multFactor + 1));
181180

182181
lastChangeTime = currTime;
183182
}

0 commit comments

Comments
 (0)