开发者

Problem with High speed data read with Settimer method

I am using the hardware with ftdi chip in FIFO mode and D2xx driver for my work. Hardware is sending data bytes at the rate of 19.5KHz to 312.5 KHz for different settings. So my application software(MFC C++) is supposed to read these bytes coming at various speed.I am using Settimer and Ontimer method with value of 10 ms.So every 10 ms i am reading the data bytes and do some processing in OnTimer function. My questions are

1>with settimer method different systems are giving different results even though both the systems are XP SP3. One system is reading all the bytes without any missing but in another system data will miss. So is this timer is depend on OS or system hardware?

2> From what i understand minimum value i can set for settimer is 10 ms So every 10 ms i can read the data.If i do not read fast there will be overflow in driver buffer which i cannot control.So can i read more faster in microsecond or nano seconds with Any timer method or is there any other 开发者_StackOverflow社区method? Please suggest me some idea... Thanks in advance


It will probably be more reliable to keep blocking on Read() in a separate thread.

SetTimer() is meant only for low-res work. Its resolution can actually be scaled back depending on power settings in more recent versions of Windows.

If you want high-resolution timers, Timer Queues or Multimedia Timers (specifically, timeSetEvent()) are the way to go, both of which can have a resolution down to 1ms.


The problem with SetTimer is that you will get timer notifications no sooner than the time you set, but you can't guarantee that it will be at exactly the time you set.

First, you depend on the system's timer resolution, which is usually 15 ms. So, even if you set 10 ms, it will tick at 15 ms (or more).

Second, timer notifications are sent when there are no more messages to process. So, in the message loop, when there are no more messages in the queue, the systems looks if there's any timer set and if it has ticked. If it has, it sends one notification. The thing is, if your program is busy doing other things, it might lose one or several "ticks" and "group" them in one notification, which can happen at, say, 75 ms.

The bottom line is SetTimer is not a reliable timer method for high resolution needs.

So you may have to look at other solutions, like a separate thread to do the reading.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜