Electronic – Rotary switch that changes resistance on each click

automotiverotarysound

I am trying to create controller for my car head unit as it lacks a volume knob amongst other things.

I have worked out that when tapping onto the control pin I can "send" commands by applying a resistor of specific value between two pins:

  • 1000Ω = Volume up
  • 3300Ω = Volume down

I can achieve this using a button or switch method simply by putting the resistors on those items however I would like to create a volume "knob".

Is a rotary encoder the thing I will need here? Could somebody provide a little more direction on how to achieve the above functionality? As it will need to change the resistance each click yet reset it before the next click, it will also need to continue to spin rather than reach a limit.

Picture (may help)
wiring

Thanks again

Best Answer

It is possible with an incremental encoder, a D flip-flop, two mosfets and a few passives.

An incremental encoder will give you pulses for each "click". There are two out-of-phase pulse outputs, so that you can guess the direction in which the encoder is turned:

enter image description here

(the "D" dashed line is when the detent happen on the knob)

You see that when the knob is turned clockwise, the rising edge of the B signal will happen while the A signal is high. When turning couter-clockwise, the rising edge of the B signal will happen while the A signal is low (read the above timing diagram respectively from right to left or from left to right). This is the principle.

Therefore, using a simple D flip-flop, you can register the direction is which the knob is turned. Wiring one of the encoder output to the D input, and the other to the CLK input, the flip-flop will have its output kept at 1 if the knob is turned clockwise, and 0 if it was turned counter-clockwise. You can also use the CLK pulses to trigger the required action for each click.

As we now have a signal indicating the direction and a signal indicating the click action, it is just a matter of correctly triggering a combination of resistors and fets to connect the appropriate resistors. Basically, when a click occurs, a 3.3k resistor must be connected between your two pins, and, if the direction was clockwise, we add a 1.5k resistor in parallel so the total equivalent resistance is roughly 1k, as per the spec.

Here is a basic schematic (assuming pin 23 is a common ground, that a 3.3V to 5V supply is available, and that pin 21 is not below the ground potential):

schematic

simulate this circuit – Schematic created using CircuitLab

You need R1 and R2 to pull down the encoder output signals. Also, even if it is not shown, you'll need some decoupling capacitor across the D flip-flop supplies (100nF is typically fine)

The choice of the D flip-flop is up to you. 74LVC1G79 is a perfect fit, but it is tiny (hard to solder by hand, and inappropriate for a breadboard). You could use a 74HC74, CD4013, etc... Be sure to read the datasheet and appropriately connect the unused inputs (set/reset) to the inactive level. Also check that your available supply is within the recommended supply voltage range of the component you choose.