Easy and Accurate Clocks without RTC IC


Results 1 to 19 of 19

Threaded View

  1. #1
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517

    Default Easy and Accurate Clocks without RTC IC

    Greetings,

    Attached are two programs that demonstrate how to easily make accurate clocks WITHOUT the use of Interrupts or Real Time Clock (RTC) chips. Both are based on TMRO but do not require preloading, adjusting, or tweaking the TMRO register before or after overflows. These programs also give the user lots of time to do other stuff between clock updates. The only time error is 100% related to crystal tolerance and drift (these examples require a 4 MHz crystal). The programs are based on the PIC12F629 but can be changed to your controller of choice. Extensive comments and schematics are in the code.

    These programs maintain the time as accurately as a DS1307 RTC or similar at +/-2 sec/day. If you need super accuracy, I suggest a MAXIM DS3231 RTC which boasts +/- 1 min/year accuracy.

    The algorithms used here have been adapted from Roman Black's “1 second timer” (www.romanblack.com). We have simplified and adapted these algorithms for easy implementation with PicBasic Pro. Comments welcome (in this forum for all to benefit) ...

    Enjoy,

    Paul Borgmeier
    Salt Lake City, Utah USA
    www.cruxanalysis.com

    Program 1 : EZCLOCK1.bas
    A simple program to set and show the time on an alphanumeric serial LCD (HH:MM format with blinking colon). Most of the code is dedicated to setting the initial time. Only about 30 lines of the code are required to accurately maintain the time and LCD updates, including colon blink.

    Program 2: EZCLOCK2.bas
    A technique we have used in our own consulting – most of EZCLOCK1.bas is dedicated to setting the initial time and then maintaining the display. This takes lots of valuable code space and additional hardware. For some projects, we just set the time in code at 12:00 (noon) and then start the device at precisely noon. Since the clock is highly accurate, a display is not required for many non-critical applications (e.g., sprinkler timer, fish feeder, water softener, while away lamp turn on relay, etc.). We have the code toggle a line high for 1.0 second on the hour so that we can check that the clock is running (e.g., LED, buzzer, counter, VOM, nothing, etc). Daylight savings time is the ideal time to stop and restart the device, which removes the crystal tolerance error while adjusting for the time change. The entire program is about 30–40 lines of code (depending on how you count), including register settings, variable declarations, initial values, and time keeping.

    As an example of doing something useful, we turn on GP0 at 8:00PM and then turn it off at 8:15PM. You can adjust to meet your own needs.

    A Note on Displays:

    EXCLOCK1 is written for a serial LCD alphanumeric display - probably the most popular style of display out there. Most of us have one or have made one. There are lots of displays options. The code also could easily be changed to work with parallel displays since the instruction set is essentially identical.

    How to make a Serial LCD
    search PicBasic List and/or Forum “serial LCD backpack'”

    Alphanumeric Displays
    google search “serial LCD”

    Larger 4 Digit Displays
    google search “serial LCD 4 digit”

    Enjoy ...
    Attached Images Attached Images  
    Attached Files Attached Files

Members who have read this thread : 2

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts