- Important Note for Arduino IDE
- Why do we need this ATtiny_TimerInterrupt library
- Changelog
- Prerequisites
- Installation
- HOWTO Fix
Multiple Definitions
Linker Error - More useful Information
- Usage
- Examples
- Example ISR_16_Timers_Array_Complex
- Debug Terminal Output Samples
- Debug
- Troubleshooting
- Issues
- TO DO
- DONE
- Contributions and Thanks
- Contributing
- License
- Copyright
With some Arduino IDE versions, such as v1.8.19, upload directly via USB to some boards, such as AVR_CuriosityNano3217
can't be done without unknown-to-me fix. We'll get the following error when uploading
avrdude: Version 6.3-20201216
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2014 Joerg Wunsch
System wide configuration file is "/home/kh/.arduino15/packages/megaTinyCore/hardware/megaavr/2.5.11/avrdude.conf"
User configuration file is "/home/kh/.avrduderc"
User configuration file does not exist or is not a regular file, skipping
Using Port : usb
Using Programmer : curiosity_updi
avrdude: usbdev_open(): Found nEDBG CMSIS-DAP, serno: MCHP3333021800000998
avrdude: usbdev_open(): WARNING: failed to set configuration 1: Device or resource busy
avrdude: Found CMSIS-DAP compliant device, using EDBG protocol
avrdude: usbdev_send(): wrote -5 out of 912 bytes, err = Input/output error
avrdude: jtag3_edbg_prepare(): failed to send command to serial port
avrdude done. Thank you.
the selected serial port
does not exist or your board is not connected
We can use drag-and-drop method to drag-and-drop
the compiled hex file to CURIOSITY
virtual drive.
If success
, The LED blinks slowly for 2 sec. The LED will blinks rapidly for 2 sec if failure
For example, to run Change_Interval example, use Arduino IDE to compile, and get the Change_Interval.ino.hex
file. For Ubuntu Linux, the file is stored in directory /tmp/arduino_build_xxxxxx
After drag-and-drop the Change_Interval.ino.hex
into CURIOSITY
virtual drive, the code will run immediately if successfully loaded (LED blinks slowly)
Why do we need this ATtiny_TimerInterrupt library
This library enables you to use Interrupt from Hardware Timers on Arduino AVR ATtiny-based boards (ATtiny3217, etc.) using using megaTinyCore
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 (uint64_t millisecs).
Now with these new 16 ISR-based timers, the maximum interval is practically unlimited (limited only by uint64_t
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, such as connecting to WiFi, Internet and Blynk services. This important feature is absolutely necessary for mission-critical tasks. You can also have many (up to 16)
timers to use.
This non-being-blocked 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.
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:
-
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.
- tinyAVR boards using megaTinyCore
Arduino IDE 1.8.19+
for Arduino.SpenceKonde megaTinyCore core 2.5.11+
for Arduino ATtiny boards. . Follow megaTinyCore Installation.- To use with certain example
SimpleTimer library
for ISR_Timers_Array_Simple and ISR_16_Timers_Array_Complex examples.
The best and easiest way is to use Arduino Library Manager
. Search for ATtiny_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 ATtiny_TimerInterrupt page.
- Download the latest release
ATtiny_TimerInterrupt-main.zip
. - Extract the zip file to
ATtiny_TimerInterrupt-main
directory - Copy whole
ATtiny_TimerInterrupt-main
folder to Arduino libraries' directory such as~/Arduino/libraries/
.
- Install VS Code
- Install PlatformIO
- Install ATtiny_TimerInterrupt library by using Library Manager. Search for ATtiny_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 "ATtiny_TimerInterrupt.hpp" //https://github.com/khoih-prog/ATtiny_TimerInterrupt
// Can be included as many times as necessary, without `Multiple Definitions` Linker Error
#include "ATtiny_ISR_Timer.hpp" //https://github.com/khoih-prog/ATtiny_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 "ATtiny_TimerInterrupt.h" //https://github.com/khoih-prog/ATtiny_TimerInterrupt
// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
#include "ATtiny_ISR_Timer.h" //https://github.com/khoih-prog/ATtiny_TimerInterrupt
Check the new multiFileProject example for a HOWTO
demo.
- Arduino 101: Timers and Interrupts
- Getting Started with Timer/Counter Type B (TCB)
- megaTinyCore README.md
- ATtiny3217 Curiosity Nano Hardware User Guide
- AVR128DA48-Curiosity-Nano-Hardware-User Guide
- AVR128DB48-Curiosity-Nano-Hardware-User Guide
TCB0-TCB1 are 16-bit timers
The ATtiny boards, such as ATtiny3217
, ATtiny1617
, will have only maximum 2 TCB timers, (TCB0-TCB1).
The ATtiny boards, such as ATtiny817
, will have only maximum 1 TCB timer, (TCB0).
The number of TCB timers will be automatically configured by the library.
The following is the partial list of number of TCBs for each ATtiny board/chip
ATtiny3217, ATtiny1617, ATtiny3216, ATtiny1616, ATtiny1614
ATtinyx12, ATtinyx14, ATtinyx16, ATtinyx17, such as ATtiny817, ATtiny417, ATtiny816, etc.
ATtinyx02, ATtinyx04, ATtinyx06, ATtinyx07, such as ATtiny1607, ATtiny807, ATtiny1606, etc.
Before using any Timer, you have to make sure the Timer has not been used by any other purpose.
// Select USING_FULL_CLOCK == true for 20/16MHz to Timer TCBx => shorter timer, but better accuracy
// Select USING_HALF_CLOCK == true for 10/ 8MHz to Timer TCBx => shorter timer, but better accuracy
// Select USING_250KHZ == true for 250KHz to Timer TCBx => longer timer, but worse accuracy
// Not select for default 250KHz to Timer TCBx => longer timer, but worse accuracy
#define USING_FULL_CLOCK true
#define USING_HALF_CLOCK false
#define USING_250KHZ false // Not supported now
// Try to use RTC, TCA0 or TCD0 for millis()
#define USE_TIMER_0 true // Check if used by millis(), Servo or tone()
#define USE_TIMER_1 false // Check if used by millis(), Servo or tone()
#if USE_TIMER_0
#define CurrentTimer ITimer0
#elif USE_TIMER_1
#define CurrentTimer ITimer1
#else
#error You must select one Timer
#endif
// Init timer CurrentTimer
CurrentTimer.init();
Use one of these functions with interval in unsigned long milliseconds
// interval (in ms) and duration (in milliseconds). Duration = 0 or not specified => run indefinitely
template<typename TArg> bool setInterval(unsigned long interval, void (*callback)(TArg), TArg params, unsigned long duration = 0);
// interval (in ms) and duration (in milliseconds). Duration = 0 or not specified => run indefinitely
bool setInterval(unsigned long interval, timer_callback callback, unsigned long duration = 0);
// Interval (in ms) and duration (in milliseconds). Duration = 0 or not specified => run indefinitely
template<typename TArg> bool attachInterruptInterval(unsigned long interval, void (*callback)(TArg), TArg params, unsigned long duration = 0);
// Interval (in ms) and duration (in milliseconds). Duration = 0 or not specified => run indefinitely
bool attachInterruptInterval(unsigned long interval, timer_callback callback, unsigned long duration = 0)
as follows
void TimerHandler1()
{
// Doing something here inside ISR
}
#define TIMER1_INTERVAL_MS 50L
void setup()
{
....
// Interval in unsigned long millisecs
ITimer1.init();
if (ITimer1.attachInterruptInterval(TIMER1_INTERVAL_MS, TimerHandler1))
{
SerialDebug.print(F("Starting ITimer OK, millis() = ")); SerialDebug.println(millis());
}
else
SerialDebug.println(F("Can't set ITimer. Select another freq. or timer"));
}
Use one of these functions with frequency in float Hz
// frequency (in hertz) and duration (in milliseconds). Duration = 0 or not specified => run indefinitely
bool setFrequency(float frequency, timer_callback_p callback, /* void* */ uint32_t params, unsigned long duration = 0);
// frequency (in hertz) and duration (in milliseconds). Duration = 0 or not specified => run indefinitely
bool setFrequency(float frequency, timer_callback callback, unsigned long duration = 0);
// frequency (in hertz) and duration (in milliseconds). Duration = 0 or not specified => run indefinitely
template<typename TArg> bool attachInterrupt(float frequency, void (*callback)(TArg), TArg params, unsigned long duration = 0);
// frequency (in hertz) and duration (in milliseconds). Duration = 0 or not specified => run indefinitely
bool attachInterrupt(float frequency, timer_callback callback, unsigned long duration = 0);
as follows
void TimerHandler1()
{
// Doing something here inside ISR
}
#define TIMER1_FREQ_HZ 5555.555
void setup()
{
....
// Frequency in float Hz
if (ITimer1.attachInterrupt(TIMER1_FREQ_HZ, TimerHandler1))
{
SerialDebug.print(F("Starting ITimer OK, millis() = ")); SerialDebug.println(millis());
}
else
SerialDebug.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
// 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.
#define TIMER_INTERRUPT_DEBUG 0
#define _TIMERINTERRUPT_LOGLEVEL_ 0
// Select USING_FULL_CLOCK == true for 20/16MHz to Timer TCBx => shorter timer, but better accuracy
// Select USING_HALF_CLOCK == true for 10/ 8MHz to Timer TCBx => shorter timer, but better accuracy
// Select USING_250KHZ == true for 250KHz to Timer TCBx => longer timer, but worse accuracy
// Not select for default 250KHz to Timer TCBx => longer timer, but worse accuracy
#define USING_FULL_CLOCK true
#define USING_HALF_CLOCK false
#define USING_250KHZ false // Not supported now
// Try to use RTC, TCA0 or TCD0 for millis()
#define USE_TIMER_0 true // Check if used by millis(), Servo or tone()
#define USE_TIMER_1 false // Check if used by millis(), Servo or tone()
#if USE_TIMER_0
#define CurrentTimer ITimer0
#elif USE_TIMER_1
#define CurrentTimer ITimer1
#else
#error You must select one Timer
#endif
// Init ISR_Timer
// Each ISR_Timer can service 16 different ISR-based timers
ISR_Timer ISR_Timer1;
void TimerHandler()
{
ISR_Timer1.run();
}
#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 SerialDebug.print with String() argument
// The pure simple SerialDebug.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()
{
....
// Timer TCB2 is used for micros(), millis(), delay(), etc and can't be used
CurrentTimer.init();
// Interval in millisecs
if (CurrentTimer.attachInterruptInterval(HW_TIMER_INTERVAL_MS, TimerHandler))
{
lastMillis = millis();
SerialDebug.print(F("Starting ITimer OK, millis() = ")); SerialDebug.println(millis());
}
else
SerialDebug.println(F("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);
}
- Argument_Complex
- Argument_None
- Argument_Simple
- Change_Interval.
- FakeAnalogWrite.
- ISR_16_Timers_Array_Complex.
- ISR_RPM_Measure
- Change_Interval_HF
- ISR_Timers_Array_Simple.
- RPM_Measure
- SwitchDebounce
- TimerDuration
- TimerInterruptTest
- multiFileProject
Example ISR_16_Timers_Array_Complex
The following is the sample terminal output when running example ISR_16_Timers_Array_Complex on AVR_CuriosityNano3217 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 in loop().
Starting ISR_16_Timers_Array_Complex on AVR_CuriosityNano3217
ATtiny_TimerInterrupt v1.0.1
CPU Frequency = 20 MHz
TCB Clock Frequency = Full clock (20/16MHz, etc) for highest accuracy
Starting ITimer OK, millis() = 13
SimpleTimer : 2, ms : 9949, Dms : 9949
Timer : 0, programmed : 5000, actual : 5015
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 : 19876, Dms : 9927
Timer : 0, programmed : 5000, actual : 5000
Timer : 1, programmed : 10000, actual : 10016
Timer : 2, programmed : 15000, actual : 15016
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 : 179959, Dms : 9997
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 : 29996
Timer : 6, programmed : 35000, actual : 35000
Timer : 7, programmed : 40000, actual : 39996
Timer : 8, programmed : 45000, actual : 45001
Timer : 9, programmed : 50000, actual : 49997
Timer : 10, programmed : 55000, actual : 54996
Timer : 11, programmed : 60000, actual : 60001
Timer : 12, programmed : 65000, actual : 64997
Timer : 13, programmed : 70000, actual : 69997
Timer : 14, programmed : 75000, actual : 74997
Timer : 15, programmed : 80000, actual : 79997
Starting ISR_16_Timers_Array_Complex on AVR_CuriosityNano3217
ATtiny_TimerInterrupt v1.0.1
CPU Frequency = 20 MHz
TCB Clock Frequency = Full clock (20/16MHz, etc) for highest accuracy
Starting ITimer OK, millis() = 13
SimpleTimer : 2, ms : 9949, Dms : 9949
Timer : 0, programmed : 5000, actual : 5015
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 : 19876, Dms : 9927
Timer : 0, programmed : 5000, actual : 5000
Timer : 1, programmed : 10000, actual : 10016
Timer : 2, programmed : 15000, actual : 15016
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 : 179959, Dms : 9997
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 : 29996
Timer : 6, programmed : 35000, actual : 35000
Timer : 7, programmed : 40000, actual : 39996
Timer : 8, programmed : 45000, actual : 45001
Timer : 9, programmed : 50000, actual : 49997
Timer : 10, programmed : 55000, actual : 54996
Timer : 11, programmed : 60000, actual : 60001
Timer : 12, programmed : 65000, actual : 64997
Timer : 13, programmed : 70000, actual : 69997
Timer : 14, programmed : 75000, actual : 74997
Timer : 15, programmed : 80000, actual : 79997
Starting ISR_16_Timers_Array_Complex on AVR_CuriosityNano3217
ATtiny_TimerInterrupt v1.0.1
CPU Frequency = 20 MHz
TCB Clock Frequency = Half clock (10/8MHz, etc.) for high accuracy
Starting ITimer OK, millis() = 13
SimpleTimer : 2, ms : 9752, Dms : 9752
Timer : 0, programmed : 5000, actual : 5015
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 : 19810, Dms : 10058
Timer : 0, programmed : 5000, actual : 5000
Timer : 1, programmed : 10000, actual : 10016
Timer : 2, programmed : 15000, actual : 15016
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 : 89713, Dms : 9998
Timer : 0, programmed : 5000, actual : 5000
Timer : 1, programmed : 10000, actual : 10001
Timer : 2, programmed : 15000, actual : 15001
Timer : 3, programmed : 20000, actual : 20001
Timer : 4, programmed : 25000, actual : 25001
Timer : 5, programmed : 30000, actual : 30000
Timer : 6, programmed : 35000, actual : 35000
Timer : 7, programmed : 40000, actual : 40001
Timer : 8, programmed : 45000, actual : 45017
Timer : 9, programmed : 50000, actual : 50016
Timer : 10, programmed : 55000, actual : 55017
Timer : 11, programmed : 60000, actual : 60016
Timer : 12, programmed : 65000, actual : 65017
Timer : 13, programmed : 70000, actual : 70016
Timer : 14, programmed : 75000, actual : 75017
Timer : 15, programmed : 80000, actual : 80017
The following is the sample terminal output when running example Change_Interval_HF on AVR_CuriosityNano3217 to demonstrate how to change High Frequency Timer Interval on-the-fly
Starting Change_Interval_HF on AVR_CuriosityNano3217
ATtiny_TimerInterrupt v1.0.1
CPU Frequency = 20 MHz
TCB Clock Frequency = Full clock (20/16MHz, etc) for highest accuracy
Starting ITimer OK, millis() = 13
Frequency, Timer = 50
Time = 1001, Timer1Count = 49
Time = 2002, Timer1Count = 99
Time = 3003, Timer1Count = 149
Time = 4004, Timer1Count = 199
Time = 5005, Timer1Count = 249
Changing Frequency, Timer = 25
Time = 6006, Timer1Count = 274
Time = 7007, Timer1Count = 299
Time = 8008, Timer1Count = 324
Time = 9009, Timer1Count = 349
Time = 10010, Timer1Count = 374
Changing Frequency, Timer = 16
Time = 11011, Timer1Count = 390
Time = 12012, Timer1Count = 406
Time = 13013, Timer1Count = 422
Time = 14014, Timer1Count = 438
Time = 15015, Timer1Count = 454
Changing Frequency, Timer = 12
Time = 16016, Timer1Count = 466
Time = 17017, Timer1Count = 478
Time = 18018, Timer1Count = 490
Time = 19019, Timer1Count = 502
Time = 20020, Timer1Count = 514
Changing Frequency, Timer = 10
Time = 21021, Timer1Count = 524
Time = 22022, Timer1Count = 534
Time = 23023, Timer1Count = 544
Time = 24024, Timer1Count = 554
Time = 25025, Timer1Count = 564
Debug is enabled by default on Serial
for AVR_CuriosityNano3217
.
You can also change the debugging level from 0 to 4
// These define's must be placed at the beginning before #include "ATtiny_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 TIMER_INTERRUPT_DEBUG 0
#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: ATtiny_TimerInterrupt issues
- Search for bug and improvement
- Add support to 250KHz Timer Frequency
- Longer Interval for timers
- Reduce code size if use less timers. Eliminate compiler warnings
- Now supporting complex object pointer-type argument
- 16 hardware-initiated software-enabled timers while using only 1 hardware timer
- Add support to ATtiny-based boards (AVR_CuriosityNano3217, etc.) using megaTinyCore
- Selectable TCB Clock FULL, HALF depending on necessary accuracy
- Fix
multiple-definitions
linker error - Optimize library code by using
reference-passing
instead ofvalue-passing
- Improve and customize examples for
AVR_CuriosityNano3217
boards to use on-board LED and SW - Add notes
howto upload by drag-and-drop
toCURIOSITY
virtual drive - Using Serial for debugging with
AVR_CuriosityNano3217
- Default to use
TCB0
in examples for boards having only 1 TCB Timer, such asATtiny817
,ATtiny807
- Fix bug giving error when using TCB0 (
USE_TIMER_0 == true
)
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 this ATtiny_TimerInterrupt library
- Thanks to good work of Spence Konde (aka Dr. Azzy) for the megaTinyCore
- Thanks to LaurentR59 to request the enhancement Support for DX CORE CPU and MightyCORE CPU possible? #8 leading to this new library
⭐️⭐️ Spence Konde |
LaurentR59 |
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 (c) 2022- Khoi Hoang