An encoder turns the active one of many inputs into binary, and a priority encoder honors only the highest priority. This page explains the principle and 74LS148 use.
A normal encoder has 2 to the n inputs and n outputs, allowing only one input active at a time and outputting its binary code; an 8 to 3 encoder turns active line 5 into 101. If several go active it errors, so inputs must be mutually exclusive. Used for keyboard scan and position coding, compressing state into compact binary.
A priority encoder like 74LS148 allows several inputs active and responds only to the highest priority (usually smallest or largest number), outputting its code plus a GS (group select) valid flag. This solves which of many interrupt sources to serve first by hardware arbitration; software reads the code to know who. The EI enable cascades to expand lines.
| Type | Multi active | Output |
|---|---|---|
| Normal | errors | its code |
| Priority | top priority | plus GS |
| 74LS148 | 8 in 3 out | low inv code |
| EI | cascade en | expand |
| Use | key int | arbitrate |
| Trap | forget GS | false none |
A normal encoder needs exclusive inputs; a priority encoder like 74LS148 takes the highest priority and gives a GS flag. Use priority for interrupt arbitration and read GS before trusting the code; note the output is often low true inverted and EI cascades one way.
The quantities and component characteristics discussed here follow current national standards and the corresponding IEC documents: Encoding and interrupt per GB/T 4728; control to GB/T 5226.1 and IEC 60204-1. Always check the device datasheet and the product design file for ratings and derating.
Locate the issue with the approach above, then confirm with measurements; safety-related circuits must follow the standards and manufacturer requirements.