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
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 (RTC & Watchdog Timer IC)
- 32.768 kHz Quartz Crystal (for RTC)
- 10µF Capacitors (2 pieces)
- Microcontroller (e.g., Arduino or PIC) to read the RTC and display the time
- 16x2 LCD Display (or 7-segment display)
- Push Button (to set the time)
- Power supply (5V or 3.3V, depending on the microcontroller)
- Breadboard and connecting wires
Real-Time Clock (RTC) Functionality
- 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.
- The microcontroller communicates with the DS1233 via I2C (SCL, SDA pins) to read the time data.
Watchdog Timer
- The DS1233 also features a watchdog timer, which is useful in systems that require periodic resets to prevent them from getting stuck.
- 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
- The microcontroller reads the time from the DS1233 using the I2C interface and updates the LCD display every second.
- 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
- 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
- The microcontroller periodically resets the watchdog timer by toggling a bit on the DS1233 to indicate that it is functioning properly.
- 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
- Real-Time Clock:
- The DS1233AZ-10+T&R continuously tracks time using the 32.768 kHz crystal oscillator and keeps the microcontroller updated.
- The microcontroller reads the time data from the DS1233 and displays it on the LCD every second.
- Watchdog Timer:
- The microcontroller sends a signal to the DS1233 at regular intervals (e.g., every 1 second) to reset the watchdog timer.
- If the microcontroller fails to do this (perhaps due to a system hang), the DS1233 sends a reset signal to restart the system.
- Manual Time Setting:
- 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:
- Wire Library: Used for I2C communication with the DS1233.
- LCD Library: Used to interface with the LCD display and display the time.
- setRTC(): Sets the RTC with a fixed time (adjust this for your needs).
- readRTC(): Reads the current time (seconds, minutes, and hours) from the DS1233.
- Loop: The main loop reads the time from the RTC every second and updates the LCD display.
Applications:
- Embedded systems: For devices that need a reliable real-time clock and watchdog functionality.
- Time-sensitive applications: For tracking time in applications like data logging, alarms, and time-based control systems.
- Watchdog system: Ensures systems recover from failures by automatically resetting them if the software fails to reset the watchdog.