- Important Change from v1.1.0
- Why do we need this MBED_RPI_PICO_TimerInterrupt library
- Changelog
- Prerequisites
- Installation
- HOWTO Fix
Multiple Definitions
Linker Error - More useful Information
- Usage
- Examples
- Example ISR_Timers_Array_Simple
- Debug Terminal Output Samples
- Debug
- Troubleshooting
- Issues
- TO DO
- DONE
- Contributions and Thanks
- Contributing
- License
- Copyright
Please have a look at HOWTO Fix Multiple Definitions
Linker Error
Why do we need this MBED_RPI_PICO_TimerInterrupt library
This library enables you to use Interrupt from Hardware Timers on MBED RP2040-based boards such as Nano_RP2040_Connect, RASPBERRY_PI_PICO, using Arduino-mbed RP2040 core
As Hardware Timers are rare, and very precious assets of any board, this library now enables you to use up to 16 ISR-based Timers, while consuming only 1 Hardware Timer. Timers' interval is very long (ulong millisecs).
Now with these new 16 ISR-based timers, the maximum interval is practically unlimited (limited only by unsigned long milliseconds) while the accuracy is nearly perfect compared to software timers.
The most important feature is they're ISR-based timers. Therefore, their executions are not blocked by bad-behaving functions / tasks. This important feature is absolutely necessary for mission-critical tasks.
The ISR_16_Timers_Array_Complex example will demonstrate the nearly perfect accuracy compared to software timers by printing the actual elapsed millisecs of each type of timers.
Being ISR-based timers, their executions are not blocked by bad-behaving functions / tasks, such as connecting to WiFi, Internet and Blynk services. You can also have many (up to 16)
timers to use.
This non-being-blocked important feature is absolutely necessary for mission-critical tasks.
You'll see blynkTimer Software is blocked while system is connecting to WiFi / Internet / Blynk, as well as by blocking task
in loop()
, using delay() function as an example. The elapsed time then is very unaccurate
Imagine you have a system with a mission-critical function, measuring water level and control the sump pump or doing something much more important. You normally use a software timer to poll, or even place the function in loop()
. But what if another function is blocking the loop()
or setup()
.
So your function might not be executed, and the result would be disastrous.
You'd prefer to have your function called, no matter what happening with other functions (busy loop, bug, etc.).
The correct choice is to use a Hardware Timer with Interrupt to call your function.
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.
Functions using normal software timers, relying on loop()
and calling millis()
, won't work if the loop()
or setup()
is blocked by certain operation. For example, certain function is blocking while it's connecting to WiFi or some services.
The catch is your function is now part of an ISR (Interrupt Service Routine), and must be lean / mean, and follow certain rules. More to read on:
- RP2040-based boards such as Nano_RP2040_Connect, RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040, etc. using Arduino-mbed RP2040 core
-
Inside the attached function, delay() won’t work and the value returned by millis() will not increment. Serial data received while in the function may be lost. You should declare as volatile any variables that you modify within the attached function.
-
Typically global variables are used to pass data between an ISR and the main program. To make sure variables shared between an ISR and the main program are updated correctly, declare them as volatile.
-
For this MBED-based core, never use Serial.print(ln) inside ISR or the system will hang.
Arduino IDE 1.8.19+
for Arduino.Arduino mbed_rp2040 core 3.4.1+
for Arduino (Use Arduino Board Manager) RP2040-based boards, such as Arduino Nano RP2040 Connect, RASPBERRY_PI_PICO, etc..- To use with certain example, depending on which Ethernet card you're using:
Ethernet_Generic library v2.7.1+
for W5100, W5200 and W5500.EthernetENC library v2.0.3+
for ENC28J60. . New and BetterUIPEthernet library v2.0.12+
for ENC28J60.
- To use with certain example
SimpleTimer library
for ISR_16_Timers_Array and ISR_16_Timers_Array_Complex examples.
The best and easiest way is to use Arduino Library Manager
. Search for MBED_RPI_PICO_TimerInterrupt, then select / install the latest version.
You can also use this link for more detailed instructions.
Another way to install is to:
- Navigate to MBED_RPI_PICO_TimerInterrupt page.
- Download the latest release
MBED_RPI_PICO_TimerInterrupt-main.zip
. - Extract the zip file to
MBED_RPI_PICO_TimerInterrupt-main
directory - Copy whole
MBED_RPI_PICO_TimerInterrupt-main
folder to Arduino libraries' directory such as~/Arduino/libraries/
.
- Install VS Code
- Install PlatformIO
- Install MBED_RPI_PICO_TimerInterrupt library by using Library Manager. Search for MBED_RPI_PICO_TimerInterrupt in Platform.io Author's Libraries
- Use included platformio.ini file from examples to ensure that all dependent libraries will installed automatically. Please visit documentation for the other options and examples at Project Configuration File
The current library implementation, using xyz-Impl.h
instead of standard xyz.cpp
, possibly creates certain Multiple Definitions
Linker error in certain use cases.
You can include these .hpp
files
// 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
// Can be included as many times as necessary, without `Multiple Definitions` Linker Error
#include "MBED_RPi_Pico_ISR_Timer.hpp" //https://github.com/khoih-prog/MBED_RPI_PICO_TimerInterrupt
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
// 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
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
#include "MBED_RPi_Pico_ISR_Timer.h" //https://github.com/khoih-prog/MBED_RPI_PICO_TimerInterrupt
Check the new multiFileProject example for a HOWTO
demo.
The RPI_PICO system timer peripheral provides a global microsecond timebase for the system, and generates interrupts based on this timebase. It supports the following features: • A single 64-bit counter, incrementing once per microsecond • This counter can be read from a pair of latching registers, for race-free reads over a 32-bit bus. • Four alarms: match on the lower 32 bits of counter, IRQ on match: TIMER_IRQ_0-TIMER_IRQ_3
Now with these new 16 ISR-based timers
(while consuming only 1 hardware timer), the maximum interval is practically unlimited (limited only by unsigned long milliseconds). The accuracy is nearly perfect compared to software timers. The most important feature is they're ISR-based timers Therefore, their executions are not blocked by bad-behaving functions / tasks.
This important feature is absolutely necessary for mission-critical tasks.
The ISR_Timer_Complex
example will demonstrate the nearly perfect accuracy compared to software timers by printing the actual elapsed millisecs of each type of timers.
Being ISR-based timers, their executions are not blocked by bad-behaving functions / tasks, such as connecting to WiFi, Internet and Blynk services. You can also have many (up to 16)
timers to use.
This non-being-blocked important feature is absolutely necessary for mission-critical tasks.
You'll see blynkTimer Software is blocked while system is connecting to WiFi / Internet / Blynk, as well as by blocking task in loop(), using delay() function as an example. The elapsed time then is very unaccurate
Before using any Timer, you have to make sure the Timer has not been used by any other purpose.
TIMER_IRQ_0, TIMER_IRQ_1, TIMER_IRQ_2 and TIMER_IRQ_3
are supported for RP2040-based boards.
// Select the timer you're using, from ITimer0(0)-ITimer3(3)
// Init MBED_RPI_PICO_Timer
MBED_RPI_PICO_Timer ITimer1(1);
Use one of these functions with interval in unsigned long microseconds
// interval (in us), callback is ISR
bool setInterval(unsigned long interval, pico_timer_callback callback);
// interval (in us), callback is ISR
bool attachInterruptInterval(unsigned long interval, pico_timer_callback callback)
as follows
// Never use Serial.print inside this mbed ISR. Will hang the system
void TimerHandler(uint alarm_num)
{
// Doing something here inside ISR
}
#define TIMER_INTERVAL_MS 5000L
// Init MBED_RPI_PICO_Timer
MBED_RPI_PICO_Timer ITimer(0);
void setup()
{
....
// Interval in unsigned long microseconds
if (ITimer.attachInterruptInterval(TIMER_INTERVAL_MS * 1000, TimerHandler))
Serial.println("Starting ITimer OK, millis() = " + String(millis()));
else
Serial.println("Can't set ITimer. Select another freq. or timer");
}
Use one of these functions with frequency in float Hz
// frequency (in Hz), callback is ISR
bool setFrequency(float frequency, pico_timer_callback callback)
// frequency (in Hz), callback is ISR
bool attachInterrupt(float frequency, timer_callback callback);
as follows
// Never use Serial.print inside this mbed ISR. Will hang the system
void TimerHandler(uint alarm_num)
{
///////////////////////////////////////////////////////////
// Always call this for MBED RP2040 before processing ISR
TIMER_ISR_START(alarm_num);
///////////////////////////////////////////////////////////
// Doing something here inside ISR
////////////////////////////////////////////////////////////
// Always call this for MBED RP2040 after processing ISR
TIMER_ISR_END(alarm_num);
////////////////////////////////////////////////////////////
}
#define TIMER_FREQ_HZ 5555.555
// Init MBED_RPI_PICO_Timer
MBED_RPI_PICO_Timer ITimer(0);
void setup()
{
....
// Frequency in float Hz
if (ITimer.attachInterrupt(TIMER_FREQ_HZ, TimerHandler))
Serial.println("Starting ITimer OK, millis() = " + String(millis()));
else
Serial.println("Can't set ITimer. Select another freq. or timer");
}
The 16 ISR_based Timers, designed for long timer intervals, only support using unsigned long millisec intervals. If you have to use much higher frequency or sub-millisecond interval, you have to use the Hardware Timers directly as in 1.3 Set Hardware Timer Frequency and attach Timer Interrupt Handler function
// Init MBED_RPI_PICO_Timer
MBED_RPI_PICO_Timer ITimer1(1);
// Init ISR_Timer
// Each ISR_Timer can service 16 different ISR-based timers
MBED_RPI_PICO_ISR_Timer ISR_timer;
// Never use Serial.print inside this mbed ISR. Will hang the system
void TimerHandler(uint alarm_num)
{
///////////////////////////////////////////////////////////
// Always call this for MBED RP2040 before processing ISR
TIMER_ISR_START(alarm_num);
///////////////////////////////////////////////////////////
ISR_timer.run();
////////////////////////////////////////////////////////////
// Always call this for MBED RP2040 after processing ISR
TIMER_ISR_END(alarm_num);
////////////////////////////////////////////////////////////
}
#define HW_TIMER_INTERVAL_MS 50L
#define TIMER_INTERVAL_2S 2000L
#define TIMER_INTERVAL_5S 5000L
#define TIMER_INTERVAL_11S 11000L
#define TIMER_INTERVAL_101S 101000L
// In AVR, avoid doing something fancy in ISR, for example complex Serial.print with String() argument
// The pure simple Serial.prints here are just for demonstration and testing. Must be eliminate in working environment
// Or you can get this run-time error / crash
void doingSomething2s()
{
// Doing something here inside ISR every 2 seconds
}
void doingSomething5s()
{
// Doing something here inside ISR every 5 seconds
}
void doingSomething11s()
{
// Doing something here inside ISR every 11 seconds
}
void doingSomething101s()
{
// Doing something here inside ISR every 101 seconds
}
void setup()
{
....
if (ITimer1.attachInterruptInterval(HW_TIMER_INTERVAL_MS * 1000, TimerHandler))
{
Serial.print(F("Starting ITimer1 OK, millis() = ")); Serial.println(millis());
}
else
Serial.println(F("Can't set ITimer1. Select another freq. or timer"));
// Just to demonstrate, don't use too many ISR Timers if not absolutely necessary
// You can use up to 16 timer for each ISR_Timer
ISR_timer.setInterval(TIMER_INTERVAL_2S, doingSomething2s);
ISR_timer.setInterval(TIMER_INTERVAL_5S, doingSomething5s);
ISR_timer.setInterval(TIMER_INTERVAL_11S, doingSomething11s);
ISR_timer.setInterval(TIMER_INTERVAL_101S, doingSomething101s);
}
- Argument_Complex
- Argument_None
- Argument_Simple
- Change_Interval
- ISR_16_Timers_Array_Complex
- ISR_Timers_Array_Simple
- SwitchDebounce
- TimerInterruptTest
- 50ms_HWTimer New
- multiFileProject New
Example ISR_Timers_Array_Simple
The following is the sample terminal output when running example ISR_Timers_Array_Simple to demonstrate the accuracy of ISR Hardware Timer, especially when system is very busy. The ISR timer is programmed for 2s, is activated exactly after 2.000s !!!
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.2.0
[TISR] _timerNo = 1, Clock (Hz) = 1000000.00, _fre (Hz) = 1000.00
[TISR] _count = 0-1000
[TISR] hardware_alarm_set_target, uS = 1000
Starting ITimer1 OK, millis() = 1690
SimpleTimer : programmed 2000ms, current time ms : 11290, Delta ms : 11290
Timer2s actual : 2000
Timer5s actual : 5000
SimpleTimer : programmed 2000ms, current time ms : 20890, Delta ms : 9600
Timer2s actual : 2000
Timer5s actual : 5000
SimpleTimer : programmed 2000ms, current time ms : 30490, Delta ms : 9600
Timer2s actual : 2000
Timer5s actual : 5000
The following is the sample terminal output when running example TimerInterruptTest to demonstrate how to start/stop Hardware Timers on MBED RP2040-based boards.
Starting TimerInterruptTest on RaspberryPi Pico
MBED_RPi_Pico_TimerInterrupt v1.2.0
[TISR] _timerNo = 0, Clock (Hz) = 1000000.00, _fre (Hz) = 1.00
[TISR] _count = 0-1000000
[TISR] hardware_alarm_set_target, uS = 1000000
Starting ITimer0 OK, millis() = 1787
[TISR] _timerNo = 1, Clock (Hz) = 1000000.00, _fre (Hz) = 0.33
[TISR] _count = 0-3000000
[TISR] hardware_alarm_set_target, uS = 3000000
Starting ITimer1 OK, millis() = 1789
Stop ITimer0, millis() = 5001
Start ITimer0, millis() = 10002
Stop ITimer1, millis() = 15001
Stop ITimer0, millis() = 15003
Start ITimer0, millis() = 20004
Stop ITimer0, millis() = 25005
Start ITimer1, millis() = 30002
Start ITimer0, millis() = 30006
The following is the sample terminal output when running example Change_Interval to demonstrate how to change Timer Interval on-the-fly on MBED RP2040-based boards.
Starting Change_Interval on RaspberryPi Pico
MBED_RPi_Pico_TimerInterrupt v1.2.0
[TISR] _timerNo = 0, Clock (Hz) = 1000000.00, _fre (Hz) = 0.50
[TISR] _count = 0-2000000
[TISR] hardware_alarm_set_target, uS = 2000000
Starting ITimer0 OK, millis() = 1282
[TISR] _timerNo = 1, Clock (Hz) = 1000000.00, _fre (Hz) = 0.20
[TISR] _count = 0-5000000
[TISR] hardware_alarm_set_target, uS = 5000000
Starting ITimer1 OK, millis() = 1284
Time = 10001, Timer0Count = 4, Timer1Count = 1
Time = 20002, Timer0Count = 9, Timer1Count = 3
[TISR] MBED_RPI_PICO_TimerInterrupt: _timerNo = 0 , _fre = 1000000.00
[TISR] _count = 0 - 4000000
[TISR] hardware_alarm_set_target, uS = 4000000
[TISR] MBED_RPI_PICO_TimerInterrupt: _timerNo = 1 , _fre = 1000000.00
[TISR] _count = 0 - 10000000
[TISR] hardware_alarm_set_target, uS = 10000000
Changing Interval, Timer0 = 4000, Timer1 = 10000
Time = 30003, Timer0Count = 11, Timer1Count = 3
Time = 40004, Timer0Count = 14, Timer1Count = 4
[TISR] MBED_RPI_PICO_TimerInterrupt: _timerNo = 0 , _fre = 1000000.00
[TISR] _count = 0 - 2000000
[TISR] hardware_alarm_set_target, uS = 2000000
[TISR] MBED_RPI_PICO_TimerInterrupt: _timerNo = 1 , _fre = 1000000.00
[TISR] _count = 0 - 5000000
[TISR] hardware_alarm_set_target, uS = 5000000
Changing Interval, Timer0 = 2000, Timer1 = 5000
Time = 50005, Timer0Count = 18, Timer1Count = 6
The following is the sample terminal output when running example SwitchDebounce
Starting SwitchDebounce on RaspberryPi Pico
MBED_RPi_Pico_TimerInterrupt v1.2.0
[TISR] _timerNo = 1, Clock (Hz) = 1000000.00, _fre (Hz) = 1000.00
[TISR] _count = 0-1000
[TISR] hardware_alarm_set_target, uS = 1000
Starting ITimer1 OK, millis() = 1185
SW Pressed, from millis() = 4537
SW Released, from millis() = 4888
SW Pressed total time ms = 351
SW Pressed, from millis() = 5266
SW Released, from millis() = 5604
SW Pressed total time ms = 338
SW Pressed, from millis() = 6600
SW Long Pressed, total time ms = 11589 - 6600 = 4989
SW Long Pressed, total time ms = 11640 - 6600 = 5040
SW Long Pressed, total time ms = 11691 - 6600 = 5091
SW Long Pressed, total time ms = 11742 - 6600 = 5142
SW Long Pressed, total time ms = 11793 - 6600 = 5193
SW Long Pressed, total time ms = 11844 - 6600 = 5244
SW Long Pressed, total time ms = 11895 - 6600 = 5295
SW Released, from millis() = 11996
SW Pressed total time ms = 5396
SW Pressed, from millis() = 13007
SW Released, from millis() = 13155
SW Pressed total time ms = 148
The following is the sample terminal output when running example ISR_16_Timers_Array_Complex to demonstrate the accuracy of ISR Hardware Timer, especially when system is very busy. The SimpleTimer, programmed for 2s, is activated only after nearly 10s !!!
Starting ISR_16_Timers_Array_Complex on RaspberryPi Pico
MBED_RPi_Pico_TimerInterrupt v1.2.0
[TISR] _timerNo = 0, Clock (Hz) = 1000000.00, _fre (Hz) = 100.00
[TISR] _count = 0-10000
[TISR] hardware_alarm_set_target, uS = 10000
Starting ITimer OK, millis() = 1621
SimpleTimer : 2, ms : 11622, Dms : 10000
Timer : 0, programmed : 5000, actual : 5009
Timer : 1, programmed : 10000, actual : 0
Timer : 2, programmed : 15000, actual : 0
Timer : 3, programmed : 20000, actual : 0
Timer : 4, programmed : 25000, actual : 0
Timer : 5, programmed : 30000, actual : 0
Timer : 6, programmed : 35000, actual : 0
Timer : 7, programmed : 40000, actual : 0
Timer : 8, programmed : 45000, actual : 0
Timer : 9, programmed : 50000, actual : 0
Timer : 10, programmed : 55000, actual : 0
Timer : 11, programmed : 60000, actual : 0
Timer : 12, programmed : 65000, actual : 0
Timer : 13, programmed : 70000, actual : 0
Timer : 14, programmed : 75000, actual : 0
Timer : 15, programmed : 80000, actual : 0
SimpleTimer : 2, ms : 21628, Dms : 10006
Timer : 0, programmed : 5000, actual : 5000
Timer : 1, programmed : 10000, actual : 10009
Timer : 2, programmed : 15000, actual : 15009
Timer : 3, programmed : 20000, actual : 0
Timer : 4, programmed : 25000, actual : 0
Timer : 5, programmed : 30000, actual : 0
Timer : 6, programmed : 35000, actual : 0
Timer : 7, programmed : 40000, actual : 0
Timer : 8, programmed : 45000, actual : 0
Timer : 9, programmed : 50000, actual : 0
Timer : 10, programmed : 55000, actual : 0
Timer : 11, programmed : 60000, actual : 0
Timer : 12, programmed : 65000, actual : 0
Timer : 13, programmed : 70000, actual : 0
Timer : 14, programmed : 75000, actual : 0
Timer : 15, programmed : 80000, actual : 0
SimpleTimer : 2, ms : 31634, Dms : 10006
Timer : 0, programmed : 5000, actual : 5000
Timer : 1, programmed : 10000, actual : 10000
Timer : 2, programmed : 15000, actual : 15000
Timer : 3, programmed : 20000, actual : 20009
Timer : 4, programmed : 25000, actual : 25009
Timer : 5, programmed : 30000, actual : 30009
Timer : 6, programmed : 35000, actual : 0
Timer : 7, programmed : 40000, actual : 0
Timer : 8, programmed : 45000, actual : 0
Timer : 9, programmed : 50000, actual : 0
Timer : 10, programmed : 55000, actual : 0
Timer : 11, programmed : 60000, actual : 0
Timer : 12, programmed : 65000, actual : 0
Timer : 13, programmed : 70000, actual : 0
Timer : 14, programmed : 75000, actual : 0
Timer : 15, programmed : 80000, actual : 0
SimpleTimer : 2, ms : 41640, Dms : 10006
Timer : 0, programmed : 5000, actual : 5000
Timer : 1, programmed : 10000, actual : 10000
Timer : 2, programmed : 15000, actual : 15000
Timer : 3, programmed : 20000, actual : 20000
Timer : 4, programmed : 25000, actual : 25009
Timer : 5, programmed : 30000, actual : 30009
Timer : 6, programmed : 35000, actual : 35009
Timer : 7, programmed : 40000, actual : 40009
Timer : 8, programmed : 45000, actual : 0
Timer : 9, programmed : 50000, actual : 0
Timer : 10, programmed : 55000, actual : 0
Timer : 11, programmed : 60000, actual : 0
Timer : 12, programmed : 65000, actual : 0
Timer : 13, programmed : 70000, actual : 0
Timer : 14, programmed : 75000, actual : 0
Timer : 15, programmed : 80000, actual : 0
SimpleTimer : 2, ms : 51646, Dms : 10006
Timer : 0, programmed : 5000, actual : 5000
Timer : 1, programmed : 10000, actual : 10000
Timer : 2, programmed : 15000, actual : 15000
Timer : 3, programmed : 20000, actual : 20000
Timer : 4, programmed : 25000, actual : 25000
Timer : 5, programmed : 30000, actual : 30009
Timer : 6, programmed : 35000, actual : 35009
Timer : 7, programmed : 40000, actual : 40009
Timer : 8, programmed : 45000, actual : 45009
Timer : 9, programmed : 50000, actual : 50009
Timer : 10, programmed : 55000, actual : 0
Timer : 11, programmed : 60000, actual : 0
Timer : 12, programmed : 65000, actual : 0
Timer : 13, programmed : 70000, actual : 0
Timer : 14, programmed : 75000, actual : 0
Timer : 15, programmed : 80000, actual : 0
SimpleTimer : 2, ms : 61652, Dms : 10006
Timer : 0, programmed : 5000, actual : 5000
Timer : 1, programmed : 10000, actual : 10000
Timer : 2, programmed : 15000, actual : 15000
Timer : 3, programmed : 20000, actual : 20000
Timer : 4, programmed : 25000, actual : 25000
Timer : 5, programmed : 30000, actual : 30000
Timer : 6, programmed : 35000, actual : 35009
Timer : 7, programmed : 40000, actual : 40009
Timer : 8, programmed : 45000, actual : 45009
Timer : 9, programmed : 50000, actual : 50009
Timer : 10, programmed : 55000, actual : 55009
Timer : 11, programmed : 60000, actual : 60009
Timer : 12, programmed : 65000, actual : 0
Timer : 13, programmed : 70000, actual : 0
Timer : 14, programmed : 75000, actual : 0
Timer : 15, programmed : 80000, actual : 0
SimpleTimer : 2, ms : 71658, Dms : 10006
Timer : 0, programmed : 5000, actual : 5000
Timer : 1, programmed : 10000, actual : 10000
Timer : 2, programmed : 15000, actual : 15000
Timer : 3, programmed : 20000, actual : 20000
Timer : 4, programmed : 25000, actual : 25000
Timer : 5, programmed : 30000, actual : 30000
Timer : 6, programmed : 35000, actual : 35000
Timer : 7, programmed : 40000, actual : 40009
Timer : 8, programmed : 45000, actual : 45009
Timer : 9, programmed : 50000, actual : 50009
Timer : 10, programmed : 55000, actual : 55009
Timer : 11, programmed : 60000, actual : 60009
Timer : 12, programmed : 65000, actual : 65009
Timer : 13, programmed : 70000, actual : 70009
Timer : 14, programmed : 75000, actual : 0
Timer : 15, programmed : 80000, actual : 0
SimpleTimer : 2, ms : 81664, Dms : 10006
Timer : 0, programmed : 5000, actual : 5000
Timer : 1, programmed : 10000, actual : 10000
Timer : 2, programmed : 15000, actual : 15000
Timer : 3, programmed : 20000, actual : 20000
Timer : 4, programmed : 25000, actual : 25000
Timer : 5, programmed : 30000, actual : 30000
Timer : 6, programmed : 35000, actual : 35000
Timer : 7, programmed : 40000, actual : 40000
Timer : 8, programmed : 45000, actual : 45009
Timer : 9, programmed : 50000, actual : 50009
Timer : 10, programmed : 55000, actual : 55009
Timer : 11, programmed : 60000, actual : 60009
Timer : 12, programmed : 65000, actual : 65009
Timer : 13, programmed : 70000, actual : 70009
Timer : 14, programmed : 75000, actual : 75009
Timer : 15, programmed : 80000, actual : 80009
...
SimpleTimer : 2, ms : 161712, Dms : 10006
Timer : 0, programmed : 5000, actual : 5000
Timer : 1, programmed : 10000, actual : 10000
Timer : 2, programmed : 15000, actual : 15000
Timer : 3, programmed : 20000, actual : 20000
Timer : 4, programmed : 25000, actual : 25000
Timer : 5, programmed : 30000, actual : 30000
Timer : 6, programmed : 35000, actual : 35000
Timer : 7, programmed : 40000, actual : 40000
Timer : 8, programmed : 45000, actual : 45000
Timer : 9, programmed : 50000, actual : 50000
Timer : 10, programmed : 55000, actual : 55000
Timer : 11, programmed : 60000, actual : 60000
Timer : 12, programmed : 65000, actual : 65000
Timer : 13, programmed : 70000, actual : 70000
Timer : 14, programmed : 75000, actual : 75000
Timer : 15, programmed : 80000, actual : 80000
SimpleTimer : 2, ms : 171718, Dms : 10006
Timer : 0, programmed : 5000, actual : 5000
Timer : 1, programmed : 10000, actual : 10000
Timer : 2, programmed : 15000, actual : 15000
Timer : 3, programmed : 20000, actual : 20000
Timer : 4, programmed : 25000, actual : 25000
Timer : 5, programmed : 30000, actual : 30000
Timer : 6, programmed : 35000, actual : 35000
Timer : 7, programmed : 40000, actual : 40000
Timer : 8, programmed : 45000, actual : 45000
Timer : 9, programmed : 50000, actual : 50000
Timer : 10, programmed : 55000, actual : 55000
Timer : 11, programmed : 60000, actual : 60000
Timer : 12, programmed : 65000, actual : 65000
Timer : 13, programmed : 70000, actual : 70000
Timer : 14, programmed : 75000, actual : 75000
Timer : 15, programmed : 80000, actual : 80000
Debug is enabled by default on Serial.
You can also change the debugging level (TIMERINTERRUPT_LOGLEVEL) from 0 to 4
// These define's must be placed at the beginning before #include "MBED_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.
#define _TIMERINTERRUPT_LOGLEVEL_ 0
If you get compilation errors, more often than not, you may need to install a newer version of the core for Arduino boards.
Sometimes, the library will only work if you update the board core to the latest version because I am using newly added functions.
Submit issues to: MBED_RPI_PICO_TimerInterrupt issues
- Search for bug and improvement.
- Basic hardware timers for RP2040-based boards such as Nano_RP2040_Connect, RASPBERRY_PI_PICO, using Arduino-mbed RP2040 core
- More hardware-initiated software-enabled timers
- Longer time interval
- Add Version String
- Add Table of Contents
- Fix
multiple-definitions
linker error - Optimize library code by using
reference-passing
instead ofvalue-passing
- Using
float
instead ofulong
for interval for better accuracy
Many thanks for everyone for bug reporting, new feature suggesting, testing and contributing to the development of this library.
- Neil Baylis to report issue Poor accuracy on timer interrupt frequency or interval. #4 leading to version v1.2.0 to fix
poor-timer-accuracy
bug
Neil Baylis |
If you want to contribute to this project:
- Report bugs and errors
- Ask for enhancements
- Create issues and pull requests
- Tell other people about this library
- The library is licensed under MIT
Copyright 2021- Khoi Hoang