Giter Club home page Giter Club logo

khoih-prog / timerinterrupt_generic Goto Github PK

View Code? Open in Web Editor NEW
37.0 5.0 5.0 1.71 MB

This library enables you to use Interrupt from Hardware Timers on supported Arduino boards such as AVR, ESP8266, ESP32, SAMD, SAM DUE, nRF52, Teensy, etc. These 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's 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'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.

License: MIT License

C++ 68.88% C 30.88% Shell 0.24%
esp32 esp8266 stm32 timer timer-interrupt hardware-timers isr interrupt accuracy non-blocking

timerinterrupt_generic's People

Contributors

khoih-prog avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

timerinterrupt_generic's Issues

Multiple Defintions error

Hi!

I'm trying to compile some code for Teensy 3.5 with PlatformIO 2.3.2, and I'm getting multiple definitions error.

I followed the procedure described in README, which sadly didn't work even though I cleaned the build environment and restarted VScode all the time.

Error message looks like this: link

I'm using Arch based linux distro:
Linux sz-81nh 5.11.14-arch1-1 #1 SMP PREEMPT Wed, 14 Apr 2021 12:06:34 +0000 x86_64 GNU/Linux

Also, the same code (the only difference being instead of TeensyTimer, I used STM32Timer) compiles and works perfectly on ST Nulceo F303RE

Steps to Reproduce

Minimal example: Teensy_minimal.zip

Expected behavior

Code compiles for Teensy

Actual behavior

Linker spews out a bunch of Multiple definitions error

Doesn't compile for nrf52 boards with Arduino IDE

Arduino: 1.8.15 (Mac OS X), Board: "Adafruit Feather nRF52840 Sense, S140 6.1.1, Level 0 (Release)"

/Users/NNL/Library/Arduino15/packages/adafruit/tools/arm-none-eabi-gcc/9-2019q4/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: sketch/TimerInterruptLEDDemo.ino.cpp.o: in function doingSomething1()': /var/folders/4p/g4vjjkm91599mvnrhgf992kw0000gp/T/arduino_modified_sketch_899459/TimerInterruptLEDDemo.ino:91: undefined reference to Serial'
/Users/NNL/Library/Arduino15/packages/adafruit/tools/arm-none-eabi-gcc/9-2019q4/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: sketch/TimerInterruptLEDDemo.ino.cpp.o: in function doingSomething2()': /var/folders/4p/g4vjjkm91599mvnrhgf992kw0000gp/T/arduino_modified_sketch_899459/TimerInterruptLEDDemo.ino:97: undefined reference to Serial'
/Users/NNL/Library/Arduino15/packages/adafruit/tools/arm-none-eabi-gcc/9-2019q4/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: sketch/TimerInterruptLEDDemo.ino.cpp.o: in function doingSomething3()': /var/folders/4p/g4vjjkm91599mvnrhgf992kw0000gp/T/arduino_modified_sketch_899459/TimerInterruptLEDDemo.ino:102: undefined reference to Serial'
/Users/NNL/Library/Arduino15/packages/adafruit/tools/arm-none-eabi-gcc/9-2019q4/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: sketch/TimerInterruptLEDDemo.ino.cpp.o: in function setup': /var/folders/4p/g4vjjkm91599mvnrhgf992kw0000gp/T/arduino_modified_sketch_899459/TimerInterruptLEDDemo.ino:107: undefined reference to Adafruit_USBD_CDC::begin(unsigned long)'
/Users/NNL/Library/Arduino15/packages/adafruit/tools/arm-none-eabi-gcc/9-2019q4/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: /var/folders/4p/g4vjjkm91599mvnrhgf992kw0000gp/T/arduino_modified_sketch_899459/TimerInterruptLEDDemo.ino:108: undefined reference to Adafruit_USBD_CDC::operator bool()' /Users/NNL/Library/Arduino15/packages/adafruit/tools/arm-none-eabi-gcc/9-2019q4/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: /var/folders/4p/g4vjjkm91599mvnrhgf992kw0000gp/T/arduino_modified_sketch_899459/TimerInterruptLEDDemo.ino:136: undefined reference to Serial'
/Users/NNL/Library/Arduino15/packages/adafruit/tools/arm-none-eabi-gcc/9-2019q4/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: sketch/TimerInterruptLEDDemo.ino.cpp.o: in function ISR_Timer::findFirstFreeSlot()': /Users/NNL/Documents/Arduino/libraries/TimerInterrupt_Generic/src/ISR_Timer-Impl_Generic.h:158: undefined reference to Serial'
collect2: error: ld returned 1 exit status
exit status 1
Error compiling for board Adafruit Feather nRF52840 Sense.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Use of the code should be more generic cross-platform.

It appears from the examples that even with the generic wrapper, the code still needs to be written to be quite specific to the platform. It should be possible , for at least simple cases, to be able to structure it in a way that the library can be used in a way where it requires no changes to compile and run on different platforms. There are, of course, challenges, as the different platforms have very different internal implementations...
I am starting on implementing this, but would like to discuss some of the things I have noticed in the current implementation that could cause issues with my ideas...

remove then reinstall?

when i initially came across this timer code i came across the rp2040 only version which has the archived github page, would it be recommended to remove that and install this?

also i see every where in the documentation that before using a timer you should see if it is used elsewhere , how do i go about doing that ?

PlatformIO and Heltec WiFi LoRa V2

Describe the bug

Seems i cannot make it compile because it cannot find some function. Googling for it does not reveal any help. I have no idea how to overcome this issue.

  • timer_isr_callback_add
  • TIMER_INTR_T0
  • TIMER_INTR_T1

Steps to Reproduce

Visual Studio Code 1.63.2 + PlatformIO Core 5.2.4. + ESP32 + #include "TimerInterrupt_Generic.h"

Expected behavior

Compile successfully

Actual behavior

Terminal output when compiling

Processing heltec_wifi_lora_32_V2 (platform: espressif32; board: heltec_wifi_lora_32_V2; framework: arduino)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via -v, --verbose option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/heltec_wifi_lora_32_V2.html
PLATFORM: Espressif 32 (3.4.0) > Heltec WiFi LoRa 32 (V2)
HARDWARE: ESP32 240MHz, 320KB RAM, 8MB Flash
DEBUG: Current (esp-prog) External (esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES:

  • framework-arduinoespressif32 3.10006.210326 (1.0.6)
  • tool-esptoolpy 1.30100.210531 (3.1.0)
  • toolchain-xtensa32 2.50200.97 (5.2.0)
    LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
    LDF Modes: Finder ~ chain, Compatibility ~ strict
    Found 45 compatible libraries
    Scanning dependencies...
    Dependency Graph
    |-- 1.1.0
    | |-- 1.0
    | |-- 1.0.1
    |-- <TimerInterrupt_Generic> 1.8.0
    |-- 1.18
    |-- 1.0.5
    |-- 1.0
    |-- 2.31.2
    | |-- 1.0
    | |-- 1.0.1
    |-- 1.0.1
    |-- 1.4
    Building in release mode
    Compiling .pio\build\heltec_wifi_lora_32_V2\src\WeckerDeluxe.cpp.o
    In file included from .pio\libdeps\heltec_wifi_lora_32_V2\TimerInterrupt_Generic\src/TimerInterrupt_Generic.h:221:0,
    from src\WeckerDeluxe.cpp:38:
    .pio\libdeps\heltec_wifi_lora_32_V2\TimerInterrupt_Generic\src/ESP32TimerInterrupt_Generic.h:90:22: warning: "/" within comment [-Wcomment]
    TIMER_GROUP_0 = 0, /
    !<Hw timer group 0
    ^
    .pio\libdeps\heltec_wifi_lora_32_V2\TimerInterrupt_Generic\src/ESP32TimerInterrupt_Generic.h:91:22: warning: "/" within comment [-Wcomment]
    TIMER_GROUP_1 = 1, /
    !<Hw timer group 1
    ^
    .pio\libdeps\heltec_wifi_lora_32_V2\TimerInterrupt_Generic\src/ESP32TimerInterrupt_Generic.h:100:16: warning: "/" within comment [-Wcomment]
    TIMER_0 = 0, /
    !<Select timer0 of GROUPx
    ^
    .pio\libdeps\heltec_wifi_lora_32_V2\TimerInterrupt_Generic\src/ESP32TimerInterrupt_Generic.h:101:16: warning: "/" within comment [-Wcomment]
    TIMER_1 = 1, /
    !<Select timer1 of GROUPx
    ^
    Compiling .pio\build\heltec_wifi_lora_32_V2\libda1\U8g2\clib\u8g2_message.c.o
    Compiling .pio\build\heltec_wifi_lora_32_V2\libda1\U8g2\clib\u8g2_polygon.c.o
    Compiling .pio\build\heltec_wifi_lora_32_V2\libda1\U8g2\clib\u8g2_selection_list.c.o
    In file included from .pio\libdeps\heltec_wifi_lora_32_V2\TimerInterrupt_Generic\src/TimerInterrupt_Generic.h:221:0,
    from src\WeckerDeluxe.cpp:38:
    .pio\libdeps\heltec_wifi_lora_32_V2\TimerInterrupt_Generic\src/ESP32TimerInterrupt_Generic.h: In member function 'bool ESP32TimerInterrupt::setFrequency(float, esp32_timer_callback)':
    .pio\libdeps\heltec_wifi_lora_32_V2\TimerInterrupt_Generic\src/ESP32TimerInterrupt_Generic.h:307:100: error: 'timer_isr_callback_add' was not declared in this scope
    timer_isr_callback_add(_timerGroup, _timerIndex, _callback, (void *) (uint32_t) _timerNo, 0);
    ^
    .pio\libdeps\heltec_wifi_lora_32_V2\TimerInterrupt_Generic\src/ESP32TimerInterrupt_Generic.h: In member function 'void ESP32TimerInterrupt::detachInterrupt()':
    .pio\libdeps\heltec_wifi_lora_32_V2\TimerInterrupt_Generic\src/ESP32TimerInterrupt_Generic.h:349:66: error: 'TIMER_INTR_T0' was not declared in this scope
    timer_group_intr_disable(_timerGroup, (_timerIndex == 0) ? TIMER_INTR_T0 : TIMER_INTR_T1);
    ^
    .pio\libdeps\heltec_wifi_lora_32_V2\TimerInterrupt_Generic\src/ESP32TimerInterrupt_Generic.h:349:82: error: 'TIMER_INTR_T1' was not declared in this scope
    timer_group_intr_disable(_timerGroup, (_timerIndex == 0) ? TIMER_INTR_T0 : TIMER_INTR_T1);
    ^
    .pio\libdeps\heltec_wifi_lora_32_V2\TimerInterrupt_Generic\src/ESP32TimerInterrupt_Generic.h: In member function 'void ESP32TimerInterrupt::disableTimer()':
    .pio\libdeps\heltec_wifi_lora_32_V2\TimerInterrupt_Generic\src/ESP32TimerInterrupt_Generic.h:358:66: error: 'TIMER_INTR_T0' was not declared in this scope
    timer_group_intr_disable(_timerGroup, (_timerIndex == 0) ? TIMER_INTR_T0 : TIMER_INTR_T1);
    ^
    .pio\libdeps\heltec_wifi_lora_32_V2\TimerInterrupt_Generic\src/ESP32TimerInterrupt_Generic.h:358:82: error: 'TIMER_INTR_T1' was not declared in this scope
    timer_group_intr_disable(_timerGroup, (_timerIndex == 0) ? TIMER_INTR_T0 : TIMER_INTR_T1);
    ^
    .pio\libdeps\heltec_wifi_lora_32_V2\TimerInterrupt_Generic\src/ESP32TimerInterrupt_Generic.h: In member function 'void ESP32TimerInterrupt::reattachInterrupt()':
    .pio\libdeps\heltec_wifi_lora_32_V2\TimerInterrupt_Generic\src/ESP32TimerInterrupt_Generic.h:368:65: error: 'TIMER_INTR_T0' was not declared in this scope
    timer_group_intr_enable(_timerGroup, (_timerIndex == 0) ? TIMER_INTR_T0 : TIMER_INTR_T1);
    ^
    .pio\libdeps\heltec_wifi_lora_32_V2\TimerInterrupt_Generic\src/ESP32TimerInterrupt_Generic.h:368:81: error: 'TIMER_INTR_T1' was not declared in this scope
    timer_group_intr_enable(_timerGroup, (_timerIndex == 0) ? TIMER_INTR_T0 : TIMER_INTR_T1);
    ^
    .pio\libdeps\heltec_wifi_lora_32_V2\TimerInterrupt_Generic\src/ESP32TimerInterrupt_Generic.h: In member function 'void ESP32TimerInterrupt::enableTimer()':
    .pio\libdeps\heltec_wifi_lora_32_V2\TimerInterrupt_Generic\src/ESP32TimerInterrupt_Generic.h:378:65: error: 'TIMER_INTR_T0' was not declared in this scope
    timer_group_intr_enable(_timerGroup, (_timerIndex == 0) ? TIMER_INTR_T0 : TIMER_INTR_T1);
    ^
    .pio\libdeps\heltec_wifi_lora_32_V2\TimerInterrupt_Generic\src/ESP32TimerInterrupt_Generic.h:378:81: error: 'TIMER_INTR_T1' was not declared in this scope
    timer_group_intr_enable(_timerGroup, (_timerIndex == 0) ? TIMER_INTR_T0 : TIMER_INTR_T1);
    ^
    Compiling .pio\build\heltec_wifi_lora_32_V2\libda1\U8g2\clib\u8g2_setup.c.o
    Compiling .pio\build\heltec_wifi_lora_32_V2\libda1\U8g2\clib\u8log.c.o
    Compiling .pio\build\heltec_wifi_lora_32_V2\libda1\U8g2\clib\u8log_u8g2.c.o
    Compiling .pio\build\heltec_wifi_lora_32_V2\libda1\U8g2\clib\u8log_u8x8.c.o
    Compiling .pio\build\heltec_wifi_lora_32_V2\libda1\U8g2\clib\u8x8_8x8.c.o
    Compiling .pio\build\heltec_wifi_lora_32_V2\libda1\U8g2\clib\u8x8_byte.c.o
    Compiling .pio\build\heltec_wifi_lora_32_V2\libda1\U8g2\clib\u8x8_cad.c.o
    Compiling .pio\build\heltec_wifi_lora_32_V2\libda1\U8g2\clib\u8x8_capture.c.o
    Compiling .pio\build\heltec_wifi_lora_32_V2\libda1\U8g2\clib\u8x8_d_a2printer.c.o
    Compiling .pio\build\heltec_wifi_lora_32_V2\libda1\U8g2\clib\u8x8_d_hd44102.c.o
    Compiling .pio\build\heltec_wifi_lora_32_V2\libda1\U8g2\clib\u8x8_d_il3820_296x128.c.o
    Compiling .pio\build\heltec_wifi_lora_32_V2\libda1\U8g2\clib\u8x8_d_ist3020.c.o
    Compiling .pio\build\heltec_wifi_lora_32_V2\libda1\U8g2\clib\u8x8_d_ist7920.c.o
    Compiling .pio\build\heltec_wifi_lora_32_V2\libda1\U8g2\clib\u8x8_d_ks0108.c.o
    Compiling .pio\build\heltec_wifi_lora_32_V2\libda1\U8g2\clib\u8x8_d_lc7981.c.o
    Compiling .pio\build\heltec_wifi_lora_32_V2\libda1\U8g2\clib\u8x8_d_ld7032_60x32.c.o
    Compiling .pio\build\heltec_wifi_lora_32_V2\libda1\U8g2\clib\u8x8_d_ls013b7dh03.c.o
    Compiling .pio\build\heltec_wifi_lora_32_V2\libda1\U8g2\clib\u8x8_d_max7219.c.o
    Compiling .pio\build\heltec_wifi_lora_32_V2\libda1\U8g2\clib\u8x8_d_pcd8544_84x48.c.o
    Compiling .pio\build\heltec_wifi_lora_32_V2\libda1\U8g2\clib\u8x8_d_pcf8812.c.o
    Compiling .pio\build\heltec_wifi_lora_32_V2\libda1\U8g2\clib\u8x8_d_pcf8814_hx1230.c.o
    Compiling .pio\build\heltec_wifi_lora_32_V2\libda1\U8g2\clib\u8x8_d_s1d15721.c.o
    Compiling .pio\build\heltec_wifi_lora_32_V2\libda1\U8g2\clib\u8x8_d_s1d15e06.c.o
    C:\Users\mic\Documents\Arduino\libraries\U8g2\src\clib\u8x8_d_s1d15721.c: In function 'u8x8_d_s1d15721_common':
    C:\Users\mic\Documents\Arduino\libraries\U8g2\src\clib\u8x8_d_s1d15721.c:71:14: warning: variable 'y' set but not used [-Wunused-but-set-variable]
    uint8_t x, y, c;
    ^
    Compiling .pio\build\heltec_wifi_lora_32_V2\libda1\U8g2\clib\u8x8_d_sbn1661.c.o
    Compiling .pio\build\heltec_wifi_lora_32_V2\libda1\U8g2\clib\u8x8_d_sed1330.c.o
    Compiling .pio\build\heltec_wifi_lora_32_V2\libda1\U8g2\clib\u8x8_d_sh1106_64x32.c.o
    *** [.pio\build\heltec_wifi_lora_32_V2\src\WeckerDeluxe.cpp.o] Error 1

Screenshots

If applicable, add screenshots to help explain your problem.

Information

Please ensure to specify the following:
Visual Studio Code 1.63.2 + PlatformIO Core 5.2.4. + ESP32

  • Platform.io Core 5.2.4.
  • ESP32 (heltecautomation/Heltec ESP32 Dev-Boards@^1.1.0)
  • Windows 10 64bit

Example

#if !defined( ESP32 )
  #error This code is intended to run on the ESP32 platform! Please check your Tools->Board setting.
#endif

#include "Arduino.h"
#include "heltec.h"   // WiFi LoRa 32 (V2)

// The Timer for the different things
// These define's must be placed at the beginning before #include "ESP32_New_TimerInterrupt.h"
// _TIMERINTERRUPT_LOGLEVEL_ from 0 to 4
#define _TIMERINTERRUPT_LOGLEVEL_     0
#include "TimerInterrupt_Generic.h"

Additional context

; platformio.ini
[env:heltec_wifi_lora_32_V2]
platform = espressif32
board = heltec_wifi_lora_32_V2
board_build.mcu = esp32
board_build.f_cpu = 240000000L
framework = arduino
lib_extra_dirs = ~/Documents/Arduino/libraries
upload_port = COM8
lib_compat_mode = strict
lib_deps =
heltecautomation/Heltec ESP32 Dev-Boards@^1.1.0
khoih-prog/TimerInterrupt_Generic@^1.8.0

Support for DX CORE CPU and MightyCORE CPU possible?

Is your feature request related to a problem? Please describe.

As alter part AVR DA DB DD and modern ATtiny CPU are interesting to use
DX CORE is closed to MEGACOREX.

Describe the solution you'd like

Support generic timer mode like ATMEGA4809 CPU for new CPU (ATTINY series 0 1 () 2 and AVR DA DB (DD?)

Describe alternatives you've considered

none existing or adjustment for supporting new parts

Additional context

Put a look at DX CORE lib and mithtycore from Spence Konde.

Thanks in advan,ce t consider benefits of enlargment copatibility CPU supported.

Regards
Laurent

Timer STM32 #error This code is designed to run on STM32F/L/H/G/WB/MP1 platform! Please check your Tools->Board setting.

I have installed the library of TimerInterrupt_Generic for ArduinoSTM32 module via Arduino IDE, so i have tried to test the example of library as you can see below:

enter image description here
and i have gotten this error:




TimerInterruptLEDDemo:45:4: error: #error This code is designed to run on STM32F/L/H/G/WB/MP1 platform! Please check your Tools->Board setting.
   #error This code is designed to run on STM32F/L/H/G/WB/MP1 platform! Please check your Tools->Board setting.
    ^
In file included from /home/so/snap/arduino/current/Arduino/libraries/TimerInterrupt_Generic/examples/STM32/TimerInterruptLEDDemo/TimerInterruptLEDDemo.ino:64:0:
/home/so/snap/arduino/current/Arduino/libraries/TimerInterrupt_Generic/src/TimerInterrupt_Generic.h:86:4: error: #error Unsupported Board! Please check your Tools->Board setting.
   #error Unsupported Board! Please check your Tools->Board setting.
    ^
exit status 1
#error This code is designed to run on STM32F/L/H/G/WB/MP1 platform! Please check your Tools->Board setting.

Also, This question is asked here:
https://arduino.stackexchange.com/questions/79638/timer-stm32-error-this-code-is-designed-to-run-on-stm32f-l-h-g-wb-mp1-platform

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.