473,473 Members | 1,759 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Better timing??

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

Nov 21 '05 #1
2 868
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.

"jamie" <an*******@discussions.microsoft.com> wrote in message
news:07****************************@phx.gbl...
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

Nov 21 '05 #2
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.
Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Greg Stark | last post by:
This query is odd, it seems to be taking over a second according to my log_duration logs and according to psql's \timing numbers. However explain analyze says it's running in about a third of a...
1
by: Novice | last post by:
Hi all, I'm at my wit's end on trying to insert some timing code into the server side code that parses the hashed data contained in the hidden field being submitted to the server I've tried...
2
by: Steven D'Aprano | last post by:
The timeit module is ideal for measuring small code snippets; I want to measure large function objects. Because the timeit module takes the code snippet argument as a string, it is quite handy...
0
by: Bart Kastermans | last post by:
|    def __str__ (self): I did some timing of operations involved. Doing this I found that the operation below to get a string representation for trees was in fact not quadratic. The final...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.