diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 25e5803..6ccb5cf 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -29,7 +29,7 @@ Please ensure to specify the following: Arduino IDE version: 1.8.13 Arduino megaAVR Core Version 1.8.7 OS: Ubuntu 20.04 LTS -Linux xy-Inspiron-3593 5.4.0-70-generic #78-Ubuntu SMP Fri Mar 19 13:29:52 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux +Linux xy-Inspiron-3593 5.4.0-71-generic #79-Ubuntu SMP Wed Mar 24 10:56:57 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux Context: I encountered a crash while trying to use the Timer Interrupt. diff --git a/README.md b/README.md index c48a32a..c01cd33 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ * [Important Notes about ISR](#important-notes-about-isr) * [Currently supported Boards](#currently-supported-boards) * [Changelog](#changelog) + * [Release v1.3.0](#release-v130) * [Release v1.2.0](#release-v120) * [Release v1.1.0](#release-v110) * [Initial Release v1.0.0](#initial-release-v100) @@ -129,6 +130,11 @@ The catch is your function is now part of an ISR (Interrupt Service Routine), an ## Changelog +### Release v1.3.0 + +1. Fix TCB Clock bug. Don't use v1.2.0 + + ### Release v1.2.0 1. Selectable **TCB Clock 16MHz, 8MHz or 250KHz** depending on necessary accuracy @@ -793,7 +799,7 @@ While software timer, **programmed for 2s, is activated after more than 10.000s ``` Starting ISR_16_Timers_Array_Complex on megaAVR Nano Every -megaAVR_TimerInterrupt v1.2.0 +megaAVR_TimerInterrupt v1.3.0 CPU Frequency = 16 MHz TCB Clock Frequency = 250KHz for lower accuracy but longer time Starting ITimer1 OK, millis() = 6 @@ -945,7 +951,7 @@ The following is the sample terminal output when running example [Change_Interva ``` Starting Change_Interval on megaAVR Nano Every -megaAVR_TimerInterrupt v1.2.0 +megaAVR_TimerInterrupt v1.3.0 CPU Frequency = 16 MHz TCB Clock Frequency = 250KHz for lower accuracy but longer time Starting ITimer1 OK, millis() = 1 @@ -974,7 +980,7 @@ Changing Interval, Timer1 = 100, Timer2 = 200 ``` Starting ISR_16_Timers_Array_Complex on megaAVR Nano Every -megaAVR_TimerInterrupt v1.2.0 +megaAVR_TimerInterrupt v1.3.0 CPU Frequency = 16 MHz TCB Clock Frequency = 16MHz for highest accuracy Starting ITimer1 OK, millis() = 6 @@ -1060,7 +1066,7 @@ Timer : 15, programmed : 80000, actual : 80000 ``` Starting ISR_16_Timers_Array_Complex on megaAVR Nano Every -megaAVR_TimerInterrupt v1.2.0 +megaAVR_TimerInterrupt v1.3.0 CPU Frequency = 16 MHz TCB Clock Frequency = 8MHz for very high accuracy Starting ITimer1 OK, millis() = 10 @@ -1128,7 +1134,7 @@ Timer : 15, programmed : 80000, actual : 80000 ``` Starting ISR_16_Timers_Array_Complex on megaAVR Nano Every -megaAVR_TimerInterrupt v1.2.0 +megaAVR_TimerInterrupt v1.3.0 CPU Frequency = 16 MHz TCB Clock Frequency = 250KHz for lower accuracy but longer time Starting ITimer1 OK, millis() = 11 @@ -1240,6 +1246,10 @@ Sometimes, the library will only work if you update the board core to the latest ## Releases +### Release v1.3.0 + +1. Fix TCB Clock bug. Don't use v1.2.0 + ### Release v1.2.0 1. Selectable **TCB Clock 16MHz, 8MHz or 250KHz** depending on necessary accuracy diff --git a/examples/Argument_Complex/Argument_Complex.ino b/examples/Argument_Complex/Argument_Complex.ino index 334f382..9efa180 100644 --- a/examples/Argument_Complex/Argument_Complex.ino +++ b/examples/Argument_Complex/Argument_Complex.ino @@ -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.2.0 + Version: 1.3.0 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K.Hoang 01/04/2021 Initial coding to support Arduino megaAVR ATmega4809-based boards (UNO WiFi Rev2, etc.) 1.1.0 K.Hoang 14/04/2021 Fix bug. Don't use v1.0.0 1.2.0 K.Hoang 17/04/2021 Selectable TCB Clock 16MHz, 8MHz or 250KHz depending on necessary accuracy + 1.3.0 K.Hoang 17/04/2021 Fix TCB Clock bug. Don't use v1.2.0 *****************************************************************************************************************************/ // These define's must be placed at the beginning before #include "megaAVR_TimerInterrupt.h" diff --git a/examples/Argument_None/Argument_None.ino b/examples/Argument_None/Argument_None.ino index d7708f9..6cd0608 100644 --- a/examples/Argument_None/Argument_None.ino +++ b/examples/Argument_None/Argument_None.ino @@ -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.2.0 + Version: 1.3.0 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K.Hoang 01/04/2021 Initial coding to support Arduino megaAVR ATmega4809-based boards (UNO WiFi Rev2, etc.) 1.1.0 K.Hoang 14/04/2021 Fix bug. Don't use v1.0.0 1.2.0 K.Hoang 17/04/2021 Selectable TCB Clock 16MHz, 8MHz or 250KHz depending on necessary accuracy + 1.3.0 K.Hoang 17/04/2021 Fix TCB Clock bug. Don't use v1.2.0 *****************************************************************************************************************************/ // These define's must be placed at the beginning before #include "megaAVR_TimerInterrupt.h" diff --git a/examples/Argument_Simple/Argument_Simple.ino b/examples/Argument_Simple/Argument_Simple.ino index 8a717cb..a2edcdc 100644 --- a/examples/Argument_Simple/Argument_Simple.ino +++ b/examples/Argument_Simple/Argument_Simple.ino @@ -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.2.0 + Version: 1.3.0 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K.Hoang 01/04/2021 Initial coding to support Arduino megaAVR ATmega4809-based boards (UNO WiFi Rev2, etc.) 1.1.0 K.Hoang 14/04/2021 Fix bug. Don't use v1.0.0 1.2.0 K.Hoang 17/04/2021 Selectable TCB Clock 16MHz, 8MHz or 250KHz depending on necessary accuracy + 1.3.0 K.Hoang 17/04/2021 Fix TCB Clock bug. Don't use v1.2.0 *****************************************************************************************************************************/ // These define's must be placed at the beginning before #include "megaAVR_TimerInterrupt.h" diff --git a/examples/Change_Interval/Change_Interval.ino b/examples/Change_Interval/Change_Interval.ino index 4c42dbd..7fef400 100644 --- a/examples/Change_Interval/Change_Interval.ino +++ b/examples/Change_Interval/Change_Interval.ino @@ -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.2.0 + Version: 1.3.0 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K.Hoang 01/04/2021 Initial coding to support Arduino megaAVR ATmega4809-based boards (UNO WiFi Rev2, etc.) 1.1.0 K.Hoang 14/04/2021 Fix bug. Don't use v1.0.0 1.2.0 K.Hoang 17/04/2021 Selectable TCB Clock 16MHz, 8MHz or 250KHz depending on necessary accuracy + 1.3.0 K.Hoang 17/04/2021 Fix TCB Clock bug. Don't use v1.2.0 *****************************************************************************************************************************/ /* @@ -64,10 +65,10 @@ #define TIMER1_INTERVAL_MS 1000UL -#define TIMER2_INTERVAL_MS 2000UL +#define TIMER2_INTERVAL_MS 500UL -volatile uint32_t Timer1Count = 0; -volatile uint32_t Timer2Count = 0; +volatile uint32_t Timer1Count = 1; +volatile uint32_t Timer2Count = 1; void printResult(uint32_t currTime) { @@ -186,11 +187,15 @@ void loop() ITimer1.setInterval(TIMER1_INTERVAL_MS * (multFactor + 1), TimerHandler1); + Timer1Count++; + Serial.print(F("Changing Interval, Timer1 = ")); Serial.println(TIMER1_INTERVAL_MS * (multFactor + 1)); #if USE_TIMER_2 ITimer2.setInterval(TIMER2_INTERVAL_MS * (multFactor + 1), TimerHandler2); + Timer2Count++; + Serial.print(F("Changing Interval, Timer2 = ")); Serial.println(TIMER2_INTERVAL_MS * (multFactor + 1)); #endif diff --git a/examples/FakeAnalogWrite/FakeAnalogWrite.ino b/examples/FakeAnalogWrite/FakeAnalogWrite.ino index bfb5c40..f33348b 100644 --- a/examples/FakeAnalogWrite/FakeAnalogWrite.ino +++ b/examples/FakeAnalogWrite/FakeAnalogWrite.ino @@ -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.2.0 + Version: 1.3.0 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K.Hoang 01/04/2021 Initial coding to support Arduino megaAVR ATmega4809-based boards (UNO WiFi Rev2, etc.) 1.1.0 K.Hoang 14/04/2021 Fix bug. Don't use v1.0.0 1.2.0 K.Hoang 17/04/2021 Selectable TCB Clock 16MHz, 8MHz or 250KHz depending on necessary accuracy + 1.3.0 K.Hoang 17/04/2021 Fix TCB Clock bug. Don't use v1.2.0 *****************************************************************************************************************************/ /* Notes: 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 4d0f033..b0d7220 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 @@ -12,28 +12,29 @@ Therefore, their executions are not blocked by bad-behaving functions / tasks. This important feature is absolutely necessary for mission-critical tasks. - Version: 1.2.0 + Version: 1.3.0 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K.Hoang 01/04/2021 Initial coding to support Arduino megaAVR ATmega4809-based boards (UNO WiFi Rev2, etc.) 1.1.0 K.Hoang 14/04/2021 Fix bug. Don't use v1.0.0 1.2.0 K.Hoang 17/04/2021 Selectable TCB Clock 16MHz, 8MHz or 250KHz depending on necessary accuracy + 1.3.0 K.Hoang 17/04/2021 Fix TCB Clock bug. Don't use v1.2.0 *****************************************************************************************************************************/ // These define's must be placed at the beginning before #include "megaAVR_TimerInterrupt.h" // _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_ 0 +#define _TIMERINTERRUPT_LOGLEVEL_ 3 // Select USING_16MHZ == true for 16MHz to Timer TCBx => shorter timer, but better accuracy // Select USING_8MHZ == true for 8MHz to Timer TCBx => shorter timer, but better accuracy // Select USING_250KHZ == true for 250KHz to Timer TCBx => shorter timer, but better accuracy // Not select for default 250KHz to Timer TCBx => longer timer, but worse accuracy -#define USING_16MHZ true +#define USING_16MHZ false #define USING_8MHZ false -#define USING_250KHZ false +#define USING_250KHZ true #define USE_TIMER_0 false diff --git a/examples/ISR_RPM_Measure/ISR_RPM_Measure.ino b/examples/ISR_RPM_Measure/ISR_RPM_Measure.ino index 64dce33..385ea6e 100644 --- a/examples/ISR_RPM_Measure/ISR_RPM_Measure.ino +++ b/examples/ISR_RPM_Measure/ISR_RPM_Measure.ino @@ -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.2.0 + Version: 1.3.0 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K.Hoang 01/04/2021 Initial coding to support Arduino megaAVR ATmega4809-based boards (UNO WiFi Rev2, etc.) 1.1.0 K.Hoang 14/04/2021 Fix bug. Don't use v1.0.0 1.2.0 K.Hoang 17/04/2021 Selectable TCB Clock 16MHz, 8MHz or 250KHz depending on necessary accuracy + 1.3.0 K.Hoang 17/04/2021 Fix TCB Clock bug. Don't use v1.2.0 *****************************************************************************************************************************/ /* RPM Measuring uses high frequency hardware timer 1Hz == 1ms) to measure the time from of one rotation, in ms then convert to RPM. One rotation is detected by reading the state of a magnetic REED SW or IR LED Sensor diff --git a/examples/ISR_Switch/ISR_Switch.ino b/examples/ISR_Switch/ISR_Switch.ino index 7f08acd..10cee76 100644 --- a/examples/ISR_Switch/ISR_Switch.ino +++ b/examples/ISR_Switch/ISR_Switch.ino @@ -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.2.0 + Version: 1.3.0 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K.Hoang 01/04/2021 Initial coding to support Arduino megaAVR ATmega4809-based boards (UNO WiFi Rev2, etc.) 1.1.0 K.Hoang 14/04/2021 Fix bug. Don't use v1.0.0 1.2.0 K.Hoang 17/04/2021 Selectable TCB Clock 16MHz, 8MHz or 250KHz depending on necessary accuracy + 1.3.0 K.Hoang 17/04/2021 Fix TCB Clock bug. Don't use v1.2.0 *****************************************************************************************************************************/ /**************************************************************************************************************************** ISR_Switch demontrates the use of ISR to avoid being blocked by other CPU-monopolizing task diff --git a/examples/ISR_Timer_Complex/ISR_Timer_Complex.ino b/examples/ISR_Timer_Complex/ISR_Timer_Complex.ino index 47542af..0bde07c 100644 --- a/examples/ISR_Timer_Complex/ISR_Timer_Complex.ino +++ b/examples/ISR_Timer_Complex/ISR_Timer_Complex.ino @@ -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.2.0 + Version: 1.3.0 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K.Hoang 01/04/2021 Initial coding to support Arduino megaAVR ATmega4809-based boards (UNO WiFi Rev2, etc.) 1.1.0 K.Hoang 14/04/2021 Fix bug. Don't use v1.0.0 1.2.0 K.Hoang 17/04/2021 Selectable TCB Clock 16MHz, 8MHz or 250KHz depending on necessary accuracy + 1.3.0 K.Hoang 17/04/2021 Fix TCB Clock bug. Don't use v1.2.0 *****************************************************************************************************************************/ /**************************************************************************************************************************** diff --git a/examples/ISR_Timer_Switch/ISR_Timer_Switch.ino b/examples/ISR_Timer_Switch/ISR_Timer_Switch.ino index daa1af6..50899a8 100644 --- a/examples/ISR_Timer_Switch/ISR_Timer_Switch.ino +++ b/examples/ISR_Timer_Switch/ISR_Timer_Switch.ino @@ -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.2.0 + Version: 1.3.0 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K.Hoang 01/04/2021 Initial coding to support Arduino megaAVR ATmega4809-based boards (UNO WiFi Rev2, etc.) 1.1.0 K.Hoang 14/04/2021 Fix bug. Don't use v1.0.0 1.2.0 K.Hoang 17/04/2021 Selectable TCB Clock 16MHz, 8MHz or 250KHz depending on necessary accuracy + 1.3.0 K.Hoang 17/04/2021 Fix TCB Clock bug. Don't use v1.2.0 *****************************************************************************************************************************/ /**************************************************************************************************************************** ISR_Timer_Switch demontrates the use of ISR combining with Timer Interrupt to avoid being blocked by diff --git a/examples/ISR_Timer_Switches/ISR_Timer_Switches.ino b/examples/ISR_Timer_Switches/ISR_Timer_Switches.ino index 965128c..f4bd361 100644 --- a/examples/ISR_Timer_Switches/ISR_Timer_Switches.ino +++ b/examples/ISR_Timer_Switches/ISR_Timer_Switches.ino @@ -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.2.0 + Version: 1.3.0 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K.Hoang 01/04/2021 Initial coding to support Arduino megaAVR ATmega4809-based boards (UNO WiFi Rev2, etc.) 1.1.0 K.Hoang 14/04/2021 Fix bug. Don't use v1.0.0 1.2.0 K.Hoang 17/04/2021 Selectable TCB Clock 16MHz, 8MHz or 250KHz depending on necessary accuracy + 1.3.0 K.Hoang 17/04/2021 Fix TCB Clock bug. Don't use v1.2.0 *****************************************************************************************************************************/ /**************************************************************************************************************************** ISR_Timer_Switches demontrates the use of ISR combining with Timer Interrupt to avoid being blocked by 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 30a9a20..78698da 100644 --- a/examples/ISR_Timers_Array_Simple/ISR_Timers_Array_Simple.ino +++ b/examples/ISR_Timers_Array_Simple/ISR_Timers_Array_Simple.ino @@ -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.2.0 + Version: 1.3.0 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K.Hoang 01/04/2021 Initial coding to support Arduino megaAVR ATmega4809-based boards (UNO WiFi Rev2, etc.) 1.1.0 K.Hoang 14/04/2021 Fix bug. Don't use v1.0.0 1.2.0 K.Hoang 17/04/2021 Selectable TCB Clock 16MHz, 8MHz or 250KHz depending on necessary accuracy + 1.3.0 K.Hoang 17/04/2021 Fix TCB Clock bug. Don't use v1.2.0 *****************************************************************************************************************************/ // These define's must be placed at the beginning before #include "megaAVR_TimerInterrupt.h" diff --git a/examples/RPM_Measure/RPM_Measure.ino b/examples/RPM_Measure/RPM_Measure.ino index 6a48a83..9f8c5f2 100644 --- a/examples/RPM_Measure/RPM_Measure.ino +++ b/examples/RPM_Measure/RPM_Measure.ino @@ -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.2.0 + Version: 1.3.0 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K.Hoang 01/04/2021 Initial coding to support Arduino megaAVR ATmega4809-based boards (UNO WiFi Rev2, etc.) 1.1.0 K.Hoang 14/04/2021 Fix bug. Don't use v1.0.0 1.2.0 K.Hoang 17/04/2021 Selectable TCB Clock 16MHz, 8MHz or 250KHz depending on necessary accuracy + 1.3.0 K.Hoang 17/04/2021 Fix TCB Clock bug. Don't use v1.2.0 *****************************************************************************************************************************/ /* RPM Measuring uses high frequency hardware timer 1Hz == 1ms) to measure the time from of one rotation, in ms then convert to RPM. One rotation is detected by reading the state of a magnetic REED SW or IR LED Sensor diff --git a/examples/SwitchDebounce/SwitchDebounce.ino b/examples/SwitchDebounce/SwitchDebounce.ino index 20cf7a8..8940c78 100644 --- a/examples/SwitchDebounce/SwitchDebounce.ino +++ b/examples/SwitchDebounce/SwitchDebounce.ino @@ -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.2.0 + Version: 1.3.0 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K.Hoang 01/04/2021 Initial coding to support Arduino megaAVR ATmega4809-based boards (UNO WiFi Rev2, etc.) 1.1.0 K.Hoang 14/04/2021 Fix bug. Don't use v1.0.0 1.2.0 K.Hoang 17/04/2021 Selectable TCB Clock 16MHz, 8MHz or 250KHz depending on necessary accuracy + 1.3.0 K.Hoang 17/04/2021 Fix TCB Clock bug. Don't use v1.2.0 *****************************************************************************************************************************/ /**************************************************************************************************************************** Switch Debouncing uses high frequency hardware timer 50Hz == 20ms) to measure the time from the SW is pressed, diff --git a/examples/TimerDuration/TimerDuration.ino b/examples/TimerDuration/TimerDuration.ino index 7c256b0..6588bc7 100644 --- a/examples/TimerDuration/TimerDuration.ino +++ b/examples/TimerDuration/TimerDuration.ino @@ -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.2.0 + Version: 1.3.0 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K.Hoang 01/04/2021 Initial coding to support Arduino megaAVR ATmega4809-based boards (UNO WiFi Rev2, etc.) 1.1.0 K.Hoang 14/04/2021 Fix bug. Don't use v1.0.0 1.2.0 K.Hoang 17/04/2021 Selectable TCB Clock 16MHz, 8MHz or 250KHz depending on necessary accuracy + 1.3.0 K.Hoang 17/04/2021 Fix TCB Clock bug. Don't use v1.2.0 *****************************************************************************************************************************/ // These define's must be placed at the beginning before #include "megaAVR_TimerInterrupt.h" diff --git a/examples/TimerInterruptTest/TimerInterruptTest.ino b/examples/TimerInterruptTest/TimerInterruptTest.ino index 7ebef97..9779b6b 100644 --- a/examples/TimerInterruptTest/TimerInterruptTest.ino +++ b/examples/TimerInterruptTest/TimerInterruptTest.ino @@ -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.2.0 + Version: 1.3.0 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K.Hoang 01/04/2021 Initial coding to support Arduino megaAVR ATmega4809-based boards (UNO WiFi Rev2, etc.) 1.1.0 K.Hoang 14/04/2021 Fix bug. Don't use v1.0.0 1.2.0 K.Hoang 17/04/2021 Selectable TCB Clock 16MHz, 8MHz or 250KHz depending on necessary accuracy + 1.3.0 K.Hoang 17/04/2021 Fix TCB Clock bug. Don't use v1.2.0 *****************************************************************************************************************************/ // These define's must be placed at the beginning before #include "megaAVR_TimerInterrupt.h" diff --git a/library.json b/library.json index 9f7405f..162e4e0 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "megaAVR_TimerInterrupt", - "version": "1.2.0", + "version": "1.3.0", "keywords": "timer, interrupt, hardware, isr, isr-based, timing, control, device, hardware-timer, mission-critical, accuracy, precise, megaavr, mega-avr, nano, uno, atmega4809, nano-every, uno-wifi-rev2, arduino", "description": "This library enables you to use Interrupt from Hardware Timers on an Arduino megaAVR board, such as UNO WiFi Rev2, AVR_NANO_EVERY, etc. 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're 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 d0d6120..90377be 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=megaAVR_TimerInterrupt -version=1.2.0 +version=1.3.0 author=Khoi Hoang maintainer=Khoi Hoang sentence=This library enables you to use Interrupt from Hardware Timers on an Arduino megaAVR board, such as UNO WiFi Rev2, AVR_NANO_EVERY, etc. diff --git a/src/TimerInterrupt_Generic_Debug.h b/src/TimerInterrupt_Generic_Debug.h index bf3d59d..a502e70 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.2.0 + Version: 1.3.0 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K.Hoang 01/04/2021 Initial coding to support Arduino megaAVR ATmega4809-based boards (UNO WiFi Rev2, etc.) 1.1.0 K.Hoang 14/04/2021 Fix bug. Don't use v1.0.0 1.2.0 K.Hoang 17/04/2021 Selectable TCB Clock 16MHz, 8MHz or 250KHz depending on necessary accuracy + 1.3.0 K.Hoang 17/04/2021 Fix TCB Clock bug. Don't use v1.2.0 *****************************************************************************************************************************/ #pragma once diff --git a/src/megaAVR_ISR_Timer-Impl.h b/src/megaAVR_ISR_Timer-Impl.h index ed17b04..c0edcd8 100644 --- a/src/megaAVR_ISR_Timer-Impl.h +++ b/src/megaAVR_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.2.0 + Version: 1.3.0 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K.Hoang 01/04/2021 Initial coding to support Arduino megaAVR ATmega4809-based boards (UNO WiFi Rev2, etc.) 1.1.0 K.Hoang 14/04/2021 Fix bug. Don't use v1.0.0 1.2.0 K.Hoang 17/04/2021 Selectable TCB Clock 16MHz, 8MHz or 250KHz depending on necessary accuracy + 1.3.0 K.Hoang 17/04/2021 Fix TCB Clock bug. Don't use v1.2.0 *****************************************************************************************************************************/ #pragma once diff --git a/src/megaAVR_ISR_Timer.h b/src/megaAVR_ISR_Timer.h index 3f60858..615679b 100644 --- a/src/megaAVR_ISR_Timer.h +++ b/src/megaAVR_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.2.0 + Version: 1.3.0 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K.Hoang 01/04/2021 Initial coding to support Arduino megaAVR ATmega4809-based boards (UNO WiFi Rev2, etc.) 1.1.0 K.Hoang 14/04/2021 Fix bug. Don't use v1.0.0 1.2.0 K.Hoang 17/04/2021 Selectable TCB Clock 16MHz, 8MHz or 250KHz depending on necessary accuracy + 1.3.0 K.Hoang 17/04/2021 Fix TCB Clock bug. Don't use v1.2.0 *****************************************************************************************************************************/ #pragma once @@ -41,7 +42,7 @@ #endif #ifndef MEGA_AVR_TIMER_INTERRUPT_VERSION - #define MEGA_AVR_TIMER_INTERRUPT_VERSION "megaAVR_TimerInterrupt v1.2.0" + #define MEGA_AVR_TIMER_INTERRUPT_VERSION "megaAVR_TimerInterrupt v1.3.0" #endif #include "TimerInterrupt_Generic_Debug.h" diff --git a/src/megaAVR_TimerInterrupt-Impl.h b/src/megaAVR_TimerInterrupt-Impl.h index 01f192b..f8cb490 100644 --- a/src/megaAVR_TimerInterrupt-Impl.h +++ b/src/megaAVR_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.2.0 + Version: 1.3.0 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K.Hoang 01/04/2021 Initial coding to support Arduino megaAVR ATmega4809-based boards (UNO WiFi Rev2, etc.) 1.1.0 K.Hoang 14/04/2021 Fix bug. Don't use v1.0.0 1.2.0 K.Hoang 17/04/2021 Selectable TCB Clock 16MHz, 8MHz or 250KHz depending on necessary accuracy + 1.3.0 K.Hoang 17/04/2021 Fix TCB Clock bug. Don't use v1.2.0 ****************************************************************************************************************************/ #pragma once @@ -67,25 +68,34 @@ typedef enum TCB_CNTMODE_enum TCB_t* TimerTCB[ NUM_HW_TIMERS ] = { &TCB0, &TCB1, &TCB2, &TCB3 }; +#define CLK_TCA_FREQ (250000L) + // Clock for UNO WiFi Rev2 and Nano Every is 16MHz -#if USING_16MHZ // Use no prescaler (prescaler 1) => 16MHz +#if USING_16MHZ + // Use no prescaler (prescaler 1) => 16MHz #warning Using no prescaler => 16MHz #define TCB_CLKSEL_VALUE TCB_CLKSEL_CLKDIV1_gc + #define CLOCK_PRESCALER 1 #elif USING_8MHZ // Use prescaler 2 => 8MHz #warning Using prescaler 2 => 8MHz #define TCB_CLKSEL_VALUE TCB_CLKSEL_CLKDIV2_gc + #define CLOCK_PRESCALER 2 #elif USING_250KHZ // Optional, but for clarity // Use Timer A as clock (prescaler 64) => 250KHz #warning Using prescaler 64 => 250KHz #define TCB_CLKSEL_VALUE TCB_CLKSEL_CLKTCA_gc + #define CLOCK_PRESCALER 64 #else // Use Timer A as clock (prescaler 64) => 250KHz #warning Using prescaler 64 => 250KHz #define TCB_CLKSEL_VALUE TCB_CLKSEL_CLKTCA_gc + #define CLOCK_PRESCALER 64 #endif +#define CLK_TCB_FREQ ( F_CPU / CLOCK_PRESCALER ) + void TimerInterrupt::init(int8_t timer) { // Set timer specific stuff @@ -103,13 +113,13 @@ void TimerInterrupt::init(int8_t timer) TISR_LOGWARN1(F("TCB"), timer); - TISR_LOGDEBUG(F("==================")); - TISR_LOGDEBUG1(F("Init, Timer ="), timer); - TISR_LOGDEBUG1(F("CTRLB ="), TimerTCB[timer]->CTRLB); - TISR_LOGDEBUG1(F("CCMP ="), TimerTCB[timer]->CCMP); - TISR_LOGDEBUG1(F("INTCTRL ="), TimerTCB[timer]->INTCTRL); - TISR_LOGDEBUG1(F("CTRLA ="), TimerTCB[timer]->CTRLA); - TISR_LOGDEBUG(F("==================")); + TISR_LOGINFO(F("==================")); + TISR_LOGINFO1(F("Init, Timer ="), timer); + TISR_LOGINFO1(F("CTRLB ="), TimerTCB[timer]->CTRLB); + TISR_LOGINFO1(F("CCMP ="), TimerTCB[timer]->CCMP); + TISR_LOGINFO1(F("INTCTRL ="), TimerTCB[timer]->INTCTRL); + TISR_LOGINFO1(F("CTRLA ="), TimerTCB[timer]->CTRLA); + TISR_LOGINFO(F("==================")); _timer = timer; @@ -132,12 +142,12 @@ void TimerInterrupt::set_CCMP() TimerTCB[_timer]->INTCTRL = TCB_CAPT_bm; // Enable the interrupt - TISR_LOGDEBUG(F("==================")); - TISR_LOGDEBUG1(F("set_CCMP, Timer ="), _timer); - TISR_LOGDEBUG1(F("CTRLB ="), TimerTCB[_timer]->CTRLB); - TISR_LOGDEBUG1(F("CCMP ="), TimerTCB[_timer]->CCMP); - TISR_LOGDEBUG1(F("INTCTRL ="), TimerTCB[_timer]->INTCTRL); - TISR_LOGDEBUG1(F("CTRLA ="), TimerTCB[_timer]->CTRLA); + TISR_LOGINFO(F("==================")); + TISR_LOGINFO1(F("set_CCMP, Timer ="), _timer); + TISR_LOGINFO1(F("CTRLB ="), TimerTCB[_timer]->CTRLB); + TISR_LOGINFO1(F("CCMP ="), TimerTCB[_timer]->CCMP); + TISR_LOGINFO1(F("INTCTRL ="), TimerTCB[_timer]->INTCTRL); + TISR_LOGINFO1(F("CTRLA ="), TimerTCB[_timer]->CTRLA); TISR_LOGDEBUG(F("==================")); // Flag _CCMPValue == 0 => end of long timer @@ -150,13 +160,8 @@ void TimerInterrupt::set_CCMP() // Return true if frequency is OK with selected timer (CCMPValue is in range) bool TimerInterrupt::setFrequency(float frequency, timer_callback_p callback, uint32_t params, unsigned long duration) { - -#define CLK_TCA_FREQ (250000L) - bool isSuccess = false; - // Currently using CLK_TCA from TCA0 == 250KHz - //frequencyLimit must > 1 float frequencyLimit = frequency * 17179.840; @@ -174,8 +179,8 @@ bool TimerInterrupt::setFrequency(float frequency, timer_callback_p callback, ui { _toggle_count = frequency * duration / 1000; - TISR_LOGWARN1(F("setFrequency => _toggle_count ="), _toggle_count); - TISR_LOGWARN3(F("Frequency ="), frequency, F(", duration ="), duration); + TISR_LOGINFO1(F("setFrequency => _toggle_count ="), _toggle_count); + TISR_LOGINFO3(F("Frequency ="), frequency, F(", duration ="), duration); if (_toggle_count < 1) { @@ -199,11 +204,10 @@ bool TimerInterrupt::setFrequency(float frequency, timer_callback_p callback, ui _timerDone = false; - - _CCMPValue = _CCMPValueRemaining = (uint32_t) (CLK_TCA_FREQ / frequency); - - TISR_LOGDEBUG3(F("Frequency ="), frequency, F(", CLK_TCA_FREQ ="), CLK_TCA_FREQ); - TISR_LOGDEBUG1(F("setFrequency: _CCMPValueRemaining = "), _CCMPValueRemaining); + _CCMPValue = _CCMPValueRemaining = (uint32_t) (CLK_TCB_FREQ / frequency); + + TISR_LOGINFO3(F("Frequency ="), frequency, F(", CLK_TCB_FREQ ="), CLK_TCB_FREQ); + TISR_LOGINFO1(F("setFrequency: _CCMPValueRemaining = "), _CCMPValueRemaining); // Set the CCMP for the given timer, // set the toggle count, diff --git a/src/megaAVR_TimerInterrupt.h b/src/megaAVR_TimerInterrupt.h index fa5ef8c..c237ce4 100644 --- a/src/megaAVR_TimerInterrupt.h +++ b/src/megaAVR_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.2.0 + Version: 1.3.0 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K.Hoang 01/04/2021 Initial coding to support Arduino megaAVR ATmega4809-based boards (UNO WiFi Rev2, etc.) 1.1.0 K.Hoang 14/04/2021 Fix bug. Don't use v1.0.0 1.2.0 K.Hoang 17/04/2021 Selectable TCB Clock 16MHz, 8MHz or 250KHz depending on necessary accuracy + 1.3.0 K.Hoang 17/04/2021 Fix TCB Clock bug. Don't use v1.2.0 ****************************************************************************************************************************/ #pragma once @@ -47,7 +48,7 @@ #include "TimerInterrupt_Generic_Debug.h" #ifndef MEGA_AVR_TIMER_INTERRUPT_VERSION - #define MEGA_AVR_TIMER_INTERRUPT_VERSION "megaAVR_TimerInterrupt v1.1.0" + #define MEGA_AVR_TIMER_INTERRUPT_VERSION "megaAVR_TimerInterrupt v1.3.0" #endif #include diff --git a/src_cpp/TimerInterrupt_Generic_Debug.h b/src_cpp/TimerInterrupt_Generic_Debug.h index bf3d59d..a502e70 100644 --- a/src_cpp/TimerInterrupt_Generic_Debug.h +++ b/src_cpp/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.2.0 + Version: 1.3.0 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K.Hoang 01/04/2021 Initial coding to support Arduino megaAVR ATmega4809-based boards (UNO WiFi Rev2, etc.) 1.1.0 K.Hoang 14/04/2021 Fix bug. Don't use v1.0.0 1.2.0 K.Hoang 17/04/2021 Selectable TCB Clock 16MHz, 8MHz or 250KHz depending on necessary accuracy + 1.3.0 K.Hoang 17/04/2021 Fix TCB Clock bug. Don't use v1.2.0 *****************************************************************************************************************************/ #pragma once diff --git a/src_cpp/megaAVR_ISR_Timer.cpp b/src_cpp/megaAVR_ISR_Timer.cpp index a69b898..34fd8ad 100644 --- a/src_cpp/megaAVR_ISR_Timer.cpp +++ b/src_cpp/megaAVR_ISR_Timer.cpp @@ -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.2.0 + Version: 1.3.0 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K.Hoang 01/04/2021 Initial coding to support Arduino megaAVR ATmega4809-based boards (UNO WiFi Rev2, etc.) 1.1.0 K.Hoang 14/04/2021 Fix bug. Don't use v1.0.0 1.2.0 K.Hoang 17/04/2021 Selectable TCB Clock 16MHz, 8MHz or 250KHz depending on necessary accuracy + 1.3.0 K.Hoang 17/04/2021 Fix TCB Clock bug. Don't use v1.2.0 *****************************************************************************************************************************/ #include "megaAVR_ISR_Timer.h" diff --git a/src_cpp/megaAVR_ISR_Timer.h b/src_cpp/megaAVR_ISR_Timer.h index bdb1654..1a7423e 100644 --- a/src_cpp/megaAVR_ISR_Timer.h +++ b/src_cpp/megaAVR_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.2.0 + Version: 1.3.0 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K.Hoang 01/04/2021 Initial coding to support Arduino megaAVR ATmega4809-based boards (UNO WiFi Rev2, etc.) 1.1.0 K.Hoang 14/04/2021 Fix bug. Don't use v1.0.0 1.2.0 K.Hoang 17/04/2021 Selectable TCB Clock 16MHz, 8MHz or 250KHz depending on necessary accuracy + 1.3.0 K.Hoang 17/04/2021 Fix TCB Clock bug. Don't use v1.2.0 *****************************************************************************************************************************/ #pragma once @@ -41,7 +42,7 @@ #endif #ifndef MEGA_AVR_TIMER_INTERRUPT_VERSION - #define MEGA_AVR_TIMER_INTERRUPT_VERSION "megaAVR_TimerInterrupt v1.2.0" + #define MEGA_AVR_TIMER_INTERRUPT_VERSION "megaAVR_TimerInterrupt v1.3.0" #endif #include "TimerInterrupt_Generic_Debug.h" diff --git a/src_cpp/megaAVR_TimerInterrupt.cpp b/src_cpp/megaAVR_TimerInterrupt.cpp index b18041a..014f2ce 100644 --- a/src_cpp/megaAVR_TimerInterrupt.cpp +++ b/src_cpp/megaAVR_TimerInterrupt.cpp @@ -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.2.0 + Version: 1.3.0 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K.Hoang 01/04/2021 Initial coding to support Arduino megaAVR ATmega4809-based boards (UNO WiFi Rev2, etc.) 1.1.0 K.Hoang 14/04/2021 Fix bug. Don't use v1.0.0 1.2.0 K.Hoang 17/04/2021 Selectable TCB Clock 16MHz, 8MHz or 250KHz depending on necessary accuracy + 1.3.0 K.Hoang 17/04/2021 Fix TCB Clock bug. Don't use v1.2.0 ****************************************************************************************************************************/ #include "megaAVR_TimerInterrupt.h" @@ -62,25 +63,34 @@ typedef enum TCB_CNTMODE_enum TCB_t* TimerTCB[ NUM_HW_TIMERS ] = { &TCB0, &TCB1, &TCB2, &TCB3 }; +#define CLK_TCA_FREQ (250000L) + // Clock for UNO WiFi Rev2 and Nano Every is 16MHz -#if USING_16MHZ // Use no prescaler (prescaler 1) => 16MHz +#if USING_16MHZ + // Use no prescaler (prescaler 1) => 16MHz #warning Using no prescaler => 16MHz #define TCB_CLKSEL_VALUE TCB_CLKSEL_CLKDIV1_gc + #define CLOCK_PRESCALER 1 #elif USING_8MHZ // Use prescaler 2 => 8MHz #warning Using prescaler 2 => 8MHz #define TCB_CLKSEL_VALUE TCB_CLKSEL_CLKDIV2_gc + #define CLOCK_PRESCALER 2 #elif USING_250KHZ // Optional, but for clarity // Use Timer A as clock (prescaler 64) => 250KHz #warning Using prescaler 64 => 250KHz #define TCB_CLKSEL_VALUE TCB_CLKSEL_CLKTCA_gc + #define CLOCK_PRESCALER 64 #else // Use Timer A as clock (prescaler 64) => 250KHz #warning Using prescaler 64 => 250KHz #define TCB_CLKSEL_VALUE TCB_CLKSEL_CLKTCA_gc + #define CLOCK_PRESCALER 64 #endif +#define CLK_TCB_FREQ ( F_CPU / CLOCK_PRESCALER ) + void TimerInterrupt::init(int8_t timer) { // Set timer specific stuff @@ -98,13 +108,13 @@ void TimerInterrupt::init(int8_t timer) TISR_LOGWARN1(F("TCB"), timer); - TISR_LOGDEBUG(F("==================")); - TISR_LOGDEBUG1(F("Init, Timer ="), timer); - TISR_LOGDEBUG1(F("CTRLB ="), TimerTCB[timer]->CTRLB); - TISR_LOGDEBUG1(F("CCMP ="), TimerTCB[timer]->CCMP); - TISR_LOGDEBUG1(F("INTCTRL ="), TimerTCB[timer]->INTCTRL); - TISR_LOGDEBUG1(F("CTRLA ="), TimerTCB[timer]->CTRLA); - TISR_LOGDEBUG(F("==================")); + TISR_LOGINFO(F("==================")); + TISR_LOGINFO1(F("Init, Timer ="), timer); + TISR_LOGINFO1(F("CTRLB ="), TimerTCB[timer]->CTRLB); + TISR_LOGINFO1(F("CCMP ="), TimerTCB[timer]->CCMP); + TISR_LOGINFO1(F("INTCTRL ="), TimerTCB[timer]->INTCTRL); + TISR_LOGINFO1(F("CTRLA ="), TimerTCB[timer]->CTRLA); + TISR_LOGINFO(F("==================")); _timer = timer; @@ -127,12 +137,12 @@ void TimerInterrupt::set_CCMP() TimerTCB[_timer]->INTCTRL = TCB_CAPT_bm; // Enable the interrupt - TISR_LOGDEBUG(F("==================")); - TISR_LOGDEBUG1(F("set_CCMP, Timer ="), _timer); - TISR_LOGDEBUG1(F("CTRLB ="), TimerTCB[_timer]->CTRLB); - TISR_LOGDEBUG1(F("CCMP ="), TimerTCB[_timer]->CCMP); - TISR_LOGDEBUG1(F("INTCTRL ="), TimerTCB[_timer]->INTCTRL); - TISR_LOGDEBUG1(F("CTRLA ="), TimerTCB[_timer]->CTRLA); + TISR_LOGINFO(F("==================")); + TISR_LOGINFO1(F("set_CCMP, Timer ="), _timer); + TISR_LOGINFO1(F("CTRLB ="), TimerTCB[_timer]->CTRLB); + TISR_LOGINFO1(F("CCMP ="), TimerTCB[_timer]->CCMP); + TISR_LOGINFO1(F("INTCTRL ="), TimerTCB[_timer]->INTCTRL); + TISR_LOGINFO1(F("CTRLA ="), TimerTCB[_timer]->CTRLA); TISR_LOGDEBUG(F("==================")); // Flag _CCMPValue == 0 => end of long timer @@ -145,13 +155,8 @@ void TimerInterrupt::set_CCMP() // Return true if frequency is OK with selected timer (CCMPValue is in range) bool TimerInterrupt::setFrequency(float frequency, timer_callback_p callback, uint32_t params, unsigned long duration) { - -#define CLK_TCA_FREQ (250000L) - bool isSuccess = false; - // Currently using CLK_TCA from TCA0 == 250KHz - //frequencyLimit must > 1 float frequencyLimit = frequency * 17179.840; @@ -169,8 +174,8 @@ bool TimerInterrupt::setFrequency(float frequency, timer_callback_p callback, ui { _toggle_count = frequency * duration / 1000; - TISR_LOGWARN1(F("setFrequency => _toggle_count ="), _toggle_count); - TISR_LOGWARN3(F("Frequency ="), frequency, F(", duration ="), duration); + TISR_LOGINFO1(F("setFrequency => _toggle_count ="), _toggle_count); + TISR_LOGINFO3(F("Frequency ="), frequency, F(", duration ="), duration); if (_toggle_count < 1) { @@ -194,11 +199,10 @@ bool TimerInterrupt::setFrequency(float frequency, timer_callback_p callback, ui _timerDone = false; - - _CCMPValue = _CCMPValueRemaining = (uint32_t) (CLK_TCA_FREQ / frequency); - - TISR_LOGDEBUG3(F("Frequency ="), frequency, F(", CLK_TCA_FREQ ="), CLK_TCA_FREQ); - TISR_LOGDEBUG1(F("setFrequency: _CCMPValueRemaining = "), _CCMPValueRemaining); + _CCMPValue = _CCMPValueRemaining = (uint32_t) (CLK_TCB_FREQ / frequency); + + TISR_LOGINFO3(F("Frequency ="), frequency, F(", CLK_TCB_FREQ ="), CLK_TCB_FREQ); + TISR_LOGINFO1(F("setFrequency: _CCMPValueRemaining = "), _CCMPValueRemaining); // Set the CCMP for the given timer, // set the toggle count, @@ -258,3 +262,4 @@ void TimerInterrupt::resumeTimer(void) reattachInterrupt(); } + diff --git a/src_cpp/megaAVR_TimerInterrupt.h b/src_cpp/megaAVR_TimerInterrupt.h index 9cdfc88..2159192 100644 --- a/src_cpp/megaAVR_TimerInterrupt.h +++ b/src_cpp/megaAVR_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.2.0 + Version: 1.3.0 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K.Hoang 01/04/2021 Initial coding to support Arduino megaAVR ATmega4809-based boards (UNO WiFi Rev2, etc.) 1.1.0 K.Hoang 14/04/2021 Fix bug. Don't use v1.0.0 1.2.0 K.Hoang 17/04/2021 Selectable TCB Clock 16MHz, 8MHz or 250KHz depending on necessary accuracy + 1.3.0 K.Hoang 17/04/2021 Fix TCB Clock bug. Don't use v1.2.0 ****************************************************************************************************************************/ #pragma once @@ -47,7 +48,7 @@ #include "TimerInterrupt_Generic_Debug.h" #ifndef MEGA_AVR_TIMER_INTERRUPT_VERSION - #define MEGA_AVR_TIMER_INTERRUPT_VERSION "megaAVR_TimerInterrupt v1.1.0" + #define MEGA_AVR_TIMER_INTERRUPT_VERSION "megaAVR_TimerInterrupt v1.3.0" #endif #include diff --git a/src_h/TimerInterrupt_Generic_Debug.h b/src_h/TimerInterrupt_Generic_Debug.h index bf3d59d..a502e70 100644 --- a/src_h/TimerInterrupt_Generic_Debug.h +++ b/src_h/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.2.0 + Version: 1.3.0 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K.Hoang 01/04/2021 Initial coding to support Arduino megaAVR ATmega4809-based boards (UNO WiFi Rev2, etc.) 1.1.0 K.Hoang 14/04/2021 Fix bug. Don't use v1.0.0 1.2.0 K.Hoang 17/04/2021 Selectable TCB Clock 16MHz, 8MHz or 250KHz depending on necessary accuracy + 1.3.0 K.Hoang 17/04/2021 Fix TCB Clock bug. Don't use v1.2.0 *****************************************************************************************************************************/ #pragma once diff --git a/src_h/megaAVR_ISR_Timer-Impl.h b/src_h/megaAVR_ISR_Timer-Impl.h index ed17b04..c0edcd8 100644 --- a/src_h/megaAVR_ISR_Timer-Impl.h +++ b/src_h/megaAVR_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.2.0 + Version: 1.3.0 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K.Hoang 01/04/2021 Initial coding to support Arduino megaAVR ATmega4809-based boards (UNO WiFi Rev2, etc.) 1.1.0 K.Hoang 14/04/2021 Fix bug. Don't use v1.0.0 1.2.0 K.Hoang 17/04/2021 Selectable TCB Clock 16MHz, 8MHz or 250KHz depending on necessary accuracy + 1.3.0 K.Hoang 17/04/2021 Fix TCB Clock bug. Don't use v1.2.0 *****************************************************************************************************************************/ #pragma once diff --git a/src_h/megaAVR_ISR_Timer.h b/src_h/megaAVR_ISR_Timer.h index 3f60858..615679b 100644 --- a/src_h/megaAVR_ISR_Timer.h +++ b/src_h/megaAVR_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.2.0 + Version: 1.3.0 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K.Hoang 01/04/2021 Initial coding to support Arduino megaAVR ATmega4809-based boards (UNO WiFi Rev2, etc.) 1.1.0 K.Hoang 14/04/2021 Fix bug. Don't use v1.0.0 1.2.0 K.Hoang 17/04/2021 Selectable TCB Clock 16MHz, 8MHz or 250KHz depending on necessary accuracy + 1.3.0 K.Hoang 17/04/2021 Fix TCB Clock bug. Don't use v1.2.0 *****************************************************************************************************************************/ #pragma once @@ -41,7 +42,7 @@ #endif #ifndef MEGA_AVR_TIMER_INTERRUPT_VERSION - #define MEGA_AVR_TIMER_INTERRUPT_VERSION "megaAVR_TimerInterrupt v1.2.0" + #define MEGA_AVR_TIMER_INTERRUPT_VERSION "megaAVR_TimerInterrupt v1.3.0" #endif #include "TimerInterrupt_Generic_Debug.h" diff --git a/src_h/megaAVR_TimerInterrupt-Impl.h b/src_h/megaAVR_TimerInterrupt-Impl.h index 01f192b..f8cb490 100644 --- a/src_h/megaAVR_TimerInterrupt-Impl.h +++ b/src_h/megaAVR_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.2.0 + Version: 1.3.0 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K.Hoang 01/04/2021 Initial coding to support Arduino megaAVR ATmega4809-based boards (UNO WiFi Rev2, etc.) 1.1.0 K.Hoang 14/04/2021 Fix bug. Don't use v1.0.0 1.2.0 K.Hoang 17/04/2021 Selectable TCB Clock 16MHz, 8MHz or 250KHz depending on necessary accuracy + 1.3.0 K.Hoang 17/04/2021 Fix TCB Clock bug. Don't use v1.2.0 ****************************************************************************************************************************/ #pragma once @@ -67,25 +68,34 @@ typedef enum TCB_CNTMODE_enum TCB_t* TimerTCB[ NUM_HW_TIMERS ] = { &TCB0, &TCB1, &TCB2, &TCB3 }; +#define CLK_TCA_FREQ (250000L) + // Clock for UNO WiFi Rev2 and Nano Every is 16MHz -#if USING_16MHZ // Use no prescaler (prescaler 1) => 16MHz +#if USING_16MHZ + // Use no prescaler (prescaler 1) => 16MHz #warning Using no prescaler => 16MHz #define TCB_CLKSEL_VALUE TCB_CLKSEL_CLKDIV1_gc + #define CLOCK_PRESCALER 1 #elif USING_8MHZ // Use prescaler 2 => 8MHz #warning Using prescaler 2 => 8MHz #define TCB_CLKSEL_VALUE TCB_CLKSEL_CLKDIV2_gc + #define CLOCK_PRESCALER 2 #elif USING_250KHZ // Optional, but for clarity // Use Timer A as clock (prescaler 64) => 250KHz #warning Using prescaler 64 => 250KHz #define TCB_CLKSEL_VALUE TCB_CLKSEL_CLKTCA_gc + #define CLOCK_PRESCALER 64 #else // Use Timer A as clock (prescaler 64) => 250KHz #warning Using prescaler 64 => 250KHz #define TCB_CLKSEL_VALUE TCB_CLKSEL_CLKTCA_gc + #define CLOCK_PRESCALER 64 #endif +#define CLK_TCB_FREQ ( F_CPU / CLOCK_PRESCALER ) + void TimerInterrupt::init(int8_t timer) { // Set timer specific stuff @@ -103,13 +113,13 @@ void TimerInterrupt::init(int8_t timer) TISR_LOGWARN1(F("TCB"), timer); - TISR_LOGDEBUG(F("==================")); - TISR_LOGDEBUG1(F("Init, Timer ="), timer); - TISR_LOGDEBUG1(F("CTRLB ="), TimerTCB[timer]->CTRLB); - TISR_LOGDEBUG1(F("CCMP ="), TimerTCB[timer]->CCMP); - TISR_LOGDEBUG1(F("INTCTRL ="), TimerTCB[timer]->INTCTRL); - TISR_LOGDEBUG1(F("CTRLA ="), TimerTCB[timer]->CTRLA); - TISR_LOGDEBUG(F("==================")); + TISR_LOGINFO(F("==================")); + TISR_LOGINFO1(F("Init, Timer ="), timer); + TISR_LOGINFO1(F("CTRLB ="), TimerTCB[timer]->CTRLB); + TISR_LOGINFO1(F("CCMP ="), TimerTCB[timer]->CCMP); + TISR_LOGINFO1(F("INTCTRL ="), TimerTCB[timer]->INTCTRL); + TISR_LOGINFO1(F("CTRLA ="), TimerTCB[timer]->CTRLA); + TISR_LOGINFO(F("==================")); _timer = timer; @@ -132,12 +142,12 @@ void TimerInterrupt::set_CCMP() TimerTCB[_timer]->INTCTRL = TCB_CAPT_bm; // Enable the interrupt - TISR_LOGDEBUG(F("==================")); - TISR_LOGDEBUG1(F("set_CCMP, Timer ="), _timer); - TISR_LOGDEBUG1(F("CTRLB ="), TimerTCB[_timer]->CTRLB); - TISR_LOGDEBUG1(F("CCMP ="), TimerTCB[_timer]->CCMP); - TISR_LOGDEBUG1(F("INTCTRL ="), TimerTCB[_timer]->INTCTRL); - TISR_LOGDEBUG1(F("CTRLA ="), TimerTCB[_timer]->CTRLA); + TISR_LOGINFO(F("==================")); + TISR_LOGINFO1(F("set_CCMP, Timer ="), _timer); + TISR_LOGINFO1(F("CTRLB ="), TimerTCB[_timer]->CTRLB); + TISR_LOGINFO1(F("CCMP ="), TimerTCB[_timer]->CCMP); + TISR_LOGINFO1(F("INTCTRL ="), TimerTCB[_timer]->INTCTRL); + TISR_LOGINFO1(F("CTRLA ="), TimerTCB[_timer]->CTRLA); TISR_LOGDEBUG(F("==================")); // Flag _CCMPValue == 0 => end of long timer @@ -150,13 +160,8 @@ void TimerInterrupt::set_CCMP() // Return true if frequency is OK with selected timer (CCMPValue is in range) bool TimerInterrupt::setFrequency(float frequency, timer_callback_p callback, uint32_t params, unsigned long duration) { - -#define CLK_TCA_FREQ (250000L) - bool isSuccess = false; - // Currently using CLK_TCA from TCA0 == 250KHz - //frequencyLimit must > 1 float frequencyLimit = frequency * 17179.840; @@ -174,8 +179,8 @@ bool TimerInterrupt::setFrequency(float frequency, timer_callback_p callback, ui { _toggle_count = frequency * duration / 1000; - TISR_LOGWARN1(F("setFrequency => _toggle_count ="), _toggle_count); - TISR_LOGWARN3(F("Frequency ="), frequency, F(", duration ="), duration); + TISR_LOGINFO1(F("setFrequency => _toggle_count ="), _toggle_count); + TISR_LOGINFO3(F("Frequency ="), frequency, F(", duration ="), duration); if (_toggle_count < 1) { @@ -199,11 +204,10 @@ bool TimerInterrupt::setFrequency(float frequency, timer_callback_p callback, ui _timerDone = false; - - _CCMPValue = _CCMPValueRemaining = (uint32_t) (CLK_TCA_FREQ / frequency); - - TISR_LOGDEBUG3(F("Frequency ="), frequency, F(", CLK_TCA_FREQ ="), CLK_TCA_FREQ); - TISR_LOGDEBUG1(F("setFrequency: _CCMPValueRemaining = "), _CCMPValueRemaining); + _CCMPValue = _CCMPValueRemaining = (uint32_t) (CLK_TCB_FREQ / frequency); + + TISR_LOGINFO3(F("Frequency ="), frequency, F(", CLK_TCB_FREQ ="), CLK_TCB_FREQ); + TISR_LOGINFO1(F("setFrequency: _CCMPValueRemaining = "), _CCMPValueRemaining); // Set the CCMP for the given timer, // set the toggle count, diff --git a/src_h/megaAVR_TimerInterrupt.h b/src_h/megaAVR_TimerInterrupt.h index fa5ef8c..c237ce4 100644 --- a/src_h/megaAVR_TimerInterrupt.h +++ b/src_h/megaAVR_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.2.0 + Version: 1.3.0 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K.Hoang 01/04/2021 Initial coding to support Arduino megaAVR ATmega4809-based boards (UNO WiFi Rev2, etc.) 1.1.0 K.Hoang 14/04/2021 Fix bug. Don't use v1.0.0 1.2.0 K.Hoang 17/04/2021 Selectable TCB Clock 16MHz, 8MHz or 250KHz depending on necessary accuracy + 1.3.0 K.Hoang 17/04/2021 Fix TCB Clock bug. Don't use v1.2.0 ****************************************************************************************************************************/ #pragma once @@ -47,7 +48,7 @@ #include "TimerInterrupt_Generic_Debug.h" #ifndef MEGA_AVR_TIMER_INTERRUPT_VERSION - #define MEGA_AVR_TIMER_INTERRUPT_VERSION "megaAVR_TimerInterrupt v1.1.0" + #define MEGA_AVR_TIMER_INTERRUPT_VERSION "megaAVR_TimerInterrupt v1.3.0" #endif #include