I own and work in a small company called Yaeltex, in Argentina, where we are designing, making and selling tools for people to make their own MIDI Controllers.
One of our products is the Kilomux shield, which is an I/O expansion shield with MIDI IN/OUT circuitry.
This shield gives me 32 analog or digital inputs (whatever combination works) and 16 digital outputs.
The code I am using is here. It is somewhat messy and not yet fully commented, but the reading of the analog inputs is inside a function called ReadInputs() on lines 601-624, and the handling of this input to determine whether or not it should send a MIDI message and what will this message be, is done inside the function called InputChanged(), lines 650-736.
When I read an analog input, I divide the value by 8 in order to have a 7bit value to send it through MIDI. This gives me a value between 0-127. This is working perfectly, most of the time.
Now, sometimes, the value doesn't go the full way down to 0, but it stops on 2 (23 if full I verify thhe full 10 bit resolution).
I've been using the code above for many MIDI controllers we've created, and never came across this issue before.
I noticed that usually when this happens, I am using an USB hub, where I plug the MIDI Controller, and then this HUB is connected to the computer's USB port. But most of the time the controller works just fine when connected to this HUB.
Every time that this happened, the problem went away when pluggin the USB directly to my computer. And sometimes reconnecting to the HUB.
But yesterday I tried this on a different computer and the problem persisted after disconnecting and reconnecting the USB cable on the computer's port, without any HUB.
The problem seems electrical, and not in the code, but I can't figure out if it's a problem with the USB power, with the ribbon cable and its length, or what.
Has anyone ever come across a simillar issue and solved it?