arduino / arduino/ArduinoCore-renesas

RTC.setPeriodicCallback can't manage it 256 times a second

Open
#451 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
193
Forks
112
PR merge metrics
No merged PRs in 30d

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);
}
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with RTC.h and run the supplied sketch on the affected Arduino hardware to reproduce the callback rates for N64, N128, and N256. Trace the RTC.setPeriodicCallback entry point and its Period handling; done means N256_TIMES_EVERY_SEC produces the expected 256 callbacks per second without changing the existing rates.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
embedded-iot
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.