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

Commit 837388e

Browse files
authored
Releases v1.3.0
### Releases v1.3.0 1. Add support to **AVR ATMEGA_16U4, ATMEGA_32U4** such as **Leonardo, YUN, ESPLORA, etc.** 2. Update examples
1 parent 5f29ca0 commit 837388e

36 files changed

+997
-411
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Please ensure to specify the following:
2929
Arduino IDE version: 1.8.13
3030
Arduino Core Version 1.8.3
3131
OS: Ubuntu 20.04 LTS
32-
Linux xy-Inspiron-3593 5.4.0-51-generic #56-Ubuntu SMP Mon Oct 5 14:28:49 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
32+
Linux xy-Inspiron-3593 5.4.0-66-generic #74-Ubuntu SMP Wed Jan 27 22:54:38 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
3333
3434
Context:
3535
I encountered a crash while trying to use the Timer Interrupt.

README.md

Lines changed: 80 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* [Currently supported Boards](#currently-supported-boards)
1717
* [Important Notes about ISR](#important-notes-about-isr)
1818
* [Changelog](#changelog)
19+
* [Releases v1.3.0](#releases-v130)
1920
* [Releases v1.2.0](#releases-v120)
2021
* [Releases v1.1.2](#releases-v112)
2122
* [Releases v1.1.1](#releases-v111)
@@ -124,18 +125,24 @@ The catch is your function is now part of an ISR (Interrupt Service Routine), an
124125

125126
### Currently supported Boards
126127

127-
- Arduino Uno / Mega / Leonardo / Duemilanove / Diecimila / LilyPad / Mini / Fio / Nano etc.
128+
- Arduino Uno / Mega / Duemilanove / Diecimila / LilyPad / Mini / Fio / Nano, etc.
128129
- Sanguino
129130
- ATmega8, 48, 88, 168, 328
130131
- ATmega8535, 16, 32, 164, 324, 644, 1284,
131132
- ATmega64, 128
132133
- ATtiny 84 / 85
134+
- **ATMega 16U4, 32U4** such as AVR Leonardo, Leonardo ETH, YUN, Esplora, LILYPAD_USB, AVR_ROBOT_CONTROL, AVR_ROBOT_MOTOR, AVR_INDUSTRIAL101, etc.
133135

134136
---
135137
---
136138

137139
## Changelog
138140

141+
### Releases v1.3.0
142+
143+
1. Add support to **AVR ATMEGA_16U4, ATMEGA_32U4** such as **Leonardo, YUN, ESPLORA, etc.**
144+
2. Update examples
145+
139146
### Releases v1.2.0
140147

141148
1. Add better debug feature.
@@ -169,7 +176,7 @@ The catch is your function is now part of an ISR (Interrupt Service Routine), an
169176
## Prerequisites
170177

171178
1. [`Arduino IDE 1.8.13+` for Arduino](https://www.arduino.cc/en/Main/Software)
172-
2. [`Arduino AVR core 1.8.3+`](https://github.com/arduino/ArduinoCore-avr) for Arduino AVR boards. Use Arduino Board Manager to install.
179+
2. [`Arduino AVR core 1.8.3+`](https://github.com/arduino/ArduinoCore-avr) for Arduino AVR boards. Use Arduino Board Manager to install. [![Latest release](https://img.shields.io/github/release/arduino/ArduinoCore-avr.svg)](https://github.com/arduino/ArduinoCore-avr/releases/latest/)
173180

174181
---
175182
---
@@ -236,7 +243,7 @@ In the Arduino world timer0 is been used for the timer functions, like delay(),
236243

237244
### 2. Timer1:
238245

239-
Timer1 is a 16-bit timer.
246+
Timer1 is a 16-bit timer. This is available Timer to use for **ATMEGA_16U4, ATMEGA_32U4 boards**, such as Leonardo, YUN, ESPLORA, etc.
240247
In the Arduino world the Servo library uses timer1 on Arduino Uno (Timer5 on Arduino Mega).
241248

242249
### 3. Timer2:
@@ -252,7 +259,9 @@ Timer 3,4,5 are only available on Arduino Mega boards. These timers are all 16-b
252259

253260
Before using any Timer, you have to make sure the **Timer has not been used by any other purpose.**
254261

255-
Only Timer1 and Timer2 are supported for Nano, UNO, etc. boards possessing 3 timers.
262+
Only Timer1 is supported for Nano, UNO, etc. boards possessing 3 timers.
263+
264+
Only Timer1 and Timer2 are supported for ATMEGA_16U4, ATMEGA_32U4 boards, such as Leonardo, YUN, ESPLORA, etc.
256265

257266
Timer3, Timer4 and Timer5 are only available for Arduino Mega boards.
258267

@@ -269,11 +278,15 @@ Before using any Timer, you have to make sure the Timer has not been used by any
269278

270279
```
271280
// Select the timers you're using, here ITimer1
272-
#define USE_TIMER_1 true
273-
#define USE_TIMER_2 false
274-
#define USE_TIMER_3 false
275-
#define USE_TIMER_4 false
276-
#define USE_TIMER_5 false
281+
#if ( TIMER_INTERRUPT_USING_ATMEGA_32U4 )
282+
#define USE_TIMER_1 true
283+
#else
284+
#define USE_TIMER_1 true
285+
#define USE_TIMER_2 false
286+
#define USE_TIMER_3 false
287+
#define USE_TIMER_4 false
288+
#define USE_TIMER_5 false
289+
#endif
277290
278291
// Init timer ITimer1
279292
ITimer1.init();
@@ -369,12 +382,15 @@ The 16 ISR_based Timers, designed for long timer intervals, only support using *
369382
### 2.2 Init Hardware Timer and ISR-based Timer
370383

371384
```
372-
// Select the timers you're using, here ITimer2
373-
#define USE_TIMER_1 false
374-
#define USE_TIMER_2 true
375-
#define USE_TIMER_3 false
376-
#define USE_TIMER_4 false
377-
#define USE_TIMER_5 false
385+
#if ( TIMER_INTERRUPT_USING_ATMEGA_32U4 )
386+
#define USE_TIMER_1 true
387+
#else
388+
#define USE_TIMER_1 true
389+
#define USE_TIMER_2 false
390+
#define USE_TIMER_3 false
391+
#define USE_TIMER_4 false
392+
#define USE_TIMER_5 false
393+
#endif
378394
379395
// Init ISR_Timer
380396
// Each ISR_Timer can service 16 different ISR-based timers
@@ -468,12 +484,22 @@ void setup()
468484
### Example [ISR_16_Timers_Array_Complex](examples/ISR_16_Timers_Array_Complex)
469485

470486
```cpp
471-
#if defined(__AVR_ATmega8__) || defined(__AVR_ATmega128__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || \
472-
defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644A__) || \
473-
defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__) || defined(ARDUINO_AVR_UNO) || defined(ARDUINO_AVR_NANO) || \
474-
defined(ARDUINO_AVR_MINI) || defined(ARDUINO_AVR_ETHERNET) || defined(ARDUINO_AVR_FIO) || defined(ARDUINO_AVR_BT) || \
475-
defined(ARDUINO_AVR_LILYPAD) || defined(ARDUINO_AVR_PRO) || defined(ARDUINO_AVR_NG) || defined(ARDUINO_AVR_UNO_WIFI_DEV_ED)
476-
487+
#if ( defined(__AVR_ATmega8__) || defined(__AVR_ATmega128__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || \
488+
defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644A__) || \
489+
defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__) || defined(ARDUINO_AVR_UNO) || defined(ARDUINO_AVR_NANO) || \
490+
defined(ARDUINO_AVR_MINI) || defined(ARDUINO_AVR_ETHERNET) || defined(ARDUINO_AVR_FIO) || defined(ARDUINO_AVR_BT) || \
491+
defined(ARDUINO_AVR_LILYPAD) || defined(ARDUINO_AVR_PRO) || defined(ARDUINO_AVR_NG) || defined(ARDUINO_AVR_UNO_WIFI_DEV_ED) )
492+
493+
#elif ( defined(ARDUINO_AVR_LEONARDO) || defined(ARDUINO_AVR_LEONARDO_ETH) || defined(ARDUINO_AVR_YUN) || defined(ARDUINO_AVR_MICRO) || \
494+
defined(ARDUINO_AVR_ESPLORA) || defined(ARDUINO_AVR_LILYPAD_USB) || defined(ARDUINO_AVR_ROBOT_CONTROL) || defined(ARDUINO_AVR_ROBOT_MOTOR) || \
495+
defined(ARDUINO_AVR_CIRCUITPLAY) || defined(ARDUINO_AVR_YUNMINI) || defined(ARDUINO_AVR_INDUSTRIAL101) || defined(ARDUINO_AVR_LININO_ONE) )
496+
#if defined(TIMER_INTERRUPT_USING_ATMEGA_32U4)
497+
#undef TIMER_INTERRUPT_USING_ATMEGA_32U4
498+
#endif
499+
#define TIMER_INTERRUPT_USING_ATMEGA_32U4 true
500+
#warning Using ATMega32U4, such as Leonardo or Leonardo ETH. Only Timer1 is available
501+
#elif defined(ARDUINO_AVR_GEMMA)
502+
#error These AVR boards are not supported! You can use Software Serial. Please check your Tools->Board setting.
477503
#else
478504
#error This is designed only for Arduino AVR board! Please check your Tools->Board setting.
479505
#endif
@@ -484,11 +510,15 @@ void setup()
484510
#define TIMER_INTERRUPT_DEBUG 0
485511
#define _TIMERINTERRUPT_LOGLEVEL_ 0
486512

487-
#define USE_TIMER_1 false
488-
#define USE_TIMER_2 true
489-
#define USE_TIMER_3 false
490-
#define USE_TIMER_4 false
491-
#define USE_TIMER_5 false
513+
#if ( TIMER_INTERRUPT_USING_ATMEGA_32U4 )
514+
#define USE_TIMER_1 true
515+
#else
516+
#define USE_TIMER_1 true
517+
#define USE_TIMER_2 false
518+
#define USE_TIMER_3 false
519+
#define USE_TIMER_4 false
520+
#define USE_TIMER_5 false
521+
#endif
492522

493523
#include "TimerInterrupt.h"
494524
#include "ISR_Timer.h"
@@ -499,25 +529,25 @@ void setup()
499529
#define LED_BUILTIN 13
500530
#endif
501531

502-
ISR_Timer ISR_Timer2;
532+
ISR_Timer ISR_Timer1;
503533

504534
#define LED_TOGGLE_INTERVAL_MS 1000L
505535

506536
// You have to use longer time here if having problem because Arduino AVR clock is low, 16MHz => lower accuracy.
507537
// Tested OK with 1ms when not much load => higher accuracy.
508-
#define TIMER2_INTERVAL_MS 5L
538+
#define TIMER1_INTERVAL_MS 5L
509539

510540
volatile uint32_t startMillis = 0;
511541

512-
void TimerHandler2()
542+
void TimerHandler1()
513543
{
514544
static bool toggle = false;
515545
static int timeRun = 0;
516546

517-
ISR_Timer2.run();
547+
ISR_Timer1.run();
518548

519549
// Toggle LED every LED_TOGGLE_INTERVAL_MS = 2000ms = 2s
520-
if (++timeRun == ((LED_TOGGLE_INTERVAL_MS) / TIMER2_INTERVAL_MS) )
550+
if (++timeRun == ((LED_TOGGLE_INTERVAL_MS) / TIMER1_INTERVAL_MS) )
521551
{
522552
timeRun = 0;
523553

@@ -751,28 +781,28 @@ void setup()
751781
Serial.println(TIMER_INTERRUPT_VERSION);
752782
Serial.print(F("CPU Frequency = ")); Serial.print(F_CPU / 1000000); Serial.println(F(" MHz"));
753783

754-
ITimer2.init();
784+
ITimer1.init();
755785

756-
if (ITimer2.attachInterruptInterval(TIMER2_INTERVAL_MS, TimerHandler2))
786+
if (ITimer1.attachInterruptInterval(TIMER1_INTERVAL_MS, TimerHandler1))
757787
{
758-
Serial.print(F("Starting ITimer2 OK, millis() = ")); Serial.println(millis());
788+
Serial.print(F("Starting ITimer1 OK, millis() = ")); Serial.println(millis());
759789
}
760790
else
761-
Serial.println(F("Can't set ITimer2. Select another freq. or timer"));
791+
Serial.println(F("Can't set ITimer1. Select another freq. or timer"));
762792

763-
//ISR_Timer2.setInterval(2000L, doingSomething2s);
764-
//ISR_Timer2.setInterval(5000L, doingSomething5s);
793+
//ISR_Timer1.setInterval(2000L, doingSomething2s);
794+
//ISR_Timer1.setInterval(5000L, doingSomething5s);
765795

766796
// Just to demonstrate, don't use too many ISR Timers if not absolutely necessary
767797
// You can use up to 16 timer for each ISR_Timer
768798
for (uint16_t i = 0; i < NUMBER_ISR_TIMERS; i++)
769799
{
770800
#if USE_COMPLEX_STRUCT
771801
curISRTimerData[i].previousMillis = startMillis;
772-
ISR_Timer2.setInterval(curISRTimerData[i].TimerInterval, curISRTimerData[i].irqCallbackFunc);
802+
ISR_Timer1.setInterval(curISRTimerData[i].TimerInterval, curISRTimerData[i].irqCallbackFunc);
773803
#else
774804
previousMillis[i] = startMillis;
775-
ISR_Timer2.setInterval(TimerInterval[i], irqCallbackFunc[i]);
805+
ISR_Timer1.setInterval(TimerInterval[i], irqCallbackFunc[i]);
776806
#endif
777807
}
778808

@@ -809,7 +839,7 @@ While software timer, **programmed for 2s, is activated after more than 10.000s
809839
810840
```
811841
Starting ISR_16_Timers_Array_Complex on AVR
812-
TimerInterrupt v1.1.2
842+
TimerInterrupt v1.3.0
813843
CPU Frequency = 16 MHz
814844
Starting ITimer2 OK, millis() = 1
815845
SimpleTimer : 2, ms : 10007, Dms : 10007
@@ -959,7 +989,7 @@ The following is the sample terminal output when running example [Change_Interva
959989
960990
```
961991
Starting Change_Interval on AVR
962-
TimerInterrupt v1.1.2
992+
TimerInterrupt v1.3.0
963993
CPU Frequency = 16 MHz
964994
Starting ITimer1 OK, millis() = 1
965995
Starting ITimer2 OK, millis() = 4
@@ -1007,6 +1037,11 @@ Sometimes, the library will only work if you update the board core to the latest
10071037

10081038
## Releases
10091039

1040+
### Releases v1.3.0
1041+
1042+
1. Add support to **AVR ATMEGA_16U4, ATMEGA_32U4** such as **Leonardo, YUN, ESPLORA, etc.**
1043+
2. Update examples
1044+
10101045
### Releases v1.2.0
10111046

10121047
1. Add better debug feature.
@@ -1077,6 +1112,7 @@ Submit issues to: [TimerInterrupt issues](https://github.com/khoih-prog/TimerInt
10771112
4. Fix some bugs in v1.0.0
10781113
5. Add more examples.
10791114
6. Similar library for ESP32, ESP8266, SAMD21/SAMD51, nRF52, Mbed-OS Nano-33-BLE, STM32
1115+
7. Add support to **ATMega-16U4, ATMega-32U4**-based boards
10801116

10811117

10821118
---
@@ -1087,10 +1123,13 @@ Submit issues to: [TimerInterrupt issues](https://github.com/khoih-prog/TimerInt
10871123
Many thanks for everyone for bug reporting, new feature suggesting, testing and contributing to the development of this library. Especially to these people who have directly or indirectly contributed to this [TimerInterrupt library](https://github.com/khoih-prog/TimerInterrupt)
10881124

10891125
1. Thanks to [Django0](https://github.com/Django0) to provide the following PR [Fixed warnings from cppcheck (platformio) and -Wall arduino-cli. PR#10](https://github.com/khoih-prog/TimerInterrupt/pull/10).
1126+
2. Thanks to [eslavko](https://github.com/eslavko) to report the issue [Error compiling for arduino leonardo #13](https://github.com/khoih-prog/TimerInterrupt/issues/13) leading to new release v1.3.0 to provide support to **ATMega-16U4, ATMega-32U4**-based boards, such as AVR Leonardo, Leonardo ETH, YUN, Esplora, LILYPAD_USB, AVR_ROBOT_CONTROL, AVR_ROBOT_MOTOR, AVR_INDUSTRIAL101, etc..
1127+
10901128

10911129
<table>
10921130
<tr>
10931131
<td align="center"><a href="https://github.com/Django0"><img src="https://github.com/Django0.png" width="100px;" alt="Django0"/><br /><sub><b>Django0</b></sub></a><br /></td>
1132+
<td align="center"><a href="https://github.com/eslavko"><img src="https://github.com/eslavko.png" width="100px;" alt="eslavko"/><br /><sub><b>eslavko</b></sub></a><br /></td>
10941133
</tr>
10951134
</table>
10961135

examples/Argument_Complex/Argument_Complex.ino

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
If your data is multiple variables, such as an array and a count, usually interrupts need to be disabled
2323
or the entire sequence of your code which accesses the data.
2424
25-
Version: 1.2.0
25+
Version: 1.3.0
2626
2727
Version Modified By Date Comments
2828
------- ----------- ---------- -----------
@@ -33,14 +33,25 @@
3333
1.1.1 K.Hoang 06/12/2020 Add example Change_Interval. Bump up version to sync with other TimerInterrupt Libraries
3434
1.1.2 K.Hoang 05/01/2021 Fix warnings. Optimize examples to reduce memory usage
3535
1.2.0 K.Hoang 07/01/2021 Add better debug feature. Optimize code and examples to reduce RAM usage
36+
1.3.0 K.Hoang 25/02/2021 Add support to AVR Leonardo and Leonardo ETH
3637
*****************************************************************************************************************************/
3738

38-
#if defined(__AVR_ATmega8__) || defined(__AVR_ATmega128__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || \
39-
defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644A__) || \
40-
defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__) || defined(ARDUINO_AVR_UNO) || defined(ARDUINO_AVR_NANO) || \
41-
defined(ARDUINO_AVR_MINI) || defined(ARDUINO_AVR_ETHERNET) || defined(ARDUINO_AVR_FIO) || defined(ARDUINO_AVR_BT) || \
42-
defined(ARDUINO_AVR_LILYPAD) || defined(ARDUINO_AVR_PRO) || defined(ARDUINO_AVR_NG) || defined(ARDUINO_AVR_UNO_WIFI_DEV_ED)
43-
39+
#if ( defined(__AVR_ATmega8__) || defined(__AVR_ATmega128__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || \
40+
defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644A__) || \
41+
defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__) || defined(ARDUINO_AVR_UNO) || defined(ARDUINO_AVR_NANO) || \
42+
defined(ARDUINO_AVR_MINI) || defined(ARDUINO_AVR_ETHERNET) || defined(ARDUINO_AVR_FIO) || defined(ARDUINO_AVR_BT) || \
43+
defined(ARDUINO_AVR_LILYPAD) || defined(ARDUINO_AVR_PRO) || defined(ARDUINO_AVR_NG) || defined(ARDUINO_AVR_UNO_WIFI_DEV_ED) )
44+
45+
#elif ( defined(ARDUINO_AVR_LEONARDO) || defined(ARDUINO_AVR_LEONARDO_ETH) || defined(ARDUINO_AVR_YUN) || defined(ARDUINO_AVR_MICRO) || \
46+
defined(ARDUINO_AVR_ESPLORA) || defined(ARDUINO_AVR_LILYPAD_USB) || defined(ARDUINO_AVR_ROBOT_CONTROL) || defined(ARDUINO_AVR_ROBOT_MOTOR) || \
47+
defined(ARDUINO_AVR_CIRCUITPLAY) || defined(ARDUINO_AVR_YUNMINI) || defined(ARDUINO_AVR_INDUSTRIAL101) || defined(ARDUINO_AVR_LININO_ONE) )
48+
#if defined(TIMER_INTERRUPT_USING_ATMEGA_32U4)
49+
#undef TIMER_INTERRUPT_USING_ATMEGA_32U4
50+
#endif
51+
#define TIMER_INTERRUPT_USING_ATMEGA_32U4 true
52+
#warning Using ATMega32U4, such as Leonardo or Leonardo ETH. Only Timer1 is available
53+
#elif defined(ARDUINO_AVR_GEMMA)
54+
#error These AVR boards are not supported! You can use Software Serial. Please check your Tools->Board setting.
4455
#else
4556
#error This is designed only for Arduino AVR board! Please check your Tools->Board setting.
4657
#endif
@@ -51,11 +62,15 @@
5162
#define TIMER_INTERRUPT_DEBUG 0
5263
#define _TIMERINTERRUPT_LOGLEVEL_ 0
5364

54-
#define USE_TIMER_1 true
55-
#define USE_TIMER_2 false
56-
#define USE_TIMER_3 false
57-
#define USE_TIMER_4 false
58-
#define USE_TIMER_5 false
65+
#if ( TIMER_INTERRUPT_USING_ATMEGA_32U4 )
66+
#define USE_TIMER_1 true
67+
#else
68+
#define USE_TIMER_1 true
69+
#define USE_TIMER_2 false
70+
#define USE_TIMER_3 false
71+
#define USE_TIMER_4 false
72+
#define USE_TIMER_5 false
73+
#endif
5974

6075
#include "TimerInterrupt.h"
6176

0 commit comments

Comments
 (0)