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 46a540a commit d8df380
Show file tree
Hide file tree
Showing 27 changed files with 1,559 additions and 922 deletions.
373 changes: 297 additions & 76 deletions README.md

Large diffs are not rendered by default.

88 changes: 47 additions & 41 deletions examples/Argument_None/Argument_None.ino
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
/****************************************************************************************************************************
Argument_None.ino
For NRF52 boards
Written by Khoi Hoang
Built by Khoi Hoang https://github.com/khoih-prog/NRF52_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 NRF52 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: mromani@ottotecnica.com
Copyright (c) 2010 OTTOTECNICA Italy
Based on BlynkTimer.h
Author: Volodymyr Shymanskyy
Version: 1.1.1
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.0 K Hoang 02/11/2020 Initial coding
1.0.1 K Hoang 06/11/2020 Add complicated example ISR_16_Timers_Array using all 16 independent ISR Timers.
1.0.2 K Hoang 24/11/2020 Add complicated example ISR_16_Timers_Array_Complex and optimize examples
1.1.1 K.Hoang 06/12/2020 Add Change_Interval example. Bump up version to sync with other TimerInterrupt Libraries
Argument_None.ino
For NRF52 boards
Written by Khoi Hoang
Built by Khoi Hoang https://github.com/khoih-prog/NRF52_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 NRF52 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: mromani@ottotecnica.com
Copyright (c) 2010 OTTOTECNICA Italy
Based on BlynkTimer.h
Author: Volodymyr Shymanskyy
Version: 1.2.0
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.0 K Hoang 02/11/2020 Initial coding
1.0.1 K Hoang 06/11/2020 Add complicated example ISR_16_Timers_Array using all 16 independent ISR Timers.
1.0.2 K Hoang 24/11/2020 Add complicated example ISR_16_Timers_Array_Complex and optimize examples
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 11/01/2021 Add better debug feature. Optimize code and examples to reduce RAM usage
*****************************************************************************************************************************/

/*
Expand All @@ -49,8 +50,11 @@
#endif

// These define's must be placed at the beginning before #include "NRF52TimerInterrupt.h"
// Don't define NRF52_TIMER_INTERRUPT_DEBUG > 2. Only for special ISR debugging only. Can hang the system.
#define NRF52_TIMER_INTERRUPT_DEBUG 1
// _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 "NRF52TimerInterrupt.h"

Expand Down Expand Up @@ -86,10 +90,12 @@ volatile uint32_t Timer1Count = 0;

void printResult(uint32_t currTime)
{
Serial.printf("Time = %ld, Timer0Count = %lu, , Timer1Count = %lu\n", currTime, Timer0Count, 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 @@ -101,7 +107,7 @@ void TimerHandler0(void)
toggle0 = !toggle0;
}

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

Expand All @@ -122,26 +128,26 @@ void setup()
while (!Serial);

delay(100);

Serial.printf("\nStarting Argument_None on %s\n", BOARD_NAME);
Serial.print(F("\nStarting Argument_None on ")); Serial.println(BOARD_NAME);
Serial.println(NRF52_TIMER_INTERRUPT_VERSION);
Serial.printf("CPU Frequency = %ld MHz\n", F_CPU / 1000000);
Serial.print(F("CPU Frequency = ")); Serial.print(F_CPU / 1000000); Serial.println(F(" MHz"));

// Interval in microsecs
if (ITimer0.attachInterruptInterval(TIMER0_INTERVAL_MS * 1000, TimerHandler0))
{
Serial.printf("Starting ITimer0 OK, millis() = %ld\n", millis());
Serial.print(F("Starting ITimer0 OK, millis() = ")); Serial.println(millis());
}
else
Serial.println("Can't set ITimer0. Select another freq. or timer");
Serial.println(F("Can't set ITimer0. Select another freq. or timer"));

// Interval in microsecs
if (ITimer1.attachInterruptInterval(TIMER1_INTERVAL_MS * 1000, TimerHandler1))
{
Serial.printf("Starting ITimer1 OK, millis() = %ld\n", millis());
Serial.print(F("Starting ITimer1 OK, millis() = ")); Serial.println(millis());
}
else
Serial.println("Can't set ITimer1. Select another freq. or timer");
Serial.println(F("Can't set ITimer1. Select another freq. or timer"));
}

#define CHECK_INTERVAL_MS 10000L
Expand Down
91 changes: 49 additions & 42 deletions examples/Change_Interval/Change_Interval.ino
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
/****************************************************************************************************************************
Change_Interval.ino
For NRF52 boards
Written by Khoi Hoang
Built by Khoi Hoang https://github.com/khoih-prog/NRF52_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 NRF52 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: mromani@ottotecnica.com
Copyright (c) 2010 OTTOTECNICA Italy
Based on BlynkTimer.h
Author: Volodymyr Shymanskyy
Version: 1.1.1
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.0 K Hoang 02/11/2020 Initial coding
1.0.1 K Hoang 06/11/2020 Add complicated example ISR_16_Timers_Array using all 16 independent ISR Timers.
1.0.2 K Hoang 24/11/2020 Add complicated example ISR_16_Timers_Array_Complex and optimize examples
1.1.1 K.Hoang 06/12/2020 Add Change_Interval example. Bump up version to sync with other TimerInterrupt Libraries
Change_Interval.ino
For NRF52 boards
Written by Khoi Hoang
Built by Khoi Hoang https://github.com/khoih-prog/NRF52_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 NRF52 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: mromani@ottotecnica.com
Copyright (c) 2010 OTTOTECNICA Italy
Based on BlynkTimer.h
Author: Volodymyr Shymanskyy
Version: 1.2.0
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.0 K Hoang 02/11/2020 Initial coding
1.0.1 K Hoang 06/11/2020 Add complicated example ISR_16_Timers_Array using all 16 independent ISR Timers.
1.0.2 K Hoang 24/11/2020 Add complicated example ISR_16_Timers_Array_Complex and optimize examples
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 11/01/2021 Add better debug feature. Optimize code and examples to reduce RAM usage
*****************************************************************************************************************************/

/*
Expand All @@ -49,8 +50,11 @@
#endif

// These define's must be placed at the beginning before #include "NRF52TimerInterrupt.h"
// Don't define NRF52_TIMER_INTERRUPT_DEBUG > 2. Only for special ISR debugging only. Can hang the system.
#define NRF52_TIMER_INTERRUPT_DEBUG 0
// _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 "NRF52TimerInterrupt.h"

Expand Down Expand Up @@ -83,10 +87,12 @@ NRF52Timer ITimer1(NRF_TIMER_3);

void printResult(uint32_t currTime)
{
Serial.printf("Time = %ld, Timer0Count = %lu, , Timer1Count = %lu\n", currTime, Timer0Count, 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 @@ -98,7 +104,7 @@ void TimerHandler0(void)
toggle0 = !toggle0;
}

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

Expand All @@ -119,26 +125,26 @@ void setup()
while (!Serial);

delay(100);

Serial.printf("\nStarting Change_Interval on %s\n", BOARD_NAME);
Serial.print(F("\nStarting Change_Interval on ")); Serial.println(BOARD_NAME);
Serial.println(NRF52_TIMER_INTERRUPT_VERSION);
Serial.printf("CPU Frequency = %ld MHz\n", F_CPU / 1000000);
Serial.print(F("CPU Frequency = ")); Serial.print(F_CPU / 1000000); Serial.println(F(" MHz"));

// Interval in microsecs
if (ITimer0.attachInterruptInterval(TIMER0_INTERVAL_MS * 1000, TimerHandler0))
{
Serial.printf("Starting ITimer0 OK, millis() = %ld\n", millis());
Serial.print(F("Starting ITimer0 OK, millis() = ")); Serial.println(millis());
}
else
Serial.println("Can't set ITimer0. Select another freq. or timer");
Serial.println(F("Can't set ITimer0. Select another freq. or timer"));

// Interval in microsecs
if (ITimer1.attachInterruptInterval(TIMER1_INTERVAL_MS * 1000, TimerHandler1))
{
Serial.printf("Starting ITimer1 OK, millis() = %ld\n", millis());
Serial.print(F("Starting ITimer1 OK, millis() = ")); Serial.println(millis());
}
else
Serial.println("Can't set ITimer1. Select another freq. or timer");
Serial.println(F("Can't set ITimer1. Select another freq. or timer"));
}

#define CHECK_INTERVAL_MS 10000L
Expand Down Expand Up @@ -166,8 +172,9 @@ void loop()
ITimer0.setInterval(TIMER0_INTERVAL_MS * 1000 * (multFactor + 1), TimerHandler0);
ITimer1.setInterval(TIMER1_INTERVAL_MS * 1000 * (multFactor + 1), TimerHandler1);

Serial.printf("Changing Interval, Timer0 = %lu, Timer1 = %lu\n", TIMER0_INTERVAL_MS * (multFactor + 1), 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 d8df380

Please sign in to comment.