From e844b26a8ef72e9d91c47f963f61ca01fee7fc18 Mon Sep 17 00:00:00 2001 From: Khoi Hoang <57012152+khoih-prog@users.noreply.github.com> Date: Sat, 27 Aug 2022 14:52:15 -0400 Subject: [PATCH] v1.0.1 for bug related to TCB0 ### Initial Release v1.0.1 1. Fix bug giving error when using TCB0 (`USE_TIMER_0 == true`) 2. Default to use TCB0 for boards having only 1 TCB Timer, such as `ATtiny817`, `ATtiny807` --- changelog.md | 6 ++++++ examples/Argument_Complex/Argument_Complex.ino | 4 ++-- examples/Argument_None/Argument_None.ino | 4 ++-- examples/Argument_Simple/Argument_Simple.ino | 4 ++-- examples/Change_Interval/Change_Interval.ino | 4 ++-- examples/Change_Interval_HF/Change_Interval_HF.ino | 4 ++-- examples/FakeAnalogWrite/FakeAnalogWrite.ino | 4 ++-- .../ISR_16_Timers_Array_Complex.ino | 8 ++++---- examples/ISR_RPM_Measure/ISR_RPM_Measure.ino | 4 ++-- .../ISR_Timers_Array_Simple/ISR_Timers_Array_Simple.ino | 4 ++-- examples/RPM_Measure/RPM_Measure.ino | 4 ++-- examples/SwitchDebounce/SwitchDebounce.ino | 4 ++-- examples/TimerDuration/TimerDuration.ino | 4 ++-- examples/TimerInterruptTest/TimerInterruptTest.ino | 4 ++-- examples/multiFileProject/multiFileProject.h | 4 ++-- library.json | 2 +- library.properties | 2 +- src/ATtiny_ISR_Timer.h | 3 ++- src/ATtiny_ISR_Timer.hpp | 9 +++++---- src/ATtiny_ISR_Timer_Impl.h | 3 ++- src/ATtiny_TimerInterrupt.h | 3 ++- src/ATtiny_TimerInterrupt.hpp | 9 +++++---- src/ATtiny_TimerInterrupt_Impl.h | 7 ++++--- src/TimerInterrupt_Generic_Debug.h | 3 ++- 24 files changed, 60 insertions(+), 47 deletions(-) diff --git a/changelog.md b/changelog.md index 4a4ec1a..3636397 100644 --- a/changelog.md +++ b/changelog.md @@ -9,6 +9,7 @@ ## Table of Contents * [Changelog](#changelog) + * [Release v1.0.1](#release-v101) * [Initial Release v1.0.0](#initial-release-v100) --- @@ -16,6 +17,11 @@ ## Changelog +### Initial Release v1.0.1 + +1. Fix bug giving error when using TCB0 (`USE_TIMER_0 == true`) +2. Default to use TCB0 for boards having only 1 TCB Timer, such as `ATtiny817`, `ATtiny807` + ### Initial Release v1.0.0 1. Intial release to support Arduino **AVR ATtiny-based boards (ATtiny3217, etc.) using megaTinyCore** diff --git a/examples/Argument_Complex/Argument_Complex.ino b/examples/Argument_Complex/Argument_Complex.ino index a48ff13..5730073 100644 --- a/examples/Argument_Complex/Argument_Complex.ino +++ b/examples/Argument_Complex/Argument_Complex.ino @@ -35,8 +35,8 @@ #define USING_250KHZ false // Not supported now // Try to use RTC, TCA0 or TCD0 for millis() -#define USE_TIMER_0 false // Check if used by millis(), Servo or tone() -#define USE_TIMER_1 true // Check if used by millis(), Servo or tone() +#define USE_TIMER_0 true // Check if used by millis(), Servo or tone() +#define USE_TIMER_1 false // Check if used by millis(), Servo or tone() #if USE_TIMER_0 #define CurrentTimer ITimer0 diff --git a/examples/Argument_None/Argument_None.ino b/examples/Argument_None/Argument_None.ino index b1ea362..a9850a1 100644 --- a/examples/Argument_None/Argument_None.ino +++ b/examples/Argument_None/Argument_None.ino @@ -35,8 +35,8 @@ #define USING_250KHZ false // Not supported now // Try to use RTC, TCA0 or TCD0 for millis() -#define USE_TIMER_0 false // Check if used by millis(), Servo or tone() -#define USE_TIMER_1 true // Check if used by millis(), Servo or tone() +#define USE_TIMER_0 true // Check if used by millis(), Servo or tone() +#define USE_TIMER_1 false // Check if used by millis(), Servo or tone() #if USE_TIMER_0 #define CurrentTimer ITimer0 diff --git a/examples/Argument_Simple/Argument_Simple.ino b/examples/Argument_Simple/Argument_Simple.ino index 6fbe1f1..35f7ee3 100644 --- a/examples/Argument_Simple/Argument_Simple.ino +++ b/examples/Argument_Simple/Argument_Simple.ino @@ -35,8 +35,8 @@ #define USING_250KHZ false // Not supported now // Try to use RTC, TCA0 or TCD0 for millis() -#define USE_TIMER_0 false // Check if used by millis(), Servo or tone() -#define USE_TIMER_1 true // Check if used by millis(), Servo or tone() +#define USE_TIMER_0 true // Check if used by millis(), Servo or tone() +#define USE_TIMER_1 false // Check if used by millis(), Servo or tone() #if USE_TIMER_0 #define CurrentTimer ITimer0 diff --git a/examples/Change_Interval/Change_Interval.ino b/examples/Change_Interval/Change_Interval.ino index 28bc1ff..e3933ed 100644 --- a/examples/Change_Interval/Change_Interval.ino +++ b/examples/Change_Interval/Change_Interval.ino @@ -35,8 +35,8 @@ #define USING_250KHZ false // Not supported now // Try to use RTC, TCA0 or TCD0 for millis() -#define USE_TIMER_0 false // Check if used by millis(), Servo or tone() -#define USE_TIMER_1 true // Check if used by millis(), Servo or tone() +#define USE_TIMER_0 true // Check if used by millis(), Servo or tone() +#define USE_TIMER_1 false // Check if used by millis(), Servo or tone() #if USE_TIMER_0 #define CurrentTimer ITimer0 diff --git a/examples/Change_Interval_HF/Change_Interval_HF.ino b/examples/Change_Interval_HF/Change_Interval_HF.ino index 91533b8..05d97f6 100644 --- a/examples/Change_Interval_HF/Change_Interval_HF.ino +++ b/examples/Change_Interval_HF/Change_Interval_HF.ino @@ -35,8 +35,8 @@ #define USING_250KHZ false // Not supported now // Try to use RTC, TCA0 or TCD0 for millis() -#define USE_TIMER_0 false // Check if used by millis(), Servo or tone() -#define USE_TIMER_1 true // Check if used by millis(), Servo or tone() +#define USE_TIMER_0 true // Check if used by millis(), Servo or tone() +#define USE_TIMER_1 false // Check if used by millis(), Servo or tone() #if USE_TIMER_0 #define CurrentTimer ITimer0 diff --git a/examples/FakeAnalogWrite/FakeAnalogWrite.ino b/examples/FakeAnalogWrite/FakeAnalogWrite.ino index 5ae254d..9be954e 100644 --- a/examples/FakeAnalogWrite/FakeAnalogWrite.ino +++ b/examples/FakeAnalogWrite/FakeAnalogWrite.ino @@ -35,8 +35,8 @@ #define USING_250KHZ false // Not supported now // Try to use RTC, TCA0 or TCD0 for millis() -#define USE_TIMER_0 false // Check if used by millis(), Servo or tone() -#define USE_TIMER_1 true // Check if used by millis(), Servo or tone() +#define USE_TIMER_0 true // Check if used by millis(), Servo or tone() +#define USE_TIMER_1 false // Check if used by millis(), Servo or tone() #if USE_TIMER_0 #define CurrentTimer ITimer0 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 0642d84..20b0349 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 @@ -30,13 +30,13 @@ // Select USING_HALF_CLOCK == true for 10/ 8MHz to Timer TCBx => shorter timer, but better accuracy // Select USING_250KHZ == true for 250KHz to Timer TCBx => longer timer, but worse accuracy // Not select for default 250KHz to Timer TCBx => longer timer, but worse accuracy -#define USING_FULL_CLOCK false -#define USING_HALF_CLOCK true +#define USING_FULL_CLOCK true +#define USING_HALF_CLOCK false #define USING_250KHZ false // Not supported now // Try to use RTC, TCA0 or TCD0 for millis() -#define USE_TIMER_0 false // Check if used by millis(), Servo or tone() -#define USE_TIMER_1 true // Check if used by millis(), Servo or tone() +#define USE_TIMER_0 true // Check if used by millis(), Servo or tone() +#define USE_TIMER_1 false // Check if used by millis(), Servo or tone() #if USE_TIMER_0 #define CurrentTimer ITimer0 diff --git a/examples/ISR_RPM_Measure/ISR_RPM_Measure.ino b/examples/ISR_RPM_Measure/ISR_RPM_Measure.ino index aa4b7a0..01391bd 100644 --- a/examples/ISR_RPM_Measure/ISR_RPM_Measure.ino +++ b/examples/ISR_RPM_Measure/ISR_RPM_Measure.ino @@ -35,8 +35,8 @@ #define USING_250KHZ false // Not supported now // Try to use RTC, TCA0 or TCD0 for millis() -#define USE_TIMER_0 false // Check if used by millis(), Servo or tone() -#define USE_TIMER_1 true // Check if used by millis(), Servo or tone() +#define USE_TIMER_0 true // Check if used by millis(), Servo or tone() +#define USE_TIMER_1 false // Check if used by millis(), Servo or tone() #if USE_TIMER_0 #define CurrentTimer ITimer0 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 a800bad..ca8f1c1 100644 --- a/examples/ISR_Timers_Array_Simple/ISR_Timers_Array_Simple.ino +++ b/examples/ISR_Timers_Array_Simple/ISR_Timers_Array_Simple.ino @@ -35,8 +35,8 @@ #define USING_250KHZ false // Not supported now // Try to use RTC, TCA0 or TCD0 for millis() -#define USE_TIMER_0 false // Check if used by millis(), Servo or tone() -#define USE_TIMER_1 true // Check if used by millis(), Servo or tone() +#define USE_TIMER_0 true // Check if used by millis(), Servo or tone() +#define USE_TIMER_1 false // Check if used by millis(), Servo or tone() #if USE_TIMER_0 #define CurrentTimer ITimer0 diff --git a/examples/RPM_Measure/RPM_Measure.ino b/examples/RPM_Measure/RPM_Measure.ino index fff85b8..b5e413f 100644 --- a/examples/RPM_Measure/RPM_Measure.ino +++ b/examples/RPM_Measure/RPM_Measure.ino @@ -45,8 +45,8 @@ #define USING_250KHZ false // Not supported now // Try to use RTC, TCA0 or TCD0 for millis() -#define USE_TIMER_0 false // Check if used by millis(), Servo or tone() -#define USE_TIMER_1 true // Check if used by millis(), Servo or tone() +#define USE_TIMER_0 true // Check if used by millis(), Servo or tone() +#define USE_TIMER_1 false // Check if used by millis(), Servo or tone() #if USE_TIMER_0 #define CurrentTimer ITimer0 diff --git a/examples/SwitchDebounce/SwitchDebounce.ino b/examples/SwitchDebounce/SwitchDebounce.ino index 2861df8..f77fe5f 100644 --- a/examples/SwitchDebounce/SwitchDebounce.ino +++ b/examples/SwitchDebounce/SwitchDebounce.ino @@ -42,8 +42,8 @@ #define USING_250KHZ false // Not supported now // Try to use RTC, TCA0 or TCD0 for millis() -#define USE_TIMER_0 false // Check if used by millis(), Servo or tone() -#define USE_TIMER_1 true // Check if used by millis(), Servo or tone() +#define USE_TIMER_0 true // Check if used by millis(), Servo or tone() +#define USE_TIMER_1 false // Check if used by millis(), Servo or tone() #if USE_TIMER_0 #define CurrentTimer ITimer0 diff --git a/examples/TimerDuration/TimerDuration.ino b/examples/TimerDuration/TimerDuration.ino index 66de1ca..7a723bb 100644 --- a/examples/TimerDuration/TimerDuration.ino +++ b/examples/TimerDuration/TimerDuration.ino @@ -35,8 +35,8 @@ #define USING_250KHZ false // Not supported now // Try to use RTC, TCA0 or TCD0 for millis() -#define USE_TIMER_0 false // Check if used by millis(), Servo or tone() -#define USE_TIMER_1 true // Check if used by millis(), Servo or tone() +#define USE_TIMER_0 true // Check if used by millis(), Servo or tone() +#define USE_TIMER_1 false // Check if used by millis(), Servo or tone() #if USE_TIMER_0 #define CurrentTimer ITimer0 diff --git a/examples/TimerInterruptTest/TimerInterruptTest.ino b/examples/TimerInterruptTest/TimerInterruptTest.ino index 6314c0e..97ab0f0 100644 --- a/examples/TimerInterruptTest/TimerInterruptTest.ino +++ b/examples/TimerInterruptTest/TimerInterruptTest.ino @@ -35,8 +35,8 @@ #define USING_250KHZ false // Not supported now // Try to use RTC, TCA0 or TCD0 for millis() -#define USE_TIMER_0 false // Check if used by millis(), Servo or tone() -#define USE_TIMER_1 true // Check if used by millis(), Servo or tone() +#define USE_TIMER_0 true // Check if used by millis(), Servo or tone() +#define USE_TIMER_1 false // Check if used by millis(), Servo or tone() #if USE_TIMER_0 #define CurrentTimer ITimer0 diff --git a/examples/multiFileProject/multiFileProject.h b/examples/multiFileProject/multiFileProject.h index 2d31c27..863e4fc 100644 --- a/examples/multiFileProject/multiFileProject.h +++ b/examples/multiFileProject/multiFileProject.h @@ -34,8 +34,8 @@ #define USING_250KHZ false // Not supported now // Try to use RTC, TCA0 or TCD0 for millis() -#define USE_TIMER_0 false // Check if used by millis(), Servo or tone() -#define USE_TIMER_1 true // Check if used by millis(), Servo or tone() +#define USE_TIMER_0 true // Check if used by millis(), Servo or tone() +#define USE_TIMER_1 false // Check if used by millis(), Servo or tone() #if USE_TIMER_0 #define CurrentTimer ITimer0 diff --git a/library.json b/library.json index 080e4ed..a27f94b 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "ATtiny_TimerInterrupt", - "version": "1.0.0", + "version": "1.0.1", "keywords": "timer, interrupt, isr, isr-based, timing, control, hardware-timer, mission-critical, accuracy, megaavr, avr-attiny, attiny, megatinycore, megatiny-core, attiny-timerinterrupt, tcb-timers", "description": "This library enables you to use Interrupt from Hardware Timers on Arduino AVR ATtiny-based boards (ATtiny3217, etc.) using megaTinyCore. These ATtiny 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 89684e0..9aefc84 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=ATtiny_TimerInterrupt -version=1.0.0 +version=1.0.1 author=Khoi Hoang maintainer=Khoi Hoang sentence=This library enables you to use Interrupt from Hardware Timers on Arduino AVR ATtiny-based boards (ATtiny3217, etc.) using megaTinyCore diff --git a/src/ATtiny_ISR_Timer.h b/src/ATtiny_ISR_Timer.h index bee3b8c..0c44b0c 100644 --- a/src/ATtiny_ISR_Timer.h +++ b/src/ATtiny_ISR_Timer.h @@ -12,11 +12,12 @@ Therefore, their executions are not blocked by bad-behaving functions / tasks. This important feature is absolutely necessary for mission-critical tasks. - Version: 1.0.0 + Version: 1.0.1 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K.Hoang 27/08/2022 Initial coding to support AVR ATtiny (ATtiny3217, etc.) using megaTinyCore + 1.0.1 K.Hoang 27/08/2022 Fix TCB0 disable bug *****************************************************************************************************************************/ #pragma once diff --git a/src/ATtiny_ISR_Timer.hpp b/src/ATtiny_ISR_Timer.hpp index 1e7e481..0ed8f97 100644 --- a/src/ATtiny_ISR_Timer.hpp +++ b/src/ATtiny_ISR_Timer.hpp @@ -12,11 +12,12 @@ Therefore, their executions are not blocked by bad-behaving functions / tasks. This important feature is absolutely necessary for mission-critical tasks. - Version: 1.0.0 + Version: 1.0.1 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K.Hoang 27/08/2022 Initial coding to support AVR ATtiny (ATtiny3217, etc.) using megaTinyCore + 1.0.1 K.Hoang 27/08/2022 Fix TCB0 disable bug *****************************************************************************************************************************/ #pragma once @@ -31,13 +32,13 @@ #endif #ifndef AT_TINY_TIMER_INTERRUPT_VERSION - #define AT_TINY_TIMER_INTERRUPT_VERSION F("ATtiny_TimerInterrupt v1.0.0") + #define AT_TINY_TIMER_INTERRUPT_VERSION F("ATtiny_TimerInterrupt v1.0.1") #define AT_TINY_TIMER_INTERRUPT_VERSION_MAJOR 1 #define AT_TINY_TIMER_INTERRUPT_VERSION_MINOR 0 - #define AT_TINY_TIMER_INTERRUPT_VERSION_PATCH 0 + #define AT_TINY_TIMER_INTERRUPT_VERSION_PATCH 1 - #define AT_TINY_TIMER_INTERRUPT_VERSION_INT 1000000 + #define AT_TINY_TIMER_INTERRUPT_VERSION_INT 1000001 #endif #include "TimerInterrupt_Generic_Debug.h" diff --git a/src/ATtiny_ISR_Timer_Impl.h b/src/ATtiny_ISR_Timer_Impl.h index efc2553..ee7356b 100644 --- a/src/ATtiny_ISR_Timer_Impl.h +++ b/src/ATtiny_ISR_Timer_Impl.h @@ -12,11 +12,12 @@ Therefore, their executions are not blocked by bad-behaving functions / tasks. This important feature is absolutely necessary for mission-critical tasks. - Version: 1.0.0 + Version: 1.0.1 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K.Hoang 27/08/2022 Initial coding to support AVR ATtiny (ATtiny3217, etc.) using megaTinyCore + 1.0.1 K.Hoang 27/08/2022 Fix TCB0 disable bug *****************************************************************************************************************************/ #pragma once diff --git a/src/ATtiny_TimerInterrupt.h b/src/ATtiny_TimerInterrupt.h index 6424a45..544d4a0 100644 --- a/src/ATtiny_TimerInterrupt.h +++ b/src/ATtiny_TimerInterrupt.h @@ -12,11 +12,12 @@ Therefore, their executions are not blocked by bad-behaving functions / tasks. This important feature is absolutely necessary for mission-critical tasks. - Version: 1.0.0 + Version: 1.0.1 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K.Hoang 27/08/2022 Initial coding to support AVR ATtiny (ATtiny3217, etc.) using megaTinyCore + 1.0.1 K.Hoang 27/08/2022 Fix TCB0 disable bug ****************************************************************************************************************************/ #pragma once diff --git a/src/ATtiny_TimerInterrupt.hpp b/src/ATtiny_TimerInterrupt.hpp index d33e745..387fd89 100644 --- a/src/ATtiny_TimerInterrupt.hpp +++ b/src/ATtiny_TimerInterrupt.hpp @@ -12,11 +12,12 @@ Therefore, their executions are not blocked by bad-behaving functions / tasks. This important feature is absolutely necessary for mission-critical tasks. - Version: 1.0.0 + Version: 1.0.1 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K.Hoang 27/08/2022 Initial coding to support AVR ATtiny (ATtiny3217, etc.) using megaTinyCore + 1.0.1 K.Hoang 27/08/2022 Fix TCB0 disable bug ****************************************************************************************************************************/ #pragma once @@ -155,13 +156,13 @@ #include "TimerInterrupt_Generic_Debug.h" #ifndef AT_TINY_TIMER_INTERRUPT_VERSION - #define AT_TINY_TIMER_INTERRUPT_VERSION F("ATtiny_TimerInterrupt v1.0.0") + #define AT_TINY_TIMER_INTERRUPT_VERSION F("ATtiny_TimerInterrupt v1.0.1") #define AT_TINY_TIMER_INTERRUPT_VERSION_MAJOR 1 #define AT_TINY_TIMER_INTERRUPT_VERSION_MINOR 0 - #define AT_TINY_TIMER_INTERRUPT_VERSION_PATCH 0 + #define AT_TINY_TIMER_INTERRUPT_VERSION_PATCH 1 - #define AT_TINY_TIMER_INTERRUPT_VERSION_INT 1000000 + #define AT_TINY_TIMER_INTERRUPT_VERSION_INT 1000001 #endif #include diff --git a/src/ATtiny_TimerInterrupt_Impl.h b/src/ATtiny_TimerInterrupt_Impl.h index dfe4d8b..3d61a07 100644 --- a/src/ATtiny_TimerInterrupt_Impl.h +++ b/src/ATtiny_TimerInterrupt_Impl.h @@ -12,11 +12,12 @@ Therefore, their executions are not blocked by bad-behaving functions / tasks. This important feature is absolutely necessary for mission-critical tasks. - Version: 1.0.0 + Version: 1.0.1 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K.Hoang 27/08/2022 Initial coding to support AVR ATtiny (ATtiny3217, etc.) using megaTinyCore + 1.0.1 K.Hoang 27/08/2022 Fix TCB0 disable bug ****************************************************************************************************************************/ #pragma once @@ -194,8 +195,8 @@ bool TimerInterrupt::setFrequency(const float& frequency, timer_callback_p callb float frequencyLimit = frequency * 17179.840; // Limit frequency to larger than (0.00372529 / 64) Hz or interval 17179.840s / 17179840 ms to avoid uint32_t overflow - if ((_timer <= 0) || (callback == NULL) || ((frequencyLimit) < 1) ) - { + if ((_timer < 0) || (callback == NULL) || ((frequencyLimit) < 1) ) + { return false; } else diff --git a/src/TimerInterrupt_Generic_Debug.h b/src/TimerInterrupt_Generic_Debug.h index 841477a..790a3fc 100644 --- a/src/TimerInterrupt_Generic_Debug.h +++ b/src/TimerInterrupt_Generic_Debug.h @@ -12,11 +12,12 @@ Therefore, their executions are not blocked by bad-behaving functions / tasks. This important feature is absolutely necessary for mission-critical tasks. - Version: 1.0.0 + Version: 1.0.1 Version Modified By Date Comments ------- ----------- ---------- ----------- 1.0.0 K.Hoang 27/08/2022 Initial coding to support AVR ATtiny (ATtiny3217, etc.) using megaTinyCore + 1.0.1 K.Hoang 27/08/2022 Fix TCB0 disable bug *****************************************************************************************************************************/ #pragma once