The Network Time Protocol (NTP) has transformed global timekeeping, enabling accurate date and time retrieval from anywhere in the world. NTP is a straightforward UDP-based protocol that can be implemented in microcontrollers. The Tuxgraphics NTP clock has gained popularity over the years, with version 2.0 featuring a built-in DHCP client. This clock can be plugged into any network, and the setup process is automatic, requiring no prior knowledge of IP networking. The NTP protocol is outlined in RFC958 and utilizes a 64-bit timestamp, where 32 bits represent the seconds in Coordinated Universal Time (UTC) since January 1, 1900, and the remaining 32 bits represent fractions of a second. This allows for a high degree of accuracy, although for basic applications, evaluating only the seconds is sufficient. The AVR NTP clock synchronizes with an NTP server upon startup and maintains local time using a timer interrupt. It attempts to resynchronize every hour, and in case of a temporary loss of network connection, the onboard crystal maintains accurate time for several weeks. Once the network connection is restored, the clock synchronizes again. A status indicator appears in the lower right corner while awaiting a response from the NTP server. Public NTP servers are maintained by universities, government organizations, and major companies like Apple, with a suitable server pre-configured in the Tuxgraphics NTP server code. The clock functions as a counter, with the NTP server providing the initial counter value, which is then incremented every second. The NTP server transmits time as seconds (and fractions of seconds) since January 1, 1900, GMT. Converting these seconds into a human-readable format can be computationally intensive for a microcontroller, especially since the AVR is an 8-bit processor, making 32-bit arithmetic costly, though it is still feasible.
For constructing a suitable case for the clock, previous versions have utilized thin polycarbonate (Lexan) or acrylic glass (Plexiglas) sheets, bent into an L-shape. These sheets are available from online retailers or larger hardware stores. To bend the polycarbonate without breaking it, heating along a thin line is required. A plastic sheet bending machine can be constructed using constantan wire from an old toaster or electric heater. This machine holds the wire straight using a spring, as the wire expands when heated. The groove where the wire sits is lined with aluminum foil. A current of about 3 amperes DC is passed through the wire to heat it, with the exact amount depending on the wire's diameter. The wire should be hot but not glowing red. The plastic sheet is placed over the groove and heated along the thin line for approximately two minutes, ensuring it does not touch the wire. Once heated to the appropriate temperature, the plastic can be bent easily. It is important to use a sufficiently strong plastic, as the ultra-thin clear plastic packaging found in grocery stores is not suitable. Stronger clear plastic packaging from consumer electronics or toys may be used, or a clear plastic bottle can be repurposed by cutting it into sheets. The clear plastic can be easily cut with scissors and bent along a ruler without prior heating. A strip measuring about 10 cm (4 inches) wide can be cut and folded into a triangle shape for the clock's case. The clock will display an Ethernet link status and will continue to attempt synchronization with the NTP server every hour.The Network Time Protocol (NTP) has revolutionized the world. Suddenly one could have anywhere in the world accurate time and date. NTP is a simple UDP based protocol and can be implemented in a microcontroller. The tuxgraphics NTP clock has been very popular over the years. This version 2. 0 has a built-in DHCP client. You just plug this clock int o any network and everything else is automatic. You don`t need any knowledge about IP networking. The NTP protocol is described in RFC958. Essentially it is just a 64 bit time-stamp. 32 bits of this time-stamp are the seconds in UTC (=GMT Greenwich mean time) since since Jan. 1st 1900. The other 32 bits are fractions of a second. In other words NTP can be very very accurate. For our purposes it is however enough if we just evaluate the seconds. The AVR NTP clock synchronizes at startup with a NTP server and uses then a timer interrupt to maintain time locally. Every hour it tries then to synchronize again. If your DSL router is however off during the night then it`s not a problem. The clock just continues. We use the on board crystal to maintain accurate time over several week. Once the network connection is back it will just synchronize again. A little status indicator appears in the lower right corner while the clock is waiting for an answer from the NTP server.
Public NTP servers are maintained by various universities, government organizations and big computer companies like apple. A suitable server is already pre-configured in the tuxgraphics ntp server code. A clock is essentially just a counter. Since NTP is already a 32-bit "counter" we just take a 32bit variable and increment it. That is: the initial setting of the counter comes via NTP and then we just count up every second. A NTP server sends out the time as seconds (and fractions of seconds) since 1-Jan-1900 GMT. The math to convert seconds since day-X into a human readable format is a quite heavy for a microcontroller.
The AVR is a 8-bit processor therefore 32-bit math is expensive but it can still be done. I am always asked for ideas on how to build a good case for the clock. For all previous version I have used a thin (2-4mm) polycarbonate (lexan) or acrylic-glas (plexiglas) sheet and I just bend it into an L-like shape. You can find such sheets on ebay or in bigger hardware stores. You need to heat the polycarbonate sheet along a thin line in order bend it without breaking it. For this you can build a plastic sheet bending machine out of a constantan wire from an old toaster or an electric heater.
A plastic sheet bending machine. A spring holds the constantan wire straight inside the groove because the wire expands while heated. The groove is lined on the sides with ordinary aluminum foil. You run about 3 ampere DC through the wire to heat it. The exact amount depends on the diameter of the constantan wire. The wire must be hot but not glow red. The plastic sheet is then placed over the groove and heated just along that thin line for about 2 minutes. Note that the plastic does actually not touch the wire. Once heated to the right temperature you can bend the plastic sheet like warm wax. Since we have heated the sheet only along that thin line it will just bend there. The ultra thin clear plastic packaging as found in the grocery store is too thin and not suitable to make a case.
It should have some strength. Consumer electronics or toys are often packaged in bit stronger clear plastic. You may as well be able to use a large clear plastic bottle from which you slice out a ring and then cut it open to get a sheet of plastic. The clear plastic packaging can just be cut with scissors and you can bend it along the edge of a ruler without heating it first.
Cut out a long stripe about 10cm (4 inch) wide and fold it into a triangle as shown below. `|`: ETH link up we are waiting for an answer from the NTP sever. The clock tries to sync every hour. Thus if you cut 🔗 External reference
Quartz clocks, which have dominated timekeeping for the past 20 years, have one issue: their errors, although slight, are cumulative.
Quartz clocks operate based on the piezoelectric effect of quartz crystals, which oscillate at a precise frequency when subjected to...
An In Circuit Programmer is a very valuable tool. Not only does it allow you to program your AVR's with ease, you can update your program without having to remove the AVR (very useful when working with surface mount...
This circuit generates a digital square wave that can be displayed directly or utilized to drive additional circuits. It employs the CMOS 4047 Low-Power Monostable/Astable Multivibrator, as referenced in Tom Duncan's "Adventures with Digital Electronics" book, to control a...
The clock will have 6 digits and time setting will be done by means of a few buttons. I will try to use the most common types from widely used microcontroller families of miscellaneous producers. I will write the...
Use microcontrollers to establish serial communication between the AVR-006 kit and a computer. This project utilizes the AVR-006 microcontroller from Circuits-Home. Before developing the program, it is essential to understand the hardware specifications. An example program (in C) for...
An L7805 voltage regulator provides a 5V rail. The input and output of the regulator are stabilized using a 470µF capacitor and a 10µF capacitor, respectively, to smooth the voltage supply. This 5V rail powers the MAX232 level shifter...
We use cookies to enhance your experience, analyze traffic, and serve personalized ads.
By clicking "Accept", you agree to our use of cookies.
Learn more