1

I want to develop a Windows based application that would interface with external hardware using serial communication. The hardware would in turn relay back the feedback to the application. This entire loop should be ideally completed within a millisecond.

Is it possible to develop such an application on Windows OS? I read somewhere that only 0.01 seconds accurate precision can be achieved on Windows. Initially I have tried developing a smaller model running on Labview with a 2 line matlab script, but even that is taking atleast 2 ms to execute without any external communication.

I went through the this link which talks about microseconds timing in Windows in C++. Which gives me the idea that Windows is not accurate to even a millisecond precision. Do I have to leave Windows and develop an RTOS/bare metal application on a suitable hardware?

15
  • By the way, one of the mitigation for CPU branch prediction related vulnerabilities (spectre, meldown, etc...), is to report less precision in timers. The reason is that many of the exploit are based on accurate measures of time to identify what is is CPU cache, at least that is the gist of it. Because of that mitigation, you could have code that runs as fast as you need, and yet, when you measure it, it says it is slower.
    – Theraot
    Commented Nov 13, 2019 at 3:57
  • Would taking an average over several runs mitigate this error. Or maybe putting the whole thing in a for loop and measure the time by dividing total time over iterations @Theraot Commented Nov 13, 2019 at 4:05
  • Right, if you measure the total time of a lot of iteration and divide by the number of iterations, the effect of the mitigation should be minimized, that is you will get a more accurate measurement. And, of course, the more iterations, the better.
    – Theraot
    Commented Nov 13, 2019 at 4:12
  • 1
    What is the reason you want such a fast realtime connection? Is it really necessary? On any OS you will have trouble with such timings, as the OS can (and will) give processor time to other applications during which your program will be doing nothing.
    – Turksarama
    Commented Nov 13, 2019 at 4:15
  • Windows has multimedia timers that will give you much better than the 20ms or precision that Windows normally has. Commented Nov 13, 2019 at 4:26

1 Answer 1

4

According to this MSDN article section, Windows can definitely provide adequately accurate measurements for you to know whether your instructions are being executed fast enough, depending on the platform. As your measurements typically involve a total "counting" time-span of a few seconds.

Apart from that, the only way to find out if your processes can meet the requirement of < 1 ms cycle execution time, is to profile some actual code on the typical machine, where the code is expected to be used, along with the typical hardware you will be interfacing with.

As per your comment, Windows, as a platform, is not entirely relevant to your question. As you will see in the linked article, the whole "time measurement" concept really relies on the underlying hardware, for which Windows exposes suitably coded APIs to make it look like a high-precision clock.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.