Looking for a component : 16 asynchronous inputs to 4 bits binary/grey code

Hello, I am looking for a electronic component, and, not being an electronician myself, I happend not to be able to find even if it exists or how it could be named.

But first, here is what I want to achieve :

I have a non-shorting rotary switch with 1 pole and 12 outputs. Like this one.

I am looking for a simple, 'low-tech' way to get which pole output is active, without using 12 digital inputs on my arduino. I am using arduino with johnny-five.

Here is the solution I am thinking about :

I was thinking that I could simply wire the switch outputs, using diods, to output four bits that I could connect to 4 digital inputs on the arduino board.

Like this :

But there may be a electronic component that can do that and spare me the hasle to make a PCB and solder dozens of diods on it. A component that have 12 or more (16 ?) inputs that can't be simultaneous, and output some binary or grey code on 4 outputs.

Does it exist ? Does it have a name ? I searched and cannot find something.

Thanks a lot,

leo

P.-S. : my first language is not english, and I never had a course in electronics, so please excuse my non-fluency in these two languages !

deleted:
I have a non-shorting rotary switch with 1 pole and 12 outputs. Like this one.

I am looking for a simple, 'low-tech' way to get which pole is active, without using 12 digital inputs on my arduino. I am using arduino with johnny-five.

So, you mentioned you have a rotary switch, with one pole, and 12 outputs. Could you please explain what you mean by 'which pole is active'? You mentioned 1 pole to begin with......but then there is some kind of contradiction about 'which pole is active'.

Also ...... 16 (assumed digital) inputs .... means 2^16 possible input states. And 4 (digital) outputs means 2^4 possible output states. So there is a big mismatch here (unless some sort of rounding is done to convert 16 bit to 4 bit) ...... but it's possible that I'm not understanding something correctly about what you're trying to do here.

Thanks for your answer, I'm going to try to clarify. Not being working in the fields of electronics nor having studied electronics, I might use the incorrect terms more than I should.

Here is a picture of the rotary switch from the data-sheet linked before :

So there is one 'pole' (A) which is always connected to only one of the outputs.

What I want to know is to which output (not pole, my mistake).

As the pole is only connected to one output at a time, there is only 12 possibilities, as there is twelve outputs.

So I was thinking to use diods to output a 4 bits binary code. and I m wondering if there is some existing component that could achieve that.

Hope that helps.

Google "BCD encoder".

You can also change the switch into a stepped pot with resistors, and read that with one analogue input.
Google "Arduino resistor ladder" (images).
Leo..

A simple way enclosed.

Allan

answ.pdf (18.5 KB)

I thought about using analog in, but I want to avoid to use those inputs, as I might need them. (Also, my question would be quite similar : is there a component that do this to spare me some soldering ?)

I tried to look for BCD encoder, but I only found rotary switches with embeded encoders during my previous search on a supplier database.

I now find what seems to be called "10-to-4 Line Priority Encoder". But what I would need is at least '12-to-4 line'. This do not seems to be common. I am reading that cascading two 8 input priority encoder could do the work, but I need to read/search more.

Are you so desperate for pins that you can't spare ONE analog input?

Any digital approach will use many more - eg shift registers or data selectors using eg I2C...

Allan

I may or may not be short on analog pins. Those rotary switches will often be used along potentiometers and other components outputing an analog signal, and there will often be multiple analog device and only one rotary switch, so an analog solution does not seems to be a viable solution for me. Using more digital inputs pin is less problematic.

It is quite late where I am, but this topic seems to provide some valuable information I will review tomorrow.

I want to avoid to use those inputs, as I might need them

You might need a bunch of digital inputs, too. The resistor ladder is simple, quick and works well with one analog input. Problem solved.

jremington:
You might need a bunch of digital inputs, too. The resistor ladder is simple, quick and works well with one analog input. Problem solved.

Sure, there might be cases where I need more digital inputs. But for the moments, the only cases I had to switch from a uno to a mega were because I runned out of analog inputs. Therefore, I am looking for something else than a resistor ladder.

Note that if you know the reference of an out-of-the box resistor-ladder component, I am interested too. If it does not exist I might try to prototype a PCB for that (but maybe something that can handle simultaneous inputs).

Just solder the resistors across the switch.

Allan

This statement is totally not correct:
"So there is one 'pole' (A) which is always connected to only one of the outputs.".

As you move the switch from one position to the other, you will have a time period when NO connection is made to any pole. There is another type of switch that shorts the old pole to the new as the switch is moved, and then opens to old connection. The first is called "break-before-make" and is the most common, probably what you have.

Check with an ohmmeter.

Paul

deleted (or.... 'the one who can't be named') ..... will that rotary switch be connected to the arduino only? That is, the switch won't be used directly to control or switch other electronic components on or off right?

If that's the case, then allanhurst's technique looks quite good.

Could also use some kind of self-designed (or somebody-designed) logic circuit that has 16 separate inputs (voltages), and normalises them to 1 volt (or whatever). Normally, only 1 of the 16 pins will be high. Or, perhaps, there might even be one case where all those pins could be 'low' (for the case where the pole contact is not touching any of the outputs). So that could be 16 states, plus maybe 1 extra one.... 17 states at least.

So need a logic circuit that takes 16 inputs and maybe have 5 parallel bit outputs. So inputs of:
0000000000000001 translates to 00001
0000000000000010 translates to 00011
0000000000000100 translates to 00010
0000000000001000 translates to 00110
0000000000010000 translates to 00111 etc.

An FPGA could handle this easily.

I think I'd go for Allan's method. Should be much easier.

deleted:
...the only cases I had to switch from a uno to a mega were because I runned out of analog inputs.

Many ways to skin that cat.

An Uno and one 74HC4051 breakout board gives you 13 analogue inputs, at the cost of three digital inputs.
An Uno and one 74HC4067 breakout board gives you 21 analogue inputs, at the cost of four digital inputs.
An Uno and six 74HC4067 breakout boards gives you 96 analogue inputs, at the cost of four digital inputs.

An 16-channel I2C port expander can read your 12-position switch at the cost of two I2C pins.
You can have a whole bunch of port expanders connected to those two I2C pins.

Leo..

I now find what seems to be called "10-to-4 Line Priority Encoder"

Yes, that would be the chip you're looking for. There are (I think) well-documented methods of combining a couple of 8-to-3 line encoders" into a 16-to-4 line encoder, but of course that increases complexity. Most current logic families will require pull-up resistors with the type of switch you have, and that adds complexity too.
Your diode plan (or something similar) would also work.
See Encoders and Decoders
Depending on where you live and where you are able to shop, the best idea might be to throw a additional arduino-class microcontroller at the problem. ATmega8 chips can be had for under $1, have built-in pull-up resistors, and would convert your 12-pole switch to a single bit (serial) output with no problem (and still have room and pins to do more stuff)
(I ran into a similar situation trying to find 4bit hexadecimal to 7segment decoders...)

This link here shows how to get a 16:4 priority encoder...

See figure 2 in that file. But make sure to check out the note about transients.

Paul_KD7HB:
This statement is totally not correct:
"So there is one 'pole' (A) which is always connected to only one of the outputs.".

(...)

That's true. As stated, it's a non-shorting switch, So there also will be a short moment where the pole will be connected to nothing. So I shouldn't encode the first output as 0000, as it will be the binary code when the pole is connected to nothing. Didn't think to that prior to reading your post.

Southpark:
will that rotary switch be connected to the arduino only? That is, the switch won't be used directly to control or switch other electronic components on or off right?

I guess 99% of the time it will be connected directly to the arduino.

Southpark:
If that's the case, then allanhurst's technique looks quite good.

It is. But I did not look for an analog solution because, as stated before, it doesn't match my needs.

Southpark:
FPGA could handle this easily.

I'll read about this, looks interesting.

Southpark:
I think I'd go for Allan's method. Should be much easier.

I'd love to be able to use analog inputs ! Sadly I'm usually short on those so I cannot consider to use more of them !

Wawa:
Many ways to skin that cat.

An Uno and one 74HC4051 breakout board gives you 13 analogue inputs, at the cost of three digital inputs.
An Uno and one 74HC4067 breakout board gives you 21 analogue inputs, at the cost of four digital inputs.
An Uno and six 74HC4067 breakout boards gives you 96 analogue inputs, at the cost of four digital inputs.

An 16-channel I2C port expander can read your 12-position switch at the cost of two I2C pins.
You can have a whole bunch of port expanders connected to those two I2C pins.
Gammon Forum : Electronics : Microprocessors : Buttons, I2C, interrupts and port-expanders
Leo..

Yes, It is the first solution I though of. As stated before, I use Johnny-Five (arduino+firmata+nodejs), and sadly, johnny-five does not offer support of 74HC40xx as input at the time.

Also, I want to stay way from i2c etc... What I want to achieve is to have some 'out-of-the box' very simple modules that can be used to build interfaces in a course that is not about electronics so I do not want to add too much complexity.

westfw:
Yes, that would be the chip you're looking for. There are (I think) well-documented methods of combining a couple of 8-to-3 line encoders" into a 16-to-4 line encoder, but of course that increases complexity. Most current logic families will require pull-up resistors with the type of switch you have, and that adds complexity too.
Your diode plan (or something similar) would also work.
See Encoders and Decoders
Depending on where you live and where you are able to shop, the best idea might be to throw a additional arduino-class microcontroller at the problem. ATmega8 chips can be had for under $1, have built-in pull-up resistors, and would convert your 12-pole switch to a single bit (serial) output with no problem (and still have room and pins to do more stuff)
(I ran into a similar situation trying to find 4bit hexadecimal to 7segment decoders...)

The ATmega solution is interesting ! Need to educate myself about this but could be a solution and a tool to solve other problems !