USB HID Volume Knob Strange Behaviour

General discussion on mikroC PRO for PIC.
Post Reply
Author
Message
alvaroevc5
Posts: 69
Joined: 23 Apr 2014 07:32

USB HID Volume Knob Strange Behaviour

#1 Post by alvaroevc5 » 05 Feb 2022 00:54

Hello MikroC people.

So, after quite a long time messing around with USB HID on MikroC Pro using a PIC18F2550, I managed to get a volume knob working with my requirements....kind of...

I was wondering if when lowering the volume, is it supposed to go faster than when volume goes up?
Because that's the result I'm getting, and I have gone through my code and can't find a possible culprit so far...

There is this weird behavior where, if I move the knob at a decent speed, not too fast not too slow, volume changes normally on steps of two units (something standardized apparently). But, if I go somewhat slow when lowering the volume, it jumps aggressively and not so consistently, steps of about 8 or 10 units, and it only happens when lowering the volume, when going up, these abrupt jumps don't happen.

I have checked if it was due to my debouncing circuit, and something as simple as switching Channel A with Channel B on the encoder side would show me if it was related to the way the circuitry was handled, but no, it doesn't matter which way I choose to be VOLUME+ or VOLUME-, the issue only happens when lowering the volume.

Then I thought extra packets were being sent due to probably not being careful with my flags and timings on my code, but no, I downloaded Free Device Monitoring Studio, a software to track packets in many protocols, and found out that strangely, no extra packets were being sent.

For example, for every step on the knob there is a packet sent for a volume change of 2 units on the screen, but when the aggressive volume jumps appear, let's say from 100 to 80 normally and the from 80 to 60 suddenly on the volume scale, there should be 10 extra packets right there, but there are significantly less, just the ones corresponding to the first 10 normal pulses, whereas, when bringing the volume up, the number of packets were consistent with the number of units displayed on screen.

So I don't know if this is how the HID driver handles volume, or if I am doing something wrong either in code or in the descriptor, which once again, I have checked over and over and nothing appears to be causing that particular problem, I even ended up optimizing other parts of the code when debugging, how ironic is that...

Any ideas?

alvaroevc5
Posts: 69
Joined: 23 Apr 2014 07:32

Re: USB HID Volume Knob Strange Behaviour

#2 Post by alvaroevc5 » 18 Feb 2022 22:54

So, I don't know why I didn't think of this before, maybe you get so focused on the complex side of things that sometimes you don't see the easy stuff that is right on front of your nose...

I confirmed that the volume behavior is just like that on a computer, or at least on windows, it goes up slowly, and down faster.

How did I confirm this?
By using my keyboard volume keys.

When pressing the UP VOLUME key repeatedly and slowly, the volume goes up by increments of 2 units, when pressing the VOLUME DOWN key repeatedly and slowly, there is a point in which the volume goes down in bigger decrements and faster, as if "aiding" the user into lowering the volume, which seems to make sense, but makes it seem like there is something wrong with the knob, it makes me wish there was a way to avoid that, but that goes pretty deep into how the HID driver works on a PC.

My coding is perfect, or at least I can now have some peace of mind by thinking that. 8)

I was going to upload into this post two videos or GIFs demonstrating how it looked, but it seems like the option is not available, and uploading that somewhere else would mean the link dying in a few months or years.

Post Reply

Return to “mikroC PRO for PIC General”