Specialist Supplier of Crystals & Frequency Control Componentssales@mecxtal.com.cn0755-26500570
MERLIN home / Rednote / Passive Crystals and Oscillator Circuits

Why a SAM D21 RTC uses 1024 Hz with a 32.768 kHz crystal

A logger built around a SAM D21 has a healthy 32.768 kHz passive crystal, yet firmware writes a one-second record after every thousand RTC counts. After an hour, the file has more entries than expected. Inspect the dividers ahead of the counter first. Microchip's RTC application note groups the result of dividing 32.768 kHz by 32 under the 1 kHz setting. Its nominal rate is 1024 Hz. Treating that shorthand as 1000 Hz creates a timing error even with an accurate crystal.

Give each stage its own frequency

For a SAM D21 design using the external low-frequency crystal, the XOSC32K circuit provides a nominal 32768 Hz. The clock passes through a generic clock generator divider before reaching the RTC's prescaler. The clock setup section in AT03266 describes a calendar configuration that divides by 32 in the GCLK stage and by 1024 inside the RTC. The intermediate rate is 1024 Hz and the final rate is one hertz. Use calendar seconds when reading the seconds field. Use 1024 counts per second when reading a counter driven by the intermediate clock with no further division.

Keep the crystal frequency, active GCLK source, effective GCLK divider, RTC mode, and RTC prescaler separate in the schematic notes and test record. An internal oscillator can also supply a clock in this range. Counter activity shows that a clock reaches the RTC. Read the clock source registers to confirm that the measurement actually represents the external 32.768 kHz crystal. This check matters when the same firmware serves board builds populated with and without a watch crystal.

Calculate the effect of waiting for 1000 counts

Assume an exact 1024 Hz counter clock, a divide-by-one RTC prescaler in count mode, and software that waits for a difference of 1000 ticks. The elapsed time is 1000 divided by 1024, or 0.9765625 seconds. Each interval finishes about 23.4375 milliseconds early. Ignoring execution overhead, one real hour produces 3,686,400 ticks. That completes 3686 full intervals of 1000 ticks, with 400 ticks remaining. A log that treats every interval as a second can therefore report about 86 extra seconds. This example illustrates a unit conversion error. Actual behavior also depends on how the code starts the counter, handles interrupts, and schedules the task.

For comparison, a 32.768 kHz passive crystal running 20 ppm fast under the intended load and temperature creates about 0.072 seconds of excess time per hour. A result close to 86 seconds per hour calls for inspection of the clock tree, units, and compare rules first. Check the raw counter increment and the final application timestamps against an independent time reference. Once the large conversion error disappears, investigate the smaller residual in terms of load capacitance, temperature, and crystal tolerance. Record the two observations separately.

Tell a clock error from a logger error

Capture the raw RTC count, record count, and external reference together. An ideal 1024 Hz path accumulates 10240 counts in ten seconds. In a separate test with the calendar path configured, look for ten one-second increments. Use the actual configured rate when converting counts, and check wraparound handling. For hardware compare or clear-on-match, verify the counter origin and event semantics in the device datasheet. Measure the gap between successive events on the target. Follow the documented synchronization procedure when reading an asynchronous counter so that a stale read does not look like a lost count. If the raw count behaves correctly but entries are missing, inspect task scheduling, buffering, or storage latency before replacing a crystal.

Check cold startup and wake-up with the same firmware build. The system may select a different source during a transition. Track steady-state rate independently from the time spent waiting for the external crystal to start. When firmware relies on an internal clock during that wait, record when the external source actually takes over. For a replacement approval, capture the selected external clock, divider and count behavior, and final timing error under the required load and temperature conditions.

Compare both the steady rate and individual record gaps

If several units gain time at the same fixed rate over two observation windows, preserve the raw counts and firmware version. Reprocess the same capture offline using the verified scale to see whether only the display or log conversion is wrong. If individual records arrive in bursts or occasionally leave gaps, compare the hardware event time with the application write time. Sensor tasks, communications retries, and transitions out of sleep can change the recording cadence. A useful capture extends across those events.

Evaluate crystal lots once the large error is fixed. At 20 ppm fast, the expected lead after ten seconds is just 0.2 milliseconds. A logger with millisecond timestamps can check the divider scale in a short test but cannot reliably resolve a 20 ppm acceptance limit from that capture. Engineering should state the longer observation time, reference source, and temperature stability. Purchasing can then request candidate data taken under comparable conditions. If a firmware change coincides with a crystal lot change, measure a known baseline board as well so the two effects can be kept distinct.

Preserve the component type and frequency on the purchase order

Write the complete manufacturer order code for the 32.768 kHz passive crystal and maintain its load capacitance, maximum ESR, drive level, package, and temperature specification with the design. A build driven by a 32.768 kHz active oscillator needs separate assembly and purchasing information for supply voltage, output logic, enable behavior, pinout, and external-clock input mode. Review the receiver electrical limits before approving any substitution. The intermediate 1.024 kHz and final 1 Hz belong in the manufacturing test documentation. With this distinction, purchasing can order the part and engineering can verify the timing path using the same description.

References

WeChat

MERLIN · TIMING COMPONENTS

Scan with WeChat to contact Sales

Add our WeCom contacts from your usual WeChat app.

On desktop, scan with your phone. On mobile, save the QR image and select it from your album in WeChat Scan.