Точность системного таймера в NT
От: asmodey  
Дата: 05.12.02 15:35
Оценка:
Как повысить точность системного таймера в NT с 10 милисекунд до 1 милисекунды, а то что то засекаю время а оно меньше 10 мс и в отображается 0 мс. И как написать на Си
Re: Точность системного таймера в NT
От: old->*Plutonia_Experiment() Беларусь http://blogs.rsdn.org/ikemefula
Дата: 05.12.02 16:01
Оценка:
Здравствуйте, asmodey, Вы писали:

A>Как повысить точность системного таймера в NT с 10 милисекунд до 1 милисекунды, а то что то засекаю время а оно меньше 10 мс и в отображается 0 мс. И как написать на Си


GetSystemTimeAdjustment
SetSystemTimeAdjustment — позволит установить 1 милисекунду

Замерять можно так —

DWORD dwStart = GetTickCount();
DWORD dwEnd;
 
while((GetTickCount() - dwStart) == 0)    // ожидаем следующего тика для уменьшения погрешности
  dwStart = GetTickCount();

//Do something 

dwEnd = GetTickCount();
Re: Точность системного таймера в NT
От: Anton V. Kolotaev  
Дата: 05.12.02 16:08
Оценка:
Здравствуйте, asmodey, Вы писали:

A>Как повысить точность системного таймера в NT с 10 милисекунд до 1 милисекунды, а то что то засекаю время а оно меньше 10 мс и в отображается 0 мс. И как написать на Си


A QueryPerfomanceCounter не устраивает?
Re[2]: Точность системного таймера в NT
От: asmodey  
Дата: 05.12.02 16:27
Оценка:
Здравствуйте, old->*Plutonia_Experiment(), Вы писали:

OE>Здравствуйте, asmodey, Вы писали:


A>>Как повысить точность системного таймера в NT с 10 милисекунд до 1 милисекунды, а то что то засекаю время а оно меньше 10 мс и в отображается 0 мс. И как написать на Си



OE>Замерять можно так —


OE>
OE>DWORD dwStart = GetTickCount();
OE>DWORD dwEnd;
OE> 
OE>while((GetTickCount() - dwStart) == 0)    // ожидаем следующего тика для уменьшения погрешности
OE>  dwStart = GetTickCount();

OE>//Do something 

OE>dwEnd = GetTickCount();
OE>


OE>GetSystemTimeAdjustment

OE>SetSystemTimeAdjustment — позволит установить 1 милисекунду

Как эти функции использовать в программе? а то у меня MSDN нету
Re[2]: Как использовать GetSystemTimeAdjustment
От: asmodey  
Дата: 05.12.02 16:39
Оценка:
Здравствуйте, old->*Plutonia_Experiment(), Вы писали:

OE>Здравствуйте, asmodey, Вы писали:


A>>Как повысить точность системного таймера в NT с 10 милисекунд до 1 милисекунды, а то что то засекаю время а оно меньше 10 мс и в отображается 0 мс. И как написать на Си


OE>GetSystemTimeAdjustment

OE>SetSystemTimeAdjustment — позволит установить 1 милисекунду



Как правильно использовать GetSystemTimeAdjustment функцию и настроить необходимые параметры времени?
Re[3]: Точность системного таймера в NT
От: old->*Plutonia_Experiment() Беларусь http://blogs.rsdn.org/ikemefula
Дата: 05.12.02 16:40
Оценка:
Здравствуйте, asmodey, Вы писали:

OE>>
OE>>DWORD dwStart = GetTickCount();
OE>>DWORD dwEnd;
OE>> 
OE>>while((GetTickCount() - dwStart) == 0)    // ожидаем следующего тика для уменьшения погрешности
OE>>  dwStart = GetTickCount();

OE>>//Do something 

OE>>dwEnd = GetTickCount();
OE>>


OE>>GetSystemTimeAdjustment

OE>>SetSystemTimeAdjustment — позволит установить 1 милисекунду

A>Как эти функции использовать в программе? а то у меня MSDN нету



Пример рабочий
Re[3]: Как использовать GetSystemTimeAdjustment
От: old->*Plutonia_Experiment() Беларусь http://blogs.rsdn.org/ikemefula
Дата: 05.12.02 16:42
Оценка:
Здравствуйте, asmodey, Вы писали:

SetSystemTimeAdjustment
The SetSystemTimeAdjustment function enables or disables periodic time adjustments to the system's time-of-day clock. Such time adjustments are used to synchronize the time of day with some other source of time information. When periodic time adjustments are enabled, they are applied at each clock interrupt.

BOOL SetSystemTimeAdjustment(
DWORD dwTimeAdjustment, // size of adjustment
BOOL bTimeAdjustmentDisabled // disable option
);
Parameters
dwTimeAdjustment
[in] Specifies the number of 100-nanosecond units added to the time-of-day clock at each clock interrupt if periodic time adjustment is enabled.
bTimeAdjustmentDisabled
[in] Specifies the time adjustment mode that the system is to use. Periodic system time adjustments can be disabled or enabled.
A value of TRUE specifies that periodic time adjustment is to be disabled. The system is free to adjust time of day using its own internal mechanisms. The value of dwTimeAdjustment is ignored. The system's internal adjustment mechanisms may cause the time-of-day clock to jump noticeably when adjustments are made.

A value of FALSE specifies that periodic time adjustment is to be enabled, and will be used to adjust the time-of-day clock. The system will not interfere with the time adjustment scheme, and will not attempt to synchronize time of day on its own. The system will add the value of dwTimeAdjustment to the time of day at each clock interrupt.

Return Values
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError. One way the function can fail is if the caller does not possess the SE_SYSTEMTIME_NAME privilege.

Remarks
The GetSystemTimeAdjustment and SetSystemTimeAdjustment functions support algorithms that synchronize the time-of-day clock, reported via GetSystemTime and GetLocalTime, with another time source using a periodic time adjustment.

The SetSystemTimeAdjustment function supports two modes of time synchronization: time-adjustment – disabled and time-adjustment – enabled.

In the first mode, bTimeAdjustmentDisabled is set to FALSE. At each clock interrupt, the system adds the value of dwTimeAdjustment to the time of day. The clock interrupt rate may be determined by calling GetSystemTimeAdjustment, and looking at the returned value pointed to by lpTimeIncrement.

In the second mode, bTimeAdjustmentDisabled is set to TRUE. At each clock interrupt, the system adds the interval between clock interrupts to the time of day. No adjustment to that interval is made. The system is free to periodically refresh the time-of-day clock using other techniques. Such other techniques may cause the time-of-day clock to jump noticeably when adjustments are made.

An application must have system-time privilege (the SE_SYSTEMTIME_NAME privilege) for this function to succeed. The SE_SYSTEMTIME_NAME privilege is disabled by default. Use the AdjustTokenPrivileges function to enable the privilege before calling SetSystemTimeAdjustment, and then to disable the privilege after the SetSystemTimeAdjustment call.

Requirements
Windows NT/2000/XP: Included in Windows NT 3.5 and later.
Windows 95/98/Me: Unsupported.
Header: Declared in Winbase.h; include Windows.h.
Library: Use Kernel32.lib.

See Also
Time Overview, Time Functions, AdjustTokenPrivileges, GetLocalTime, GetSystemTime, GetSystemTimeAdjustment




Platform SDK: Windows System Information
GetSystemTimeAdjustment
The GetSystemTimeAdjustment function determines whether the system is applying periodic time adjustments to its time-of-day clock at each clock interrupt, along with the value and period of any such adjustments. Note that the period of such adjustments is equivalent to the time period between clock interrupts.

BOOL GetSystemTimeAdjustment(
PDWORD lpTimeAdjustment, // size of time adjustment
PDWORD lpTimeIncrement, // time between adjustments
PBOOL lpTimeAdjustmentDisabled // disable option
);
Parameters
lpTimeAdjustment
[out] Pointer to a DWORD that the function sets to the number of 100-nanosecond units added to the time-of-day clock at each periodic time adjustment.
lpTimeIncrement
[out] Pointer to a DWORD that the function sets to the interval, counted in 100-nanosecond units, between periodic time adjustments. This interval is the time period between a system's clock interrupts.
lpTimeAdjustmentDisabled
[out] Pointer to a BOOL that the function sets to indicate whether periodic time adjustment is in effect.
A value of TRUE indicates that periodic time adjustment is disabled. At each clock interrupt, the system merely adds the interval between clock interrupts to the time-of-day clock. The system is free, however, to adjust its time-of-day clock using other techniques. Such other techniques may cause the time-of-day clock to noticeably jump when adjustments are made.

A value of FALSE indicates that periodic time adjustment is being used to adjust the time-of-day clock. At each clock interrupt, the system adds the time increment specified by SetSystemTimeAdjustment's dwTimeIncrement parameter to the time-of-day clock. The system will not interfere with the time adjustment scheme, and will not attempt to synchronize time of day on its own via other techniques.

Return Values
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks
The GetSystemTimeAdjustment and SetSystemTimeAdjustment functions support algorithms that want to synchronize the time-of-day clock, reported by GetSystemTime and GetLocalTime, with another time source using a periodic time adjustment applied at each clock interrupt.

When periodic time adjustment is in effect, the system adds an adjusting value to the time-of-day clock at a periodic interval, at each clock interrupt. The GetSystemTimeAdjustment function lets a caller determine whether periodic time adjustment is enabled, and if it is, obtain the amount of each adjustment and the time between adjustments. The SetSystemTimeAdjustment function lets a caller enable or disable periodic time adjustment, and set the value of the adjusting increment.

Requirements
Windows NT/2000/XP: Included in Windows NT 3.5 and later.
Windows 95/98/Me: Unsupported.
Header: Declared in Winbase.h; include Windows.h.
Library: Use Kernel32.lib.

See Also
Time Overview, Time Functions, SetSystemTimeAdjustment, GetSystemTime, GetLocalTime

Platform SDK Release: August 2001 What did you think of this topic?
Let us know. Order a Platform SDK CD Online
(U.S/Canada) (International)



Requirements
Windows NT/2000/XP: Included in Windows NT 3.5 and later.
Windows 95/98/Me: Unsupported.
Header: Declared in Winbase.h; include Windows.h.
Library: Use Kernel32.lib.
See Also
Time Overview, Time Functions, SetSystemTimeAdjustment, GetSystemTime, GetLocalTime




A>>>Как повысить точность системного таймера в NT с 10 милисекунд до 1 милисекунды, а то что то засекаю время а оно меньше 10 мс и в отображается 0 мс. И как написать на Си


OE>>GetSystemTimeAdjustment

OE>>SetSystemTimeAdjustment — позволит установить 1 милисекунду

A>


A>Как правильно использовать GetSystemTimeAdjustment функцию и настроить необходимые параметры времени?
Re[4]: Как использовать GetSystemTimeAdjustment
От: asmodey  
Дата: 05.12.02 16:48
Оценка:
Здравствуйте, old->*Plutonia_Experiment(), Вы писали:


A>>Как правильно использовать GetSystemTimeAdjustment функцию и настроить необходимые параметры времени?


А на примере можно для чайников?
Re[2]: Лучше использовать
От: Lopcom  
Дата: 05.12.02 21:31
Оценка:
OE>GetSystemTimeAdjustment
OE>SetSystemTimeAdjustment — позволит установить 1 милисекунду

— эти функции работают только под NT'и, лучше используйте
timeBeginPeriod
timeEndPeriod
будет работать везде!

Что те, что эти функции повышают точноть до 1 миллисекунды.
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.