Skip to content

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
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions examples/Mode0_32-bit_Counter/Mode0_32-bit_Counter.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
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 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!");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
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 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!");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
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 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!");
}
13 changes: 13 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ setAlarmTime KEYWORD2
enableAlarm KEYWORD2
disableAlarm KEYWORD2

enableCounter KEYWORD2
disableCounter KEYWORD2

enableOverflow KEYWORD2
disableOverflow KEYWORD2

getIntSource KEYWORD2
getCount KEYWORD2
getCompare KEYWORD2

setCount KEYWORD2
setPeriod KEYWORD2

standbyMode KEYWORD2

#######################################
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=RTCZero
version=1.6.0
version=1.7.0
author=Arduino
maintainer=Arduino <[email protected]>
sentence=Allows to use the RTC functionalities. For Arduino Zero, MKRZero and MKR1000 only.
Expand Down
Loading