Re: High res timer




"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


.



Relevant Pages

  • [git patches] libata fixes
    ... tidy host controller interrupt handling ... Target mode, for those without docs, is the ability to directly ... static inline unsigned int mv_hc_from_port ... * port is the sole input, ...
    (Linux-Kernel)
  • Weird interrupt issues with RELENG_5
    ... When I bring up the network interface, ... second IDE bus. ... WARNING - READ_DMA no interrupt but good status ... <Parallel port bus> on ppc0 ...
    (freebsd-current)
  • DSP56F801FA80: SCI data formatting and executions of Interrupts
    ... com port running MS XP operating system. ... as transmit and receive is concerned. ... AS1_SendCharcall is sending tow bytes rather one. ... can i execute tow interrupt in parallel with same ...
    (comp.dsp)
  • Re: Device Drivers and all for one interrupts, can it be done.
    ... What you have describe is the scenario generally called a Shared IRQ, howver since it is a GPIO pin on a port of multiplepins it is a special case. ... It then translates that to an internal IRQ number that a device driver can request a SYSINTR for which the OAL will assign dynamically at runtime. ... Basically the OAL has an ISR for the GPIO port itself and then calls all Installable ISR routines registerd for that shared interrupt. ...
    (microsoft.public.windowsce.embedded)
  • Regression: libata: implement ata_wait_after_reset()
    ... The controller card is this one: ... ALi Corporation ALi M5281 Serial ATA / RAID Host Controller ... Interrupt: pin A routed to IRQ 19 ... spending 2s on 0xff port would incur too ...
    (Linux-Kernel)