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

Commit 62c003f

Browse files
authored
v1.9.0 to add more Timers to SAMD21
### Releases v1.9.0 1. Add TC4, TC5, TCC1 and TCC2 Timers to SAMD21 2. Add example [SAMD21_MultiTimers](examples/SAMD21_MultiTimers) to demo the how to use all 6 SAMD21 timers simultaneously. 3. Add functions `attachInterruptInterval_MS()` and `setInterval_MS()` 4. Rewrite examples to take advantage of new functions and timers
1 parent 8038b88 commit 62c003f

File tree

1 file changed

+117
-18
lines changed

1 file changed

+117
-18
lines changed

README.md

Lines changed: 117 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@
6363
* [ 11. **Change_Interval**](examples/Change_Interval)
6464
* [ 12. **ISR_16_Timers_Array_Complex**](examples/ISR_16_Timers_Array_Complex)
6565
* [ 13. **RepeatedAttachInterrupt_uS**](examples/RepeatedAttachInterrupt_uS)
66-
* [ 14. **multiFileProject**](examples/multiFileProject) **New**
66+
* [ 14. **multiFileProject**](examples/multiFileProject)
67+
* [ 15. **SAMD21_MultiTimers**](examples/SAMD21_MultiTimers) **New**
6768
* [Example ISR_16_Timers_Array_Complex](#example-ISR_16_Timers_Array_Complex)
6869
* [Debug Terminal Output Samples](#debug-terminal-output-samples)
6970
* [1. ISR_Timer_Complex_WiFiNINA on Arduino SAMD21 SAMD_NANO_33_IOT using WiFiNINA](#1-isr_timer_complex_wifinina-on-arduino-samd21-samd_nano_33_iot-using-wifinina)
@@ -393,10 +394,20 @@ Before using any Timer, you have to make sure the Timer has not been used by any
393394
#### 1.1 Init Hardware Timer
394395

395396
```
396-
// Depending on the board, you can select SAMD21 Hardware Timer from TC3-TCC
397-
// SAMD21 Hardware Timer from TC3 or TCC
397+
// Depending on the board, you can select SAMD21 Hardware Timer from TC3, TC4, TC5, TCC, TCC1 or TCC2
398398
// SAMD51 Hardware Timer only TC3
399-
SAMDTimer ITimer0(TIMER_TC3);
399+
400+
// Init SAMD timer TIMER_TC3
401+
SAMDTimer ITimer(TIMER_TC3);
402+
403+
#if (TIMER_INTERRUPT_USING_SAMD21)
404+
// Init SAMD timer TIMER_TCC
405+
//SAMDTimer ITimer(TIMER_TC4);
406+
//SAMDTimer ITimer(TIMER_TC5);
407+
//SAMDTimer ITimer(TIMER_TCC);
408+
//SAMDTimer ITimer(TIMER_TCC1);
409+
//SAMDTimer ITimer(TIMER_TCC2);
410+
#endif
400411
```
401412

402413
#### 1.2 Set Hardware Timer Interval and attach Timer Interrupt Handler function
@@ -413,7 +424,7 @@ void setup()
413424
....
414425
415426
// Interval in microsecs
416-
if (ITimer0.attachInterruptInterval(TIMER0_INTERVAL_MS * 1000, TimerHandler0))
427+
if (ITimer0.attachInterruptInterval_MS(TIMER0_INTERVAL_MS, TimerHandler0))
417428
Serial.println("Starting ITimer0 OK, millis() = " + String(millis()));
418429
else
419430
Serial.println("Can't set ITimer0. Select another freq. or timer");
@@ -426,10 +437,20 @@ void setup()
426437
#### 2.1 Init Hardware Timer and ISR-based Timer
427438

428439
```
429-
// Depending on the board, you can select SAMD21 Hardware Timer from TC3-TCC
430-
// SAMD21 Hardware Timer from TC3 or TCC
440+
// Depending on the board, you can select SAMD21 Hardware Timer from TC3, TC4, TC5, TCC, TCC1 or TCC2
431441
// SAMD51 Hardware Timer only TC3
432-
SAMDTimer ITimer0(TIMER_TC3);
442+
443+
// Init SAMD timer TIMER_TC3
444+
SAMDTimer ITimer(TIMER_TC3);
445+
446+
#if (TIMER_INTERRUPT_USING_SAMD21)
447+
// Init SAMD timer TIMER_TCC
448+
//SAMDTimer ITimer(TIMER_TC4);
449+
//SAMDTimer ITimer(TIMER_TC5);
450+
//SAMDTimer ITimer(TIMER_TCC);
451+
//SAMDTimer ITimer(TIMER_TCC1);
452+
//SAMDTimer ITimer(TIMER_TCC2);
453+
#endif
433454
434455
// Init SAMD_ISR_Timer
435456
// Each SAMD_ISR_Timer can service 16 different ISR-based timers
@@ -479,7 +500,7 @@ void setup()
479500
....
480501
481502
// Interval in microsecs
482-
if (ITimer.attachInterruptInterval(HW_TIMER_INTERVAL_MS * 1000, TimerHandler))
503+
if (ITimer.attachInterruptInterval_MS(HW_TIMER_INTERVAL_MS, TimerHandler))
483504
{
484505
lastMillis = millis();
485506
Serial.println("Starting ITimer OK, millis() = " + String(lastMillis));
@@ -512,18 +533,19 @@ void setup()
512533
8. [SwitchDebounce](examples/SwitchDebounce)
513534
9. [TimerInterruptTest](examples/TimerInterruptTest)
514535
10. [TimerInterruptLEDDemo](examples/TimerInterruptLEDDemo)
515-
11. [**Change_Interval**](examples/Change_Interval). New
536+
11. [**Change_Interval**](examples/Change_Interval).
516537
12. [**ISR_16_Timers_Array_Complex**](examples/ISR_16_Timers_Array_Complex).
517538
13. [**RepeatedAttachInterrupt_uS**](examples/RepeatedAttachInterrupt_uS).
518-
14. [**multiFileProject**](examples/multiFileProject). **New**
539+
14. [**multiFileProject**](examples/multiFileProject).
540+
15. [**SAMD21_MultiTimers**](examples/SAMD21_MultiTimers). **New**
519541

520542

521543
---
522544
---
523545

524546
### Example [ISR_16_Timers_Array_Complex](examples/ISR_16_Timers_Array_Complex)
525547

526-
https://github.com/khoih-prog/SAMD_TimerInterrupt/blob/329513558a9d43b15533a469ceabc30b5896fd80/examples/ISR_16_Timers_Array_Complex/ISR_16_Timers_Array_Complex.ino#L35-L380
548+
https://github.com/khoih-prog/SAMD_TimerInterrupt/blob/8038b88957b0fb8c0ea818013a696e98c797b832/examples/ISR_16_Timers_Array_Complex/ISR_16_Timers_Array_Complex.ino#L35-L383
527549

528550

529551
---
@@ -539,7 +561,7 @@ While software timer, **programmed for 2s, is activated after 7.937s !!!**. Then
539561

540562
```
541563
Starting ISR_Timer_Complex_WiFiNINA on SAMD_NANO_33_IOT
542-
SAMDTimerInterrupt v1.8.0
564+
SAMDTimerInterrupt v1.9.0
543565
CPU Frequency = 48 MHz
544566
[TISR] SAMDTimerInterrupt: F_CPU (MHz) = 48 , TIMER_HZ = 48
545567
[TISR] TC_Timer::startTimer _Timer = 0x 42002c00 , TC3 = 0x 42002c00
@@ -604,7 +626,7 @@ The following is the sample terminal output when running example [**TimerInterru
604626

605627
```
606628
Starting TimerInterruptTest on ITSYBITSY_M4
607-
SAMDTimerInterrupt v1.8.0
629+
SAMDTimerInterrupt v1.9.0
608630
CPU Frequency = 48 MHz
609631
[TISR] SAMDTimerInterrupt: F_CPU (MHz) = 120 , TIMER_HZ = 48
610632
[TISR] TC_Timer::startTimer _Timer = 0x 0x4101c000 , TC3 = 0x 0x4101c000
@@ -682,7 +704,7 @@ The following is the sample terminal output when running example [**Argument_Non
682704

683705
```
684706
Starting Argument_None on SAMD_NANO_33_IOT
685-
SAMDTimerInterrupt v1.8.0
707+
SAMDTimerInterrupt v1.9.0
686708
CPU Frequency = 48 MHz
687709
[TISR] SAMDTimerInterrupt: F_CPU (MHz) = 48 , TIMER_HZ = 48
688710
[TISR] TC_Timer::startTimer _Timer = 0x 42002c00 , TC3 = 0x 42002c00
@@ -732,7 +754,7 @@ In this example, 16 independent ISR Timers are used, yet utilized just one Hardw
732754

733755
```
734756
Starting ISR_16_Timers_Array on SAMD_NANO_33_IOT
735-
SAMDTimerInterrupt v1.8.0
757+
SAMDTimerInterrupt v1.9.0
736758
CPU Frequency = 48 MHz
737759
[TISR] SAMDTimerInterrupt: F_CPU (MHz) = 48 , TIMER_HZ = 48
738760
[TISR] TC_Timer::startTimer _Timer = 0x 42002c00 , TC3 = 0x 42002c00
@@ -856,7 +878,7 @@ The following is the sample terminal output when running example [Change_Interva
856878

857879
```
858880
Starting Change_Interval on SAMD_NANO_33_IOT
859-
SAMDTimerInterrupt v1.8.0
881+
SAMDTimerInterrupt v1.9.0
860882
CPU Frequency = 48 MHz
861883
[TISR] SAMDTimerInterrupt: F_CPU (MHz) = 48 , TIMER_HZ = 48
862884
[TISR] TC_Timer::startTimer _Timer = 0x 42002c00 , TC3 = 0x 42002c00
@@ -920,7 +942,7 @@ The following is the sample terminal output when running example [RepeatedAttach
920942

921943
```
922944
Starting RepeatedAttachInterrupt_uS on SEEED_XIAO_M0
923-
SAMDTimerInterrupt v1.8.0
945+
SAMDTimerInterrupt v1.9.0
924946
CPU Frequency = 48 MHz
925947
[TISR] _period = 19995 , frequency = 50.01
926948
[TISR] SAMDTimerInterrupt: F_CPU (MHz) = 48 , TIMER_HZ = 48
@@ -977,6 +999,74 @@ myClockTimer (30000) = 29997
977999
[TISR] _compareValue = 59984
9781000
```
9791001

1002+
1003+
---
1004+
1005+
### 7. SAMD21_MultiTimers on SAMD21 SAMD_NANO_33_IOT
1006+
1007+
The following is the sample terminal output when running example [SAMD21_MultiTimers](examples/SAMD21_MultiTimers) on **SAMD_NANO_33_IOT** to demonstrate demo the how to use all **6 SAMD21 timers simultaneously**.
1008+
1009+
1010+
```
1011+
Starting SAMD21_MultiTimers on SAMD_NANO_33_IOT
1012+
SAMDTimerInterrupt v1.9.0
1013+
CPU Frequency = 48 MHz
1014+
[TISR] _period = 20000.00 , frequency = 50.00
1015+
[TISR] _timerNumber = 0
1016+
[TISR] SAMDTimerInterrupt: F_CPU (MHz) = 48 , TIMER_HZ = 48
1017+
[TISR] TC3_Timer::startTimer _Timer = 0x 42002c00 , TC3 = 0x 42002c00
1018+
[TISR] SAMD21 TC3 period = 20000.00 , _prescaler = 16
1019+
[TISR] _compareValue = 59999
1020+
Starting TIMER_TC3 OK, millis() = 962
1021+
[TISR] _period = 50000.00 , frequency = 20.00
1022+
[TISR] _timerNumber = 1
1023+
[TISR] SAMDTimerInterrupt: F_CPU (MHz) = 48 , TIMER_HZ = 48
1024+
[TISR] TC4_Timer::startTimer _Timer = 0x 42003000 , TC4 = 0x 42003000
1025+
[TISR] SAMD21 TC4 period = 50000.00 , _prescaler = 64
1026+
[TISR] _compareValue = 37499
1027+
Starting TIMER_TC4 OK, millis() = 964
1028+
[TISR] _period = 100000.00 , frequency = 10.00
1029+
[TISR] _timerNumber = 2
1030+
[TISR] SAMDTimerInterrupt: F_CPU (MHz) = 48 , TIMER_HZ = 48
1031+
[TISR] TC5_Timer::startTimer _Timer = 0x 42003400 , TC5 = 0x 42003400
1032+
[TISR] SAMD21 TC5 period = 100000.00 , _prescaler = 256
1033+
[TISR] _compareValue = 18749
1034+
Starting TIMER_TC5 OK, millis() = 966
1035+
[TISR] _period = 200000.00 , frequency = 5.00
1036+
[TISR] SAMDTimerInterrupt: F_CPU (MHz) = 48 , TIMER_HZ = 48
1037+
[TISR] TCC_Timer::startTimer _Timer = 0x 42002000 , TCC0 = 0x 42002000
1038+
[TISR] SAMD21 TCC period = 200000.00 , _prescaler = 256
1039+
[TISR] _compareValue = 37499
1040+
Starting TIMER_TCC OK, millis() = 968
1041+
[TISR] _period = 500000.00 , frequency = 2.00
1042+
[TISR] SAMDTimerInterrupt: F_CPU (MHz) = 48 , TIMER_HZ = 48
1043+
[TISR] TCC_Timer::startTimer _Timer = 0x 42002400 , TCC1 = 0x 42002400
1044+
[TISR] SAMD21 TCC1 period = 500000.00 , _prescaler = 1024
1045+
[TISR] _compareValue = 23436
1046+
Starting TIMER_TCC1 OK, millis() = 970
1047+
[TISR] _period = 1000000.00 , frequency = 1.00
1048+
[TISR] SAMDTimerInterrupt: F_CPU (MHz) = 48 , TIMER_HZ = 48
1049+
[TISR] TCC_Timer::startTimer _Timer = 0x 42002800 , TCC2 = 0x 42002800
1050+
[TISR] SAMD21 TCC2 period = 1000000.00 , _prescaler = 1024
1051+
[TISR] _compareValue = 46874
1052+
Starting TIMER_TCC2 OK, millis() = 971
1053+
========================================
1054+
TC3 Actual/Programmed (ms) 20/20
1055+
TC4 Actual/Programmed (ms) 50/50
1056+
TC5 Actual/Programmed (ms) 100/100
1057+
TCC Actual/Programmed (ms) 200/200
1058+
TCC1 Actual/Programmed (ms) 500/500
1059+
TCC2 Actual/Programmed (ms) 1000/1000
1060+
========================================
1061+
TC3 Actual/Programmed (ms) 20/20
1062+
TC4 Actual/Programmed (ms) 50/50
1063+
TC5 Actual/Programmed (ms) 100/100
1064+
TCC Actual/Programmed (ms) 200/200
1065+
TCC1 Actual/Programmed (ms) 500/500
1066+
TCC2 Actual/Programmed (ms) 1000/1000
1067+
```
1068+
1069+
9801070
---
9811071
---
9821072

@@ -1009,13 +1099,16 @@ Sometimes, the library will only work if you update the board core to the latest
10091099

10101100
Submit issues to: [SAMD_TimerInterrupt issues](https://github.com/khoih-prog/SAMD_TimerInterrupt/issues)
10111101

1102+
---
10121103
---
10131104

10141105
## TO DO
10151106

10161107
1. Search for bug and improvement.
10171108
2. Similar features for remaining Arduino boards such as SAM-DUE
1109+
3. Add more Timers to SAMD51
10181110

1111+
---
10191112

10201113
## DONE
10211114

@@ -1030,6 +1123,10 @@ Submit issues to: [SAMD_TimerInterrupt issues](https://github.com/khoih-prog/SAM
10301123
8. Optimize library code by using `reference-passing` instead of `value-passing`
10311124
9. Optimize code for `setInterval()` of SAMD21 TC3
10321125
10. Reverse the change in `setInterval()` of SAMD21 TC3 to fix bug when using SAMD21 TC3.
1126+
11. Add TC4, TC5, TCC1 and TCC2 Timers to SAMD21
1127+
12. Add example [SAMD21_MultiTimers](examples/SAMD21_MultiTimers) to demo the how to use all 6 SAMD21 timers simultaneously.
1128+
13. Add functions `attachInterruptInterval_MS()` and `setInterval_MS()`
1129+
10331130

10341131
---
10351132
---
@@ -1048,6 +1145,7 @@ Many thanks for everyone for bug reporting, new feature suggesting, testing and
10481145
8. Thanks to [Dave Hooper](https://github.com/stripwax) to report the bug and propose the fix in [setInterval on a running timer results in a period significantly longer than the specified period #17](https://github.com/khoih-prog/SAMD_TimerInterrupt/issues/17) leading to new release v1.7.0
10491146
9. Thanks to [Rui Marinheiro](https://github.com/sailorsail) to start the discussion in [Do I have a brick? I'm unable to upload sketches after using this library! #21](https://github.com/khoih-prog/SAMD_TimerInterrupt/discussions/21) leading to new release v1.8.0 to fix the bug
10501147

1148+
---
10511149

10521150
<table>
10531151
<tr>
@@ -1065,6 +1163,7 @@ Many thanks for everyone for bug reporting, new feature suggesting, testing and
10651163
</tr>
10661164
</table>
10671165

1166+
---
10681167
---
10691168

10701169
### Contributing

0 commit comments

Comments
 (0)