From 5da293e180a3e313e0b98e888907fa8491eda101 Mon Sep 17 00:00:00 2001 From: Khoi Hoang <57012152+khoih-prog@users.noreply.github.com> Date: Thu, 25 Aug 2022 00:06:51 -0400 Subject: [PATCH] v1.1.2 to use auto SerialDebug port ### Release v1.1.2 1. Using `Serial3` for debugging with `Curiosity Nano AVRDB`, and `Serial1` for debugging with `Curiosity Nano AVRDA` --- changelog.md | 6 ++ .../Argument_Complex/Argument_Complex.ino | 45 +++++++------ examples/Argument_None/Argument_None.ino | 31 +++++---- examples/Argument_Simple/Argument_Simple.ino | 39 +++++++----- examples/Change_Interval/Change_Interval.ino | 39 +++++++----- .../Change_Interval_HF/Change_Interval_HF.ino | 39 +++++++----- examples/FakeAnalogWrite/FakeAnalogWrite.ino | 63 +++++++++++-------- .../ISR_16_Timers_Array_Complex.ino | 53 +++++++++------- examples/ISR_RPM_Measure/ISR_RPM_Measure.ino | 39 +++++++----- .../ISR_Timers_Array_Simple.ino | 41 +++++++----- examples/RPM_Measure/RPM_Measure.ino | 37 ++++++----- examples/SwitchDebounce/SwitchDebounce.ino | 45 +++++++------ examples/TimerDuration/TimerDuration.ino | 33 ++++++---- .../TimerInterruptTest/TimerInterruptTest.ino | 47 ++++++++------ examples/multiFileProject/multiFileProject.h | 9 +++ library.json | 2 +- library.properties | 2 +- src/Dx_ISR_Timer.h | 3 +- src/Dx_ISR_Timer.hpp | 9 +-- src/Dx_ISR_Timer_Impl.h | 3 +- src/Dx_TimerInterrupt.h | 3 +- src/Dx_TimerInterrupt.hpp | 9 +-- src/Dx_TimerInterrupt_Impl.h | 3 +- src/TimerInterrupt_Generic_Debug.h | 3 +- 24 files changed, 371 insertions(+), 232 deletions(-) diff --git a/changelog.md b/changelog.md index 697e248..eee110e 100644 --- a/changelog.md +++ b/changelog.md @@ -9,6 +9,7 @@ ## Table of Contents * [Changelog](#changelog) + * [Release v1.1.2](#release-v112) * [Release v1.1.1](#release-v111) * [Release v1.1.0](#release-v110) * [Initial Release v1.0.0](#initial-release-v100) @@ -18,6 +19,11 @@ ## Changelog +### Release v1.1.2 + +1. Using `Serial3` for debugging with `Curiosity Nano AVRDB`, and `Serial1` for debugging with `Curiosity Nano AVRDA` + + ### Release v1.1.1 1. Using Serial1 instead of Serial for debugging with Curiosity Nano AVRDA/AVRDB diff --git a/examples/Argument_Complex/Argument_Complex.ino b/examples/Argument_Complex/Argument_Complex.ino index 2d3e6ed..c8c2dc6 100644 --- a/examples/Argument_Complex/Argument_Complex.ino +++ b/examples/Argument_Complex/Argument_Complex.ino @@ -73,6 +73,15 @@ #endif #endif +#if defined(__AVR_AVR128DA48__) + #define SerialDebug Serial1 +#elif defined(__AVR_AVR128DB48__) + #define SerialDebug Serial3 +#else + // standard Serial + #define SerialDebug Serial +#endif + struct pinStruct { unsigned int Pin1; @@ -88,19 +97,19 @@ void TimerHandler1(unsigned int outputPinsAddress) //timer interrupt toggles pins #if (TIMER_INTERRUPT_DEBUG > 1) - Serial1.print("Toggle pin1 = "); Serial1.println( ((pinStruct *) outputPinsAddress)->Pin1 ); + SerialDebug.print("Toggle pin1 = "); SerialDebug.println( ((pinStruct *) outputPinsAddress)->Pin1 ); #endif digitalWrite(((pinStruct *) outputPinsAddress)->Pin1, toggle); #if (TIMER_INTERRUPT_DEBUG > 1) - Serial1.print("Read pin2 A0 ("); Serial1.print(((pinStruct *) outputPinsAddress)->Pin2 ); - Serial1.print(") = "); - Serial1.println(digitalRead(((pinStruct *) outputPinsAddress)->Pin2) ? "HIGH" : "LOW" ); + SerialDebug.print("Read pin2 A0 ("); SerialDebug.print(((pinStruct *) outputPinsAddress)->Pin2 ); + SerialDebug.print(") = "); + SerialDebug.println(digitalRead(((pinStruct *) outputPinsAddress)->Pin2) ? "HIGH" : "LOW" ); - Serial1.print("Read pin3 A1 ("); Serial1.print(((pinStruct *) outputPinsAddress)->Pin3 ); - Serial1.print(") = "); - Serial1.println(digitalRead(((pinStruct *) outputPinsAddress)->Pin3) ? "HIGH" : "LOW" ); + SerialDebug.print("Read pin3 A1 ("); SerialDebug.print(((pinStruct *) outputPinsAddress)->Pin3 ); + SerialDebug.print(") = "); + SerialDebug.println(digitalRead(((pinStruct *) outputPinsAddress)->Pin3) ? "HIGH" : "LOW" ); #endif toggle = !toggle; @@ -114,21 +123,21 @@ void setup() pinMode(myOutputPins.Pin2, INPUT_PULLUP); pinMode(myOutputPins.Pin3, INPUT_PULLUP); - Serial1.begin(115200); - while (!Serial1 && millis() < 5000); + SerialDebug.begin(115200); + while (!SerialDebug && millis() < 5000); - Serial1.print(F("\nStarting Argument_Complex on ")); Serial1.println(BOARD_NAME); - Serial1.println(DX_TIMER_INTERRUPT_VERSION); - Serial1.print(F("CPU Frequency = ")); Serial1.print(F_CPU / 1000000); Serial1.println(F(" MHz")); + SerialDebug.print(F("\nStarting Argument_Complex on ")); SerialDebug.println(BOARD_NAME); + SerialDebug.println(DX_TIMER_INTERRUPT_VERSION); + SerialDebug.print(F("CPU Frequency = ")); SerialDebug.print(F_CPU / 1000000); SerialDebug.println(F(" MHz")); - Serial1.print(F("TCB Clock Frequency = ")); + SerialDebug.print(F("TCB Clock Frequency = ")); #if USING_FULL_CLOCK - Serial1.println(F("Full clock (24/16MHz, etc) for highest accuracy")); + SerialDebug.println(F("Full clock (24/16MHz, etc) for highest accuracy")); #elif USING_HALF_CLOCK - Serial1.println(F("Half clock (12/8MHz, etc.) for high accuracy")); + SerialDebug.println(F("Half clock (12/8MHz, etc.) for high accuracy")); #else - Serial1.println(F("250KHz for lower accuracy but longer time")); + SerialDebug.println(F("250KHz for lower accuracy but longer time")); #endif // Timer TCB2 is used for micros(), millis(), delay(), etc and can't be used @@ -136,10 +145,10 @@ void setup() if (CurrentTimer.attachInterruptInterval(TIMER1_INTERVAL_MS, TimerHandler1, (unsigned int) &myOutputPins)) { - Serial1.print(F("Starting ITimer OK, millis() = ")); Serial1.println(millis()); + SerialDebug.print(F("Starting ITimer OK, millis() = ")); SerialDebug.println(millis()); } else - Serial1.println(F("Can't set ITimer. Select another freq. or timer")); + SerialDebug.println(F("Can't set ITimer. Select another freq. or timer")); } void loop() diff --git a/examples/Argument_None/Argument_None.ino b/examples/Argument_None/Argument_None.ino index 7112ca6..d5eeeed 100644 --- a/examples/Argument_None/Argument_None.ino +++ b/examples/Argument_None/Argument_None.ino @@ -75,6 +75,15 @@ #endif #endif +#if defined(__AVR_AVR128DA48__) + #define SerialDebug Serial1 +#elif defined(__AVR_AVR128DB48__) + #define SerialDebug Serial3 +#else + // standard Serial + #define SerialDebug Serial +#endif + void TimerHandler1(void) { static bool toggle = false; @@ -88,21 +97,21 @@ void setup() { pinMode(LED_BUILTIN, OUTPUT); - Serial1.begin(115200); - while (!Serial1 && millis() < 5000); + SerialDebug.begin(115200); + while (!SerialDebug && millis() < 5000); - Serial1.print(F("\nStarting Argument_None on ")); Serial1.println(BOARD_NAME); - Serial1.println(DX_TIMER_INTERRUPT_VERSION); - Serial1.print(F("CPU Frequency = ")); Serial1.print(F_CPU / 1000000); Serial1.println(F(" MHz")); + SerialDebug.print(F("\nStarting Argument_None on ")); SerialDebug.println(BOARD_NAME); + SerialDebug.println(DX_TIMER_INTERRUPT_VERSION); + SerialDebug.print(F("CPU Frequency = ")); SerialDebug.print(F_CPU / 1000000); SerialDebug.println(F(" MHz")); - Serial1.print(F("TCB Clock Frequency = ")); + SerialDebug.print(F("TCB Clock Frequency = ")); #if USING_FULL_CLOCK - Serial1.println(F("Full clock (24/16MHz, etc) for highest accuracy")); + SerialDebug.println(F("Full clock (24/16MHz, etc) for highest accuracy")); #elif USING_HALF_CLOCK - Serial1.println(F("Half clock (12/8MHz, etc.) for high accuracy")); + SerialDebug.println(F("Half clock (12/8MHz, etc.) for high accuracy")); #else - Serial1.println(F("250KHz for lower accuracy but longer time")); + SerialDebug.println(F("250KHz for lower accuracy but longer time")); #endif // Timer TCB2 is used for micros(), millis(), delay(), etc and can't be used @@ -110,10 +119,10 @@ void setup() if (CurrentTimer.attachInterruptInterval(TIMER1_INTERVAL_MS, TimerHandler1)) { - Serial1.print(F("Starting ITimer OK, millis() = ")); Serial1.println(millis()); + SerialDebug.print(F("Starting ITimer OK, millis() = ")); SerialDebug.println(millis()); } else - Serial1.println(F("Can't set ITimer. Select another freq. or timer")); + SerialDebug.println(F("Can't set ITimer. Select another freq. or timer")); } void loop() diff --git a/examples/Argument_Simple/Argument_Simple.ino b/examples/Argument_Simple/Argument_Simple.ino index 137027a..568698f 100644 --- a/examples/Argument_Simple/Argument_Simple.ino +++ b/examples/Argument_Simple/Argument_Simple.ino @@ -73,6 +73,15 @@ #endif #endif +#if defined(__AVR_AVR128DA48__) + #define SerialDebug Serial1 +#elif defined(__AVR_AVR128DB48__) + #define SerialDebug Serial3 +#else + // standard Serial + #define SerialDebug Serial +#endif + unsigned int outputPin1 = LED_BUILTIN; #define TIMER1_INTERVAL_MS 1000 @@ -83,8 +92,8 @@ void TimerHandler1(unsigned int outputPin = LED_BUILTIN) #if (TIMER_INTERRUPT_DEBUG > 1) //timer interrupt toggles pin outputPin, default LED_BUILTIN - Serial1.print("pin1 = "); Serial1.print(outputPin); - Serial1.print(" address: "); Serial1.println((uint32_t) &outputPin ); + SerialDebug.print("pin1 = "); SerialDebug.print(outputPin); + SerialDebug.print(" address: "); SerialDebug.println((uint32_t) &outputPin ); #endif digitalWrite(outputPin, toggle); @@ -95,21 +104,21 @@ void setup() { pinMode(LED_BUILTIN, OUTPUT); - Serial1.begin(115200); - while (!Serial1 && millis() < 5000); + SerialDebug.begin(115200); + while (!SerialDebug && millis() < 5000); - Serial1.print(F("\nStarting Argument_Simple on ")); Serial1.println(BOARD_NAME); - Serial1.println(DX_TIMER_INTERRUPT_VERSION); - Serial1.print(F("CPU Frequency = ")); Serial1.print(F_CPU / 1000000); Serial1.println(F(" MHz")); + SerialDebug.print(F("\nStarting Argument_Simple on ")); SerialDebug.println(BOARD_NAME); + SerialDebug.println(DX_TIMER_INTERRUPT_VERSION); + SerialDebug.print(F("CPU Frequency = ")); SerialDebug.print(F_CPU / 1000000); SerialDebug.println(F(" MHz")); - Serial1.print(F("TCB Clock Frequency = ")); + SerialDebug.print(F("TCB Clock Frequency = ")); #if USING_FULL_CLOCK - Serial1.println(F("Full clock (24/16MHz, etc) for highest accuracy")); + SerialDebug.println(F("Full clock (24/16MHz, etc) for highest accuracy")); #elif USING_HALF_CLOCK - Serial1.println(F("Half clock (12/8MHz, etc.) for high accuracy")); + SerialDebug.println(F("Half clock (12/8MHz, etc.) for high accuracy")); #else - Serial1.println(F("250KHz for lower accuracy but longer time")); + SerialDebug.println(F("250KHz for lower accuracy but longer time")); #endif // Timer2 is used for micros(), millis(), delay(), etc and can't be used @@ -117,15 +126,15 @@ void setup() if (CurrentTimer.attachInterruptInterval(TIMER1_INTERVAL_MS, TimerHandler1, outputPin1)) { - Serial1.print(F("Starting ITimer OK, millis() = ")); Serial1.println(millis()); + SerialDebug.print(F("Starting ITimer OK, millis() = ")); SerialDebug.println(millis()); #if (TIMER_INTERRUPT_DEBUG > 1) - Serial1.print(F("OutputPin1 = ")); Serial1.print(outputPin1); - Serial1.print(F(" address: ")); Serial1.println((uint32_t) &outputPin1 ); + SerialDebug.print(F("OutputPin1 = ")); SerialDebug.print(outputPin1); + SerialDebug.print(F(" address: ")); SerialDebug.println((uint32_t) &outputPin1 ); #endif } else - Serial1.println(F("Can't set ITimer. Select another freq. or timer")); + SerialDebug.println(F("Can't set ITimer. Select another freq. or timer")); } void loop() diff --git a/examples/Change_Interval/Change_Interval.ino b/examples/Change_Interval/Change_Interval.ino index 1dccca9..e996e63 100644 --- a/examples/Change_Interval/Change_Interval.ino +++ b/examples/Change_Interval/Change_Interval.ino @@ -73,21 +73,30 @@ #endif #endif +#if defined(__AVR_AVR128DA48__) + #define SerialDebug Serial1 +#elif defined(__AVR_AVR128DB48__) + #define SerialDebug Serial3 +#else + // standard Serial + #define SerialDebug Serial +#endif + #define TIMER1_INTERVAL_MS 50UL volatile uint32_t Timer1Count = 1; void printResult(uint32_t currTime) { - Serial1.print(F("Time = ")); Serial1.print(currTime); - Serial1.print(F(", Timer1Count = ")); Serial1.println(Timer1Count); + SerialDebug.print(F("Time = ")); SerialDebug.print(currTime); + SerialDebug.print(F(", Timer1Count = ")); SerialDebug.println(Timer1Count); } void TimerHandler1() { static bool toggle = false; - // Flag for checking to be sure ISR is working as Serial1.print is not OK here in ISR + // Flag for checking to be sure ISR is working as SerialDebug.print is not OK here in ISR Timer1Count++; //timer interrupt toggles pin LED_BUILTIN @@ -99,21 +108,21 @@ void setup() { pinMode(LED_BUILTIN, OUTPUT); - Serial1.begin(115200); - while (!Serial1 && millis() < 5000); + SerialDebug.begin(115200); + while (!SerialDebug && millis() < 5000); - Serial1.print(F("\nStarting Change_Interval on ")); Serial1.println(BOARD_NAME); - Serial1.println(DX_TIMER_INTERRUPT_VERSION); - Serial1.print(F("CPU Frequency = ")); Serial1.print(F_CPU / 1000000); Serial1.println(F(" MHz")); + SerialDebug.print(F("\nStarting Change_Interval on ")); SerialDebug.println(BOARD_NAME); + SerialDebug.println(DX_TIMER_INTERRUPT_VERSION); + SerialDebug.print(F("CPU Frequency = ")); SerialDebug.print(F_CPU / 1000000); SerialDebug.println(F(" MHz")); - Serial1.print(F("TCB Clock Frequency = ")); + SerialDebug.print(F("TCB Clock Frequency = ")); #if USING_FULL_CLOCK - Serial1.println(F("Full clock (24/16MHz, etc) for highest accuracy")); + SerialDebug.println(F("Full clock (24/16MHz, etc) for highest accuracy")); #elif USING_HALF_CLOCK - Serial1.println(F("Half clock (12/8MHz, etc.) for high accuracy")); + SerialDebug.println(F("Half clock (12/8MHz, etc.) for high accuracy")); #else - Serial1.println(F("250KHz for lower accuracy but longer time")); + SerialDebug.println(F("250KHz for lower accuracy but longer time")); #endif // Timer TCB2 is used for micros(), millis(), delay(), etc and can't be used @@ -121,10 +130,10 @@ void setup() if (CurrentTimer.attachInterruptInterval(TIMER1_INTERVAL_MS, TimerHandler1)) { - Serial1.print(F("Starting ITimer OK, millis() = ")); Serial1.println(millis()); + SerialDebug.print(F("Starting ITimer OK, millis() = ")); SerialDebug.println(millis()); } else - Serial1.println(F("Can't set ITimer. Select another freq. or timer")); + SerialDebug.println(F("Can't set ITimer. Select another freq. or timer")); } #define CHECK_INTERVAL_MS 1000L @@ -156,7 +165,7 @@ void loop() Timer1Count++; - Serial1.print(F("Changing Interval, Timer = ")); Serial1.println(TIMER1_INTERVAL_MS * (multFactor + 1)); + SerialDebug.print(F("Changing Interval, Timer = ")); SerialDebug.println(TIMER1_INTERVAL_MS * (multFactor + 1)); lastChangeTime = currTime; } diff --git a/examples/Change_Interval_HF/Change_Interval_HF.ino b/examples/Change_Interval_HF/Change_Interval_HF.ino index 3c32685..c9d2e6e 100644 --- a/examples/Change_Interval_HF/Change_Interval_HF.ino +++ b/examples/Change_Interval_HF/Change_Interval_HF.ino @@ -73,14 +73,23 @@ #endif #endif +#if defined(__AVR_AVR128DA48__) + #define SerialDebug Serial1 +#elif defined(__AVR_AVR128DB48__) + #define SerialDebug Serial3 +#else + // standard Serial + #define SerialDebug Serial +#endif + #define TIMER1_FREQUENCY 50UL volatile uint32_t Timer1Count = 0; void printResult(uint32_t currTime) { - Serial1.print(F("Time = ")); Serial1.print(currTime); - Serial1.print(F(", Timer1Count = ")); Serial1.println(Timer1Count); + SerialDebug.print(F("Time = ")); SerialDebug.print(currTime); + SerialDebug.print(F(", Timer1Count = ")); SerialDebug.println(Timer1Count); } void TimerHandler1() @@ -96,23 +105,23 @@ void TimerHandler1() void setup() { - Serial1.begin(115200); - while (!Serial1 && millis() < 5000); + SerialDebug.begin(115200); + while (!SerialDebug && millis() < 5000); pinMode(LED_BUILTIN, OUTPUT); - Serial1.print(F("\nStarting Change_Interval_HF on ")); Serial1.println(BOARD_NAME); - Serial1.println(DX_TIMER_INTERRUPT_VERSION); - Serial1.print(F("CPU Frequency = ")); Serial1.print(F_CPU / 1000000); Serial1.println(F(" MHz")); + SerialDebug.print(F("\nStarting Change_Interval_HF on ")); SerialDebug.println(BOARD_NAME); + SerialDebug.println(DX_TIMER_INTERRUPT_VERSION); + SerialDebug.print(F("CPU Frequency = ")); SerialDebug.print(F_CPU / 1000000); SerialDebug.println(F(" MHz")); - Serial1.print(F("TCB Clock Frequency = ")); + SerialDebug.print(F("TCB Clock Frequency = ")); #if USING_FULL_CLOCK - Serial1.println(F("Full clock (24/16MHz, etc) for highest accuracy")); + SerialDebug.println(F("Full clock (24/16MHz, etc) for highest accuracy")); #elif USING_HALF_CLOCK - Serial1.println(F("Half clock (12/8MHz, etc.) for high accuracy")); + SerialDebug.println(F("Half clock (12/8MHz, etc.) for high accuracy")); #else - Serial1.println(F("250KHz for lower accuracy but longer time")); + SerialDebug.println(F("250KHz for lower accuracy but longer time")); #endif // Timer2 is used for micros(), millis(), delay(), etc and can't be used @@ -120,11 +129,11 @@ void setup() if (CurrentTimer.attachInterrupt(TIMER1_FREQUENCY, TimerHandler1)) { - Serial1.print(F("Starting ITimer OK, millis() = ")); Serial1.println(millis()); - Serial1.print(F("Frequency, Timer = ")); Serial1.println(TIMER1_FREQUENCY); + SerialDebug.print(F("Starting ITimer OK, millis() = ")); SerialDebug.println(millis()); + SerialDebug.print(F("Frequency, Timer = ")); SerialDebug.println(TIMER1_FREQUENCY); } else - Serial1.println(F("Can't set ITimer. Select another freq. or timer")); + SerialDebug.println(F("Can't set ITimer. Select another freq. or timer")); } #define CHECK_INTERVAL_MS 1000L @@ -154,7 +163,7 @@ void loop() CurrentTimer.setFrequency(TIMER1_FREQUENCY / (multFactor + 1), TimerHandler1); - Serial1.print(F("Changing Frequency, Timer = ")); Serial1.println(TIMER1_FREQUENCY / (multFactor + 1)); + SerialDebug.print(F("Changing Frequency, Timer = ")); SerialDebug.println(TIMER1_FREQUENCY / (multFactor + 1)); lastChangeTime = currTime; } diff --git a/examples/FakeAnalogWrite/FakeAnalogWrite.ino b/examples/FakeAnalogWrite/FakeAnalogWrite.ino index 8c8b551..5df4d52 100644 --- a/examples/FakeAnalogWrite/FakeAnalogWrite.ino +++ b/examples/FakeAnalogWrite/FakeAnalogWrite.ino @@ -73,6 +73,15 @@ #endif #endif +#if defined(__AVR_AVR128DA48__) + #define SerialDebug Serial1 +#elif defined(__AVR_AVR128DB48__) + #define SerialDebug Serial3 +#else + // standard Serial + #define SerialDebug Serial +#endif + // For PWM_Value from 0-255.You can change to 1024 or 2048 #define MAX_PWM_VALUE 256 @@ -134,8 +143,8 @@ typedef struct bool beingUsed; } ISRTimerData; -// Avoid doing something fancy in ISR, for example Serial1.print() -// The pure simple Serial1.prints here are just for demonstration and testing. Must be eliminate in working environment +// Avoid doing something fancy in ISR, for example SerialDebug.print() +// The pure simple SerialDebug.prints here are just for demonstration and testing. Must be eliminate in working environment // Or you can get this run-time error / crash /////////////////////////////////// @@ -191,21 +200,21 @@ void setup() { pinMode(LED_BUILTIN, OUTPUT); - Serial1.begin(115200); - while (!Serial1 && millis() < 5000); + SerialDebug.begin(115200); + while (!SerialDebug && millis() < 5000); - Serial1.print(F("\nStarting FakeAnalogWrite on ")); Serial1.println(BOARD_NAME); - Serial1.println(DX_TIMER_INTERRUPT_VERSION); - Serial1.print(F("CPU Frequency = ")); Serial1.print(F_CPU / 1000000); Serial1.println(F(" MHz")); + SerialDebug.print(F("\nStarting FakeAnalogWrite on ")); SerialDebug.println(BOARD_NAME); + SerialDebug.println(DX_TIMER_INTERRUPT_VERSION); + SerialDebug.print(F("CPU Frequency = ")); SerialDebug.print(F_CPU / 1000000); SerialDebug.println(F(" MHz")); - Serial1.print(F("TCB Clock Frequency = ")); + SerialDebug.print(F("TCB Clock Frequency = ")); #if USING_FULL_CLOCK - Serial1.println(F("Full clock (24/16MHz, etc) for highest accuracy")); + SerialDebug.println(F("Full clock (24/16MHz, etc) for highest accuracy")); #elif USING_HALF_CLOCK - Serial1.println(F("Half clock (12/8MHz, etc.) for high accuracy")); + SerialDebug.println(F("Half clock (12/8MHz, etc.) for high accuracy")); #else - Serial1.println(F("250KHz for lower accuracy but longer time")); + SerialDebug.println(F("250KHz for lower accuracy but longer time")); #endif CurrentTimer.init(); @@ -213,10 +222,10 @@ void setup() //if (CurrentTimer.attachInterruptInterval(TIMER2_INTERVAL_MS, TimerHandler)) if (CurrentTimer.attachInterrupt(TIMER2_FREQUENCY_HZ, TimerHandler)) { - Serial1.print(F("Starting ITimer OK, millis() = ")); Serial1.println(millis()); + SerialDebug.print(F("Starting ITimer OK, millis() = ")); SerialDebug.println(millis()); } else - Serial1.println(F("Can't set ITimer. Select another freq. or timer")); + SerialDebug.println(F("Can't set ITimer. Select another freq. or timer")); // Just to demonstrate, don't use too many ISR Timers if not absolutely necessary // You can use up to 16 timer for each ISR_Timer @@ -250,7 +259,7 @@ void fakeAnalogWrite(uint16_t pin, uint16_t value) if (curISRTimerData[i].PWM_PremapValue == localValue) { #if (LOCAL_DEBUG > 0) - Serial1.print(F("Ignore : Same Value for index = ")); Serial1.println(i); + SerialDebug.print(F("Ignore : Same Value for index = ")); SerialDebug.println(i); #endif return; @@ -281,7 +290,7 @@ void fakeAnalogWrite(uint16_t pin, uint16_t value) } #if (LOCAL_DEBUG > 1) - Serial1.print(F("localIndex = ")); Serial1.println(localIndex); + SerialDebug.print(F("localIndex = ")); SerialDebug.println(localIndex); #endif // Can use map() function @@ -294,10 +303,10 @@ void fakeAnalogWrite(uint16_t pin, uint16_t value) #endif #if (LOCAL_DEBUG > 0) - Serial1.print(F("Update index = ")); Serial1.print(i); - Serial1.print(F(", pin = ")); Serial1.print(pin); - Serial1.print(F(", input PWM_Value = ")); Serial1.print(value); - Serial1.print(F(", mapped PWM_Value = ")); Serial1.println(curISRTimerData[i].PWM_Value); + SerialDebug.print(F("Update index = ")); SerialDebug.print(i); + SerialDebug.print(F(", pin = ")); SerialDebug.print(pin); + SerialDebug.print(F(", input PWM_Value = ")); SerialDebug.print(value); + SerialDebug.print(F(", mapped PWM_Value = ")); SerialDebug.println(curISRTimerData[i].PWM_Value); #endif } } @@ -347,7 +356,7 @@ void fakeAnalogWrite(uint16_t pin, uint16_t value) } #if (LOCAL_DEBUG > 1) - Serial1.print(F("localIndex = ")); Serial1.println(localIndex); + SerialDebug.print(F("localIndex = ")); SerialDebug.println(localIndex); #endif // Can use map() function @@ -364,10 +373,10 @@ void fakeAnalogWrite(uint16_t pin, uint16_t value) pinMode(pin, OUTPUT); #if (LOCAL_DEBUG > 0) - Serial1.print(F("Add index = ")); Serial1.print(i); - Serial1.print(F(", pin = ")); Serial1.print(pin); - Serial1.print(F(", input PWM_Value = ")); Serial1.print(value); - Serial1.print(F(", mapped PWM_Value = ")); Serial1.println(curISRTimerData[i].PWM_Value); + SerialDebug.print(F("Add index = ")); SerialDebug.print(i); + SerialDebug.print(F(", pin = ")); SerialDebug.print(pin); + SerialDebug.print(F(", input PWM_Value = ")); SerialDebug.print(value); + SerialDebug.print(F(", mapped PWM_Value = ")); SerialDebug.println(curISRTimerData[i].PWM_Value); #endif return; @@ -406,13 +415,13 @@ void loop() fakeAnalogWrite(A4, i * DIVIDER); #if (LOCAL_DEBUG > 0) - Serial1.print(F("Test PWM_Value = ")); Serial1.print(i * DIVIDER); - Serial1.print(F(", max = ")); Serial1.println(MAX_PWM_VALUE - 1); + SerialDebug.print(F("Test PWM_Value = ")); SerialDebug.print(i * DIVIDER); + SerialDebug.print(F(", max = ")); SerialDebug.println(MAX_PWM_VALUE - 1); #endif delay(DELAY_BETWEEN_CHANGE_MS); } - Serial1.println(F("===================")); + SerialDebug.println(F("===================")); delay(REPEAT_INTERVAL_MS); } diff --git a/examples/ISR_16_Timers_Array_Complex/ISR_16_Timers_Array_Complex.ino b/examples/ISR_16_Timers_Array_Complex/ISR_16_Timers_Array_Complex.ino index f304d3b..ee8b171 100644 --- a/examples/ISR_16_Timers_Array_Complex/ISR_16_Timers_Array_Complex.ino +++ b/examples/ISR_16_Timers_Array_Complex/ISR_16_Timers_Array_Complex.ino @@ -78,6 +78,15 @@ #endif #endif +#if defined(__AVR_AVR128DA48__) + #define SerialDebug Serial1 +#elif defined(__AVR_AVR128DB48__) + #define SerialDebug Serial3 +#else + // standard Serial + #define SerialDebug Serial +#endif + ISR_Timer ISR_Timer1; #define LED_TOGGLE_INTERVAL_MS 1000L @@ -126,8 +135,8 @@ typedef void (*irqCallback) (); unsigned long previousMillis; } ISRTimerData; - // Avoid doing something fancy in ISR, for example Serial1.print() - // The pure simple Serial1.prints here are just for demonstration and testing. Must be eliminate in working environment + // Avoid doing something fancy in ISR, for example SerialDebug.print() + // The pure simple SerialDebug.prints here are just for demonstration and testing. Must be eliminate in working environment // Or you can get this run-time error / crash void doingSomething(int index); @@ -298,20 +307,20 @@ void simpleTimerDoingSomething2s() unsigned long currMillis = millis(); - Serial1.print(F("SimpleTimer : "));Serial1.print(SIMPLE_TIMER_MS / 1000); - Serial1.print(F(", ms : ")); Serial1.print(currMillis); - Serial1.print(F(", Dms : ")); Serial1.println(currMillis - previousMillis); + SerialDebug.print(F("SimpleTimer : "));SerialDebug.print(SIMPLE_TIMER_MS / 1000); + SerialDebug.print(F(", ms : ")); SerialDebug.print(currMillis); + SerialDebug.print(F(", Dms : ")); SerialDebug.println(currMillis - previousMillis); for (uint16_t i = 0; i < NUMBER_ISR_TIMERS; i++) { #if USE_COMPLEX_STRUCT - Serial1.print(F("Timer : ")); Serial1.print(i); - Serial1.print(F(", programmed : ")); Serial1.print(curISRTimerData[i].TimerInterval); - Serial1.print(F(", actual : ")); Serial1.println(curISRTimerData[i].deltaMillis); + SerialDebug.print(F("Timer : ")); SerialDebug.print(i); + SerialDebug.print(F(", programmed : ")); SerialDebug.print(curISRTimerData[i].TimerInterval); + SerialDebug.print(F(", actual : ")); SerialDebug.println(curISRTimerData[i].deltaMillis); #else - Serial1.print(F("Timer : ")); Serial1.print(i); - Serial1.print(F(", programmed : ")); Serial1.print(TimerInterval[i]); - Serial1.print(F(", actual : ")); Serial1.println(deltaMillis[i]); + SerialDebug.print(F("Timer : ")); SerialDebug.print(i); + SerialDebug.print(F(", programmed : ")); SerialDebug.print(TimerInterval[i]); + SerialDebug.print(F(", actual : ")); SerialDebug.println(deltaMillis[i]); #endif } @@ -322,31 +331,31 @@ void setup() { pinMode(LED_BUILTIN, OUTPUT); - Serial1.begin(115200); - while (!Serial1 && millis() < 5000); + SerialDebug.begin(115200); + while (!SerialDebug && millis() < 5000); - Serial1.print(F("\nStarting ISR_16_Timers_Array_Complex on ")); Serial1.println(BOARD_NAME); - Serial1.println(DX_TIMER_INTERRUPT_VERSION); - Serial1.print(F("CPU Frequency = ")); Serial1.print(F_CPU / 1000000); Serial1.println(F(" MHz")); + SerialDebug.print(F("\nStarting ISR_16_Timers_Array_Complex on ")); SerialDebug.println(BOARD_NAME); + SerialDebug.println(DX_TIMER_INTERRUPT_VERSION); + SerialDebug.print(F("CPU Frequency = ")); SerialDebug.print(F_CPU / 1000000); SerialDebug.println(F(" MHz")); - Serial1.print(F("TCB Clock Frequency = ")); + SerialDebug.print(F("TCB Clock Frequency = ")); #if USING_FULL_CLOCK - Serial1.println(F("Full clock (24/16MHz, etc) for highest accuracy")); + SerialDebug.println(F("Full clock (24/16MHz, etc) for highest accuracy")); #elif USING_HALF_CLOCK - Serial1.println(F("Half clock (12/8MHz, etc.) for high accuracy")); + SerialDebug.println(F("Half clock (12/8MHz, etc.) for high accuracy")); #else - Serial1.println(F("250KHz for lower accuracy but longer time")); + SerialDebug.println(F("250KHz for lower accuracy but longer time")); #endif CurrentTimer.init(); if (CurrentTimer.attachInterruptInterval(TIMER1_INTERVAL_MS, TimerHandler1)) { - Serial1.print(F("Starting ITimer OK, millis() = ")); Serial1.println(millis()); + SerialDebug.print(F("Starting ITimer OK, millis() = ")); SerialDebug.println(millis()); } else - Serial1.println(F("Can't set ITimer. Select another freq. or timer")); + SerialDebug.println(F("Can't set ITimer. Select another freq. or timer")); //ISR_Timer1.setInterval(2000L, doingSomething2s); //ISR_Timer1.setInterval(5000L, doingSomething5s); diff --git a/examples/ISR_RPM_Measure/ISR_RPM_Measure.ino b/examples/ISR_RPM_Measure/ISR_RPM_Measure.ino index 8b5d7b3..a692d94 100644 --- a/examples/ISR_RPM_Measure/ISR_RPM_Measure.ino +++ b/examples/ISR_RPM_Measure/ISR_RPM_Measure.ino @@ -73,6 +73,15 @@ #endif #endif +#if defined(__AVR_AVR128DA48__) + #define SerialDebug Serial1 +#elif defined(__AVR_AVR128DB48__) + #define SerialDebug Serial3 +#else + // standard Serial + #define SerialDebug Serial +#endif + // To modify according to your board // For Curiosity Nano AVR128DA48 => use SW => PIN_PC7 // For Curiosity Nano AVR128DB48 => use SW => PIN_PB2 @@ -121,8 +130,8 @@ void TimerHandler1() avgRPM = ( 2 * avgRPM + RPM) / 3, #if (TIMER_INTERRUPT_DEBUG > 1) - Serial1.print("RPM = "); Serial1.print(avgRPM); - Serial1.print(", rotationTime ms = "); Serial1.println(rotationTime * TIMER1_INTERVAL_MS); + SerialDebug.print("RPM = "); SerialDebug.print(avgRPM); + SerialDebug.print(", rotationTime ms = "); SerialDebug.println(rotationTime * TIMER1_INTERVAL_MS); #endif rotationTime = 0; @@ -142,7 +151,7 @@ void TimerHandler1() RPM = 0; #if (TIMER_INTERRUPT_DEBUG > 1) - Serial1.print("RPM = "); Serial1.print(RPM); Serial1.print(", rotationTime = "); Serial1.println(rotationTime); + SerialDebug.print("RPM = "); SerialDebug.print(RPM); SerialDebug.print(", rotationTime = "); SerialDebug.println(rotationTime); #endif rotationTime = 0; @@ -155,24 +164,24 @@ void TimerHandler1() void setup() { - Serial1.begin(115200); - while (!Serial1 && millis() < 5000); + SerialDebug.begin(115200); + while (!SerialDebug && millis() < 5000); pinMode(LED_BUILTIN, OUTPUT); pinMode(interruptPin, INPUT_PULLUP); - Serial1.print(F("\nStarting ISR_RPM_Measure on ")); Serial1.println(BOARD_NAME); - Serial1.println(DX_TIMER_INTERRUPT_VERSION); - Serial1.print(F("CPU Frequency = ")); Serial1.print(F_CPU / 1000000); Serial1.println(F(" MHz")); + SerialDebug.print(F("\nStarting ISR_RPM_Measure on ")); SerialDebug.println(BOARD_NAME); + SerialDebug.println(DX_TIMER_INTERRUPT_VERSION); + SerialDebug.print(F("CPU Frequency = ")); SerialDebug.print(F_CPU / 1000000); SerialDebug.println(F(" MHz")); - Serial1.print(F("TCB Clock Frequency = ")); + SerialDebug.print(F("TCB Clock Frequency = ")); #if USING_FULL_CLOCK - Serial1.println(F("Full clock (24/16MHz, etc) for highest accuracy")); + SerialDebug.println(F("Full clock (24/16MHz, etc) for highest accuracy")); #elif USING_HALF_CLOCK - Serial1.println(F("Half clock (12/8MHz, etc.) for high accuracy")); + SerialDebug.println(F("Half clock (12/8MHz, etc.) for high accuracy")); #else - Serial1.println(F("250KHz for lower accuracy but longer time")); + SerialDebug.println(F("250KHz for lower accuracy but longer time")); #endif // Timer0 is used for micros(), millis(), delay(), etc and can't be used @@ -185,11 +194,11 @@ void setup() if (CurrentTimer.attachInterruptInterval(TIMER1_INTERVAL_MS, TimerHandler1)) { - Serial1.print(F("Starting ITimer OK, millis() = ")); - Serial1.println(millis()); + SerialDebug.print(F("Starting ITimer OK, millis() = ")); + SerialDebug.println(millis()); } else - Serial1.println(F("Can't set ITimer. Select another freq. or timer")); + SerialDebug.println(F("Can't set ITimer. Select another freq. or timer")); // Assumming the interruptPin will go LOW attachInterrupt(digitalPinToInterrupt(interruptPin), detectRotation, FALLING); diff --git a/examples/ISR_Timers_Array_Simple/ISR_Timers_Array_Simple.ino b/examples/ISR_Timers_Array_Simple/ISR_Timers_Array_Simple.ino index b050584..516d4bb 100644 --- a/examples/ISR_Timers_Array_Simple/ISR_Timers_Array_Simple.ino +++ b/examples/ISR_Timers_Array_Simple/ISR_Timers_Array_Simple.ino @@ -80,6 +80,15 @@ ISR_Timer ISR_Timer1; #endif #endif +#if defined(__AVR_AVR128DA48__) + #define SerialDebug Serial1 +#elif defined(__AVR_AVR128DB48__) + #define SerialDebug Serial3 +#else + // standard Serial + #define SerialDebug Serial +#endif + #define LED_TOGGLE_INTERVAL_MS 1000L // You have to use longer time here if having problem because Arduino AVR clock is low, 16MHz => lower accuracy. @@ -146,12 +155,12 @@ void simpleTimerDoingSomething2s() unsigned long currMillis = millis(); - Serial1.print(F("SimpleTimer : programmed ")); Serial1.print(SIMPLE_TIMER_MS); - Serial1.print(F("ms, current time ms : ")); Serial1.print(currMillis); - Serial1.print(F(", Delta ms : ")); Serial1.println(currMillis - previousMillis); + SerialDebug.print(F("SimpleTimer : programmed ")); SerialDebug.print(SIMPLE_TIMER_MS); + SerialDebug.print(F("ms, current time ms : ")); SerialDebug.print(currMillis); + SerialDebug.print(F(", Delta ms : ")); SerialDebug.println(currMillis - previousMillis); - Serial1.print(F("Timer2s actual : ")); Serial1.println(deltaMillis2s); - Serial1.print(F("Timer5s actual : ")); Serial1.println(deltaMillis5s); + SerialDebug.print(F("Timer2s actual : ")); SerialDebug.println(deltaMillis2s); + SerialDebug.print(F("Timer5s actual : ")); SerialDebug.println(deltaMillis5s); previousMillis = currMillis; } @@ -162,31 +171,31 @@ void setup() { pinMode(LED_BUILTIN, OUTPUT); - Serial1.begin(115200); - while (!Serial1 && millis() < 5000); + SerialDebug.begin(115200); + while (!SerialDebug && millis() < 5000); - Serial1.print(F("\nStarting ISR_Timers_Array_Simple on ")); Serial1.println(BOARD_NAME); - Serial1.println(DX_TIMER_INTERRUPT_VERSION); - Serial1.print(F("CPU Frequency = ")); Serial1.print(F_CPU / 1000000); Serial1.println(F(" MHz")); + SerialDebug.print(F("\nStarting ISR_Timers_Array_Simple on ")); SerialDebug.println(BOARD_NAME); + SerialDebug.println(DX_TIMER_INTERRUPT_VERSION); + SerialDebug.print(F("CPU Frequency = ")); SerialDebug.print(F_CPU / 1000000); SerialDebug.println(F(" MHz")); - Serial1.print(F("TCB Clock Frequency = ")); + SerialDebug.print(F("TCB Clock Frequency = ")); #if USING_FULL_CLOCK - Serial1.println(F("Full clock (24/16MHz, etc) for highest accuracy")); + SerialDebug.println(F("Full clock (24/16MHz, etc) for highest accuracy")); #elif USING_HALF_CLOCK - Serial1.println(F("Half clock (12/8MHz, etc.) for high accuracy")); + SerialDebug.println(F("Half clock (12/8MHz, etc.) for high accuracy")); #else - Serial1.println(F("250KHz for lower accuracy but longer time")); + SerialDebug.println(F("250KHz for lower accuracy but longer time")); #endif CurrentTimer.init(); if (CurrentTimer.attachInterruptInterval(TIMER1_INTERVAL_MS, TimerHandler1)) { - Serial1.print(F("Starting ITimer OK, millis() = ")); Serial1.println(millis()); + SerialDebug.print(F("Starting ITimer OK, millis() = ")); SerialDebug.println(millis()); } else - Serial1.println(F("Can't set ITimer. Select another freq. or timer")); + SerialDebug.println(F("Can't set ITimer. Select another freq. or timer")); ISR_Timer1.setInterval(2000L, doingSomething2s); ISR_Timer1.setInterval(5000L, doingSomething5s); diff --git a/examples/RPM_Measure/RPM_Measure.ino b/examples/RPM_Measure/RPM_Measure.ino index 8324aa6..4718219 100644 --- a/examples/RPM_Measure/RPM_Measure.ino +++ b/examples/RPM_Measure/RPM_Measure.ino @@ -67,6 +67,15 @@ // To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error #include "Dx_TimerInterrupt.h" +#if defined(__AVR_AVR128DA48__) + #define SerialDebug Serial1 +#elif defined(__AVR_AVR128DB48__) + #define SerialDebug Serial3 +#else + // standard Serial + #define SerialDebug Serial +#endif + // To modify according to your board // For Curiosity Nano AVR128DA48 => use SW => PIN_PC7 // For Curiosity Nano AVR128DB48 => use SW => PIN_PB2 @@ -101,8 +110,8 @@ void TimerHandler1() avgRPM = ( 2 * avgRPM + RPM) / 3, #if (TIMER_INTERRUPT_DEBUG > 1) - Serial1.print("RPM = "); Serial1.print(avgRPM); - Serial1.print(", rotationTime ms = "); Serial1.println(rotationTime * TIMER1_INTERVAL_MS); + SerialDebug.print("RPM = "); SerialDebug.print(avgRPM); + SerialDebug.print(", rotationTime ms = "); SerialDebug.println(rotationTime * TIMER1_INTERVAL_MS); #endif rotationTime = 0; @@ -119,7 +128,7 @@ void TimerHandler1() RPM = 0; #if (TIMER_INTERRUPT_DEBUG > 1) - Serial1.print("RPM = "); Serial1.print(RPM); Serial1.print(", rotationTime = "); Serial1.println(rotationTime); + SerialDebug.print("RPM = "); SerialDebug.print(RPM); SerialDebug.print(", rotationTime = "); SerialDebug.println(rotationTime); #endif rotationTime = 0; @@ -132,23 +141,23 @@ void TimerHandler1() void setup() { - Serial1.begin(115200); - while (!Serial1 && millis() < 5000); + SerialDebug.begin(115200); + while (!SerialDebug && millis() < 5000); pinMode(SWPin, INPUT_PULLUP); - Serial1.print(F("\nStarting RPM_Measure on ")); Serial1.println(BOARD_NAME); - Serial1.println(DX_TIMER_INTERRUPT_VERSION); - Serial1.print(F("CPU Frequency = ")); Serial1.print(F_CPU / 1000000); Serial1.println(F(" MHz")); + SerialDebug.print(F("\nStarting RPM_Measure on ")); SerialDebug.println(BOARD_NAME); + SerialDebug.println(DX_TIMER_INTERRUPT_VERSION); + SerialDebug.print(F("CPU Frequency = ")); SerialDebug.print(F_CPU / 1000000); SerialDebug.println(F(" MHz")); - Serial1.print(F("TCB Clock Frequency = ")); + SerialDebug.print(F("TCB Clock Frequency = ")); #if USING_FULL_CLOCK - Serial1.println(F("Full clock (24/16MHz, etc) for highest accuracy")); + SerialDebug.println(F("Full clock (24/16MHz, etc) for highest accuracy")); #elif USING_HALF_CLOCK - Serial1.println(F("Half clock (12/8MHz, etc.) for high accuracy")); + SerialDebug.println(F("Half clock (12/8MHz, etc.) for high accuracy")); #else - Serial1.println(F("250KHz for lower accuracy but longer time")); + SerialDebug.println(F("250KHz for lower accuracy but longer time")); #endif // Timer2 is used for micros(), millis(), delay(), etc and can't be used @@ -156,10 +165,10 @@ void setup() if (CurrentTimer.attachInterruptInterval(TIMER1_INTERVAL_MS, TimerHandler1)) { - Serial1.print(F("Starting ITimer OK, millis() = ")); Serial1.println(millis()); + SerialDebug.print(F("Starting ITimer OK, millis() = ")); SerialDebug.println(millis()); } else - Serial1.println(F("Can't set ITimer. Select another freq. or timer")); + SerialDebug.println(F("Can't set ITimer. Select another freq. or timer")); } void loop() diff --git a/examples/SwitchDebounce/SwitchDebounce.ino b/examples/SwitchDebounce/SwitchDebounce.ino index c257803..70f3dbb 100644 --- a/examples/SwitchDebounce/SwitchDebounce.ino +++ b/examples/SwitchDebounce/SwitchDebounce.ino @@ -83,6 +83,15 @@ #define LED_ON 0 #define LED_OFF 1 +#if defined(__AVR_AVR128DA48__) + #define SerialDebug Serial1 +#elif defined(__AVR_AVR128DB48__) + #define SerialDebug Serial3 +#else + // standard Serial + #define SerialDebug Serial +#endif + // To modify according to your board // For Curiosity Nano AVR128DA48 => use SW => PIN_PC7 // For Curiosity Nano AVR128DB48 => use SW => PIN_PB2 @@ -126,7 +135,7 @@ void TimerHandler1() #if (TIMER_INTERRUPT_DEBUG > 1) SWPressedTime = currentMillis; - Serial1.print("SW Press, from millis() = "); Serial1.println(SWPressedTime); + SerialDebug.print("SW Press, from millis() = "); SerialDebug.println(SWPressedTime); #endif SWPressed = true; @@ -142,9 +151,9 @@ void TimerHandler1() if (!SWLongPressed) { #if (TIMER_INTERRUPT_DEBUG > 1) - Serial1.print("SW Long Pressed, total time ms = "); Serial1.print(currentMillis); - Serial1.print(" - "); Serial1.print(SWPressedTime); - Serial1.print(" = "); Serial1.println(currentMillis - SWPressedTime); + SerialDebug.print("SW Long Pressed, total time ms = "); SerialDebug.print(currentMillis); + SerialDebug.print(" - "); SerialDebug.print(SWPressedTime); + SerialDebug.print(" = "); SerialDebug.println(currentMillis - SWPressedTime); #endif SWLongPressed = true; @@ -164,7 +173,7 @@ void TimerHandler1() SWReleasedTime = currentMillis; // Call and flag SWPressed - Serial1.print("SW Released, from millis() = "); Serial1.println(SWReleasedTime); + SerialDebug.print("SW Released, from millis() = "); SerialDebug.println(SWReleasedTime); #endif SWPressed = false; @@ -177,8 +186,8 @@ void TimerHandler1() // Call and flag SWPressed #if (TIMER_INTERRUPT_DEBUG > 1) - Serial1.print("SW Pressed total time ms = "); - Serial1.println(SWReleasedTime - SWPressedTime); + SerialDebug.print("SW Pressed total time ms = "); + SerialDebug.println(SWReleasedTime - SWPressedTime); #endif debounceCountSWPressed = 0; @@ -188,24 +197,24 @@ void TimerHandler1() void setup() { - Serial1.begin(115200); - while (!Serial1 && millis() < 5000); + SerialDebug.begin(115200); + while (!SerialDebug && millis() < 5000); pinMode(SWPin, INPUT_PULLUP); pinMode(LED_BUILTIN, OUTPUT); - Serial1.print(F("\nStarting SwitchDebounce on ")); Serial1.println(BOARD_NAME); - Serial1.println(DX_TIMER_INTERRUPT_VERSION); - Serial1.print(F("CPU Frequency = ")); Serial1.print(F_CPU / 1000000); Serial1.println(F(" MHz")); + SerialDebug.print(F("\nStarting SwitchDebounce on ")); SerialDebug.println(BOARD_NAME); + SerialDebug.println(DX_TIMER_INTERRUPT_VERSION); + SerialDebug.print(F("CPU Frequency = ")); SerialDebug.print(F_CPU / 1000000); SerialDebug.println(F(" MHz")); - Serial1.print(F("TCB Clock Frequency = ")); + SerialDebug.print(F("TCB Clock Frequency = ")); #if USING_FULL_CLOCK - Serial1.println(F("Full clock (24/16MHz, etc) for highest accuracy")); + SerialDebug.println(F("Full clock (24/16MHz, etc) for highest accuracy")); #elif USING_HALF_CLOCK - Serial1.println(F("Half clock (12/8MHz, etc.) for high accuracy")); + SerialDebug.println(F("Half clock (12/8MHz, etc.) for high accuracy")); #else - Serial1.println(F("250KHz for lower accuracy but longer time")); + SerialDebug.println(F("250KHz for lower accuracy but longer time")); #endif // Timer2 is used for micros(), millis(), delay(), etc and can't be used @@ -213,10 +222,10 @@ void setup() if (CurrentTimer.attachInterruptInterval(TIMER1_INTERVAL_MS, TimerHandler1)) { - Serial1.print(F("Starting ITimer OK, millis() = ")); Serial1.println(millis()); + SerialDebug.print(F("Starting ITimer OK, millis() = ")); SerialDebug.println(millis()); } else - Serial1.println(F("Can't set ITimer. Select another freq. or timer")); + SerialDebug.println(F("Can't set ITimer. Select another freq. or timer")); } void loop() diff --git a/examples/TimerDuration/TimerDuration.ino b/examples/TimerDuration/TimerDuration.ino index 17e7eff..66a1b38 100644 --- a/examples/TimerDuration/TimerDuration.ino +++ b/examples/TimerDuration/TimerDuration.ino @@ -73,12 +73,21 @@ #endif #endif +#if defined(__AVR_AVR128DA48__) + #define SerialDebug Serial1 +#elif defined(__AVR_AVR128DB48__) + #define SerialDebug Serial3 +#else + // standard Serial + #define SerialDebug Serial +#endif + void TimerHandler1(unsigned int outputPin = LED_BUILTIN) { static bool toggle = false; #if (TIMER_INTERRUPT_DEBUG > 1) - Serial1.print("ITimer called, millis() = "); Serial1.println(millis()); + SerialDebug.print("ITimer called, millis() = "); SerialDebug.println(millis()); #endif //timer interrupt toggles pin LED_BUILTIN @@ -94,23 +103,23 @@ unsigned int outputPin1 = LED_BUILTIN; void setup() { - Serial1.begin(115200); - while (!Serial1 && millis() < 5000); + SerialDebug.begin(115200); + while (!SerialDebug && millis() < 5000); pinMode(outputPin1, OUTPUT); - Serial1.print(F("\nStarting TimerDuration on ")); Serial1.println(BOARD_NAME); - Serial1.println(DX_TIMER_INTERRUPT_VERSION); - Serial1.print(F("CPU Frequency = ")); Serial1.print(F_CPU / 1000000); Serial1.println(F(" MHz")); + SerialDebug.print(F("\nStarting TimerDuration on ")); SerialDebug.println(BOARD_NAME); + SerialDebug.println(DX_TIMER_INTERRUPT_VERSION); + SerialDebug.print(F("CPU Frequency = ")); SerialDebug.print(F_CPU / 1000000); SerialDebug.println(F(" MHz")); - Serial1.print(F("TCB Clock Frequency = ")); + SerialDebug.print(F("TCB Clock Frequency = ")); #if USING_FULL_CLOCK - Serial1.println(F("Full clock (24/16MHz, etc) for highest accuracy")); + SerialDebug.println(F("Full clock (24/16MHz, etc) for highest accuracy")); #elif USING_HALF_CLOCK - Serial1.println(F("Half clock (12/8MHz, etc.) for high accuracy")); + SerialDebug.println(F("Half clock (12/8MHz, etc.) for high accuracy")); #else - Serial1.println(F("250KHz for lower accuracy but longer time")); + SerialDebug.println(F("250KHz for lower accuracy but longer time")); #endif // Timer2 is used for micros(), millis(), delay(), etc and can't be used @@ -119,10 +128,10 @@ void setup() //if (CurrentTimer.attachInterrupt(TIMER1_FREQUENCY, TimerHandler1, outputPin1, TIMER1_DURATION_MS)) if (CurrentTimer.attachInterruptInterval(TIMER1_INTERVAL_MS, TimerHandler1, outputPin1, TIMER1_DURATION_MS)) { - Serial1.print(F("Starting ITimer OK, millis() = ")); Serial1.println(millis()); + SerialDebug.print(F("Starting ITimer OK, millis() = ")); SerialDebug.println(millis()); } else - Serial1.println(F("Can't set ITimer. Select another freq. or timer")); + SerialDebug.println(F("Can't set ITimer. Select another freq. or timer")); } void loop() diff --git a/examples/TimerInterruptTest/TimerInterruptTest.ino b/examples/TimerInterruptTest/TimerInterruptTest.ino index 351c11e..08ff669 100644 --- a/examples/TimerInterruptTest/TimerInterruptTest.ino +++ b/examples/TimerInterruptTest/TimerInterruptTest.ino @@ -79,12 +79,21 @@ #endif #endif +#if defined(__AVR_AVR128DA48__) + #define SerialDebug Serial1 +#elif defined(__AVR_AVR128DB48__) + #define SerialDebug Serial3 +#else + // standard Serial + #define SerialDebug Serial +#endif + void TimerHandler1(unsigned int outputPin = LED_BUILTIN) { static bool toggle = false; #if (TIMER_INTERRUPT_DEBUG > 1) - Serial1.print("ITimer called, millis() = "); Serial1.println(millis()); + SerialDebug.print("ITimer called, millis() = "); SerialDebug.println(millis()); #endif //timer interrupt toggles pin LED_BUILTIN @@ -102,36 +111,36 @@ unsigned int outputPin1 = LED_BUILTIN; void setup() { - Serial1.begin(115200); - while (!Serial1 && millis() < 5000); + SerialDebug.begin(115200); + while (!SerialDebug && millis() < 5000); pinMode(outputPin1, OUTPUT); - Serial1.print(F("\nStarting TimerInterruptTest on ")); Serial1.println(BOARD_NAME); - Serial1.println(DX_TIMER_INTERRUPT_VERSION); - Serial1.print(F("CPU Frequency = ")); Serial1.print(F_CPU / 1000000); Serial1.println(F(" MHz")); + SerialDebug.print(F("\nStarting TimerInterruptTest on ")); SerialDebug.println(BOARD_NAME); + SerialDebug.println(DX_TIMER_INTERRUPT_VERSION); + SerialDebug.print(F("CPU Frequency = ")); SerialDebug.print(F_CPU / 1000000); SerialDebug.println(F(" MHz")); - Serial1.print(F("TCB Clock Frequency = ")); + SerialDebug.print(F("TCB Clock Frequency = ")); #if USING_FULL_CLOCK - Serial1.println(F("Full clock (24/16MHz, etc) for highest accuracy")); + SerialDebug.println(F("Full clock (24/16MHz, etc) for highest accuracy")); #elif USING_HALF_CLOCK - Serial1.println(F("Half clock (12/8MHz, etc.) for high accuracy")); + SerialDebug.println(F("Half clock (12/8MHz, etc.) for high accuracy")); #else - Serial1.println(F("250KHz for lower accuracy but longer time")); + SerialDebug.println(F("250KHz for lower accuracy but longer time")); #endif - Serial1.print(F("CPU ADJUST_FACTOR = ")); Serial1.println(ADJUST_FACTOR); + SerialDebug.print(F("CPU ADJUST_FACTOR = ")); SerialDebug.println(ADJUST_FACTOR); // Timer2 is used for micros(), millis(), delay(), etc and can't be used CurrentTimer.init(); if (CurrentTimer.attachInterruptInterval(TIMER1_INTERVAL_MS * ADJUST_FACTOR, TimerHandler1, outputPin1, TIMER1_DURATION_MS)) { - Serial1.print(F("Starting ITimer OK, millis() = ")); Serial1.println(millis()); + SerialDebug.print(F("Starting ITimer OK, millis() = ")); SerialDebug.println(millis()); } else - Serial1.println(F("Can't set ITimer. Select another freq. or timer")); + SerialDebug.println(F("Can't set ITimer. Select another freq. or timer")); } void loop() @@ -146,8 +155,8 @@ void loop() { lastTimer1 = millis(); // try reinit timer - Serial1.print(F("Re-enable ITimer, millis() = ")); Serial1.print(lastTimer1); - Serial1.print(F(" count = ")); Serial1.println(CurrentTimer.getCount()); + SerialDebug.print(F("Re-enable ITimer, millis() = ")); SerialDebug.print(lastTimer1); + SerialDebug.print(F(" count = ")); SerialDebug.println(CurrentTimer.getCount()); CurrentTimer.reattachInterrupt(TIMER1_DURATION_MS); timerPaused = false; @@ -157,8 +166,8 @@ void loop() { timerPaused = true; - Serial1.print(F("Pause ITimer, millis() = ")); Serial1.print(millis()); - Serial1.print(F(" count = ")); Serial1.println(CurrentTimer.getCount()); + SerialDebug.print(F("Pause ITimer, millis() = ")); SerialDebug.print(millis()); + SerialDebug.print(F(" count = ")); SerialDebug.println(CurrentTimer.getCount()); CurrentTimer.pauseTimer(); } @@ -166,8 +175,8 @@ void loop() { timerResumed = true; - Serial1.print(F("Resume ITimer, millis() = ")); Serial1.print(millis()); - Serial1.print(F(" count = ")); Serial1.println(CurrentTimer.getCount()); + SerialDebug.print(F("Resume ITimer, millis() = ")); SerialDebug.print(millis()); + SerialDebug.print(F(" count = ")); SerialDebug.println(CurrentTimer.getCount()); CurrentTimer.resumeTimer(); } diff --git a/examples/multiFileProject/multiFileProject.h b/examples/multiFileProject/multiFileProject.h index 1860c9f..70d536b 100644 --- a/examples/multiFileProject/multiFileProject.h +++ b/examples/multiFileProject/multiFileProject.h @@ -53,6 +53,15 @@ #error You must select one Timer #endif +#if defined(__AVR_AVR128DA48__) + #define SerialDebug Serial1 +#elif defined(__AVR_AVR128DB48__) + #define SerialDebug Serial3 +#else + // standard Serial + #define SerialDebug Serial +#endif + // To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error #include "Dx_TimerInterrupt.hpp" diff --git a/library.json b/library.json index 0a47886..3ca929d 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "Dx_TimerInterrupt", - "version": "1.1.1", + "version": "1.1.2", "keywords": "timer, interrupt, isr, isr-based, timing, control, hardware-timer, mission-critical, accuracy, megaavr, avr-da, avr-db, avr-dd, dxcore, avr128dx, avr64dx, avr32dx, megatinycore, dx-timerinterrupt, tcb-timers", "description": "This library enables you to use Interrupt from Hardware Timers on Arduino AVRDx-based boards (AVR128Dx, AVR64Dx, AVR32Dx, etc.) using DxCore. These AVRDx Hardware Timers, using Interrupt, still work even if other functions are blocking. Moreover, they are much more precise (certainly depending on clock frequency accuracy) than other software timers using millis() or micros(). That is mandatory if you need to measure some data requiring better accuracy. It now supports 16 ISR-based Timers, while consuming only 1 Hardware Timer. Timers interval is very long (ulong millisecs). The most important feature is they are ISR-based Timers. Therefore, their executions are not blocked by bad-behaving functions or tasks. This important feature is absolutely necessary for mission-critical tasks", "authors": diff --git a/library.properties b/library.properties index b706051..487c988 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Dx_TimerInterrupt -version=1.1.1 +version=1.1.2 author=Khoi Hoang maintainer=Khoi Hoang sentence=This library enables you to use Interrupt from Hardware Timers on Arduino AVRDx-based boards (AVR128Dx, AVR64Dx, AVR32Dx, etc.) using DxCore diff --git a/src/Dx_ISR_Timer.h b/src/Dx_ISR_Timer.h index 9fffc56..40a32b1 100644 --- a/src/Dx_ISR_Timer.h +++ b/src/Dx_ISR_Timer.h @@ -12,13 +12,14 @@ Therefore, their executions are not blocked by bad-behaving functions / tasks. This important feature is absolutely necessary for mission-critical tasks. - Version: 1.1.1 + Version: 1.1.2 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K.Hoang 23/08/2022 Initial coding to support AVR Dx (AVR128Dx, AVR64Dx, AVR32Dx, etc.) using DxCore 1.1.0 K.Hoang 24/08/2022 Improve and customize examples for Curiosity Nano AVRDA/AVRDB boards 1.1.1 K.Hoang 24/08/2022 Using Serial1 instead of Serial for debugging with Curiosity Nano AVRDA/AVRDB + 1.1.2 K.Hoang 24/08/2022 Using Serial3 for debugging with Curiosity Nano AVRDB *****************************************************************************************************************************/ #pragma once diff --git a/src/Dx_ISR_Timer.hpp b/src/Dx_ISR_Timer.hpp index 048a725..9d7c72b 100644 --- a/src/Dx_ISR_Timer.hpp +++ b/src/Dx_ISR_Timer.hpp @@ -12,13 +12,14 @@ Therefore, their executions are not blocked by bad-behaving functions / tasks. This important feature is absolutely necessary for mission-critical tasks. - Version: 1.1.1 + Version: 1.1.2 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K.Hoang 23/08/2022 Initial coding to support AVR Dx (AVR128Dx, AVR64Dx, AVR32Dx, etc.) using DxCore 1.1.0 K.Hoang 24/08/2022 Improve and customize examples for Curiosity Nano AVRDA/AVRDB boards 1.1.1 K.Hoang 24/08/2022 Using Serial1 instead of Serial for debugging with Curiosity Nano AVRDA/AVRDB + 1.1.2 K.Hoang 24/08/2022 Using Serial3 for debugging with Curiosity Nano AVRDB *****************************************************************************************************************************/ #pragma once @@ -33,13 +34,13 @@ #endif #ifndef DX_TIMER_INTERRUPT_VERSION - #define DX_TIMER_INTERRUPT_VERSION F("Dx_TimerInterrupt v1.1.1") + #define DX_TIMER_INTERRUPT_VERSION F("Dx_TimerInterrupt v1.1.2") #define DX_TIMER_INTERRUPT_VERSION_MAJOR 1 #define DX_TIMER_INTERRUPT_VERSION_MINOR 1 - #define DX_TIMER_INTERRUPT_VERSION_PATCH 1 + #define DX_TIMER_INTERRUPT_VERSION_PATCH 2 - #define DX_TIMER_INTERRUPT_VERSION_INT 1001001 + #define DX_TIMER_INTERRUPT_VERSION_INT 1001002 #endif #include "TimerInterrupt_Generic_Debug.h" diff --git a/src/Dx_ISR_Timer_Impl.h b/src/Dx_ISR_Timer_Impl.h index 2975964..27efa8b 100644 --- a/src/Dx_ISR_Timer_Impl.h +++ b/src/Dx_ISR_Timer_Impl.h @@ -12,13 +12,14 @@ Therefore, their executions are not blocked by bad-behaving functions / tasks. This important feature is absolutely necessary for mission-critical tasks. - Version: 1.1.1 + Version: 1.1.2 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K.Hoang 23/08/2022 Initial coding to support AVR Dx (AVR128Dx, AVR64Dx, AVR32Dx, etc.) using DxCore 1.1.0 K.Hoang 24/08/2022 Improve and customize examples for Curiosity Nano AVRDA/AVRDB boards 1.1.1 K.Hoang 24/08/2022 Using Serial1 instead of Serial for debugging with Curiosity Nano AVRDA/AVRDB + 1.1.2 K.Hoang 24/08/2022 Using Serial3 for debugging with Curiosity Nano AVRDB *****************************************************************************************************************************/ #pragma once diff --git a/src/Dx_TimerInterrupt.h b/src/Dx_TimerInterrupt.h index f574b7d..afe27c8 100644 --- a/src/Dx_TimerInterrupt.h +++ b/src/Dx_TimerInterrupt.h @@ -12,13 +12,14 @@ Therefore, their executions are not blocked by bad-behaving functions / tasks. This important feature is absolutely necessary for mission-critical tasks. - Version: 1.1.1 + Version: 1.1.2 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K.Hoang 23/08/2022 Initial coding to support AVR Dx (AVR128Dx, AVR64Dx, AVR32Dx, etc.) using DxCore 1.1.0 K.Hoang 24/08/2022 Improve and customize examples for Curiosity Nano AVRDA/AVRDB boards 1.1.1 K.Hoang 24/08/2022 Using Serial1 instead of Serial for debugging with Curiosity Nano AVRDA/AVRDB + 1.1.2 K.Hoang 24/08/2022 Using Serial3 for debugging with Curiosity Nano AVRDB ****************************************************************************************************************************/ #pragma once diff --git a/src/Dx_TimerInterrupt.hpp b/src/Dx_TimerInterrupt.hpp index a84e362..f7c791e 100644 --- a/src/Dx_TimerInterrupt.hpp +++ b/src/Dx_TimerInterrupt.hpp @@ -12,13 +12,14 @@ Therefore, their executions are not blocked by bad-behaving functions / tasks. This important feature is absolutely necessary for mission-critical tasks. - Version: 1.1.1 + Version: 1.1.2 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K.Hoang 23/08/2022 Initial coding to support AVR Dx (AVR128Dx, AVR64Dx, AVR32Dx, etc.) using DxCore 1.1.0 K.Hoang 24/08/2022 Improve and customize examples for Curiosity Nano AVRDA/AVRDB boards 1.1.1 K.Hoang 24/08/2022 Using Serial1 instead of Serial for debugging with Curiosity Nano AVRDA/AVRDB + 1.1.2 K.Hoang 24/08/2022 Using Serial3 for debugging with Curiosity Nano AVRDB ****************************************************************************************************************************/ #pragma once @@ -113,13 +114,13 @@ #include "TimerInterrupt_Generic_Debug.h" #ifndef DX_TIMER_INTERRUPT_VERSION - #define DX_TIMER_INTERRUPT_VERSION F("Dx_TimerInterrupt v1.1.1") + #define DX_TIMER_INTERRUPT_VERSION F("Dx_TimerInterrupt v1.1.2") #define DX_TIMER_INTERRUPT_VERSION_MAJOR 1 #define DX_TIMER_INTERRUPT_VERSION_MINOR 1 - #define DX_TIMER_INTERRUPT_VERSION_PATCH 1 + #define DX_TIMER_INTERRUPT_VERSION_PATCH 2 - #define DX_TIMER_INTERRUPT_VERSION_INT 1001001 + #define DX_TIMER_INTERRUPT_VERSION_INT 1001002 #endif #include diff --git a/src/Dx_TimerInterrupt_Impl.h b/src/Dx_TimerInterrupt_Impl.h index d824c06..0ce053c 100644 --- a/src/Dx_TimerInterrupt_Impl.h +++ b/src/Dx_TimerInterrupt_Impl.h @@ -12,13 +12,14 @@ Therefore, their executions are not blocked by bad-behaving functions / tasks. This important feature is absolutely necessary for mission-critical tasks. - Version: 1.1.1 + Version: 1.1.2 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K.Hoang 23/08/2022 Initial coding to support AVR Dx (AVR128Dx, AVR64Dx, AVR32Dx, etc.) using DxCore 1.1.0 K.Hoang 24/08/2022 Improve and customize examples for Curiosity Nano AVRDA/AVRDB boards 1.1.1 K.Hoang 24/08/2022 Using Serial1 instead of Serial for debugging with Curiosity Nano AVRDA/AVRDB + 1.1.2 K.Hoang 24/08/2022 Using Serial3 for debugging with Curiosity Nano AVRDB ****************************************************************************************************************************/ #pragma once diff --git a/src/TimerInterrupt_Generic_Debug.h b/src/TimerInterrupt_Generic_Debug.h index 33394ae..91df9f5 100644 --- a/src/TimerInterrupt_Generic_Debug.h +++ b/src/TimerInterrupt_Generic_Debug.h @@ -12,13 +12,14 @@ Therefore, their executions are not blocked by bad-behaving functions / tasks. This important feature is absolutely necessary for mission-critical tasks. - Version: 1.1.1 + Version: 1.1.2 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K.Hoang 23/08/2022 Initial coding to support AVR Dx (AVR128Dx, AVR64Dx, AVR32Dx, etc.) using DxCore 1.1.0 K.Hoang 24/08/2022 Improve and customize examples for Curiosity Nano AVRDA/AVRDB boards 1.1.1 K.Hoang 24/08/2022 Using Serial1 instead of Serial for debugging with Curiosity Nano AVRDA/AVRDB + 1.1.2 K.Hoang 24/08/2022 Using Serial3 for debugging with Curiosity Nano AVRDB *****************************************************************************************************************************/ #pragma once