Updates
- 31/01/2016 - Added: Hourly chime restriction function
- 27/10/2019 - Fixed: Hourly chime delay error (v3)
- 27/10/2019 - Fixed: Auto mode data showing time increased (v3)
|
Alarm Clock |
This is the newest clock I made using DS1307 real time clock IC. Not like other clock circuits I posted, this clock circuit built in all necessary function such as hourly chime, alarm, time drift correction, etc. In addition, it also include temperature sensor as optional function.
This clock has eight display modes (including standby mode).
- Mode 1 – Display Seconds
- Mode 2 – Display Time
- Mode 3 – Display Date
- Mode 4 – Display Year
- Mode 5 – Display Alarm
- Mode 6 – Display Temperature
- Mode 7 – Show Time, Date and Temperature continuously
- Mode 8 – Stand By Mode
|
DS1307 Alarm Clock |
This PIC project uses PIC16F88 micro-controller, DS1307 Real Time Clock, LM35 temperature sensor, and SSD-5461AG common cathode seven segment display. (If you cannot find that display then use four common cathode seven segment displays).
The PIC16F88 used its internal oscillator and it runs at 8MHz. We can reduce cost and complexity of circuit and can save micro-controller’s pin by using internal oscillator.RA0 and RA1 configured as digital and analogue alternatively to drive seven segment and read voltage of LM35.
The DS1307 (RTC) Real Time Clock is an 8-pin device using an I2C interface. It has eight read/write registers that store the information. This IC will do the timekeeping and it not only keeps track of time but also the date and the day of the week. DS1307 RTC is fully Binary Coded Decimal (BCD) clock/calendar. Therefore, the data read from DS1307 should be converted to BCD format. The most important is the Clock Halt Bit (CH), which is, bit 7 of address 0. This is the register that controls 'seconds' and the CH bit has to be preserved otherwise the chip stops the clock. Writing zero to this bit resets the CH bit so that the clock runs. So when the first usage we must set ‘seconds’. Otherwise clock fail to run.
|
Alarm Clock's Internal |
Time Setting
Using MODE button you can change the display mode and the current status will save to Eeprom.
SET button can be used for edit the time, date, alarm etc. When you pressed the SET button, clock entered to the Edit mode and two displays will turn off. You can be able to edit values on other display by pressing UP and DOWN buttons. To edit turn off displays value pressed SET button again. Press the SET button again to return clock to normal mode. If the clock is in normal mode UP button also can used to change the time format (12hr or 24hr) and DOWN button can used to turn on or off alarm.
When time changed to 12hr mode LED will indicate the AM/PM status. Alarm on will indicated by the decimal point of last seven segment display. If you wish, you can also connect separate LED for it.
Error correction
Surprisingly making an accurate 32kHz oscillator is a difficult. This is because low speed oscillator drivers are designed for low power operation. That means high impedance and therefore low current, which makes the driver extremely sensitive to noise (or any nearby signals, which can capacitive couple to the crystal wire). Because that when using DS1307 we cannot get accurate time. Therefore, I added simple error correction mechanism for this clock
First, set the clock to current time (time of computer or internet) and keep it run up-to 24 hours.
After 24 hours, check the time of clock with time of computer. If time is drift, check how many seconds are drifted..? (Use clock mode 1 to view seconds)
E.g. 1: PC time: 16:30:00
Clock time: 16:30:05
+5 seconds drifted. So we have to reduce time.
I used Eeprom (2) to store this values and default value is 30 (0x1E). See the Eeprom figure.
Now simply overwrite it with 25 (0x19). You must use hex values for it.
E.g. 2: PC time: 16:30:00
Clock time: 16:29:58
-2 seconds drifted. So we have to increase time.
Overwrite Eeprom (2) value with 32 (0x20).
Hourly Chime Restriction
You can able to stop hourly chime function for specific time period using this setting. Device Eeprom address 6 and 7 use for this. default values are 0x00 and 0x18 (0 and 24)
Eeprom(6) ≤ Chime Restriction < Eeprom(7)
Eg: Stop Chime from 21.00 to 6.00
Eeprom(6) = 0x06 and Eeprom(7) = 0x15
6 ≤ Chime Restriction < 21
|
Eeprom of 16F88 |