v1.3.1 using float for interval

### Releases v1.3.1

1. Using `float` instead of `ulong` for better interval accuracy
This commit is contained in:
Khoi Hoang
2022-09-29 22:06:10 -04:00
committed by GitHub
parent b7d8f4b4b7
commit 6b319e531f
10 changed files with 71 additions and 60 deletions
+1 -1
View File
@@ -31,7 +31,7 @@ Arduino IDE version: 1.8.19
RP2040 core v2.5.4
RASPBERRY_PI_PICO Module
OS: Ubuntu 20.04 LTS
Linux xy-Inspiron-3593 5.15.0-46-generic #49~20.04.1-Ubuntu SMP Thu Aug 4 19:15:44 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Linux xy-Inspiron-3593 5.15.0-48-generic #54~20.04.1-Ubuntu SMP Thu Sep 1 16:17:26 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Context:
I encountered a crash while using this library
+28 -27
View File
@@ -220,7 +220,7 @@ The current library implementation, using `xyz-Impl.h` instead of standard `xyz.
You can include these `.hpp` or `.h` files
```
```C++
// Can be included as many times as necessary, without `Multiple Definitions` Linker Error
#include "RPi_Pico_TimerInterrupt.h" //https://github.com/khoih-prog/RPI_PICO_TimerInterrupt
@@ -230,7 +230,7 @@ You can include these `.hpp` or `.h` files
in many files. But be sure to use the following `.h` file **in just 1 `.h`, `.cpp` or `.ino` file**, which must **not be included in any other file**, to avoid `Multiple Definitions` Linker Error
```
```C++
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
#include "RPi_Pico_ISR_Timer.h" //https://github.com/khoih-prog/RPI_PICO_TimerInterrupt
```
@@ -271,7 +271,7 @@ Before using any Timer, you have to make sure the Timer has not been used by any
### 1.1 Init Hardware Timer
```
```C++
// Select the timer you're using, from ITimer0(0)-ITimer3(3)
// Init RPI_PICO_Timer
RPI_PICO_Timer ITimer1(1);
@@ -281,7 +281,7 @@ RPI_PICO_Timer ITimer1(1);
Use one of these functions with **interval in unsigned long microseconds**
```
```C++
// interval (in us), callback is ISR
bool setInterval(unsigned long interval, pico_timer_callback callback);
@@ -291,7 +291,7 @@ bool attachInterruptInterval(unsigned long interval, pico_timer_callback callbac
as follows
```
```C++
void TimerHandler()
{
// Doing something here inside ISR
@@ -318,7 +318,7 @@ void setup()
Use one of these functions with **frequency in float Hz**
```
```C++
// frequency (in Hz), callback is ISR
bool setFrequency(float frequency, pico_timer_callback callback)
@@ -328,7 +328,7 @@ bool attachInterrupt(float frequency, timer_callback callback);
as follows
```
```C++
void TimerHandler()
{
// Doing something here inside ISR
@@ -360,7 +360,7 @@ The 16 ISR_based Timers, designed for long timer intervals, only support using *
### 2.2 Init Hardware Timer and ISR-based Timer
```
```C++
// Init RPI_PICO_Timer
RPI_PICO_Timer ITimer1(1);
@@ -371,7 +371,7 @@ RPI_PICO_ISR_Timer ISR_timer;
### 2.3 Set Hardware Timer Interval and attach Timer Interrupt Handler functions
```
```C++
void TimerHandler()
{
ISR_timer.run();
@@ -448,7 +448,7 @@ void setup()
### Example [ISR_Timers_Array_Simple](examples/ISR_Timers_Array_Simple)
https://github.com/khoih-prog/RPI_PICO_TimerInterrupt/blob/f2ca9ced6ef985653cb234a3268b237b0fa257f1/examples/ISR_Timers_Array_Simple/ISR_Timers_Array_Simple.ino#L23-L166
https://github.com/khoih-prog/RPI_PICO_TimerInterrupt/blob/b7d8f4b4b7eabec8c140fc55d88efb82939a6ad6/examples/ISR_Timers_Array_Simple/ISR_Timers_Array_Simple.ino#L23-L168
---
---
@@ -462,9 +462,8 @@ The following is the sample terminal output when running example [ISR_Timers_Arr
While software timer, **programmed for 2s, is activated after more than 10.000s !!!**
```
Starting ISR_Timers_Array_Simple on RASPBERRY_PI_PICO
RPi_Pico_TimerInterrupt v1.3.0
RPi_Pico_TimerInterrupt v1.3.1
CPU Frequency = 125 MHz
[TISR] _timerNo = 1, Clock (Hz) = 1000000.00, _fre (Hz) = 1000.00
[TISR] _count = 0-1000
@@ -489,7 +488,7 @@ The following is the sample terminal output when running example [TimerInterrupt
```
Starting TimerInterruptTest on RASPBERRY_PI_PICO
RPi_Pico_TimerInterrupt v1.3.0
RPi_Pico_TimerInterrupt v1.3.1
CPU Frequency = 125 MHz
[TISR] _timerNo = 0, Clock (Hz) = 1000000.00, _fre (Hz) = 1.00
[TISR] _count = 0-1000000
@@ -533,7 +532,7 @@ The following is the sample terminal output when running example [Change_Interva
```
Starting Change_Interval on RASPBERRY_PI_PICO
RPi_Pico_TimerInterrupt v1.3.0
RPi_Pico_TimerInterrupt v1.3.1
CPU Frequency = 125 MHz
[TISR] _timerNo = 0, Clock (Hz) = 1000000.00, _fre (Hz) = 0.50
[TISR] _count = 0-2000000
@@ -614,7 +613,7 @@ The following is the sample terminal output when running example [SwitchDebounce
```
Starting SwitchDebounce on RASPBERRY_PI_PICO
RPi_Pico_TimerInterrupt v1.3.0
RPi_Pico_TimerInterrupt v1.3.1
CPU Frequency = 125 MHz
[TISR] _timerNo = 1, Clock (Hz) = 1000000.00, _fre (Hz) = 50.00
[TISR] _count = 0-20000
@@ -639,7 +638,7 @@ The following is the sample terminal output when running example [ISR_Timers_Arr
```
Starting ISR_Timers_Array_Simple on RASPBERRY_PI_PICO
RPi_Pico_TimerInterrupt v1.3.0
RPi_Pico_TimerInterrupt v1.3.1
CPU Frequency = 125 MHz
[TISR] _timerNo = 1, Clock (Hz) = 1000000.00, _fre (Hz) = 1000.00
[TISR] _count = 0-1000
@@ -662,7 +661,7 @@ The following is the sample terminal output when running example [ISR_16_Timers_
```
Starting ISR_16_Timers_Array_Complex on RASPBERRY_PI_PICO
RPi_Pico_TimerInterrupt v1.3.0
RPi_Pico_TimerInterrupt v1.3.1
CPU Frequency = 125 MHz
[TISR] _timerNo = 1, Clock (Hz) = 1000000.00, _fre (Hz) = 100.00
[TISR] _count = 0-10000
@@ -815,7 +814,7 @@ Debug is enabled by default on Serial.
You can also change the debugging level (_TIMERINTERRUPT_LOGLEVEL_) from 0 to 4
```cpp
```C++
// These define's must be placed at the beginning before #include "RPI_PICO_TimerInterrupt.h"
// _TIMERINTERRUPT_LOGLEVEL_ from 0 to 4
// Don't define _TIMERINTERRUPT_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system.
@@ -850,15 +849,17 @@ Submit issues to: [RPI_PICO_TimerInterrupt issues](https://github.com/khoih-prog
## DONE
1. Basic hardware timers for **RP2040-based boards such as RASPBERRY_PI_PICO**, using [**Earle Philhower's arduino-pico** core](https://github.com/earlephilhower/arduino-pico)
2. More hardware-initiated software-enabled timers
3. Longer time interval
4. Add Version String
5. Add Table of Contents
6. Add support to new boards (**ADAFRUIT_ITSYBITSY_RP2040, ADAFRUIT_QTPY_RP2040, ADAFRUIT_STEMMAFRIEND_RP2040, ADAFRUIT_TRINKEYQT_RP2040, ADAFRUIT_MACROPAD_RP2040, SPARKFUN_PROMICRO_RP2040, Nano_RP2040_Connect, etc.**) using the arduino-pico core
7. Fix `multiple-definitions` linker error
8. Optimize library code by using `reference-passing` instead of `value-passing`
9. Fix severe bug affecting time between the starts. Check [Enable fixed timing between timer calls (vs fixed time btw. end of timer call and next call as implemented) #3](https://github.com/khoih-prog/RPI_PICO_TimerInterrupt/issues/3)
1. Basic hardware timers for **RP2040-based boards such as RASPBERRY_PI_PICO**, using [**Earle Philhower's arduino-pico** core](https://github.com/earlephilhower/arduino-pico)
2. More hardware-initiated software-enabled timers
3. Longer time interval
4. Add Version String
5. Add Table of Contents
6. Add support to new boards (**ADAFRUIT_ITSYBITSY_RP2040, ADAFRUIT_QTPY_RP2040, ADAFRUIT_STEMMAFRIEND_RP2040, ADAFRUIT_TRINKEYQT_RP2040, ADAFRUIT_MACROPAD_RP2040, SPARKFUN_PROMICRO_RP2040, Nano_RP2040_Connect, etc.**) using the arduino-pico core
7. Fix `multiple-definitions` linker error
8. Optimize library code by using `reference-passing` instead of `value-passing`
9. Fix severe bug affecting time between the starts. Check [Enable fixed timing between timer calls (vs fixed time btw. end of timer call and next call as implemented) #3](https://github.com/khoih-prog/RPI_PICO_TimerInterrupt/issues/3)
10. Using `float` instead of `ulong` for better interval accuracy
---
---
+5
View File
@@ -12,6 +12,7 @@
## Table of Contents
* [Changelog](#changelog)
* [Releases v1.3.1](#releases-v131)
* [Releases v1.3.0](#releases-v130)
* [Releases v1.2.0](#releases-v120)
* [Releases v1.1.1](#releases-v111)
@@ -25,6 +26,10 @@
## Changelog
### Releases v1.3.1
1. Using `float` instead of `ulong` for better interval accuracy
### Releases v1.3.0
1. Fix severe bug affecting time between the starts. Check [Enable fixed timing between timer calls (vs fixed time btw. end of timer call and next call as implemented) #3](https://github.com/khoih-prog/RPI_PICO_TimerInterrupt/issues/3)
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "RPI_PICO_TimerInterrupt",
"version": "1.3.0",
"version": "1.3.1",
"keywords": "timing, device, control, timer, interrupt, hardware, isr, isr-based, hardware-timer, mission-critical, accuracy, non-blocking, raspberry-pico, rpi-pico, pico, rp2040, arduino-pico, rp2040w, raspberry-pico-w, pico-w",
"description": "This library enables you to use Interrupt from Hardware Timers on RP2040-based boards such as RASPBERRY_PI_PICO. 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. 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 necessary if you need to measure some data requiring better accuracy.",
"authors":
+1 -1
View File
@@ -1,5 +1,5 @@
name=RPI_PICO_TimerInterrupt
version=1.3.0
version=1.3.1
author=Khoi Hoang <khoih.prog@gmail.com>
maintainer=Khoi Hoang <khoih.prog@gmail.com>
sentence=This library enables you to use Interrupt from Hardware Timers on RP2040-based boards such as RASPBERRY_PI_PICO
+10 -9
View File
@@ -25,7 +25,7 @@
Based on BlynkTimer.h
Author: Volodymyr Shymanskyy
Version: 1.3.0
Version: 1.3.1
Version Modified By Date Comments
------- ----------- ---------- -----------
@@ -35,6 +35,7 @@
1.1.1 K Hoang 22/10/2021 Fix platform in library.json for PIO
1.2.0 K.Hoang 21/01/2022 Fix `multiple-definitions` linker error
1.3.0 K.Hoang 25/09/2022 Fix severe bug affecting time between the starts
1.3.1 K.Hoang 29/09/2022 Using float instead of ulong for interval
*****************************************************************************************************************************/
#pragma once
@@ -170,7 +171,7 @@ int RPI_PICO_ISR_Timer::findFirstFreeSlot()
////////////////////////////////////////////////////////////////
int RPI_PICO_ISR_Timer::setupTimer(const unsigned long& d, void* f, void* p, bool h, const unsigned& n)
int RPI_PICO_ISR_Timer::setupTimer(const float& d, void* f, void* p, bool h, const unsigned& n)
{
int freeTimer;
@@ -205,49 +206,49 @@ int RPI_PICO_ISR_Timer::setupTimer(const unsigned long& d, void* f, void* p, boo
////////////////////////////////////////////////////////////////
int RPI_PICO_ISR_Timer::setTimer(const unsigned long& d, timer_callback f, const unsigned& n)
int RPI_PICO_ISR_Timer::setTimer(const float& d, timer_callback f, const unsigned& n)
{
return setupTimer(d, (void *)f, NULL, false, n);
}
////////////////////////////////////////////////////////////////
int RPI_PICO_ISR_Timer::setTimer(const unsigned long& d, timer_callback_p f, void* p, const unsigned& n)
int RPI_PICO_ISR_Timer::setTimer(const float& d, timer_callback_p f, void* p, const unsigned& n)
{
return setupTimer(d, (void *)f, p, true, n);
}
////////////////////////////////////////////////////////////////
int RPI_PICO_ISR_Timer::setInterval(const unsigned long& d, timer_callback f)
int RPI_PICO_ISR_Timer::setInterval(const float& d, timer_callback f)
{
return setupTimer(d, (void *)f, NULL, false, RPI_PICO_RUN_FOREVER);
}
////////////////////////////////////////////////////////////////
int RPI_PICO_ISR_Timer::setInterval(const unsigned long& d, timer_callback_p f, void* p)
int RPI_PICO_ISR_Timer::setInterval(const float& d, timer_callback_p f, void* p)
{
return setupTimer(d, (void *)f, p, true, RPI_PICO_RUN_FOREVER);
}
////////////////////////////////////////////////////////////////
int RPI_PICO_ISR_Timer::setTimeout(const unsigned long& d, timer_callback f)
int RPI_PICO_ISR_Timer::setTimeout(const float& d, timer_callback f)
{
return setupTimer(d, (void *)f, NULL, false, RPI_PICO_RUN_ONCE);
}
////////////////////////////////////////////////////////////////
int RPI_PICO_ISR_Timer::setTimeout(const unsigned long& d, timer_callback_p f, void* p)
int RPI_PICO_ISR_Timer::setTimeout(const float& d, timer_callback_p f, void* p)
{
return setupTimer(d, (void *)f, p, true, RPI_PICO_RUN_ONCE);
}
////////////////////////////////////////////////////////////////
bool RPI_PICO_ISR_Timer::changeInterval(const unsigned& numTimer, const unsigned long& d)
bool RPI_PICO_ISR_Timer::changeInterval(const unsigned& numTimer, const float& d)
{
if (numTimer >= RPI_PICO_MAX_TIMERS)
{
+2 -1
View File
@@ -25,7 +25,7 @@
Based on BlynkTimer.h
Author: Volodymyr Shymanskyy
Version: 1.3.0
Version: 1.3.1
Version Modified By Date Comments
------- ----------- ---------- -----------
@@ -35,6 +35,7 @@
1.1.1 K Hoang 22/10/2021 Fix platform in library.json for PIO
1.2.0 K.Hoang 21/01/2022 Fix `multiple-definitions` linker error
1.3.0 K.Hoang 25/09/2022 Fix severe bug affecting time between the starts
1.3.1 K.Hoang 29/09/2022 Using float instead of ulong for interval
*****************************************************************************************************************************/
#pragma once
+14 -13
View File
@@ -25,7 +25,7 @@
Based on BlynkTimer.h
Author: Volodymyr Shymanskyy
Version: 1.3.0
Version: 1.3.1
Version Modified By Date Comments
------- ----------- ---------- -----------
@@ -35,6 +35,7 @@
1.1.1 K Hoang 22/10/2021 Fix platform in library.json for PIO
1.2.0 K.Hoang 21/01/2022 Fix `multiple-definitions` linker error
1.3.0 K.Hoang 25/09/2022 Fix severe bug affecting time between the starts
1.3.1 K.Hoang 29/09/2022 Using float instead of ulong for interval
*****************************************************************************************************************************/
#pragma once
@@ -56,13 +57,13 @@
////////////////////////////////////////////////////////////////
#ifndef RPI_PICO_TIMER_INTERRUPT_VERSION
#define RPI_PICO_TIMER_INTERRUPT_VERSION "RPi_Pico_TimerInterrupt v1.3.0"
#define RPI_PICO_TIMER_INTERRUPT_VERSION "RPi_Pico_TimerInterrupt v1.3.1"
#define RPI_PICO_TIMER_INTERRUPT_VERSION_MAJOR 1
#define RPI_PICO_TIMER_INTERRUPT_VERSION_MINOR 3
#define RPI_PICO_TIMER_INTERRUPT_VERSION_PATCH 0
#define RPI_PICO_TIMER_INTERRUPT_VERSION_PATCH 1
#define RPI_PICO_TIMER_INTERRUPT_VERSION_INT 1003000
#define RPI_PICO_TIMER_INTERRUPT_VERSION_INT 1003001
#endif
////////////////////////////////////////////////////////////////
@@ -111,35 +112,35 @@ class RPI_PICO_ISR_Timer
// Timer will call function 'f' every 'd' milliseconds forever
// returns the timer number (numTimer) on success or
// -1 on failure (f == NULL) or no free timers
int setInterval(const unsigned long& d, timer_callback f);
int setInterval(const float& d, timer_callback f);
// Timer will call function 'f' with parameter 'p' every 'd' milliseconds forever
// returns the timer number (numTimer) on success or
// -1 on failure (f == NULL) or no free timers
int setInterval(const unsigned long& d, timer_callback_p f, void* p);
int setInterval(const float& d, timer_callback_p f, void* p);
// Timer will call function 'f' after 'd' milliseconds one time
// returns the timer number (numTimer) on success or
// -1 on failure (f == NULL) or no free timers
int setTimeout(const unsigned long& d, timer_callback f);
int setTimeout(const float& d, timer_callback f);
// Timer will call function 'f' with parameter 'p' after 'd' milliseconds one time
// returns the timer number (numTimer) on success or
// -1 on failure (f == NULL) or no free timers
int setTimeout(const unsigned long& d, timer_callback_p f, void* p);
int setTimeout(const float& d, timer_callback_p f, void* p);
// Timer will call function 'f' every 'd' milliseconds 'n' times
// returns the timer number (numTimer) on success or
// -1 on failure (f == NULL) or no free timers
int setTimer(const unsigned long& d, timer_callback f, const unsigned& n);
int setTimer(const float& d, timer_callback f, const unsigned& n);
// Timer will call function 'f' with parameter 'p' every 'd' milliseconds 'n' times
// returns the timer number (numTimer) on success or
// -1 on failure (f == NULL) or no free timers
int setTimer(const unsigned long& d, timer_callback_p f, void* p, const unsigned& n);
int setTimer(const float& d, timer_callback_p f, void* p, const unsigned& n);
// updates interval of the specified timer
bool changeInterval(const unsigned& numTimer, const unsigned long& d);
bool changeInterval(const unsigned& numTimer, const float& d);
// destroy the specified timer
void deleteTimer(const unsigned& numTimer);
@@ -183,7 +184,7 @@ class RPI_PICO_ISR_Timer
// low level function to initialize and enable a new timer
// returns the timer number (numTimer) on success or
// -1 on failure (f == NULL) or no free timers
int setupTimer(const unsigned long& d, void* f, void* p, bool h, const unsigned& n);
int setupTimer(const float& d, void* f, void* p, bool h, const unsigned& n);
// find the first available slot
int findFirstFreeSlot();
@@ -194,7 +195,7 @@ class RPI_PICO_ISR_Timer
void* callback; // pointer to the callback function
void* param; // function parameter
bool hasParam; // true if callback takes a parameter
unsigned long delay; // delay value
float delay; // delay value
unsigned maxNumRuns; // number of runs to be executed
unsigned numRuns; // number of executed runs
bool enabled; // true if enabled
+7 -6
View File
@@ -26,7 +26,7 @@
Based on BlynkTimer.h
Author: Volodymyr Shymanskyy
Version: 1.3.0
Version: 1.3.1
Version Modified By Date Comments
------- ----------- ---------- -----------
@@ -36,6 +36,7 @@
1.1.1 K Hoang 22/10/2021 Fix platform in library.json for PIO
1.2.0 K.Hoang 21/01/2022 Fix `multiple-definitions` linker error
1.3.0 K.Hoang 25/09/2022 Fix severe bug affecting time between the starts
1.3.1 K.Hoang 29/09/2022 Using float instead of ulong for interval
*****************************************************************************************************************************/
#pragma once
@@ -55,13 +56,13 @@
////////////////////////////////////////////////////////////////
#ifndef RPI_PICO_TIMER_INTERRUPT_VERSION
#define RPI_PICO_TIMER_INTERRUPT_VERSION "RPi_Pico_TimerInterrupt v1.3.0"
#define RPI_PICO_TIMER_INTERRUPT_VERSION "RPi_Pico_TimerInterrupt v1.3.1"
#define RPI_PICO_TIMER_INTERRUPT_VERSION_MAJOR 1
#define RPI_PICO_TIMER_INTERRUPT_VERSION_MINOR 3
#define RPI_PICO_TIMER_INTERRUPT_VERSION_PATCH 0
#define RPI_PICO_TIMER_INTERRUPT_VERSION_PATCH 1
#define RPI_PICO_TIMER_INTERRUPT_VERSION_INT 1003000
#define RPI_PICO_TIMER_INTERRUPT_VERSION_INT 1003001
#endif
////////////////////////////////////////////////////////////////
@@ -182,7 +183,7 @@ class RPI_PICO_TimerInterrupt
// interval (in microseconds) and duration (in milliseconds). Duration = 0 or not specified => run indefinitely
// No params and duration now. To be added in the future by adding similar functions here
bool setInterval(const unsigned long& interval, pico_timer_callback callback)
bool setInterval(const float& interval, pico_timer_callback callback)
{
return setFrequency((float) (1000000.0f / interval), callback);
}
@@ -198,7 +199,7 @@ class RPI_PICO_TimerInterrupt
// interval (in microseconds) and duration (in milliseconds). Duration = 0 or not specified => run indefinitely
// No params and duration now. To be added in the future by adding similar functions here
bool attachInterruptInterval(const unsigned long& interval, pico_timer_callback callback)
bool attachInterruptInterval(const float& interval, pico_timer_callback callback)
{
return setFrequency( (float) ( 1000000.0f / interval), callback);
}
+2 -1
View File
@@ -25,7 +25,7 @@
Based on BlynkTimer.h
Author: Volodymyr Shymanskyy
Version: 1.3.0
Version: 1.3.1
Version Modified By Date Comments
------- ----------- ---------- -----------
@@ -35,6 +35,7 @@
1.1.1 K Hoang 22/10/2021 Fix platform in library.json for PIO
1.2.0 K.Hoang 21/01/2022 Fix `multiple-definitions` linker error
1.3.0 K.Hoang 25/09/2022 Fix severe bug affecting time between the starts
1.3.1 K.Hoang 29/09/2022 Using float instead of ulong for interval
*****************************************************************************************************************************/
#pragma once