I plan on writing a guide on what to buy, and how to wire it up, but before spending that time, let's make sure it works as intended.
The tester
This was largely based on that topic in the forums : https://forums.blurbusters.com/viewtopic.php?t=1381, and especially this post towards the end : https://forums.blurbusters.com/viewtopi ... 420#p27989 (many thanks to everyone who participated on that
I've then added some stuff to make life easier for me :
- switched the photodiode sensor from digital to analog, which lets me test on different stuff without having to adjust a potentiometer.
- copied some hacks (can't post external links yet, will edit later, should be first google result if you search "arduino faster analog read") to make analog read on the arduino faster
- added displays on the arduino, to not have to start com port monitoring every time, which was a bit annoying.
- also 3D printed a case, for fun and convenience again.
This is what it currently looks like : The code
The whole code can be accessed here : (can't post outside links yet, will edit this later ), but the main part, and what is interesting for us in this post is mainly this part :
Code: Select all
while (digitalRead(hold) == LOW && digitalRead(reset) == HIGH)
{
float photodiode_state = analogRead(photodiode);
float photodiode_low_barrier = (photodiode_state*0.9);
float photodiode_high_barrier = (photodiode_state*1.1);
Mouse.click();
startTime = micros();
delayMicroseconds(1);
while( photodiode_low_barrier < photodiode_state && photodiode_state < photodiode_high_barrier && digitalRead(hold) == LOW)
{
photodiode_state = analogRead(photodiode);
}
endTime = micros();
responseTime = (endTime - startTime)/1000.0;
delay(random(400, 600));
}
- It takes the current light level, then sends a mouse click, and check until it detects a 10% difference in light level.
- I've also done the barriers maths outside of the comparator loop in an effort to make that while run as fast as possible, but I'm not sure how much it matters, if I'm being honest.
Validation
Precision
This is what I did to try and validate it, and make sure it works well enough.
First, my goal was to find out how fast the arduino is without anything in, just the pure delay of the hardware and code.
The test setup for that looked like this : The whole PC was replaced with a simple LED, and I was
- turning on the LED
- starting timer
- checking the photodiode for light change
- stopping the timer
This gave me results between 30 and 40 µs, over more than 1000 samples. The input lag of a (good) PC being between 10 and 20 ms, this is 0.2% of that. I'd call it good enough.
Consistency
Then, my goal was to see how consistent it is on a real test, with a computer. So I booted up CS:GO, which is (I think) a really consistent game for that, and I started testing.
I averaged my input lag over 500 samples, which should give me a fairly accurate average, and repeated my test 10 times, without changing anything. Results were as follow :
- 14,03748
- 14,05702
- 14,17843
- 14,08252
- 14,0019
- 13,94938
- 14,00252
- 14,01164
- 14,11475
- 14,04328
Which gives me a standard deviation of 0.065, and margins of error that looks like this : Based on this, I think I can say this is reasonably accurate, and as long as tests are done properly, and with enough samples, I think this should be a good way to measure input lag.
Now, I'd like your input, especially if I'm wrong somewhere, or if you think I could improve something.
Thanks !