5

I'm looking for a chip that has 16 inputs where if only one of the inputs go high then it encodes the data to a 4 bit output. If one doesn't exist what would be the simplest way to build such a circuit?

Chris Stratton
  • 33,491
  • 3
  • 44
  • 90
David
  • 187
  • 1
  • 6
  • you have to invert for active low encoders but what state defines all off? Therefore you need to define an extra output. 8 bit priority encoder is the primitve choice – Tony Stewart EE75 Sep 02 '17 at 20:36
  • 2
    What operating speed do you need, and what is it for? – Bruce Abbott Sep 02 '17 at 21:46
  • I'm experimenting with window comparators and analog-to-digital conversion or direct-conversion ADC. – David Sep 02 '17 at 22:17
  • In that case, priority encoders and simple comparators may make life simpler : only the highest active input is encoded, no need for window comparison –  Sep 03 '17 at 08:51
  • @AssadEbrahim. Your erroneous edit has been rolled back. The correct term is in fact "one-hot" not "one-shot" - only the first term can even be applied to a combinatorial circuit, the second applies to only to a stateful circuit such as a pulse generator. – Chris Stratton Sep 07 '20 at 04:18
  • @voltagespike please do not approve edits which introduce gross technical errors – Chris Stratton Sep 07 '20 at 04:20
  • @ChrisStratton - thanks for pointing out the distinction - one-hot – Assad Ebrahim Sep 07 '20 at 06:10

3 Answers3

10

The function you are looking for is normally referred to as a Priority Encoder.

A priority encoder can cope with more than one signal being active and still give the correct result for the highest numbered active input. If your system can guarantee that one and one input only will be active you can use a simpler solution as suggested by Dave Tweed in the comments, however such solutions can give a completely incorrect result if two or more inputs are active.

As far as I know there has never been an off-the-shelf device to implement a 16-input priority encoder.

An 8-bit version has been around for many years. One of the current versions is SN74HC148.

@Marku points out that the data sheet (link above) has a 16-bit example using two such devices together with 4x 2-input AND gates requiring three packages in total.

These days it is more common to implement functionality like this either in software within a microcontroller or in programmable hardware in Verilog/VHDL.

Can you describe your system in more detail to see which solution would fit better?

Kevin White
  • 33,153
  • 1
  • 48
  • 78
  • The logic for combining two 74HC148's into a 16-bit priority encoder is shown in Figure 2 in the linked datasheet. – MarkU Sep 02 '17 at 20:37
  • @MarkU - thanks. I didn't notice that. – Kevin White Sep 02 '17 at 20:39
  • 4
    Note that the OP is not actually asking for a priority encoder. If you can guarantee that only one input is active at a time, all you need is four 8-input OR gates to encode it as a binary number, plus one more 5-input OR gate to provide a "valid" output strobe. – Dave Tweed Sep 02 '17 at 20:50
  • @DaveTweed - True – Kevin White Sep 02 '17 at 20:54
  • @AssadEbrahim please do not make such pointless edits! All you've really done is replaced the authors style with your own, to no improvement whatsoever. – Chris Stratton Sep 07 '20 at 04:23
  • 1
    @assadebrahim fortunately you did not include that in your edit, as you are mistaken about it. If you note the inverted inputs on the NOR/OR function symbols and take time to understand DeMorgan's theorem you will see that the first data sheet example uses what are commonly known and sold as AND gates and the second NAND. The part numbers given are correct for those functions, your suggested change to a '32 would be wrong. Please delete your erroneous comments. – Chris Stratton Sep 07 '20 at 12:17
  • @ChrisStratton - True. I didn't notice that. Both comments removed. Thanks for the explanation. – Assad Ebrahim Sep 08 '20 at 06:00
3

I don't know whether such a device exists, but:

Approaches in lieu of a 16x "one hot" -> 4 bit output IC

Serialize, count clocks until the 1 appears

  1. Use a parallel-to-serial shift register(s) to convert your one-hot to a sequence of 15 zeros and 1 one in the right place. Clock that shift register and feed its output into
  2. a 4 bit or more (you'll probably find 8 bit) counter with parallel output that you clock with the same clock, but latch on the data input

Programmable logic

Your problem might very well cheapest be solved with a CPLD or even a GAL

Memory IC

Use Memory IC with parallel address bus and parallel data output bus. Example IC

Simply store right 4-bit value at right 16bit address

ROM in diode logic

You can basically do a lookup table matrix in PCB traces. Will require lots of discrete diodes (4 output bits being ORs of 8 input bits, each, so 32 if my math is right). But it's "logically" easy.

Assume you have an 8-input "OR" gate (that would be 8 diodes with a common cathode). Then, the highest output would be "Is it any of the second half of inputs", right? So, you just connect that OR to these. Similarly, your lowest output would be "any of every other input", so you connect these to another 8xOR gate.

Fun fact: there's 8-diode common-cathode components, and they're pretty cheap! Just use TVS clamping diode arrays (example) and an elegant PCB layout. If your input voltages aren't higher than the TVS' clamping voltage, you'll have to go for 8 quad common-cathode diode arrays.

ROM using discrete gates

Same as above, but use ready (probably 74-series) logic gates (ORs, or actually just buffers with output resistors).

Resistor ladder DAC + parallel output ADC

Assuming constant voltage inputs: build a resistor ladder:

schematic

simulate this circuit – Schematic created using CircuitLab

Hint: there's resistor networks (many resistors in the same package) that make this less of a pain to solder.

Vout is proportional to the input that is currently hot.

Use an ADC with a parallel output to read that out.

Strangly, this might be a relatively simple and cheap approach, considering 8-bit parallel-out ADCs are readily available and not that expensive.

Marcus Müller
  • 94,373
  • 5
  • 139
  • 252
  • The resistor and ADC solution is often used in cars to communicate between the steering wheel controls and the rest of the car because the steering wheel rotates. It automatically gives the highest priority result as in the example In16 will override all the others. – Kevin White Sep 03 '17 at 15:15
0

Here is my 2xCD4532 and 1xCD4071 solution.

enter image description here

Roman
  • 291
  • 5
  • 12