Encoders: which line is active?
An encoder is a decoder in reverse: many input lines in, the binary number of the active one out. Priority decides when several are active.
What an encoder does
Octal to binary: one of eight inputs active gives its 3 bit number.
Decimal to BCD: a key of a keypad gives its BCD code.
Keyboards, interrupt requests to a CPU, data compression.
Priority
A plain encoder assumes only one input is active. If two keys are pressed together, OR gates give a wrong code (3 and 4 together read as 7). A priority encoder outputs the code of the highest active input and ignores the others, and it has an extra output that says whether any input is active at all.
The 74148
Highest LOW input is 5: A2 A1 A0 = 010, the inverse of 101.
Hold the chip with its notch on the left. Pin 1 is at the bottom left, the pins count up to the right, then continue along the top from right to left. Most 14 pin chips have VCC on pin 14 and GND on pin 7, but not all: check every new chip.
Everything on the 74148 is active LOW: an input is active at 0, and A2 A1 A0 give the inverted code. EI must be LOW to enable it. GS is LOW when any input is active; EO is LOW when the chip is enabled but no input is active, to enable a second chip in a cascade.
Designing the 4 x 2 encoder
Inputs I3 (highest) to I0, outputs Y1 Y0. Y1 = 1 for codes 2 and 3: Y1 = I3 + I2. Y0 = 1 for code 3, or for code 1 when I2 is not active: Y0 = I3 + I1 I2'. I0 never changes the outputs.
Octal to binary with OR gates
Check yourself
Q1On the 74148, inputs 2 and 5 are LOW. What are A2 A1 A0?
010: the code of 5 (101) inverted.
Q2What does EI = 1 do?
Disables the 74148: all outputs go HIGH.
Q3Why does a simple OR gate encoder fail with two inputs active?
It ORs both codes: 3 and 4 together give 111 = 7.
Q4In the 4 x 2 priority encoder, why is I0 not in any expression?
When it is the only active input the code is 00, the same as no input.