Encoders and the 74148 Priority Encoder
Learn how encoders and priority encoders work. See the 74148 inputs, active low outputs, the GS and EO signals, and how to cascade two chips to encode 16 lines.
The opposite of a decoder
An encoder has many input lines and a few output lines. When one input line becomes active, the outputs show its number in binary. An 8 to 3 encoder has eight inputs, numbered 0 to 7, and a 3 bit output. If input 5 is active, the output is 101.
An encoder is used to turn a set of buttons into a code. A keypad, a row of sensors and an interrupt request system all have many lines that must be reported as a number.
The problem with a simple encoder
A plain encoder assumes that only one input is active at a time. If two are active at once, the output is wrong, because the code bits of the two inputs are mixed together. For example, if inputs 3 (011) and 4 (100) are both active, the output might be 111, which is neither of them.
It also cannot tell the case where input 0 is active from the case where nothing is active, since both give 000.
Priority encoding
A priority encoder solves the first problem. It gives each input a rank. If several inputs are active, the output shows only the one with the highest priority. In the 74148, input 7 has the highest priority and input 0 the lowest. If inputs 2, 5 and 3 are all active, the output is the code of 5.
This is exactly what is needed for interrupts in a computer, where many devices can ask for service at the same time and the most urgent must be served first.
The 74148
The 74148 is an 8 to 3 priority encoder with the supply on pin 16 and ground on pin 8. Its inputs 0 to 7 are active low. The outputs A0, A1 and A2 are also active low, so the code appears inverted. It has three further pins: the enable input EI, the enable output EO and the group signal GS. All three are active low.
| Active input (low) | A2 A1 A0 | Code shown | GS | EO |
|---|---|---|---|---|
| none | 1 1 1 | none | high | low |
| 0 only | 1 1 1 | 0 | low | high |
| 3 (highest) | 1 0 0 | 3 | low | high |
| 5 (highest) | 0 1 0 | 5 | low | high |
| 7 (highest) | 0 0 0 | 7 | low | high |
Because the outputs are active low, the code for 5 (101) appears as 010, the complement. Invert it with three NOT gates if you need the true code. Notice the first two rows. Both show 111 on the outputs. The GS pin tells them apart: it goes low whenever any input is active, and stays high when none is.
The enable pins
EI is the enable input. With EI high, the chip is disabled and all outputs are high. EO is the enable output. It goes low only when the chip is enabled and no input is active, which means that this chip has nothing to report. This is a signal for the next chip in a cascade.
Cascading two chips for 16 inputs
- Use one chip for inputs 8 to 15, which is the higher group, and one for inputs 0 to 7.
- Connect EO of the higher chip to EI of the lower chip. The lower chip is then enabled only when the higher chip has no active input.
- Enable the higher chip by tying its EI low.
- The fourth code bit is the GS output of the higher chip, inverted. The lower three code bits come from combining the matching outputs of the two chips with AND gates, because a chip with nothing to report leaves its outputs high. The combined result is still active low.
This works because the higher chip blocks the lower one while it has something to report, so the highest priority input wins across all 16 lines.
Testing on a bench
Connect switches to the inputs through pull up wiring so that an unpressed input is high. Pull an input low to make it active. Press two switches at the same time and confirm that the higher one wins. Read the outputs with LEDs, remembering that a lit LED on an active low output means logic 0.
Try it in the virtual lab
SinBench has free 3D benches and interactive demos for this topic. Open one to try the ideas above with real instruments, no sign up needed.
Questions and answers
What is a priority encoder?
It is an encoder that gives the code of the highest priority input when several inputs are active at the same time.
Why are the 74148 outputs inverted?
The chip uses active low inputs and outputs. The code appears complemented, so input 5 gives 010. Add inverters if you need the true code.
What does the GS pin tell you?
GS goes low when at least one input is active. It separates the case of input 0 active from the case of no input active.
How do you cascade two 74148 chips?
Connect EO of the higher priority chip to EI of the lower one, so the lower chip is enabled only when the higher chip has nothing to report.
Related topics
3-to-8 Line Decoder: How the 74138 Works
Learn how a 3 to 8 line decoder works, the 74138 enable pins and active low outputs, how to build any function from minterms, and expand to 4 to 16 lines.
Digital Logic DesignMultiplexer and Demultiplexer: The 74151 and 74138
Learn how a multiplexer selects one of many inputs, how the 74151 works, how to build a Boolean function with it, and how a demultiplexer sends data out.
Digital Logic DesignLogic Gates and Truth Tables: AND, OR, NOT, NAND, NOR, XOR
Learn the seven basic logic gates with truth tables, symbols and expressions, the common TTL chips that hold them and how to read a gate level circuit.