Re: High res timer
- From: "Jon Slaughter" <Jon_Slaughter@xxxxxxxxxxx>
- Date: Thu, 06 Sep 2007 21:06:52 GMT
"Doug Semler" <dougsemler@xxxxxxxxx> wrote in message
news:1189109416.141893.174170@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Sep 6, 3:46 pm, "Jon Slaughter" <Jon_Slaugh...@xxxxxxxxxxx> wrote:
To be honest, I guess I really need a high res timer becaues I also want
to
send data. The data doesn't have to be syncronized though as the pc will
be
a "master". Although I will need to send the data to the port in a timely
fashion at some configurable rate from 1khz to 100khz(the faster the
better). (jitter is not a huge concern though)
I figure that if I time a thread that, say, runs at 150mhz, I can setup a
delay to lock in on a specific rate. But in this case I'm wasting a lot
of
cycles delaying the thread. If I had a Thread.Sleep that was more
accurate
than 1ms then it would be a piece of cake. (I understand that theres a
lot
of task switching invovled and stuff but I'm not looking for the optimal
method but something that works and doesn't bring the system to a
screaching
halt).
First off, the windows timer has a resolution of something like 15-45
ms (depending on the OS). Sleep(1) can last 15 ms. That's just the
way it is.
You could potentially use QueryPerformanceCounter in some sort of spin
loop to get the resolution you want (i.e. call it multiple times and
break out of the loop when you find that you've gone beyond the time
span). Problem is you have to give up timeslices back to the OS to
keep your spin loop from grabbing all the cycles. Issue is the same
as above, sleep(0) can give up more than just the time slice to the
OS. I think there is also a Multimedia counter somewhere but IIRC,
the resolution is only 1 ms
You really should consider allowing the port to signal you when you
receive data rather than polling the port to see if there is data.
And how would I do this? It would require an interrupt or polling. In each
case there are issues.
Now the interrupt method might be the best if there is no way to do high
resolution polling but does require an external clock and some way to hook
the interrupt for the port. Unfortunately then its very difficult to vary
the clock speed(I suppose its not all that difficult but does require much
more hardware than it should) and requires the use of one of the pins.
Surely what I want to do is not impossible. After all, its done all the time
such as with USB, ethernet, RS-232, parallel port, etc... Its quite simple
to do in DOS but I'd rather do it in windows and use .NET.
The reason I think polling is the easiest is that its very simple to do. The
main issue is that if I use Sleep(1) then I get something like a 250hz rate
and if I don't then its up to 150mhz. Seems kinda moronic that I can get
anything inbetween.
Jon
.
- Follow-Ups:
- Re: High res timer
- From: Doug Semler
- Re: High res timer
- References:
- High res timer
- From: Jon Slaughter
- Re: High res timer
- From: Jon Slaughter
- Re: High res timer
- From: Doug Semler
- High res timer
- Prev by Date: Re: C# Console app with hidden window and user input
- Next by Date: Re: Network question
- Previous by thread: Re: High res timer
- Next by thread: Re: High res timer
- Index(es):
Relevant Pages
|