An IoT Maker Tale: Stratum-1 Time Server Built From Scratch
Cristiano Monteiro - May/2021

An IoT Maker Tale: Stratum-1 Time Server Built From Scratch

By: Cristiano Monteiro <[email protected]> - May/2021

Since a young age, I’ve been obsessed with timekeeping and clocks in general, mostly mechanical ones and their ingenuity. As a technology professional, I understand the importance of accurate timekeeping in our digitally connected world. Even a mere seconds delay in a computer clock is enough to render your token generation app almost useless or prevent Ham Radio Operators from completing digital communications (and that’s a separate topic).

My hands-on approach to dissecting IoT from the inside led me to the endeavor of fulfilling a long-time dream of having an on-site Stratum-1 Network Time Protocol (NTP) server. NTP is the decades-old synchronization protocol that keeps networked computer clocks accurate.

The best-case scenario for an NTP server is being fed from a Stratum-1 time source, that is, for instance, connected to the source of a VERY accurate time, usually an atomic clock (also called, Stratum-0).

A good amount of Stratum-0 time sources is constantly floating over our heads! The GPS satellites, each one carrying at least two cesium atomic clocks (accurate up to 1 second every 300 million years).

The idea of using GPS as time sources is not new, there are dozens of commercial products available doing exactly that. But my goal is to make it cheap, accurate, self-contained, dual powered (mains and batteries), wireless-enabled, and portable to use on the field in my HAM Radio activities. Powered by the ever-expanding universe of microcontroller units, this goal is closer than ever.

Based around the very capable Espressif ESP8266 NodeMCU Amica board, which conveniently brings WiFI capabilities. I’ve built the design and implementation described here.

No alt text provided for this image

First, I need a Real-Time Clock (RTC) module to, as accurately as possible, preserve time during the intervals where satellite connection is lost. For this task, I chose the DS3231 board, an affordable temperature-compensated quartz module. It’s a well-known phenomenon the crystal oscillation drift based on temperature changes, this can be mitigated by a temperature compensation mechanism, available in this board.

No alt text provided for this image

In order to capture the GPS signals, a GPS chip is also needed, preferably in the form of a module, since I want to keep the project as simple to replicate as possible. But not all GPS modules are built the same. In a project where the main goal is reliably acquiring the accurate GPS time reference, a “Pulse Per Second” (PPS) capable module is required.

PPS is a squared wave electrical signal with a less than one-second width but with a precise 1 Hz frequency. 1.000 pulses per second.

This signal is of vital importance to keep a time server synchronized with the atomic source, by synchronizing top of the second shift with PPS input.

For this task I’ve chosen the Neo-6m V2 module, which provides a dedicated PPS pin, as seen below:

No alt text provided for this image

Measured the PPS output on my Rigol oscilloscope and it was spot-on:

No alt text provided for this image

Now a way to show the user it is running and producing data is needed. What better than a vivid, bright, white OLED display?

No alt text provided for this image

Equipped with these basic elements I’ve built the schematics shown below (all reference files can be found on the project’s Github page below):

No alt text provided for this image

Programming a Micro Controller Unit (MCU) requires getting your hands dirty with physical pins, voltage levels, and low-level communication protocols. The most difficult part was the pin availability (or lack off) on the AMICA board. At first, I had three different communication protocols concurring for pins: SPI (display), I2C (RTC), and UART (GPS). Making these communicate in peace in this pin starving environment proved difficult, especially with my requirement of having 3 status LEDs (WiFi, Lock Status, and PPS - I like LEDs, bite me) and a push-button to disable/enable WiFi (power-hungry kid). In the end, I settled to deal with two protocols only: I2C (replacing display for an I2C version and beautifully daisy-chaining RTC from it, thus saving pins) and UART for the GPS. Still, almost exhausted all pins but had a happy and United Family in the end.

Now it’s time to work on the last, but no less important, hardware part of the project, the dual power source. For that, I just “glued” together the common 18650 lithium-ion battery cell, a battery charge/discharge controlling circuit, and a step-up module to bring the battery 3 – 4.2v output to the necessary >5V for the Amica module. Made sure to keep both blocks (timekeeping and power) independent and connectable by screw-type connectors, to make maintenance and replacement easier.

No alt text provided for this image
No alt text provided for this image

Here the final assembled unit, open heart. For that, a Patola model Pb-205 was used, the front panel is a transparent 3mm laser cut customized acrylic piece, drawn on SolidWorks.

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

To run all this bare metal, I made use of the Arduino framework and based my code on the work of:

https://w8bh.net/avr/clock2.pdf

https://forum.arduino.cc/t/ntp-time-server/192816

Changed it to suit my hardware and design choices, adding the WiFi functionality and improving the debug handling to facilitate diagnosing that many parts working in synchronicity.

All source files can be found here:

https://github.com/Montecri/GPSTimeServer

That’s it, a robust, portable, light, dual powered, Wi-Fi enabled, accurate, and cheap Stratum-1 time server.

No alt text provided for this image
No alt text provided for this image

References:

https://en.wikipedia.org/wiki/Network_Time_Protocol

https://en.wikipedia.org/wiki/Atomic_clock

https://ieeexplore.ieee.org/document/1540272

https://en.wikipedia.org/wiki/Pulse-per-second_signal

https://www.globalacrilicos.com.br/

https://www.patola.com.br/index.php?route=product/product&product_id=128

Savita Patil

Sr.Software Developer at Embosys Softech Solutions.

1 年

Hi, Its very Interesting & useful project. Thank u

Stuart Maskery

Purchasing Manager at Trafalgar Electronics

2 年

Cristiano, I hope you can help, I was going to rebuild my NTP server based on your design with the ESP32 processor as I keep having problems with the ESP8266 getting overwhelmed by the number of satellites in the sky (Starlink I believe) I wanted to use your front panel design and 3D print it, but I don't use SolidWorks and the online converters to STL keep throwing up errors. Is there any chance you can export that file to .stl in SolidWorks and upload it to GitHub?

回复
Stuart Maskery

Purchasing Manager at Trafalgar Electronics

3 年

Cristiano, just a heads up on the RTC module in your build as its a potential fire / explosion risk that came up during my debugging, the RTC clock module normally takes an LIR2032 battery (you can use a CR2032 battery if you modify the board) however it has really bad overcharge protection so I strongly suggest if your using a LIR2032 battery that you fit a MCP73871 based battery charger module between the battery and the RTC.

Hello Cristiano Monteiro, First of all thank you for this work because it interests me a lot. Indeed, I often use digital modes such as FT8. I have just gathered all the elements to set up your project but only I absolutely cannot install the program. Would it be possible to send me the .bin file to use ESP8266Flasher? Here is my email address: [email protected] Thank you very much, 73 'from Sébastien F4HRE

要查看或添加评论,请登录

Cristiano Monteiro的更多文章

社区洞察

其他会员也浏览了