
Signature
Peter [MVP Visual Developer]
Jack of all trades, master of none.
> > Hi, everyone,
> >
[quoted text clipped - 20 lines]
> second? Can you describe your situation so that alternative approaches might
> be suggested?
Thank you very much, Mr. Peter.
I will explain the situation more detail now:
We are developing a communication software on the PC side, the counterparter
is a MCU.
The sleep() is called for data synchronization, but 1 millisecond is too
long -- the baud rate is 9600bps, so I need a solution, a more accurate
version sleep() for this purpose.
Dick Grier - 03 Aug 2005 16:13 GMT
Hi,
You cannot use Sleep for precise timing. As Peter says, its minimum
resolution is 1 mS (but it may cause the thread to not execute for
considerably longer). In fact, Windows is not a real-time OS, so any
accurate measurements are problematic.
You can use the QueryPerformanceCounter API calls for somewhat more precise
timing, but the actual precision (accuracy) will be less than the resolution
that it or any other method provides.
One thing that you must realize is that there is much more going on than the
things that you can control. For example, in your application, the serial
port UART FIFO can buffer up to 16 bytes before an interrupt is generated
and processed -- so there may be that much latency involved in your
measurement. However, it is possible for the serial data to be input by the
serial port driver BEFORE all 16 bytes have been buffered by the UART FIFO.
You will never know if this has or has not happened.
Also, Windows is a multitasking OS. Since it isn't a real-time OS, any
other application (and lots of Windows own operations) will take an
indeterminate amount of time to execute.
Any measurements that you attempt that require precision better than the
basic 1 mS that most timing functions offer will be subject to hit-or-miss
operation. That is, it may or may not work well enough. IMO, any really
precise timing needs to be done in some purpose-built system.
Dick

Signature
Richard Grier (Microsoft Visual Basic MVP)
See www.hardandsoftware.net for contact information.
Author of Visual Basic Programmer's Guide to Serial Communications, 4th
Edition ISBN 1-890422-28-2 (391 pages) published July 2004. See
www.mabry.com/vbpgser4 to order.
hohhot - 04 Aug 2005 02:42 GMT
Thank you very much, Mr. Grier!
> Hi,
>
[quoted text clipped - 25 lines]
>
> Dick