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

Commit 07fca3e

Browse files
authored
v1.1.3 to fix bug related to TCB0
### Release v1.1.3 1. Fix bug giving error when using TCB0 (`USE_TIMER_0 == true`) 2. Fix bug causing system crash when using `_TIMERINTERRUPT_LOGLEVEL_ > 0`
1 parent f975fdd commit 07fca3e

11 files changed

+42
-75
lines changed

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ While software timer, **programmed for 2s, is activated after more than 10.000s
568568

569569
```
570570
Starting ISR_16_Timers_Array_Complex on AVR128DA
571-
Dx_TimerInterrupt v1.1.2
571+
Dx_TimerInterrupt v1.1.3
572572
CPU Frequency = 24 MHz
573573
TCB Clock Frequency = Full clock (24/16MHz, etc) for highest accuracy
574574
Starting ITimer OK, millis() = 13
@@ -656,7 +656,7 @@ Timer : 15, programmed : 80000, actual : 80013
656656

657657
```
658658
Starting ISR_16_Timers_Array_Complex on AVR128DA
659-
Dx_TimerInterrupt v1.1.2
659+
Dx_TimerInterrupt v1.1.3
660660
CPU Frequency = 24 MHz
661661
TCB Clock Frequency = Full clock (24/16MHz, etc) for highest accuracy
662662
Starting ITimer OK, millis() = 13
@@ -740,7 +740,7 @@ Timer : 15, programmed : 80000, actual : 80013
740740

741741
```
742742
Starting ISR_16_Timers_Array_Complex on AVR128DA
743-
Dx_TimerInterrupt v1.1.2
743+
Dx_TimerInterrupt v1.1.3
744744
CPU Frequency = 24 MHz
745745
TCB Clock Frequency = Half clock (12/8MHz, etc.) for high accuracy
746746
Starting ITimer OK, millis() = 12
@@ -807,7 +807,7 @@ The following is the sample terminal output when running example [Change_Interva
807807

808808
```
809809
Starting Change_Interval_HF on AVR128DA
810-
Dx_TimerInterrupt v1.1.2
810+
Dx_TimerInterrupt v1.1.3
811811
CPU Frequency = 24 MHz
812812
TCB Clock Frequency = Full clock (24/16MHz, etc) for highest accuracy
813813
Starting ITimer OK, millis() = 12
@@ -919,6 +919,9 @@ Submit issues to: [Dx_TimerInterrupt issues](https://github.com/khoih-prog/Dx_Ti
919919
8. Improve and customize examples for `Curiosity Nano AVRDA/AVRDB` boards to use on-board LED and SW
920920
9. Add notes `howto upload by drag-and-drop` to `CURIOSITY` virtual drive
921921
10. Using Serial3 for debugging with Curiosity Nano AVRDB, and Serial1 for debugging with Curiosity Nano AVRDA
922+
11. Fix bug giving error when using TCB0 (`USE_TIMER_0 == true`)
923+
12. Fix bug causing system crash when using `_TIMERINTERRUPT_LOGLEVEL_ > 0`
924+
922925

923926
---
924927
---

changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
## Table of Contents
1010

1111
* [Changelog](#changelog)
12+
* [Release v1.1.3](#release-v113)
1213
* [Release v1.1.2](#release-v112)
1314
* [Release v1.1.1](#release-v111)
1415
* [Release v1.1.0](#release-v110)
@@ -19,6 +20,11 @@
1920

2021
## Changelog
2122

23+
### Release v1.1.3
24+
25+
1. Fix bug giving error when using TCB0 (`USE_TIMER_0 == true`)
26+
2. Fix bug causing system crash when using `_TIMERINTERRUPT_LOGLEVEL_ > 0`
27+
2228
### Release v1.1.2
2329

2430
1. Using `Serial3` for debugging with `Curiosity Nano AVRDB`, and `Serial1` for debugging with `Curiosity Nano AVRDA`

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Dx_TimerInterrupt",
3-
"version": "1.1.2",
3+
"version": "1.1.3",
44
"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",
55
"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",
66
"authors":

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Dx_TimerInterrupt
2-
version=1.1.2
2+
version=1.1.3
33
author=Khoi Hoang
44
maintainer=Khoi Hoang <khoih.prog@gmail.com>
55
sentence=This library enables you to use Interrupt from Hardware Timers on Arduino AVRDx-based boards (AVR128Dx, AVR64Dx, AVR32Dx, etc.) using DxCore

src/Dx_ISR_Timer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212
Therefore, their executions are not blocked by bad-behaving functions / tasks.
1313
This important feature is absolutely necessary for mission-critical tasks.
1414
15-
Version: 1.1.2
15+
Version: 1.1.3
1616
1717
Version Modified By Date Comments
1818
------- ----------- ---------- -----------
1919
1.0.0 K.Hoang 23/08/2022 Initial coding to support AVR Dx (AVR128Dx, AVR64Dx, AVR32Dx, etc.) using DxCore
2020
1.1.0 K.Hoang 24/08/2022 Improve and customize examples for Curiosity Nano AVRDA/AVRDB boards
2121
1.1.1 K.Hoang 24/08/2022 Using Serial1 instead of Serial for debugging with Curiosity Nano AVRDA/AVRDB
2222
1.1.2 K.Hoang 24/08/2022 Using Serial3 for debugging with Curiosity Nano AVRDB
23+
1.1.3 K.Hoang 27/08/2022 Fix TCB0 disable bug
2324
*****************************************************************************************************************************/
2425

2526
#pragma once

src/Dx_ISR_Timer.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212
Therefore, their executions are not blocked by bad-behaving functions / tasks.
1313
This important feature is absolutely necessary for mission-critical tasks.
1414
15-
Version: 1.1.2
15+
Version: 1.1.3
1616
1717
Version Modified By Date Comments
1818
------- ----------- ---------- -----------
1919
1.0.0 K.Hoang 23/08/2022 Initial coding to support AVR Dx (AVR128Dx, AVR64Dx, AVR32Dx, etc.) using DxCore
2020
1.1.0 K.Hoang 24/08/2022 Improve and customize examples for Curiosity Nano AVRDA/AVRDB boards
2121
1.1.1 K.Hoang 24/08/2022 Using Serial1 instead of Serial for debugging with Curiosity Nano AVRDA/AVRDB
2222
1.1.2 K.Hoang 24/08/2022 Using Serial3 for debugging with Curiosity Nano AVRDB
23+
1.1.3 K.Hoang 27/08/2022 Fix TCB0 disable bug
2324
*****************************************************************************************************************************/
2425

2526
#pragma once

src/Dx_ISR_Timer_Impl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212
Therefore, their executions are not blocked by bad-behaving functions / tasks.
1313
This important feature is absolutely necessary for mission-critical tasks.
1414
15-
Version: 1.1.2
15+
Version: 1.1.3
1616
1717
Version Modified By Date Comments
1818
------- ----------- ---------- -----------
1919
1.0.0 K.Hoang 23/08/2022 Initial coding to support AVR Dx (AVR128Dx, AVR64Dx, AVR32Dx, etc.) using DxCore
2020
1.1.0 K.Hoang 24/08/2022 Improve and customize examples for Curiosity Nano AVRDA/AVRDB boards
2121
1.1.1 K.Hoang 24/08/2022 Using Serial1 instead of Serial for debugging with Curiosity Nano AVRDA/AVRDB
2222
1.1.2 K.Hoang 24/08/2022 Using Serial3 for debugging with Curiosity Nano AVRDB
23+
1.1.3 K.Hoang 27/08/2022 Fix TCB0 disable bug
2324
*****************************************************************************************************************************/
2425

2526
#pragma once

src/Dx_TimerInterrupt.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212
Therefore, their executions are not blocked by bad-behaving functions / tasks.
1313
This important feature is absolutely necessary for mission-critical tasks.
1414
15-
Version: 1.1.2
15+
Version: 1.1.3
1616
1717
Version Modified By Date Comments
1818
------- ----------- ---------- -----------
1919
1.0.0 K.Hoang 23/08/2022 Initial coding to support AVR Dx (AVR128Dx, AVR64Dx, AVR32Dx, etc.) using DxCore
2020
1.1.0 K.Hoang 24/08/2022 Improve and customize examples for Curiosity Nano AVRDA/AVRDB boards
2121
1.1.1 K.Hoang 24/08/2022 Using Serial1 instead of Serial for debugging with Curiosity Nano AVRDA/AVRDB
2222
1.1.2 K.Hoang 24/08/2022 Using Serial3 for debugging with Curiosity Nano AVRDB
23+
1.1.3 K.Hoang 27/08/2022 Fix TCB0 disable bug
2324
****************************************************************************************************************************/
2425

2526
#pragma once

src/Dx_TimerInterrupt.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212
Therefore, their executions are not blocked by bad-behaving functions / tasks.
1313
This important feature is absolutely necessary for mission-critical tasks.
1414
15-
Version: 1.1.2
15+
Version: 1.1.3
1616
1717
Version Modified By Date Comments
1818
------- ----------- ---------- -----------
1919
1.0.0 K.Hoang 23/08/2022 Initial coding to support AVR Dx (AVR128Dx, AVR64Dx, AVR32Dx, etc.) using DxCore
2020
1.1.0 K.Hoang 24/08/2022 Improve and customize examples for Curiosity Nano AVRDA/AVRDB boards
2121
1.1.1 K.Hoang 24/08/2022 Using Serial1 instead of Serial for debugging with Curiosity Nano AVRDA/AVRDB
2222
1.1.2 K.Hoang 24/08/2022 Using Serial3 for debugging with Curiosity Nano AVRDB
23+
1.1.3 K.Hoang 27/08/2022 Fix TCB0 disable bug
2324
****************************************************************************************************************************/
2425

2526
#pragma once
@@ -356,7 +357,6 @@ class TimerInterrupt
356357
// Reset value for next cycle
357358
_CCMPValueRemaining = _CCMPValue;
358359

359-
TISR_LOGDEBUG1(F("adjust_CCMPValue: reset _CCMPValueRemaining = "), _CCMPValue);
360360
_timerDone = true;
361361
}
362362
else

src/Dx_TimerInterrupt_Impl.h

Lines changed: 15 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212
Therefore, their executions are not blocked by bad-behaving functions / tasks.
1313
This important feature is absolutely necessary for mission-critical tasks.
1414
15-
Version: 1.1.2
15+
Version: 1.1.3
1616
1717
Version Modified By Date Comments
1818
------- ----------- ---------- -----------
1919
1.0.0 K.Hoang 23/08/2022 Initial coding to support AVR Dx (AVR128Dx, AVR64Dx, AVR32Dx, etc.) using DxCore
2020
1.1.0 K.Hoang 24/08/2022 Improve and customize examples for Curiosity Nano AVRDA/AVRDB boards
2121
1.1.1 K.Hoang 24/08/2022 Using Serial1 instead of Serial for debugging with Curiosity Nano AVRDA/AVRDB
2222
1.1.2 K.Hoang 24/08/2022 Using Serial3 for debugging with Curiosity Nano AVRDB
23+
1.1.3 K.Hoang 27/08/2022 Fix TCB0 disable bug
2324
****************************************************************************************************************************/
2425

2526
#pragma once
@@ -168,17 +169,7 @@ void TimerInterrupt::init(const int8_t& timer)
168169
TimerTCB[timer]->CCMP = MAX_COUNT_16BIT; // Value to compare with.
169170
TimerTCB[timer]->INTCTRL &= ~TCB_CAPT_bm; // Disable the interrupt
170171
TimerTCB[timer]->CTRLA = TCB_CLKSEL_VALUE | TCB_ENABLE_bm; // Use Timer A as clock, enable timer
171-
172-
TISR_LOGWARN1(F("TCB"), timer);
173172

174-
TISR_LOGINFO(F("=================="));
175-
TISR_LOGINFO1(F("Init, Timer = "), timer);
176-
TISR_LOGINFO1(F("CTRLB = "), TimerTCB[timer]->CTRLB);
177-
TISR_LOGINFO1(F("CCMP = "), TimerTCB[timer]->CCMP);
178-
TISR_LOGINFO1(F("INTCTRL = "), TimerTCB[timer]->INTCTRL);
179-
TISR_LOGINFO1(F("CTRLA = "), TimerTCB[timer]->CTRLA);
180-
TISR_LOGINFO(F("=================="));
181-
182173
_timer = timer;
183174

184175
interrupts();
@@ -201,15 +192,7 @@ void TimerInterrupt::set_CCMP()
201192
TimerTCB[_timer]->CCMP = _CCMPValueToUse; // Value to compare with.
202193

203194
TimerTCB[_timer]->INTCTRL = TCB_CAPT_bm; // Enable the interrupt
204-
205-
TISR_LOGDEBUG(F("=================="));
206-
TISR_LOGDEBUG1(F("set_CCMP, Timer = "), _timer);
207-
TISR_LOGDEBUG1(F("CTRLB = "), TimerTCB[_timer]->CTRLB);
208-
TISR_LOGDEBUG1(F("CCMP = "), TimerTCB[_timer]->CCMP);
209-
TISR_LOGDEBUG1(F("INTCTRL = "), TimerTCB[_timer]->INTCTRL);
210-
TISR_LOGDEBUG1(F("CTRLA = "), TimerTCB[_timer]->CTRLA);
211-
TISR_LOGDEBUG(F("=================="));
212-
195+
213196
// Flag _CCMPValue == 0 => end of long timer
214197
if (_CCMPValueRemaining == 0)
215198
_timerDone = true;
@@ -226,10 +209,8 @@ bool TimerInterrupt::setFrequency(const float& frequency, timer_callback_p callb
226209
float frequencyLimit = frequency * 17179.840;
227210

228211
// Limit frequency to larger than (0.00372529 / 64) Hz or interval 17179.840s / 17179840 ms to avoid uint32_t overflow
229-
if ((_timer <= 0) || (callback == NULL) || ((frequencyLimit) < 1) )
230-
{
231-
TISR_LOGDEBUG(F("setFrequency error"));
232-
212+
if ((_timer < 0) || (callback == NULL) || ((frequencyLimit) < 1) )
213+
{
233214
return false;
234215
}
235216
else
@@ -238,14 +219,9 @@ bool TimerInterrupt::setFrequency(const float& frequency, timer_callback_p callb
238219
if (duration > 0)
239220
{
240221
_toggle_count = frequency * duration / 1000;
241-
242-
TISR_LOGINFO1(F("setFrequency => _toggle_count = "), _toggle_count);
243-
TISR_LOGINFO3(F("Frequency ="), frequency, F(", duration = "), duration);
244222

245223
if (_toggle_count < 1)
246-
{
247-
TISR_LOGDEBUG(F("setFrequency: _toggle_count < 1 error"));
248-
224+
{
249225
return false;
250226
}
251227
}
@@ -265,9 +241,6 @@ bool TimerInterrupt::setFrequency(const float& frequency, timer_callback_p callb
265241
_timerDone = false;
266242

267243
_CCMPValue = _CCMPValueRemaining = (uint32_t) (CLK_TCB_FREQ / frequency);
268-
269-
TISR_LOGINFO3(F("Frequency = "), frequency, F(", CLK_TCB_FREQ = "), CLK_TCB_FREQ);
270-
TISR_LOGINFO1(F("setFrequency: _CCMPValueRemaining = "), _CCMPValueRemaining);
271244

272245
// Set the CCMP for the given timer,
273246
// set the toggle count,
@@ -381,9 +354,7 @@ void TimerInterrupt::resumeTimer()
381354
if (countLocal != 0)
382355
{
383356
if (ITimer0.checkTimerDone())
384-
{
385-
TISR_LOGDEBUG3(F("T0 callback, _CCMPValueRemaining = "), ITimer0.get_CCMPValueRemaining(), F(", millis = "), millis());
386-
357+
{
387358
ITimer0.callback();
388359

389360
if (ITimer0.get_CCMPValue() > MAX_COUNT_16BIT)
@@ -404,9 +375,7 @@ void TimerInterrupt::resumeTimer()
404375
}
405376
}
406377
else
407-
{
408-
TISR_LOGWARN(F("T0 done"));
409-
378+
{
410379
ITimer0.detachInterrupt();
411380
}
412381
}
@@ -437,9 +406,7 @@ void TimerInterrupt::resumeTimer()
437406
if (countLocal != 0)
438407
{
439408
if (ITimer1.checkTimerDone())
440-
{
441-
TISR_LOGDEBUG3(F("T1 callback, _CCMPValueRemaining = "), ITimer1.get_CCMPValueRemaining(), F(", millis = "), millis());
442-
409+
{
443410
ITimer1.callback();
444411

445412
if (ITimer1.get_CCMPValue() > MAX_COUNT_16BIT)
@@ -461,8 +428,6 @@ void TimerInterrupt::resumeTimer()
461428
}
462429
else
463430
{
464-
TISR_LOGWARN(F("T1 done"));
465-
466431
ITimer1.detachInterrupt();
467432
}
468433
}
@@ -491,9 +456,7 @@ void TimerInterrupt::resumeTimer()
491456
if (countLocal != 0)
492457
{
493458
if (ITimer2.checkTimerDone())
494-
{
495-
TISR_LOGDEBUG3(F("T2 callback, _CCMPValueRemaining = "), ITimer2.get_CCMPValueRemaining(), F(", millis = "), millis());
496-
459+
{
497460
ITimer2.callback();
498461

499462
if (ITimer2.get_CCMPValue() > MAX_COUNT_16BIT)
@@ -514,9 +477,7 @@ void TimerInterrupt::resumeTimer()
514477
}
515478
}
516479
else
517-
{
518-
TISR_LOGWARN(F("T2 done"));
519-
480+
{
520481
ITimer2.detachInterrupt();
521482
}
522483
}
@@ -545,9 +506,7 @@ void TimerInterrupt::resumeTimer()
545506
if (countLocal != 0)
546507
{
547508
if (ITimer3.checkTimerDone())
548-
{
549-
TISR_LOGDEBUG3(F("T3 callback, _CCMPValueRemaining = "), ITimer3.get_CCMPValueRemaining(), F(", millis = "), millis());
550-
509+
{
551510
ITimer3.callback();
552511

553512
if (ITimer3.get_CCMPValue() > MAX_COUNT_16BIT)
@@ -568,9 +527,7 @@ void TimerInterrupt::resumeTimer()
568527
}
569528
}
570529
else
571-
{
572-
TISR_LOGWARN(F("T3 done"));
573-
530+
{
574531
ITimer3.detachInterrupt();
575532
}
576533
}
@@ -600,9 +557,7 @@ void TimerInterrupt::resumeTimer()
600557
if (countLocal != 0)
601558
{
602559
if (ITimer4.checkTimerDone())
603-
{
604-
TISR_LOGDEBUG3(F("T4 callback, _CCMPValueRemaining = "), ITimer4.get_CCMPValueRemaining(), F(", millis = "), millis());
605-
560+
{
606561
ITimer4.callback();
607562

608563
if (ITimer4.get_CCMPValue() > MAX_COUNT_16BIT)
@@ -623,9 +578,7 @@ void TimerInterrupt::resumeTimer()
623578
}
624579
}
625580
else
626-
{
627-
TISR_LOGWARN(F("T4 done"));
628-
581+
{
629582
ITimer4.detachInterrupt();
630583
}
631584
}

0 commit comments

Comments
 (0)