morganwalsh
Member
Hello,
I'm working on a logging product that needs to have an up to date time via the battery backed up RTC or no time at all.
I have a GPS module running to update the time, but this can take some time to lock on (or not at all in metal buildings) if the unit is powered off for a long time.
On a Teensy 3.5 I am simulating a dead RTC backup battery by disconnecting it (having set the time previously), remove the GPS module and turn the Teensy off for a few minutes
On power up of the Teensy, I find that the RTC using Teensy3Clock.get() returns a stale time (looks like the last time the RTC was set). In non logging situations, this may be desirable, but I need to know if the RTC is essentially stale so that I can not log anything with a [very] stale time (I can accept the normal drift over time).
So, my question is this:
Is there a way to know that the RTC that the time is stale. For example, is there a way to check the Vbat voltage so that if it's zero or less than say 2v, I can assume the backup battery is dead and the RTC could be stale?
Many thanks
Gary
I'm working on a logging product that needs to have an up to date time via the battery backed up RTC or no time at all.
I have a GPS module running to update the time, but this can take some time to lock on (or not at all in metal buildings) if the unit is powered off for a long time.
On a Teensy 3.5 I am simulating a dead RTC backup battery by disconnecting it (having set the time previously), remove the GPS module and turn the Teensy off for a few minutes
On power up of the Teensy, I find that the RTC using Teensy3Clock.get() returns a stale time (looks like the last time the RTC was set). In non logging situations, this may be desirable, but I need to know if the RTC is essentially stale so that I can not log anything with a [very] stale time (I can accept the normal drift over time).
So, my question is this:
Is there a way to know that the RTC that the time is stale. For example, is there a way to check the Vbat voltage so that if it's zero or less than say 2v, I can assume the backup battery is dead and the RTC could be stale?
Many thanks
Gary
Code:
#include <TimeLib.h>
void setup() {
Serial.begin(9600);
while (!Serial); // Wait for monitor
setTime(0); // Zero time
Serial.printf("Initial now: %ld\n", now());
digitalClockDisplay();
setTime(Teensy3Clock.get());
Serial.printf("\nNow after RTC get: %ld\n", now());
digitalClockDisplay();
}
void loop() {
// put your main code here, to run repeatedly:
}
void digitalClockDisplay() {
// digital clock display of the time
Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.print(" ");
Serial.print(day());
Serial.print(" ");
Serial.print(month());
Serial.print(" ");
Serial.print(year());
Serial.println();
}
void printDigits(int digits){
// utility function for digital clock display: prints preceding colon and leading 0
Serial.print(":");
if(digits < 10)
Serial.print('0');
Serial.print(digits);
}