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

Commit 34d4b8b

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 f3b27af commit 34d4b8b

File tree

1 file changed

+32
-45
lines changed

1 file changed

+32
-45
lines changed

README.md

Lines changed: 32 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ The catch is your function is now part of an ISR (Interrupt Service Routine), an
131131

132132
1. [`Arduino IDE 1.8.19+` for Arduino](https://www.arduino.cc/en/Main/Software)
133133
2. [`MCUdude MightyCore v2.1.3+`](https://github.com/MCUdude/MightyCore) for **ATmega164, ATmega324, ATmega644, ATmega1284**. Use Arduino Board Manager to install. [![Latest release](https://img.shields.io/github/release/MCUdude/MightyCore.svg)](https://github.com/MCUdude/MightyCore/releases/latest/)
134-
134+
3. To use with certain example
135+
- [`SimpleTimer library`](https://github.com/jfturcot/SimpleTimer) for [ISR_Timers_Array_Simple](examples/ISR_Timers_Array_Simple) and [ISR_16_Timers_Array_Complex](examples/ISR_16_Timers_Array_Complex) examples.
135136

136137
---
137138
---
@@ -196,7 +197,7 @@ From [Arduino 101: Timers and Interrupts](https://www.robotshop.com/community/fo
196197

197198
Timer0 is a 8-bit timer.
198199

199-
In the Arduino world, **Timer0 is been used for the timer functions**, like delay(), millis() and micros(). If you change **Timer0** registers, this may influence the Arduino timer function. So you should know what you are doing.
200+
In the Arduino world, **Timer0 is used for the timer functions**, like delay(), millis() and micros(). If you change **Timer0** registers, this may influence the Arduino timer function. So you should know what you are doing.
200201

201202
### 2. Timer1:
202203

@@ -281,7 +282,7 @@ void setup()
281282
282283
// Interval in unsigned long millisecs
283284
if (ITimer.attachInterruptInterval(TIMER_INTERVAL_MS, TimerHandler))
284-
Serial.println("Starting ITimer OK, millis() = " + String(millis()));
285+
Serial.println("Starting ITimer OK, millis() = " + String(millis()));
285286
else
286287
Serial.println("Can't set ITimer. Select another freq. or timer");
287288
}
@@ -346,12 +347,24 @@ The 16 ISR_based Timers, designed for long timer intervals, only support using *
346347
// TIMER_4 Only valid for ATmega324PB, not ready in core yet
347348
#define USE_TIMER_4 false
348349
349-
#if (USE_TIMER_2)
350-
#warning Using Timer1 and Timer2
351-
#elif (USE_TIMER_3)
352-
#warning Using Timer1 and Timer3
353-
#elif (USE_TIMER_4)
354-
#warning Using Timer1 and Timer4
350+
#if USE_TIMER_2
351+
#define CurrentTimer ITimer2
352+
#elif USE_TIMER_3
353+
#define CurrentTimer ITimer3
354+
#elif USE_TIMER_4
355+
#define CurrentTimer ITimer4
356+
#else
357+
#error You must select one Timer
358+
#endif
359+
360+
#if (_TIMERINTERRUPT_LOGLEVEL_ > 3)
361+
#if (USE_TIMER_2)
362+
#warning Using Timer1 and Timer2
363+
#elif (USE_TIMER_3)
364+
#warning Using Timer1 and Timer3
365+
#elif (USE_TIMER_4)
366+
#warning Using Timer1 and Timer4
367+
#endif
355368
#endif
356369
357370
// Init ISR_Timer
@@ -401,47 +414,18 @@ void setup()
401414
{
402415
....
403416
404-
#if USE_TIMER_1
405-
406-
ITimer1.init();
407-
408-
// Using ATmega324 with 16MHz CPU clock ,
409-
// For 16-bit timer 1, set frequency from 0.2385 to some KHz
410-
// For 8-bit timer 2 (prescaler up to 1024, set frequency from 61.5Hz to some KHz
411-
412-
if (ITimer1.attachInterruptInterval(TIMER_INTERVAL_MS, TimerHandler))
413-
{
414-
Serial.print(F("Starting ITimer1 OK, millis() = ")); Serial.println(millis());
415-
}
416-
else
417-
Serial.println(F("Can't set ITimer1. Select another freq. or timer"));
418-
419-
#elif USE_TIMER_2
417+
CurrentTimer.init();
420418
421419
// Using ATmega324 with 16MHz CPU clock ,
422420
// For 16-bit timer 1, set frequency from 0.2385 to some KHz
423421
// For 8-bit timer 2 (prescaler up to 1024, set frequency from 61.5Hz to some KHz
424-
ITimer2.init();
425-
426-
if (ITimer2.attachInterruptInterval(TIMER_INTERVAL_MS, TimerHandler))
427-
{
428-
Serial.print(F("Starting ITimer2 OK, millis() = ")); Serial.println(millis());
429-
}
430-
else
431-
Serial.println(F("Can't set ITimer2. Select another freq. or timer"));
432422
433-
#elif USE_TIMER_3
434-
435-
ITimer3.init();
436-
437-
if (ITimer3.attachInterruptInterval(TIMER_INTERVAL_MS, TimerHandler))
423+
if (CurrentTimer.attachInterruptInterval(TIMER_INTERVAL_MS, TimerHandler))
438424
{
439-
Serial.print(F("Starting ITimer3 OK, millis() = ")); Serial.println(millis());
425+
Serial.print(F("Starting ITimer OK, millis() = ")); Serial.println(millis());
440426
}
441427
else
442-
Serial.println(F("Can't set ITimer3. Select another freq. or timer"));
443-
444-
#endif
428+
Serial.println(F("Can't set ITimer. Select another freq. or timer"));
445429
446430
// Just to demonstrate, don't use too many ISR Timers if not absolutely necessary
447431
// You can use up to 16 timer for each ISR_Timer
@@ -476,7 +460,7 @@ void setup()
476460

477461
### Example [ISR_16_Timers_Array_Complex](examples/ISR_16_Timers_Array_Complex)
478462

479-
https://github.com/khoih-prog/ATmega_TimerInterrupt/blob/5fae6b57d6e835aed11b84c5d087d67c52d98519/examples/ISR_16_Timers_Array_Complex/ISR_16_Timers_Array_Complex.ino#L25-L392
463+
https://github.com/khoih-prog/ATmega_TimerInterrupt/blob/f3b27af3eba6de4dd56ae49f04e4a8f8c3b18f9d/examples/ISR_16_Timers_Array_Complex/ISR_16_Timers_Array_Complex.ino#L25-L377
480464

481465
---
482466
---
@@ -530,7 +514,8 @@ Submit issues to: [ATmega_TimerInterrupt issues](https://github.com/khoih-prog/A
530514
4. Fix some bugs in v1.0.0
531515
5. Add more examples.
532516
6. Add support to **ATmega164(A/P), ATmega324(A/P/PA/PB), ATmega644(A/P), ATmega1284(P)**-based boards
533-
517+
7. Optimize code in examples
518+
8. Fix bug possibly causing system crash when using `_TIMERINTERRUPT_LOGLEVEL_ > 0`
534519

535520
---
536521
---
@@ -539,11 +524,13 @@ Submit issues to: [ATmega_TimerInterrupt issues](https://github.com/khoih-prog/A
539524

540525
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 [ATmega_TimerInterrupt library](https://github.com/khoih-prog/ATmega_TimerInterrupt)
541526

542-
1. Thanks to [LaurentR59](https://github.com/LaurentR59) to request the enhamcement [Support for DX CORE CPU and MightyCORE CPU possible? #8](https://github.com/khoih-prog/TimerInterrupt_Generic/issues/8) leading to this new library.
527+
1. Thanks to good work of [Hans](https://github.com/MCUdude) for the [MightyCore](https://github.com/MCUdude/MightyCore)
528+
2. Thanks to [LaurentR59](https://github.com/LaurentR59) to request the enhancement [Support for DX CORE CPU and MightyCORE CPU possible? #8](https://github.com/khoih-prog/TimerInterrupt_Generic/issues/8) leading to this new library.
543529

544530

545531
<table>
546532
<tr>
533+
<td align="center"><a href="https://github.com/MCUdude"><img src="https://github.com/MCUdude.png" width="100px;" alt="MCUdude"/><br /><sub><b>⭐️⭐️Hans</b></sub></a><br /></td>
547534
<td align="center"><a href="https://github.com/LaurentR59"><img src="https://github.com/LaurentR59.png" width="100px;" alt="LaurentR59"/><br /><sub><b>LaurentR59</b></sub></a><br /></td>
548535
</tr>
549536
</table>

0 commit comments

Comments
 (0)