RTC Precision Capture

I’m looking to build something which can capture simple signals (like a button) to 100th or better of a second in changing temperatures. Capturing in ESP32 seems easy enough but the RTC modules both provide a battery backup of the time which is nice, as well as they claim temperature compensated time for accuracy which also sounds nice. In flipping through the libraries for them I do not see a capture for decimals of the second however. Am I missing something that someone can point me at? Is there a specific chipset for RTC I should be looking at for doing this? I see that SparkFun has numerous RTC modules utilizing different chipsets available.

The RTC is mostly used to set the SYNC timing for the MCU (in this case esp32) - you’d capture the actual presses/times on the esp32 itself using microseconds, something like:

#include <Wire.h>
#include <RTClib.h>
#include <esp_timer.h>

RTC_DS3231 rtc;
uint64_t startTime;

void setup() {
  Serial.begin(115200);
  Wire.begin();
  if (!rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }
  if (rtc.lostPower()) {
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  }
  startTime = esp_timer_get_time(); // Get the start time in microseconds
}

void loop() {
  // Simulate button press
  if (digitalRead(BUTTON_PIN) == HIGH) {
    uint64_t currentTime = esp_timer_get_time();
    uint64_t elapsedTime = currentTime - startTime;
    float elapsedSeconds = elapsedTime / 1000000.0; // Convert microseconds to seconds
    Serial.print("Button pressed at: ");
    Serial.print(elapsedSeconds, 2); // Print with 2 decimal places
    Serial.println(" seconds");
  }
  delay(100); // Adjust as needed
}

And then adjust/convert the units as needed

So use the RTC to set the time on the ESP and then use the ESP time for capture is how I’m understanding this, and that could be great but would not give me the accuracy of the selling point of the RTC doing temperature compensation etc… Perhaps if the RTC can’t get that level of capture I could do this but then alter it to resync to RTC at regular polling intervals. Hm…

or… I could possibly use the temperature reading on it to trigger a SparkFun Heating Pad (Heating Pad - 5x15cm - COM-11289 - SparkFun Electronics) and maintain the temperature in the box stable…

That seems doable. Or do the opposite along with a fan or something (whichever proves more stable)