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

Commit

Permalink
v1.2.0
Browse files Browse the repository at this point in the history
### Releases v1.2.0

1. Add better debug feature.
2. Optimize code and examples to reduce RAM usage
3. Add Table of Contents
  • Loading branch information
khoih-prog authored Jan 11, 2021
1 parent e8a6911 commit 6e77859
Show file tree
Hide file tree
Showing 25 changed files with 1,259 additions and 780 deletions.
279 changes: 213 additions & 66 deletions README.md

Large diffs are not rendered by default.

109 changes: 58 additions & 51 deletions examples/Argument_None/Argument_None.ino
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
/****************************************************************************************************************************
Argument_None.ino
For SAM DUE boards
Written by Khoi Hoang
Argument_None.ino
For SAM DUE boards
Written by Khoi Hoang
Built by Khoi Hoang https://github.com/khoih-prog/SAMDUE_TimerInterrupt
Licensed under MIT license
Built by Khoi Hoang https://github.com/khoih-prog/SAMDUE_TimerInterrupt
Licensed under MIT license
Now even you use all these new 16 ISR-based timers,with their maximum interval practically unlimited (limited only by
unsigned long miliseconds), you just consume only one SAM DUE timer and avoid conflicting with other cores' tasks.
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.
Now even you use all these new 16 ISR-based timers,with their maximum interval practically unlimited (limited only by
unsigned long miliseconds), you just consume only one SAM DUE timer and avoid conflicting with other cores' tasks.
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.
Based on SimpleTimer - A timer library for Arduino.
Author: [email protected]
Copyright (c) 2010 OTTOTECNICA Italy
Based on SimpleTimer - A timer library for Arduino.
Author: [email protected]
Copyright (c) 2010 OTTOTECNICA Italy
Based on BlynkTimer.h
Author: Volodymyr Shymanskyy
Based on BlynkTimer.h
Author: Volodymyr Shymanskyy
Version: 1.1.1
Version: 1.2.0
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.1 K Hoang 06/11/2020 Initial coding
1.1.1 K.Hoang 06/12/2020 Add Change_Interval example. Bump up version to sync with other TimerInterrupt Libraries
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.1 K Hoang 06/11/2020 Initial coding
1.1.1 K.Hoang 06/12/2020 Add Change_Interval example. Bump up version to sync with other TimerInterrupt Libraries
1.2.0 K.Hoang 10/01/2021 Add better debug feature. Optimize code and examples to reduce RAM usage
*****************************************************************************************************************************/

/*
Expand All @@ -43,9 +44,12 @@
#error This code is designed to run on SAM DUE board / platform! Please check your Tools->Board setting.
#endif

// These define's must be placed at the beginning before #include "SAMDTimerInterrupt.h"
// Don't define SAMDUE_TIMER_INTERRUPT_DEBUG > 0. Only for special ISR debugging only. Can hang the system.
#define SAMDUE_TIMER_INTERRUPT_DEBUG 1
// These define's must be placed at the beginning before #include "SAMDUETimerInterrupt.h"
// _TIMERINTERRUPT_LOGLEVEL_ from 0 to 4
// Don't define _TIMERINTERRUPT_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system.
// Don't define TIMER_INTERRUPT_DEBUG > 2. Only for special ISR debugging only. Can hang the system.
#define TIMER_INTERRUPT_DEBUG 0
#define _TIMERINTERRUPT_LOGLEVEL_ 0

#include "SAMDUETimerInterrupt.h"

Expand All @@ -71,88 +75,94 @@ volatile uint32_t preMillisTimer1 = 0;
volatile uint32_t preMillisTimer2 = 0;
volatile uint32_t preMillisTimer3 = 0;

void TimerHandler0(void)
void TimerHandler0()
{
static bool toggle = false;
static bool toggle0 = false;
static bool started = false;
static uint32_t curMillis = 0;


if (!started)
{
started = true;
pinMode(LED_BUILTIN, OUTPUT);
}

#if (SAMDUE_TIMER_INTERRUPT_DEBUG > 0)
#if (TIMER_INTERRUPT_DEBUG > 0)
static uint32_t curMillis = 0;

curMillis = millis();

if (curMillis > TIMER0_INTERVAL_MS)
{
Serial.println("ITimer0: millis() = " + String(curMillis) + ", delta = " + String(curMillis - preMillisTimer0));
Serial.print("ITimer0: millis() = "); Serial.print(curMillis);
Serial.print(", delta = "); Serial.println(curMillis - preMillisTimer0);
}

preMillisTimer0 = curMillis;
#endif

//timer interrupt toggles pin LED_BUILTIN
digitalWrite(LED_BUILTIN, toggle);
toggle = !toggle;
digitalWrite(LED_BUILTIN, toggle0);
toggle0 = !toggle0;
}

void TimerHandler1(void)
void TimerHandler1()
{
static bool toggle = false;
static bool toggle1 = false;
static bool started = false;
static uint32_t curMillis = 0;

if (!started)
{
started = true;
pinMode(LED_BLUE, OUTPUT);
}

#if (SAMDUE_TIMER_INTERRUPT_DEBUG > 0)
#if (TIMER_INTERRUPT_DEBUG > 0)
static uint32_t curMillis = 0;

curMillis = millis();

if (curMillis > TIMER1_INTERVAL_MS)
{
Serial.println("ITimer1: millis() = " + String(curMillis) + ", delta = " + String(curMillis - preMillisTimer1));
Serial.print("ITimer1: millis() = "); Serial.print(curMillis);
Serial.print(", delta = "); Serial.println(curMillis - preMillisTimer1);
}

preMillisTimer1 = curMillis;
#endif

//timer interrupt toggles outputPin
digitalWrite(LED_BLUE, toggle);
toggle = !toggle;
digitalWrite(LED_BLUE, toggle1);
toggle1 = !toggle1;
}

void TimerHandler2(void)
void TimerHandler2()
{
#if (SAMDUE_TIMER_INTERRUPT_DEBUG > 0)
#if (TIMER_INTERRUPT_DEBUG > 0)
static uint32_t curMillis = 0;

curMillis = millis();

if (curMillis > TIMER2_INTERVAL_MS)
{
Serial.println("ITimer2: millis() = " + String(curMillis) + ", delta = " + String(curMillis - preMillisTimer2));
Serial.print("ITimer2: millis() = "); Serial.print(curMillis);
Serial.print(", delta = "); Serial.println(curMillis - preMillisTimer2);
}

preMillisTimer2 = curMillis;
#endif
}

void TimerHandler3(void)
void TimerHandler3()
{
#if (SAMDUE_TIMER_INTERRUPT_DEBUG > 0)
#if (TIMER_INTERRUPT_DEBUG > 0)
static uint32_t curMillis = 0;

curMillis = millis();

if (curMillis > TIMER3_INTERVAL_MS)
{
Serial.println("ITimer3: millis() = " + String(curMillis) + ", delta = " + String(curMillis - preMillisTimer3));
Serial.print("ITimer3: millis() = "); Serial.print(curMillis);
Serial.print(", delta = "); Serial.println(curMillis - preMillisTimer3);
}

preMillisTimer3 = curMillis;
Expand All @@ -167,10 +177,7 @@ uint16_t attachDueInterrupt(double microseconds, timerCallback callback, const c

uint16_t timerNumber = dueTimerInterrupt.getTimerNumber();

Serial.print(TimerName);
Serial.print(" attached to Timer(");
Serial.print(timerNumber);
Serial.println(")");
Serial.print(TimerName); Serial.print(F(" attached to Timer(")); Serial.print(timerNumber); Serial.println(F(")"));

return timerNumber;
}
Expand All @@ -182,10 +189,10 @@ void setup()

delay(100);

Serial.println("\nStarting Argument_None on " + String(BOARD_NAME));
Serial.print(F("\nStarting Argument_None on ")); Serial.println(BOARD_NAME);
Serial.println(SAMDUE_TIMER_INTERRUPT_VERSION);
Serial.println("CPU Frequency = " + String(F_CPU / 1000000) + " MHz");
Serial.println("Timer Frequency = " + String(SystemCoreClock / 1000000) + " MHz");
Serial.print(F("CPU Frequency = ")); Serial.print(F_CPU / 1000000); Serial.println(F(" MHz"));
Serial.print(F("Timer Frequency = ")); Serial.print(SystemCoreClock / 1000000); Serial.println(F(" MHz"));

// Interval in microsecs
uint32_t curMillis = millis();
Expand Down
83 changes: 41 additions & 42 deletions examples/Change_Interval/Change_Interval.ino
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
/****************************************************************************************************************************
Change_Interval.ino
For SAM DUE boards
Written by Khoi Hoang
Change_Interval.ino
For SAM DUE boards
Written by Khoi Hoang
Built by Khoi Hoang https://github.com/khoih-prog/SAMDUE_TimerInterrupt
Licensed under MIT license
Built by Khoi Hoang https://github.com/khoih-prog/SAMDUE_TimerInterrupt
Licensed under MIT license
Now even you use all these new 16 ISR-based timers,with their maximum interval practically unlimited (limited only by
unsigned long miliseconds), you just consume only one SAM DUE timer and avoid conflicting with other cores' tasks.
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.
Now even you use all these new 16 ISR-based timers,with their maximum interval practically unlimited (limited only by
unsigned long miliseconds), you just consume only one SAM DUE timer and avoid conflicting with other cores' tasks.
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.
Based on SimpleTimer - A timer library for Arduino.
Author: [email protected]
Copyright (c) 2010 OTTOTECNICA Italy
Based on SimpleTimer - A timer library for Arduino.
Author: [email protected]
Copyright (c) 2010 OTTOTECNICA Italy
Based on BlynkTimer.h
Author: Volodymyr Shymanskyy
Based on BlynkTimer.h
Author: Volodymyr Shymanskyy
Version: 1.1.1
Version: 1.2.0
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.1 K Hoang 06/11/2020 Initial coding
1.1.1 K.Hoang 06/12/2020 Add Change_Interval example. Bump up version to sync with other TimerInterrupt Libraries
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.1 K Hoang 06/11/2020 Initial coding
1.1.1 K.Hoang 06/12/2020 Add Change_Interval example. Bump up version to sync with other TimerInterrupt Libraries
1.2.0 K.Hoang 10/01/2021 Add better debug feature. Optimize code and examples to reduce RAM usage
*****************************************************************************************************************************/

/*
Expand All @@ -43,9 +44,12 @@
#error This code is designed to run on SAM DUE board / platform! Please check your Tools->Board setting.
#endif

// These define's must be placed at the beginning before #include "SAMDTimerInterrupt.h"
// Don't define SAMDUE_TIMER_INTERRUPT_DEBUG > 0. Only for special ISR debugging only. Can hang the system.
#define SAMDUE_TIMER_INTERRUPT_DEBUG 1
// These define's must be placed at the beginning before #include "SAMDUETimerInterrupt.h"
// _TIMERINTERRUPT_LOGLEVEL_ from 0 to 4
// Don't define _TIMERINTERRUPT_LOGLEVEL_ > 0. Only for special ISR debugging only. Can hang the system.
// Don't define TIMER_INTERRUPT_DEBUG > 2. Only for special ISR debugging only. Can hang the system.
#define TIMER_INTERRUPT_DEBUG 0
#define _TIMERINTERRUPT_LOGLEVEL_ 0

#include "SAMDUETimerInterrupt.h"

Expand All @@ -66,13 +70,14 @@

volatile uint32_t Timer0Count = 0;
volatile uint32_t Timer1Count = 0;

void printResult(uint32_t currTime)
{
Serial.println("Time = " + String(currTime) + ", Timer0Count = " + String(Timer0Count) + ", Timer1Count = " + String(Timer1Count));
Serial.print(F("Time = ")); Serial.print(currTime);
Serial.print(F(", Timer0Count = ")); Serial.print(Timer0Count);
Serial.print(F(", Timer1Count = ")); Serial.println(Timer1Count);
}

void TimerHandler0(void)
void TimerHandler0()
{
static bool toggle0 = false;

Expand All @@ -84,7 +89,7 @@ void TimerHandler0(void)
toggle0 = !toggle0;
}

void TimerHandler1(void)
void TimerHandler1()
{
static bool toggle1 = false;

Expand All @@ -107,10 +112,7 @@ uint16_t attachDueInterrupt(double microseconds, timerCallback callback, const c

uint16_t timerNumber = dueTimerInterrupt.getTimerNumber();

Serial.print(TimerName);
Serial.print(" attached to Timer(");
Serial.print(timerNumber);
Serial.println(")");
Serial.print(TimerName); Serial.print(F(" attached to Timer(")); Serial.print(timerNumber); Serial.println(F(")"));

return timerNumber;
}
Expand All @@ -123,10 +125,7 @@ uint16_t updateTimerInterval(uint16_t timerNumberInput, double microseconds, tim

uint16_t timerNumber = dueTimerInterrupt.getTimerNumber();

Serial.print(TimerName);
Serial.print(" attached to Timer(");
Serial.print(timerNumber);
Serial.println(")");
Serial.print(TimerName); Serial.print(F(" attached to Timer(")); Serial.print(timerNumber); Serial.println(F(")"));

return timerNumber;
}
Expand All @@ -140,11 +139,11 @@ void setup()
while (!Serial);

delay(100);

Serial.println("\nStarting Change_Interval on " + String(BOARD_NAME));
Serial.print(F("\nStarting Change_Interval on ")); Serial.println(BOARD_NAME);
Serial.println(SAMDUE_TIMER_INTERRUPT_VERSION);
Serial.println("CPU Frequency = " + String(F_CPU / 1000000) + " MHz");
Serial.println("Timer Frequency = " + String(SystemCoreClock / 1000000) + " MHz");
Serial.print(F("CPU Frequency = ")); Serial.print(F_CPU / 1000000); Serial.println(F(" MHz"));
Serial.print(F("Timer Frequency = ")); Serial.print(SystemCoreClock / 1000000); Serial.println(F(" MHz"));

// Interval in microsecs
timerNumber0 = attachDueInterrupt(TIMER0_INTERVAL_MS * 1000, TimerHandler0, "ITimer0");
Expand Down Expand Up @@ -175,9 +174,9 @@ void loop()

updateTimerInterval(timerNumber0, TIMER0_INTERVAL_MS * 1000 * (multFactor + 1), TimerHandler0, "ITimer0");
updateTimerInterval(timerNumber1, TIMER1_INTERVAL_MS * 1000 * (multFactor + 1), TimerHandler1, "ITimer1");
Serial.println("Changing Interval, Timer0 = " + String(TIMER0_INTERVAL_MS * (multFactor + 1)) +
", Timer1 = " + String(TIMER1_INTERVAL_MS * (multFactor + 1)));

Serial.print(F("Changing Interval, Timer0 = ")); Serial.print(TIMER0_INTERVAL_MS * (multFactor + 1));
Serial.print(F(", Timer1 = ")); Serial.println(TIMER1_INTERVAL_MS * (multFactor + 1));

lastChangeTime = currTime;
}
Expand Down
Loading

0 comments on commit 6e77859

Please sign in to comment.