rotary encoder usb audio volume control

Sub forums for various specialist XMOS applications. e.g. USB audio, motor control and robotics.
Junior Member
Posts: 7
Joined: Mon Dec 26, 2016 10:06 am

rotary encoder usb audio volume control

Postby diyinhk » Mon Dec 26, 2016 10:59 am

We are planning to start a project for rotary encoder volume control on the xmos usb audio to replace the default HID button volume control(tough and hard to use).

I need to know if xmos also have plan or is already working on something similar to avoid duplicate work. The ADC VR volume control is a big surprise when I notes it few year ago.

It will make use of QEI code xmos develop for robotics three year ago(seems retired?), the latest comment from the xmos qei sample code:
QEI server algorithm now uses regular sampling of QEI ports (i.e. NOT triggered by change on port). This is more robust to QEI noise.

To detect rotary encoder change, SELECT should not be used? or no problem to use due to manual turning encoder is much slower than motor?
Respected Member
Posts: 346
Joined: Wed Jan 27, 2016 5:21 pm

Postby henk » Tue Dec 27, 2016 12:05 pm


Rotary encoders are really easy to interface to an xCORE. I have used them in a few projects.

Put the rotary encoders on two bits of a four bit port, with pull-ups, and I think a small capacitor. Wherever you have a thread that looks at buttons in a big select statement, add a statement like

Code: Select all

   case p_rotary when pinsneq(p_rotary_value) :> p_rotary_new_value:
      int changed_bit = p_rotary_value ^ p_rotary_new_value;
      if (((changed_bit == ROT0_BIT) && (p_rotary_value & ROT1_BIT))|| 
          ((changed_bit == ROT1_BIT) && !(p_rotary_value & ROT0_BIT))) {
          // Went one way
       } else {
            // Went the other way
      p_rotary_value = p_rotary_new_value;
(from memory - remove any obvious syntax errors)

Not sure how much debounce you need; the rotary encoder may hesitate between two settings which may mean you get an 'LEFT RIGHT LEFT' sequence rather than just a single 'LEFT'; this won't matter for volume control, but may matter in other places.

You can add another rotary encoder on the same 4-bit port; and use more 4-bit ports if you need more encoders.


Who is online

Users browsing this forum: No registered users and 0 guests