A battery-powered device sleeps between acquisitions and uses the watchdog to wake up. After replacing the main crystal, the UART baud rate is closer to nominal, but long sampling intervals have changed little. The ATmega328P watchdog runs from an independent on-chip oscillator and can operate when the processor’s main clock stops. Identify the timebase that runs during sleep before deciding what to upgrade.
Measure active and sleep intervals separately
Add one short marker pulse where the code saves a sample and another where it actually enters sleep. Record several dozen full cycles against an independent reference. Calculate each active and sleep interval and compare the distributions after changes in temperature or supply. Stable active intervals with drift concentrated in the longer sleep interval point toward the watchdog oscillator. Averaging the combined intervals can obscure the dominant error.
When reviewing firmware, record the watchdog prescaler setting, interrupt and reset enables, and when the timer is rearmed after wake-up. Suppose one processing step takes 20 ms and firmware begins the next relative delay only after that work finishes. Each 20 ms interval then adds to the sampling schedule. Even if each sleep on its own is exact, the long-term cadence still includes software processing time.
If the product needs samples at times close to absolute calendar time, evaluate an external RTC or a suitable asynchronous timebase that wakes it at absolute timestamps. The independent watchdog can continue to provide fault recovery. Specify timing error, standby current, and acceptable wake-up latency separately. Test continuous operation and actual sleep. The main crystal’s nominal accuracy alone does not establish a standby timekeeping guarantee.Microchip ATmega328P datasheet
