Motherboard Forums


Reply
Thread Tools Display Modes

how does software clock keeps time?

 
 
Harza
Guest
Posts: n/a
 
      08-23-2003, 05:49 PM
On start-up the software clock gets its time from the Real Time Clock
and sets itself to within 1 second of the RTC. It then operates
independently of the RTC maintaining the time by......?

I know it is something to do with hardware interrupts but can anyone
explain it properly?
 
Reply With Quote
 
 
 
 
Arno Wagner
Guest
Posts: n/a
 
      08-23-2003, 07:16 PM
Previously Harza <> wrote:
> On start-up the software clock gets its time from the Real Time Clock
> and sets itself to within 1 second of the RTC. It then operates
> independently of the RTC maintaining the time by......?


> I know it is something to do with hardware interrupts but can anyone
> explain it properly?


There is s timer chip (today part of a larger chip) that can be
programmed to generated interrupts at a fixed frequerncy.
For example on Linux it is set to 100Hz, generating 100 interrupts
per second. Each interrupt causes the software-clock to be increased
by 10ms.

Find more details on the chip here:

http://www.intel.com/design/periphrl/technote/7203.htm
http://tin.tu-ilmenau.de/ra/skripte/intel_8254.pdf

Arno
--
For email address: lastname AT tik DOT ee DOT ethz DOT ch
GnuPG: ID:1E25338F FP:0C30 5782 9D93 F785 E79C 0296 797F 6B50 1E25 338F
"The more corrupt the state, the more numerous the laws" - Tacitus


 
Reply With Quote
 
Harza
Guest
Posts: n/a
 
      08-24-2003, 03:14 PM
Thanks for that explanation.

Does WinNT/2000/XP uses 100 Hz also?

I think MS-DOS/Win95/98 use 18.2Hz.
Is this related to the timer chip running at 1.19318 MHZ and using
65536 to divide it down --> 1.19318 MHz/65536 = 18.2 Hz?

If so then what divisor does WinNT/2000/XP and Linux etc. use?

Also, I notice that on a Win2000 machine the timer granularity is
3579545 rather than 1193182 on WinNT.
What does this different timer granularity effect?


Finally, are the interrupts that are generated by the timer chip
hardware interrupts? Are they on IRQ 0? Is there a counter involved?


>
> There is s timer chip (today part of a larger chip) that can be
> programmed to generated interrupts at a fixed frequerncy.
> For example on Linux it is set to 100Hz, generating 100 interrupts
> per second. Each interrupt causes the software-clock to be increased
> by 10ms.
>
> Find more details on the chip here:
>
> http://www.intel.com/design/periphrl/technote/7203.htm
> http://tin.tu-ilmenau.de/ra/skripte/intel_8254.pdf
>
> Arno

 
Reply With Quote
 
 
 
 
Arno Wagner
Guest
Posts: n/a
 
      08-25-2003, 10:27 AM
Previously Harza <> wrote:
> "the crystal is hardwired at 1.19318MHz"


> So there is a crystal in the timer chip? This would mean that both the
> hardware clock (RTC) and the software clock (timer chip) have crystal
> oscillators?


Yes, they do.

> I thought oscillators were typically designed to run at 32768 Hz
> (2^15)?


Only those for one-second resolution low-power clocks. The RTC
might have one of these. The timer has not.

> Can you tell me the relationship between the RTC and the timer chip?


None. Except that they are in the same computer.

> Are the hardware interrupts produced by the timer chip used by the
> RTC? or vice versa etc. ?


No, they are completely independent.

Arno
--
For email address: lastname AT tik DOT ee DOT ethz DOT ch
GnuPG: ID:1E25338F FP:0C30 5782 9D93 F785 E79C 0296 797F 6B50 1E25 338F
"The more corrupt the state, the more numerous the laws" - Tacitus


 
Reply With Quote
 
Harza
Guest
Posts: n/a
 
      08-25-2003, 08:00 PM
Thanks for all the info Arno.

Final question (I hope):

On start-up the software clock gets its time from the RTC and sets
itself to within 1 second of the RTC.

How is this achieved if there is no relationship between the RTC and
the timer chip?


Arno Wagner <> wrote in message news:<bico9p$7v6hq$>...
> Previously Harza <> wrote:
> > "the crystal is hardwired at 1.19318MHz"

>
> > So there is a crystal in the timer chip? This would mean that both the
> > hardware clock (RTC) and the software clock (timer chip) have crystal
> > oscillators?

>
> Yes, they do.
>
> > I thought oscillators were typically designed to run at 32768 Hz
> > (2^15)?

>
> Only those for one-second resolution low-power clocks. The RTC
> might have one of these. The timer has not.
>
> > Can you tell me the relationship between the RTC and the timer chip?

>
> None. Except that they are in the same computer.
>
> > Are the hardware interrupts produced by the timer chip used by the
> > RTC? or vice versa etc. ?

>
> No, they are completely independent.
>
> Arno

 
Reply With Quote
 
Arno Wagner
Guest
Posts: n/a
 
      08-26-2003, 12:42 AM
Previously Harza <> wrote:
> Thanks for all the info Arno.


> Final question (I hope):


No problem...

> On start-up the software clock gets its time from the RTC and sets
> itself to within 1 second of the RTC.


Actually more likelt to within 10ms, at least on Linux.

> How is this achieved if there is no relationship between the RTC and
> the timer chip?


It is done by software. After all the RTC is a real clock with
calendar, but the timer is just a frequency synthesizer. All the
clock-logic (60sec = 1 min, etc.) is in the software part of the
software clock. The software clock is a thing created by the OS
with the help of a hardware timer. If the OS does not support
it, there is no software clock. That is also why there is no
hardware connection between the RTC and the timer: The timer
is not the software clock, it just provides its heartbeat,
which it has no problem doing just by itself without help from
the RTC.

On the philosophical side: Since the software clock lives only in
software it is actually not possible to have a hardware connection
between it and the RTC...

Maybe some more background: The RTC is a low-power chip and still runs
when the PC is off (there is a battery on the mainboard). It also
stores the BIOS setup parameters, since it has battery backed RAM in
addition to its clock registers. That it remains active is also the
main reason it uses a 32768Hz crystal: Lower frequencies lead to
significantly lower power consumption. Since the RTC should run 5-10
years without external power, its power consumprion is the most
critical design consideration. The RTC also has an ancient 4-bit
interface which is pretty slow to program and read from. Since it only
provides 1 second resolution, that is not really a problem. But the
software clock needs more resolution, since it also drives the process
scheduling in multitasking systems. The timer chip has a "full" 8 bit
interface which is "fast". But there is no need to read from
the timer, once it is set. After all it will provide an interrupt
every 10ms and executing the interrupt service routine is all that
is needed. No reading from/writing to the timer involved in updates
to the software clock.

Arno

> Arno Wagner <> wrote in message news:<bico9p$7v6hq$>...
>> Previously Harza <> wrote:
>> > "the crystal is hardwired at 1.19318MHz"

>>
>> > So there is a crystal in the timer chip? This would mean that both the
>> > hardware clock (RTC) and the software clock (timer chip) have crystal
>> > oscillators?

>>
>> Yes, they do.
>>
>> > I thought oscillators were typically designed to run at 32768 Hz
>> > (2^15)?

>>
>> Only those for one-second resolution low-power clocks. The RTC
>> might have one of these. The timer has not.
>>
>> > Can you tell me the relationship between the RTC and the timer chip?

>>
>> None. Except that they are in the same computer.
>>
>> > Are the hardware interrupts produced by the timer chip used by the
>> > RTC? or vice versa etc. ?

>>
>> No, they are completely independent.
>>
>> Arno


--
For email address: lastname AT tik DOT ee DOT ethz DOT ch
GnuPG: ID:1E25338F FP:0C30 5782 9D93 F785 E79C 0296 797F 6B50 1E25 338F
"The more corrupt the state, the more numerous the laws" - Tacitus


 
Reply With Quote
 
Harza
Guest
Posts: n/a
 
      09-02-2003, 10:05 AM
>> Does WinNT/2000/XP uses 100 Hz also?

>I honestly don't know. I don't use these systems.


>> I think MS-DOS/Win95/98 use 18.2Hz.


>Yes, it does.


>> Is this related to the timer chip running at 1.19318 MHZ and using
>> 65536 to divide it down --> 1.19318 MHz/65536 = 18.2 Hz?


>Exactly.


>> If so then what divisor does WinNT/2000/XP and Linux etc. use?


>Should be 11932. Gives you 99.99832...Hz, which is a 168ppm error
>and is in the range of the error the crystal oscillator has anyway.
>It is about 1.5 sec/day.


65536 = 2^15

but 11932 is not divisible by 2, so why/how is this number used?
 
Reply With Quote
 
Harza
Guest
Posts: n/a
 
      09-02-2003, 10:29 AM
> Maybe some more background: The RTC is a low-power chip and still runs
> when the PC is off (there is a battery on the mainboard). It also
> stores the BIOS setup parameters, since it has battery backed RAM in
> addition to its clock registers. That it remains active is also the
> main reason it uses a 32768Hz crystal: Lower frequencies lead to
> significantly lower power consumption.


Does the RTC use the 32768Hz frequency or divide it by 32
to use a 1024Hz (2^10) frequency?

TIA
 
Reply With Quote
 
Arno Wagner
Guest
Posts: n/a
 
      09-02-2003, 03:05 PM
Previously Harza <> wrote:
>> Maybe some more background: The RTC is a low-power chip and still runs
>> when the PC is off (there is a battery on the mainboard). It also
>> stores the BIOS setup parameters, since it has battery backed RAM in
>> addition to its clock registers. That it remains active is also the
>> main reason it uses a 32768Hz crystal: Lower frequencies lead to
>> significantly lower power consumption.


> Does the RTC use the 32768Hz frequency or divide it by 32
> to use a 1024Hz (2^10) frequency?


The RTC has its own 32768Hz crystal. The frequency ist then
divided by 32768 to get 1Hz for the "second"- pulse.

Of course dividing it by 32 is an intermediate step.

Arno
--
For email address: lastname AT tik DOT ee DOT ethz DOT ch
GnuPG: ID:1E25338F FP:0C30 5782 9D93 F785 E79C 0296 797F 6B50 1E25 338F
"The more corrupt the state, the more numerous the laws" - Tacitus


 
Reply With Quote
 
Arno Wagner
Guest
Posts: n/a
 
      09-02-2003, 03:15 PM
Previously Harza <> wrote:
>>> Does WinNT/2000/XP uses 100 Hz also?


>>I honestly don't know. I don't use these systems.


>>> I think MS-DOS/Win95/98 use 18.2Hz.


>>Yes, it does.


>>> Is this related to the timer chip running at 1.19318 MHZ and using
>>> 65536 to divide it down --> 1.19318 MHz/65536 = 18.2 Hz?


>>Exactly.


>>> If so then what divisor does WinNT/2000/XP and Linux etc. use?


>>Should be 11932. Gives you 99.99832...Hz, which is a 168ppm error
>>and is in the range of the error the crystal oscillator has anyway.
>>It is about 1.5 sec/day.


> 65536 = 2^15

No, 65536 = 2^16

> but 11932 is not divisible by 2, so why/how is this number used?


It is dividible by 2. But that does not matter. Crystals are analog
components that always have tolerances. So they do not need to match
exactly, but only approxiately. Today you would possibly use
a 1.000MHz crystal to get 'exact' 100Hz. (Division by 10 is
possible in digital electronics and fairly standard.) Still
it would not be that more exact, because cheap crystals have
100ppm tolerance anyway.

As to why thea ecact frequency was chosen: When the timer circuit
configuration was designed computers where in their infancy. My guess
is that 1.19318 MHz crystals where available cheaply because they
where used in some other application, e.g. as filters in radios or as
components from TV sets. Crystal manufacture is a fairly standard
process, yet they need to be adjusted individually. That means
they are expensive unless produced in huge numbers. Since IBM
designed the PC for 10.000 unites only (I think), special crystals
would have been a cost factor.

Arno



--
For email address: lastname AT tik DOT ee DOT ethz DOT ch
GnuPG: ID:1E25338F FP:0C30 5782 9D93 F785 E79C 0296 797F 6B50 1E25 338F
"The more corrupt the state, the more numerous the laws" - Tacitus


 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Software real time clock using timer unit Paul Keinanen Embedded 4 11-11-2009 05:03 PM
Re: Software real time clock using timer unit Rich Webb Embedded 7 11-11-2009 04:58 PM
Re: Software real time clock using timer unit Arlet Embedded 0 11-08-2009 03:16 PM
Software Real-Time Clock on HC12 Christian Winter Embedded 5 03-03-2006 03:48 PM
Merits of software real time clock. Joseph Casey Embedded 6 01-21-2005 08:47 PM


All times are GMT. The time now is 12:48 AM.


Welcome!
Welcome to Motherboard Point
 

Advertisment
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47