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

Commit

Permalink
v1.8.0 fixes doubling time bug
Browse files Browse the repository at this point in the history
### Releases v1.8.0

1. Fix doubled time for `ESP32_C3`. Check [Error in the value defined by TIMER0_INTERVAL_MS #28](https://github.com/khoih-prog/ESP32_C3_TimerInterrupt/issues/28)
2. Modify examples to avoid using `LED_BUILTIN` / `GPIO2`, `GPIO1` as it can cause crash in some boards, such as `ESP32_C3`
3. Use `allman astyle` and add `utils`
  • Loading branch information
khoih-prog authored Nov 16, 2022
1 parent ea8de75 commit c593e91
Show file tree
Hide file tree
Showing 19 changed files with 913 additions and 733 deletions.
32 changes: 27 additions & 5 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
* `ESP32` Core Version (e.g. ESP32 core v2.0.4)
* `ESP32` Core Version (e.g. ESP32 core v2.0.5)
* `ESP32-C3` Board type (e.g. ESP32C3_DEV Module, LOLIN_C3_MINI, DFROBOT_BEETLE_ESP32_C3, ADAFRUIT_QTPY_ESP32C3, AirM2M_CORE_ESP32C3, XIAO_ESP32C3, etc.)
* Contextual information (e.g. what you were trying to achieve)
* Simplest possible steps to reproduce
Expand All @@ -28,28 +28,50 @@ Please ensure to specify the following:

```
Arduino IDE version: 1.8.19
ESP32 Core Version v2.0.4
ESP32 core v2.0.5
ESP32C3_DEV Module
OS: Ubuntu 20.04 LTS
Linux xy-Inspiron-3593 5.15.0-41-generic #44~20.04.1-Ubuntu SMP Fri Jun 24 13:27:29 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 using TimerInterrupt.
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/ESP32_C3_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/ESP32_C3_TimerInterrupt_GitHub/
xy@xy-Inspiron-3593:~/Arduino/xy/ESP32_C3_TimerInterrupt_GitHub$
```

2. Issue astyle command

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

15 changes: 13 additions & 2 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@

[![arduino-library-badge](https://www.ardu-badge.com/badge/ESP32_C3_TimerInterrupt.svg?)](https://www.ardu-badge.com/ESP32_C3_TimerInterrupt)
[![GitHub release](https://img.shields.io/github/release/khoih-prog/ESP32_C3_TimerInterrupt.svg)](https://github.com/khoih-prog/ESP32_C3_TimerInterrupt/releases)
[![GitHub](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/khoih-prog/ESP32_C3_TimerInterrupt/blob/master/LICENSE)
[![GitHub](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/khoih-prog/ESP32_C3_TimerInterrupt/blob/main/LICENSE)
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](#Contributing)
[![GitHub issues](https://img.shields.io/github/issues/khoih-prog/ESP32_C3_TimerInterrupt.svg)](http://github.com/khoih-prog/ESP32_C3_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 khoih-prog 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-ESP32_C3_TimerInterrupt/count.svg" title="ESP32_C3_TimerInterrupt Visitor count"><img src="https://profile-counter.glitch.me/khoih-prog-ESP32_C3_TimerInterrupt/count.svg" style="height: 30px;width: 200px;"></a>

---
---

## Table of Contents

* [Changelog](#changelog)
* [Releases v1.8.0](#releases-v180)
* [Releases v1.7.0](#releases-v170)
* [Releases v1.6.0](#releases-v160)
* [Releases v1.5.0](#releases-v150)
Expand All @@ -23,11 +28,17 @@

## Changelog

### Releases v1.8.0

1. Fix doubled time for `ESP32_C3`. Check [Error in the value defined by TIMER0_INTERVAL_MS #28](https://github.com/khoih-prog/ESP32_C3_TimerInterrupt/issues/28)
2. Modify examples to avoid using `LED_BUILTIN` / `GPIO2`, `GPIO1` as it can cause crash in some boards, such as `ESP32_C3`
3. Use `allman astyle` and add `utils`

### Releases v1.7.0

1. Add support to
- ESP32_C3 : LOLIN_C3_MINI, DFROBOT_BEETLE_ESP32_C3, ADAFRUIT_QTPY_ESP32C3, AirM2M_CORE_ESP32C3, XIAO_ESP32C3

### Releases v1.6.0

1. Suppress errors and warnings for new ESP32 core v2.0.4+
Expand Down
111 changes: 58 additions & 53 deletions examples/Argument_None/Argument_None.ino
Original file line number Diff line number Diff line change
Expand Up @@ -46,35 +46,34 @@
// Can be included as many times as necessary, without `Multiple Definitions` Linker Error
#include "ESP32_C3_TimerInterrupt.h"

#ifndef LED_BUILTIN
#define LED_BUILTIN 2 // Pin D2 mapped to pin GPIO2/ADC12 of ESP32, control on-board LED
#endif

#define PIN_D1 1 // Pin D1 mapped to pin GPIO1 of ESP32-S2
// Don't use PIN_D3 in core v2.0.0 and v2.0.1. Check https://github.com/espressif/arduino-esp32/issues/5868
// Don't use PIN_D2 with ESP32_C3 (crash)
#define PIN_D39 19 // Pin D19 mapped to pin GPIO9 of ESP32
#define PIN_D3 3 // Pin D3 mapped to pin GPIO3/RX0 of ESP32

bool IRAM_ATTR TimerHandler0(void * timerNo)
{
static bool toggle0 = false;

//timer interrupt toggles pin LED_BUILTIN
digitalWrite(LED_BUILTIN, toggle0);
toggle0 = !toggle0;
return true;
{
static bool toggle0 = false;

//timer interrupt toggles pin PIN_D39
digitalWrite(PIN_D39, toggle0);
toggle0 = !toggle0;

return true;
}

bool IRAM_ATTR TimerHandler1(void * timerNo)
{
static bool toggle1 = false;
static bool toggle1 = false;

//timer interrupt toggles outputPin
digitalWrite(PIN_D1, toggle1);
toggle1 = !toggle1;
//timer interrupt toggles outputPin
digitalWrite(PIN_D3, toggle1);
toggle1 = !toggle1;

return true;
return true;
}

#define TIMER0_INTERVAL_MS 1000
#define TIMER0_INTERVAL_MS 100 //1000

#define TIMER1_INTERVAL_MS 5000

Expand All @@ -84,40 +83,46 @@ ESP32Timer ITimer1(1);

void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
pinMode(PIN_D1, OUTPUT);

Serial.begin(115200);
while (!Serial);

delay(100);

Serial.print(F("\nStarting Argument_None on ")); Serial.println(ARDUINO_BOARD);
Serial.println(ESP32_C3_TIMER_INTERRUPT_VERSION);
Serial.print(F("CPU Frequency = ")); Serial.print(F_CPU / 1000000); Serial.println(F(" MHz"));

// Using ESP32 => 80 / 160 / 240MHz CPU clock ,
// For 64-bit timer counter
// For 16-bit timer prescaler up to 1024

// Interval in microsecs
if (ITimer0.attachInterruptInterval(TIMER0_INTERVAL_MS * 1000, TimerHandler0))
//if (ITimer0.attachInterrupt(1, TimerHandler0))
{
Serial.print(F("Starting ITimer0 OK, millis() = ")); Serial.println(millis());
}
else
Serial.println(F("Can't set ITimer0. Select another Timer, freq. or timer"));


// Interval in microsecs
if (ITimer1.attachInterruptInterval(TIMER1_INTERVAL_MS * 1000, TimerHandler1))
//if (ITimer1.attachInterrupt(2, TimerHandler1))
{
Serial.print(F("Starting ITimer1 OK, millis() = ")); Serial.println(millis());
}
else
Serial.println(F("Can't set ITimer1. Select another Timer, freq. or timer"));
pinMode(PIN_D39, OUTPUT);
pinMode(PIN_D3, OUTPUT);

Serial.begin(115200);

while (!Serial && millis() < 5000);

delay(500);

Serial.print(F("\nStarting Argument_None on "));
Serial.println(ARDUINO_BOARD);
Serial.println(ESP32_C3_TIMER_INTERRUPT_VERSION);
Serial.print(F("CPU Frequency = "));
Serial.print(F_CPU / 1000000);
Serial.println(F(" MHz"));

// Using ESP32 => 80 / 160 / 240MHz CPU clock ,
// For 64-bit timer counter
// For 16-bit timer prescaler up to 1024

// Interval in microsecs
if (ITimer0.attachInterruptInterval(TIMER0_INTERVAL_MS * 1000, TimerHandler0))
//if (ITimer0.attachInterrupt(1, TimerHandler0))
{
Serial.print(F("Starting ITimer0 OK, millis() = "));
Serial.println(millis());
}
else
Serial.println(F("Can't set ITimer0. Select another Timer, freq. or timer"));


// Interval in microsecs
if (ITimer1.attachInterruptInterval(TIMER1_INTERVAL_MS * 1000, TimerHandler1))
//if (ITimer1.attachInterrupt(2, TimerHandler1))
{
Serial.print(F("Starting ITimer1 OK, millis() = "));
Serial.println(millis());
}
else
Serial.println(F("Can't set ITimer1. Select another Timer, freq. or timer"));
}

void loop()
Expand Down
Loading

0 comments on commit c593e91

Please sign in to comment.