I'm having a nightmare trying to get an accurate clock working on my T3.5... The most frustrating bit is that there is apparently an ideal function that will do exactly what I need but I can't make it work...
Teensy3.compensate(x)
Whatever I do, I can't get this to work. I have modified one of the example RTC programs and am using a scope to watch the variance between the GPS PPS and the software generated PPS... Whatever I set the compensate to, and however long I wait, the software PPS keeps marching off at a consistent rate of around -20ppm.
Is it still supported to use the compensate function to slightly change the speed of the RTC? The last time "teensy3clock.compensate" appeared on this forum according to a google search is in 2013 (https://forum.pjrc.com/threads/24149-Teensy-3-0-RTC-drift)
I note that compensate doesn't show up here - https://github.com/PaulStoffregen/Time
Here's the code with the command apparently compiling, but having no effect.
Cheers -N
Teensy3.compensate(x)
Whatever I do, I can't get this to work. I have modified one of the example RTC programs and am using a scope to watch the variance between the GPS PPS and the software generated PPS... Whatever I set the compensate to, and however long I wait, the software PPS keeps marching off at a consistent rate of around -20ppm.
Is it still supported to use the compensate function to slightly change the speed of the RTC? The last time "teensy3clock.compensate" appeared on this forum according to a google search is in 2013 (https://forum.pjrc.com/threads/24149-Teensy-3-0-RTC-drift)
I note that compensate doesn't show up here - https://github.com/PaulStoffregen/Time
Here's the code with the command apparently compiling, but having no effect.
Code:
/*
TimeRTC.pde
example code illustrating Time library with Real Time Clock.
*/
#include <TimeLib.h>
void setup() {
pinMode(14, INPUT);
pinMode(24, OUTPUT);
// set the Time library to use Teensy 3.0's RTC to keep time
setSyncProvider(getTeensy3Time);
setSyncInterval(2);
Teensy3Clock.compensate(10000);
Serial.begin(115200);
while (!Serial); // Wait for Arduino Serial Monitor to open
delay(100);
if (timeStatus() != timeSet) {
Serial.println("Unable to sync with the RTC");
} else {
Serial.println("RTC has set the system time");
}
}
void loop() {
if (Serial.available()) {
time_t t = processSyncMessage();
if (t != 0) {
Teensy3Clock.set(t); // set the RTC
setTime(t);
}
}
digitalClockDisplay();
delay(1000);
}
void digitalClockDisplay() {
digitalWriteFast(24, HIGH);
// 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();
delay(1);
digitalWriteFast(24, LOW);
}
time_t getTeensy3Time()
{
return Teensy3Clock.get();
}
/* code to process time sync messages from the serial port */
#define TIME_HEADER "T" // Header tag for serial time sync message
unsigned long processSyncMessage() {
unsigned long pctime = 0L;
const unsigned long DEFAULT_TIME = 1357041600; // Jan 1 2013
if (Serial.find(TIME_HEADER)) {
pctime = Serial.parseInt();
return pctime;
if ( pctime < DEFAULT_TIME) { // check the value is a valid time (greater than Jan 1 2013)
pctime = 0L; // return 0 to indicate that the time is not valid
}
}
return pctime;
}
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);
}
Cheers -N