News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

RTC

Started by mircoo, November 29, 2005, 01:48:54 PM

Previous topic - Next topic

mircoo

Is possible, set Real Time Clock in resolution of miliseconds?

MichaelW

For a PC the normal RTC interrupt period is 1/1024 second. This period appears to be the result of (effectively) dividing 32000 by the 32768Hz input frequency. The available periods, as listed in Frank van Gilluwe's The Undocumented PC, are related to the normal period by powers of two, so I think you cannot come any closer to a 1/1000 period.

I assume you are aware that the RTC is not accessible from a Windows program and that under Windows 2000 and XP, the RTC and the related BIOS functions are not accessible even from a DOS program.


eschew obfuscation

P1

mircoo,

Welcome to MASMforum!        :U

Read around the different areas and get a feel for the place.          :dance:

Read the help files and tutorials of MASM32.   It's best, if you download the most recent MASM32 package and install it. 

'Search' & Google are your friends for programming.  Then ask your questions.     

Sometimes the answer is in what your trying to do and than in a certain technique.  So, what are you trying to do ?  That is more to timing that a RTC.  Use Search and check the board for timers.

Regards,  P1   

Tedd

The RTC interrupt is generated once every second - to indicate the time has changed.

You could use the PIT to get a millisecond timer (though access will be limited/non-existent under windows). Unless all you want to do is mess up the system clock ::)

Alternatively, under windows you can try playing with a multi-media timer - which is more accurate than using SetTimer.
Or you can try QueryPerfomanceCounter.
No snowflake in an avalanche feels responsible.

MichaelW

Quote from: Tedd on November 29, 2005, 06:47:54 PM
The RTC interrupt is generated once every second - to indicate the time has changed.

I don't know what Windows does with the RTC, but the BIOS normally programs the RTC to generate periodic interrupts (IRQ8, Interrupt 70h) at a rate of 1024 interrupts per second, when the periodic interrupt is enabled, which it normally is not. This is why the actual wait intervals for the BIOS Event Wait and Wait functions (Interrupt 15h, functions 83h and 86h), which utilize the RTC periodic interrupt, are multiples of 1/1024 second.

eschew obfuscation

mircoo

I'm not on Windows, i use Pharlap OS, so I cannot use Dos interrupts  :'( I can only writing to i/o ports directly. It is possible to set only seconds in CMOS memory.

Gustav

> I assume you are aware that under Windows 2000 and XP,
> the RTC and the related BIOS functions are not accessible even from a DOS program.

the BIOS interrupt 15h, ah=8xh doesn't work in a XP DOS box, but accessing the RTC directly - and installing an INT 70h IRQ handler - surprisingly did work!

MichaelW

mircoo,

Yes, you can set just the seconds. Assuming you can call BIOS interrupts you could set the seconds, without changing the minutes or hours, by calling the Get RTC Time function (Interrupt 1Ah, function 2), loading the new seconds value into DH, and then calling the Set RTC Time function (Interrupt 1Ah, function 3). Or you could change the seconds by writing the seconds register (CMOS register 0), but for reliability you should temporarily halt the clock by setting bit 7 of Status Register B (CMOS register 0Bh).

Gustav,

Thanks for the information. I assumed without testing that the BIOS function not working indicated that you could not do it directly.

eschew obfuscation

mircoo

I cannot call Bios interrupts too :'( You tell me about 2 methods to set RTC clock - Bios interrupt or write to CMOS. For example, by writing to CMOS address 0, I set seconds. I can replace this, by calling Bios interrupt 1ah.
With theese methods, can i set only seconds. There are also interrupt - SET SYSTEM TIME (interrupt 1ah function 01h) With this can I set number of clock ticks since midnight. And my question is, if it is possible to set theese ticks, without using bios interrupt. Thanx

Tedd

Quote from: MichaelW on November 29, 2005, 08:03:33 PM
Quote from: Tedd on November 29, 2005, 06:47:54 PM
The RTC interrupt is generated once every second - to indicate the time has changed.

I don't know what Windows does with the RTC, but the BIOS normally programs the RTC to generate periodic interrupts (IRQ8, Interrupt 70h) at a rate of 1024 interrupts per second, when the periodic interrupt is enabled, which it normally is not. This is why the actual wait intervals for the BIOS Event Wait and Wait functions (Interrupt 15h, functions 83h and 86h), which utilize the RTC periodic interrupt, are multiples of 1/1024 second.

These are two 'different' interrupt signals, though they're both indicated by IRQ8 (you have to check the rtc status register to find out which it was.)
The periodic signal can be set to be generated every 1/1024 seconds, while the time-of-day-has-changed singal will be generated once every second. (I don't think windows does anything different with either of them.)
No snowflake in an avalanche feels responsible.

Tedd

Quote from: mircoo on November 30, 2005, 01:39:21 PM
I cannot call Bios interrupts too :'( You tell me about 2 methods to set RTC clock - Bios interrupt or write to CMOS. For example, by writing to CMOS address 0, I set seconds. I can replace this, by calling Bios interrupt 1ah.
With theese methods, can i set only seconds. There are also interrupt - SET SYSTEM TIME (interrupt 1ah function 01h) With this can I set number of clock ticks since midnight. And my question is, if it is possible to set theese ticks, without using bios interrupt. Thanx

That function counts 'ticks' in 1/18.2 seconds. Which doesn't use the rtc interrupt at all, it's a PIT timer (which is set to 18.2Hz as default by BIOS.)
If you want to get milliseconds-since-midnight, then you'll have to calculate it yourself from the cmos-seconds-since-midnight * 1000.
Seconds is available from register 0, minutes from reg 2, and hours from reg 4 (note: the values are in BCD, not plain binary.)
No snowflake in an avalanche feels responsible.

PBrennick

I thought Pharlap is a DOS Extender??

Paul
The GeneSys Project is available from:
The Repository or My crappy website

MichaelW

#12
Tedd,

There are actually three events that can trigger an IRQ8, the periodic interrupt, the alarm interrupt, and the update complete interrupt. I was assuming that mircoo was interested in the periodic interrupt, because the others can do no better than a resolution of one second. I cannot recall ever testing a system where any of these interrupt events were, by default, enabled. Frank van Gilluwe's book The Undocumented PC, First Edition, Addison-Wesley, 1994, ISBN 0-201-62277-7, clearly lists all three of these as being disabled by default. The attachment contains a DOS app that monitors Interrupt 70h while it enables, in turn, all three of the possible interrupt events, and the handler displays an indicator of which event triggered the interrupt. Running under Windows 2000 none of the three interrupt events are initially enabled and everything works as expected. Running off a Windows 98 startup disk on my backup system none of the three interrupt events are initially enabled, the update complete interrupt event is enabled whenever either of the other interrupt events is enabled, and status register C never reports an alarm interrupt.

mircoo,

The attachment shows how to control the RTC without using BIOS interrupts, by writing directly to the CMOS registers.

The BIOS maintains a 32-bit count of the system timer (PIT channel 0) ticks since midnight in low memory at address 40h:6Ch. You should be able to read the value without problems, assuming you read it in a single instruction or disable hardware interrupts while you are reading it. You could probably safely modify the value, assuming you write it in a single instruction or disable hardware interrupts while you are writing it.

Like Paul, I associate the name Pharlap with a DOS Extender. At least in the early days DOS Extenders would allow you to access real-mode interrupts just as you would from a real-mode program.

EDIT: Corrected a problem with the commented code in the IRQ8 handler.


[attachment deleted by admin]
eschew obfuscation

Tedd

Quote from: MichaelW on December 01, 2005, 10:46:03 AM
There are actually three events that can trigger an IRQ8, the periodic interrupt, the alarm interrupt, and the update complete interrupt.
Yes. But we weren't talking about the alarm signal. I was just pointing out that we were both talking about different signals - to avoid any confusions.

Quote
I cannot recall ever testing a system where any of these interrupt events were, by default, enabled.
No-one said they were enabled by default.
No snowflake in an avalanche feels responsible.

MichaelW

Quote from: Tedd on December 01, 2005, 12:16:41 PM
No-one said they were enabled by default.

No, but in this statement:

QuoteThe RTC interrupt is generated once every second - to indicate the time has changed.

You implied that the update complete interrupt is enabled. I'm just trying to provide accurate answers.

eschew obfuscation