• STM8 Clock - RTC

    11/20/2019 at 13:28 6 comments

    I have upgrade the code inside the clock with a numerically-controlled oscillator (NCO) with a 24-bit phase accumulator.  The NCO allows me to finely compensate against the crystal's tolerance.  It is a step up in the resolution from tweaking the 16-bit timer divider in my timer project. While the timer divider could be extended in firmware using overflow and timer compare, the NCO approach actually is much simpler. 

    I have modified my RTC code which was running from a 10Hz interrupt. The timer now generates a 20Hz (+/- clock tolerance) interrupt with the NCO code implementing the divide by (2 + tolerance tweak).

    There will be additional jitters (of 50ms) of this approach, but it is not too noticeable.

    // 20Hz IRQ
    // tick comes from Direct Digital Synthesis
    DDS_Accum += DDS_PhaseInc;
    if (DDS_Accum & DDS_CARRY)
      // 10Hz RTC code here
    DDS_Accum &= DDS_MASK;

    The clock has been running close to 32 hours and so far it is within 100ms (or so) to the internet time at https://time.is/  So likely it would be within a few seconds for a month.  Just 3 lines of code.  Why pay for an extra RTC chip?

    Meanwhile my Win10 clock has drifted to 1.6 seconds in the same period. (Win10 would resync the clock once in a while.)

    The clock is limited by the drift and temperature coefficient of the cheap 12MHz crystal.  It is sitting on my computer desk which is unlikely to get more than 10C of temperature change.

  • STM8 LED Clock

    11/14/2019 at 18:58 6 comments

    I made a digital clock. Originally I planned to use a VFD, but the user interface on a 4 digits was too much of a limitation. (I already have to cramped the UI on my STM8 timer with 16x2 LCD) 

     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 RTC is implemented in firmware using a DDS for fine frequency adjustment.  A supercap allows the STM8 to work for a few minutes during a power failure. The LED driver is on a separate rail.

    The PCB is wired to the original (stripped) 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, but the 74HC595 frees up a few GPIO lines. UART, I2C, a Timer pin, power and the debug interface 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.)

    Still working on the user interface and other features.

    Side by side view of the old traveler's Casio clock it is replacing as it is much harder to read during night time.

    My blog: https://hw-by-design.blogspot.com/2019/11/stm8-led-clock-part-1.html 

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

    Initial release: bare minimal feature.  

    It is one of those things that once it works, you don't want to mess around too much.

  • Possible STM8 based meter

    09/15/2019 at 01:47 0 comments

    I found a USB meter that might have a STM8 inside along with a 4-pin programming connector.  It also have series resistors for the display.

    I'll let someone else play with it.