for(int count = 0; count < 1000; count++) {
Sleep(1);
}
The above code takes around 10 seconds in windows 2000 and more than 6
seconds in Windows 9X....
So i decided to use some other mechanism.... I wrote a device driver which
exposes a call to KeStallExecutionProcessor() (inside a for loop) and now
using that for a delay resolution of 1 milli seconds... Is there anyother
API which provides resolution in terms of 1 millisecond...
Any comments will be helpful....
Thanks in Advance...
Regards,
Vijay
Hope they help.
Happy programming!
Marco
"Vijay Anand" <vi...@qmaxtest.com> wrote in message
news:enXGOpBSCHA.3936@tkmsftngp12...
Regards,
Vijay
"puzzino" <marc...@eri.ericsson.se> wrote in message
news:ajsu9t$1bv$1...@newstoo.ericsson.se...
Try a few debug GetTick and see the granularity. If I
remember right I never got better than 30msec granularity.
Erik
>.
>
You should get 10ms on most platforms.
--
-Gary Chanson (MVP for Windows SDK)
-Software Consultant (Embedded systems and Real Time Controls)
-gcha...@mvps.org
-Abolish public schools
Have you tried Multimedia Timers :
Multimedia timer services allow applications to schedule timer events with
the greatest resolution (or accuracy) possible for the hardware platform.
These multimedia timer services allow you to schedule timer events at a
higher resolution than other timer services.
These timer services are useful for applications that demand high-resolution
timing. For example, a MIDI sequencer requires a high-resolution timer
because it must maintain the pace of MIDI events within a resolution of 1
millisecond.
Applications that do not use high-resolution timing should use the SetTimer
function instead of multimedia timer services. The timer services provided
by SetTimer post WM_TIMER messages to a message queue, while the multimedia
timer services call a callback function. Applications that want a waitable
timer should use the CreateWaitableTimer function.
ab
"Vijay Anand" <vi...@qmaxtest.com> a écrit dans le message de news:
enXGOpBSCHA.3936@tkmsftngp12...
Axel
void PASCAL SleepWakeupHandler( DWORD id, DWORD msg, DWORD EventHandle,
DWORD dw1, DWORD dw2)
{
SetEvent( (HANDLE)EventHandle );
UNREFERENCED_PARAMETER( msg );
UNREFERENCED_PARAMETER( dw1 );
UNREFERENCED_PARAMETER( dw2 );
UNREFERENCED_PARAMETER( id );
}
void MySleep( DWORD msTime )
{
HANDLE TimeIsUp = CreateEvent( NULL, TRUE, FALSE, NULL) ;
UINT TimerEvent;
static InitDone = false;
static TIMECAPS TimerCaps;
if( !InitDone )
{
timeGetDevCaps( &TimerCaps, sizeof( TimerCaps ) );
InitDone = true;
}
if( !msTime )
return;
timeBeginPeriod( TimerCaps.wPeriodMin );
TimerEvent = timeSetEvent( msTime, 0, (LPTIMECALLBACK)SleepWakeupHandler,
(DWORD)TimeIsUp, TIME_ONESHOT);
if( !TimerEvent )
{
// ran out of available timers, so just Sleep().
Sleep( msTime );
}
else
{
WaitForSingleObject( TimeIsUp, msTime );
timeKillEvent( TimerEvent );
}
timeEndPeriod( TimerCaps.wPeriodMin );
CloseHandle( TimeIsUp );
}
"Vijay Anand" <vi...@qmaxtest.com> wrote in message
news:enXGOpBSCHA.3936@tkmsftngp12...
Regards,
Vijay
"Arnaud Boussus" <abou...@graphnet.fr> wrote in message
news:ONHY5tQSCHA.4260@tkmsftngp09...
1 ms sounds like an awfully long settling time for hardware. Registers
usually settle out after a few microseconds, and that kind of stall can best
be done in the driver using KeStallExectionProcessor for no more than 50 us.
Trying to do this at the application level is in all practicaltiy
impossible.
--
Gary G. Little
gli...@broadstor.com
gli...@inland.net
"Gary G. Little" <gli...@broadstor.com> wrote in message
news:ak0le5$p44$1...@nntp2-cm.news.eni.net...
> 1 ms sounds like an awfully long settling time for hardware. Registers
> usually settle out after a few microseconds
>
How about upping the priority of your thread and spinning in a loop
until the time elapses?
Regards,
Vijay
"Gary Chanson" <gcha...@no.spam.TheWorld.com> wrote in message
news:ak1plj$r5v$6...@pcls4.std.com...>
Regards,
Vijay
"Fred Jackson" <fjackson_at_...@nowhere.com> wrote in message
news:e#UlCRVSCHA.1796@tkmsftngp13...
>Thanks Axel, Gary and Fred.
>Thanks for your valuable ideas...
>Yes i am talking about Hardware Relays and most of them need atleast a milli
>second to get settled.
>I have used KeStallExecutionProcessor in my device drivers for a few micro
>second delays...But now iam writing an user mode application. Looping around
>a DeviceIoControl to call that KeStallExecutionProcessor looks like a bad
>idea... Seems that i have to settle down with multimedia timers...
>Thanks again...
>
>
>Regards,
>Vijay
If memory serves, all you need to do is use the multimedia timers to
increase the resolution of the clock from ~10ms to 1ms (the max rate
NT has APIs for). Then, everything that depends on that timer becomes
more accurate, including the Sleep() calls, GetTickCount(), and the
accuracy of measuring the CPU usage.
(Again, it was quite a long time since I've done that work, so I might
remember wrong.)
HTH, Ziv.
Too long wouldn't normally hurt when actuating relays (it just
makes things run slower than optimum), but too short (zero in
the extreme case) would cause failure.
So, if I'm right, try an MM timer for 2 ms when you need 1 ms
minimum delay.
I've used MM timers in NT, and raised the priority class of my
process and/or the priority of the process' main and/or other
threads when I wanted really stable timing, and have been
fairly impressed by the results. You do have to be careful
when raising priority, because if you tie up the processor
continually for more than brief periods without yielding,
you can easily bring the whole system to its knees.
~~~~~
* E.g., I seem to recall the figure is 15 ms for dual
processor x86 NT systems; not sure if that has been changed
in 2K or XP.
"Vijay Anand" <vi...@qmaxtest.com> wrote in message
news:uvLkPAcSCHA.1640@tkmsftngp11...
Axel
"Fred Jackson" <fjackson_at_...@nowhere.com> wrote in message
news:eBUc$1fSCHA.2556@tkmsftngp09...
That's fine (and I agree) if you can do it, but you'll probably find it
hard to get the short interval you want.
Regards,
Vijay
"Axel Mammes" <mam...@hotmail.com (put s instead of z)> wrote in message
news:esV$pLhSCHA.1900@tkmsftngp09...
> Hi there,
> I am writing an application in which i need to introduce a delay
> for 1 milli secods between two operations.. (Hardware settling time for
> RELAY ON/OFF)..
> I tried using Sleep API... But iam getting around 10 milli seconds for
> Sleep(1). Worse, if i call that Sleep API inside a for loop... Below is my
Have a look here:-
www.sysinternals.com/ntw2k/info/timer.shtml
--
Dave
Vijay, cool stuff. The WINMM.DLL really has the best resolution on NT
available and sysinternals even documents the native DLL export from
NTDLL.DLL. Microsoft does not document this since NTDLL is for internal use
only (sort of)...
Regards,
Vijay
"Egbert Nierop (MVP for IIS)" <egbert...@nospam.com> wrote in message
news:OsYzLMWUCHA.4092@tkmsftngp11...