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

Commit f3b27af

Browse files
authored
v1.1.1 to fix bug, optimize examples
### Releases v1.1.1 1. Fix bug possibly causing system crash when using `_TIMERINTERRUPT_LOGLEVEL_ > 0` 2. Optimize code in examples
1 parent 66473cc commit f3b27af

25 files changed

+420
-725
lines changed

Diff for: changelog.md

+6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
## Table of Contents
1313

1414
* [Changelog](#changelog)
15+
* [Releases v1.1.1](#releases-v111)
1516
* [Releases v1.1.0](#releases-v110)
1617
* [Releases v1.0.0](#releases-v100)
1718

@@ -21,6 +22,11 @@
2122
## Changelog
2223

2324

25+
### Releases v1.1.1
26+
27+
1. Fix bug possibly causing system crash when using `_TIMERINTERRUPT_LOGLEVEL_ > 0`
28+
2. Optimize code in examples
29+
2430
### Releases v1.1.0
2531

2632
1. Fix missing code for Timer3 and Timer4

Diff for: examples/Argument_Complex/Argument_Complex.ino

+26-46
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,28 @@
3737
// TIMER_4 Only valid for ATmega324PB, not ready in core yet
3838
#define USE_TIMER_4 false
3939

40-
#if (USE_TIMER_1)
41-
#warning Using Timer1
42-
#elif (USE_TIMER_2)
43-
#warning Using Timer2
44-
#elif (USE_TIMER_3)
45-
#warning Using Timer3
46-
#elif (USE_TIMER_4)
47-
#warning Using Timer4
40+
#if USE_TIMER_1
41+
#define CurrentTimer ITimer1
42+
#elif USE_TIMER_2
43+
#define CurrentTimer ITimer2
44+
#elif USE_TIMER_3
45+
#define CurrentTimer ITimer3
46+
#elif USE_TIMER_4
47+
#define CurrentTimer ITimer4
48+
#else
49+
#error You must select one Timer
50+
#endif
51+
52+
#if (_TIMERINTERRUPT_LOGLEVEL_ > 3)
53+
#if (USE_TIMER_1)
54+
#warning Using Timer1
55+
#elif (USE_TIMER_2)
56+
#warning Using Timer2
57+
#elif (USE_TIMER_3)
58+
#warning Using Timer3
59+
#elif (USE_TIMER_4)
60+
#warning Using Timer4
61+
#endif
4862
#endif
4963

5064
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
@@ -106,52 +120,18 @@ void setup()
106120
// Select Timer 1-2
107121
// Timer 2 is 8-bit timer, only for higher frequency
108122

109-
#if USE_TIMER_1
110-
111-
ITimer1.init();
112-
113-
// Using ATmega324 with 16MHz CPU clock ,
114-
// For 16-bit timer 1, set frequency from 0.2385 to some KHz
115-
// For 8-bit timer 2 (prescaler up to 1024, set frequency from 61.5Hz to some KHz
116-
117-
if (ITimer1.attachInterruptInterval(TIMER_INTERVAL_MS, TimerHandler, (unsigned int) &myOutputPins))
118-
{
119-
Serial.print(F("Starting ITimer1 OK, millis() = ")); Serial.println(millis());
120-
}
121-
else
122-
Serial.println(F("Can't set ITimer1. Select another freq. or timer"));
123-
124-
#elif USE_TIMER_2
123+
CurrentTimer.init();
125124

126125
// Using ATmega324 with 16MHz CPU clock ,
127126
// For 16-bit timer 1, set frequency from 0.2385 to some KHz
128127
// For 8-bit timer 2 (prescaler up to 1024, set frequency from 61.5Hz to some KHz
129-
ITimer2.init();
130128

131-
if (ITimer2.attachInterruptInterval(TIMER_INTERVAL_MS, TimerHandler))
129+
if (CurrentTimer.attachInterruptInterval(TIMER_INTERVAL_MS, TimerHandler, (unsigned int) &myOutputPins))
132130
{
133-
Serial.print(F("Starting ITimer2 OK, millis() = ")); Serial.println(millis());
131+
Serial.print(F("Starting ITimer OK, millis() = ")); Serial.println(millis());
134132
}
135133
else
136-
Serial.println(F("Can't set ITimer2. Select another freq. or timer"));
137-
138-
#elif USE_TIMER_3
139-
140-
ITimer3.init();
141-
142-
if (ITimer3.attachInterruptInterval(TIMER_INTERVAL_MS, TimerHandler, outputPin))
143-
{
144-
Serial.print(F("Starting ITimer3 OK, millis() = ")); Serial.println(millis());
145-
146-
#if (TIMER_INTERRUPT_DEBUG > 1)
147-
Serial.print(F("OutputPin = ")); Serial.print(outputPin);
148-
Serial.print(F(" address: ")); Serial.println((uint32_t) &outputPin );
149-
#endif
150-
}
151-
else
152-
Serial.println(F("Can't set ITimer3. Select another freq. or timer"));
153-
154-
#endif
134+
Serial.println(F("Can't set ITimer. Select another freq. or timer"));
155135
}
156136

157137
void loop()

Diff for: examples/Argument_Complex_Multi/Argument_Complex_Multi.h

+22-8
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,28 @@
4343
// TIMER_4 Only valid for ATmega324PB, not ready in core yet
4444
#define USE_TIMER_4 false
4545

46-
#if (USE_TIMER_1)
47-
#warning Using Timer1
48-
#elif (USE_TIMER_2)
49-
#warning Using Timer2
50-
#elif (USE_TIMER_3)
51-
#warning Using Timer3
52-
#elif (USE_TIMER_4)
53-
#warning Using Timer4
46+
#if USE_TIMER_1
47+
#define CurrentTimer ITimer1
48+
#elif USE_TIMER_2
49+
#define CurrentTimer ITimer2
50+
#elif USE_TIMER_3
51+
#define CurrentTimer ITimer3
52+
#elif USE_TIMER_4
53+
#define CurrentTimer ITimer4
54+
#else
55+
#error You must select one Timer
56+
#endif
57+
58+
#if (_TIMERINTERRUPT_LOGLEVEL_ > 3)
59+
#if (USE_TIMER_1)
60+
#warning Using Timer1
61+
#elif (USE_TIMER_2)
62+
#warning Using Timer2
63+
#elif (USE_TIMER_3)
64+
#warning Using Timer3
65+
#elif (USE_TIMER_4)
66+
#warning Using Timer4
67+
#endif
5468
#endif
5569

5670
// Can be included in many files without `Multiple Definitions` Linker Error

Diff for: examples/Argument_Complex_Multi/Argument_Complex_Multi.ino

+5-39
Original file line numberDiff line numberDiff line change
@@ -52,53 +52,19 @@ void setup()
5252
// Timer0 is already used for micros(), millis(), delay(), etc and can't be used
5353
// Select Timer 1-2
5454
// Timer 2 is 8-bit timer, only for higher frequency
55-
56-
#if USE_TIMER_1
57-
58-
ITimer1.init();
55+
56+
CurrentTimer.init();
5957

6058
// Using ATmega324 with 16MHz CPU clock ,
6159
// For 16-bit timer 1, set frequency from 0.2385 to some KHz
6260
// For 8-bit timer 2 (prescaler up to 1024, set frequency from 61.5Hz to some KHz
6361

64-
if (ITimer1.attachInterruptInterval(TIMER_INTERVAL_MS, TimerHandler, (unsigned int) &myOutputPins))
62+
if (CurrentTimer.attachInterruptInterval(TIMER_INTERVAL_MS, TimerHandler, (unsigned int) &myOutputPins))
6563
{
66-
Serial.print(F("Starting ITimer1 OK, millis() = ")); Serial.println(millis());
64+
Serial.print(F("Starting ITimer OK, millis() = ")); Serial.println(millis());
6765
}
6866
else
69-
Serial.println(F("Can't set ITimer1. Select another freq. or timer"));
70-
71-
#elif USE_TIMER_2
72-
73-
// Using ATmega324 with 16MHz CPU clock ,
74-
// For 16-bit timer 1, set frequency from 0.2385 to some KHz
75-
// For 8-bit timer 2 (prescaler up to 1024, set frequency from 61.5Hz to some KHz
76-
ITimer2.init();
77-
78-
if (ITimer2.attachInterruptInterval(TIMER_INTERVAL_MS, TimerHandler))
79-
{
80-
Serial.print(F("Starting ITimer2 OK, millis() = ")); Serial.println(millis());
81-
}
82-
else
83-
Serial.println(F("Can't set ITimer2. Select another freq. or timer"));
84-
85-
#elif USE_TIMER_3
86-
87-
ITimer3.init();
88-
89-
if (ITimer3.attachInterruptInterval(TIMER_INTERVAL_MS, TimerHandler, outputPin))
90-
{
91-
Serial.print(F("Starting ITimer3 OK, millis() = ")); Serial.println(millis());
92-
93-
#if (TIMER_INTERRUPT_DEBUG > 1)
94-
Serial.print(F("OutputPin = ")); Serial.print(outputPin);
95-
Serial.print(F(" address: ")); Serial.println((uint32_t) &outputPin );
96-
#endif
97-
}
98-
else
99-
Serial.println(F("Can't set ITimer3. Select another freq. or timer"));
100-
101-
#endif
67+
Serial.println(F("Can't set ITimer. Select another freq. or timer"));
10268
}
10369

10470
void loop()

Diff for: examples/Argument_None/Argument_None.ino

+26-26
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,24 @@
3838
// TIMER_4 Only valid for ATmega324PB, not ready in core yet
3939
#define USE_TIMER_4 false
4040

41-
#if (USE_TIMER_2)
42-
#warning Using Timer1 and Timer2
43-
#elif (USE_TIMER_3)
44-
#warning Using Timer1 and Timer3
45-
#elif (USE_TIMER_4)
46-
#warning Using Timer1 and Timer4
41+
#if USE_TIMER_2
42+
#define CurrentTimer ITimer2
43+
#elif USE_TIMER_3
44+
#define CurrentTimer ITimer3
45+
#elif USE_TIMER_4
46+
#define CurrentTimer ITimer4
47+
#else
48+
#error You must select one Timer
49+
#endif
50+
51+
#if (_TIMERINTERRUPT_LOGLEVEL_ > 3)
52+
#if (USE_TIMER_2)
53+
#warning Using Timer1 and Timer2
54+
#elif (USE_TIMER_3)
55+
#warning Using Timer1 and Timer3
56+
#elif (USE_TIMER_4)
57+
#warning Using Timer1 and Timer4
58+
#endif
4759
#endif
4860

4961
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
@@ -98,38 +110,26 @@ void setup()
98110

99111
if (ITimer1.attachInterruptInterval(TIMER1_INTERVAL_MS, TimerHandler1))
100112
{
101-
Serial.print(F("Starting ITimer1 OK, millis() = ")); Serial.println(millis());
113+
Serial.print(F("Starting ITimer1 OK, millis() = ")); Serial.println(millis());
102114
}
103115
else
104116
Serial.println(F("Can't set ITimer1. Select another freq. or timer"));
105117

106-
#if USE_TIMER_2
107-
108118
// Using ATmega324 with 16MHz CPU clock ,
109119
// For 16-bit timer 1, set frequency from 0.2385 to some KHz
110120
// For 8-bit timer 2 (prescaler up to 1024, set frequency from 61.5Hz to some KHz
111-
ITimer2.init();
112-
113-
if (ITimer2.attachInterruptInterval(TIMER_INTERVAL_MS, TimerHandler))
114-
{
115-
Serial.print(F("Starting ITimer2 OK, millis() = ")); Serial.println(millis());
116-
}
117-
else
118-
Serial.println(F("Can't set ITimer2. Select another freq. or timer"));
119121

120-
#elif USE_TIMER_3
121-
122-
// For ATmega1284(P)
123-
ITimer3.init();
122+
///////////////////////////////////////////////
123+
124+
// Init second timer
125+
CurrentTimer.init();
124126

125-
if (ITimer3.attachInterruptInterval(TIMER_INTERVAL_MS, TimerHandler))
127+
if (CurrentTimer.attachInterruptInterval(TIMER_INTERVAL_MS, TimerHandler))
126128
{
127-
Serial.print(F("Starting ITimer3 OK, millis() = ")); Serial.println(millis());
129+
Serial.print(F("Starting ITimer OK, millis() = ")); Serial.println(millis());
128130
}
129131
else
130-
Serial.println(F("Can't set ITimer3. Select another freq. or timer"));
131-
132-
#endif
132+
Serial.println(F("Can't set ITimer. Select another freq. or timer"));
133133
}
134134

135135
void loop()

Diff for: examples/Argument_Simple/Argument_Simple.ino

+31-32
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
// _TIMERINTERRUPT_LOGLEVEL_ from 0 to 4
2828
// Don't define _TIMERINTERRUPT_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system.
2929
#define TIMER_INTERRUPT_DEBUG 0
30-
#define _TIMERINTERRUPT_LOGLEVEL_ 3
30+
#define _TIMERINTERRUPT_LOGLEVEL_ 4
3131

3232
#define USE_TIMER_1 true
3333

@@ -38,12 +38,24 @@
3838
// TIMER_4 Only valid for ATmega324PB, not ready in core yet
3939
#define USE_TIMER_4 false
4040

41-
#if (USE_TIMER_2)
42-
#warning Using Timer1 and Timer2
43-
#elif (USE_TIMER_3)
44-
#warning Using Timer1 and Timer3
45-
#elif (USE_TIMER_4)
46-
#warning Using Timer1 and Timer4
41+
#if USE_TIMER_2
42+
#define CurrentTimer ITimer2
43+
#elif USE_TIMER_3
44+
#define CurrentTimer ITimer3
45+
#elif USE_TIMER_4
46+
#define CurrentTimer ITimer4
47+
#else
48+
#error You must select one Timer
49+
#endif
50+
51+
#if (_TIMERINTERRUPT_LOGLEVEL_ > 3)
52+
#if (USE_TIMER_2)
53+
#warning Using Timer1 and Timer2
54+
#elif (USE_TIMER_3)
55+
#warning Using Timer1 and Timer3
56+
#elif (USE_TIMER_4)
57+
#warning Using Timer1 and Timer4
58+
#endif
4759
#endif
4860

4961
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
@@ -109,7 +121,9 @@ void setup()
109121
// Timer0 is already used for micros(), millis(), delay(), etc and can't be used
110122
// Select Timer 1-2
111123
// Timer 2 is 8-bit timer, only for higher frequency
112-
124+
125+
#if USE_TIMER_1
126+
113127
ITimer1.init();
114128

115129
// Using ATmega324 with 16MHz CPU clock ,
@@ -118,7 +132,7 @@ void setup()
118132

119133
if (ITimer1.attachInterruptInterval(TIMER1_INTERVAL_MS, TimerHandler1, outputPin1))
120134
{
121-
Serial.print(F("Starting ITimer1 OK, millis() = ")); Serial.println(millis());
135+
Serial.print(F("Starting ITimer1 OK, millis() = ")); Serial.println(millis());
122136

123137
#if (TIMER_INTERRUPT_DEBUG > 1)
124138
Serial.print(F("OutputPin1 = ")); Serial.print(outputPin1);
@@ -127,40 +141,25 @@ void setup()
127141
}
128142
else
129143
Serial.println(F("Can't set ITimer1. Select another freq. or timer"));
144+
145+
#endif
130146

131-
#if USE_TIMER_2
147+
///////////////////////////////////////////////
132148

133-
ITimer2.init();
134-
135-
if (ITimer2.attachInterruptInterval(TIMER_INTERVAL_MS, TimerHandler, outputPin))
136-
{
137-
Serial.print(F("Starting ITimer2 OK, millis() = ")); Serial.println(millis());
149+
// Init second timer
150+
CurrentTimer.init();
138151

139-
#if (TIMER_INTERRUPT_DEBUG > 1)
140-
Serial.print(F("OutputPin = ")); Serial.print(outputPin);
141-
Serial.print(F(" address: ")); Serial.println((uint32_t) &outputPin );
142-
#endif
143-
}
144-
else
145-
Serial.println(F("Can't set ITimer2. Select another freq. or timer"));
146-
147-
#elif USE_TIMER_3
148-
149-
ITimer3.init();
150-
151-
if (ITimer3.attachInterruptInterval(TIMER_INTERVAL_MS, TimerHandler, outputPin))
152+
if (CurrentTimer.attachInterruptInterval(TIMER_INTERVAL_MS, TimerHandler, outputPin))
152153
{
153-
Serial.print(F("Starting ITimer3 OK, millis() = ")); Serial.println(millis());
154+
Serial.print(F("Starting ITimer OK, millis() = ")); Serial.println(millis());
154155

155156
#if (TIMER_INTERRUPT_DEBUG > 1)
156157
Serial.print(F("OutputPin = ")); Serial.print(outputPin);
157158
Serial.print(F(" address: ")); Serial.println((uint32_t) &outputPin );
158159
#endif
159160
}
160161
else
161-
Serial.println(F("Can't set ITimer3. Select another freq. or timer"));
162-
163-
#endif
162+
Serial.println(F("Can't set ITimer. Select another freq. or timer"));
164163
}
165164

166165
void loop()

0 commit comments

Comments
 (0)