Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Time Clock and memory problems

Status
Not open for further replies.

tedsmith

Programmer
Nov 23, 2000
1,762
AU
Hi from an Aussie programmer (yes I've had my operation so I can wear thongs)
My program makes the windows local time clock lose seconds over a few hours. It seems to happen when the available physical memory reaches zero and swap file comes into use and the (Compaq-ughh) computer momentarily freezes. It seems to be worse when data is coming in from another computer via the MScomms control while playing wave files at the same time.
The master crystal clock is not affected because the time comes back to normal if I simply reboot the computer!
I use GetLocalTime() but the system time loses thew same am ount of time as well.
Can anyone tell me how to relock the system timer to the Master crystal clock on the motherboard without shutting down the computer?
Also how do I reset all the unused available physical memory like you can if you load and immediately unload IE5?
Ted
 
This is a puzzle. At the very lowest level, whenever an MS product (or an app created with an MS product) sets the BIOS time it also sets the CMOS time. There is a low-level interrupt designed to adjust the CMOS time without affecting the BIOS but I wasn't aware of one that would perform the opposite.

You might try using the GetSystemTime API at the beginning of your app and calculate the number of hours difference between UTC time and local time with the Time function, then use GetSystemTime again before you unload your app and adjust the local time with the Time statement using the UTC time plus-or-minus the "hour" difference you calculated earlier.

Whew... haven't tried it but it might work for you.
VCA.gif

Alt255@Vorpalcom.Intranets.com
 
Thanks for your comments Alt255 but unfortunately the System Time is the one that is loosing seconds and is not the same as the real time clock, as explained in the Microsoft blurb on GetSystemTime. The local time automatically follows this.
Also to make it more complicated, it depends on the RAM activity particularly in relation to when the available physical memory reaches zero and the swap file comes into play to release memory (as easily seen using the SYSTEM MONITOR). With no applications running the time seems OK.
What I need to do is periodically use the same routine that initially locks the system time to the original quartz crystal reference that stores the time when I have the computer off.
I since found, on the web,a great free program called Ramboost that continually shuffles memory so you always have a good reserve of RAM and prevents that annoying temporary freeze. My 64mb with Ramboost works better that my friends 128mb without it.
Thanks Ted
 
There were a number of utilities a few years ago which would do a call to some 'accurate' source, calculate the delay between the source and the system which was calling, retrieve the time (from the 'accurate' source, add the delay to the time and (finally) reseet the system time.

These, of course, used a public bulletin board approach, which is not very suitable in today's web environment, however if you have a local network with a machine you could trust to keep the 'right' time, You could (probably) retrieve it's system time and use that to reset your clock. For a local machine, it would be safe to ignore the transmission delay?

I have generally gotten system administrators to 'set' user/desktop system clocks to be synchronized with the network (master) server on start-up, and have not really noticed a problem over single 'Sessions' (days), but it is easy to understand that systems left running over longer periods could have a significant difference in the clock times. If the system admin can provide a utility which forces synchronization perhaps you could just invoke that process/utility whenever you need.



MichaelRed
mred@duvallgroup.com
There is never time to do it right but there is always time to do it over
 
Thanks MichaelRed but my problem is purely working with a stand alone desktop computer. The real time clock (the xtal clock ticking away somewhere inside my computer when it is off) keeps time OK - BUT it is the displayed time that gets out of step with this real time clock.
When memory is low you can even see the system time pause briefly as it is counting and it remains out of step (a few seconds slow) until the computer is restarted and it comes back in time again!
It only is a problem with continuous operation in applications such as my current problem (a public information kiosk).
As most people don't leave their computers on continuously they never notice it! It comes back OK each time you restart.
I am hoping someone out there knows the answer on how to re-sync the Windows system time clock to the real time clock in the computer without rebooting.(NB. GetSystemTime etc. doesnt do it and SetSystemTime does it the other way around)
Ted
 
I can't find an API designed to retrieve the RTC time (that doesn't mean that one doesn't exist, I just don't know how to do it). You could create a "work-around" with a low-level DOS app that retrieves the CMOS time and sets the BIOS time accordingly (you would lose a certain amount of precision, since time is tracked at one-second intervals in the RTC). See thread272-9689 for a discussion of the applicable interrupts.

This is really outside the scope of the Win32API forum but it might be a decent solution... in a pinch.

Good luck.
VCA.gif

Alt255@Vorpalcom.Intranets.com
 
Thanks Alt255. When I try to open Thread272-9689 I just get a blank screen, When I refresh I get a message to say "cant open etc"
 
I'm glad you found a solution, Ted. I think I'll take a look at that link.

Strange you couldn't open thread272-9689. You should have gone there as soon as you clicked on the link.
VCA.gif

Alt255@Vorpalcom.Intranets.com
 
Im still having problems finding out how to set the system time to the cmos clock without rebooting the computer, Any ideas?
 
I'm very sorry Ted, I know you want to hear from somebody who can give you an API solution, but the more I look the more I am convinced that the the API doesn't provide that sort of low-level, hardware functionality. I really hope that somebody proves me wrong because I would love to throw that function into my tool box.

Here is a solution. You might use it when you reach wits-end. It is written in Quick Basic (you shouldn't have a problem finding a QB compiler. If you can't find one, I'll compile it into an EXE and email it to you).

This just retrieves the time from the real-time clock chip and then sets the system time accordingly. You would call it from your app with the Shell function:
[tt]
DEFINT A-Z
TYPE RegTypeX
AX AS INTEGER
BX AS INTEGER
CX AS INTEGER
DX AS INTEGER
BP AS INTEGER
SI AS INTEGER
DI AS INTEGER
Flags AS INTEGER
DS AS INTEGER
ES AS INTEGER
END TYPE
DIM InRegs AS RegTypeX, Outregs AS RegTypeX
InRegs.AX = &H200
CALL Interruptx(&H1A, InRegs, Outregs) 'get CMOS time

Mhr$ = HEX$(Outregs.CX)
FOR Re = 1 TO 4
IF LEN(Mhr$) < 4 THEN
Mhr$ = &quot;0&quot; + Mhr$
ELSE
EXIT FOR
END IF
NEXT
Sec$ = HEX$(Outregs.DX)
FOR Re = 1 TO 4
IF LEN(Sec$) < 4 THEN
Sec$ = &quot;0&quot; + Sec$
ELSE
EXIT FOR
END IF
NEXT

Hr$ = LEFT$(Mhr$, 2)
Mn$ = RIGHT$(Mhr$, 2)
Sc$ = LEFT$(Sec$, 2)
Dls$ = RIGHT$(Sec$, 2)
CmosT$ = Hr$ + &quot;:&quot; + Mn$ + &quot;:&quot; + Sc$
CmT$ = LEFT$(CmosT$, 8)
TIME$ = CmT$ 'set system time to CMOS time
[/tt]

Definately not an API soltion but it is written in Basic and it works quite well.
VCA.gif

Alt255@Vorpalcom.Intranets.com
 
Thanks Alt255. I had forgotten about quickbasic - I think I got it on some old 5 1/4 floppies from the last century.
Pity VB doesnt have interrupt functions - or does it?
Regards Ted
 
You can't use the DOS interrupts in 32bit VB... believe me, I've tried to find a way. The closest you can come to full low-level support is with ftp://ftp.softcircuits.com/tools/vbasm.zip but it will only work with a 16bit version of VB). I asked the fine folks at Softcircuits if they planned to release a 32bit version and the answer was a very firm &quot;No&quot;. 'Tis a Pity.
VCA.gif

Alt255@Vorpalcom.Intranets.com
 
Thanks Alt255,
I tried your qbasic routine in Quickbasic4.5 but there is an error in the line &quot;CALL Interruptx(&H1A, InRegs, Outregs)&quot; because the subroutine was not declared. Is there some sort of declaration section and a library to match that I should have as well?
My old copy of QBasic is faulty but it would be no good anyway because I can't complile an EXE with QBasic.
If that interrupt call is universal for CMOS time, I should be able to access it in C++ and make a little activeX control to do the job. I'll let you know if it works.
On a different subject, do you know how to erase all the previous items in the Yahoo (or any other search engine)combo drop down box list. I have so many it is clogging up my search words entry as it sorts them into alphabetical order. I have tried erasing all the history files and folders I can see to no avail. No one else I have contacted seems to know!
Thanks for all your trouble - Ted
 
Ah... sorry about that. In order to use the DOS interrupts in QB45 you need to load the standard QB library. Use the command line: [tt]QB.EXE /ah /l qb.qlb[/tt].

Naturally, that will only work with QB45 or QB7. If you can call the interrupts with C++, that would be the way to go. There wouldn't be a need to shell to a DOS app.

I'm not sure about the solution to your other problem but if you are using Internet Explorer you can remove items from the URL history by editing the data in the [tt]HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\TypedURLs[/tt] registry key. You could do it with regedit but it might be funner to accomplish the task with a VB app.

Anyway, we are getting off topic here. You would do well to create a new thread with your second question.
VCA.gif

Alt255@Vorpalcom.Intranets.com
 
Thanks Alt255
Now I can view the CMOS time! Problem now is that if I set the Windows System time to the CMOS Time as found by the routine, it also re-sets the CMOS time to the same value. Because I can only get time resolution to 1 second, if the time was really +.5 second, it would put the CMOS time wrong. The error would quickly accumulate.
What I now need is a routine that ONLY sets the System time without affecting the CMOS time which is otherwise very accurate!
I hope I dont set the record for the longest thread!
Silly me, I found that you can delete lookup list entries by selecting the unwanted one and pressing the delete key!
Regards Ted
 
Hi, Ted. The one-second granularity could pose a problem but, if you think about it, it would probably introduce less error than the problem you are facing now. A quick fix would suggest that you add one second to the system time every time you called the routine. Since the value returned by the RTC represents a truncated interval you would only stand to lose the fractional precision within any given second.

I don't think this method could introduce errors by resetting the CMOS time: get the CMOS time, set the BIOS time and a millisecond later set the CMOS time to the CMOS time. A bit awkward... but I don't know a way to set the BIOS time without setting the CMOS time also.

I'm glad you are making progress. Still, I wish there was a way to do this using nothing but VB and the API. I'm still hopeful that one of the Tek-Tips pros will step forward and unveil the deus ex machina.
VCA.gif

Alt255@Vorpalcom.Intranets.com
 
Thanks Alt255. Now that I can monitor the difference between the CMOS and Windows time, it is interesting to note that the time stays in sync for about 2 hours after rebooting, then goes out slowly. As the hours pass the rate of loss of time increases to the point where, after 10 hours, it is loosing almost a second every ten minutes . The computer is also sluggish with all applications and it seems it is in the period where it is hesitating, that the time gets lost.
It doesnt do this with just the desk top showing for 24 hours. The only thing I can see changing is the available physical memory which flys up and down with my application because I have a lot of wav files (it is an audio enquiry kiosk). Resources are still 90%.
I was using the sndPlay set of APIs for playing the wav files as they are very fast response but the loss of memory was too much (I couldnt see a way of closing the first sound file if a second one played before the first finished so I used the (slower) MCI control.
I have comms data coming in from a proximity sensor and the problem is, if this triggers the oncomm while the sound is playing, the available physical memory never quite returns to the level it was before the sound started playing.
Have you any suggestions on how to use the sound APIs without getting memory leaks? (or perhaps how to restore a memory leak without rebooting)
Hope I'm not being a nusiance but my problems are a bit different to the usual it seems- Ted
 
I have been playing around with this problem for a while now. So far, the best solution I have found is to use a time synchronizing utility that accesses certiffied accurate time from US government sources.
My problem was the same as many of you. My PC tells bad time but because of certain tasks etc. it was losing even more time than usual. So, I decided to give up on trying to get my PC to get back to telling lousy time and get it to be as close to precise as you can get.
The great thing about using this has been that I can set it to sync my CMOS time and Windows time as many times a day as I want. This works for me as I have an &quot;always on&quot; connection to the Internet
I understand that if you are a using dial-up modem, it is a little more clumsy.
Anyway, here is the site for more info. Try it and report back. Oh, by the way, it is free.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top