Close
0%
0%

A Very Accurate LED Clock

This clock is accurate to +/- 1 sec/month without relying on GPS or NTP synchronization. The RTC is implemented in firmware.

Similar projects worth following
STM8S003 LED clock. This clock uses a firmware 24-bit Numerically Controller Oscillator for fine tuning tolerance. Once calibrated, it removes the need for external synchronization.

Features:
- 6 digits 7 segments LED display
- Accurate all firmware based RTC with Supercap for RTC backup.
- Time, date, leap year, Daylight Saving Time
- Low power consumption: 5V at 20mA

Motivation:

I sometime play games into the night without realizing how late it is. I need a clock below my monitor that is non-distracting, large, easy to read in my peripheral vision. Also it would be ideal if is set and forget i.e. accurate enough and handle silly DST time changes.

Additional pages for this project on HaD:

https://hackaday.io/page/6687-stm8-led-clock - more project details
https://hackaday.io/pages/10708 - test results

External Project page: 

Github: https://github.com/FPGA-Computer/LED-Clock

User interface

The clock and display time:

The arrows key switches between the time and date display.  The date display uses a different format to distinguish the modes.  The 7 segment LED can only show a limited set of characters and have to make do with some approximations. 

e.g. Th(ursday) 16 Jan is shown below.  

Time (and similarly date) can be set using 3 buttons.

Hardware description:

Instead of using the usual RTC modules used by other projects, the RTC is implemented in firmware with features such as Daylight Saving Time. The RTC code can be adapted for oddball clocks that uses different units of time. e.g. Metric time or Mars time. 

The clock doesn't require an ultra accurate crystal.  As long as it has a very stable frequency, then the tolerance can be calibrated out.  I used a common AT-cut 12MHz crystal as the frequency source. 

If clock is used in a home environment with temperature controlled, chances are that the temperature variation is small enough to get away without using a TXCO.  e.g. Heater set to 21C and air condition to 25C means that the variation is about 4C.

There is only a very narrow frequency range that you can shift a crystal by the load capacitance and a trimmer capacitor doesn't make fine adjustment predictable nor repeatable.

A 16-bit timer in the STM8 generates a 20Hz IRQ. A more accurate 10Hz is then generated from using a 24-bit Numerically-controlled oscillator (NCO) implemented in firmware.

e.g. if your 20Hz is  +50ppm fast = 20.001Hz, 10Hz can be generated by dividing it by 2.0001.

NCO can perform fractional frequency division by keeping track of the phase in an accumulator.  Don't let the name fool you, this 3 extra lines of code is all that's needed for very fine frequency adjustments!

The 10Hz is used by the RTC code to update the time, date and implement the Daylight Saving Time (DST) for North America.

 (repost from https://hackaday.io/page/6687-stm8-led-clock)

I made a digital clock. Originally I planned to use a VFD, but the user interface on a 4 digits would be too limiting. I used a STM8S003, 74HC595 and a couple of  the cheap green 7 segment displays. The display efficiency is actually not bad as the entire clock runs on 5V at ~20mA.

The LED driver is on a separate rail. A supercap allows the STM8 to work for a few minutes during a power failure. 

The PCB is wired to the original (stripped) Caller ID PCB to use existing buttons. The same GPIO for the common cathode driver when off-duty is used for polling the buttons.

I could have used the STM8 alone to drive the display. By adding the 74HC595, I freed up a few GPIO lines for future expansion.

External I/O

UART, I2C, a Timer pin, 5V power and the hardware debug interface (SWIM) are connected to the headers on an I/O panel PCB using the existing RJ11 cutouts. I have since changed the power connector to a MicroUSB as it has much better latching.

Side by side view of the old traveler's Casio clock it is replacing as it...

Read more »

  • my thoughts

    K.C. Lee05/13/2020 at 11:34 0 comments

    Like a lot of my projects, I try to build things with what I have and reuse/repurpose some old broken parts for different purposes. I also try out new ideas which in this case is the use of NCO for trimming the clock.  Unlike the clock on website https://time.is/ my clock doesn't skip a second here and there.

    I have been coding RTC in firmware instead of relying a chip or a module or NTP or GPS like most clock projects. NTP and its etwork hardware and IP stack doesn't come for free either.  It means less parts for me to stock, order or pay for.

    I have read user comments about how inaccurate that some of the modules can be. My $0.20 microcontroller cost much less than a RTC and in most case can get close to the accuracy of the better parts after calibration. The calibration doesn't require anything other than my patience and a PC running a web browser. Since the calibration is done over a long time period, it averages out minor drifts due to temperature fluctuations etc.

    A RTC module has much lower standby power consumption than firmware running on a microconroller. For my projects, I do not see the need for long duration of standby operation.

    My 2nd year computer science course actually taught that as an example of a timer interrupt. Daylight saving time is implemented in my firmware. As we have seen how the politics can change the duration on a wimp rendering a hardware implementation non-functional.

    I always prefer a firmware trim than a mechanical trimpot or a trimmer cap as it is far more reproducible and controllable than trying to turn a fraction of a degree assuming you know which direction with a screw driver.  Thankfully some of the RTC chips and RTC peripherals on some of the microcontroller such as the STM32F030 are incorporating a trim register.

View project log

Enjoy this project?

Share

Discussions

Dan Maloney wrote 01/16/2020 at 19:32 point

I too love an accurate clock, and this is pretty impressive. But one thing I'd pay dearly for more than accuracy is synchronization - I hate that the microwave clock and the range clock seem to be in time zones separated by a couple of seconds. The clock in my high school were all synchronized, and that was 40 years ago. You'd think we'd have figured this out by now.

</rant>

  Are you sure? yes | no

K.C. Lee wrote 01/16/2020 at 19:46 point

AC frequency has/had pretty good long term accuracy until the politicians in the US decided to mess with it.  

My store bough $10 LED clock is pretty accurate, but I had to add a capacitor because the active power factor on my PC PSU injects enough noise to mess it up.

This LED clock is around $2-3 worth of part (minus the repurposed case and supercap backup).  :) I think I can get $6 GPS modules.

I have serial port on the back of the clock for GPS, but reception at my computer desk is not good and I am too lazy to write code.  I thought about a IR broadcast from my PC, but it turns out that my computer clock is less accurate - I saw up to 3 second drift a day until it was corrected by Windows synchronizations.

  Are you sure? yes | no

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates