Subject: real time clock
From: rotaryeng
Date: 6/15/2013, 11:26 PM
To: AAA-rotaryeng


I may not have all my setting right (RE:real-time clock).
Please explain why you think my
battery is dead, it was replaced less than 2 months ago.
Dan


Your messages are saying it is 10:31 AM in your computer when I just got it.
Are you working for the NSA? :) Maybe the NSA does not like you and they
are reading and delaying the forwarding of your messages :).

Paul Lamar
===================================================================
http://scholar.lib.vt.edu/vtpubs/spectrum/sp970911/3b.html


    Every personal computer contains two clocks: a built-in hardware clock and a virtual
clock. The hardware clock (real-time clock) runs whether the system is on or off. The
virtual clock (system clock) is set to the real-time clock when the computer is turned on
and exists only while the computer is operating. While the computer is up and running, the
two clocks run independent of each other.

   The system clock is a 24-hour timer and has no real concept of days, whereas the
real-time clock tracks the time and date. In fact, the system clock has no concept of
traditional hours, minutes, and seconds. It merely increments a counter 18.2 times per
second. The operating system, which is dependent upon the system clock for the time,
converts the counter into hours, minutes and seconds.

   As for the date, the operating system reads the real-time clock via the BIOS during
initialization, then tracks the date independently based on the virtual-system clock
rolling over midnight.

   The real-time clocks used in today's personal computers do not track centuries; only
years, such as '96, are tracked. After Dec. 31, 1999, the real-time clock merely indicates
year '00. It is the BIOS's responsibility to track the century and preserve that
information in the real-time clock's nonvolatile memory. The BIOS assumes that the years
1900 through 1979 cannot occur, so when the year is within 00-79 and the century
information is 19, the BIOS sets the century information to 20. If the BIOS does not track
the century, the operating system will be given an invalid year and most likely will
assume 1980. (Microsoft operating systems do not support dates earlier than 1980.)

   Caveats

   Since the two clocks run independently, the real-time clock can be set to any
nonsensical value and the operating system will not notice. Such will occur Jan. 1, 2000
if your system does not support the year 2000. As long as the system is running, the
operating system will correctly support the occurrence of the year 2000. Problems will
occur, however, when the system is rebooted or powered off, then on. This is the first
caveat: setting the date and time just before the year 2000 and just letting the new year
occur is not a valid test. The real-time clock may be invalid, but the date according to
the operating system will be correct. The system must be powered off, then on to complete
this type of test, but there is still a catch.

   The second caveat applies when the operating system is used to set the date and time.
The system clock will always be set by the operating system. However, not all operating
systems will concurrently set the real-time clock with the system clock. In this scenario,
the above methodology may cause a system that correctly supports the year 2000 to fail if
the operating system does not set the real-time clock as well.

=======================================================

http://www.softdevlabs.com/ClockMon/ClockMon.html


Software Development Laboratories™


ClockMon™©


A free Windows real time clock
monitoring and synchronization utility


Version 2.3.0.291


(click on the above link to download; 40K)
(or build it yourself from the source; 128K)



The problem


I happened to notice that for some time now my Windows system couldn't keep time worth crap.

It was constantly losing time, anywhere from several seconds per hour or so to many minutes per day (sometimes as much as 15 minutes or more in a single day!)

I couldn't figure out why it was happening and just figured either my RTC circuitry was bad or the battery was low or something.

I even went so far as to install a little freeware clock synchronization program that syncs up your computer clock to one of the many atomic clock time servers out there on the Internet, and wrote a little batch program to log the results.

For several months I simply made note of the fact that my clock was very frequently very out-of-sync with the rest of the world and made adjustments to how often I would have to resync to one of the atomic clocks in order to maintain a reasonably accurate time-of-day clock, until eventually I had to resync every few hours.

Eventually, though, I began to notice a definite pattern.

I noticed that whenever I would get heavily involved in program development, doing frequent compiles and links of whatever program I happen to be developing, the clock would get out of sync more quickly than otherwise. I found this to be especially true (especially noticeable) when I did cross-platform development under Cygwin, using the GNU make and gcc compiler and other tools. I also noticed that during such Cygwin builds, my mouse would be slightly jerky and somewhat on the sluggish side.

This eventually caused me to suspect that the reason my clock was becoming more and more out of sync was because clock interrupts were being lost, gradually causing the Windows clock to get further and further behind (i.e. to lose time).

A few hours of investigation doing various searches on the web and a few searches of Microsoft's own support database confirmed my suspicion.

However, as what may come to no surprise to some, the various suggested work-arounds failed to resolve the problem. My clock was still getting out of sync rather quickly whenever I did some heavy duty program development.


The solution


Eventually I decided enough was enough and sat down and wrote ClockMon™, a handy little program that periodically reads the hardware (BIOS or CMOS) Real Time Clock (RTC) and compares it with the Windows operating system clock, resetting the Windows clock whenever it notices the two are out of sync.



The Rotary Engine News Letter. Powered by Linux.
ACRE NL web site. http://www.rotaryeng.net.
You Tube http://tinyurl.com/beqqxas.
Copyright 1998-2013 All world wide rights reserved.