Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jan 29, 2023. It is now read-only.

This library enables you to use Interrupt from Hardware Timers on an ATmega4809-based board, such as Arduino UNO WiFi Rev2, AVR_NANO_EVERY, etc. 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 exec…

License

NotificationsYou must be signed in to change notification settings

khoih-prog/megaAVR_TimerInterrupt

Repository files navigation

arduino-library-badgeGitHub releaseGitHubcontributions welcomeGitHub issues

Donate to my libraries using BuyMeACoffee



Table of Contents



Important Change from v1.5.0

Please have a look atHOWTO FixMultiple Definitions Linker Error

Features

This library enables you to use Interrupt from Hardware Timers on an ATmega4809-based boards, such as Arduino megaAVR : UNO WiFi Rev2, AVR_NANO_EVERY, etc.

AsHardware Timers are rare, and very precious assets of any board, this library now enables you to use up to16 ISR-based Timers, while consuming only 1 Hardware Timer. Timers' interval is very long (ulong millisecs).

Now with these new16 ISR-based timers, the maximum interval ispractically unlimited (limited only by unsigned long milliseconds) whilethe accuracy is nearly perfect compared to software timers.

The most important feature is they're ISR-based timers. Therefore, their executions arenot blocked by bad-behaving functions / tasks. This important feature is absolutely necessary for mission-critical tasks.

TheISR_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 taskin loop(), using delay() function as an example. The elapsed time then is very unaccurate

Why using ISR-based Hardware Timer Interrupt is better

Imagine you have a system with amission-critical function, measuring water level and control the sump pump or doing something much more important. You normally use asoftware 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 aHardware Timer with Interrupt to call your function.

These hardware timers, using interrupt, still work even if other functions are blocking. Moreover, they aremuch 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:

HOWTO Attach Interrupt

Important Notes about ISR

  1. 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.

  2. 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.

Currently supported Boards

  • Arduino UNO WiFi Rev2, AVR_NANO_EVERY, etc.
  • ATmega4809-based boards.


Prerequisites

  1. Arduino IDE 1.8.19+ for Arduino.GitHub release
  2. Arduino megaAVR core 1.8.7+ for Arduino megaAVR boards. Use Arduino Board Manager to install.
  3. MegaCoreX megaAVR core 1.1.0+ for Arduino megaAVR boards.GitHub release. FollowHow to install.
  4. To use with certain example


Installation

Use Arduino Library Manager

The best and easiest way is to useArduino Library Manager. Search formegaAVR_TimerInterrupt, then select / install the latest version.You can also use this linkarduino-library-badge for more detailed instructions.

Manual Install

Another way to install is to:

  1. Navigate tomegaAVR_TimerInterrupt page.
  2. Download the latest releasemegaAVR_TimerInterrupt-main.zip.
  3. Extract the zip file tomegaAVR_TimerInterrupt-main directory
  4. Copy wholemegaAVR_TimerInterrupt-main folder to Arduino libraries' directory such as~/Arduino/libraries/.

VS Code & PlatformIO:

  1. InstallVS Code
  2. InstallPlatformIO
  3. InstallmegaAVR_TimerInterrupt library by usingLibrary Manager. Search for megaAVR_TimerInterrupt inPlatform.io Author's Libraries
  4. Use includedplatformio.ini file from examples to ensure that all dependent libraries will installed automatically. Please visit documentation for the other options and examples atProject Configuration File


HOWTO FixMultiple Definitions Linker Error

The current library implementation, usingxyz-Impl.h instead of standardxyz.cpp, possibly creates certainMultiple 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"megaAVR_TimerInterrupt.hpp"//https://github.com/khoih-prog/megaAVR_TimerInterrupt// Can be included as many times as necessary, without `Multiple Definitions` Linker Error#include"megaAVR_ISR_Timer.hpp"//https://github.com/khoih-prog/megaAVR_TimerInterrupt

in many files. But be sure to use the following.h filesin just 1.h,.cpp or.ino file, which mustnot be included in any other file, to avoidMultiple Definitions Linker Error

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

Check the newmultiFileProject example for aHOWTO demo.



More useful Information

1. Documents

  1. Arduino 101: Timers and Interrupts
  2. megaAVR0-series-Family-Data-Sheet

2. Timer TCB0-TCB3

TCB0-TCB3 are 16-bit timers.



Usage

Before using any Timer, you have to make sure the Timer has not been used by any other purpose.

1. Using only Hardware Timer directly

1.1 Init Hardware Timer

// Select USING_16MHZ     == true for  16MHz to Timer TCBx => shorter timer, but better accuracy// Select USING_8MHZ      == true for   8MHz to Timer TCBx => shorter timer, but better accuracy// Select USING_250KHZ    == true for 250KHz to Timer TCBx => shorter timer, but better accuracy// Not select for default 250KHz to Timer TCBx => longer timer,  but worse accuracy#defineUSING_16MHZtrue#defineUSING_8MHZfalse#defineUSING_250KHZfalse// Select the timers you're using, here ITimer1#defineUSE_TIMER_0false#defineUSE_TIMER_1true#defineUSE_TIMER_2false#defineUSE_TIMER_3false// Init timer ITimer1ITimer1.init();

1.2 Set Hardware Timer Interval and attach Timer Interrupt Handler function

Use one of these functions withinterval in unsigned long milliseconds

// interval (in ms) and duration (in milliseconds). Duration = 0 or not specified => run indefinitelytemplate<typename TArg>boolsetInterval(unsignedlong interval,void (*callback)(TArg), TArg params, unsigned long duration = 0);// interval (in ms) and duration (in milliseconds). Duration = 0 or not specified => run indefinitelyboolsetInterval(unsignedlong interval, timer_callback callback,unsignedlong duration =0);// Interval (in ms) and duration (in milliseconds). Duration = 0 or not specified => run indefinitelytemplate<typename TArg>boolattachInterruptInterval(unsignedlong interval,void (*callback)(TArg), TArg params, unsigned long duration = 0);// Interval (in ms) and duration (in milliseconds). Duration = 0 or not specified => run indefinitelyboolattachInterruptInterval(unsignedlong interval, timer_callback callback,unsignedlong duration =0)

as follows

voidTimerHandler1(){// Doing something here inside ISR}#defineTIMER1_INTERVAL_MS50Lvoidsetup(){  ....// Interval in unsigned long millisecsif (ITimer1.attachInterruptInterval(TIMER1_INTERVAL_MS, TimerHandler1))    Serial.println("Starting  ITimer1 OK, millis() =" +String(millis()));else    Serial.println("Can't set ITimer1. Select another freq. or timer");}

1.3 Set Hardware Timer Frequency and attach Timer Interrupt Handler function

Use one of these functions withfrequency in float Hz

// frequency (in hertz) and duration (in milliseconds). Duration = 0 or not specified => run indefinitelyboolsetFrequency(float frequency, timer_callback_p callback,/* void**/uint32_t params,unsignedlong duration =0);// frequency (in hertz) and duration (in milliseconds). Duration = 0 or not specified => run indefinitelyboolsetFrequency(float frequency, timer_callback callback,unsignedlong duration =0);// frequency (in hertz) and duration (in milliseconds). Duration = 0 or not specified => run indefinitelytemplate<typename TArg>boolattachInterrupt(float frequency,void (*callback)(TArg), TArg params, unsigned long duration = 0);// frequency (in hertz) and duration (in milliseconds). Duration = 0 or not specified => run indefinitelyboolattachInterrupt(float frequency, timer_callback callback,unsignedlong duration =0);

as follows

voidTimerHandler1(){// Doing something here inside ISR}#defineTIMER1_FREQ_HZ5555.555voidsetup(){  ....// Frequency in float Hzif (ITimer1.attachInterrupt(TIMER1_FREQ_HZ, TimerHandler1))    Serial.println("Starting  ITimer1 OK, millis() =" +String(millis()));else    Serial.println("Can't set ITimer1. Select another freq. or timer");}

2. Using 16 ISR_based Timers from 1 Hardware Timer

2.1 Important Note

The 16 ISR_based Timers, designed for long timer intervals, only support usingunsigned long millisec intervals. If you have to use much higher frequency or sub-millisecond interval, you have to use the Hardware Timers directly as in1.3 Set Hardware Timer Frequency and attach Timer Interrupt Handler function

2.2 Init Hardware Timer and ISR-based Timer

// Select USING_16MHZ     == true for  16MHz to Timer TCBx => shorter timer, but better accuracy// Select USING_8MHZ      == true for   8MHz to Timer TCBx => shorter timer, but better accuracy// Select USING_250KHZ    == true for 250KHz to Timer TCBx => shorter timer, but better accuracy// Not select for default 250KHz to Timer TCBx => longer timer,  but worse accuracy#defineUSING_16MHZtrue#defineUSING_8MHZfalse#defineUSING_250KHZfalse#defineUSE_TIMER_0false#defineUSE_TIMER_1true#defineUSE_TIMER_2false#defineUSE_TIMER_3false// Init ISR_Timer// Each ISR_Timer can service 16 different ISR-based timersISR_Timer ISR_Timer1;

2.3 Set Hardware Timer Interval and attach Timer Interrupt Handler functions

voidTimerHandler(){  ISR_Timer1.run();}#defineHW_TIMER_INTERVAL_MS50L#defineTIMER_INTERVAL_2S2000L#defineTIMER_INTERVAL_5S5000L#defineTIMER_INTERVAL_11S11000L#defineTIMER_INTERVAL_101S101000L// 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 / crashvoiddoingSomething2s(){// Doing something here inside ISR every 2 seconds}voiddoingSomething5s(){// Doing something here inside ISR every 5 seconds}voiddoingSomething11s(){// Doing something here inside ISR  every 11 seconds}voiddoingSomething101s(){// Doing something here inside ISR every 101 seconds}voidsetup(){  ....// Interval in millisecsif (ITimer.attachInterruptInterval(HW_TIMER_INTERVAL_MS, TimerHandler))  {    lastMillis =millis();    Serial.println("Starting ITimer OK, millis() =" +String(lastMillis));  }else    Serial.println("Can't set ITimer correctly. Select another freq. or interval");// 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_Timer1.setInterval(TIMER_INTERVAL_2S, doingSomething2s);  ISR_Timer1.setInterval(TIMER_INTERVAL_5S, doingSomething5s);  ISR_Timer1.setInterval(TIMER_INTERVAL_11S, doingSomething11s);  ISR_Timer1.setInterval(TIMER_INTERVAL_101S, doingSomething101s);}


Examples:

  1. Argument_Complex
  2. Argument_None
  3. Argument_Simple
  4. Change_Interval.
  5. FakeAnalogWrite.
  6. ISR_16_Timers_Array_Complex.
  7. ISR_RPM_Measure
  8. Change_Interval_HF
  9. ISR_Timers_Array_Simple.
  10. RPM_Measure
  11. SwitchDebounce
  12. TimerDuration
  13. TimerInterruptTest
  14. multiFileProjectNew

#if !( defined(__AVR_ATmega4809__) || defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(ARDUINO_AVR_NANO_EVERY) || \
defined(ARDUINO_AVR_ATmega4809) || defined(ARDUINO_AVR_ATmega4808) || defined(ARDUINO_AVR_ATmega3209) || \
defined(ARDUINO_AVR_ATmega3208) || defined(ARDUINO_AVR_ATmega1609) || defined(ARDUINO_AVR_ATmega1608) || \
defined(ARDUINO_AVR_ATmega809) || defined(ARDUINO_AVR_ATmega808) )
#error This is designed only for Arduino or MegaCoreX megaAVR board! Please check your Tools->Board setting
#endif
// These define's must be placed at the beginning before #include "megaAVR_TimerInterrupt.h"
// _TIMERINTERRUPT_LOGLEVEL_ from 0 to 4
// Don't define _TIMERINTERRUPT_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system.
#defineTIMER_INTERRUPT_DEBUG0
#define_TIMERINTERRUPT_LOGLEVEL_3
// Select USING_16MHZ == true for 16MHz to Timer TCBx => shorter timer, but better accuracy
// Select USING_8MHZ == true for 8MHz to Timer TCBx => shorter timer, but better accuracy
// Select USING_250KHZ == true for 250KHz to Timer TCBx => shorter timer, but better accuracy
// Not select for default 250KHz to Timer TCBx => longer timer, but worse accuracy
#defineUSING_16MHZtrue
#defineUSING_8MHZfalse
#defineUSING_250KHZfalse
#defineUSE_TIMER_0false
#defineUSE_TIMER_1true
#defineUSE_TIMER_2false
#defineUSE_TIMER_3false
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
#include"megaAVR_TimerInterrupt.h"
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
#include"megaAVR_ISR_Timer.h"
#include<SimpleTimer.h>// https://github.com/jfturcot/SimpleTimer
#ifndef LED_BUILTIN
#defineLED_BUILTIN13
#endif
ISR_Timer ISR_Timer1;
#defineLED_TOGGLE_INTERVAL_MS1000L
// You have to use longer time here if having problem because Arduino AVR clock is low, 16MHz => lower accuracy.
// Tested OK with 1ms when not much load => higher accuracy.
#defineTIMER1_INTERVAL_MS5L
volatileuint32_t startMillis =0;
voidTimerHandler1()
{
staticbool toggle =false;
staticint timeRun =0;
ISR_Timer1.run();
// Toggle LED every LED_TOGGLE_INTERVAL_MS = 2000ms = 2s
if (++timeRun == ((LED_TOGGLE_INTERVAL_MS) / TIMER1_INTERVAL_MS) )
{
timeRun =0;
//timer interrupt toggles pin LED_BUILTIN
digitalWrite(LED_BUILTIN, toggle);
toggle = !toggle;
}
}
/////////////////////////////////////////////////
#defineNUMBER_ISR_TIMERS16
typedefvoid (*irqCallback) (void);
/////////////////////////////////////////////////
#defineUSE_COMPLEX_STRUCTtrue
#if USE_COMPLEX_STRUCT
typedefstruct
{
irqCallback irqCallbackFunc;
uint32_t TimerInterval;
unsignedlong deltaMillis;
unsignedlong previousMillis;
} ISRTimerData;
// In NRF52, avoid doing something fancy in ISR, for example Serial.print()
// 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
voiddoingSomething(int index);
#else
volatileunsignedlong deltaMillis [NUMBER_ISR_TIMERS] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
volatileunsignedlong previousMillis [NUMBER_ISR_TIMERS] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
// You can assign any interval for any timer here, in milliseconds
uint32_t TimerInterval[NUMBER_ISR_TIMERS] =
{
5000L,10000L,15000L,20000L,25000L,30000L,35000L,40000L,
45000L,50000L,55000L,60000L,65000L,70000L,75000L,80000L
};
voiddoingSomething(int index)
{
unsignedlong currentMillis =millis();
deltaMillis[index] = currentMillis - previousMillis[index];
previousMillis[index] = currentMillis;
}
#endif
////////////////////////////////////
// Shared
////////////////////////////////////
voiddoingSomething0()
{
doingSomething(0);
}
voiddoingSomething1()
{
doingSomething(1);
}
voiddoingSomething2()
{
doingSomething(2);
}
voiddoingSomething3()
{
doingSomething(3);
}
voiddoingSomething4()
{
doingSomething(4);
}
voiddoingSomething5()
{
doingSomething(5);
}
voiddoingSomething6()
{
doingSomething(6);
}
voiddoingSomething7()
{
doingSomething(7);
}
voiddoingSomething8()
{
doingSomething(8);
}
voiddoingSomething9()
{
doingSomething(9);
}
voiddoingSomething10()
{
doingSomething(10);
}
voiddoingSomething11()
{
doingSomething(11);
}
voiddoingSomething12()
{
doingSomething(12);
}
voiddoingSomething13()
{
doingSomething(13);
}
voiddoingSomething14()
{
doingSomething(14);
}
voiddoingSomething15()
{
doingSomething(15);
}
#if USE_COMPLEX_STRUCT
ISRTimerData curISRTimerData[NUMBER_ISR_TIMERS] =
{
//irqCallbackFunc, TimerInterval, deltaMillis, previousMillis
{ doingSomething0,5000L,0,0 },
{ doingSomething1,10000L,0,0 },
{ doingSomething2,15000L,0,0 },
{ doingSomething3,20000L,0,0 },
{ doingSomething4,25000L,0,0 },
{ doingSomething5,30000L,0,0 },
{ doingSomething6,35000L,0,0 },
{ doingSomething7,40000L,0,0 },
{ doingSomething8,45000L,0,0 },
{ doingSomething9,50000L,0,0 },
{ doingSomething10,55000L,0,0 },
{ doingSomething11,60000L,0,0 },
{ doingSomething12,65000L,0,0 },
{ doingSomething13,70000L,0,0 },
{ doingSomething14,75000L,0,0 },
{ doingSomething15,80000L,0,0 }
};
voiddoingSomething(int index)
{
unsignedlong currentMillis =millis();
curISRTimerData[index].deltaMillis = currentMillis - curISRTimerData[index].previousMillis;
curISRTimerData[index].previousMillis = currentMillis;
}
#else
irqCallback irqCallbackFunc[NUMBER_ISR_TIMERS] =
{
doingSomething0, doingSomething1, doingSomething2, doingSomething3,
doingSomething4, doingSomething5, doingSomething6, doingSomething7,
doingSomething8, doingSomething9, doingSomething10, doingSomething11,
doingSomething12, doingSomething13, doingSomething14, doingSomething15
};
#endif
////////////////////////////////////////////////
#defineSIMPLE_TIMER_MS2000L
// Init SimpleTimer
SimpleTimer simpleTimer;
// Here is software Timer, you can do somewhat fancy stuffs without many issues.
// But always avoid
// 1. Long delay() it just doing nothing and pain-without-gain wasting CPU power.Plan and design your code / strategy ahead
// 2. Very long "do", "while", "for" loops without predetermined exit time.
voidsimpleTimerDoingSomething2s()
{
staticunsignedlong previousMillis = startMillis;
unsignedlong currMillis =millis();
Serial.print(F("SimpleTimer :"));
Serial.print(SIMPLE_TIMER_MS /1000);
Serial.print(F(", ms :"));
Serial.print(currMillis);
Serial.print(F(", Dms :"));
Serial.println(currMillis - previousMillis);
for (uint16_t i =0; i < NUMBER_ISR_TIMERS; i++)
{
#if USE_COMPLEX_STRUCT
Serial.print(F("Timer :"));
Serial.print(i);
Serial.print(F(", programmed :"));
Serial.print(curISRTimerData[i].TimerInterval);
Serial.print(F(", actual :"));
Serial.println(curISRTimerData[i].deltaMillis);
#else
Serial.print(F("Timer :"));
Serial.print(i);
Serial.print(F(", programmed :"));
Serial.print(TimerInterval[i]);
Serial.print(F(", actual :"));
Serial.println(deltaMillis[i]);
#endif
}
previousMillis = currMillis;
}
voidsetup()
{
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(115200);
while (!Serial);
Serial.print(F("\nStarting ISR_16_Timers_Array_Complex on"));
Serial.println(BOARD_NAME);
Serial.println(MEGA_AVR_TIMER_INTERRUPT_VERSION);
Serial.print(F("CPU Frequency ="));
Serial.print(F_CPU /1000000);
Serial.println(F(" MHz"));
Serial.print(F("TCB Clock Frequency ="));
#if USING_16MHZ
Serial.println(F("16MHz for highest accuracy"));
#elif USING_8MHZ
Serial.println(F("8MHz for very high accuracy"));
#else
Serial.println(F("250KHz for lower accuracy but longer time"));
#endif
ITimer1.init();
if (ITimer1.attachInterruptInterval(TIMER1_INTERVAL_MS, TimerHandler1))
{
Serial.print(F("Starting ITimer1 OK, millis() ="));
Serial.println(millis());
}
else
Serial.println(F("Can't set ITimer1. Select another freq. or timer"));
//ISR_Timer1.setInterval(2000L, doingSomething2s);
//ISR_Timer1.setInterval(5000L, doingSomething5s);
// 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
for (uint16_t i =0; i < NUMBER_ISR_TIMERS; i++)
{
#if USE_COMPLEX_STRUCT
curISRTimerData[i].previousMillis = startMillis;
ISR_Timer1.setInterval(curISRTimerData[i].TimerInterval, curISRTimerData[i].irqCallbackFunc);
#else
previousMillis[i] = startMillis;
ISR_Timer1.setInterval(TimerInterval[i], irqCallbackFunc[i]);
#endif
}
// You need this timer for non-critical tasks. Avoid abusing ISR if not absolutely necessary.
simpleTimer.setInterval(SIMPLE_TIMER_MS, simpleTimerDoingSomething2s);
}
#defineBLOCKING_TIME_MS10000L
voidloop()
{
// This unadvised blocking task is used to demonstrate the blocking effects onto the execution and accuracy to Software timer
// You see the time elapse of ISR_Timer still accurate, whereas very unaccurate for Software Timer
// The time elapse for 2000ms software timer now becomes 3000ms (BLOCKING_TIME_MS)
// While that of ISR_Timer is still prefect.
delay(BLOCKING_TIME_MS);
// You need this Software timer for non-critical tasks. Avoid abusing ISR if not absolutely necessary
// You don't need to and never call ISR_Timer.run() here in the loop(). It's already handled by ISR timer.
simpleTimer.run();
}



Debug Terminal Output Samples

1. ISR_16_Timers_Array_Complex on Arduino megaAVR Nano Every

The following is the sample terminal output when running exampleISR_16_Timers_Array_Complex onArduino megaAVR Nano Every to demonstrate the accuracy of ISR Hardware Timer,especially when system is very busy. The ISR timer isprogrammed for 2s, is activated exactly after 2.000s !!!

While software timer, **programmed for 2s, is activated after more than 10.000s in loop().

Starting ISR_16_Timers_Array_Complex on megaAVR Nano EverymegaAVR_TimerInterrupt v1.7.0CPU Frequency = 16 MHzTCB Clock Frequency = 250KHz for lower accuracy but longer timeStarting  ITimer1 OK, millis() = 6SimpleTimer : 2, ms : 10006, Dms : 10006Timer : 0, programmed : 5000, actual : 5006Timer : 1, programmed : 10000, actual : 10010Timer : 2, programmed : 15000, actual : 0Timer : 3, programmed : 20000, actual : 0Timer : 4, programmed : 25000, actual : 0Timer : 5, programmed : 30000, actual : 0Timer : 6, programmed : 35000, actual : 0Timer : 7, programmed : 40000, actual : 0Timer : 8, programmed : 45000, actual : 0Timer : 9, programmed : 50000, actual : 0Timer : 10, programmed : 55000, actual : 0Timer : 11, programmed : 60000, actual : 0Timer : 12, programmed : 65000, actual : 0Timer : 13, programmed : 70000, actual : 0Timer : 14, programmed : 75000, actual : 0Timer : 15, programmed : 80000, actual : 0SimpleTimer : 2, ms : 20065, Dms : 10059Timer : 0, programmed : 5000, actual : 4994Timer : 1, programmed : 10000, actual : 9998Timer : 2, programmed : 15000, actual : 15014Timer : 3, programmed : 20000, actual : 20008Timer : 4, programmed : 25000, actual : 0Timer : 5, programmed : 30000, actual : 0Timer : 6, programmed : 35000, actual : 0Timer : 7, programmed : 40000, actual : 0Timer : 8, programmed : 45000, actual : 0Timer : 9, programmed : 50000, actual : 0Timer : 10, programmed : 55000, actual : 0Timer : 11, programmed : 60000, actual : 0Timer : 12, programmed : 65000, actual : 0Timer : 13, programmed : 70000, actual : 0Timer : 14, programmed : 75000, actual : 0Timer : 15, programmed : 80000, actual : 0SimpleTimer : 2, ms : 30125, Dms : 10060Timer : 0, programmed : 5000, actual : 4994Timer : 1, programmed : 10000, actual : 9998Timer : 2, programmed : 15000, actual : 14992Timer : 3, programmed : 20000, actual : 20008Timer : 4, programmed : 25000, actual : 25012Timer : 5, programmed : 30000, actual : 30006Timer : 6, programmed : 35000, actual : 0Timer : 7, programmed : 40000, actual : 0Timer : 8, programmed : 45000, actual : 0Timer : 9, programmed : 50000, actual : 0Timer : 10, programmed : 55000, actual : 0Timer : 11, programmed : 60000, actual : 0Timer : 12, programmed : 65000, actual : 0Timer : 13, programmed : 70000, actual : 0Timer : 14, programmed : 75000, actual : 0Timer : 15, programmed : 80000, actual : 0SimpleTimer : 2, ms : 40184, Dms : 10059Timer : 0, programmed : 5000, actual : 5004Timer : 1, programmed : 10000, actual : 10008Timer : 2, programmed : 15000, actual : 14992Timer : 3, programmed : 20000, actual : 20006Timer : 4, programmed : 25000, actual : 25012Timer : 5, programmed : 30000, actual : 30006Timer : 6, programmed : 35000, actual : 35010Timer : 7, programmed : 40000, actual : 40014Timer : 8, programmed : 45000, actual : 0Timer : 9, programmed : 50000, actual : 0Timer : 10, programmed : 55000, actual : 0Timer : 11, programmed : 60000, actual : 0Timer : 12, programmed : 65000, actual : 0Timer : 13, programmed : 70000, actual : 0Timer : 14, programmed : 75000, actual : 0Timer : 15, programmed : 80000, actual : 0SimpleTimer : 2, ms : 50245, Dms : 10061Timer : 0, programmed : 5000, actual : 5004Timer : 1, programmed : 10000, actual : 9998Timer : 2, programmed : 15000, actual : 15002Timer : 3, programmed : 20000, actual : 20006Timer : 4, programmed : 25000, actual : 25000Timer : 5, programmed : 30000, actual : 30006Timer : 6, programmed : 35000, actual : 35010Timer : 7, programmed : 40000, actual : 40014Timer : 8, programmed : 45000, actual : 45008Timer : 9, programmed : 50000, actual : 50012Timer : 10, programmed : 55000, actual : 0Timer : 11, programmed : 60000, actual : 0Timer : 12, programmed : 65000, actual : 0Timer : 13, programmed : 70000, actual : 0Timer : 14, programmed : 75000, actual : 0Timer : 15, programmed : 80000, actual : 0SimpleTimer : 2, ms : 60307, Dms : 10062Timer : 0, programmed : 5000, actual : 5004Timer : 1, programmed : 10000, actual : 9998Timer : 2, programmed : 15000, actual : 15002Timer : 3, programmed : 20000, actual : 19996Timer : 4, programmed : 25000, actual : 25000Timer : 5, programmed : 30000, actual : 30004Timer : 6, programmed : 35000, actual : 35010Timer : 7, programmed : 40000, actual : 40014Timer : 8, programmed : 45000, actual : 45008Timer : 9, programmed : 50000, actual : 50012Timer : 10, programmed : 55000, actual : 55006Timer : 11, programmed : 60000, actual : 60010Timer : 12, programmed : 65000, actual : 0Timer : 13, programmed : 70000, actual : 0Timer : 14, programmed : 75000, actual : 0Timer : 15, programmed : 80000, actual : 0SimpleTimer : 2, ms : 70369, Dms : 10062Timer : 0, programmed : 5000, actual : 4994Timer : 1, programmed : 10000, actual : 9998Timer : 2, programmed : 15000, actual : 15002Timer : 3, programmed : 20000, actual : 19996Timer : 4, programmed : 25000, actual : 25000Timer : 5, programmed : 30000, actual : 30004Timer : 6, programmed : 35000, actual : 34998Timer : 7, programmed : 40000, actual : 40014Timer : 8, programmed : 45000, actual : 45008Timer : 9, programmed : 50000, actual : 50012Timer : 10, programmed : 55000, actual : 55006Timer : 11, programmed : 60000, actual : 60010Timer : 12, programmed : 65000, actual : 65014Timer : 13, programmed : 70000, actual : 70008Timer : 14, programmed : 75000, actual : 0Timer : 15, programmed : 80000, actual : 0SimpleTimer : 2, ms : 80432, Dms : 10063Timer : 0, programmed : 5000, actual : 4994Timer : 1, programmed : 10000, actual : 9998Timer : 2, programmed : 15000, actual : 15002Timer : 3, programmed : 20000, actual : 19996Timer : 4, programmed : 25000, actual : 25000Timer : 5, programmed : 30000, actual : 30004Timer : 6, programmed : 35000, actual : 34998Timer : 7, programmed : 40000, actual : 39992Timer : 8, programmed : 45000, actual : 45008Timer : 9, programmed : 50000, actual : 50012Timer : 10, programmed : 55000, actual : 55006Timer : 11, programmed : 60000, actual : 60010Timer : 12, programmed : 65000, actual : 65014Timer : 13, programmed : 70000, actual : 70008Timer : 14, programmed : 75000, actual : 75012Timer : 15, programmed : 80000, actual : 80016

2. Change_Interval on Arduino megaAVR Nano Every

The following is the sample terminal output when running exampleChange_Interval onArduino megaAVR Nano Every to demonstrate how to change Timer Interval on-the-fly

Starting Change_Interval on megaAVR Nano EverymegaAVR_TimerInterrupt v1.7.0CPU Frequency = 16 MHzTCB Clock Frequency = 250KHz for lower accuracy but longer timeStarting  ITimer1 OK, millis() = 1Starting  ITimer2 OK, millis() = 4Time = 10001, Timer1Count = 97, Timer2Count = 49Time = 20002, Timer1Count = 195, Timer2Count = 99Changing Interval, Timer1 = 200,  Timer2 = 400Time = 30003, Timer1Count = 244, Timer2Count = 123Time = 40004, Timer1Count = 294, Timer2Count = 148Changing Interval, Timer1 = 100,  Timer2 = 200Time = 50006, Timer1Count = 391, Timer2Count = 197Time = 60007, Timer1Count = 489, Timer2Count = 247Changing Interval, Timer1 = 200,  Timer2 = 400Time = 70008, Timer1Count = 538, Timer2Count = 271Time = 80009, Timer1Count = 588, Timer2Count = 296Changing Interval, Timer1 = 100,  Timer2 = 200

3. ISR_16_Timers_Array_Complex on Arduino megaAVR Nano Every to show accuracy difference.

3.1. TCB Clock Frequency 16MHz for highest accuracy

Starting ISR_16_Timers_Array_Complex on megaAVR Nano EverymegaAVR_TimerInterrupt v1.7.0CPU Frequency = 16 MHzTCB Clock Frequency = 16MHz for highest accuracyStarting  ITimer1 OK, millis() = 6SimpleTimer : 2, ms : 10007, Dms : 10007Timer : 0, programmed : 5000, actual : 5000Timer : 1, programmed : 10000, actual : 10006Timer : 2, programmed : 15000, actual : 0Timer : 3, programmed : 20000, actual : 0Timer : 4, programmed : 25000, actual : 0Timer : 5, programmed : 30000, actual : 0Timer : 6, programmed : 35000, actual : 0Timer : 7, programmed : 40000, actual : 0Timer : 8, programmed : 45000, actual : 0Timer : 9, programmed : 50000, actual : 0Timer : 10, programmed : 55000, actual : 0Timer : 11, programmed : 60000, actual : 0Timer : 12, programmed : 65000, actual : 0Timer : 13, programmed : 70000, actual : 0Timer : 14, programmed : 75000, actual : 0Timer : 15, programmed : 80000, actual : 0SimpleTimer : 2, ms : 20066, Dms : 10059Timer : 0, programmed : 5000, actual : 5000Timer : 1, programmed : 10000, actual : 10000Timer : 2, programmed : 15000, actual : 15006Timer : 3, programmed : 20000, actual : 20006Timer : 4, programmed : 25000, actual : 0Timer : 5, programmed : 30000, actual : 0Timer : 6, programmed : 35000, actual : 0Timer : 7, programmed : 40000, actual : 0Timer : 8, programmed : 45000, actual : 0Timer : 9, programmed : 50000, actual : 0Timer : 10, programmed : 55000, actual : 0Timer : 11, programmed : 60000, actual : 0Timer : 12, programmed : 65000, actual : 0Timer : 13, programmed : 70000, actual : 0Timer : 14, programmed : 75000, actual : 0Timer : 15, programmed : 80000, actual : 0...SimpleTimer : 2, ms : 211269, Dms : 10064Timer : 0, programmed : 5000, actual : 5000            <========== Very accurate @ clock 16MHzTimer : 1, programmed : 10000, actual : 10000Timer : 2, programmed : 15000, actual : 15000Timer : 3, programmed : 20000, actual : 20000Timer : 4, programmed : 25000, actual : 25000Timer : 5, programmed : 30000, actual : 30000Timer : 6, programmed : 35000, actual : 35000Timer : 7, programmed : 40000, actual : 40000Timer : 8, programmed : 45000, actual : 45000Timer : 9, programmed : 50000, actual : 50000Timer : 10, programmed : 55000, actual : 55000Timer : 11, programmed : 60000, actual : 60000Timer : 12, programmed : 65000, actual : 65000Timer : 13, programmed : 70000, actual : 70000Timer : 14, programmed : 75000, actual : 75000Timer : 15, programmed : 80000, actual : 80000SimpleTimer : 2, ms : 221333, Dms : 10064Timer : 0, programmed : 5000, actual : 5000Timer : 1, programmed : 10000, actual : 10000Timer : 2, programmed : 15000, actual : 15000Timer : 3, programmed : 20000, actual : 20000Timer : 4, programmed : 25000, actual : 25000Timer : 5, programmed : 30000, actual : 30000Timer : 6, programmed : 35000, actual : 35000Timer : 7, programmed : 40000, actual : 40000Timer : 8, programmed : 45000, actual : 45000Timer : 9, programmed : 50000, actual : 50000Timer : 10, programmed : 55000, actual : 55000Timer : 11, programmed : 60000, actual : 60000Timer : 12, programmed : 65000, actual : 65000Timer : 13, programmed : 70000, actual : 70000Timer : 14, programmed : 75000, actual : 75000Timer : 15, programmed : 80000, actual : 80000

3.2. TCB Clock Frequency 8MHz for very high accuracy

Starting ISR_16_Timers_Array_Complex on megaAVR Nano EverymegaAVR_TimerInterrupt v1.7.0CPU Frequency = 16 MHzTCB Clock Frequency = 8MHz for very high accuracyStarting  ITimer1 OK, millis() = 10SimpleTimer : 2, ms : 10011, Dms : 10011Timer : 0, programmed : 5000, actual : 5000Timer : 1, programmed : 10000, actual : 10011Timer : 2, programmed : 15000, actual : 0Timer : 3, programmed : 20000, actual : 0Timer : 4, programmed : 25000, actual : 0Timer : 5, programmed : 30000, actual : 0Timer : 6, programmed : 35000, actual : 0Timer : 7, programmed : 40000, actual : 0Timer : 8, programmed : 45000, actual : 0Timer : 9, programmed : 50000, actual : 0Timer : 10, programmed : 55000, actual : 0Timer : 11, programmed : 60000, actual : 0Timer : 12, programmed : 65000, actual : 0Timer : 13, programmed : 70000, actual : 0Timer : 14, programmed : 75000, actual : 0Timer : 15, programmed : 80000, actual : 0...SimpleTimer : 2, ms : 160949, Dms : 10064Timer : 0, programmed : 5000, actual : 5000            <========== Very accurate @ clock 8MHzTimer : 1, programmed : 10000, actual : 10000Timer : 2, programmed : 15000, actual : 15000Timer : 3, programmed : 20000, actual : 20000Timer : 4, programmed : 25000, actual : 25000Timer : 5, programmed : 30000, actual : 30000Timer : 6, programmed : 35000, actual : 35000Timer : 7, programmed : 40000, actual : 40000Timer : 8, programmed : 45000, actual : 45000Timer : 9, programmed : 50000, actual : 50000Timer : 10, programmed : 55000, actual : 55000Timer : 11, programmed : 60000, actual : 60000Timer : 12, programmed : 65000, actual : 65000Timer : 13, programmed : 70000, actual : 70000Timer : 14, programmed : 75000, actual : 75000Timer : 15, programmed : 80000, actual : 80000SimpleTimer : 2, ms : 171013, Dms : 10064Timer : 0, programmed : 5000, actual : 5000Timer : 1, programmed : 10000, actual : 10000Timer : 2, programmed : 15000, actual : 15000Timer : 3, programmed : 20000, actual : 20000Timer : 4, programmed : 25000, actual : 25000Timer : 5, programmed : 30000, actual : 30000Timer : 6, programmed : 35000, actual : 35000Timer : 7, programmed : 40000, actual : 40000Timer : 8, programmed : 45000, actual : 45000Timer : 9, programmed : 50000, actual : 50000Timer : 10, programmed : 55000, actual : 55000Timer : 11, programmed : 60000, actual : 60000Timer : 12, programmed : 65000, actual : 65000Timer : 13, programmed : 70000, actual : 70000Timer : 14, programmed : 75000, actual : 75000Timer : 15, programmed : 80000, actual : 80000

3.3. TCB Clock Frequency 250KHz for lower accuracy but longer time

Starting ISR_16_Timers_Array_Complex on megaAVR Nano EverymegaAVR_TimerInterrupt v1.7.0CPU Frequency = 16 MHzTCB Clock Frequency = 250KHz for lower accuracy but longer timeStarting  ITimer1 OK, millis() = 11SimpleTimer : 2, ms : 10012, Dms : 10012Timer : 0, programmed : 5000, actual : 5021Timer : 1, programmed : 10000, actual : 10015Timer : 2, programmed : 15000, actual : 0Timer : 3, programmed : 20000, actual : 0Timer : 4, programmed : 25000, actual : 0Timer : 5, programmed : 30000, actual : 0Timer : 6, programmed : 35000, actual : 0Timer : 7, programmed : 40000, actual : 0Timer : 8, programmed : 45000, actual : 0Timer : 9, programmed : 50000, actual : 0Timer : 10, programmed : 55000, actual : 0Timer : 11, programmed : 60000, actual : 0Timer : 12, programmed : 65000, actual : 0Timer : 13, programmed : 70000, actual : 0Timer : 14, programmed : 75000, actual : 0Timer : 15, programmed : 80000, actual : 0SimpleTimer : 2, ms : 20071, Dms : 10059Timer : 0, programmed : 5000, actual : 4994Timer : 1, programmed : 10000, actual : 9999Timer : 2, programmed : 15000, actual : 15020Timer : 3, programmed : 20000, actual : 20014Timer : 4, programmed : 25000, actual : 0Timer : 5, programmed : 30000, actual : 0Timer : 6, programmed : 35000, actual : 0Timer : 7, programmed : 40000, actual : 0Timer : 8, programmed : 45000, actual : 0Timer : 9, programmed : 50000, actual : 0Timer : 10, programmed : 55000, actual : 0Timer : 11, programmed : 60000, actual : 0Timer : 12, programmed : 65000, actual : 0Timer : 13, programmed : 70000, actual : 0Timer : 14, programmed : 75000, actual : 0Timer : 15, programmed : 80000, actual : 0...SimpleTimer : 2, ms : 845278, Dms : 10063Timer : 0, programmed : 5000, actual : 4994            <========== Less accurate @ clock 250KHzTimer : 1, programmed : 10000, actual : 9997Timer : 2, programmed : 15000, actual : 15001Timer : 3, programmed : 20000, actual : 20005Timer : 4, programmed : 25000, actual : 25000Timer : 5, programmed : 30000, actual : 30004Timer : 6, programmed : 35000, actual : 34998Timer : 7, programmed : 40000, actual : 40001Timer : 8, programmed : 45000, actual : 44995Timer : 9, programmed : 50000, actual : 50000Timer : 10, programmed : 55000, actual : 55004Timer : 11, programmed : 60000, actual : 59998Timer : 12, programmed : 65000, actual : 64992Timer : 13, programmed : 70000, actual : 70005Timer : 14, programmed : 75000, actual : 75000Timer : 15, programmed : 80000, actual : 80004SimpleTimer : 2, ms : 855342, Dms : 10064Timer : 0, programmed : 5000, actual : 5004Timer : 1, programmed : 10000, actual : 9999Timer : 2, programmed : 15000, actual : 15003Timer : 3, programmed : 20000, actual : 20005Timer : 4, programmed : 25000, actual : 25000Timer : 5, programmed : 30000, actual : 30004Timer : 6, programmed : 35000, actual : 34998Timer : 7, programmed : 40000, actual : 40001Timer : 8, programmed : 45000, actual : 45007Timer : 9, programmed : 50000, actual : 50000Timer : 10, programmed : 55000, actual : 55004Timer : 11, programmed : 60000, actual : 59998Timer : 12, programmed : 65000, actual : 64992Timer : 13, programmed : 70000, actual : 70005Timer : 14, programmed : 75000, actual : 75000Timer : 15, programmed : 80000, actual : 80004

4. Change_Interval_HF on Arduino megaAVR Nano Every

The following is the sample terminal output when running exampleChange_Interval_HF onArduino megaAVR Nano Every to demonstrate how to change High Frequency Timer Interval on-the-fly

Starting Change_Interval_HF on megaAVR Nano EverymegaAVR_TimerInterrupt v1.7.0CPU Frequency = 16 MHzTCB Clock Frequency = 16MHz for highest accuracy[TISR] TCB 1[TISR] ==================[TISR] Init, Timer = 1[TISR] CTRLB   = 0[TISR] CCMP    = 65535[TISR] INTCTRL = 0[TISR] CTRLA   = 1[TISR] ==================[TISR] Frequency = 10000.00 , CLK_TCB_FREQ = 16000000[TISR] setFrequency: _CCMPValueRemaining =  1600Starting ITimer1 OK, millis() = 12Frequency, Timer1 = 10000Time = 10001, Timer1Count = 99856Time = 20002, Timer1Count = 199807[TISR] Frequency = 5000.00 , CLK_TCB_FREQ = 16000000[TISR] setFrequency: _CCMPValueRemaining =  3200Changing Frequency, Timer1 = 5000Time = 30003, Timer1Count = 249792Time = 40004, Timer1Count = 299784[TISR] Frequency = 10000.00 , CLK_TCB_FREQ = 16000000[TISR] setFrequency: _CCMPValueRemaining =  1600Changing Frequency, Timer1 = 10000

5. ISR_16_Timers_Array_Complex on Arduino megaAVR Nano Every using MegaCoreX

The following is the sample terminal output when running exampleISR_16_Timers_Array_Complex onArduino megaAVR Nano Every using MegaCoreX to demonstrate the accuracy of ISR Hardware Timer,especially when system is very busy. The ISR timer isprogrammed for 2s, is activated exactly after 2.000s !!!

While software timer, **programmed for 2s, is activated after more than 10.000s in loop().

Starting ISR_16_Timers_Array_Complex on MegaCoreX ATmega4809megaAVR_TimerInterrupt v1.7.0CPU Frequency = 16 MHzTCB Clock Frequency = 16MHz for highest accuracy[TISR] TCB1[TISR] ==================[TISR] Init, Timer = 1[TISR] CTRLB   = 0[TISR] CCMP    = 65535[TISR] INTCTRL = 0[TISR] CTRLA   = 1[TISR] ==================[TISR] Frequency = 200.00, CLK_TCB_FREQ = 16000000[TISR] setFrequency: _CCMPValueRemaining = 80000Starting  ITimer1 OK, millis() = 12SimpleTimer : 2, ms : 10013, Dms : 10013Timer : 0, programmed : 5000, actual : 5016Timer : 1, programmed : 10000, actual : 10016Timer : 2, programmed : 15000, actual : 0Timer : 3, programmed : 20000, actual : 0Timer : 4, programmed : 25000, actual : 0Timer : 5, programmed : 30000, actual : 0Timer : 6, programmed : 35000, actual : 0Timer : 7, programmed : 40000, actual : 0Timer : 8, programmed : 45000, actual : 0Timer : 9, programmed : 50000, actual : 0Timer : 10, programmed : 55000, actual : 0Timer : 11, programmed : 60000, actual : 0Timer : 12, programmed : 65000, actual : 0Timer : 13, programmed : 70000, actual : 0Timer : 14, programmed : 75000, actual : 0Timer : 15, programmed : 80000, actual : 0SimpleTimer : 2, ms : 20072, Dms : 10059Timer : 0, programmed : 5000, actual : 5000Timer : 1, programmed : 10000, actual : 10000Timer : 2, programmed : 15000, actual : 15016Timer : 3, programmed : 20000, actual : 20016Timer : 4, programmed : 25000, actual : 0Timer : 5, programmed : 30000, actual : 0Timer : 6, programmed : 35000, actual : 0Timer : 7, programmed : 40000, actual : 0Timer : 8, programmed : 45000, actual : 0Timer : 9, programmed : 50000, actual : 0Timer : 10, programmed : 55000, actual : 0Timer : 11, programmed : 60000, actual : 0Timer : 12, programmed : 65000, actual : 0Timer : 13, programmed : 70000, actual : 0Timer : 14, programmed : 75000, actual : 0Timer : 15, programmed : 80000, actual : 0SimpleTimer : 2, ms : 30132, Dms : 10060Timer : 0, programmed : 5000, actual : 5000Timer : 1, programmed : 10000, actual : 10001Timer : 2, programmed : 15000, actual : 15001Timer : 3, programmed : 20000, actual : 20016Timer : 4, programmed : 25000, actual : 25017Timer : 5, programmed : 30000, actual : 30017Timer : 6, programmed : 35000, actual : 0Timer : 7, programmed : 40000, actual : 0Timer : 8, programmed : 45000, actual : 0Timer : 9, programmed : 50000, actual : 0Timer : 10, programmed : 55000, actual : 0Timer : 11, programmed : 60000, actual : 0Timer : 12, programmed : 65000, actual : 0Timer : 13, programmed : 70000, actual : 0Timer : 14, programmed : 75000, actual : 0Timer : 15, programmed : 80000, actual : 0SimpleTimer : 2, ms : 40192, Dms : 10060Timer : 0, programmed : 5000, actual : 5000Timer : 1, programmed : 10000, actual : 10000Timer : 2, programmed : 15000, actual : 15001Timer : 3, programmed : 20000, actual : 20001Timer : 4, programmed : 25000, actual : 25017Timer : 5, programmed : 30000, actual : 30017Timer : 6, programmed : 35000, actual : 35017Timer : 7, programmed : 40000, actual : 40017Timer : 8, programmed : 45000, actual : 0Timer : 9, programmed : 50000, actual : 0Timer : 10, programmed : 55000, actual : 0Timer : 11, programmed : 60000, actual : 0Timer : 12, programmed : 65000, actual : 0Timer : 13, programmed : 70000, actual : 0Timer : 14, programmed : 75000, actual : 0Timer : 15, programmed : 80000, actual : 0SimpleTimer : 2, ms : 50253, Dms : 10061Timer : 0, programmed : 5000, actual : 5000Timer : 1, programmed : 10000, actual : 10000Timer : 2, programmed : 15000, actual : 15000Timer : 3, programmed : 20000, actual : 20001Timer : 4, programmed : 25000, actual : 25000Timer : 5, programmed : 30000, actual : 30017Timer : 6, programmed : 35000, actual : 35017Timer : 7, programmed : 40000, actual : 40017Timer : 8, programmed : 45000, actual : 45017Timer : 9, programmed : 50000, actual : 50017Timer : 10, programmed : 55000, actual : 0Timer : 11, programmed : 60000, actual : 0Timer : 12, programmed : 65000, actual : 0Timer : 13, programmed : 70000, actual : 0Timer : 14, programmed : 75000, actual : 0Timer : 15, programmed : 80000, actual : 0SimpleTimer : 2, ms : 60315, Dms : 10062Timer : 0, programmed : 5000, actual : 5000Timer : 1, programmed : 10000, actual : 10000Timer : 2, programmed : 15000, actual : 15000Timer : 3, programmed : 20000, actual : 20000Timer : 4, programmed : 25000, actual : 25000Timer : 5, programmed : 30000, actual : 30000Timer : 6, programmed : 35000, actual : 35017Timer : 7, programmed : 40000, actual : 40017Timer : 8, programmed : 45000, actual : 45017Timer : 9, programmed : 50000, actual : 50017Timer : 10, programmed : 55000, actual : 55017Timer : 11, programmed : 60000, actual : 60017Timer : 12, programmed : 65000, actual : 0Timer : 13, programmed : 70000, actual : 0Timer : 14, programmed : 75000, actual : 0Timer : 15, programmed : 80000, actual : 0SimpleTimer : 2, ms : 70377, Dms : 10062Timer : 0, programmed : 5000, actual : 5000Timer : 1, programmed : 10000, actual : 9996Timer : 2, programmed : 15000, actual : 15000Timer : 3, programmed : 20000, actual : 20000Timer : 4, programmed : 25000, actual : 25000Timer : 5, programmed : 30000, actual : 30000Timer : 6, programmed : 35000, actual : 34996Timer : 7, programmed : 40000, actual : 40017Timer : 8, programmed : 45000, actual : 45017Timer : 9, programmed : 50000, actual : 50017Timer : 10, programmed : 55000, actual : 55017Timer : 11, programmed : 60000, actual : 60017Timer : 12, programmed : 65000, actual : 65013Timer : 13, programmed : 70000, actual : 70013Timer : 14, programmed : 75000, actual : 0Timer : 15, programmed : 80000, actual : 0SimpleTimer : 2, ms : 80440, Dms : 10063Timer : 0, programmed : 5000, actual : 5000Timer : 1, programmed : 10000, actual : 10000Timer : 2, programmed : 15000, actual : 14996Timer : 3, programmed : 20000, actual : 19996Timer : 4, programmed : 25000, actual : 24996Timer : 5, programmed : 30000, actual : 30000Timer : 6, programmed : 35000, actual : 34996Timer : 7, programmed : 40000, actual : 39996Timer : 8, programmed : 45000, actual : 45017Timer : 9, programmed : 50000, actual : 50017Timer : 10, programmed : 55000, actual : 55017Timer : 11, programmed : 60000, actual : 60017Timer : 12, programmed : 65000, actual : 65013Timer : 13, programmed : 70000, actual : 70013Timer : 14, programmed : 75000, actual : 75013Timer : 15, programmed : 80000, actual : 80013


Debug

Debug is enabled by default on Serial.

You can also change the debugging level from 0 to 3

// These define's must be placed at the beginning before #include "megaAVR_TimerInterrupt.h"// _TIMERINTERRUPT_LOGLEVEL_ from 0 to 4// Don't define _TIMERINTERRUPT_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system.#defineTIMER_INTERRUPT_DEBUG0#define_TIMERINTERRUPT_LOGLEVEL_0

Troubleshooting

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.



Issues

Submit issues to:megaAVR_TimerInterrupt issues



TO DO

  1. Search for bug and improvement.

DONE

  1. Longer Interval for timers.
  2. Reduce code size if use less timers. Eliminate compiler warnings.
  3. Now supporting complex object pointer-type argument.
  4. 16 hardware-initiated software-enabled timers while using only 1 hardware timer.
  5. Fix some bugs in v1.0.0
  6. Add more examples.
  7. Similar library for ESP32, ESP8266, SAMD21/SAMD51, nRF52, Mbed-OS Nano-33-BLE, STM32
  8. Add support toATmega4809-based boards, such asArduino UNO WiFi Rev2, AVR_NANO_EVERY, etc.
  9. SelectableTCB Clock 16MHz, 8MHz or 250KHz depending on necessary accuracy
  10. Fixmultiple-definitions linker error
  11. Optimize library code by usingreference-passing instead ofvalue-passing
  12. Add support toMegaCoreX core, includingATmega4809, ATmega4808, ATmega3209, ATmega3208, ATmega1609, ATmega1608, ATmega809 and ATmega808
  13. Useallman astyle and addutils


Contributions and Thanks

Many thanks for everyone for bug reporting, new feature suggesting, testing and contributing to the development of this library. Especially to these people who have directly or indirectly contributed to thismegaAVR_TimerInterrupt library

  1. Thanks to good work ofMiguel Wisintainer for initiating, inspriring, working with, developing, debugging, testing and maintaining.
  2. Thanks toBill Wuttke to report the issueInterrupt interval 2X requested interval #1 leading to new release v1.4.0 to fix bug in using higher frequencies than 250Hz
  3. Thanks tocattledogGH to report the issueInterrupt interval 2X requested interval #1 leading to new release v1.7.0 to fix bug disablingTCB0
tcpipchip
⭐️ Miguel Wisintainer

wcwuttke
Bill Wuttke

cattledogGH
cattledogGH


Contributing

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

License

  • The library is licensed underMIT

Copyright

Copyright 2021- Khoi Hoang

About

This library enables you to use Interrupt from Hardware Timers on an ATmega4809-based board, such as Arduino UNO WiFi Rev2, AVR_NANO_EVERY, etc. 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 exec…

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp