FreeJoy icon indicating copy to clipboard operation
FreeJoy copied to clipboard

Improve latency

Open misteraddons opened this issue 4 years ago • 15 comments

I work on the MiSTerFPGA project. We have a testing suite used to measure input latency using an FPGA in the loop.

FreeJoy is something I'm very intersted in using in some upcoming projects, but it would be awesome to find a way to decrease the input latency.

The best controllers have 0-5ms of latency, where FreeJoy currently has ~60ms: Average: 60.1666 ms Max: 63.804 ms Min: 56.408 ms Std Dev: 1.591 ms I set up all buttons to be BTN_GND, and ran the test with more than 2000 samples.

Let me know if I can be of any assistance!

misteraddons avatar Aug 19 '20 17:08 misteraddons

Hello, i guess you get 60ms latency because of debouncing algorithm for the buttons. You can decrease debouncing time to improve input latency but there are ghost presses possible at to low values

vostrenkov avatar Aug 19 '20 17:08 vostrenkov

image

vostrenkov avatar Aug 19 '20 17:08 vostrenkov

Excellent, thank you! I haven't tested without debounce so it may still need to be tweaked but here are my current results: Capture Also, full spreadsheet of results here: https://docs.google.com/spreadsheets/d/1KlRObr3Be4zLch7Zyqg6qCJzGuhyGmXaOIUrpfncXIM/edit?usp=sharing

Looking forward to the possibility of 2P support :)

misteraddons avatar Aug 19 '20 21:08 misteraddons

Ideally debounce should happen in the hardware. So, assuming it is, what would be the latency with software debounce off?

Avalonnw avatar Aug 19 '20 23:08 Avalonnw

The Notes column of the results shows that the top 4 results were with software debounce disabled.

misteraddons avatar Aug 20 '20 00:08 misteraddons

The Notes column of the results shows that the top 4 results were with software debounce disabled.

I can see that. I meant I was curious to see FreeJoy's latency with debounce off. I am aasuming it would be in 6.2-13.9 range?

Avalonnw avatar Aug 20 '20 00:08 Avalonnw

Sorry, I don't follow. Those are the results with debounce off.

misteraddons avatar Aug 20 '20 00:08 misteraddons

FreeJoy results are with debounce set to 50ms. I says so in your table.

Avalonnw avatar Aug 20 '20 00:08 Avalonnw

That's only the bottom result. The other 4 are with "0 ms debounce".

misteraddons avatar Aug 20 '20 00:08 misteraddons

That's only the bottom result. The other 4 are with "0 ms debounce".

Ah, sorry, I thought the top 4 were done with other controllers. My bad.

Avalonnw avatar Aug 20 '20 01:08 Avalonnw

No problem :)

misteraddons avatar Aug 20 '20 01:08 misteraddons

You can also try to set higher USB exchange rate in advanced settings. It should reduce input latency even more. But i think 30-60ms is quite enough for most of applications. Also i should say that button processing have lowest priority in the software. So adding analog axes and digital sensors to the system may significantly increase button input latency

vostrenkov avatar Aug 20 '20 11:08 vostrenkov

I forgot to mention, this is with 1 ms/1000 Hz polling enabled on the MiSTer FPGA system. The lowest latency devices are around 0.75 ms. I see you're looking into bootsector's STM32 HID bootloader. In talking with him, that should help significantly. Let me know if you'd like me to retest with any experimental firmware.

misteraddons avatar Aug 21 '20 14:08 misteraddons

Thank you! I'm satisfied with the testing results enough, so I don't think there is a reason to improve input performance, at least for now.

I used to analyze some lightweight bootloader implementations but finally made a fat one using stm usb library. It does everything i wanted though

vostrenkov avatar Aug 21 '20 15:08 vostrenkov

I ended up working with bootsector and he was able to get his own firmware down to 0.73 ms on MiSTer. If you ever want to improve latency, that might be something to look into. Cheers and thanks for the awesome, flexible code!

misteraddons avatar Aug 27 '20 11:08 misteraddons