Notecard Real-Time Clock
This application note provides technical details and implementation guidance for using the real-time clock (RTC) functionality on Notecard, including crystal specifications, accuracy considerations, and best practices for time-sensitive applications.
Overview
The Notecard includes a built-in RTC that provides reasonably accurate timekeeping for your applications. The RTC is synchronized with network time when the Notecard connects to cellular, WiFi, or satellite networks, and maintains time locally between synchronization events.
The RTC subsystem uses a crystal oscillator that produces a precise "heartbeat" signal, which the RTC uses to track time. This allows the Notecard to maintain time even when disconnected from the network, making it suitable for applications that require timestamping of events, scheduled operations, and time-based logic.
How the RTC Works
When a Notecard first powers on, the RTC has no knowledge of the current time. Upon the first successful sync to Notehub (via cellular, WiFi, or satellite connection), the Notecard synchronizes its RTC with the time provided by Notehub. The Notecard obtains accurate time references from cellular towers or GPS (when available), which Notehub uses to provide precise time synchronization.
Once synchronized, the RTC continues to track time using its local crystal oscillator, even when the Notecard is offline or in low-power modes. The RTC primarily serves to track intervals between scheduled operations (such as "how long until the next sync") rather than maintaining absolute precision.
The Notecard automatically resynchronizes its RTC during subsequent Notehub syncs, which corrects any drift that may have accumulated since the last synchronization. This means that even if the RTC drifts while offline, your data will still reach Notehub with accurate timestamps once connectivity is restored.
Crystal Specifications
All Notecard models use a 32.768 kHz crystal oscillator for their RTC subsystem. The crystal specifications vary slightly between Notecard and Notecard (legacy) models.
Notecards
Notecards use crystals with:
- Nominal frequency: 32.768 kHz
- Accuracy at 25°C: ±20 ppm (±0.002%)
- Drift at 25°C: ±2 seconds per day
Notecards have additional temperature characterization data showing drift across the full operating temperature range:
| Temperature | Drift | Time Drift per Day (Approximation) |
|---|---|---|
| -40°C | Up to -175 ppm (-0.018%) slower | -15 seconds |
| 25°C | ±20 ppm (±0.002%) | ±2 seconds |
| 85°C | Up to -140 ppm (-0.014%) slower | -12 seconds |
These specifications are typical for crystal oscillators used in consumer electronics, including smartphones. At approximately 25°C, the crystal oscillator at its most stable. More precise timing would require temperature-compensated crystal oscillators (TCXO), which are significantly more expensive.
Accuracy Considerations
While crystal oscillators are reasonably precise in stable conditions, several environmental and operational factors can cause the RTC to drift over time:
Temperature Effects
Crystal oscillators are sensitive to temperature changes. Most crystals have a temperature coefficient that causes their frequency to vary with temperature. This means that:
- In extreme heat, the crystal may oscillate faster or slower than its nominal frequency, causing time to drift
- In extreme cold, similar drift can occur
- Temperature changes during operation can cause accumulated drift over time
- The rate of drift is typically non-linear with temperature and varies by crystal specification
Aging and Long-Term Drift
All crystal oscillators experience some degree of aging over time:
- Frequency can drift slowly over months and years of operation
- The rate of aging varies by crystal type and operating conditions
- Network time synchronization helps compensate for long-term drift
The Notecard is designed to be tolerant of RTC drift. Even if the local timebase varies due to temperature changes or infrequent connectivity, the Notecard will still successfully sync your data to Notehub. Time-critical timestamps are corrected during synchronization, ensuring your data reaches Notehub with accurate timestamps regardless of local RTC drift.
When Precision is Required
While the Notecard's RTC is sufficient for most applications, some use cases may require higher precision timing. If your application requires sub-second accuracy over days or weeks without Notehub connectivity, consider:
- Using an external TCXO (Temperature Compensated Crystal Oscillator) based RTC module
- Implementing more frequent Notehub synchronization (e.g. increase the
outboundandinboundsync times in thehub.setrequest) - Using GPS timing on Notecard models with GPS (when GPS lock is available)
RTC Synchronization
Automatic Synchronization
The Notecard automatically synchronizes its RTC during:
- First sync: When the Notecard first syncs to Notehub after power-on
- Periodic syncs: During each subsequent sync session with Notehub
- Manual sync requests: When explicitly requested via API
No special configuration is required for automatic RTC synchronization, it happens as part of the Notecard's Notehub sync process. The Notecard obtains time from cellular towers or GPS, which provides highly accurate time references for synchronization.
Checking RTC Status
You can check the current RTC time and synchronization status using the card.time request:
{"req": "card.time"}This returns the current time in both Unix timestamp and human-readable formats,
along with the timezone information.
Before the Notecard has successfully synced
to Notehub, this request will return {"zone":"UTC,Unknown"} indicating that
time has not yet been obtained.
Time Zones
The Notecard maintains time in UTC internally. Your host application can convert UTC time to local time zones as needed.
Calibrating the RTC
For most applications, the automatic Notehub synchronization described above keeps Notecard timestamps accurate without any manual intervention. However, if your application must maintain accurate local time through long periods without connectivity, you can measure and store an RTC calibration on Notecard.
As described in Accuracy Considerations, the amount of clock drift varies from one Notecard model to the next, and with the temperature at which the device operates. Calibrating a Notecard under the same conditions in which it will be deployed lets Notecard compensate for its own drift and hold more accurate time between syncs.
Requirements
- Notecard firmware v11.3.1 or later.
- The Notecard CLI.
- A host computer with an accurate, high-resolution clock (for example, one kept in sync via NTP). Notecard measures its drift relative to the host clock, so the quality of the calibration depends on the accuracy of that clock.
Measuring and Storing a Calibration
Connect Notecard to your host computer and run the following command. Notecard
will measure its drift against the host clock once per second, reporting its
running estimate (daily, in seconds of drift per day) and its confidence
(calibration, as a percentage). Once Notecard has reported full confidence
(calibration:100.0%) for several consecutive readings, the measured
calibration is stored and the command exits.
notecard -rtc calibrate1 rtc: daily:1.284000 calibration:12.0%
2 rtc: daily:0.912000 calibration:24.0%
...
23 rtc: daily:0.031000 calibration:100.0%
24 rtc: daily:0.031000 calibration:100.0%The stored calibration persists across reboots and factory resets, and Notecard applies it automatically from that point forward.
For the best results, run the calibration while Notecard is at the temperature it will experience in the field. Because drift is temperature-dependent, a calibration measured at room temperature may be less accurate for a device that operates in extreme heat or cold.
Additional Calibration Commands
The -rtc flag accepts several modes:
notecard -rtc test— measure drift and report the estimate without storing a calibration.notecard -rtc calibration— display the calibration currently stored on Notecard.notecard -rtc reset— clear the stored calibration.
Power Considerations
The RTC continues to operate during all Notecard power modes:
Active Mode
The RTC operates normally with full accuracy during active operation.
Low-Power Modes
The RTC continues to track time during sleep and hibernation modes. The crystal oscillator remains active to maintain time, but power consumption is minimal (current consumption can be measured in microamperes).
Power Loss
If the Notecard completely loses power (e.g. VBAT disconnected), the RTC will lose track of time and will need to resynchronize when power is restored and a network connection is established.