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

Commit 59d45e4

Browse files
authored
v1.7.0 to fix bug disabling TCB0
### Release v1.7.0 1. Fix bug disabling `TCB0`. Check [TimerB0 does not trigger interrupt #4](#4) 2. Use `allman astyle` and add `utils`
1 parent f7666d9 commit 59d45e4

26 files changed

+1728
-1477
lines changed

CONTRIBUTING.md

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ If you don't find anything, please [open a new issue](https://github.com/khoih-p
1515
Please ensure to specify the following:
1616

1717
* Arduino IDE version (e.g. 1.8.19) or Platform.io version
18-
* `Arduino megaAVR` or `MegaCoreX` Core Version (e.g. Arduino megaAVR core v1.8.7 or MegaCoreX core v1.0.10)
18+
* `Arduino megaAVR` or `MegaCoreX` Core Version (e.g. Arduino megaAVR core v1.8.7 or MegaCoreX core v1.1.0)
1919
* Contextual information (e.g. what you were trying to achieve)
2020
* Simplest possible steps to reproduce
2121
* Anything that might be relevant in your opinion, such as:
@@ -29,24 +29,47 @@ Please ensure to specify the following:
2929
Arduino IDE version: 1.8.19
3030
Arduino megaAVR Core Version 1.8.7
3131
OS: Ubuntu 20.04 LTS
32-
Linux xy-Inspiron-3593 5.13.0-40-generic #45~20.04.1-Ubuntu SMP Mon Apr 4 09:38:31 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
32+
Linux xy-Inspiron-3593 5.15.0-52-generic #58~20.04.1-Ubuntu SMP Thu Oct 13 13:09:46 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
3333
3434
Context:
35-
I encountered a crash while trying to use the Timer Interrupt.
36-
35+
I encountered a crash while using this library
3736
Steps to reproduce:
3837
1. ...
3938
2. ...
4039
3. ...
4140
4. ...
4241
```
42+
43+
### Additional context
44+
45+
Add any other context about the problem here.
46+
47+
---
48+
4349
### Sending Feature Requests
4450

4551
Feel free to post feature requests. It's helpful if you can explain exactly why the feature would be useful.
4652

4753
There are usually some outstanding feature requests in the [existing issues list](https://github.com/khoih-prog/megaAVR_TimerInterrupt/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement), feel free to add comments to them.
4854

55+
---
56+
4957
### Sending Pull Requests
5058

5159
Pull Requests with changes and fixes are also welcome!
5260

61+
Please use the `astyle` to reformat the updated library code as follows (demo for Ubuntu Linux)
62+
63+
1. Change directory to the library GitHub
64+
65+
```
66+
xy@xy-Inspiron-3593:~$ cd Arduino/xy/megaAVR_TimerInterrupt_GitHub/
67+
xy@xy-Inspiron-3593:~/Arduino/xy/megaAVR_TimerInterrupt_GitHub$
68+
```
69+
70+
2. Issue astyle command
71+
72+
```
73+
xy@xy-Inspiron-3593:~/Arduino/xy/megaAVR_TimerInterrupt_GitHub$ bash utils/restyle.sh
74+
```
75+

changelog.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,18 @@
66
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](#Contributing)
77
[![GitHub issues](https://img.shields.io/github/issues/khoih-prog/megaAVR_TimerInterrupt.svg)](http://github.com/khoih-prog/megaAVR_TimerInterrupt/issues)
88

9+
<a href="https://www.buymeacoffee.com/khoihprog6" title="Donate to my libraries using BuyMeACoffee"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Donate to my libraries using BuyMeACoffee" style="height: 50px !important;width: 181px !important;" ></a>
10+
<a href="https://www.buymeacoffee.com/khoihprog6" title="Donate to my libraries using BuyMeACoffee"><img src="https://img.shields.io/badge/buy%20me%20a%20coffee-donate-orange.svg?logo=buy-me-a-coffee&logoColor=FFDD00" style="height: 20px !important;width: 200px !important;" ></a>
11+
<a href="https://profile-counter.glitch.me/khoih-prog/count.svg" title="Total Visitor count"><img src="https://profile-counter.glitch.me/khoih-prog/count.svg" style="height: 30px;width: 200px;"></a>
12+
<a href="https://profile-counter.glitch.me/khoih-prog-megaAVR_TimerInterrupt/count.svg" title="Visitor count"><img src="https://profile-counter.glitch.me/khoih-prog-megaAVR_TimerInterrupt/count.svg" style="height: 30px;width: 200px;"></a>
13+
14+
---
15+
---
16+
917
## Table of Contents
1018

1119
* [Changelog](#changelog)
20+
* [Release v1.7.0](#release-v170)
1221
* [Release v1.6.1](#release-v161)
1322
* [Release v1.6.0](#release-v160)
1423
* [Release v1.5.0](#release-v150)
@@ -23,12 +32,16 @@
2332

2433
## Changelog
2534

35+
### Release v1.7.0
36+
37+
1. Fix bug disabling `TCB0`. Check [TimerB0 does not trigger interrupt #4](https://github.com/khoih-prog/megaAVR_TimerInterrupt/issues/4)
38+
2. Use `allman astyle` and add `utils`
39+
2640
### Release v1.6.1
2741

2842
1. Suppress warnings when `_TIMERINTERRUPT_LOGLEVEL_` < 2
2943
2. Remove unused `_prescalerIndex`
3044

31-
3245
### Release v1.6.0
3346

3447
1. Add support to `MegaCoreX` core, including ATmega4809, ATmega4808, ATmega3209, ATmega3208, ATmega1609, ATmega1608, ATmega809 and ATmega808

examples/Argument_Complex/Argument_Complex.ino

Lines changed: 61 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
defined(ARDUINO_AVR_ATmega4809) || defined(ARDUINO_AVR_ATmega4808) || defined(ARDUINO_AVR_ATmega3209) || \
1818
defined(ARDUINO_AVR_ATmega3208) || defined(ARDUINO_AVR_ATmega1609) || defined(ARDUINO_AVR_ATmega1608) || \
1919
defined(ARDUINO_AVR_ATmega809) || defined(ARDUINO_AVR_ATmega808) )
20-
#error This is designed only for Arduino or MegaCoreX megaAVR board! Please check your Tools->Board setting
20+
#error This is designed only for Arduino or MegaCoreX megaAVR board! Please check your Tools->Board setting
2121
#endif
2222

2323
// These define's must be placed at the beginning before #include "megaAVR_TimerInterrupt.h"
@@ -43,89 +43,96 @@
4343
#include "megaAVR_TimerInterrupt.h"
4444

4545
#if !defined(LED_BUILTIN)
46-
#define LED_BUILTIN 13
46+
#define LED_BUILTIN 13
4747
#endif
4848

4949
struct pinStruct
5050
{
51-
unsigned int Pin1;
52-
unsigned int Pin2;
53-
unsigned int Pin3;
51+
unsigned int Pin1;
52+
unsigned int Pin2;
53+
unsigned int Pin3;
5454
};
5555

5656
volatile pinStruct myOutputPins = { LED_BUILTIN, A0, A1 };
5757

5858
void TimerHandler1(unsigned int outputPinsAddress)
5959
{
60-
static bool toggle1 = false;
61-
static bool started = false;
62-
63-
if (!started)
64-
{
65-
started = true;
66-
pinMode(((pinStruct *) outputPinsAddress)->Pin1, OUTPUT);
67-
pinMode(((pinStruct *) outputPinsAddress)->Pin2, INPUT_PULLUP);
68-
pinMode(((pinStruct *) outputPinsAddress)->Pin3, INPUT_PULLUP);
69-
}
70-
71-
//timer interrupt toggles pins
60+
static bool toggle1 = false;
61+
static bool started = false;
62+
63+
if (!started)
64+
{
65+
started = true;
66+
pinMode(((pinStruct *) outputPinsAddress)->Pin1, OUTPUT);
67+
pinMode(((pinStruct *) outputPinsAddress)->Pin2, INPUT_PULLUP);
68+
pinMode(((pinStruct *) outputPinsAddress)->Pin3, INPUT_PULLUP);
69+
}
70+
71+
//timer interrupt toggles pins
7272
#if (TIMER_INTERRUPT_DEBUG > 1)
73-
Serial.print("Toggle pin1 = "); Serial.println( ((pinStruct *) outputPinsAddress)->Pin1 );
73+
Serial.print("Toggle pin1 = ");
74+
Serial.println( ((pinStruct *) outputPinsAddress)->Pin1 );
7475
#endif
75-
76-
digitalWrite(((pinStruct *) outputPinsAddress)->Pin1, toggle1);
7776

78-
#if (TIMER_INTERRUPT_DEBUG > 1)
79-
Serial.print("Read pin2 A0 ("); Serial.print(((pinStruct *) outputPinsAddress)->Pin2 );
80-
Serial.print(") = ");
81-
Serial.println(digitalRead(((pinStruct *) outputPinsAddress)->Pin2) ? "HIGH" : "LOW" );
77+
digitalWrite(((pinStruct *) outputPinsAddress)->Pin1, toggle1);
8278

83-
Serial.print("Read pin3 A1 ("); Serial.print(((pinStruct *) outputPinsAddress)->Pin3 );
84-
Serial.print(") = ");
85-
Serial.println(digitalRead(((pinStruct *) outputPinsAddress)->Pin3) ? "HIGH" : "LOW" );
79+
#if (TIMER_INTERRUPT_DEBUG > 1)
80+
Serial.print("Read pin2 A0 (");
81+
Serial.print(((pinStruct *) outputPinsAddress)->Pin2 );
82+
Serial.print(") = ");
83+
Serial.println(digitalRead(((pinStruct *) outputPinsAddress)->Pin2) ? "HIGH" : "LOW" );
84+
85+
Serial.print("Read pin3 A1 (");
86+
Serial.print(((pinStruct *) outputPinsAddress)->Pin3 );
87+
Serial.print(") = ");
88+
Serial.println(digitalRead(((pinStruct *) outputPinsAddress)->Pin3) ? "HIGH" : "LOW" );
8689
#endif
87-
88-
toggle1 = !toggle1;
90+
91+
toggle1 = !toggle1;
8992
}
9093

9194
#define TIMER1_INTERVAL_MS 5000
9295

9396
void setup()
9497
{
95-
Serial.begin(115200);
96-
while (!Serial);
98+
Serial.begin(115200);
99+
100+
while (!Serial);
97101

98-
Serial.print(F("\nStarting Argument_Complex on "));
99-
Serial.println(BOARD_NAME);
100-
Serial.println(MEGA_AVR_TIMER_INTERRUPT_VERSION);
101-
Serial.print(F("CPU Frequency = ")); Serial.print(F_CPU / 1000000); Serial.println(F(" MHz"));
102+
Serial.print(F("\nStarting Argument_Complex on "));
103+
Serial.println(BOARD_NAME);
104+
Serial.println(MEGA_AVR_TIMER_INTERRUPT_VERSION);
105+
Serial.print(F("CPU Frequency = "));
106+
Serial.print(F_CPU / 1000000);
107+
Serial.println(F(" MHz"));
102108

103-
Serial.print(F("TCB Clock Frequency = "));
109+
Serial.print(F("TCB Clock Frequency = "));
104110

105-
#if USING_16MHZ
106-
Serial.println(F("16MHz for highest accuracy"));
107-
#elif USING_8MHZ
108-
Serial.println(F("8MHz for very high accuracy"));
111+
#if USING_16MHZ
112+
Serial.println(F("16MHz for highest accuracy"));
113+
#elif USING_8MHZ
114+
Serial.println(F("8MHz for very high accuracy"));
109115
#else
110-
Serial.println(F("250KHz for lower accuracy but longer time"));
116+
Serial.println(F("250KHz for lower accuracy but longer time"));
111117
#endif
112118

113-
// Timer0 is used for micros(), millis(), delay(), etc and can't be used
114-
// Select Timer 1-2 for UNO, 0-5 for MEGA
115-
// Timer 2 is 8-bit timer, only for higher frequency
119+
// Timer0 is used for micros(), millis(), delay(), etc and can't be used
120+
// Select Timer 1-2 for UNO, 0-5 for MEGA
121+
// Timer 2 is 8-bit timer, only for higher frequency
116122

117-
ITimer1.init();
123+
ITimer1.init();
118124

119-
// Using ATmega328 used in UNO => 16MHz CPU clock ,
120-
// For 16-bit timer 1, 3, 4 and 5, set frequency from 0.2385 to some KHz
121-
// For 8-bit timer 2 (prescaler up to 1024, set frequency from 61.5Hz to some KHz
125+
// Using ATmega328 used in UNO => 16MHz CPU clock ,
126+
// For 16-bit timer 1, 3, 4 and 5, set frequency from 0.2385 to some KHz
127+
// For 8-bit timer 2 (prescaler up to 1024, set frequency from 61.5Hz to some KHz
122128

123-
if (ITimer1.attachInterruptInterval(TIMER1_INTERVAL_MS, TimerHandler1, (unsigned int) &myOutputPins))
124-
{
125-
Serial.print(F("Starting ITimer1 OK, millis() = ")); Serial.println(millis());
126-
}
127-
else
128-
Serial.println(F("Can't set ITimer1. Select another freq. or timer"));
129+
if (ITimer1.attachInterruptInterval(TIMER1_INTERVAL_MS, TimerHandler1, (unsigned int) &myOutputPins))
130+
{
131+
Serial.print(F("Starting ITimer1 OK, millis() = "));
132+
Serial.println(millis());
133+
}
134+
else
135+
Serial.println(F("Can't set ITimer1. Select another freq. or timer"));
129136
}
130137

131138
void loop()

0 commit comments

Comments
 (0)