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

Commit

Permalink
v1.1.1 to fix bug, optimize examples
Browse files Browse the repository at this point in the history
### Releases v1.1.1

1. Fix bug possibly causing system crash when using `_TIMERINTERRUPT_LOGLEVEL_ > 0` 
2. Optimize code in examples
  • Loading branch information
khoih-prog authored Aug 27, 2022
1 parent 66473cc commit f3b27af
Show file tree
Hide file tree
Showing 25 changed files with 420 additions and 725 deletions.
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
## Table of Contents

* [Changelog](#changelog)
* [Releases v1.1.1](#releases-v111)
* [Releases v1.1.0](#releases-v110)
* [Releases v1.0.0](#releases-v100)

Expand All @@ -21,6 +22,11 @@
## Changelog


### Releases v1.1.1

1. Fix bug possibly causing system crash when using `_TIMERINTERRUPT_LOGLEVEL_ > 0`
2. Optimize code in examples

### Releases v1.1.0

1. Fix missing code for Timer3 and Timer4
Expand Down
72 changes: 26 additions & 46 deletions examples/Argument_Complex/Argument_Complex.ino
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,28 @@
// TIMER_4 Only valid for ATmega324PB, not ready in core yet
#define USE_TIMER_4 false

#if (USE_TIMER_1)
#warning Using Timer1
#elif (USE_TIMER_2)
#warning Using Timer2
#elif (USE_TIMER_3)
#warning Using Timer3
#elif (USE_TIMER_4)
#warning Using Timer4
#if USE_TIMER_1
#define CurrentTimer ITimer1
#elif USE_TIMER_2
#define CurrentTimer ITimer2
#elif USE_TIMER_3
#define CurrentTimer ITimer3
#elif USE_TIMER_4
#define CurrentTimer ITimer4
#else
#error You must select one Timer
#endif

#if (_TIMERINTERRUPT_LOGLEVEL_ > 3)
#if (USE_TIMER_1)
#warning Using Timer1
#elif (USE_TIMER_2)
#warning Using Timer2
#elif (USE_TIMER_3)
#warning Using Timer3
#elif (USE_TIMER_4)
#warning Using Timer4
#endif
#endif

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

#if USE_TIMER_1

ITimer1.init();

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

if (ITimer1.attachInterruptInterval(TIMER_INTERVAL_MS, TimerHandler, (unsigned int) &myOutputPins))
{
Serial.print(F("Starting ITimer1 OK, millis() = ")); Serial.println(millis());
}
else
Serial.println(F("Can't set ITimer1. Select another freq. or timer"));

#elif USE_TIMER_2
CurrentTimer.init();

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

if (ITimer2.attachInterruptInterval(TIMER_INTERVAL_MS, TimerHandler))
if (CurrentTimer.attachInterruptInterval(TIMER_INTERVAL_MS, TimerHandler, (unsigned int) &myOutputPins))
{
Serial.print(F("Starting ITimer2 OK, millis() = ")); Serial.println(millis());
Serial.print(F("Starting ITimer OK, millis() = ")); Serial.println(millis());
}
else
Serial.println(F("Can't set ITimer2. Select another freq. or timer"));

#elif USE_TIMER_3

ITimer3.init();

if (ITimer3.attachInterruptInterval(TIMER_INTERVAL_MS, TimerHandler, outputPin))
{
Serial.print(F("Starting ITimer3 OK, millis() = ")); Serial.println(millis());

#if (TIMER_INTERRUPT_DEBUG > 1)
Serial.print(F("OutputPin = ")); Serial.print(outputPin);
Serial.print(F(" address: ")); Serial.println((uint32_t) &outputPin );
#endif
}
else
Serial.println(F("Can't set ITimer3. Select another freq. or timer"));

#endif
Serial.println(F("Can't set ITimer. Select another freq. or timer"));
}

void loop()
Expand Down
30 changes: 22 additions & 8 deletions examples/Argument_Complex_Multi/Argument_Complex_Multi.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,28 @@
// TIMER_4 Only valid for ATmega324PB, not ready in core yet
#define USE_TIMER_4 false

#if (USE_TIMER_1)
#warning Using Timer1
#elif (USE_TIMER_2)
#warning Using Timer2
#elif (USE_TIMER_3)
#warning Using Timer3
#elif (USE_TIMER_4)
#warning Using Timer4
#if USE_TIMER_1
#define CurrentTimer ITimer1
#elif USE_TIMER_2
#define CurrentTimer ITimer2
#elif USE_TIMER_3
#define CurrentTimer ITimer3
#elif USE_TIMER_4
#define CurrentTimer ITimer4
#else
#error You must select one Timer
#endif

#if (_TIMERINTERRUPT_LOGLEVEL_ > 3)
#if (USE_TIMER_1)
#warning Using Timer1
#elif (USE_TIMER_2)
#warning Using Timer2
#elif (USE_TIMER_3)
#warning Using Timer3
#elif (USE_TIMER_4)
#warning Using Timer4
#endif
#endif

// Can be included in many files without `Multiple Definitions` Linker Error
Expand Down
44 changes: 5 additions & 39 deletions examples/Argument_Complex_Multi/Argument_Complex_Multi.ino
Original file line number Diff line number Diff line change
Expand Up @@ -52,53 +52,19 @@ void setup()
// Timer0 is already used for micros(), millis(), delay(), etc and can't be used
// Select Timer 1-2
// Timer 2 is 8-bit timer, only for higher frequency

#if USE_TIMER_1

ITimer1.init();

CurrentTimer.init();

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

if (ITimer1.attachInterruptInterval(TIMER_INTERVAL_MS, TimerHandler, (unsigned int) &myOutputPins))
if (CurrentTimer.attachInterruptInterval(TIMER_INTERVAL_MS, TimerHandler, (unsigned int) &myOutputPins))
{
Serial.print(F("Starting ITimer1 OK, millis() = ")); Serial.println(millis());
Serial.print(F("Starting ITimer OK, millis() = ")); Serial.println(millis());
}
else
Serial.println(F("Can't set ITimer1. Select another freq. or timer"));

#elif USE_TIMER_2

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

if (ITimer2.attachInterruptInterval(TIMER_INTERVAL_MS, TimerHandler))
{
Serial.print(F("Starting ITimer2 OK, millis() = ")); Serial.println(millis());
}
else
Serial.println(F("Can't set ITimer2. Select another freq. or timer"));

#elif USE_TIMER_3

ITimer3.init();

if (ITimer3.attachInterruptInterval(TIMER_INTERVAL_MS, TimerHandler, outputPin))
{
Serial.print(F("Starting ITimer3 OK, millis() = ")); Serial.println(millis());

#if (TIMER_INTERRUPT_DEBUG > 1)
Serial.print(F("OutputPin = ")); Serial.print(outputPin);
Serial.print(F(" address: ")); Serial.println((uint32_t) &outputPin );
#endif
}
else
Serial.println(F("Can't set ITimer3. Select another freq. or timer"));

#endif
Serial.println(F("Can't set ITimer. Select another freq. or timer"));
}

void loop()
Expand Down
52 changes: 26 additions & 26 deletions examples/Argument_None/Argument_None.ino
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,24 @@
// TIMER_4 Only valid for ATmega324PB, not ready in core yet
#define USE_TIMER_4 false

#if (USE_TIMER_2)
#warning Using Timer1 and Timer2
#elif (USE_TIMER_3)
#warning Using Timer1 and Timer3
#elif (USE_TIMER_4)
#warning Using Timer1 and Timer4
#if USE_TIMER_2
#define CurrentTimer ITimer2
#elif USE_TIMER_3
#define CurrentTimer ITimer3
#elif USE_TIMER_4
#define CurrentTimer ITimer4
#else
#error You must select one Timer
#endif

#if (_TIMERINTERRUPT_LOGLEVEL_ > 3)
#if (USE_TIMER_2)
#warning Using Timer1 and Timer2
#elif (USE_TIMER_3)
#warning Using Timer1 and Timer3
#elif (USE_TIMER_4)
#warning Using Timer1 and Timer4
#endif
#endif

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

if (ITimer1.attachInterruptInterval(TIMER1_INTERVAL_MS, TimerHandler1))
{
Serial.print(F("Starting ITimer1 OK, millis() = ")); Serial.println(millis());
Serial.print(F("Starting ITimer1 OK, millis() = ")); Serial.println(millis());
}
else
Serial.println(F("Can't set ITimer1. Select another freq. or timer"));

#if USE_TIMER_2

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

if (ITimer2.attachInterruptInterval(TIMER_INTERVAL_MS, TimerHandler))
{
Serial.print(F("Starting ITimer2 OK, millis() = ")); Serial.println(millis());
}
else
Serial.println(F("Can't set ITimer2. Select another freq. or timer"));

#elif USE_TIMER_3

// For ATmega1284(P)
ITimer3.init();
///////////////////////////////////////////////
// Init second timer
CurrentTimer.init();

if (ITimer3.attachInterruptInterval(TIMER_INTERVAL_MS, TimerHandler))
if (CurrentTimer.attachInterruptInterval(TIMER_INTERVAL_MS, TimerHandler))
{
Serial.print(F("Starting ITimer3 OK, millis() = ")); Serial.println(millis());
Serial.print(F("Starting ITimer OK, millis() = ")); Serial.println(millis());
}
else
Serial.println(F("Can't set ITimer3. Select another freq. or timer"));

#endif
Serial.println(F("Can't set ITimer. Select another freq. or timer"));
}

void loop()
Expand Down
63 changes: 31 additions & 32 deletions examples/Argument_Simple/Argument_Simple.ino
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
// _TIMERINTERRUPT_LOGLEVEL_ from 0 to 4
// Don't define _TIMERINTERRUPT_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system.
#define TIMER_INTERRUPT_DEBUG 0
#define _TIMERINTERRUPT_LOGLEVEL_ 3
#define _TIMERINTERRUPT_LOGLEVEL_ 4

#define USE_TIMER_1 true

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

#if (USE_TIMER_2)
#warning Using Timer1 and Timer2
#elif (USE_TIMER_3)
#warning Using Timer1 and Timer3
#elif (USE_TIMER_4)
#warning Using Timer1 and Timer4
#if USE_TIMER_2
#define CurrentTimer ITimer2
#elif USE_TIMER_3
#define CurrentTimer ITimer3
#elif USE_TIMER_4
#define CurrentTimer ITimer4
#else
#error You must select one Timer
#endif

#if (_TIMERINTERRUPT_LOGLEVEL_ > 3)
#if (USE_TIMER_2)
#warning Using Timer1 and Timer2
#elif (USE_TIMER_3)
#warning Using Timer1 and Timer3
#elif (USE_TIMER_4)
#warning Using Timer1 and Timer4
#endif
#endif

// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
Expand Down Expand Up @@ -109,7 +121,9 @@ void setup()
// Timer0 is already used for micros(), millis(), delay(), etc and can't be used
// Select Timer 1-2
// Timer 2 is 8-bit timer, only for higher frequency


#if USE_TIMER_1

ITimer1.init();

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

if (ITimer1.attachInterruptInterval(TIMER1_INTERVAL_MS, TimerHandler1, outputPin1))
{
Serial.print(F("Starting ITimer1 OK, millis() = ")); Serial.println(millis());
Serial.print(F("Starting ITimer1 OK, millis() = ")); Serial.println(millis());

#if (TIMER_INTERRUPT_DEBUG > 1)
Serial.print(F("OutputPin1 = ")); Serial.print(outputPin1);
Expand All @@ -127,40 +141,25 @@ void setup()
}
else
Serial.println(F("Can't set ITimer1. Select another freq. or timer"));

#endif

#if USE_TIMER_2
///////////////////////////////////////////////

ITimer2.init();

if (ITimer2.attachInterruptInterval(TIMER_INTERVAL_MS, TimerHandler, outputPin))
{
Serial.print(F("Starting ITimer2 OK, millis() = ")); Serial.println(millis());
// Init second timer
CurrentTimer.init();

#if (TIMER_INTERRUPT_DEBUG > 1)
Serial.print(F("OutputPin = ")); Serial.print(outputPin);
Serial.print(F(" address: ")); Serial.println((uint32_t) &outputPin );
#endif
}
else
Serial.println(F("Can't set ITimer2. Select another freq. or timer"));

#elif USE_TIMER_3

ITimer3.init();

if (ITimer3.attachInterruptInterval(TIMER_INTERVAL_MS, TimerHandler, outputPin))
if (CurrentTimer.attachInterruptInterval(TIMER_INTERVAL_MS, TimerHandler, outputPin))
{
Serial.print(F("Starting ITimer3 OK, millis() = ")); Serial.println(millis());
Serial.print(F("Starting ITimer OK, millis() = ")); Serial.println(millis());

#if (TIMER_INTERRUPT_DEBUG > 1)
Serial.print(F("OutputPin = ")); Serial.print(outputPin);
Serial.print(F(" address: ")); Serial.println((uint32_t) &outputPin );
#endif
}
else
Serial.println(F("Can't set ITimer3. Select another freq. or timer"));

#endif
Serial.println(F("Can't set ITimer. Select another freq. or timer"));
}

void loop()
Expand Down
Loading

0 comments on commit f3b27af

Please sign in to comment.