473,748 Members | 2,551 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need to implement a calendar clock with millisecond resolution, please help.

Hi all,

I know it may sound like dump newbie question (which is very much
true, as I am a newbie, not even a real programmer), but I need to
implement a calendar time clock with a millisecond resolution. For
hours I've been digging the Visual C++ 6 help and Googling like a
madman. It seems to me that the standard C just don't have the tool to
get this type on information. Sure I found the time() and the clock()
but they don't really help me.

Is there any way I can get a real calendar time, say from a system?
Maybe I should look in the direction of some kind of Assemly language
routine inserted into the C (not that I like the option, last time I
touched Assembly was years ago, back at the university).

I'll appreciate any ideas you have.

/* I run VC6, on a PC powered by Win2000 */

Aug 26 '07 #1
5 2417
In article <11************ **********@k79g 2000hse.googleg roups.com>,
Hunter <Ig*********@gm ail.comwrote:
>Hi all,

I know it may sound like dump newbie question (which is very much
true, as I am a newbie, not even a real programmer), but I need to
implement a calendar time clock with a millisecond resolution. For
hours I've been digging the Visual C++ 6 help and Googling like a
madman. It seems to me that the standard C just don't have the tool to
get this type on information. Sure I found the time() and the clock()
but they don't really help me.
You are correct, standard C does not have such a mechanism.

You probably don't need to drop into assembler, though; check out
a Windows programming newsgroup to find out what you can do within
the Windows API (since assembler wouldn't be portable anyhow.)

By the way, after you get finished figuring out how to get
millisecond -resoluti0n-, you are going to have the even more
fun task of getting similar -precision-. On most systems, the
built-in real-time clocks drift, fairly noticably, so if you want
calendar time with millisecond resolution, you are going to need
to start thinking about how to keep that clock synchronized with
some sort of standard time signal.
--
Prototypes are supertypes of their clones. -- maplesoft
Aug 26 '07 #2
Oh... API... Whatever that means :(
As for precision, do you know how much it can "drift"?
I mean, what I need is to synchronize between to programs, each
acquiring it's data from a different source (And the data rate is
about 1kHz), and saving it into the file. The programs not necessarily
start at the same time, but they do run simultaneously most of the
time. So I thought of "time stamping" the data in files.
Thank you very much!

Aug 26 '07 #3
On Sun, 26 Aug 2007 03:07:23 -0700, Hunter wrote:
Oh... API... Whatever that means :(
As for precision, do you know how much it can "drift"?
Usually the rate of hardware clocks is not extremely accurate, it
can be slightly too fast or too slow, depending among other things
on temperature. Normally the differences are of about one part on
10**5 or less, but if you need to measure times to within one
microseconds it will make the least significant digits bogus.
I mean, what I need is to synchronize between to programs, each
acquiring it's data from a different source (And the data rate is
about 1kHz), and saving it into the file. The programs not necessarily
start at the same time, but they do run simultaneously most of the
time. So I thought of "time stamping" the data in files.
Well, so you just need high precision and resolution, even if
accuracy is not perfect.

--
Army1987 (Replace "NOSPAM" with "email")
No-one ever won a game by resigning. -- S. Tartakower

Aug 26 '07 #4
Such a drift strikes me as a bit odd. I meen the sysem clock runs at
hundreds of MHz, and probably has plenty of PLLs and dividors to form
all the derivative clocks.

Anyway thanks a lot!

Aug 26 '07 #5
On Sun, 26 Aug 2007 03:07:23 -0700, Hunter <Ig*********@gm ail.com>
wrote:
Oh... API... Whatever that means :(
http://en.wikipedia.org/wiki/API and in this case particularly
http://en.wikipedia.org/wiki/Windows_API
As for precision, do you know how much it can "drift"?
s/precision/accuracy/; see PP (previous post)
I mean, what I need is to synchronize between to programs, each
acquiring it's data from a different source (And the data rate is
about 1kHz), and saving it into the file. The programs not necessarily
start at the same time, but they do run simultaneously most of the
time. So I thought of "time stamping" the data in files.
Programs on the same machine, or different machines?

On the same machine, if that machine can be a multiprocessor -- and
any machine you bought recently in the consumer market likely was --
make sure you use a call which gets time from a 'global' or 'shared'
clock, not a per-CPU counter, since those may not be or stay in sync.
I'm confident Windows does provide such a capability, but I'm not sure
if (or when) it's the default, and if not how you get it, and since
it's implementation-specific (to Windows) it's offtopic here.
comp.programmer .ms-windows.win32 is rumored to be good.

On different machines, if you want to keep clocks in sync to the
millisecond level, you need something specialized for the purpose.
There may be some Windows-specific capability, though I haven't heard
of one; the win32 group would probably know. There is an Internet
standard (in both the de-jure and de-facto sense) for this called NTP
(Network Time Protocol), but last I looked they weren't getting very
good precision on Windows. You could try comp.protocols. time.ntp ,
and in particular www.meinberg.de reportedly supports (free) a build
and configuration for Windows from the generic/portable NTP source.
(The company's business is selling precision clock _hardware_, and
they provide this support for NTP free presumably in the hope that
lots more NTP users = somewhat more clock buyers.)

- formerly david.thompson1 || achar(64) || worldnet.att.ne t
Sep 9 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
14880
by: cg_news | last post by:
In short, what I am trying to do is, based on a date, calculate the week of year (as described in ISO 8601), then calculate the first and last date in this week period and return them in the format CCYYMMDD. Sounds easy enough, right?? I am attempting to accomplish this by creating a GregorianCalender which will get me the week of year. Then by changing the day of week to 1 (start of week) i'm trying the get the first day of the week,...
8
6200
by: Victor | last post by:
I need a JavaScript timer - I have five events I need to time, that can be triggered by a mouseclick event, or a keypress event. Each event is separated by only one to two seconds. The first event (mouse or key) starts the timer. Then, each time the event (mouse or key) occurs, I need to display the present time in the corresponding spot on the screen (so when it's over, the screen is displaying five times for each corresponding event)....
11
47113
by: Yeounkun, Oh | last post by:
Hello. Sleep (x) function make a process sleep during x seconds. but, how to sleep during milliseconds... Pls. help me. Thank you. Regards.
12
2932
by: jUrner | last post by:
Hello all I have the problem of how to calculate the resolution of the system clock. Its now two days of head sratching and still there is nothing more than these few lines on my huge white sheet of paper stiring at me. Lame I know. import time
30
17314
by: Matt | last post by:
Does clock_t clock() measure real time or process time? Unless I have missed something, Stroustrup's treatment in TC++PL (section D.4.4.1) is none too clear on that question. Is clock() well-implemented for the major compilers g++, VC++, and Macintosh compilers and other C++ compilers on Linux/Unix, Windows, and MacOS?
1
1979
by: 848lu | last post by:
hey i really need help...i got this code....basically im suppose to make a calender that allows a user to type in month and year .... and the calander displays it on the scree using "GregorianCalendar"....and finally the users shold be able to select a date and store information... please feel free to edit the code and play around with it...if you do please commen them out so i understand it... peace... P.S. IT CANT BE ON APLET ...
19
40818
by: UG | last post by:
I just wanted to know whether any timer facility exists in C, as it is not mentioned in K&R 2, or in the ISO Draft. By timer function i mean that when we use standard input function like scanf() or getch() or any other function, the interface stops to take input from user but what if user doesn't give input for hours, the program will still be waiting. Is there any way to circumvent the scanf() (or any other input function for that matter)...
5
6936
by: none | last post by:
Hello, can you help? if I include: #include <time.h> and run the code: clock_t t = clock(); cout << "t is " << t << endl; I get (seemingly randomly) "t is 0" or "t is 10000"
9
8299
by: Ron Adam | last post by:
I'm having some cross platform issues with timing loops. It seems time.time is better for some computers/platforms and time.clock others, but it's not always clear which, so I came up with the following to try to determine which. import time # Determine if time.time is better than time.clock # The one with better resolution should be lower.
0
9555
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9329
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9250
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6076
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4878
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2787
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.