Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / March 2005

Tip: Looking for answers? Try searching our database.

High Resolution Callback Timer (microseconds)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Michael Evans - 09 Mar 2005 19:39 GMT
Anyone,

I'm looking for a way to setup a callback function in our VC++ .ne
2003 7.1 console application using a higher resolution timer.  Th
multimedia timer is too low resolution at 1 millisecond.  We nee
microsecond resolution to guarantee an exact update rate (60 or 70 H
for example.)

We use the Performance Counter to get microsecond resolution whe
measuring elapsed time, but there doesn't appear to be any tools fo
generating callbacks or interrupts, etc. at that higher resolution.

Any ideas would be greatly appreciated.   Thanks,

Mik


Carl Daniel [VC++ MVP] - 09 Mar 2005 20:10 GMT
> Anyone,
>
[quoted text clipped - 9 lines]
>
> Any ideas would be greatly appreciated.   Thanks,

You need to use an operating system other than Windows if you need
microsecond precision in timing - Windows was simply not designed to do
that.

Your only recourses under Windows are probably:

1. Use a multimedia timer to get close, and then poll at high frequency
until the desired event time.

2. Build (or find) a custom hardware device that generates interrupts at the
desired rate, then write a kernel device driver to service that interrupt.
The video display (if that's what you're updating) could be the source of
that interrupt stream.

If it is a display device that you need to interact with at precise times
(e.g. once per vertical blank), then Direct Draw provides frame
synchronization (which it implements using technique #1 above).

Even with the above techniques you have absolutely no guarantee that your
event will occur with any predictable latency/jitter.

-cd
Tom Widmer - 10 Mar 2005 11:47 GMT
> Anyone,
>
[quoted text clipped - 9 lines]
>
> Any ideas would be greatly appreciated.   Thanks,

This isn't generally possible even with realtime operating systems.
Typically, OSes service timers at a particular resolution, such as every
1 ms, or whatever. If a timer callback or event is supposed to fire at
microsecond 123456, it will actually fire at the first kernel tick after
that time, say at microsecond 124000 (+ any kernel and scheduling latency).

The two approaches Carl mentioned are the two feasible ones. A realtime
operating system will give you almost perfect timings every time using
either (as long as priorities are set appropriately), while Windows will
give you, on average, reasonable timings (as long as priorities are set
appropriately), but with no guarantees. Remember to boost the priority
of the timing process and thread as high as possible, at least during
the critical regions (e.g. during the polling stage using technique 1).

If you are just updating a display, if you use DirectX, you shouldn't
need any timers better than 1ms accuracy. What exactly are you doing?

Tom

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.