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

Commit

Permalink
v1.1.2 using float for interval
Browse files Browse the repository at this point in the history
### Releases v1.1.2

1. Using `float` instead of `ulong` for interval for better accuracy
  • Loading branch information
khoih-prog authored Sep 30, 2022
1 parent 473b61d commit 72a9d11
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 49 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Arduino IDE version: 1.8.19
Arduino mbed_rp2040 core v3.3.0
RASPBERRY_PI_PICO board
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
Expand Down
29 changes: 15 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ The current library implementation, using `xyz-Impl.h` instead of standard `xyz.

You can include these `.hpp` files

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

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

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

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

Expand Down Expand Up @@ -230,7 +230,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 MBED_RPI_PICO_Timer
MBED_RPI_PICO_Timer ITimer1(1);
Expand All @@ -240,7 +240,7 @@ MBED_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);
Expand All @@ -250,7 +250,7 @@ bool attachInterruptInterval(unsigned long interval, pico_timer_callback callbac

as follows

```
```C++
// Never use Serial.print inside this mbed ISR. Will hang the system
void TimerHandler(uint alarm_num)
{
Expand Down Expand Up @@ -278,7 +278,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)
Expand All @@ -288,7 +288,7 @@ bool attachInterrupt(float frequency, timer_callback callback);

as follows

```
```C++
// Never use Serial.print inside this mbed ISR. Will hang the system
void TimerHandler(uint alarm_num)
{
Expand Down Expand Up @@ -331,7 +331,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 MBED_RPI_PICO_Timer
MBED_RPI_PICO_Timer ITimer1(1);
Expand All @@ -342,7 +342,7 @@ MBED_RPI_PICO_ISR_Timer ISR_timer;

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

```
```C++
// Never use Serial.print inside this mbed ISR. Will hang the system
void TimerHandler(uint alarm_num)
{
Expand Down Expand Up @@ -445,7 +445,7 @@ While software timer, **programmed for 2s, is activated after more than 10.000s
```
Starting ISR_Timers_Array_Simple on RaspberryPi Pico
MBED_RPi_Pico_TimerInterrupt v1.1.1
MBED_RPi_Pico_TimerInterrupt v1.1.2
[TISR] _timerNo = 1, Clock (Hz) = 1000000.00, _fre (Hz) = 1000.00
[TISR] _count = 0-1000
[TISR] hardware_alarm_set_target, uS = 1000
Expand All @@ -469,7 +469,7 @@ The following is the sample terminal output when running example [TimerInterrupt
```
Starting TimerInterruptTest on RaspberryPi Pico
MBED_RPi_Pico_TimerInterrupt v1.1.1
MBED_RPi_Pico_TimerInterrupt v1.1.2
[TISR] _timerNo = 0, Clock (Hz) = 1000000.00, _fre (Hz) = 1.00
[TISR] _count = 0-1000000
[TISR] hardware_alarm_set_target, uS = 1000000
Expand Down Expand Up @@ -497,7 +497,7 @@ The following is the sample terminal output when running example [Change_Interva
```
Starting Change_Interval on RaspberryPi Pico
MBED_RPi_Pico_TimerInterrupt v1.1.1
MBED_RPi_Pico_TimerInterrupt v1.1.2
[TISR] _timerNo = 0, Clock (Hz) = 1000000.00, _fre (Hz) = 0.50
[TISR] _count = 0-2000000
[TISR] hardware_alarm_set_target, uS = 2000000
Expand Down Expand Up @@ -535,7 +535,7 @@ The following is the sample terminal output when running example [SwitchDebounce
```
Starting SwitchDebounce on RaspberryPi Pico
MBED_RPi_Pico_TimerInterrupt v1.1.1
MBED_RPi_Pico_TimerInterrupt v1.1.2
[TISR] _timerNo = 1, Clock (Hz) = 1000000.00, _fre (Hz) = 1000.00
[TISR] _count = 0-1000
[TISR] hardware_alarm_set_target, uS = 1000
Expand Down Expand Up @@ -569,7 +569,7 @@ The following is the sample terminal output when running example [ISR_16_Timers_
```
Starting ISR_16_Timers_Array_Complex on RaspberryPi Pico
MBED_RPi_Pico_TimerInterrupt v1.1.1
MBED_RPi_Pico_TimerInterrupt v1.1.2
[TISR] _timerNo = 0, Clock (Hz) = 1000000.00, _fre (Hz) = 100.00
[TISR] _count = 0-10000
[TISR] hardware_alarm_set_target, uS = 10000
Expand Down Expand Up @@ -779,6 +779,7 @@ Submit issues to: [MBED_RPI_PICO_TimerInterrupt issues](https://github.com/khoih
5. Add Table of Contents
6. Fix `multiple-definitions` linker error
7. Optimize library code by using `reference-passing` instead of `value-passing`
8. Using `float` instead of `ulong` for interval for better accuracy

---
---
Expand Down
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
## Table of Contents

* [Changelog](#changelog)
* [Releases v1.1.2](#releases-v112)
* [Releases v1.1.1](#releases-v111)
* [Releases v1.1.0](#releases-v110)
* [Releases v1.0.1](#releases-v101)
Expand All @@ -22,6 +23,10 @@

## Changelog

### Releases v1.1.2

1. Using `float` instead of `ulong` for interval for better accuracy

### Releases v1.1.1

1. Remove redundant function call
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "MBED_RPI_PICO_TimerInterrupt",
"version": "1.1.1",
"version": "1.1.2",
"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",
"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.",
"authors":
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=MBED_RPI_PICO_TimerInterrupt
version=1.1.1
version=1.1.2
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 Nano_RP2040_Connect, RASPBERRY_PI_PICO
Expand Down
19 changes: 10 additions & 9 deletions src/MBED_RPi_Pico_ISR_Timer-Impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@
Based on BlynkTimer.h
Author: Volodymyr Shymanskyy
Version: 1.1.1
Version: 1.1.2
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.0 K Hoang 07/06/2021 Initial coding to support MBED RP2040-based boards such as RASPBERRY_PI_PICO. etc.
1.0.1 K Hoang 22/10/2021 Fix platform in library.json for PIO
1.1.0 K.Hoang 22/01/2022 Fix `multiple-definitions` linker error
1.1.1 K.Hoang 25/09/2022 Remove redundant function call
1.1.2 K.Hoang 25/09/2022 Using float instead of ulong for interval
*****************************************************************************************************************************/

#pragma once
Expand Down Expand Up @@ -158,7 +159,7 @@ int MBED_RPI_PICO_ISR_Timer::findFirstFreeSlot()
}


int MBED_RPI_PICO_ISR_Timer::setupTimer(const unsigned long& d, void* f, void* p, bool h, const unsigned& n)
int MBED_RPI_PICO_ISR_Timer::setupTimer(const float& d, void* f, void* p, bool h, const unsigned& n)
{
int freeTimer;

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


int MBED_RPI_PICO_ISR_Timer::setTimer(const unsigned long& d, timer_callback f, const unsigned& n)
int MBED_RPI_PICO_ISR_Timer::setTimer(const float& d, timer_callback f, const unsigned& n)
{
return setupTimer(d, (void *)f, NULL, false, n);
}

int MBED_RPI_PICO_ISR_Timer::setTimer(const unsigned long& d, timer_callback_p f, void* p, const unsigned& n)
int MBED_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 MBED_RPI_PICO_ISR_Timer::setInterval(const unsigned long& d, timer_callback f)
int MBED_RPI_PICO_ISR_Timer::setInterval(const float& d, timer_callback f)
{
return setupTimer(d, (void *)f, NULL, false, RPI_PICO_RUN_FOREVER);
}

int MBED_RPI_PICO_ISR_Timer::setInterval(const unsigned long& d, timer_callback_p f, void* p)
int MBED_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 MBED_RPI_PICO_ISR_Timer::setTimeout(const unsigned long& d, timer_callback f)
int MBED_RPI_PICO_ISR_Timer::setTimeout(const float& d, timer_callback f)
{
return setupTimer(d, (void *)f, NULL, false, RPI_PICO_RUN_ONCE);
}

int MBED_RPI_PICO_ISR_Timer::setTimeout(const unsigned long& d, timer_callback_p f, void* p)
int MBED_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 MBED_RPI_PICO_ISR_Timer::changeInterval(const unsigned& numTimer, const unsigned long& d)
bool MBED_RPI_PICO_ISR_Timer::changeInterval(const unsigned& numTimer, const float& d)
{
if (numTimer >= RPI_PICO_MAX_TIMERS)
{
Expand Down
3 changes: 2 additions & 1 deletion src/MBED_RPi_Pico_ISR_Timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@
Based on BlynkTimer.h
Author: Volodymyr Shymanskyy
Version: 1.1.1
Version: 1.1.2
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.0 K Hoang 07/06/2021 Initial coding to support MBED RP2040-based boards such as RASPBERRY_PI_PICO. etc.
1.0.1 K Hoang 22/10/2021 Fix platform in library.json for PIO
1.1.0 K.Hoang 22/01/2022 Fix `multiple-definitions` linker error
1.1.1 K.Hoang 25/09/2022 Remove redundant function call
1.1.2 K.Hoang 25/09/2022 Using float instead of ulong for interval
*****************************************************************************************************************************/

#pragma once
Expand Down
31 changes: 17 additions & 14 deletions src/MBED_RPi_Pico_ISR_Timer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@
Based on BlynkTimer.h
Author: Volodymyr Shymanskyy
Version: 1.1.1
Version: 1.1.2
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.0 K Hoang 07/06/2021 Initial coding to support MBED RP2040-based boards such as RASPBERRY_PI_PICO. etc.
1.0.1 K Hoang 22/10/2021 Fix platform in library.json for PIO
1.1.0 K.Hoang 22/01/2022 Fix `multiple-definitions` linker error
1.1.1 K.Hoang 25/09/2022 Remove redundant function call
1.1.2 K.Hoang 25/09/2022 Using float instead of ulong for interval
*****************************************************************************************************************************/

#pragma once
Expand All @@ -42,19 +43,21 @@

#if ( defined(ARDUINO_NANO_RP2040_CONNECT) || defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) || \
defined(ARDUINO_GENERIC_RP2040) ) && defined(ARDUINO_ARCH_MBED)
#warning Using MBED RASPBERRY_PI_PICO platform
#if(_TIMERINTERRUPT_LOGLEVEL_>3)
#warning Using MBED RASPBERRY_PI_PICO platform
#endif
#else
#error This code is intended to run on the MBED RASPBERRY_PI_PICO platform! Please check your Tools->Board setting.
#endif

#ifndef MBED_RPI_PICO_TIMER_INTERRUPT_VERSION
#define MBED_RPI_PICO_TIMER_INTERRUPT_VERSION "MBED_RPi_Pico_TimerInterrupt v1.1.1"
#define MBED_RPI_PICO_TIMER_INTERRUPT_VERSION "MBED_RPi_Pico_TimerInterrupt v1.1.2"

#define MBED_RPI_PICO_TIMER_INTERRUPT_VERSION_MAJOR 1
#define MBED_RPI_PICO_TIMER_INTERRUPT_VERSION_MINOR 1
#define MBED_RPI_PICO_TIMER_INTERRUPT_VERSION_PATCH 1
#define MBED_RPI_PICO_TIMER_INTERRUPT_VERSION_PATCH 2

#define MBED_RPI_PICO_TIMER_INTERRUPT_VERSION_INT 1001001
#define MBED_RPI_PICO_TIMER_INTERRUPT_VERSION_INT 1001002
#endif

#include "Arduino.h"
Expand Down Expand Up @@ -100,35 +103,35 @@ class MBED_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);
Expand Down Expand Up @@ -172,7 +175,7 @@ class MBED_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();
Expand All @@ -183,7 +186,7 @@ class MBED_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
Expand Down
3 changes: 2 additions & 1 deletion src/MBED_RPi_Pico_TimerInterrupt.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@
Based on BlynkTimer.h
Author: Volodymyr Shymanskyy
Version: 1.1.1
Version: 1.1.2
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.0 K Hoang 07/06/2021 Initial coding to support MBED RP2040-based boards such as RASPBERRY_PI_PICO. etc.
1.0.1 K Hoang 22/10/2021 Fix platform in library.json for PIO
1.1.0 K.Hoang 22/01/2022 Fix `multiple-definitions` linker error
1.1.1 K.Hoang 25/09/2022 Remove redundant function call
1.1.2 K.Hoang 25/09/2022 Using float instead of ulong for interval
*****************************************************************************************************************************/

#pragma once
Expand Down
Loading

0 comments on commit 72a9d11

Please sign in to comment.