高分辨率计时器 [英] High res timer

查看:84
本文介绍了高分辨率计时器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能有一个同步线程...实际上是一个超出.NET提供的1khz / 1ms分辨率的
的计时器?


我希望以超过1khz的速率对并行端口进行轮询......如果可能的话,大约10到100

倍。


我想要监控数据的并行端口并显示它但是

我需要一种快速但有些精确的方式来了解采样率。


只需一个简单的线程做一些测试我可以使用普通优先级System.Thread获得大约150mhz的速度

左右。我认为,因为我只需要大约1/1000的
它不应该是那么大的交易。


这在C#中是否可行。净?如果没有,是否可以在非托管C ++中编写一个简单的驱动程序

轮询端口或挂钩到

中断(同步)以获取数据到C# app?


谢谢,

Jon

Is it possible to have a synchronous thread... actually a timer that is
beyond the 1khz/1ms resolution that .NET offers?

I want to poll the parallel port at rates beyond 1khz... about 10 to 100
times that rate if possible.

Essnetially I want to monitor the parallel port for data and display it but
I need a fast but somewhat precise way of knowing the sample rate.

Doing some tests on just a simple thread I can get speeds at around 150mhz
or so with a normal priority System.Thread. I figure that since I just need
about 1/1000 of that it shouldn''t be that big a deal.

Is this possible in C#.NET? If not, is it possible to write a simple driver
in unmanaged C++ that either polls the port or hooks onto an
interrupt(synced) to get the data to a C# app?

Thanks,
Jon

推荐答案



说实话,我想我真的需要一个高分辨率计时器,因为我也想要发送数据。
发送数据。数据并不一定要同步,因为电脑将是主电源。虽然我需要以1khz到100khz的可配置速率及时将数据发送到端口(

越快越好)。 (抖动不是一个大问题)


我想如果我计算一个线程,比如运行150mhz,我可以设置一个

延迟锁定特定的费率。但在这种情况下,我浪费了很多延迟线程的
周期。如果我有一个更精确的Thread.Sleep,那么它将是一块蛋糕。 (我知道有很多

的任务切换调整和东西,但我不是在寻找最佳的

方法,但是有效的东西并没有带来系统到了screaching

停止。


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).


9月6日下午3:46,Jon Slaughter < Jon_Slaugh ... @ Hotmail.comwrote:
On Sep 6, 3:46 pm, "Jon Slaughter" <Jon_Slaugh...@Hotmail.comwrote:

说实话,我想我真的需要一个高分辨率计时器因为我也想要

发送数据。数据并不一定要同步,因为电脑将是主电源。虽然我需要以1khz到100khz的可配置速率及时将数据发送到端口(

越快越好)。 (抖动不是一个大问题)


我想如果我计算一个线程,比如运行150mhz,我可以设置一个

延迟锁定特定的费率。但在这种情况下,我浪费了很多延迟线程的
周期。如果我有一个更精确的Thread.Sleep,那么它将是一块蛋糕。 (我知道有很多

的任务切换调整和东西,但我不是在寻找最佳的

方法,但是有效的东西并没有带来系统到了screaching

停止)。
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).



首先,Windows计时器的分辨率大小为15-45美元b $ b ms(取决于操作系统)。睡眠(1)可以持续15毫秒。这只是

的方式。


您可能会在某种旋转中使用QueryPerformanceCounter

循环到获得你想要的分辨率(即多次调用它,并且当你发现你已经超出时间时,
突破了循环

span)。问题是你必须放弃时间片回到操作系统来确保你的旋转循环不会占用所有周期。问题是如上所述的

,sleep(0)可以放弃超过

操作系统的时间片。我认为还有一个多媒体计数器,但IIRC,

分辨率只有1毫秒


你真的应该考虑允许端口在你发信号时给你发信号

接收数据而不是轮询端口以查看是否有数据。


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.




" ; Doug Semler < do ******** @ gmail.comwrote in message

news:11 ********************** @ d55g2000hsg.googlegr oups.com ...

"Doug Semler" <do********@gmail.comwrote in message
news:11**********************@d55g2000hsg.googlegr oups.com...

9月6日下午3:46,Jon Slaughter < Jon_Slaugh ... @ Hotmail.comwrote:
On Sep 6, 3:46 pm, "Jon Slaughter" <Jon_Slaugh...@Hotmail.comwrote:

>说实话,我想我真的需要一个高分辨率计时器因为我也想要
发送数据。数据不必同步,因为个人电脑将是主人。虽然我需要以1khz到100khz的可配置速率及时将数据发送到端口(
越快越好)。 (抖动不是一个大问题)

我认为,如果我计算一个线程,比如运行150mhz,我可以设置一个
延迟来锁定一个特定的速率。但在这种情况下,我浪费了很多延迟线程的循环。如果我的Thread.Sleep比1ms更精确,那么它将是一块蛋糕。 (我知道有很多任务切换调用和东西但是我不是在寻找最佳的方法但是有些东西可行并且不会使系统进入
screaching
停止)。
>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).




首先,Windows计时器的分辨率为15-45

ms(取决于操作系统) 。睡眠(1)可以持续15毫秒。这只是

的方式。


您可能会在某种旋转中使用QueryPerformanceCounter

循环到获得你想要的分辨率(即多次调用它,并且当你发现你已经超出时间时,
突破了循环

span)。问题是你必须放弃时间片回到操作系统来确保你的旋转循环不会占用所有周期。问题是如上所述的

,sleep(0)可以放弃超过

操作系统的时间片。我认为还有一个多媒体计数器,但IIRC,

分辨率只有1毫秒


你真的应该考虑允许端口在你发信号时给你发信号

接收数据而不是轮询端口以查看是否有数据。



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.



我该怎么做?这需要中断或轮询。在每个

的情况下都有问题。


现在中断方法可能是最好的,如果没有办法做高

分辨率轮询,但需要一个外部时钟和一些方法来挂钩端口的中断。不幸的是,它很难在时钟速度上变化(我认为它并不是那么困难,但确实需要更多的硬件比它应该多的b $ b)并且需要使用一个销售。


当然,我想要做的并非不可能。毕竟,它一直在完成

,比如USB,以太网,RS-232,并口等等......在DOS上做的很简单,但要做到b $ b。我宁愿在Windows中使用.NET。


我认为轮询最简单的原因是它非常简单。

主要问题是,如果我使用Sleep(1)然后我会得到类似250hz的价格

,如果我不高达150mhz。看起来有点蠢,我可以得到

介于两者之间。


Jon

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


这篇关于高分辨率计时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆