Got back to this again. This time I did a different test only using Arduino, firmware and console application on PC:
• On PC: send a signal to Arduino from PC through USB's virtual Serial port
• On Arduino: when it gets the signal, send 'a' key back using default Keyboard.h library.
• On PC: wait for the keystroke to arrive.
• On PC: Measure time between the moment before it started sending the signal to Arduino and the moment it registered the key press.
• On PC: print the result to the console window.
Do it a 1000 times and get the average of 1000 measurements.
tl;dr conclusion: no need for PCIe because even at 1000 Hz average latency is below 1ms, and at overclocked 8000 Hz it should be around 62.5 microseconds.
I got interesting results which I can't explain. On a default polling rate, I get less than 0.5ms on average from 1000 measurements and almost all of them are below 0.5ms(and very close to it). Here are the numbers from one run:
Average of this run is 0.482ms.
When I install custom hidusb driver from the USB mouse hard overclocking
thread, install service, filter and set polling rate to 1000, I get very similar results: sub 0.5ms average ping time. I don't understand why all of them are so close to 0.5ms. They should be fluctuating 0.001-2.000ms all the time, not be in a very close to 0.5ms range. I think they should be fluctuating 0.001-2.000ms because PC also first sends information to the Arduino and only after that waits for the keystroke, so it should take at least 2 transfers: one out and one in.
When I change polling rate to 500, average becomes very close to 1ms. That's expected again, but all results are very close to 1ms. As I said, I expect them to fluctuate from 0.001-4.000ms in this case to get an average of 2ms because of 2 transfers.
And this situation repeats on no matter what polling rate I do it on: 31, 62, 125, 250, 500, 1000. On every try, time of the ping equals to (1000 / polling rate / 2)ms. So at 1000 Hz it's 0.5ms, at 500 Hz it's 1ms, at 125Hz it's 4ms, etc.
When I install the 4kHz-8kHz driver and set the rate to 62, which is supposed to be 8000 Hz, ping time gets very close to 125µs, as it's supposed to. Here are results from one run:
In this run average is 128µs(0.128ms).
This is finally expected average because of 2 transfers, but why all of them are still so damn close to the 125µs? They should be in 0-250µs range because of 2 transfers, as I understand it.
If anyone wants to try it out, I uploaded it to GitHub: https://github.com/KulaGGin/USB-Lag-Test
. All you need to do is to upload LagTest.Arduino.ino
sketch to Arduino from Visual Studio, Arduino IDE or whatever you use, build LagTest.PC
project, start it, enter the name of Arduino's com port or just press enter if you have only one or if first will do and wait for the results. In my case looks like this:
For the completeness, here's code.
Does anyone know and could, please, explain, why am I getting the average of (1000 / polling rate / 2)ms, when, as I think, it should be average of (1000 / polling rate)ms, because PC first sends the signal and only then Arduino answers? And also why all results are so close to the (1000 / polling rate / 2)ms and not spread around between 0 to (1000 / polling rate)ms?