Open
Description
RTC.setPeriodicCallback
works as advertised up to Period::N128_TIMES_EVERY_SEC
, but N256_TIMES_EVERY_SEC
gives the same callback rate as N128_TIMES_EVERY_SEC.
Sample here shows the issue.
#include "RTC.h"
void setup() {
Serial.begin(9600);
while(!Serial)
; // do nothing
Serial.println("started");
RTC.begin();
RTCTime start = RTCTime(0UL);
RTC.setTime(start); // have to set a time, doesn't matter what
}
volatile unsigned long rate = 0;
void on_timer() {
static unsigned long count = 0;
static unsigned long last_secs = 0;
unsigned long secs = millis() / 1000;
if (secs != last_secs) {
rate = count;
count = 0;
last_secs = secs;
}
++count;
}
void run_test(Period period) {
if (!RTC.setPeriodicCallback(on_timer, period)) {
Serial.println("ERROR: periodic callback not set");
}
delay(1500); // ignore first result
for (unsigned int i = 0; i < 5; ++i) {
delay(1000);
Serial.print("rate = ");
Serial.println(rate);
}
}
void loop() {
Serial.println("Expect 64 per sec");
run_test(Period::N64_TIMES_EVERY_SEC);
Serial.println("Expect 128 per sec");
run_test(Period::N128_TIMES_EVERY_SEC);
Serial.println("Expect 256 per sec");
run_test(Period::N256_TIMES_EVERY_SEC);
}
Metadata
Metadata
Assignees
Labels
No labels