[Leonardo] USB|PS/2 mouse lag when cpu is busy

Hello

First of all, not Leonardo, but Micro. Just named topic for simpler search and understanding. My project is PS/2 to USB converter/adapter for my favorite mouse (very unique, 5 buttons and 2 wheels).

ISSUE:
When multiple applications startup or in some other ways cpu is busy for short moment, mouse cursor lags and then jump in different place. Rare, but false clicks happen too. Happens with NicoHood and default Arduino mouse code. Quick way to reproduce is by starting Chrome browser and after it's blank window appears in 1.5-2 seconds lag occurs. Win10 suffers horrible from this, Win7 is way better.

What i have found till now by using serial timing measurements, reading ps/2 port signals becomes very slow in those moments of lags, like 180-470 ms. It's because of code in that library which have cycles to wait valid signals, i did some modifications to replace infinite cycles to avoid spinning forever, but that still not works. Without arduino adapter regular usb mouse works fine. So it seems some issue with communication between OS and usb of the Arduino, Windows requests something by usb and that produce delay big enough to break reading ps/2 signals in right time. Or it's arduino sends data by usb somehow regulary and when OS is busy, arduino is waiting (but i do not execute any usb related code in those moments, not sure this is possible for non multithreaded controller, but hell knows).
I'm not much familiar with ps/2 protocol and just tried to fix some bugs which found in several libraries for ps/2 communication. Didn't find ps/2 library without mistakes (they just copy bugs of each other), so maybe somebody could suggest me the one. Or how to make things work, any idea is welcome.

EDIT: Attached source code. Problem somewhere in the PS2MouseHandler.cpp, when USB lag makes controller not execute in right time. Playing with cycles changes things, but not fix issue. And keep in mind i replaced "while" by "for" on purpose, otherwise infinite loops occur.

PS2MouseHandler.cpp (11.0 KB)
PS2MouseHandler.h (1.5 KB)
ps2tousb.ino (7.0 KB)

I am not following exactly what you are saying but if the processor is busy it will not process the other devices such as the mouse and interrupts etc will get missed.

Cpu is not really busy much to stop things working, described issue just happens when it's busy. Maybe this is happens in the moments when other applications initialize input, i don't know. But definetly this moment forces Arduino to have some kind of delay or slowdown and it can't read data from PS/2 mouse properly. At least it seems like that to me. I could try to connect ps/2 to other pins (now it's 14 and 16 which are SPI), if it matters. The only workaround right now is to use two Arduino modules, one for reading ps/2 port and another for communication with usb, then usb not gonna influence ps/2 with those lags. But this is wrong way to solve issues.

Added files to attachment of first message.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.