What is an Encoder and Decoder? Working, Differences and Applications?

Summary
Digital systems commonly need to shrink many signals into one short code. Then the code must be turned back again. This guide explains what is encoder and decoder are in plain words. It covers how does an encoder work and how does a decoder work, with simple truth tables. It also shows the difference between encoder and decoder circuits. Real encoder decoder examples come from keypads, memory chips and Industrial Automation. Each part is kept short and simple.
Key Takeaways
- Encoders convert multiple input signals into compact binary codes, while decoders transform binary codes into corresponding output signals.
- Basic encoders require one active input, whereas priority encoders resolve conflicts when multiple inputs become active simultaneously.
- Encoders primarily use OR gates, while decoders use AND gates and inverters to identify specific input combinations.
- Common encoder applications include keypad scanning, motor feedback, industrial automation, interrupt handling, and high-speed data acquisition systems.
- Decoders support memory addressing, chip selection, seven-segment displays, communication receivers, and microprocessor instruction execution.
- Selecting suitable circuits requires considering input and output lines, priority handling, logic family, operating speed, and application requirements.
Introduction
Keypads, switches and sensors generate a large number of individual signals. The processor selects a short code; there must be something in between the two, and this is the role of the encoder. On the other side, a different circuit carries out the opposite function and is referred to as a decoder. Thus, an explanation of what encoder and decoder logic is and why both are needed. The difference between an encoder and a decoder becomes clear when the two are viewed as mirror images. For instance, a keyboard having 64 keys would be inefficient if it had 64 wires leading to a chip; a 6-bit code could produce the same result. The following sections describe each device and indicate where each one is used.
What is an Encoder
The usual method of defining an encoder and a decoder starts with the encoder. An encoder is a kind of logic circuit with 2^n input lines and n output lines; only one input should be active at any given time, the output showing which one it is. For example, a 4-to-2 encoder has inputs marked D0 to D3; in the case where D2 is active the output will be 10. The circuit is made up using OR gates. Several actual integrated circuits are priority encoders, these being devices which, when two inputs are active, select the one with the higher priority. The 74148 is a typical example of an 8-to-3 priority encoder. A rotary encoder operates on the same principle, the only difference being that it sends a signal showing the position of the shaft rather than indicating a key has been pressed.
What is Decoder
There is a second section dealing with the encoder and decoder. A decoder takes an n-bit code and switches on one of the 2^n output lines; for instance, a 2-to-4 decoder has two inputs and four outputs, and a 3-to-8 integrated circuit such as the 74138 has three inputs and eight outputs. Inside the chip, AND gates and inverters examine each code in turn. Most of the chips also have enable inputs, which allow two small decoders to be combined in order to form a larger one. The fact which many people do not realise is that each output corresponds to one minterm; this is the reason why a decoder is useful when constructing custom logic.
How Does an Encoder Work
If you want to understand how does an encoder work, you start by using a truth table because each input line corresponds to a single binary pattern and the output gates collect all the inputs which have a 1 in a specific bit position; the two types that are of practical relevance are the basic encoder and the priority encoder, while rotary types add motion to the situation.
Basic Digital Encoder Logic
Let us take the case of an 8-to-3 encoder. A0 is the OR of D1, D3, D5 and D7; A1 is the OR of D2, D3, D6 and D7; and A2 is the OR of D4 through to D7. If D5 goes high the output will be 101. The circuit works on the basis that only one input is active; if two of the inputs rise at the same time then the output code will be wrong. Because of this the simple form is appropriate for use with controlled sources, for example a single selector switch.
Priority Encoder Operation
An priority encoder arranges its inputs in such a way that the line which is most strongly driven has priority, even if some of the other lines are also at a high level; it also gives a valid signal showing that at least one of the inputs is active. It has an enable output which allows the chips to be linked together in a chain and thus removes the need to guess in the simple case. Interrupt controllers apply this principle by ranking the requests from a number of devices and then causing the processor to deal with the most urgent one first.
Rotary and Position Encoders
A slotted disc causes the light beam to be interrupted as the disc rotates and this action is used by a rotary encoder to generate pulses. The two channels, A and B, are 90 degrees apart and this difference indicates the direction of rotation. Most models generate between 100 and 10,000 pulses per revolution. Absolute types send a special Grey code for each angle with only one bit changing at a time, which in this way reduces reading errors and it is possible to determine the position even after a power loss.
How Does a Decoder Work
The main thing to know about how does a decoder work is concerned with AND logic; each output gate is designed to respond to one particular input combination and only that gate generates a true signal. Inverters are employed in order to produce the inverted inputs. The result is one active line for each code. Three examples are given to illustrate the idea.
Binary Decoding with AND Gates
Take a 2-to-4 decoder with inputs A and B. Output Y0 equals A′B′. Y1 equals A′B. Y2 equals AB′. Y3 equals AB. An input of 10 therefore lights only Y2. Many chips use active-low outputs. The chosen line drops to 0 V while the others stay high. The datasheet states which level is used. Checking it early avoids wiring mistakes.
Enable Lines and Cascading
Switches for enabling the inputs turn the entire decoder on or off; a 74138 has three such switches, two of which are active low and one is active high; the chip only responds when all three conditions are satisfied; by connecting the most significant address bit to these pins, two 3-to-8 chips can share a 4-bit address; the same method can be used to build larger memory maps; it also supplies the chip select lines on a processor board.
BCD to Seven-Segment Decoding
A decoder of type BCD, for example the 7447, converts a 4-bit digit into signals for each of the seven segments; the segments are designated a to g. When the input is 0101, the result is the digit five, this causing the a, c, d, f and g segments to light up. A resistor is required for each segment. The current needed is typically between 10 mA and 20 mA. Inputs higher than 1001 produce either a blank display or an odd pattern. Meters and clocks make use of this stage.
Difference Between Encoder and Decoder
A side-by-side view clears up most doubts. The encoder vs decoder comparison covers direction, pin counts, gate type and role. Each point below ties back to how the two chips sit in a real circuit.
Function and Signal Direction
An encoder takes many lines and converts them into a short code, while a decoder takes that short code and reconstructs it into many lines. One collects information and the other distributes it. In a data path they function as a pair. The encoder is located at the point of transmission and the decoder at the point of reception. Together they are able to reproduce the original single choice without any loss.
Inputs, Outputs and Logic Structure
The encoder and decoder difference in structure is easy to see. An encoder has 2^n inputs and n outputs. It is built mostly from OR gates. A decoder has n inputs and 2^n outputs. It uses AND gates and inverters. Encoders may need priority logic. Decoders may need enable lines. A 3-to-8 decoder cannot act as an encoder by swapping pins. The inner gating is different.
Typical Use in a System
Encoders convert actual events into data; examples include key presses, changes in switch positions and variations in shaft angle. Decoders take data and carry out actions; they select a memory chip, enable a port or illuminate a digit. Both types of circuit are combinational, the output changing only when the input changes and with no clock signal or stored state being involved. The difference between encoder and decoder therefore lies more in their function than in their speed.
Encoder Applications
Encoders collect facts from the physical world. They suit keypads, motors and data converters. The main encoder and decoder applications on the sending side fall into three groups, and each one uses the same compression idea.
Keypad and Keyboard Scanning
A matrix keypad employs an encoder in order to convert activity in the rows and columns into a key code; a keypad with 16 keys only requires a 4-bit output which thus saves 12 lines. Debounce circuits remove the contact bounce which lasts between 5 and 20 milliseconds. Priority logic prevents a false code being produced when two keys are pressed at the same time. Calculators, remote controls and control panels all make use of this method.
Motion Control in Industrial Automation
In the field of industrial automation, rotary and linear encoders transmit information about position and speed to servo drives, and this applies also to CNC machines and conveyors. Incremental encoders count pulses, while absolute encoders provide the exact position upon power-up, usually with a resolution of 12 to 24 bits. The drive then makes corrections for any errors in less than a microsecond. The types of connections commonly used are quadrature, SSI and fieldbus. Accurate feedback ensures that the machines stay on target.
Interrupt Handling and Data Acquisition
Priority encoders are included in interrupt controllers. Since numerous devices request attention simultaneously, the processor has to select the most urgent one. Flash converters also make use of an encoder. A 3-bit flash converter has seven comparators and the encoder converts the outputs of these comparators into a 3-bit result. This process takes place at a very high speed, a feature that is suitable for video and radar signals.
Decoder Applications
Decoders convert codes into choices and are used by almost every computer and display. Examples of encoder decoder circuits on this side are those used for memory selection, for displays and for control logic. In these applications the focus is on addressing and control not on measurement.
Memory Addressing and Chip Select
The processor puts an address on the bus, and the decoders decide which chip will respond. The higher-order address bits can select one of eight devices using a 3-to-8 decoder. Within the memory arrays, both row and column decoders pick out one cell from among millions. Otherwise, two devices would respond simultaneously. This kind of conflict is known as bus contention and it can corrupt the data.
Display and Indicator Driving
Seven-segment decoders convert BCD figures into digits that can be read. They are used every day in meters, clocks and counters. When multiplexed displays are employed, a decoder is used to activate one digit at a time. Since the refresh rate is over 100 Hz, the eye perceives the image as steady. Displays of the common-anode and common-cathode types require that the output polarity matches that of the display; if the wrong type is used then the result is a dark or dim display.
Communication and Control Logic
Receivers translate the incoming codes back into data or commands; Manchester decoding is a case in point. Control panels make use of decoders in order to send a command to one of a number of relays or contactors. Within a microprocessor the instruction decoder reads the opcode and then activates the sections required to carry out the instruction. Each step in a programme goes through this stage.
Conclusion
The way encoder circuits differ from decoder circuits is in the direction they take. Encoders have the function of compressing data while decoders serve to expand it; together they transfer information between inputs, processors, and outputs. Encoder and decoder applications include keypads, memory maps, and motor feedback. The choice of component is determined by the number of lines, the way priority is handled, the logic family, and the speed. For sensors, control gear and panel components used in automation, Schneider Electric eShop provides a wide variety of electrical products.
FAQs
1. Does the encoder and decoder definition change in software?
Yes. Codecs, video compression and neural networks use the same words for different ideas. Those encoder decoder examples work on data streams, not on logic lines.
2. Which output type suits long cable runs in Industrial Automation?
Differential line driver outputs, such as RS-422, resist noise over cables of up to 100 m. Single-ended outputs suit short runs inside a panel.
3. What is propagation delay?
It is the time between an input change and the output response. Standard TTL decoders usually show 10 ns to 25 ns.
4. What does a decimal-to-BCD encoder do?
The 74147 turns nine decimal lines into a 4-bit BCD code. Its inputs and outputs are active-low.
5. What is fan-out?
Fan-out is the number of gate inputs one output can drive. Standard TTL outputs usually drive about ten.
Comments