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

Commit

Permalink
v1.7.0 to fix bug disabling TCB0
Browse files Browse the repository at this point in the history
### Release v1.7.0

1. Fix bug disabling `TCB0`. Check [TimerB0 does not trigger interrupt #4](#4)
2. Use `allman astyle` and add `utils`
  • Loading branch information
khoih-prog authored Nov 11, 2022
1 parent f7666d9 commit 59d45e4
Show file tree
Hide file tree
Showing 26 changed files with 1,728 additions and 1,477 deletions.
31 changes: 27 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ If you don't find anything, please [open a new issue](https://github.com/khoih-p
Please ensure to specify the following:

* Arduino IDE version (e.g. 1.8.19) or Platform.io version
* `Arduino megaAVR` or `MegaCoreX` Core Version (e.g. Arduino megaAVR core v1.8.7 or MegaCoreX core v1.0.10)
* `Arduino megaAVR` or `MegaCoreX` Core Version (e.g. Arduino megaAVR core v1.8.7 or MegaCoreX core v1.1.0)
* Contextual information (e.g. what you were trying to achieve)
* Simplest possible steps to reproduce
* Anything that might be relevant in your opinion, such as:
Expand All @@ -29,24 +29,47 @@ Please ensure to specify the following:
Arduino IDE version: 1.8.19
Arduino megaAVR Core Version 1.8.7
OS: Ubuntu 20.04 LTS
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
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
Context:
I encountered a crash while trying to use the Timer Interrupt.
I encountered a crash while using this library
Steps to reproduce:
1. ...
2. ...
3. ...
4. ...
```

### Additional context

Add any other context about the problem here.

---

### Sending Feature Requests

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

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.

---

### Sending Pull Requests

Pull Requests with changes and fixes are also welcome!

Please use the `astyle` to reformat the updated library code as follows (demo for Ubuntu Linux)

1. Change directory to the library GitHub

```
xy@xy-Inspiron-3593:~$ cd Arduino/xy/megaAVR_TimerInterrupt_GitHub/
xy@xy-Inspiron-3593:~/Arduino/xy/megaAVR_TimerInterrupt_GitHub$
```

2. Issue astyle command

```
xy@xy-Inspiron-3593:~/Arduino/xy/megaAVR_TimerInterrupt_GitHub$ bash utils/restyle.sh
```

15 changes: 14 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,18 @@
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](#Contributing)
[![GitHub issues](https://img.shields.io/github/issues/khoih-prog/megaAVR_TimerInterrupt.svg)](http://github.com/khoih-prog/megaAVR_TimerInterrupt/issues)

<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>
<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>
<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>
<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>

---
---

## Table of Contents

* [Changelog](#changelog)
* [Release v1.7.0](#release-v170)
* [Release v1.6.1](#release-v161)
* [Release v1.6.0](#release-v160)
* [Release v1.5.0](#release-v150)
Expand All @@ -23,12 +32,16 @@

## Changelog

### Release v1.7.0

1. Fix bug disabling `TCB0`. Check [TimerB0 does not trigger interrupt #4](https://github.com/khoih-prog/megaAVR_TimerInterrupt/issues/4)
2. Use `allman astyle` and add `utils`

### Release v1.6.1

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


### Release v1.6.0

1. Add support to `MegaCoreX` core, including ATmega4809, ATmega4808, ATmega3209, ATmega3208, ATmega1609, ATmega1608, ATmega809 and ATmega808
Expand Down
115 changes: 61 additions & 54 deletions examples/Argument_Complex/Argument_Complex.ino
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
defined(ARDUINO_AVR_ATmega4809) || defined(ARDUINO_AVR_ATmega4808) || defined(ARDUINO_AVR_ATmega3209) || \
defined(ARDUINO_AVR_ATmega3208) || defined(ARDUINO_AVR_ATmega1609) || defined(ARDUINO_AVR_ATmega1608) || \
defined(ARDUINO_AVR_ATmega809) || defined(ARDUINO_AVR_ATmega808) )
#error This is designed only for Arduino or MegaCoreX megaAVR board! Please check your Tools->Board setting
#error This is designed only for Arduino or MegaCoreX megaAVR board! Please check your Tools->Board setting
#endif

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

#if !defined(LED_BUILTIN)
#define LED_BUILTIN 13
#define LED_BUILTIN 13
#endif

struct pinStruct
{
unsigned int Pin1;
unsigned int Pin2;
unsigned int Pin3;
unsigned int Pin1;
unsigned int Pin2;
unsigned int Pin3;
};

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

void TimerHandler1(unsigned int outputPinsAddress)
{
static bool toggle1 = false;
static bool started = false;

if (!started)
{
started = true;
pinMode(((pinStruct *) outputPinsAddress)->Pin1, OUTPUT);
pinMode(((pinStruct *) outputPinsAddress)->Pin2, INPUT_PULLUP);
pinMode(((pinStruct *) outputPinsAddress)->Pin3, INPUT_PULLUP);
}

//timer interrupt toggles pins
static bool toggle1 = false;
static bool started = false;

if (!started)
{
started = true;
pinMode(((pinStruct *) outputPinsAddress)->Pin1, OUTPUT);
pinMode(((pinStruct *) outputPinsAddress)->Pin2, INPUT_PULLUP);
pinMode(((pinStruct *) outputPinsAddress)->Pin3, INPUT_PULLUP);
}

//timer interrupt toggles pins
#if (TIMER_INTERRUPT_DEBUG > 1)
Serial.print("Toggle pin1 = "); Serial.println( ((pinStruct *) outputPinsAddress)->Pin1 );
Serial.print("Toggle pin1 = ");
Serial.println( ((pinStruct *) outputPinsAddress)->Pin1 );
#endif

digitalWrite(((pinStruct *) outputPinsAddress)->Pin1, toggle1);

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

Serial.print("Read pin3 A1 ("); Serial.print(((pinStruct *) outputPinsAddress)->Pin3 );
Serial.print(") = ");
Serial.println(digitalRead(((pinStruct *) outputPinsAddress)->Pin3) ? "HIGH" : "LOW" );
#if (TIMER_INTERRUPT_DEBUG > 1)
Serial.print("Read pin2 A0 (");
Serial.print(((pinStruct *) outputPinsAddress)->Pin2 );
Serial.print(") = ");
Serial.println(digitalRead(((pinStruct *) outputPinsAddress)->Pin2) ? "HIGH" : "LOW" );

Serial.print("Read pin3 A1 (");
Serial.print(((pinStruct *) outputPinsAddress)->Pin3 );
Serial.print(") = ");
Serial.println(digitalRead(((pinStruct *) outputPinsAddress)->Pin3) ? "HIGH" : "LOW" );
#endif
toggle1 = !toggle1;

toggle1 = !toggle1;
}

#define TIMER1_INTERVAL_MS 5000

void setup()
{
Serial.begin(115200);
while (!Serial);
Serial.begin(115200);

while (!Serial);

Serial.print(F("\nStarting Argument_Complex on "));
Serial.println(BOARD_NAME);
Serial.println(MEGA_AVR_TIMER_INTERRUPT_VERSION);
Serial.print(F("CPU Frequency = ")); Serial.print(F_CPU / 1000000); Serial.println(F(" MHz"));
Serial.print(F("\nStarting Argument_Complex on "));
Serial.println(BOARD_NAME);
Serial.println(MEGA_AVR_TIMER_INTERRUPT_VERSION);
Serial.print(F("CPU Frequency = "));
Serial.print(F_CPU / 1000000);
Serial.println(F(" MHz"));

Serial.print(F("TCB Clock Frequency = "));
Serial.print(F("TCB Clock Frequency = "));

#if USING_16MHZ
Serial.println(F("16MHz for highest accuracy"));
#elif USING_8MHZ
Serial.println(F("8MHz for very high accuracy"));
#if USING_16MHZ
Serial.println(F("16MHz for highest accuracy"));
#elif USING_8MHZ
Serial.println(F("8MHz for very high accuracy"));
#else
Serial.println(F("250KHz for lower accuracy but longer time"));
Serial.println(F("250KHz for lower accuracy but longer time"));
#endif

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

ITimer1.init();
ITimer1.init();

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

if (ITimer1.attachInterruptInterval(TIMER1_INTERVAL_MS, TimerHandler1, (unsigned int) &myOutputPins))
{
Serial.print(F("Starting ITimer1 OK, millis() = ")); Serial.println(millis());
}
else
Serial.println(F("Can't set ITimer1. Select another freq. or timer"));
if (ITimer1.attachInterruptInterval(TIMER1_INTERVAL_MS, TimerHandler1, (unsigned int) &myOutputPins))
{
Serial.print(F("Starting ITimer1 OK, millis() = "));
Serial.println(millis());
}
else
Serial.println(F("Can't set ITimer1. Select another freq. or timer"));
}

void loop()
Expand Down
Loading

0 comments on commit 59d45e4

Please sign in to comment.