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

Commit 72a9d11

Browse files
authored
v1.1.2 using float for interval
### Releases v1.1.2 1. Using `float` instead of `ulong` for interval for better accuracy
1 parent 473b61d commit 72a9d11

11 files changed

+63
-49
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Arduino IDE version: 1.8.19
3131
Arduino mbed_rp2040 core v3.3.0
3232
RASPBERRY_PI_PICO board
3333
OS: Ubuntu 20.04 LTS
34-
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
34+
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
3535
3636
Context:
3737
I encountered a crash while using this library

README.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ The current library implementation, using `xyz-Impl.h` instead of standard `xyz.
176176

177177
You can include these `.hpp` files
178178

179-
```
179+
```C++
180180
// Can be included as many times as necessary, without `Multiple Definitions` Linker Error
181181
#include "MBED_RPi_Pico_TimerInterrupt.hpp" //https://github.com/khoih-prog/MBED_RPI_PICO_TimerInterrupt
182182

@@ -186,7 +186,7 @@ You can include these `.hpp` files
186186

187187
in many files. But be sure to use the following `.h` files **in just 1 `.h`, `.cpp` or `.ino` file**, which must **not be included in any other file**, to avoid `Multiple Definitions` Linker Error
188188

189-
```
189+
```C++
190190
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
191191
#include "MBED_RPi_Pico_TimerInterrupt.h" //https://github.com/khoih-prog/MBED_RPI_PICO_TimerInterrupt
192192

@@ -230,7 +230,7 @@ Before using any Timer, you have to make sure the Timer has not been used by any
230230

231231
### 1.1 Init Hardware Timer
232232

233-
```
233+
```C++
234234
// Select the timer you're using, from ITimer0(0)-ITimer3(3)
235235
// Init MBED_RPI_PICO_Timer
236236
MBED_RPI_PICO_Timer ITimer1(1);
@@ -240,7 +240,7 @@ MBED_RPI_PICO_Timer ITimer1(1);
240240
241241
Use one of these functions with **interval in unsigned long microseconds**
242242
243-
```
243+
```C++
244244
// interval (in us), callback is ISR
245245
bool setInterval(unsigned long interval, pico_timer_callback callback);
246246
@@ -250,7 +250,7 @@ bool attachInterruptInterval(unsigned long interval, pico_timer_callback callbac
250250

251251
as follows
252252

253-
```
253+
```C++
254254
// Never use Serial.print inside this mbed ISR. Will hang the system
255255
void TimerHandler(uint alarm_num)
256256
{
@@ -278,7 +278,7 @@ void setup()
278278
279279
Use one of these functions with **frequency in float Hz**
280280
281-
```
281+
```C++
282282
// frequency (in Hz), callback is ISR
283283
bool setFrequency(float frequency, pico_timer_callback callback)
284284
@@ -288,7 +288,7 @@ bool attachInterrupt(float frequency, timer_callback callback);
288288

289289
as follows
290290

291-
```
291+
```C++
292292
// Never use Serial.print inside this mbed ISR. Will hang the system
293293
void TimerHandler(uint alarm_num)
294294
{
@@ -331,7 +331,7 @@ The 16 ISR_based Timers, designed for long timer intervals, only support using *
331331
332332
### 2.2 Init Hardware Timer and ISR-based Timer
333333
334-
```
334+
```C++
335335
// Init MBED_RPI_PICO_Timer
336336
MBED_RPI_PICO_Timer ITimer1(1);
337337
@@ -342,7 +342,7 @@ MBED_RPI_PICO_ISR_Timer ISR_timer;
342342

343343
### 2.3 Set Hardware Timer Interval and attach Timer Interrupt Handler functions
344344

345-
```
345+
```C++
346346
// Never use Serial.print inside this mbed ISR. Will hang the system
347347
void TimerHandler(uint alarm_num)
348348
{
@@ -445,7 +445,7 @@ While software timer, **programmed for 2s, is activated after more than 10.000s
445445
446446
```
447447
Starting ISR_Timers_Array_Simple on RaspberryPi Pico
448-
MBED_RPi_Pico_TimerInterrupt v1.1.1
448+
MBED_RPi_Pico_TimerInterrupt v1.1.2
449449
[TISR] _timerNo = 1, Clock (Hz) = 1000000.00, _fre (Hz) = 1000.00
450450
[TISR] _count = 0-1000
451451
[TISR] hardware_alarm_set_target, uS = 1000
@@ -469,7 +469,7 @@ The following is the sample terminal output when running example [TimerInterrupt
469469
470470
```
471471
Starting TimerInterruptTest on RaspberryPi Pico
472-
MBED_RPi_Pico_TimerInterrupt v1.1.1
472+
MBED_RPi_Pico_TimerInterrupt v1.1.2
473473
[TISR] _timerNo = 0, Clock (Hz) = 1000000.00, _fre (Hz) = 1.00
474474
[TISR] _count = 0-1000000
475475
[TISR] hardware_alarm_set_target, uS = 1000000
@@ -497,7 +497,7 @@ The following is the sample terminal output when running example [Change_Interva
497497
498498
```
499499
Starting Change_Interval on RaspberryPi Pico
500-
MBED_RPi_Pico_TimerInterrupt v1.1.1
500+
MBED_RPi_Pico_TimerInterrupt v1.1.2
501501
[TISR] _timerNo = 0, Clock (Hz) = 1000000.00, _fre (Hz) = 0.50
502502
[TISR] _count = 0-2000000
503503
[TISR] hardware_alarm_set_target, uS = 2000000
@@ -535,7 +535,7 @@ The following is the sample terminal output when running example [SwitchDebounce
535535
536536
```
537537
Starting SwitchDebounce on RaspberryPi Pico
538-
MBED_RPi_Pico_TimerInterrupt v1.1.1
538+
MBED_RPi_Pico_TimerInterrupt v1.1.2
539539
[TISR] _timerNo = 1, Clock (Hz) = 1000000.00, _fre (Hz) = 1000.00
540540
[TISR] _count = 0-1000
541541
[TISR] hardware_alarm_set_target, uS = 1000
@@ -569,7 +569,7 @@ The following is the sample terminal output when running example [ISR_16_Timers_
569569
570570
```
571571
Starting ISR_16_Timers_Array_Complex on RaspberryPi Pico
572-
MBED_RPi_Pico_TimerInterrupt v1.1.1
572+
MBED_RPi_Pico_TimerInterrupt v1.1.2
573573
[TISR] _timerNo = 0, Clock (Hz) = 1000000.00, _fre (Hz) = 100.00
574574
[TISR] _count = 0-10000
575575
[TISR] hardware_alarm_set_target, uS = 10000
@@ -779,6 +779,7 @@ Submit issues to: [MBED_RPI_PICO_TimerInterrupt issues](https://github.com/khoih
779779
5. Add Table of Contents
780780
6. Fix `multiple-definitions` linker error
781781
7. Optimize library code by using `reference-passing` instead of `value-passing`
782+
8. Using `float` instead of `ulong` for interval for better accuracy
782783

783784
---
784785
---

changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
## Table of Contents
1313

1414
* [Changelog](#changelog)
15+
* [Releases v1.1.2](#releases-v112)
1516
* [Releases v1.1.1](#releases-v111)
1617
* [Releases v1.1.0](#releases-v110)
1718
* [Releases v1.0.1](#releases-v101)
@@ -22,6 +23,10 @@
2223

2324
## Changelog
2425

26+
### Releases v1.1.2
27+
28+
1. Using `float` instead of `ulong` for interval for better accuracy
29+
2530
### Releases v1.1.1
2631

2732
1. Remove redundant function call

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "MBED_RPI_PICO_TimerInterrupt",
3-
"version": "1.1.1",
3+
"version": "1.1.2",
44
"keywords": "timing, device, control, timer, interrupt, hardware, isr, isr-based, hardware-timer, mission-critical, accuracy, precise, non-blocking, mbed, mbed-rp2040, nano-rp2040-connect, raspberry-pico, rpi-pico, pico, rp2040",
55
"description": "This library enables you to use Interrupt from Hardware Timers on MBED RP2040-based boards such as Nano_RP2040_Connect, 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.",
66
"authors":

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=MBED_RPI_PICO_TimerInterrupt
2-
version=1.1.1
2+
version=1.1.2
33
author=Khoi Hoang <khoih.prog@gmail.com>
44
maintainer=Khoi Hoang <khoih.prog@gmail.com>
55
sentence=This library enables you to use Interrupt from Hardware Timers on RP2040-based boards such as Nano_RP2040_Connect, RASPBERRY_PI_PICO

src/MBED_RPi_Pico_ISR_Timer-Impl.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@
2525
Based on BlynkTimer.h
2626
Author: Volodymyr Shymanskyy
2727
28-
Version: 1.1.1
28+
Version: 1.1.2
2929
3030
Version Modified By Date Comments
3131
------- ----------- ---------- -----------
3232
1.0.0 K Hoang 07/06/2021 Initial coding to support MBED RP2040-based boards such as RASPBERRY_PI_PICO. etc.
3333
1.0.1 K Hoang 22/10/2021 Fix platform in library.json for PIO
3434
1.1.0 K.Hoang 22/01/2022 Fix `multiple-definitions` linker error
3535
1.1.1 K.Hoang 25/09/2022 Remove redundant function call
36+
1.1.2 K.Hoang 25/09/2022 Using float instead of ulong for interval
3637
*****************************************************************************************************************************/
3738

3839
#pragma once
@@ -158,7 +159,7 @@ int MBED_RPI_PICO_ISR_Timer::findFirstFreeSlot()
158159
}
159160

160161

161-
int MBED_RPI_PICO_ISR_Timer::setupTimer(const unsigned long& d, void* f, void* p, bool h, const unsigned& n)
162+
int MBED_RPI_PICO_ISR_Timer::setupTimer(const float& d, void* f, void* p, bool h, const unsigned& n)
162163
{
163164
int freeTimer;
164165

@@ -192,37 +193,37 @@ int MBED_RPI_PICO_ISR_Timer::setupTimer(const unsigned long& d, void* f, void* p
192193
}
193194

194195

195-
int MBED_RPI_PICO_ISR_Timer::setTimer(const unsigned long& d, timer_callback f, const unsigned& n)
196+
int MBED_RPI_PICO_ISR_Timer::setTimer(const float& d, timer_callback f, const unsigned& n)
196197
{
197198
return setupTimer(d, (void *)f, NULL, false, n);
198199
}
199200

200-
int MBED_RPI_PICO_ISR_Timer::setTimer(const unsigned long& d, timer_callback_p f, void* p, const unsigned& n)
201+
int MBED_RPI_PICO_ISR_Timer::setTimer(const float& d, timer_callback_p f, void* p, const unsigned& n)
201202
{
202203
return setupTimer(d, (void *)f, p, true, n);
203204
}
204205

205-
int MBED_RPI_PICO_ISR_Timer::setInterval(const unsigned long& d, timer_callback f)
206+
int MBED_RPI_PICO_ISR_Timer::setInterval(const float& d, timer_callback f)
206207
{
207208
return setupTimer(d, (void *)f, NULL, false, RPI_PICO_RUN_FOREVER);
208209
}
209210

210-
int MBED_RPI_PICO_ISR_Timer::setInterval(const unsigned long& d, timer_callback_p f, void* p)
211+
int MBED_RPI_PICO_ISR_Timer::setInterval(const float& d, timer_callback_p f, void* p)
211212
{
212213
return setupTimer(d, (void *)f, p, true, RPI_PICO_RUN_FOREVER);
213214
}
214215

215-
int MBED_RPI_PICO_ISR_Timer::setTimeout(const unsigned long& d, timer_callback f)
216+
int MBED_RPI_PICO_ISR_Timer::setTimeout(const float& d, timer_callback f)
216217
{
217218
return setupTimer(d, (void *)f, NULL, false, RPI_PICO_RUN_ONCE);
218219
}
219220

220-
int MBED_RPI_PICO_ISR_Timer::setTimeout(const unsigned long& d, timer_callback_p f, void* p)
221+
int MBED_RPI_PICO_ISR_Timer::setTimeout(const float& d, timer_callback_p f, void* p)
221222
{
222223
return setupTimer(d, (void *)f, p, true, RPI_PICO_RUN_ONCE);
223224
}
224225

225-
bool MBED_RPI_PICO_ISR_Timer::changeInterval(const unsigned& numTimer, const unsigned long& d)
226+
bool MBED_RPI_PICO_ISR_Timer::changeInterval(const unsigned& numTimer, const float& d)
226227
{
227228
if (numTimer >= RPI_PICO_MAX_TIMERS)
228229
{

src/MBED_RPi_Pico_ISR_Timer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@
2525
Based on BlynkTimer.h
2626
Author: Volodymyr Shymanskyy
2727
28-
Version: 1.1.1
28+
Version: 1.1.2
2929
3030
Version Modified By Date Comments
3131
------- ----------- ---------- -----------
3232
1.0.0 K Hoang 07/06/2021 Initial coding to support MBED RP2040-based boards such as RASPBERRY_PI_PICO. etc.
3333
1.0.1 K Hoang 22/10/2021 Fix platform in library.json for PIO
3434
1.1.0 K.Hoang 22/01/2022 Fix `multiple-definitions` linker error
3535
1.1.1 K.Hoang 25/09/2022 Remove redundant function call
36+
1.1.2 K.Hoang 25/09/2022 Using float instead of ulong for interval
3637
*****************************************************************************************************************************/
3738

3839
#pragma once

src/MBED_RPi_Pico_ISR_Timer.hpp

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@
2525
Based on BlynkTimer.h
2626
Author: Volodymyr Shymanskyy
2727
28-
Version: 1.1.1
28+
Version: 1.1.2
2929
3030
Version Modified By Date Comments
3131
------- ----------- ---------- -----------
3232
1.0.0 K Hoang 07/06/2021 Initial coding to support MBED RP2040-based boards such as RASPBERRY_PI_PICO. etc.
3333
1.0.1 K Hoang 22/10/2021 Fix platform in library.json for PIO
3434
1.1.0 K.Hoang 22/01/2022 Fix `multiple-definitions` linker error
3535
1.1.1 K.Hoang 25/09/2022 Remove redundant function call
36+
1.1.2 K.Hoang 25/09/2022 Using float instead of ulong for interval
3637
*****************************************************************************************************************************/
3738

3839
#pragma once
@@ -42,19 +43,21 @@
4243

4344
#if ( defined(ARDUINO_NANO_RP2040_CONNECT) || defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || \
4445
defined(ARDUINO_GENERIC_RP2040) ) && defined(ARDUINO_ARCH_MBED)
45-
#warning Using MBED RASPBERRY_PI_PICO platform
46+
#if(_TIMERINTERRUPT_LOGLEVEL_>3)
47+
#warning Using MBED RASPBERRY_PI_PICO platform
48+
#endif
4649
#else
4750
#error This code is intended to run on the MBED RASPBERRY_PI_PICO platform! Please check your Tools->Board setting.
4851
#endif
4952

5053
#ifndef MBED_RPI_PICO_TIMER_INTERRUPT_VERSION
51-
#define MBED_RPI_PICO_TIMER_INTERRUPT_VERSION "MBED_RPi_Pico_TimerInterrupt v1.1.1"
54+
#define MBED_RPI_PICO_TIMER_INTERRUPT_VERSION "MBED_RPi_Pico_TimerInterrupt v1.1.2"
5255

5356
#define MBED_RPI_PICO_TIMER_INTERRUPT_VERSION_MAJOR 1
5457
#define MBED_RPI_PICO_TIMER_INTERRUPT_VERSION_MINOR 1
55-
#define MBED_RPI_PICO_TIMER_INTERRUPT_VERSION_PATCH 1
58+
#define MBED_RPI_PICO_TIMER_INTERRUPT_VERSION_PATCH 2
5659

57-
#define MBED_RPI_PICO_TIMER_INTERRUPT_VERSION_INT 1001001
60+
#define MBED_RPI_PICO_TIMER_INTERRUPT_VERSION_INT 1001002
5861
#endif
5962

6063
#include "Arduino.h"
@@ -100,35 +103,35 @@ class MBED_RPI_PICO_ISR_Timer
100103
// Timer will call function 'f' every 'd' milliseconds forever
101104
// returns the timer number (numTimer) on success or
102105
// -1 on failure (f == NULL) or no free timers
103-
int setInterval(const unsigned long& d, timer_callback f);
106+
int setInterval(const float& d, timer_callback f);
104107

105108
// Timer will call function 'f' with parameter 'p' every 'd' milliseconds forever
106109
// returns the timer number (numTimer) on success or
107110
// -1 on failure (f == NULL) or no free timers
108-
int setInterval(const unsigned long& d, timer_callback_p f, void* p);
111+
int setInterval(const float& d, timer_callback_p f, void* p);
109112

110113
// Timer will call function 'f' after 'd' milliseconds one time
111114
// returns the timer number (numTimer) on success or
112115
// -1 on failure (f == NULL) or no free timers
113-
int setTimeout(const unsigned long& d, timer_callback f);
116+
int setTimeout(const float& d, timer_callback f);
114117

115118
// Timer will call function 'f' with parameter 'p' after 'd' milliseconds one time
116119
// returns the timer number (numTimer) on success or
117120
// -1 on failure (f == NULL) or no free timers
118-
int setTimeout(const unsigned long& d, timer_callback_p f, void* p);
121+
int setTimeout(const float& d, timer_callback_p f, void* p);
119122

120123
// Timer will call function 'f' every 'd' milliseconds 'n' times
121124
// returns the timer number (numTimer) on success or
122125
// -1 on failure (f == NULL) or no free timers
123-
int setTimer(const unsigned long& d, timer_callback f, const unsigned& n);
126+
int setTimer(const float& d, timer_callback f, const unsigned& n);
124127

125128
// Timer will call function 'f' with parameter 'p' every 'd' milliseconds 'n' times
126129
// returns the timer number (numTimer) on success or
127130
// -1 on failure (f == NULL) or no free timers
128-
int setTimer(const unsigned long& d, timer_callback_p f, void* p, const unsigned& n);
131+
int setTimer(const float& d, timer_callback_p f, void* p, const unsigned& n);
129132

130133
// updates interval of the specified timer
131-
bool changeInterval(const unsigned& numTimer, const unsigned long& d);
134+
bool changeInterval(const unsigned& numTimer, const float& d);
132135

133136
// destroy the specified timer
134137
void deleteTimer(const unsigned& numTimer);
@@ -172,7 +175,7 @@ class MBED_RPI_PICO_ISR_Timer
172175
// low level function to initialize and enable a new timer
173176
// returns the timer number (numTimer) on success or
174177
// -1 on failure (f == NULL) or no free timers
175-
int setupTimer(const unsigned long& d, void* f, void* p, bool h, const unsigned& n);
178+
int setupTimer(const float& d, void* f, void* p, bool h, const unsigned& n);
176179

177180
// find the first available slot
178181
int findFirstFreeSlot();
@@ -183,7 +186,7 @@ class MBED_RPI_PICO_ISR_Timer
183186
void* callback; // pointer to the callback function
184187
void* param; // function parameter
185188
bool hasParam; // true if callback takes a parameter
186-
unsigned long delay; // delay value
189+
float delay; // delay value
187190
unsigned maxNumRuns; // number of runs to be executed
188191
unsigned numRuns; // number of executed runs
189192
bool enabled; // true if enabled

src/MBED_RPi_Pico_TimerInterrupt.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@
2626
Based on BlynkTimer.h
2727
Author: Volodymyr Shymanskyy
2828
29-
Version: 1.1.1
29+
Version: 1.1.2
3030
3131
Version Modified By Date Comments
3232
------- ----------- ---------- -----------
3333
1.0.0 K Hoang 07/06/2021 Initial coding to support MBED RP2040-based boards such as RASPBERRY_PI_PICO. etc.
3434
1.0.1 K Hoang 22/10/2021 Fix platform in library.json for PIO
3535
1.1.0 K.Hoang 22/01/2022 Fix `multiple-definitions` linker error
3636
1.1.1 K.Hoang 25/09/2022 Remove redundant function call
37+
1.1.2 K.Hoang 25/09/2022 Using float instead of ulong for interval
3738
*****************************************************************************************************************************/
3839

3940
#pragma once

0 commit comments

Comments
 (0)