-
Notifications
You must be signed in to change notification settings - Fork 78
Added support for Mode 0 and Mode 1 #58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
amcmahon01
wants to merge
2
commits into
arduino-libraries:master
Choose a base branch
from
amcmahon01:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
RTC counter for SAMD21 controllers (Arduino Zero, MKR1000, Adafruit Feather M0) | ||
|
||
Demonstrates the use of the RTC library Mode 0 (32-bit counter) for SAMD21 controllers | ||
This example starts a counter that interrupts and resets after 10 seconds* since | ||
"reset on match" is set to true. | ||
|
||
(*seconds, based on GCLK_RTC = 1.024khz and default 1/1024 prescaler) | ||
|
||
This example code is in the public domain | ||
|
||
created by A. McMahon | ||
20 Feb 2020 | ||
*/ | ||
|
||
#include <RTCZero.h> | ||
|
||
/* Create an rtc object */ | ||
RTCZero rtc; | ||
|
||
void countDone(void); | ||
|
||
void setup() | ||
{ | ||
Serial.begin(9600); | ||
|
||
rtc.begin(true, 0, true); // initialize RTC: reset starting value, Mode 0 (32-bit counter), reset on match | ||
rtc.enableCounter(10); // set counter compare value | ||
rtc.attachInterrupt(countDone); // attach interrupt | ||
} | ||
|
||
void loop() | ||
{ | ||
Serial.println(rtc.getCount()); // print the current count | ||
delay(1000); | ||
} | ||
|
||
void countDone() // interrupt when compare value is reached | ||
{ | ||
Serial.println("Reset!"); | ||
} |
46 changes: 46 additions & 0 deletions
46
examples/Mode1_16-bit_Periodic_Counter/Mode1_16-bit_Periodic_Counter.ino
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
RTC counter for SAMD21 controllers (Arduino Zero, MKR1000, Adafruit Feather M0) | ||
|
||
Demonstrates the use of the RTC library Mode 1 (16-bit periodic counter) for SAMD21 controllers | ||
This example starts a counter that interrupts at 10 and 30 seconds* (for the compare values). | ||
The count is then reset after 60 since that is the set counter period. | ||
|
||
(*seconds, based on GCLK_RTC = 1.024khz and default 1/1024 prescaler) | ||
|
||
This example code is in the public domain | ||
|
||
created by A. McMahon | ||
20 Feb 2020 | ||
*/ | ||
|
||
#include "RTCZero.h" | ||
|
||
/* Create an rtc object */ | ||
RTCZero rtc; | ||
|
||
void countInt(void); | ||
|
||
amcmahon01 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
void setup() | ||
{ | ||
Serial.begin(9600); | ||
|
||
rtc.begin(true, 1); // initialize RTC: reset starting value, Mode 1 (16-bit counter) | ||
rtc.enableCounter(10, 30); // set counter compare values (interrupt at 10 and 30) | ||
rtc.setPeriod(60); // set counter period | ||
rtc.attachInterrupt(countInt); // attach interrupt | ||
} | ||
|
||
void loop() | ||
{ | ||
Serial.println(rtc.getCount()); // print the current count | ||
delay(1000); | ||
} | ||
|
||
void countInt() // interrupt when compare value is reached | ||
{ | ||
uint8_t source; | ||
source = rtc.getIntSource(); // check what caused the interrupt | ||
|
||
if (source == rtc.INT_COMP0) Serial.println("Count = Compare 0!"); | ||
if (source == rtc.INT_COMP1) Serial.println("Count = Compare 1!"); | ||
} |
49 changes: 49 additions & 0 deletions
49
examples/Mode1_16-bit_Periodic_Counter_Overflow/Mode1_16-bit_Periodic_Counter_Overflow.ino
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
RTC counter for SAMD21 controllers (Arduino Zero, MKR1000, Adafruit Feather M0) | ||
|
||
Demonstrates the use of the RTC library Mode 1 (16-bit periodic counter) for SAMD21 controllers | ||
This example starts a counter that interrupts at 10 and 30 seconds* (for the compare values) | ||
and at 60 (since the overflow interrupt is also enabled). The count is then reset after 60 | ||
since that is the set counter period. | ||
|
||
(*seconds, based on GCLK_RTC = 1.024khz and default 1/1024 prescaler) | ||
|
||
This example code is in the public domain | ||
|
||
created by A. McMahon | ||
20 Feb 2020 | ||
*/ | ||
|
||
#include "RTCZero.h" | ||
|
||
/* Create an rtc object */ | ||
RTCZero rtc; | ||
|
||
void countInt(void); | ||
|
||
amcmahon01 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
void setup() | ||
{ | ||
Serial.begin(9600); | ||
|
||
rtc.begin(true, 1); // initialize RTC: reset starting value, Mode 1 (16-bit counter) | ||
rtc.enableCounter(10, 30); // set counter compare values (interrupt at 10 and 30) | ||
rtc.setPeriod(60); // set counter period | ||
rtc.enableOverflow(); // enable interrupt on overflow | ||
rtc.attachInterrupt(countInt); // attach interrupt | ||
} | ||
|
||
void loop() | ||
{ | ||
Serial.println(rtc.getCount()); // print the current count | ||
delay(1000); | ||
} | ||
|
||
void countInt() // interrupt when compare value is reached | ||
{ | ||
uint8_t source; | ||
source = rtc.getIntSource(); // check what caused the interrupt | ||
|
||
if (source == rtc.INT_COMP0) Serial.println("Count = Compare 0!"); | ||
if (source == rtc.INT_COMP1) Serial.println("Count = Compare 1!"); | ||
if (source == rtc.INT_OVERFLOW) Serial.println("Overflow!"); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
name=RTCZero | ||
version=1.6.0 | ||
version=2.0.0 | ||
amcmahon01 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
author=Arduino | ||
maintainer=Arduino <[email protected]> | ||
sentence=Allows to use the RTC functionalities. For Arduino Zero, MKRZero and MKR1000 only. | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.