Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

What's the simplest way to emulate the output of a rotary encoder?

Status
Not open for further replies.

jelliott

Member
Specifically, I'd like to be able to scroll through the menus of a car stereo using a discrete signal from a steering wheel control instead of turning the knob on the stereo. If I'm making the correct assumptions about how these things work, it's just a matter of switching two of the wires to ground in the right order--A before B is a clockwise increment of the knob and B before A is a counterclockwise increment, for example. But then I'd have to switch them open again in the same order or it will just step back one increment, right? Is there a simple circuit that will do this for me? (Or am I missing something more fundamental?)
 
A switch with a pull-up resistor feeding two cascaded resistor-capacitor (for delay / debounce) and schmitt inverter setups, plus a third inverter to correct the polarity. A 40106 or 47HC14 would be fine for the inverters.

The first R-C and schmitt will debounce the switch, then the second will duplicate the signal (inverted) but delayed by the R-C, then the third inverts that back to match the first output.

So you press the switch, a debounce delay then the first output goes high, then eg. a millisecond later the third output goes high.
Release the switch and the first then the third go back to low level, with the same delays.

Duplicate that for the other switch.

Then eg. diode-OR the two circuits together, but exchanging the first and third outputs. That gives high-going pulses.

Or if you need switching to ground to emulate the encoder, you could use two small signal MOSFETs on each circuit as low going switches, again the ones from 1 & 3 swapped to give both directions.

Or swap the switch to V+ and use a pulldown resistor, so the whole thing is inverted, and diode-or again but with cathodes to the inverter outputs rather than anodes - and probably schottky diodes, to get a good low logic level.

Edit - typo, should have been 40106.
 
Last edited:
Are the steering wheel signals from two push-button switches?
 
A switch with a pull-up resistor feeding two cascaded resistor-capacitor (for delay / debounce) and schmitt inverter setups, plus a third inverter to correct the polarity. A 40106 or 47HC14 would be fine for the inverters.

The first R-C and schmitt will debounce the switch, then the second will duplicate the signal (inverted) but delayed by the R-C, then the third inverts that back to match the first output.

So you press the switch, a debounce delay then the first output goes high, then eg. a millisecond later the third output goes high.
Release the switch and the first then the third go back to low level, with the same delays.

Duplicate that for the other switch.

Then eg. diode-OR the two circuits together, but exchanging the first and third outputs. That gives high-going pulses.

Or if you need switching to ground to emulate the encoder, you could use two small signal MOSFETs on each circuit as low going switches, again the ones from 1 & 3 swapped to give both directions.

Or swap the switch to V+ and use a pulldown resistor, so the whole thing is inverted, and diode-or again but with cathodes to the inverter outputs rather than anodes - and probably schottky diodes, to get a good low logic level.

Edit - typo, should have been 40106.
Thanks! I figured the answer would involve some sort of R-C timing scheme, but wouldn't have thought of going back and forth through a Schmitt inverter.

I definitely need switching to ground at the actual output (as that's how the stereo's knob is configured), and would prefer to configure my switch that way as well. So, if I understand correctly, that leads me to the MOSFET solution--although I might use tiny relays if I already have a couple lying around--any reason not to do that?

Bad news update: the knob on the stereo seemingly has twice as many detents as encoder increments, such that every other detent leaves both encoder signals grounded. :-( So if I go ahead and build this circuit anyway, it'll be a 50/50 chance that my parallel steering wheel controls won't work, depending on whether the knob was left in a 'closed' detent or an 'open' detent. Sad. (The circuit board in the stereo is all too tiny to try to modify anything anywhere upstream of the encoder itself; I'll take a closer look to see if maybe I can remove and reinstall the encoder with wires snaking out to a normally-closed relay, but I'm not optimistic.) This discovery also raises the possibility that the stereo's UI actually responds to half-increments from the encoder, such that the circuit proposed above would step through two menu items with every button push! Dang.
 
So what are the output signals from this stalk?
Whatever I want, but since all four motions of the stalk (four separate momentary switches) switch their respective terminals to a shared common terminal, I'd prefer to ground that common terminal. But if a workable solution to this challenge necessitates putting +12 V or +5 V (or something else) on it, I can certainly do that, since the common terminal is NOT shared with any of the other functions on the column switch assembly, thankfully.
 
This discovery also raises the possibility that the stereo's UI actually responds to half-increments from the encoder, such that the circuit proposed above would step through two menu items with every button push! Dang.
OK, another option is to use an up-down counter IC.
A 74HC193 would be suitable; debounce the switches with a single schmitt gate each and connect to the up and down inputs.

You need an XOR gate as well. Connect the inputs between Q0 and Q1; the output of that is "A" and Q1 is "B".
It will step though the four quadrature states one at a time with each button press.

You would need FETs (or optocouplers?) to link in to the encoder.
I'd not use relays, due to the timing and contact bounce etc.

A more sophisticated interface could be done using a small MCU, like an 8 pin PIC; you need four inputs and two outputs.
If it was possible to intercept the original encoder signals, the MCU could read both that and the two switch inputs and emulate the incrementing or decrementing count feed to the radio, regardless of which source they came from.
 
the knob on the stereo seemingly has twice as many detents as encoder increments, such that every other detent leaves both encoder signals grounded.
I would have described that as half as many detents as encoder increments.

With quadrature signals, there are several ways of counting what one pulse is. However the minimum increment is where one of the signals changes, and the other signal does not change at that time.

Eg:-
1) Off - Off
2) Off - On
3) On - On
4) On - Off

It seems to me that your stereo has detents that leaves the knob in positions 1 or 3 only.

One solution would be to have a light that tells you if you've left the knob in the "wrong" position, and they you could wire the circuit from in parallel with the existing encoder.
 
OK, another option is to use an up-down counter IC.
A 74HC193 would be suitable; debounce the switches with a single schmitt gate each and connect to the up and down inputs.

You need an XOR gate as well. Connect the inputs between Q0 and Q1; the output of that is "A" and Q1 is "B".
It will step though the four quadrature states one at a time with each button press.

You would need FETs (or optocouplers?) to link in to the encoder.
I'd not use relays, due to the timing and contact bounce etc.

A more sophisticated interface could be done using a small MCU, like an 8 pin PIC; you need four inputs and two outputs.
If it was possible to intercept the original encoder signals, the MCU could read both that and the two switch inputs and emulate the incrementing or decrementing count feed to the radio, regardless of which source they came from.
Is there any easy way to make the counter count two steps for each button press? (I was referring to an encoder step as one complete cycle, based on the nomenclature of a random datasheet [for a different encoder, obviously] that I had on hand but, to be clear, the encoder in question steps off/off, on/on, off/off, on/on, etc., such that I would want to change both signals with each button press.)

And the more I think about it, it probably doesn't make any sense to try and modify the encoder legs and snake normally-closed wires out of the head unit; even if we could devise a circuit to detect the current state of the encoder and then either open them in succession or ground them in succession, that would inevitably leave the knob inoperable any time I used the switch with an odd number of switch presses, right? But this might still be worth doing if it's just a 50/50 chance that the switch won't work and the knob has to me turned one detent to make it work again.
 
What is the make, model and year of the car?
1988 Porsche 928. (The column switch assembly with the extra stalk comes from an '89 with an LCD display in the dash for fault reporting, which my car obviously doesn't have; I bought the '89 column switch assembly just to pursue this idea of being able to manipulate the radio without taking my hands off the wheel.)

Is there any version of the car that has a remote input that allows the menus to be scrolled remotely?
No; the stereo is an aftermarket unit, and I'm too stubborn to go out and buy one that specifically provisions for remote control via steering wheel buttons. (The stereo in question in a pretty clever Porsche-branded one that supports Apple CarPlay in a 1-DIN package that still looks kinda-sorta-period-correct in an '80s car, so when I had an opportunity to buy one used for a fraction of the retail price, I decided I had to have it, even if it makes my clever remote-control idea with the '89 column switch difficult or impossible.)

I would have described that as half as many detents as encoder increments.

With quadrature signals, there are several ways of counting what one pulse is. However the minimum increment is where one of the signals changes, and the other signal does not change at that time.

Eg:-
1) Off - Off
2) Off - On
3) On - On
4) On - Off

It seems to me that your stereo has detents that leaves the knob in positions 1 or 3 only.

One solution would be to have a light that tells you if you've left the knob in the "wrong" position, and they you could wire the circuit from in parallel with the existing encoder.
Yes, thank you; the detents leave the encoder in what you describe as states 1 or 3. I was (naively?) hoping/expecting that every detent would leave the encoder in state 1 every time, based on a datasheet I had on hand for a different encoder.

I'm not sure I'd bother with a warning light, but I like the idea enough that it's probably worth provisioning for in the circuit design, and then I can install the light at a later date if the column stalk being unresponsive half the time becomes annoying! :)
 
Is there any easy way to make the counter count two steps for each button press?
Yes, I think so, but it's getting a bit more involved..

Use another XOR gate between the A & B outputs. The output of that will be high to indicate an intermediate step.

Add a set-reset latch with two cross-connected gates from a 4093, with the inputs from the switch signals to the counter. That will indicate the last step direction.

Make two schmitt R-C oscillators with two more 4093 sections, with the second input from the XOR output.
Connect diodes from the SR outputs to the oscillator caps, so a low level at the SR prevents the cap charging.

Add inverters to the outputs of the osc gates, so the signal is low when the osc is disabled.

Use the last two XOR gates in line with the counter inputs, after the SR inputs, and connect osc signals to the second inputs.

(I also forgot to mention in the previous one, the counter operation is rising edge so the count would occur when the switch is released. To have it work on press, you need a C-R differentiator plus a schmitt inverter after the debounce).

If that all works as I intend, given that I have not had my coffee yet this morning! --

Operate a switch, the counter input goes low then high - either switch press & release or the differentiator pulse when it's pressed.

The counter is then in an intermediate state, the output of the XOR between A & B goes high, whichever RC osc is not locked out by the diode from the SR latch starts to charge and after its delay the output from that via its inverter pulses high.

That inverts the output of the XOR in line with the appropriate counter input, adding a pulse & stepping the counter again.

As soon as the A & B match, that XOR output goes low and disables the oscillators again.

Four ICs? I've lost track of the number of inverters..

40106 for the debounce, differentiator and inverters.
74HC193 counter.
4093 for the SR latch and oscilators.
4070 for the XOR gates.
 
Yes, I think so, but it's getting a bit more involved..

Use another XOR gate between the A & B outputs. The output of that will be high to indicate an intermediate step.

Add a set-reset latch with two cross-connected gates from a 4093, with the inputs from the switch signals to the counter. That will indicate the last step direction.

Make two schmitt R-C oscillators with two more 4093 sections, with the second input from the XOR output.
Connect diodes from the SR outputs to the oscillator caps, so a low level at the SR prevents the cap charging.

Add inverters to the outputs of the osc gates, so the signal is low when the osc is disabled.

Use the last two XOR gates in line with the counter inputs, after the SR inputs, and connect osc signals to the second inputs.

(I also forgot to mention in the previous one, the counter operation is rising edge so the count would occur when the switch is released. To have it work on press, you need a C-R differentiator plus a schmitt inverter after the debounce).

If that all works as I intend, given that I have not had my coffee yet this morning! --

Operate a switch, the counter input goes low then high - either switch press & release or the differentiator pulse when it's pressed.

The counter is then in an intermediate state, the output of the XOR between A & B goes high, whichever RC osc is not locked out by the diode from the SR latch starts to charge and after its delay the output from that via its inverter pulses high.

That inverts the output of the XOR in line with the appropriate counter input, adding a pulse & stepping the counter again.

As soon as the A & B match, that XOR output goes low and disables the oscillators again.

Four ICs? I've lost track of the number of inverters..

40106 for the debounce, differentiator and inverters.
74HC193 counter.
4093 for the SR latch and oscilators.
4070 for the XOR gates.
Well, over the weekend I managed to further disassemble the face plate of the new radio, and confirmed that I can, in fact, solder wires to a couple of the tiny surface-mount buttons there (whereas previously I thought only the through-hole encoders were feasible to attach to), meaning I can at least answer a phone call and invoke Siri from the steering column with switched discretes rather than trying to emulate encoder increments. So now I'm torn--designing/building this circuit is sounding like somewhat more work/complexity than I bargained for (and will only work half the time, depending on knob position), but my new radio is very GUI/menu-centric (especially for utilizing Apple CarPlay).

So I went ahead and snaked a 6-conductor cable through the chassis of the radio an into the face plate assembly, even though my 'new' column switch stalk only gives me four circuits to play with--I'll initially hook it up to 1) Mute, 2) GUI selection button (knob press of the encoder discussed above), 3) Siri, and 4) Answer phone, with the long-term plan being to replace #3 and #4 with encoder incrementing inputs if I ever successfully design and fabricate the aforementioned circuit someday!

Thanks again for all your help! I'll probably be resurrecting this thread someday when I decide to take the plunge and actually design the aforementioned circuit, the complexity of which has already grown well beyond my (largely analog) abilities!
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top