MKR1000, does RTCZero affect millis()?


hi, below 2 set of codes. 1 using rtczero millis() while other using millis() only. seems former exhibits strange behaviour while latter behaves expected. doing wrong, or if rtc.getepoch() being called , disrupt millis() well? thanks.

1. rtczero , millis()

#include <rtczero.h>
#include <scheduler.h>
rtczero rtc;
unsigned long t0, t1;
 
void setup() {
  serial.begin(115200);
  while (!serial);
 
  rtc.begin();
  rtc.setepoch(1468456152); //some random epoch time
  t0 = rtc.getepoch();
  t1 = millis();
  scheduler.startloop(loop2);
}

void loop() { 
  if ((millis() - t1) >= 500) {
    serial.print(t0);
    serial.print(f("."));
    serial.println(t1);
    t1 = millis();
  }
  yield(); 
}

void loop2() { 
  if (rtc.getepoch() > t0) {
    t0 = rtc.getepoch();
  }
  yield();
}


result:
1468456155.1434
1468456157.1944
1468456160.2449
1468456163.2951
1468456166.3456
1468456169.3960
1468456172.4462
1468456175.4967
1468456178.5469
1468456181.5974
1468456184.6480
1468456187.6983
1468456190.7487
1468456192.7991
1468456195.8496
1468456198.8998


2. millis() only

#include <scheduler.h>
unsigned long t0, t1, t3;
 
void setup() {
  serial.begin(115200);
  while (!serial);
 
  t3 = 0;
  t0 = t1 = millis();
  scheduler.startloop(loop2);
}

void loop() { 
  if ((millis() - t1) >= 500) {
    serial.print(t3);
    serial.print(f("."));
    serial.println(t1);
    t1 = millis();
  }
  yield(); 
}

void loop2() {
  if ((millis() - t0) >= 1000) {
    t3++;
    t0 = millis();
  }
  yield(); 
}


result:
0.1040
0.1540
1.2040
1.2540
2.3040
2.3540
3.4040
3.4540
4.5040
4.5540
5.6040
6.6540
6.7040
6.7540
7.8040
8.8540
8.9040
9.9540
9.10040

quote
it seems former exhibits strange behaviour
what think strange it? looks normal me.


Arduino Forum > Using Arduino > Programming Questions > MKR1000, does RTCZero affect millis()?


arduino

Comments

Popular posts from this blog

Error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode - Raspberry Pi Forums

class MPU6050 has no member named begin

missing filename after '-o'