Better timing??

  • Thread starter Thread starter jamie
  • Start date Start date
J

jamie

Hi all,

I tried posting this Q in Csharp, but they seem
to be down right now. (Anyone know why?)

Here it goes...

I am working on a school project, that includes
the control of motors throught motion profiling,
and velocity loops. The velocity loop function
has to run every 10ms, and preferably more
precise than not.

Does anyone have any suggestions as to how to
start the funcion every 10ms, with more precision
than using the Timer function? Sould I put it on
a separate thread, put the thread to sleep for
a certain amount of time?? Will that be better
than the timer function? or does it do it alread
that way? How do they do this timing for games an such??

Any and all suggestions would be greatly appreciated.

Thanks in advance for all help
 
Check out System.Timers.Timer in MSDN. It's a lot more precise than a Forms
Timer control, and kicks off on a worker thread so UI updates and such
shouldn't interfere with it as much. It is more work to set up and utilize
correctly though.
 
Hi,

You should be able to use threading using System.Threading.Thread or
System.Threading.Timer (resolution will be ABOUT 1 mS).

However, real-time programming depends on the execution speed of the code
that you execute in the thread. Obviously, if the code that executes in the
thread takes an appreciable time to execute (say 3 or more mS to complete),
you will experience quite a bit of "jitter" that may affect performance.

You have to actually write some code to see how long each iteration takes.
If it is (say) 1 mS, then you should be in good shape -- make sure that you
take into account the time that is required to deliver data OUT of the
thread to wherever it is being consumed.

Dick

--
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.
 
Back
Top