SynchroTime
CLI- and GUI-client for adjust the exact time and calibrating the RTC DS3231 modules
Install / Use
/learn @SergejBre/SynchroTimeREADME
SynchroTime - CLI- and GUI-client for adjust the exact time and calibrating the RTC DS3231 modules
<p align="center"> <a href="http://www.kernel.org" rel="nofollow"> <img alt="Platform (GNU/Linux)" src="https://img.shields.io/badge/platform-GNU/Linux-blue"/> </a> <a href="https://www.wikipedia.org/wiki/Windows" rel="nofollow"> <img alt="Platform Win32" src="https://img.shields.io/badge/platform-Win32-green"/> </a> <a href="https://github.com/SergejBre/SynchroTime/releases"> <img alt="releases page" src="https://img.shields.io/github/v/release/SergejBre/SynchroTime"/> </a> <a href="https://github.com/SergejBre/SynchroTime/releases"> <img alt="Github All Releases" src="https://img.shields.io/github/downloads/SergejBre/SynchroTime/total"/> </a> <a href="https://github.com/SergejBre/SynchroTime/issues"> <img alt="Issues" src="https://img.shields.io/github/issues/SergejBre/SynchroTime"/> </a> <a href="https://sergejbre.github.io/SynchroTime/doc/html/index.html"> <img alt="Docs Doxygen" src="https://img.shields.io/badge/docs-Doxygen-blue"/> </a> <a href="https://github.com/SergejBre/SynchroTime/blob/master/LICENSE"> <img alt="License" src="https://img.shields.io/github/license/SergejBre/SynchroTime"/> </a> </p>
Motivation. What is a Real-Time Clock (RTC)?
Electronic devices perform tasks in response to the periodic oscillation of an electrically varying digital voltage signal or clock signal. On the other hand, human time (also known as “real” time) is measured in seconds, minutes, hours, days, months, and years as dictated by the rotational cycles of the earth. For electronic devices (such as a smart watch) to perform their tasks when required by a user, they must store a digital representation of real time, which is then kept in sync by the digital clock signal. In an electronic device, realtime information is maintained by its RTC circuitry. This will usually be located within the device microcontroller or may be a separate IC on the system board.
The real-time clock module on the IC DS3231 has proven itself well in work with microcontrollers Arduino, Raspberry Pi, etc. According to the declared specification, it is an extremely accurate RTC with a guaranteed accuracy ±2 ppm (from 0°C to +40°C), which translates into an error of just 1 minute over the course of a year under the worst case scenario. But a large number of modules on the market do not meet the accuracy declared by the manufacturer, which is undoubtedly upsetting. Nevertheless, the manufacturer has provided for the possibility of correcting the drift of the frequency, which is associated with the aging of the oscillator crystal in the range from -12.8 to +12.7 ppm. This correction value can be written to one of the registers on the DS3231 (see part Discussion for exact ppm values). In addition, the manufacturer has provided a the energy-independent flash memory AT24C256 in the module, into which calibration parameters and correction factors can be placed. The tool below can automatically calibrate the DS3231 module.
Contents
- About the app
- Using the CLI app
- Using the GUI app
- Specification
- Description of the request protocol
- System Requirements
- Installing the CLI and GUI apps
- Discussion
- Documentation
- Dependencies
- Compilation under Linux
- Issues
- License
About the app
-
CLI and GUI applications are used for fine adjust and calibrating the DS3231 RTC module.
-
The application allows you to:
- adjust the time of the RTC DS3231 with your computer time;
- correct the frequency drift of the RTC DS3231. The algorithm performs correction in the range from -12.8 to +12.7 ppm.
- The application allows you to evaluate the accuracy and reliability of the RTC oscillator for a particular sample, as well as the chances of successful correction in case of significant time drift;
- automatically save parameters and calibration data to the energy-independent flash memory of the type AT24C256. In case there is a power failure to the module.
- The application allows you to estimate the response delay over a serial port using a dynamic moving average method (Simple Moving Average).
-
The interface and help system of the application are multilingual: English, German and Russian.
-
Developed in pure Qt, no third party libraries.
-
Cross-platform application implementation (Linux and Windows).
-
The client communicates with the Arduino server via the serial interface (UART). The application allows you to easily select a serial port for communication with the server and save the port name in the program settings.
-
Command Help
$ ./synchroTime -h

Using the CLI app
- First, you need to upload the sketch to Arduino from the arduino/synchro_RTC.ino project directory, if you have a DS3231 ZS-042 module or arduino/synchro_RTC_MINI.ino, if you have a DS3231 MINI module, then connect the RTC DS3231 module according to the circuit shown in the part Specification.
Connect your Arduino to your computer via a free USB port. If there is a necessary driver in the system, a new virtual serial port will appear in the system (under Linux it will be
/dev/ttyUSBx, under Windows -COMx). To find the name of this port, call the application with the-d (--discovery)switch:
$ ./synchroTime -d
Serial Port : ttyUSB1
Description : USB2.0-Serial
Manufacturer: 1a86
Vendor ID : 1a86
Product ID : 7523
System Locat: /dev/ttyUSB1
Busy : No
Serial Port : ttyUSB0
Description : USB2.0-Serial
Manufacturer: 1a86
Vendor ID : 1a86
Product ID : 7523
System Locat: /dev/ttyUSB0
Busy : No
A total of 2 serial ports were found.
And under the Windows OS
C:\\SynchroTime\\build>synchroTime -d
Serial Port : COM5
Description : USB-SERIAL CH340
Manufacturer: wch.cn
Vendor ID : 1a86
Product ID : 7523
System Locat: \\\.\\COM5
Busy : No
Serial Port : COM3
Description : Agere Systems HDA Modem
Manufacturer: Agere
Vendor ID : 11c1
Product ID : 1040
System Locat: \\\.\\COM3
Busy : No
A total of 2 serial ports were found.
- To select a virtual Serial Port, enter its system name after the command
-p \<portName\>. The app will automatically create a configuration file, and the next call will contact the selected port.
$ ./synchroTime -p ttyUSB0
Added new serial interface ttyUSB0.
And under the Windows OS
C:\\SynchroTime\\build>synchroTime -p COM5
Added new serial interface COM5.
- Use the
-i (--information)command to get the current information from the DS3231 module. If everything is connected correctly, then you will get the current time of both clocks, the difference between the clocks in milliseconds (with an accuracy of ±2 ms), the value written in the aging register and the calculated time drift value in ppm. If the aging register and time drift are zero, then the DS3231 has not yet been calibrated (see step 5.)
$ ./synchroTime -i
DS3231 clock time 1598896552596 ms: 31.08.2020 19:55:52.596
System local time 1598896589772 ms: 31.08.2020 19:56:29.772
Difference between -37176 ms
Offset reg. in ppm 0 ppm
Time drift in ppm -8.78162 ppm
last adjust of time 1594663200000 ms: 13.07.2020 20:00:00.000
- To set the exact time, use the
-a (--adjust)command. The module clock will be synchronized with the computer time with an accuracy of ±1 ms. After updating the time, the date of the time setting will be recorded in the module's memory, which will allow later to determine the exact drift of the clock time.
$ ./synchroTime -a
System local time Mo. 31 Aug. 2020 20:02:52.000
Request for adjustment completed successfully.
- To calibrate the clock of the DS3231 module, enter the
-c (--calibration)command. For the successful execution of this procedure, the module must be activated (see point 4.) and it is necessary that enough time has passed so that the calculated value of the clock drift is well distinguishable from the rounding error (ca 55 hours or 2.3 days, see part Discussion). The algorithm of the program will calculate the amount of drift of the clock time and the correction factor, which will be written into the aging register. The clock time will also be updated. If the calibration is successful, the current time, drift and correction factor will be displayed, as in the screenshot.
⚠️ Note: This method is slow, but has the advantage of not requiring any manual effort other than setting and reading the clock. Letting it run quietly on a shelf for a day or two is pretty easy. It also means that the clock goes through many day/night cycles and is subject to temperature changes, so it helps measure the long-term stability of the clock.
$ ./synchroTime -c
System local time Mo. 31 Aug. 2020 20:04:14.000
Offset last value 0
Time drift in ppm -2.11938 ppm
Offset new value -21
Request for calibration completed successfully.
- To reset the aging register to its default value and clear the module's memory of calibration data, enter the
-r (--reset)command. The default value will be written to the register, and memory ce
