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

Commit d41a464

Browse files
authored
v1.7.0 to fix bug
### Releases v1.7.0 1. Fix bug resulting wrong frequency for some low frequencies.
1 parent 171d8f7 commit d41a464

19 files changed

+141
-162
lines changed

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ While software timer, **programmed for 2s, is activated after more than 10.000s
821821
```
822822

823823
Starting ISR_16_Timers_Array_Complex on Arduino AVR UNO, Nano, etc.
824-
TimerInterrupt v1.6.0
824+
TimerInterrupt v1.7.0
825825
CPU Frequency = 16 MHz
826826
Starting ITimer1 OK, millis() = 7
827827
SimpleTimer : 2, ms : 10007, Dms : 10007
@@ -971,7 +971,7 @@ The following is the sample terminal output when running example [Change_Interva
971971
972972
```
973973
Starting Change_Interval on Arduino AVR Mega2560/ADK
974-
TimerInterrupt v1.6.0
974+
TimerInterrupt v1.7.0
975975
CPU Frequency = 16 MHz
976976
Starting ITimer1 OK, millis() = 5
977977
Starting ITimer3 OK, millis() = 8
@@ -999,7 +999,7 @@ The following is the sample terminal output when running example [Change_Interva
999999
10001000
```
10011001
Starting Change_Interval_HF on Arduino AVR UNO, Nano, etc.
1002-
TimerInterrupt v1.6.0
1002+
TimerInterrupt v1.7.0
10031003
CPU Frequency = 16 MHz
10041004
[TISR] T1
10051005
[TISR] Freq * 1000 = 5000000.00
@@ -1035,14 +1035,14 @@ Changing Frequency, Timer2 = 500
10351035
10361036
---
10371037
1038-
### 4. Change_Interval on Arduino AVR Mega2560 board
1038+
### 4. Change_Interval_HF on Arduino AVR Mega2560 board
10391039
1040-
The following is the sample terminal output when running example [Change_Interval_HF](examples/Change_Interval_HF) on **AVR Mega2560** to demonstrate how to change Timer Interval on-the-fly
1040+
The following is the sample terminal output when running example [Change_Interval_HF](examples/Change_Interval_HF) on **AVR Mega2560** to demonstrate how to change High Frequency Timer Interval on-the-fly
10411041
10421042
```
10431043

10441044
Starting Change_Interval_HF on Arduino AVR Mega2560/ADK
1045-
TimerInterrupt v1.6.0
1045+
TimerInterrupt v1.7.0
10461046
CPU Frequency = 16 MHz
10471047
[TISR] T1
10481048
[TISR] Freq * 1000 = 5000000.00
@@ -1137,6 +1137,7 @@ Submit issues to: [TimerInterrupt issues](https://github.com/khoih-prog/TimerInt
11371137
12. Add support to **Generic or Sparkfun AVR ATmega128RFA1** such as **ATMEGA128RFA1_DEV_BOARD, etc.**
11381138
13. Add Timer3 and Timer4 support to **ATmega32U4 and ATmega16U4**.
11391139
14. Fix bug resulting half frequency when using high frequencies.
1140+
15. Fix bug resulting wrong frequency for some low frequencies.
11401141

11411142
---
11421143
---

changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
## Table of Contents
1212

1313
* [Changelog](#changelog)
14+
* [Releases v1.7.0](#releases-v170)
1415
* [Releases v1.6.0](#releases-v160)
1516
* [Releases v1.5.0](#releases-v150)
1617
* [Releases v1.4.1](#releases-v141)
@@ -27,6 +28,10 @@
2728

2829
## Changelog
2930

31+
### Releases v1.7.0
32+
33+
1. Fix bug resulting wrong frequency for some low frequencies.
34+
3035
### Releases v1.6.0
3136

3237
1. Fix bug resulting half frequency when using high frequencies. Check [Frequencies are half of what I expect #22](https://github.com/khoih-prog/TimerInterrupt/discussions/22)

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "TimerInterrupt",
3-
"version": "1.6.0",
3+
"version": "1.7.0",
44
"keywords": "timer, interrupt, timer-interrupt, hardware, isr, isr-based, hardware-timer, mission-critical, accuracy, precise, atmega, atmega2560, atmega1280, atmega16u4, atmega32u4, 32u4, atmega328p, nano, uno, leonardo, yun, yun-mini, esplora, gemma, mega, feather, adafruit, 16u4, atmega128, atmega168, atmegang, atmega8, attiny85",
55
"description": "This library enables you to use Interrupt from Hardware Timers on an Arduino, Adafruit or Sparkfun AVR board, such as Nano, UNO, Mega, Leonardo, YUN, Teensy, Feather_32u4, Feather_328P, Pro Micro, 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.",
66
"authors":

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=TimerInterrupt
2-
version=1.6.0
2+
version=1.7.0
33
author=Khoi Hoang
44
maintainer=Khoi Hoang <[email protected]>
55
sentence=This library enables you to use Interrupt from Hardware Timers on an Arduino, Adafruit or Sparkfun AVR board, such as Nano, UNO, Mega, Leonardo, YUN, Teensy, Feather_32u4, Feather_328P, Pro Micro, etc.

src/ISR_Timer-Impl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
Therefore, their executions are not blocked by bad-behaving functions / tasks.
1919
This important feature is absolutely necessary for mission-critical tasks.
2020
21-
Version: 1.6.0
21+
Version: 1.7.0
2222
2323
Version Modified By Date Comments
2424
------- ----------- ---------- -----------
@@ -34,6 +34,7 @@
3434
1.4.1 K.Hoang 02/04/2021 Add support to Sparkfun 32U4, 328(P), 128RFA1 such as AVR_PROMICRO, REDBOT, etc.
3535
1.5.0 K.Hoang 08/05/2021 Add Timer 3 and 4 to 32U4. Add Timer auto-selection to examples.
3636
1.6.0 K.Hoang 15/11/2021 Fix bug resulting half frequency when using high frequencies.
37+
1.7.0 K.Hoang 19/11/2021 Fix bug resulting wrong frequency for some frequencies.
3738
*****************************************************************************************************************************/
3839

3940
#pragma once

src/ISR_Timer.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
Therefore, their executions are not blocked by bad-behaving functions / tasks.
1919
This important feature is absolutely necessary for mission-critical tasks.
2020
21-
Version: 1.6.0
21+
Version: 1.7.0
2222
2323
Version Modified By Date Comments
2424
------- ----------- ---------- -----------
@@ -34,6 +34,7 @@
3434
1.4.1 K.Hoang 02/04/2021 Add support to Sparkfun 32U4, 328(P), 128RFA1 such as AVR_PROMICRO, REDBOT, etc.
3535
1.5.0 K.Hoang 08/05/2021 Add Timer 3 and 4 to 32U4. Add Timer auto-selection to examples.
3636
1.6.0 K.Hoang 15/11/2021 Fix bug resulting half frequency when using high frequencies.
37+
1.7.0 K.Hoang 19/11/2021 Fix bug resulting wrong frequency for some frequencies.
3738
*****************************************************************************************************************************/
3839

3940
#pragma once
@@ -42,7 +43,7 @@
4243
#define ISR_TIMER_H
4344

4445
#ifndef TIMER_INTERRUPT_VERSION
45-
#define TIMER_INTERRUPT_VERSION "TimerInterrupt v1.6.0"
46+
#define TIMER_INTERRUPT_VERSION "TimerInterrupt v1.7.0"
4647
#endif
4748

4849
#include "TimerInterrupt_Generic_Debug.h"

src/TimerInterrupt-Impl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
Therefore, their executions are not blocked by bad-behaving functions / tasks.
1919
This important feature is absolutely necessary for mission-critical tasks.
2020
21-
Version: 1.6.0
21+
Version: 1.7.0
2222
2323
Version Modified By Date Comments
2424
------- ----------- ---------- -----------
@@ -34,6 +34,7 @@
3434
1.4.1 K.Hoang 02/04/2021 Add support to Sparkfun 32U4, 328(P), 128RFA1 such as AVR_PROMICRO, REDBOT, etc.
3535
1.5.0 K.Hoang 08/05/2021 Add Timer 3 and 4 to 32U4. Add Timer auto-selection to examples.
3636
1.6.0 K.Hoang 15/11/2021 Fix bug resulting half frequency when using high frequencies.
37+
1.7.0 K.Hoang 19/11/2021 Fix bug resulting wrong frequency for some frequencies.
3738
****************************************************************************************************************************/
3839

3940
#pragma once

src/TimerInterrupt.h

Lines changed: 33 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
Therefore, their executions are not blocked by bad-behaving functions / tasks.
1919
This important feature is absolutely necessary for mission-critical tasks.
2020
21-
Version: 1.6.0
21+
Version: 1.7.0
2222
2323
Version Modified By Date Comments
2424
------- ----------- ---------- -----------
@@ -34,6 +34,7 @@
3434
1.4.1 K.Hoang 02/04/2021 Add support to Sparkfun 32U4, 328(P), 128RFA1 such as AVR_PROMICRO, REDBOT, etc.
3535
1.5.0 K.Hoang 08/05/2021 Add Timer 3 and 4 to 32U4. Add Timer auto-selection to examples.
3636
1.6.0 K.Hoang 15/11/2021 Fix bug resulting half frequency when using high frequencies.
37+
1.7.0 K.Hoang 19/11/2021 Fix bug resulting wrong frequency for some frequencies.
3738
****************************************************************************************************************************/
3839

3940
#pragma once
@@ -116,7 +117,7 @@
116117
#include "TimerInterrupt_Generic_Debug.h"
117118

118119
#ifndef TIMER_INTERRUPT_VERSION
119-
#define TIMER_INTERRUPT_VERSION "TimerInterrupt v1.6.0"
120+
#define TIMER_INTERRUPT_VERSION "TimerInterrupt v1.7.0"
120121
#endif
121122

122123
#include <avr/interrupt.h>
@@ -368,20 +369,41 @@ class TimerInterrupt
368369
#if TIMER_INTERRUPT_USING_ATMEGA_32U4
369370
if (_timer == 4)
370371
{
372+
if (_OCRValueRemaining < MAX_COUNT_8BIT)
373+
{
374+
set_OCR();
375+
}
376+
371377
_OCRValueRemaining -= min(MAX_COUNT_8BIT, _OCRValueRemaining);
372378
}
373379
else
374380
{
381+
if (_OCRValueRemaining < MAX_COUNT_16BIT)
382+
{
383+
set_OCR();
384+
}
385+
375386
_OCRValueRemaining -= min(MAX_COUNT_16BIT, _OCRValueRemaining);
376387
}
377388
#else
389+
if (_OCRValueRemaining < MAX_COUNT_16BIT)
390+
{
391+
set_OCR();
392+
}
393+
378394
_OCRValueRemaining -= min(MAX_COUNT_16BIT, _OCRValueRemaining);
379395
#endif
380396
}
381397
else
398+
{
399+
if (_OCRValueRemaining < MAX_COUNT_8BIT)
400+
{
401+
set_OCR();
402+
}
403+
382404
_OCRValueRemaining -= min(MAX_COUNT_8BIT, _OCRValueRemaining);
405+
}
383406

384-
//if (_OCRValueRemaining == 0)
385407
if (_OCRValueRemaining <= 0)
386408
{
387409
// Reset value for next cycle
@@ -401,24 +423,9 @@ class TimerInterrupt
401423
noInterrupts();
402424

403425
// Reset value for next cycle, have to deduct the value already loaded to OCR register
404-
405-
if (_timer != 2)
406-
{
407-
#if TIMER_INTERRUPT_USING_ATMEGA_32U4
408-
if (_timer == 4)
409-
{
410-
_OCRValueRemaining = _OCRValue - min(MAX_COUNT_8BIT, _OCRValueRemaining);
411-
}
412-
else
413-
{
414-
_OCRValueRemaining = _OCRValue - min(MAX_COUNT_16BIT, _OCRValueRemaining);
415-
}
416-
#else
417-
_OCRValueRemaining = _OCRValue - min(MAX_COUNT_16BIT, _OCRValueRemaining);
418-
#endif
419-
}
420-
else
421-
_OCRValueRemaining = _OCRValue - min(MAX_COUNT_8BIT, _OCRValueRemaining);
426+
427+
_OCRValueRemaining = _OCRValue;
428+
set_OCR();
422429

423430
_timerDone = false;
424431

@@ -495,15 +502,11 @@ class TimerInterrupt
495502

496503
ITimer1.callback();
497504

498-
if (ITimer1.get_OCRValueRemaining() > MAX_COUNT_16BIT)
505+
if (ITimer1.get_OCRValue() > MAX_COUNT_16BIT)
499506
{
500507
// To reload _OCRValueRemaining as well as _OCR register to MAX_COUNT_16BIT if _OCRValueRemaining > MAX_COUNT_16BIT
501508
ITimer1.reload_OCRValue();
502509
}
503-
else
504-
{
505-
// Signal timer done
506-
}
507510

508511
if (countLocal > 0)
509512
ITimer1.setCount(countLocal - 1);
@@ -547,15 +550,11 @@ class TimerInterrupt
547550

548551
ITimer2.callback();
549552

550-
if (ITimer2.get_OCRValueRemaining() > MAX_COUNT_8BIT)
553+
if (ITimer2.get_OCRValue() > MAX_COUNT_8BIT)
551554
{
552555
// To reload _OCRValueRemaining as well as _OCR register to MAX_COUNT_8BIT if _OCRValueRemaining > MAX_COUNT_8BIT
553556
ITimer2.reload_OCRValue();
554557
}
555-
else
556-
{
557-
// Signal timer done
558-
}
559558

560559
if (countLocal > 0)
561560
ITimer2.setCount(countLocal - 1);
@@ -602,15 +601,11 @@ class TimerInterrupt
602601

603602
ITimer3.callback();
604603

605-
if (ITimer3.get_OCRValueRemaining() > MAX_COUNT_16BIT)
604+
if (ITimer3.get_OCRValue() > MAX_COUNT_16BIT)
606605
{
607606
// To reload _OCRValueRemaining as well as _OCR register to MAX_COUNT_16BIT if _OCRValueRemaining > MAX_COUNT_16BIT
608607
ITimer3.reload_OCRValue();
609608
}
610-
else
611-
{
612-
// Signal timer done
613-
}
614609

615610
if (countLocal > 0)
616611
ITimer3.setCount(countLocal - 1);
@@ -662,15 +657,11 @@ class TimerInterrupt
662657

663658
ITimer4.callback();
664659

665-
if (ITimer4.get_OCRValueRemaining() > MAX_COUNT_16BIT)
660+
if (ITimer4.get_OCRValue() > MAX_COUNT_16BIT)
666661
{
667662
// To reload _OCRValueRemaining as well as _OCR register to MAX_COUNT_16BIT if _OCRValueRemaining > MAX_COUNT_16BIT
668663
ITimer4.reload_OCRValue();
669664
}
670-
else
671-
{
672-
// Signal timer done
673-
}
674665

675666
if (countLocal > 0)
676667
ITimer4.setCount(countLocal - 1);
@@ -720,15 +711,11 @@ class TimerInterrupt
720711

721712
ITimer5.callback();
722713

723-
if (ITimer5.get_OCRValueRemaining() > MAX_COUNT_16BIT)
714+
if (ITimer5.get_OCRValue() > MAX_COUNT_16BIT)
724715
{
725716
// To reload _OCRValueRemaining as well as _OCR register to MAX_COUNT_16BIT if _OCRValueRemaining > MAX_COUNT_16BIT
726717
ITimer5.reload_OCRValue();
727718
}
728-
else
729-
{
730-
// Signal timer done
731-
}
732719

733720
if (countLocal > 0)
734721
ITimer5.setCount(countLocal - 1);

src/TimerInterrupt_Generic_Debug.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
Therefore, their executions are not blocked by bad-behaving functions / tasks.
1919
This important feature is absolutely necessary for mission-critical tasks.
2020
21-
Version: 1.6.0
21+
Version: 1.7.0
2222
2323
Version Modified By Date Comments
2424
------- ----------- ---------- -----------
@@ -34,6 +34,7 @@
3434
1.4.1 K.Hoang 02/04/2021 Add support to Sparkfun 32U4, 328(P), 128RFA1 such as AVR_PROMICRO, REDBOT, etc.
3535
1.5.0 K.Hoang 08/05/2021 Add Timer 3 and 4 to 32U4. Add Timer auto-selection to examples.
3636
1.6.0 K.Hoang 15/11/2021 Fix bug resulting half frequency when using high frequencies.
37+
1.7.0 K.Hoang 19/11/2021 Fix bug resulting wrong frequency for some frequencies.
3738
*****************************************************************************************************************************/
3839

3940
#pragma once

src_cpp/ISR_Timer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
Therefore, their executions are not blocked by bad-behaving functions / tasks.
1919
This important feature is absolutely necessary for mission-critical tasks.
2020
21-
Version: 1.6.0
21+
Version: 1.7.0
2222
2323
Version Modified By Date Comments
2424
------- ----------- ---------- -----------
@@ -34,6 +34,7 @@
3434
1.4.1 K.Hoang 02/04/2021 Add support to Sparkfun 32U4, 328(P), 128RFA1 such as AVR_PROMICRO, REDBOT, etc.
3535
1.5.0 K.Hoang 08/05/2021 Add Timer 3 and 4 to 32U4. Add Timer auto-selection to examples.
3636
1.6.0 K.Hoang 15/11/2021 Fix bug resulting half frequency when using high frequencies.
37+
1.7.0 K.Hoang 19/11/2021 Fix bug resulting wrong frequency for some frequencies.
3738
*****************************************************************************************************************************/
3839

3940
#include "ISR_Timer.h"

0 commit comments

Comments
 (0)