I found some guides on the internet on how to build an arduino. But i couldn't find anything about building your own rtc. I have a few ds3231 rtcs and they are great build i would prefer to build my own now. My question is does anyone have an idea how? Because i want to keep the project small i wanted to add a better crystal to the arduino but don't know enough about it. What should i do to build my own rtc?
Have you read the layout recommendations in the DS3231 datasheet?
Typical crystals have accuracy specs of 50-100 parts-per-million. You can do the calculations, but I believe that's in the ballpark of 1 minute out of 10 days. If you buy from a reputable manufacture, that's going to be a worst-case spec (as long as you stay within the specified temperature range).
If that's not good enough, I assume there are ways of "trimming" the oscillation frequency (with capacitors?). I'm pretty sure my watch (and RTC modules) are better than 50 ppm, so either they are buying super-good crystals or they are trimming.
Or, you could make timing corrections in software (if it's running consistently-fast or consistently-slow). The problem with tweaking/correcting clock speed is that you need a (accurate/calibrated) frequency counter to check the frequency if you don't want to take several weeks testing & adjusting the time-drift.
Standard C/C++ has [u]clock/time[/u] functions but I don't know if that's part of the Arduino C++ library.
DVDdoug:
Standard C/C++ has [u]clock/time[/u] functions but I don't know if that's part of the Arduino C++ library.
There is a 3rd party time library, TimeLib.h; it was originally called time.h
DVDdoug:
If that's not good enough, I assume there are ways of "trimming" the oscillation frequency (with capacitors?). I'm pretty sure my watch (and RTC modules) are better than 50 ppm, so either they are buying super-good crystals or they are trimming.
The DS3231 has both a trim register, and temperature compensation. It beats 50ppm by a mile. One of these days I plan to actually trim one to GPS time but, a trim value of zero is always so close as to make it seem OCD to change it.
dennis_arduinouser:
I found some guides on the internet on how to build an arduino. But i couldn't find anything about building your own rtc. I have a few ds3231 rtcs and they are great build i would prefer to build my own now. My question is does anyone have an idea how? Because i want to keep the project small i wanted to add a better crystal to the arduino but don't know enough about it. What should i do to build my own rtc?
Look here
Reading the Temperature from the DS3231 & DS18B20
http://kevinrye.net/index_files/reading_the_temp_ds3231_and_ds18b20.php
It is very simple to turn the ATMega328, used in the standard Arduino, into an RTC.
Replace the crystal with a 32 kHz watch crystal, which acts as a clock source for Timer2 (asynchronous mode) and use the internal 8 MHz oscillator for the rest of the CPU.
Described here and elsewhere on the web.
It won't be as accurate as the DS3231 as the crystal is not temperature compensated, but the RTC can keep running while the rest of the processor sleeps, so it is quite useful.
If you are interested I can post Arduino code to implement the RTC.
DVDdoug:
I believe that's in the ballpark of 1 minute out of 10 days
My cheap Casio wristwatch has an error of about 1 minute in 6 months - I like it to be about 1 minute fast and I only have to correct it when the time changes in March and October. I had assumed that RTC modules would have similar performance.
...R
I had assumed that RTC modules would have similar performance.
No, because they are usually subjected to larger temperature variations than a watch worn on the wrist.
For a small Arduino project with an RTC, use a Teensy 3.6. Add a coin cell battery and it will kerp time for a very long time.
For smaller, use a Teensy 3.2 but you have to add the 32kHz crystal yourself.
The processor on the Arduino Due also has this ability but the Due board does not allow it.
MorganS:
The processor on the Arduino Due also has this ability but the Due board does not allow it.
I'm curious - I noticed an unpopulated place for 32khz crystal and trim caps on my Due board. I wondered about whether you could populate and run it. Why would it be completely not allowed? What kills the idea?
Robin2:
My cheap Casio wristwatch has an error of about 1 minute in 6 months - I like it to be about 1 minute fast and I only have to correct it when the time changes in March and October. I had assumed that RTC modules would have similar performance....R
Well, Casio has a better quality than most. 99% of all cheap watches and clocks run way too fast because the trim capacitor that would be used to calibrate it is simply omitted. I don't have any experience with the cheap RTC modules, I always just avoided them since the DS3231 is so easy to get.
For a while, I was playing with adding homebrew foil capacitors to cheap clocks, and calibrating them by gradually reducing the capacitance by snipping it shorter with scissors. I have a few that keep +/- a minute a year from that experiment.
aarg:
I'm curious - I noticed an unpopulated place for 32khz crystal and trim caps on my Due board. I wondered about whether you could populate and run it. Why would it be completely not allowed? What kills the idea?
Then your Due probably can run the RTC module on the chip. All the Due boards I have don't have any spare pads for the crystal.
Adding the coin cell battery to the Due to keep the clock running when the rest of the chip is not running is also an issue to be checked. The original Due design doesn't allow those pins to be powered without powering the rest of the chip.