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

Commit

Permalink
v1.101 using float for interval
Browse files Browse the repository at this point in the history
### Releases v1.10.1

1. Using `float` instead of `ulong` for interval
2. Prevent overflow of SAMD51 TCx by flagging error
  • Loading branch information
khoih-prog committed Sep 29, 2022
1 parent f56782b commit 1d1ea84
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 32 deletions.
15 changes: 8 additions & 7 deletions README.md
Expand Up @@ -617,7 +617,7 @@ While software timer, **programmed for 2s, is activated after 7.937s !!!**. Then

```
Starting ISR_Timer_Complex_WiFiNINA on SAMD_NANO_33_IOT
SAMDTimerInterrupt v1.10.0
SAMDTimerInterrupt v1.10.1
CPU Frequency = 48 MHz
[TISR] SAMDTimerInterrupt: F_CPU (MHz) = 48 , TIMER_HZ = 48
[TISR] TC_Timer::startTimer _Timer = 0x 42002c00 , TC3 = 0x 42002c00
Expand Down Expand Up @@ -682,7 +682,7 @@ The following is the sample terminal output when running example [**TimerInterru

```
Starting TimerInterruptTest on ITSYBITSY_M4
SAMDTimerInterrupt v1.10.0
SAMDTimerInterrupt v1.10.1
CPU Frequency = 48 MHz
[TISR] SAMDTimerInterrupt: F_CPU (MHz) = 120 , TIMER_HZ = 48
[TISR] TC_Timer::startTimer _Timer = 0x 0x4101c000 , TC3 = 0x 0x4101c000
Expand Down Expand Up @@ -760,7 +760,7 @@ The following is the sample terminal output when running example [**Argument_Non

```
Starting Argument_None on SAMD_NANO_33_IOT
SAMDTimerInterrupt v1.10.0
SAMDTimerInterrupt v1.10.1
CPU Frequency = 48 MHz
[TISR] SAMDTimerInterrupt: F_CPU (MHz) = 48 , TIMER_HZ = 48
[TISR] TC_Timer::startTimer _Timer = 0x 42002c00 , TC3 = 0x 42002c00
Expand Down Expand Up @@ -810,7 +810,7 @@ In this example, 16 independent ISR Timers are used, yet utilized just one Hardw

```
Starting ISR_16_Timers_Array on SAMD_NANO_33_IOT
SAMDTimerInterrupt v1.10.0
SAMDTimerInterrupt v1.10.1
CPU Frequency = 48 MHz
[TISR] SAMDTimerInterrupt: F_CPU (MHz) = 48 , TIMER_HZ = 48
[TISR] TC_Timer::startTimer _Timer = 0x 42002c00 , TC3 = 0x 42002c00
Expand Down Expand Up @@ -934,7 +934,7 @@ The following is the sample terminal output when running example [Change_Interva

```
Starting Change_Interval on SAMD_NANO_33_IOT
SAMDTimerInterrupt v1.10.0
SAMDTimerInterrupt v1.10.1
CPU Frequency = 48 MHz
[TISR] SAMDTimerInterrupt: F_CPU (MHz) = 48 , TIMER_HZ = 48
[TISR] TC_Timer::startTimer _Timer = 0x 42002c00 , TC3 = 0x 42002c00
Expand Down Expand Up @@ -998,7 +998,7 @@ The following is the sample terminal output when running example [RepeatedAttach

```
Starting RepeatedAttachInterrupt_uS on SEEED_XIAO_M0
SAMDTimerInterrupt v1.10.0
SAMDTimerInterrupt v1.10.1
CPU Frequency = 48 MHz
[TISR] _period = 19995 , frequency = 50.01
[TISR] SAMDTimerInterrupt: F_CPU (MHz) = 48 , TIMER_HZ = 48
Expand Down Expand Up @@ -1065,7 +1065,7 @@ The following is the sample terminal output when running example [SAMD21_MultiTi

```
Starting SAMD21_MultiTimers on SAMD_NANO_33_IOT
SAMDTimerInterrupt v1.10.0
SAMDTimerInterrupt v1.10.1
CPU Frequency = 48 MHz
[TISR] _period = 20000.00 , frequency = 50.00
[TISR] _timerNumber = 0
Expand Down Expand Up @@ -1181,6 +1181,7 @@ Submit issues to: [SAMD_TimerInterrupt issues](https://github.com/khoih-prog/SAM
13. Add functions `attachInterruptInterval_MS()` and `setInterval_MS()`
14. Avoid conflict with Servo library. Check [Cannot use TimerInterrupt_Generic Library in the same time than Servo Library #11](https://github.com/khoih-prog/TimerInterrupt_Generic/discussions/11)
15. Prevent overflow of TCx by flagging error
16. Using float instead of ulong for interval

---
---
Expand Down
8 changes: 7 additions & 1 deletion changelog.md
Expand Up @@ -12,6 +12,7 @@
## Table of Contents

* [Changelog](#changelog)
* [Releases v1.10.1](#releases-v1101)
* [Releases v1.10.0](#releases-v1100)
* [Releases v1.9.0](#releases-v190)
* [Releases v1.8.0](#releases-v180)
Expand All @@ -32,10 +33,15 @@

## Changelog

### Releases v1.10.1

1. Using float instead of ulong for interval
2. Prevent overflow of SAMD51 TCx by flagging error

### Releases v1.10.0

1. Avoid conflict with Servo library. Check [Cannot use TimerInterrupt_Generic Library in the same time than Servo Library #11](https://github.com/khoih-prog/TimerInterrupt_Generic/discussions/11)
2. Prevent overflow of TCx by flagging error
2. Prevent overflow of SAMD21 TCx by flagging error
3. Modify all examples
4. Update `Packages_Patches`

Expand Down
2 changes: 1 addition & 1 deletion library.json
@@ -1,6 +1,6 @@
{
"name": "SAMD_TimerInterrupt",
"version": "1.10.0",
"version": "1.10.1",
"keywords": "timing, device, control, timer, interrupt, hardware, isr, isr-based, hardware-timer, isr-timer, isr-based-timer, mission-critical, accuracy, precise, non-blocking, samd, samd21, samd51, nano-33-iot",
"description": "This library enables you to use Interrupt from Hardware Timers on SAMD-based boards. 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 executions are not blocked by bad-behaving functions or tasks. This important feature is absolutely necessary for mission-critical tasks. 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. SAMD21 now can use 6 Timers",
"authors":
Expand Down
2 changes: 1 addition & 1 deletion library.properties
@@ -1,5 +1,5 @@
name=SAMD_TimerInterrupt
version=1.10.0
version=1.10.1
author=Khoi Hoang <khoih.prog@gmail.com>
maintainer=Khoi Hoang <khoih.prog@gmail.com>
sentence=This library enables you to use Interrupt from Hardware Timers on SAMD-based boards such as SAMD21 Nano-33-IoT, Adafruit SAMD51 Itsy-Bitsy M4, SeeedStudio XIAO, Sparkfun SAMD51_MICROMOD, etc.
Expand Down
3 changes: 2 additions & 1 deletion src/SAMDTimerInterrupt.h
Expand Up @@ -16,7 +16,7 @@
Based on BlynkTimer.h
Author: Volodymyr Shymanskyy
Version: 1.10.0
Version: 1.10.1
Version Modified By Date Comments
------- ----------- ---------- -----------
Expand All @@ -33,6 +33,7 @@
1.8.0 K.Hoang 07/05/2022 Scrap the buggy code in v1.7.0 for TC3
1.9.0 K.Hoang 08/05/2022 Add TC4, TC5, TCC1 and TCC2 Timers to SAMD21
1.10.0 K.Hoang 29/09/2022 Avoid conflict with Servo library. Modify all examples. Prevent overflow of TCx
1.10.1 K.Hoang 30/09/2022 Using float instead of ulong for interval. Prevent overflow of SAMD51 TCx
*****************************************************************************************************************************/
/*
SAMD21
Expand Down
27 changes: 14 additions & 13 deletions src/SAMDTimerInterrupt.hpp
Expand Up @@ -15,8 +15,8 @@
Copyright (c) 2010 OTTOTECNICA Italy
Based on BlynkTimer.h
Author: Volodymyr Shymanskyy
Version: 1.10.0
Version: 1.10.1
Version Modified By Date Comments
------- ----------- ---------- -----------
Expand All @@ -33,6 +33,7 @@
1.8.0 K.Hoang 07/05/2022 Scrap the buggy code in v1.7.0 for TC3
1.9.0 K.Hoang 08/05/2022 Add TC4, TC5, TCC1 and TCC2 Timers to SAMD21
1.10.0 K.Hoang 29/09/2022 Avoid conflict with Servo library. Modify all examples. Prevent overflow of TCx
1.10.1 K.Hoang 30/09/2022 Using float instead of ulong for interval. Prevent overflow of SAMD51 TCx
*****************************************************************************************************************************/
/*
SAMD21
Expand Down Expand Up @@ -155,13 +156,13 @@
#include "Arduino.h"

#ifndef SAMD_TIMER_INTERRUPT_VERSION
#define SAMD_TIMER_INTERRUPT_VERSION "SAMDTimerInterrupt v1.10.0"
#define SAMD_TIMER_INTERRUPT_VERSION "SAMDTimerInterrupt v1.10.1"

#define SAMD_TIMER_INTERRUPT_VERSION_MAJOR 1
#define SAMD_TIMER_INTERRUPT_VERSION_MINOR 10
#define SAMD_TIMER_INTERRUPT_VERSION_PATCH 0
#define SAMD_TIMER_INTERRUPT_VERSION_PATCH 1

#define SAMD_TIMER_INTERRUPT_VERSION_INT 1010000
#define SAMD_TIMER_INTERRUPT_VERSION_INT 1010001
#endif

#include "TimerInterrupt_Generic_Debug.h"
Expand Down Expand Up @@ -245,7 +246,7 @@ class SAMDTimerInterrupt

// interval (in microseconds) and duration (in milliseconds). Duration = 0 or not specified => run indefinitely
// No params and duration now. To be added in the future by adding similar functions here or to SAMD-hal-timer.c
bool setInterval(const unsigned long& interval, timerCallback callback)
bool setInterval(const float& interval, timerCallback callback)
{
return setFrequency((float) (1000000.0f / interval), callback);
}
Expand All @@ -254,7 +255,7 @@ class SAMDTimerInterrupt

// interval (in milliseconds) and duration (in milliseconds). Duration = 0 or not specified => run indefinitely
// No params and duration now. To be added in the future by adding similar functions here or to SAMD-hal-timer.c
bool setInterval_MS(const unsigned long& interval, timerCallback callback)
bool setInterval_MS(const float& interval, timerCallback callback)
{
return setFrequency((float) (1000.0f / interval), callback);
}
Expand All @@ -270,7 +271,7 @@ class SAMDTimerInterrupt

// interval (in microseconds) and duration (in milliseconds). Duration = 0 or not specified => run indefinitely
// No params and duration now. To be added in the future by adding similar functions here or to SAMD-hal-timer.c
bool attachInterruptInterval(const unsigned long& interval, timerCallback callback)
bool attachInterruptInterval(const float& interval, timerCallback callback)
{
return setFrequency( (float) ( 1000000.0f / interval), callback);
}
Expand All @@ -279,7 +280,7 @@ class SAMDTimerInterrupt

// interval (in milliseconds) and duration (in milliseconds). Duration = 0 or not specified => run indefinitely
// No params and duration now. To be added in the future by adding similar functions here or to SAMD-hal-timer.c
bool attachInterruptInterval_MS(const unsigned long& interval, timerCallback callback)
bool attachInterruptInterval_MS(const float& interval, timerCallback callback)
{
return setFrequency( (float) ( 1000.0f / interval), callback);
}
Expand Down Expand Up @@ -545,7 +546,7 @@ class SAMDTimerInterrupt

// interval (in microseconds) and duration (in milliseconds). Duration = 0 or not specified => run indefinitely
// No params and duration now. To be added in the future by adding similar functions here or to SAMD-hal-timer.c
bool setInterval(const unsigned long& interval, timerCallback callback)
bool setInterval(const float& interval, timerCallback callback)
{
return setFrequency((float) (1000000.0f / interval), callback);
}
Expand All @@ -554,7 +555,7 @@ class SAMDTimerInterrupt

// interval (in milliseconds) and duration (in milliseconds). Duration = 0 or not specified => run indefinitely
// No params and duration now. To be added in the future by adding similar functions here or to SAMD-hal-timer.c
bool setInterval_MS(const unsigned long& interval, timerCallback callback)
bool setInterval_MS(const float& interval, timerCallback callback)
{
return setFrequency((float) (1000.0f / interval), callback);
}
Expand All @@ -570,7 +571,7 @@ class SAMDTimerInterrupt

// interval (in microseconds) and duration (in milliseconds). Duration = 0 or not specified => run indefinitely
// No params and duration now. To be added in the future by adding similar functions here or to SAMD-hal-timer.c
bool attachInterruptInterval(const unsigned long& interval, timerCallback callback)
bool attachInterruptInterval(const float& interval, timerCallback callback)
{
return setFrequency( (float) ( 1000000.0f / interval), callback);
}
Expand All @@ -579,7 +580,7 @@ class SAMDTimerInterrupt

// interval (in milliseconds) and duration (in milliseconds). Duration = 0 or not specified => run indefinitely
// No params and duration now. To be added in the future by adding similar functions here or to SAMD-hal-timer.c
bool attachInterruptInterval_MS(const unsigned long& interval, timerCallback callback)
bool attachInterruptInterval_MS(const float& interval, timerCallback callback)
{
return setFrequency( (float) ( 1000.0f / interval), callback);
}
Expand Down
22 changes: 17 additions & 5 deletions src/SAMDTimerInterrupt_Impl.h
Expand Up @@ -15,8 +15,8 @@
Copyright (c) 2010 OTTOTECNICA Italy
Based on BlynkTimer.h
Author: Volodymyr Shymanskyy
Version: 1.10.0
Version: 1.10.1
Version Modified By Date Comments
------- ----------- ---------- -----------
Expand All @@ -33,6 +33,7 @@
1.8.0 K.Hoang 07/05/2022 Scrap the buggy code in v1.7.0 for TC3
1.9.0 K.Hoang 08/05/2022 Add TC4, TC5, TCC1 and TCC2 Timers to SAMD21
1.10.0 K.Hoang 29/09/2022 Avoid conflict with Servo library. Modify all examples. Prevent overflow of TCx
1.10.1 K.Hoang 30/09/2022 Using float instead of ulong for interval. Prevent overflow of SAMD51 TCx
*****************************************************************************************************************************/
/*
SAMD21
Expand Down Expand Up @@ -84,6 +85,16 @@
{
TISR_LOGWARN3(F("SAMDTimerInterrupt: F_CPU (MHz) ="), F_CPU/1000000, F(", TIMER_HZ ="), TIMER_HZ/1000000);
TISR_LOGWARN3(F("TC_Timer::startTimer _Timer = 0x"), String((uint32_t) _SAMDTimer, HEX), F(", TC3 = 0x"), String((uint32_t) TC3, HEX));

// maxPermittedPeriod = 1,398,101.33us for 48MHz timer clock
float maxPermittedPeriod = (65536.0f * 1024) / (TIMER_HZ / 1000000.0f );

if (_period > maxPermittedPeriod )
{
TISR_LOGERROR3(F("Max permissible _period (us) ="), maxPermittedPeriod, F(", current _period (us) ="), _period);

return false;
}

// Enable the TC bus clock, use clock generator 0
GCLK->PCHCTRL[TC3_GCLK_ID].reg = GCLK_PCHCTRL_GEN_GCLK1_Val | (1 << GCLK_PCHCTRL_CHEN_Pos);
Expand All @@ -108,7 +119,7 @@
TC3_callback = callback;

setPeriod_TIMER_TC3(_period);

return true;
}
else
Expand Down Expand Up @@ -273,12 +284,13 @@
{
TISR_LOGDEBUG1(F("_timerNumber ="), _timerNumber);

// maxPermittedPeriod = 1,398,101.33us for 48MHz clock
float maxPermittedPeriod = (65536.0f * 1024) / (F_CPU / 1000000.0f );
// maxPermittedPeriod = 1,398,101.33us for 48MHz timer clock
float maxPermittedPeriod = (65536.0f * 1024) / (TIMER_HZ / 1000000.0f );

if (_period > maxPermittedPeriod )
{
TISR_LOGERROR3(F("Max permissible _period (us) ="), maxPermittedPeriod, F(", current _period (us) ="), _period);

return false;
}

Expand Down
3 changes: 2 additions & 1 deletion src/SAMD_ISR_Timer-Impl.h
Expand Up @@ -19,7 +19,7 @@
Based on BlynkTimer.h
Author: Volodymyr Shymanskyy
Version: 1.10.0
Version: 1.10.1
Version Modified By Date Comments
------- ----------- ---------- -----------
Expand All @@ -36,6 +36,7 @@
1.8.0 K.Hoang 07/05/2022 Scrap the buggy code in v1.7.0 for TC3
1.9.0 K.Hoang 08/05/2022 Add TC4, TC5, TCC1 and TCC2 Timers to SAMD21
1.10.0 K.Hoang 29/09/2022 Avoid conflict with Servo library. Modify all examples. Prevent overflow of TCx
1.10.1 K.Hoang 30/09/2022 Using float instead of ulong for interval. Prevent overflow of SAMD51 TCx
*****************************************************************************************************************************/

#pragma once
Expand Down
3 changes: 2 additions & 1 deletion src/SAMD_ISR_Timer.h
Expand Up @@ -19,7 +19,7 @@
Based on BlynkTimer.h
Author: Volodymyr Shymanskyy
Version: 1.10.0
Version: 1.10.1
Version Modified By Date Comments
------- ----------- ---------- -----------
Expand All @@ -36,6 +36,7 @@
1.8.0 K.Hoang 07/05/2022 Scrap the buggy code in v1.7.0 for TC3
1.9.0 K.Hoang 08/05/2022 Add TC4, TC5, TCC1 and TCC2 Timers to SAMD21
1.10.0 K.Hoang 29/09/2022 Avoid conflict with Servo library. Modify all examples. Prevent overflow of TCx
1.10.1 K.Hoang 30/09/2022 Using float instead of ulong for interval. Prevent overflow of SAMD51 TCx
*****************************************************************************************************************************/

#pragma once
Expand Down
3 changes: 2 additions & 1 deletion src/SAMD_ISR_Timer.hpp
Expand Up @@ -19,7 +19,7 @@
Based on BlynkTimer.h
Author: Volodymyr Shymanskyy
Version: 1.10.0
Version: 1.10.1
Version Modified By Date Comments
------- ----------- ---------- -----------
Expand All @@ -36,6 +36,7 @@
1.8.0 K.Hoang 07/05/2022 Scrap the buggy code in v1.7.0 for TC3
1.9.0 K.Hoang 08/05/2022 Add TC4, TC5, TCC1 and TCC2 Timers to SAMD21
1.10.0 K.Hoang 29/09/2022 Avoid conflict with Servo library. Modify all examples. Prevent overflow of TCx
1.10.1 K.Hoang 30/09/2022 Using float instead of ulong for interval. Prevent overflow of SAMD51 TCx
*****************************************************************************************************************************/

#pragma once
Expand Down

0 comments on commit 1d1ea84

Please sign in to comment.