Simple Real-Time Clock With Watchdog Timer

by Ethanteu in Circuits > Electronics

46 Views, 0 Favorites, 0 Comments

Simple Real-Time Clock With Watchdog Timer

Real-Time Clock with Watchdog Timer.png

To design a simple circuit that uses the DS1233AZ-10+T&R to implement a real-time clock that displays the current time and also features a watchdog timer to reset the system if it becomes unresponsive.

Supplies

DS1233AZ-10+T&R.png
  1. DS1233AZ-10+T&R (RTC & Watchdog Timer IC)
  2. 32.768 kHz Quartz Crystal (for RTC)
  3. 10µF Capacitors (2 pieces)
  4. Microcontroller (e.g., Arduino or PIC) to read the RTC and display the time
  5. 16x2 LCD Display (or 7-segment display)
  6. Push Button (to set the time)
  7. Power supply (5V or 3.3V, depending on the microcontroller)
  8. Breadboard and connecting wires

Real-Time Clock (RTC) Functionality

11 (1).png
  1. The DS1233AZ-10+T&R uses the 32.768 kHz quartz crystal as a time base and can keep track of seconds, minutes, hours, days, and even provide date and year information.
  2. The microcontroller communicates with the DS1233 via I2C (SCL, SDA pins) to read the time data.

Watchdog Timer

  1. The DS1233 also features a watchdog timer, which is useful in systems that require periodic resets to prevent them from getting stuck.
  2. If the microcontroller or system fails to reset the watchdog within a set time period (determined by external components like capacitors), the DS1233 will trigger a reset signal (RST) to the microcontroller, restarting the system.

Microcontroller Communication

  1. The microcontroller reads the time from the DS1233 using the I2C interface and updates the LCD display every second.
  2. A push button can be used to set the current time manually if needed, or it can be set programmatically in the code.

LCD Display

  1. The LCD will show the current time in a format like HH:MM:SS, where HH is hours, MM is minutes, and SS is seconds. You can also add additional features like showing the date.

Watchdog Timer Reset

  1. The microcontroller periodically resets the watchdog timer by toggling a bit on the DS1233 to indicate that it is functioning properly.
  2. If the microcontroller fails to reset the timer in time (due to a software crash or freeze), the DS1233 will issue a reset signal to restart the system.

How It Works

What is Real Time Clock (RTC)? How RTC works? Applications of Real Time Clock
  1. Real-Time Clock:
  2. The DS1233AZ-10+T&R continuously tracks time using the 32.768 kHz crystal oscillator and keeps the microcontroller updated.
  3. The microcontroller reads the time data from the DS1233 and displays it on the LCD every second.
  4. Watchdog Timer:
  5. The microcontroller sends a signal to the DS1233 at regular intervals (e.g., every 1 second) to reset the watchdog timer.
  6. If the microcontroller fails to do this (perhaps due to a system hang), the DS1233 sends a reset signal to restart the system.
  7. Manual Time Setting:
  8. You can implement a simple user interface with a push button or keypad to manually set the time when the system starts up.


Code (for Arduino Example):

#include <Wire.h>

#include <LiquidCrystal_I2C.h>


#define RTC_ADDR 0x68 // Address of DS1233 (can vary, check datasheet)


LiquidCrystal_I2C lcd(0x3F, 16, 2); // LCD Address, columns, rows


void setup() {

Wire.begin();

lcd.begin(16, 2);

lcd.print("Initializing RTC...");

// Set up RTC (optional, run once to set time manually)

// Set time (HH, MM, SS, Day, Date, Month, Year)

// Here, manually set the time as an example

setRTC(12, 30, 0, 1, 25, 8, 22); // Time: 12:30:00 on 25th Aug 2022


delay(1000);

lcd.clear();

}


void loop() {

byte second = readRTC(0x00);

byte minute = readRTC(0x01);

byte hour = readRTC(0x02);

lcd.setCursor(0, 0);

lcd.print("Time: ");

lcd.print(hour);

lcd.print(":");

lcd.print(minute);

lcd.print(":");

lcd.print(second);

delay(1000); // Wait for 1 second

}


byte readRTC(byte reg) {

Wire.beginTransmission(RTC_ADDR);

Wire.write(reg);

Wire.endTransmission();

Wire.requestFrom(RTC_ADDR, 1);

return Wire.read();

}


void setRTC(byte hour, byte minute, byte second, byte day, byte date, byte month, byte year) {

Wire.beginTransmission(RTC_ADDR);

Wire.write(0x00); // Start writing to RTC register 0x00

Wire.write(second);

Wire.write(minute);

Wire.write(hour);

Wire.write(day);

Wire.write(date);

Wire.write(month);

Wire.write(year);

Wire.endTransmission();

}


Explanation of Code:

  1. Wire Library: Used for I2C communication with the DS1233.
  2. LCD Library: Used to interface with the LCD display and display the time.
  3. setRTC(): Sets the RTC with a fixed time (adjust this for your needs).
  4. readRTC(): Reads the current time (seconds, minutes, and hours) from the DS1233.
  5. Loop: The main loop reads the time from the RTC every second and updates the LCD display.


Applications:

  1. Embedded systems: For devices that need a reliable real-time clock and watchdog functionality.
  2. Time-sensitive applications: For tracking time in applications like data logging, alarms, and time-based control systems.
  3. Watchdog system: Ensures systems recover from failures by automatically resetting them if the software fails to reset the watchdog.