Stable time measurement

Hi, I am looking for accurate time measurement (may be relative to set point, not absolute). The DS3231 seems to be an improvement over the oscillator of the Teensy 3.6 we are using. Is there an easily integratable similar small footprint alternative? It may be more expensive to a reasonable degree.

Define "accurate". The DS3231 is accurate to about +/- 100 seconds error after one year.

The Teensy 3.6 has two oscillators, the high speed CPU clock which should be accurate to about 1 part in 1000 or so and the 32 kHz embedded real time clock oscillator which I would expect is of similar accuracy as the DS3231, that is, a few parts per million. Which one are you using for this comparison?

Any, as long as I can achieve an accurate square wave signal. I did not find any info about the Teensy RTC. Is it temperature stabilized?
We want to put timestamps on 200Hz (right now, may get higher) video camera frames, where the Teensy reads the exposure active signal.
If we want to keep the frame stamps comparable over a few hours with multiple synchronized units, the DS3231 is certainly not overdimensioned. It is probably fine, but if we can have more for a few bucks more, why not go for it? We are not going to make millions of units.

An ESP8266 based Arduino can pull ntp time off the internet.
No time/date adjustments, and zero drift.
Leo..

You can incorporate one of these on each unit pretty inexpensively. WWVB receiver

It eliminates needing a wifi connection since it gets it's pulses ota. Might get one myself for s-n-g's.

Thinking about it, you should be able to get time data from GPS modules as well.

tinman13kup:
Thinking about it, you should be able to get time data from GPS modules as well.

This is the best way, the PPS pulse is accurate to orders of magnitude better than SNTP, in the short term. Of course, over long periods they converge.

Timing 200Hz over a period of a few hours is like having a 200-foot measuring tape with markings of thousandths of an inch. You would not trust a real tape but the crystals in the RTC's mentions above are pretty close to this accuracy.

I think the GPS idea also has merit. Use the PPS (pulse per second) output to "gate" your Arduino's millis counter. If the Arduino counts 1005 milliseconds between two pulses then the frame timestamps recorded during that second can be multiplied by 1/1.005 to get the right answer. The next second starts from zero, with zero drift relative to the GPS.

MorganS:
Timing 200Hz over a period of a few hours is like having a 200-foot measuring tape with markings of thousandths of an inch.

Well, if the markings are accurate enough and I have a second tape that is decently accurate over short periods, that is not impossible.
I was thinking about a construct like

interupt on RTC SQW:
    last_pulse_micros =  micros();
    pulses++,

loop:
    print('Current time: ')
    println(pulse*pulse_period+micros()-last_pulse_micros); // I could also in addition adjust by a factor from the last period.

The 3ppm of the DS3231 give me almost a factor of 7 in accuracy compared to the 20ppm crystal of the Teensy RTC. That also apparently is not temperature stabilized. 3ppm is still one frame period in 0.5h, though, but I get some headroom for further synchronization.

I think the GPS idea also has merit.

Can't use GPS, we have problems even with cellphones in the building this is used in.

MrMark:
The Teensy 3.6 has two oscillators, the high speed CPU clock which should be accurate to about 1 part in 1000 or so and the 32 kHz embedded real time clock oscillator which I would expect is of similar accuracy as the DS3231, that is, a few parts per million. Which one are you using for this comparison?

Surely its a standard watch xtal used for 32.768kHz? They are typically 30, 50 or even 100ppm.
The DS3231 uses a TCXO with basic accuracy of a few ppm. For better clock accuracy you require a TCXO
or OCXO, not a bog-standard xtal.

Cellphones don't work everywhere. GPS works everywhere below low Earth orbit so long as you can see the sky.

If you can run an antenna up to a window or out a vent duct, you can probably get a good enough GPS signal.

Sparkfun once had a GPS receiver in their catalog which supposedly worked in a locked metal file cabinet in the basement. I don't know if it's still in the catalog.

[There's even a few satellites in higher orbits that are catching the GPS signals which missed the Earth.]