Вы находитесь на странице: 1из 56

ENG241 Digital Design

Week #4 Combinational Logic Design Part B

Resources

Chapter #4, Mano Sections


4.1 4.3 4.4 4.5 4.6

Combinational Circuits Decoding Encoding Multiplexers Comb Function Implementations

Fall 2010

ENG241/Digital Design

Week #4 Topics
Decoders

Combinational circuit Implementation Priority Encoders Combinational Circuit Implementation

Encoders

Multiplexers

Demultiplexers

Fall 2010

ENG241/Digital Design

Decoders

Typically n inputs and 2n outputs Drives high the output corresponding to binary code of input

Example: Binary to Octal, Binary to Hex, e.t.c

Fall 2010

ENG241/Digital Design

2-to-4 Line Decoder

Notice they are minterms


Fall 2010 ENG241/Digital Design 5

Truth Table, 3-to-8 Decoder

Notice they are minterms


ENG241/Digital Design 6

Fall 2010

3-to-8 Line Decoder Schematic

Fall 2010

ENG241/Digital Design

2-to-4 with Enable

Fall 2010

ENG241/Digital Design

Enable Used for Expansion

Fall 2010

ENG241/Digital Design

VHDL Design Styles


VHDL Design Styles

dataflow
Concurrent statements

structural
Components and interconnects

behavioral (algorithmic)
Sequential statements Registers State machines Test benches

Subset most suitable for synthesis


Fall 2010 ENG241/Digital Design 10

Decoder: Data Flow


Example: 2-to-4 decoder
entity dec_2_to_4 is port ( A0, A1: in std_logic; D0, D1, D2, D3: out std_logic); end entity decoder_2_to_4;

Interface

D3 A(1) D2 D1

A(0)

D0

architecture dataflow1 of dec_2_to_4 is Signal A0_n, A1_n: std_logic; begin A0_n <= not A0; A1_n <= not A1; D0 <= A0_n and A1_n; D1 <= A0 and A1_n; D2 <= A0_n and A1; D3 <= A0 and A1; end architecture dataflow1;

Fall 2010

ENG241/Digital Design

Functionality

A0_n

11

When Else Statement

zmux: z <= d0 when sel1 = 0 and sel0 = 0 else d1 when sel1 = 0 and sel0 = 1 else d2 when sel1 = 1 and sel0 = 0 else d3;

Fall 2010

ENG241/Digital Design

12

Decoder: Data Flow #2


Example: 2-to-4 decoder
entity dec_2_to_4 is port ( A : in std_logic_vector(1 downto 0); D : out std_logic_vector(3 downto 0) ); end entity dec_2_to_4;

Interface

D(3) A(1) D(2) D(1)

A(0)

D(0)

Functionality

architecture dataflow2 of dec_2_to_4 is begin D <= "0001" when A = "00" else "0010" when A = "01" else "0100" when A = "10" else "1000" when A = "11" else "XXXX"; end architecture dataflow2;

A(1..0) 0 0 1 1 0 1 0 1 0 0 0 1

D(3..0) 0 0 1 0 0 1 0 0 1 0 0 0

Fall 2010

ENG241/Digital Design

13

Structural VHDL Description of 2-to-4 Line Decoder

Fall 2010

ENG241/Digital Design

14

Structural VHDL Description (Entity Declaration)


-- 2-to-4 Line Decoder; structural VHDL Description library ieee; use ieee.std_logic_1164.all entity decoder_2_4_w_enable is port (EN, A0, A1 : in std_logic; D0, D1, D2, D3 : out std_logic); end decoder_2_to_4_w_enable;

Fall 2010

ENG241/Digital Design

15

Structural VHDL Description (Signals)


A1_n A0_n N0 N1 N2

N3

Fall 2010

ENG241/Digital Design

16

Structural VHDL Description (Components)


architecture structural1_1 of decoder_2_to_4_w_enable is component NOT1 port(in1: in std_logic; out1: out std_logic); end component; component AND2 port(in1, in2: in std_logic; out1: out std_logic); end component;

Fall 2010

ENG241/Digital Design

17

Structural VHDL Description (Connecting components)


architecture structural1_1 of decoder_2_to_4_w_enable is -- component NOT1 declaration -- component NAND2 signal A0_n, A1_n, N0, N1, N2, N3: std_logic; begin g0: NOT1 port map (in1 => A0, out1 => A0_n); g1: NOT1 port map (in1 => A1, out1 => A1_n); g2: AND2 port map (in1 => A0_n, in2 => A1_n, out1 => N0); g3: AND2 port map (in1 => A0, in2 => A1_n, out1 => N1); g4: AND2 port map (in1 => A0_n, in2 => A1_n, out1 => N2); g5: AND2 port map (in1 => A0, in2 => A1, out1 => N3); g6: AND2 port map (in1 =>EN, in2 => N0, out1 => D0); g7: AND2 port map (in1 => EN, in2 => N1, out1 => D1); g8: AND2 port map (in1 => EN, in2 => N2, out1 => D2); g9: AND2 port map (in1 => EN, in2 => N3, out1 => D3); end structural_1;

Fall 2010

ENG241/Digital Design

18

Cont .. Structural VHDL Description of 2-to-4 Line Decoder


A1_n
A0_n
architecture structural1_1 of decoder_2_to_4_w_enable is -- component NOT1 declaration -- component NAND2 signal A0_n, A1_n, N0, N1, N2, N3: std_logic; begin g0: NOT1 port map (in1 => A0, out1 => A0_n); g1: NOT1 port map (in1 => A1, out1 => A1_n); g2: AND2 port map (in1 => A0_n, in2 => A1_n, out1 => N0); g3: AND2 port map (in1 => A0, in2 => A1_n, out1 => N1); g4: AND2 port map (in1 => A0_n, in2 => A1_n, out1 => N2); g5: AND2 port map (in1 => A0, in2 => A1, out1 => N3); g6: AND2 port map (in1 =>EN, in2 => N0, out1 => D0); g7: AND2 port map (in1 => EN, in2 => N1, out1 => D1); g8: AND2 port map (in1 => EN, in2 => N2, out1 => D2); g9: AND2 port map (in1 => EN, in2 => N3, out1 => D3); end structural_1;

Fall 2010

ENG241/Digital Design

19

Usage for Decoders

Implement logic circuits! Memory address lines Decoders are used in Micro Computer Interfacing for Keyboard and Display applications.

Fall 2010

ENG241/Digital Design

20

Decoders as General-purpose Logic

n:2n decoder implements any function of n variables


With the variables used as control inputs Enable inputs tied to 1 and Appropriate minterms summed to form the function

Decoder generates appropriate minterm based on control signals (it "decodes" control signals)

Fall 2010

ENG241/Digital Design

21

Decoders as General-purpose Logic

Example: Implement the following boolean functions


1. 2.

S(A2,A1,A0) = SUM(m(1,2,4,7))

C(A2,A1,A0) = SUM(m(3,5,6,7))

1.

Since there are three inputs, we need a 3-to-8 line decoder. The decoder generates the eight minterms for inputs A0,A1,A2 An OR GATE forms the logical sum minterms required.
22

2.

3.

Fall 2010

ENG241/Digital Design

Example

F1 = A' B C' D + A' B' C D + A B C D


0 1 2 3 4 5 6 4:16 7 DEC 8 9 10 11 12 13 14 15 A B C D A'B'C'D' A'B'C'D A'B'CD' A'B'CD A'BC'D' A'BC'D A'BCD' A'BCD AB'C'D' AB'C'D AB'CD' AB'CD ABC'D' ABC'D ABCD' ABCD
23

F1

Enable

Fall 2010

ENG241/Digital Design

Encoder

Encoder is the opposite of decoder 2n inputs (or less maybe BCD in) n outputs Examples:

Octal to binary Hexadecimal to binary

Fall 2010

ENG241/Digital Design

24

Truth Table (Octal to binary)

Fall 2010

ENG241/Digital Design

25

Inputs are Minterms


A0 = D1 + D3 + D5 + D7

Fall 2010

ENG241/Digital Design

26

Whats the Problem?

What if D3 and D6 both high? Simple OR circuit will set A to 111 Solution?

Fall 2010

ENG241/Digital Design

27

Priority Encoder

Chooses one with highest priority

Largest number, usually

Note dont cares

What if all inputs are zero?


Fall 2010 ENG241/Digital Design 28

Need Another Output!

A Valid Output!

Fall 2010

ENG241/Digital Design

29

Valid is OR of all inputs

Fall 2010

ENG241/Digital Design

30

Multiplexer (or Mux)

Selects one of a set of inputs to pass on to output Binary control code, n lines

Choose from 2n inputs

74153

Useful for choosing from sets of data

Memory or register to ALU

Very common

Fall 2010

ENG241/Digital Design

31

Two Input Multiplexer

Fall 2010

ENG241/Digital Design

32

4-to-1 Line Multiplexer

Fall 2010

ENG241/Digital Design

33

Logic is Decoder Plus .

Fall 2010

ENG241/Digital Design

34

Compare the two Diagrams!

Fall 2010

ENG241/Digital Design

35

Dataflow VHDL Description of 4-to-1 Multiplexer


-- 4-to-1 Line Mux; Conditional Dataflow VHDL Descrip library ieee; use ieee.std_logic_1164.all entity multiplexer_4_to_1_we is port (S: in std_logic_vector(1 downto 0); I: in std_logic_vector(3 downto 0); Y: out std_logic; end multiplexer_4_to_1_we;

Fall 2010

ENG241/Digital Design

36

Cont .. Dataflow VHDL Description


architecture function_table of multiplexer_4_to_1_we is -- Using When Else Begin Y <= I(0) when S = 00 else I(1) when S = 01 else I(2) when S = 10 else I(3) when S = 11 else `X; end function_table;
Fall 2010 ENG241/Digital Design 37

Quad 2-to-4 Line Mux

Select one set of 4 lines

Fall 2010

ENG241/Digital Design

38

Muxes as General-purpose Logic

2n:1 multiplexer implements any function of n variables 1. With the variables used as control inputs and 2. Data inputs tied to 0 or 1 3. In essence, a lookup table Example: F(A,B,C) = m0 + m2 + m6 + m7

= A'B'C' + A'BC' + ABC' + ABC


1 0 1 0 0 0 1 1

0 1 2 3 4 8:1 MUX 5 6 7 S2 S1 S0 A B

C
39

Fall 2010

ENG241/Digital Design

Multiplexers as General-purpose Logic (contd)

2n-1:1 mux can implement any function of n variables With n-1 variables used as control inputs and Data inputs tied to the last variable or its complement Example: F(A,B,C) = m0 + m2 + m6 + m7 = A'B'C' + A'BC' + ABC' + ABC

1 0 1 0 0 0 1 1

0 1 2 3 4 8:1 MUX 5 6 7 S2 S1 S0 A B

A 0 0 0 0 1 1 1 1

B 0 0 1 1 0 0 1 1

C 0 1 0 1 0 1 0 1

F 1 0 1 0 0 0 1 1

C' C' 0 1

C' C' 0 1

0 1 4:1 MUX 2 3 S1 S0 A B

C
ENG241/Digital Design 40

Fall 2010

Demultiplexer

Takes one input Out to one of 2n possible outputs

Fall 2010

ENG241/Digital Design

41

Demux is a Decoder

With an enable

Fall 2010

ENG241/Digital Design

42

Fall 2010

ENG241/Digital Design

43

Decoder Expansion

A 2-to-4 Line decoder requires 4 (2-input) AND gates A 3-to-8 line decoder requires 8 (3-input) AND gates If we want to design a 6-to-64 line decoder then we will need? 64 (6-input) AND gates! Unfortunately, as decoders become larger, this approach gives a high gate input count! Instead we will resort to a procedure that uses design hierarchy to construct any decoder with n inputs and 2n outputs. The resulting decoder should have the same or a lower gate input count than the one constructed simply enlarging each AND gate.
ENG241/Digital Design 44

Fall 2010

Decoder Expansion
To design a 3-to-8 line decoder (n=3) we can use a 2-to-4 line decoder and 1to-2 line decoder feeding eight 2-input AND gates to form the minterms instead of using eight 3input AND gates!

Fall 2010

ENG241/Digital Design

45

General Procedure
1. 2. 3.

4. 5.

1.

2.

Let k=n. If k is even, divide k by 2 to obtain k/2. Use 2k AND gates driven by two decoders of output size 2k/2. If k is odd, obtain (k+1)/2 and (k-1)/2. Use 2k AND gates driven by a decoder of output size 2(k+1)/2 and a decoder of output size 2(k-1)/2 For each decoder resulting from step (2-3) (4-5), repeat with values obtained in step 2 until k=1. For k=1, use a 1-to-2 decoder.

Fall 2010

ENG241/Digital Design

46

Decoder Expansion - Example 1

3-to-8-line decoder Number of output ANDs = 8 Number of inputs to decoders driving output ANDs = 3 Closest possible split to equal (k+1)/2 2-to-4-line decoder (k-1)/ 2 1-to-2-line decoder 2-to-4-line decoder Number of output ANDs = 4 Number of inputs to decoders driving output ANDs = 2 Closest possible split to equal Two 1-to-2-line decoders See next slide for result

Fall 2010

ENG241/Digital Design

47

Decoder Expansion - Example 1

Result

Fall 2010

ENG241/Digital Design

48

Multi-Level 6-to-64

Fall 2010

ENG241/Digital Design

49

Aside: K Map for A0

X on input means we must satisfy for both possibilities: 0, 1

Fall 2010

ENG241/Digital Design

50

Variations

At right

Enable not Inverted outputs


ENG241/Digital Design 51

Fall 2010

Variations

Fall 2010

ENG241/Digital Design

52

Structural VHDL Description of 4-to-1 Line Multiplexer


S_n(0:1) D(0:3) N(0:3)

Fall 2010

ENG241/Digital Design

53

Cont .. Structural VHDL Description of 4-to-1 Multiplexer


-- 4-to-1 Line Multiplexer; structural VHDL Description library ieee; use ieee.std_logic_1164.all entity multiplexer_4_to_1_st is port (S: in std_logic_vector(0 to 1); I: in std_logic_vector(0 to 3); Y: out std_logic; end multiplexer_4_to_1_st;

Fall 2010

ENG241/Digital Design

54

Cont .. Structural VHDL Description of 4-to-1 Multiplexer


architecture structural_2 of multiplexer_4_to_1_st is component NOT1 port(in1: in std_logic; out1: out std_logic); end component; component AND2 port(in1, in2: in std_logic; out1: out std_logic); end component; component OR4 port(in1, in2, in3, in4: in std_logic; out1: out std_logic); end component;

Fall 2010

ENG241/Digital Design

55

Cont .. Structural VHDL Description of 4-to-1 Multiplexer


architecture structural_2 of multiplexer_4_to_1_st is -- component NOT1 AND2 OR4 declarations signal S_n : std_logic(0 to 1); signal D, N : std_logic_vector(0 to 3); begin g0: NOT1 port map (S(0), S_n(0)); g1: NOT1 port map (S(1), S_n(1)); g2: AND2 port map (S_n(1), S_n(0), D(0)); g3: AND2 port map (S_n(1),S(0), D(1)); g4: AND2 port map (S(1),S(0), D(3)); g5: AND2 port map (S(1), S(0), D(3)); g6: AND2 port map (D(0), I(0), N(0)); g7: AND2 port map (D(1),I(1), N(1)); g8: AND2 port map (D(2),I(2),N(2)); g9: AND2 port map (D(3),I(3), N(3)); g10: OR4 port map (N(0), N(1), N(2), N(3), Y); end structural_2;
Fall 2010 ENG241/Digital Design 56

Вам также может понравиться