How can I make an RTC?

Hi,
How should I make an RTC?
Should I use a 555 timer or a 16MHz crystal?
A 16MHz crystal with a transistor circuit
OR
A ne555p timer in an astable config
(size doesn't really matter)

Replies:
@6v6gt
I don't want to buy a RTC and I will be adding a watch battery to my homemade RTC.

@markd833
Real Time Clock
The accuracy needs to be decent

@LMI1
The 555 timer uses about 30mW @ 5V
How much current will a crystal RTC draw?
(A transistor-based oscillator)

@LMI1
Whats the difference between the DS3231 and the DS1307?

@LMI1
Thanks! I will probably buy the DS3231 chip and make my own or just buy the Adafruit module.

@Koepel
If I get a DS3231 module, I can use the Arduino library.
I see your point. I just realized that the 555 timer "RTC" is equivalent to the delay(1000); function :laughing:

What is wrong with using an existing, off the shelf, model for example the DS3231 which, incidentally, is available as a module with backup battery etc. ?
Explaining that may help to make your requirements a bit clearer.

That depends on what you mean by RTC?

I suspect you may mean Real Time Clock, but you may also mean Real Time Counter.

It doesn't really matter how you generate your clock source. What I suspect matters most is how accurate the clock source is if you are to use it for timing purposes.

I think stability and repeatibility are just as important as accuracy, which in most cases is a one-time test.
Paul

If you use a watch battery current consumption can't be high, because those batteries have low capacity.
555 works, but it is not stable in the long run. Crystals are better. Low frequency crystals take less power, but are tricky to use.
If you really want to see time of day, of the shelf ICs do that better. I have bought several assembled RTC "shields" from China,

You asked about power/current consumption. Check DS32321 datasheet. It is a good chip and has an Arduino library.

First: I recommend Adafruit version of Ds32321 shield. It works fine. But they have used a ferrite as a power supply filter, which is fine, but Chinese clones use capacitor there and that blocks the power supply. Those clone shields do not work because there is no voltage for the IC.
DS1307 is a simpler chip. One shield did not have a proper battery backup, The shield worked either with a battery or voltage supply from Arduino.
DS32321 have integrated and matched crystal, which Maxim promises to be better. It also has a proper battery backup. My shields have a battery holder, and with a battery there, it keeps the time even without Arduino.

@LinuxNinja99 Everyone is confused by your question, and I am even more confused than the others :confused:

Could you explain what your project is about, to give us a broader view and to avoid the XY-problem (when a question is strange, it might be a XY-problem).

There might be 30 ways to make a RTC yourself, but the question is: how do you want to use it. How will you interface your RTC ? Is it connected to an Arduino ? It could use a Serial port and send the date and time every second via the Serial port.

A decent accuracy and also battery powered, that might not be possible.

A RTC keeps the date and time. Do you want a clock signal of 1 second and let the Arduino make a date and a time of it ? That is not a RTC.

My wristwatch has a very good accuracy, is powered by a single tiny 1.5 V battery and works for years without need for battery replacement. I always wonder how this is done because no RTC chip I know is even close to this.

@Smajdalf
An analog watch has a motor inside that is spun every second by the quartz oscillator circuit. That motor also moves the minute and hour hand through some gears. This is how a clock works.
A digital watch usually has 1-2 3v watch batteries and has a built in RTC for displaying date.

I know how it works on the "macroscopic" scale. What is not clear for me is the effectiveness of the ASICs. Most wall clocks as well as (analog) wrist watches I know run from single 1.5 V cell. The logic works to much lower voltage. When the cell is depleted (typical open circuit voltage < 1 V) the clock stops not because of a brown out logic failure but because the circuit is unable to supply enough power to move the hands (wall clock typically stops at the rising part of the seconds hand trajectory). No MCU I know runs from such low supply. Some RTCs can keep time in such low conditions but are unable to communicate.
Another issue is the current consumption. Wrist watches can keep the oscillator running with precision much better than the 20 ppm of typical crystal AND move the hands for YEARS from a very very tiny battery. The average current consumption must be less than 1 uA. And they must use some reasonable power for the crystal: it is subject to various impacts, vibrations and electric noise but it shouldn't stop.
While many consumer electronic may be overperformed by DIY because you are not so limited by budget and may hand-pick components to tune it to perfection the cheap and tiny clock circuits are far out of reach of anything I can imagine.

I wanted to say it is possible to keep reasonably accurate time with very low power consumption. While DIY is much less effective for this it is still possible to keep track of time without "high" power consumption. (Less than 10 uA @ 3 V for the time-keeping should be quite easy).

I have a watch that costs 12 euros and runs 10 years on a single battery. So yes, that is extremely good. Everything is optimized for that purpose.

The DS3231 (datasheet) has a interface to a microcontroller or processor. They even made it compatible with 5V and 3.3V. To be able to use it with a microcontroller, it has registers that can be read and written.
They choose 3V for the battery voltage, because a 3V coin cell is often used in computers and similar devices.

That is something completely different from a watch or wall clock. Maxim made a versatile RTC to be used in devices.

I have 3 RTC boards, 1 from Adafruit and 2 from China (bought on ebay). The Adafruit board uses a PCF8523 chip. The Chinese boards use a DS1307. The RTC library supports both chips.

I have had all of these boards for about 4 years. They all show the same characteristic of poor accuracy. All of them gain time at the rate of about 8 seconds per day. Over a few months, this amounts to quite a big discrepancy. I did not realize this at first. After about 3 months I realized that the time was way off and I needed to do something about it.

The literature I read suggested that temperature affects the accuracy. My boards are all used in my basement, which has a relatively stable year round temperature of about 65 deg F, with a variation of about +/- 5 degrees F. I had to do a few things to correct the time.

#1 I wrote a program that sets the RTC clock to the compile timestamp of the Arduino program. The compile time is in the Arduino DATE variable. The program also stores the date and time that the clock was set in the Arduino EEPROM memory. This program also can be used to read the RTC clock and report the drift, and the daily adjustment needed to obtain the proper time. This assumes that the drift is linear over time. I am pretty sure that the drift is not linear, but I think the error is slight.

#2 I wrote my own “get time” function that is used by any program that uses an RTC. The function reads the RTC value, reads the “last time set” from EEPROM, and then applies the drift correction.

I preferred to store the “last time set” in the RTC chip. This could be done with the DS1307 chip (which contains a small amount of non-volitile memory), but not the PFC8523 (which has no non-volitile memory). I wanted a common method, so I opted to keep each RTC board with a specific Arduino board and store the time of the last setting in the Arduino memory.

That is to some extent, why wristwatches have good accuracy. :+1: