Presentation is loading. Please wait.

Presentation is loading. Please wait.

ECE 352 Digital System Fundamentals

Similar presentations


Presentation on theme: "ECE 352 Digital System Fundamentals"— Presentation transcript:

1 ECE 352 Digital System Fundamentals
Decoders Encoders and Priority Encoders In this presentation, we will discuss two fundamental combinational logic structures: decoders and encoders. These circuits are used frequently in digital logic design, and once we understand how they work, we’ll use them as building blocks to create more complex circuits.

2 Topics Decoders and Encoders Decoders Encoders and Priority Encoders
First, we will discuss decoders.

3 Decoder Converts an n-bit input codeword into a unique m-bit output code (called n-to-m or n:m decoder) n ≤ m ≤ 2n There may be unused input and output codes… Commonly, m = 2n Exactly one output is true (and the others are false) for any possible input combination Each output represents one of the 2n possible minterms of an n-input function An output is true if the current input values correspond to the minterm for that output Fundamental functional block that is used in many other logic circuits (e.g., addressing) In general, a decoder takes an n-bit codeword as an input, and converts it to a unique m-bit output word, where m is between n and 2^n. There may be unused input and output codes, depending on the specific design. The most common decoder – the one we will study here – has n input bits and 2^n output bits. In this case, only one output bit is a 1 and all others are 0 for each input code. There are 2^n possible input combinations, so the logic for each output is one of the 2^n possible minterms. As we’ll see, the n-to-2^n decoder is a fundamental building block that is used in many logic circuits, such as decoding addresses in a memory system.

4 Decoder Symbol Examples
Inputs Outputs Some decoder blocks are shown here. The inputs and outputs are labeled in decimal. Each input is labeled with the position of that bit in the input code word, and each output is labeled with the input word value that causes that output to become active.

5 1:2 Decoder One input, two outputs (2#inputs  21  2)
The input value indicates which one of the outputs will be 1 (the other output will be zero) The outputs must be labeled so we know which is output 1 and which is output 0 The top output does not have to be the higher number The simplest decoder takes a single-bit codeword as input, and it has two outputs. The output labeled 0 is active when the input is 0, and the output labeled 1 is active when the input is 1. Note that the pins can be ordered either way. The position of the pin isn’t meaningful - but the label is! Pay attention to labels! They explain which output pin is which (same for inputs if multiple inputs)…

6 2:4 Decoder Two inputs, four outputs
The input can be interpreted as a binary number, and that number indicates which output will be 1 Inputs/outputs need to be labeled if more than one You should put them in an order that makes sense Pay attention to labels! A 2-to-4 decoder has a 2-bit input codeword, so there are 4 possible input values and hence 4 outputs—one per value. Both the inputs and outputs MUST be labeled – their position does not have inherent meaning. The input labeled 1 is the most significant bit of the input, and the input labeled 0 is the least significant. We use the input labeling to interpret the value of the input codeword, and the output labeling to know which output is active for each possible input value. So, for the decoder in the middle, the value of the input is binary 01, which is decimal 1, so the output labeled 1 is active and all other outputs are 0. These outputs together say that the input was “01” Preferred pin order

7 Decoders Remember: each decoder output corresponds to a minterm of the input set Can use a decoder with an OR gate to implement functions in sum-of-minterms form Example: Use a decoder plus an OR gate to implement the “odd function” for 3 variables Since the outputs of a decoder are all possible minterms of the input set, we can use a decoder and an OR gate to implement a function in sum of minterms form. In the example, we have implemented the odd function, which is a 1 only when there are an odd number of 1s in the input word. So, we connect the OR gate inputs to the four minterms where the input has an odd number of 1s.

8 Decoder Structure Each output is a minterm function that includes every input variable Can use hierarchy to create a larger decoder from a smaller one... A decoder computes part of each output minterm based on a subset of the inputs Add logic to complete the minterms 1:2 decoder Since each output of a decoder is a minterm of the inputs, constructing a decoder is straightforward. With a single input, there are only 2 minterms – the input and the complemented input. With two inputs, there are four minterms. Note that output number and the minterm index are the same. This is important. If you look at the structure of the 2-to-4 decoder, you may notice that it is actually composed of two decoders, each decoding one of the inputs, along with AND gates to form the minterms for the outputs. Once we create a small decoder, we can use it in a hierarchy to create a larger decoder. Each smaller decoder computes part of each minterm, and we add logic to complete those computations and produce the outputs of the larger decoder.

9 Enable Signals Some decoders have an additional input called an “enable” Many times the names for things are a hint as to what they mean… An “enabled” decoder operates normally… …the outputs of a “disabled” decoder are ALL 0 Need to know if enable is active-high or active-low Active-high enable: decoder is enabled when enable is 1 Active-low enable: decoder is enabled when enable is 0 Can indicate active-low several ways A bubble before the enable input A bar over the enable signal name A statement saying it is active-low A very useful addition to a decoder is to add an enable input. The enable input does what its name suggests – it enables or disables the decoder. If the decoder is enabled, it works normally. If it is disabled, then all outputs are 0. Be aware that the decoder enable could be designed to be active-high (as shown here) or active-low. If the enable input is active low, the decoder would be enabled when the enable signal is 0. We would indicate that the input is active-low by placing a bubble on the enable input, or by labeling it as /EN, or by a statement to that effect. As a general rule, unless there is information to the contrary, you should assume that circuit inputs and outputs are active-high.

10 Adding an Enable Each output of the decoder is ANDed with the enable signal (for an active-high enable) To implement the enable, we can add an AND gate to each output of a decoder. If the EN is 0, all outputs are forced to 0. If enable is 1, then each output takes on the value of the associated output of the original decoder.

11 Topics Decoders and Encoders Decoders Encoders and Priority Encoders
Now, let’s take a look at encoders.

12 This says that input #0 is a 1
Encoder Performs the reverse operation of a decoder Takes up to 2n inputs, produces n-bit output Implies that meaningful inputs have only a single bit set to 1 Multiple 1 bits or no 1 bits would give erroneous output values An encoder performs the reverse operation of a decoder. If you hooked up a decoder’s outputs to the matching inputs of an encoder that’s the same size, whatever input you apply to the decoder would appear at the encoder output. However, an encoder has a fundamental problem – it has more possible input combinations than can be uniquely represented by the outputs – a LOT more! So, an encoder only operates in a meaningful way if the inputs are constrained to only the values where a single bit of the input is a 1. If more than one bit of the input is a 1, the output is meaningless. If the input is all 0s, the output is meaningless. Because of this, the basic encoder circuit isn’t very useful, and is rarely used. This says that input #0 is a 1

13 Priority Encoder Can resolve the encoding problem of multiple 1’s by assigning each a priority Design encoder so that the output is the code that corresponds to the highest-priority input that is 1 Can prioritize 1s at higher-numbered positions Output is then the highest input # where the input is 1 There’s still a problem – what if all the inputs are 0? A priority encoder solves most of the encoder’s problem by assigning each bit of the input a priority, and then the output value indicates the highest priority input that is a 1. The neatly solves the problem of multiple 1s on the inputs. Unfortunately, there is still a problem if all the inputs are 0s. The root of the problem is that the encoder output can only indicate 4 different conditions, but there are actually five possible input conditions – the 4 cases of each input having the highest 1, and the case when all the inputs are 0s.

14 Priority Encoder w/Value Detect
A variant of the priority encoder has an additional output so that it can also detect all inputs equal 0 Method 1: re-number inputs to start from 1 so an encoder output of all 0s means there were no 1s present Method 2: output V (valid) is 1 if any 1s on inputs If the valid flag is 0, the other outputs are meaningless… The X’s on the output mean the value is not specified To solve the problem with all inputs being 0, we can add an additional bit to the priority encoder outputs. Now the outputs can represent all the required possibilities (and more). We can use the added output in two ways. One technique is to assign output code 0 to mean that all inputs are 0, and then label the inputs so that they start at 1. Then output codes 1, 2, 3, and 4 correspond to the highest priority input with a 1. Note that in this case output codes 5, 6 and 7 are not used, so we would make those don’t-cares when we design the circuitry. Alternatively, we can leave the codes 0 through 3 as is, but have the new output bit indicate if there are any 1s on the inputs or not. In this case, we often name this extra output V because it indicates if the output code is “valid”. If there are no 1s on the inputs, the output V is 0 and we know that the code bits are not valid and should be ignored. We represent that case in this diagram with Xs – something we’ll talk more about shortly. If there are any 1s on the inputs, then V is 1 and we know that the code bits are valid.

15 “X” Output Here we use the “X” to say that the output value is not specified by the circuit’s requirements An output labeled as “X” will actually be a 1 or 0, because those are the only valid options But you shouldn’t depend on it to be one of these in particular, because the actual value isn’t specified e.g., two different priority encoders may have different output values when all inputs are 0… Generally also means that the circuit design uses don’t-cares “If all inputs are 0, then V=0 but we don’t care about the other outputs” In the previous example, we used an X to indicate that the output value is not specified. Of course, each output must actually be 1 or 0, but the circuit designer is not telling us what the data outputs are when V is 0. Actually, they are saying that we should not depend on those outputs to be any particular values in that case. You’ve seen examples of don’t-care outputs for input cases that will never occur, but this is a little different. An input set of all 0s could happen, but then only the V output is meaningful. Anything using the encoder output should ignore the code outputs if V is 0. This means that the encoder’s designer can treat the code outputs for that case as don’t-cares to help simplify the encoder logic.

16 Example 4-Input Encoder Behaviors
Valid Flag Priority Encoder Encoder D3 D2 D1 D0 others Y1 Y0 X X 0 0 0 1 1 0 1 1 X X D3 D2 D1 D0 X X X 1 X X X Y1 Y0 V X X 0 Here we compare the truth tables of the basic encoder and a priority encoder. When we use an X on the output side of the truth table, it means that the value is not specified. When we use an X on the input side of the truth table, it is a wildcard indicating all possible values. We do this to make the truth table more readable. The complete truth tables would have 16 rows, but with Xs the priority encoder truth table is only 5 rows and very succinctly expresses the 5 significant input conditions. Which of these encoder designs do you think would have smaller hardware? An “X” on the input side of a truth table is a wildcard indicating all possible values

17 Decoding, Encoding, Enabling
These are all concepts The ideas are more broad than the common examples shown on the previous slides Example: BCD to 7-segment Decoder Inputs 4-bit BCD value Outputs 7 bits, one per segment of the display “Decodes” the BCD value to determine which segments are lit May include an enable to allow turning the display off regardless of the BCD value…. Decoding, encoding and enabling are all general concepts we’ll see again and again. For example, we could (and later on we will) design a circuit that takes a BCD input and decodes it to drive a 7-segment display. The enable gives us the ability to turn off the display when we want it to be blank.

18 Design Example: Codes Toy: 6 Switches
Here’s a real-life example of how encoding and decoding can be used. The picture shows a child’s toy. This toy has a receptacle that accepts different letter tiles. The toy then does different things depending on which letter the child inserts. Note that there are six small switches in the receptacle, which serve as inputs to the digital circuitry inside the toy. Toy: 6 Switches

19 Design Example: Codes Letter tiles that can be placed in the slot have posts on the bottom that press the switches These are some of the tiles that can be inserted into the toy. Each tile has a post or a gap aligned with each of the switches in the toy, so inserting it causes some switches to be pressed and others not, creating a pattern of 1s and 0s. Each letter tile activates a different combination of switches. When the child inserts the tile, the toy uses the code to determine how it will react. How many different tiles could the toy recognize? Well, there are 6 switches, so there are 2^6 or 64 possible codes. However, the “no switch pressed” code must be reserved so that the toy can detect when there is no tile inserted. This means it can actually recognize as many as 63 different tiles. Decoding and encoding aren’t just for children’s toys - you will encounter these concepts over and over again in digital hardware, computer software, and as mathematical concepts. Different letter tiles have different post positions (different codes!)

20 ECE 352 Digital System Fundamentals
Decoders Encoders and Priority Encoders This concludes our video on encoders and decoders.


Download ppt "ECE 352 Digital System Fundamentals"

Similar presentations


Ads by Google