Hardware del Reloj en Tiempo Real (RTC): Cómo las Computadoras Mantienen el Tiempo

What Is an RTC?

A Real-Time Clock (RTC) is a dedicated hardware chip on a computer's motherboard that keeps track of the current time. Unlike the CPU clock (which just counts cycles), the RTC maintains calendar time: year, month, day, hour, minute, second. It is powered by a small coin cell battery (typically CR2032) that keeps it running even when the computer is off, unplugged, or in storage for months.

How the RTC Works

The RTC contains a 32.768 kHz quartz crystal oscillator — this exact frequency is chosen because it is 2^15, making it easy to divide down to exactly 1 Hz using a simple 15-bit binary counter. The chip then increments a set of BCD (Binary Coded Decimal) registers for seconds, minutes, hours, day, month, and year.

# Reading the RTC on Linux
hwclock --show          # Display RTC time
hwclock --show --utc    # Display as UTC (recommended)

# Sync RTC from system clock
hwclock --systohc       # system clock → RTC
hwclock --hctosys       # RTC → system clock

UTC vs Local Time in the RTC

A common source of dual-boot headaches: Windows stores local time in the RTC by default; Linux assumes the RTC is set to UTC. You can fix this:

# Make Windows use UTC RTC (registry edit)
# HKLM\SYSTEM\CurrentControlSet\Control\TimeZoneInformation
# RealTimeIsUniversal = 1 (DWORD)

# Or tell Linux to use local time
timedatectl set-local-rtc 1  # not recommended

The recommended approach: set the RTC to UTC everywhere, and let each OS convert to local time in software.

RTC Drift and CMOS Battery

The RTC's quartz crystal drifts — typically 10–100 ppm, or about 1–9 seconds per day. Over months without NTP correction, an RTC can be hours off. When the CMOS battery dies (typical lifespan: 5–10 years), the RTC loses its time entirely and resets to a default date (often January 1, 2000). Signs of a dead CMOS battery:

  • System clock resets to year 2000 on every boot
  • BIOS settings reset to factory defaults
  • System cannot boot without AC power

RTC on Embedded Systems

Microcontrollers (Arduino, Raspberry Pi Pico) typically don't have a built-in RTC. Common external RTC chips:

  • DS3231: High-accuracy RTC, ±2 ppm, I²C interface, includes temperature compensation
  • DS1307: Basic RTC, I²C, no temperature compensation
  • PCF8563: Low-power RTC, popular in IoT devices
# Raspberry Pi: check RTC status
timedatectl show
# Read from DS3231 via I2C
i2cget -y 1 0x68 0x00

Boot Time Sequence

  1. Power on → BIOS/UEFI reads RTC for initial time
  2. OS boots → reads RTC via hwclock and sets system clock
  3. Network available → NTP client syncs system clock from internet
  4. NTP optionally writes corrected time back to RTC (hwclock --systohc)