lecture3 combinational blocks

70
George Mason University ECE 448 – FPGA and ASIC Design with VHDL Combinational-Circuit Building Blocks Data Flow Modeling of Combinational Logic ECE 448 Lecture 3

Upload: nima-shafiee

Post on 22-Mar-2017

23 views

Category:

Engineering


1 download

TRANSCRIPT

Page 1: Lecture3 combinational blocks

George Mason University ECE 448 – FPGA and ASIC Design with VHDL

Combinational-Circuit Building Blocks

Data Flow Modeling of Combinational Logic

ECE 448Lecture 3

Page 2: Lecture3 combinational blocks

2 ECE 448 – FPGA and ASIC Design with VHDL

Required reading

• S. Brown and Z. Vranesic, Fundamentals of Digital Logic with VHDL Design

Chapter 6, Combinational-Circuit Building Blocks (sections 6.6.5-6.6.7 optional)Chapter 5.5, Design of Arithmetic Circuits Using CAD Tools

Page 3: Lecture3 combinational blocks

3 ECE 448 – FPGA and ASIC Design with VHDL

VHDL Design Styles

Page 4: Lecture3 combinational blocks

4 ECE 448 – FPGA and ASIC Design with VHDL

VHDL Design Styles

Components andinterconnects

structural

VHDL Design Styles

dataflow

Concurrent statements

behavioral(sequential)

• Registers• State machines

Sequential statements

Subset most suitable for synthesis

• Testbenches

Page 5: Lecture3 combinational blocks

5 ECE 448 – FPGA and ASIC Design with VHDL

Synthesizable VHDL

Dataflow VHDL Design Style

VHDL codesynthesizable

VHDL codesynthesizable

Dataflow VHDL Design Style

Page 6: Lecture3 combinational blocks

6 ECE 448 – FPGA and ASIC Design with VHDL

Data-Flow VHDL

• concurrent signal assignment ()

• conditional concurrent signal assignment (when-else)

• selected concurrent signal assignment (with-select-when)

• generate scheme for equations (for-generate)

Concurrent Statements

Page 7: Lecture3 combinational blocks

7 ECE 448 – FPGA and ASIC Design with VHDL

Modeling Wires and Buses

Page 8: Lecture3 combinational blocks

8 ECE 448 – FPGA and ASIC Design with VHDL

Signals

SIGNAL a : STD_LOGIC;

SIGNAL b : STD_LOGIC_VECTOR(7 DOWNTO 0);

wire

a

bus

b

1

8

Page 9: Lecture3 combinational blocks

9 ECE 448 – FPGA and ASIC Design with VHDL

Merging wires and buses

SIGNAL a: STD_LOGIC_VECTOR(3 DOWNTO 0);SIGNAL b: STD_LOGIC_VECTOR(4 DOWNTO 0);SIGNAL c: STD_LOGIC;SIGNAL d: STD_LOGIC_VECTOR(9 DOWNTO 0);

d <= a & b & c;

4

5

10

a

b

c

d

Page 10: Lecture3 combinational blocks

10 ECE 448 – FPGA and ASIC Design with VHDL

Splitting buses

SIGNAL a: STD_LOGIC_VECTOR(3 DOWNTO 0);SIGNAL b: STD_LOGIC_VECTOR(4 DOWNTO 0);SIGNAL c: STD_LOGIC;SIGNAL d: STD_LOGIC_VECTOR(9 DOWNTO 0);

a <= d(9 downto 6);b <= d(5 downto 1);c <= d(0);

4

5

10

a

b

c

d

Page 11: Lecture3 combinational blocks

11 ECE 448 – FPGA and ASIC Design with VHDL

Combinational-CircuitBuilding Blocks

Page 12: Lecture3 combinational blocks

12 ECE 448 – FPGA and ASIC Design with VHDL

Fixed Shifters & Rotators

Page 13: Lecture3 combinational blocks

13 ECE 448 – FPGA and ASIC Design with VHDL

Fixed Shift in VHDL

A(3) A(2) A(1) A(0)

‘0’ A(3) A(2) A(1)

A>>1

SIGNAL A : STD_LOGIC_VECTOR(3 DOWNTO 0);SIGNAL AshiftR: STD_LOGIC_VECTOR(3 DOWNTO 0);

AshiftR <=

AshiftR

A

Page 14: Lecture3 combinational blocks

14 ECE 448 – FPGA and ASIC Design with VHDL

Fixed Rotation in VHDL

A(3) A(2) A(1) A(0)

A(2) A(1) A(0) A(3)

A<<<1

SIGNAL A : STD_LOGIC_VECTOR(3 DOWNTO 0);SIGNAL ArotL: STD_LOGIC_VECTOR(3 DOWNTO 0);

ArotL <=

ArotL

A

Page 15: Lecture3 combinational blocks

15 ECE 448 – FPGA and ASIC Design with VHDL

Gates

Page 16: Lecture3 combinational blocks

16 ECE 448 – FPGA and ASIC Design with VHDL

x 1 x 2

x n

x 1 x 2 x n + + + x 1 x 2

x 1 x 2 +

x 1 x 2

x n

x 1 x 2

x 1 x 2 x 1 x 2 x n

(a) AND gates

(b) OR gates

x x

(c) NOT gate

Basic Gates – AND, OR, NOT

Page 17: Lecture3 combinational blocks

17 ECE 448 – FPGA and ASIC Design with VHDL

x 1 x 2

x n

x 1 x 2 x n + + + x 1 x 2

x 1 x 2 +

x 1 x 2

x n

x 1 x 2

x 1 x 2 x 1 x 2 x n

(a) NAND gates

(b) NOR gates

Basic Gates – NAND, NOR

Page 18: Lecture3 combinational blocks

18 ECE 448 – FPGA and ASIC Design with VHDL

x 1 x 2

x 1

x 2

x 1 x 2

x 1 x 2

x 1

x 2

x 1 x 2

x 1 x 2 x 1 x 2 + = (a)

x 1 x 2 + x 1 x 2 = (b)

DeMorgan’s Theorem and other symbols for NAND, NOR

Page 19: Lecture3 combinational blocks

19 ECE 448 – FPGA and ASIC Design with VHDL

Basic Gates – XOR

(b) Graphical symbol(a) Truth table

0 0 1 1

0 1 0 1

0 1 1 0

x 1 x 2

x 1 x 2

f x 1 x 2 =

f x 1 x 2 =

(c) Sum-of-products implementation

f x 1 x 2 =

x 1 x 2

Page 20: Lecture3 combinational blocks

20 ECE 448 – FPGA and ASIC Design with VHDL

Basic Gates – XNOR

(b) Graphical symbol(a) Truth table

0 0 1 1

0 1 0 1

1 0 0 1

x 1 x 2

x 1 x 2

f x 1 x 2 =

f x 1 x 2 =

(c) Sum-of-products implementation

f x 1 x 2 =

x 1 x 2

x 1 x 2 = .

Page 21: Lecture3 combinational blocks

21 ECE 448 – FPGA and ASIC Design with VHDL

Data-flow VHDL: Example

xy

cins

cout

Page 22: Lecture3 combinational blocks

22 ECE 448 – FPGA and ASIC Design with VHDL

Data-flow VHDL: Example (1)

LIBRARY ieee ;USE ieee.std_logic_1164.all ;

ENTITY fulladd ISPORT ( x : IN STD_LOGIC ;

y : IN STD_LOGIC ; cin : IN STD_LOGIC ;

s : OUT STD_LOGIC ; cout : OUT STD_LOGIC ) ;END fulladd ;

Page 23: Lecture3 combinational blocks

23 ECE 448 – FPGA and ASIC Design with VHDL

Data-flow VHDL: Example (2)

ARCHITECTURE dataflow OF fulladd ISBEGIN

s <= x XOR y XOR cin ;cout <= (x AND y) OR (cin AND x) OR (cin AND y) ;

END dataflow ;

Page 24: Lecture3 combinational blocks

24 ECE 448 – FPGA and ASIC Design with VHDL

Logic Operators

• Logic operators

• Logic operators precedence

and or nand nor xor not xnor

notand or nand nor xor xnor

Highest

Lowest

only in VHDL-93

Page 25: Lecture3 combinational blocks

25 ECE 448 – FPGA and ASIC Design with VHDL

Wanted: y = ab + cdIncorrecty <= a and b or c and d ; equivalent toy <= ((a and b) or c) and d ;equivalent toy = (ab + c)d

Correcty <= (a and b) or (c and d) ;

No Implied Precedence

Page 26: Lecture3 combinational blocks

26 ECE 448 – FPGA and ASIC Design with VHDL

Multiplexers

Page 27: Lecture3 combinational blocks

27 ECE 448 – FPGA and ASIC Design with VHDL

2-to-1 Multiplexer

(a) Graphical symbol (b) Truth table

0

1

fs

w0

w1

f

s

w0

w1

0

1

Page 28: Lecture3 combinational blocks

28 ECE 448 – FPGA and ASIC Design with VHDL

VHDL code for a 2-to-1 Multiplexer

LIBRARY ieee ;USE ieee.std_logic_1164.all ;

ENTITY mux2to1 ISPORT ( w0, w1, s : IN STD_LOGIC ;

f : OUT STD_LOGIC ) ;END mux2to1 ;

ARCHITECTURE dataflow OF mux2to1 ISBEGIN

f <= w0 WHEN s = '0' ELSE w1 ;END dataflow ;

Page 29: Lecture3 combinational blocks

29 ECE 448 – FPGA and ASIC Design with VHDL

Cascade of two multiplexers

s1

w3

w1

0

1

s2

w2

0

1 y

Page 30: Lecture3 combinational blocks

30 ECE 448 – FPGA and ASIC Design with VHDL

VHDL code for a cascade of two multiplexers

LIBRARY ieee ;USE ieee.std_logic_1164.all ;

ENTITY mux_cascade ISPORT ( w1, w2, w3: IN STD_LOGIC ;

s1, s2 : IN STD_LOGIC ;f : OUT STD_LOGIC ) ;

END mux_cascade ;

ARCHITECTURE dataflow OF mux2to1 ISBEGIN

f <= w1 WHEN s1 = ‘1' ELSE w2 WHEN s2 = ‘1’ ELSE w3 ;END dataflow ;

Page 31: Lecture3 combinational blocks

31 ECE 448 – FPGA and ASIC Design with VHDL

Operators

• Relational operators

• Logic and relational operators precedence

= /= < <= > >=

not= /= < <= > >=and or nand nor xor xnor

Highest

Lowest

Page 32: Lecture3 combinational blocks

32 ECE 448 – FPGA and ASIC Design with VHDL

compare a = bcIncorrect … when a = b and c else …equivalent to … when (a = b) and c else …

Correct … when a = (b and c) else …

Priority of logic and relational operators

Page 33: Lecture3 combinational blocks

33 ECE 448 – FPGA and ASIC Design with VHDL

VHDL operators

Page 34: Lecture3 combinational blocks

34 ECE 448 – FPGA and ASIC Design with VHDL

f

s 1 w 0 w 1

0001

(b) Truth table

w 0 w 1

s 0

w 2 w 3

1011

0 0 1 1

1 0 1

f s 1

0

s 0

w 2 w 3

(a) Graphic symbol

4-to-1 Multiplexer

Page 35: Lecture3 combinational blocks

35 ECE 448 – FPGA and ASIC Design with VHDL

VHDL code for a 4-to-1 Multiplexer

LIBRARY ieee ;USE ieee.std_logic_1164.all ;

ENTITY mux4to1 ISPORT ( w0, w1, w2, w3 : IN STD_LOGIC ;

s : IN STD_LOGIC_VECTOR(1 DOWNTO 0) ;f : OUT STD_LOGIC ) ;

END mux4to1 ;

ARCHITECTURE dataflow OF mux4to1 ISBEGIN

WITH s SELECTf <= w0 WHEN "00",

w1 WHEN "01",w2 WHEN "10",w3 WHEN OTHERS ;

END dataflow ;

Page 36: Lecture3 combinational blocks

36 ECE 448 – FPGA and ASIC Design with VHDL

Decoders

Page 37: Lecture3 combinational blocks

37 ECE 448 – FPGA and ASIC Design with VHDL

2-to-4 Decoder

0 0 1 1

1 0 1

y 0 w 1

0

w 0

x x

1 1

0

1 1

En

0 0 0

1

0

y 1

1 0 0

0

0

y 2

0 1 0

0

0

y 3

0 0 1

0

0

w 0

En

y 0 w 1 y 1

y 2 y 3

(a) Truth table (b) Graphical symbol

Page 38: Lecture3 combinational blocks

38 ECE 448 – FPGA and ASIC Design with VHDL

VHDL code for a 2-to-4 DecoderLIBRARY ieee ;USE ieee.std_logic_1164.all ;

ENTITY dec2to4 ISPORT ( w : IN STD_LOGIC_VECTOR(1 DOWNTO 0) ;

En : IN STD_LOGIC ;y : OUT STD_LOGIC_VECTOR(0 TO 3) ) ;

END dec2to4 ;

ARCHITECTURE dataflow OF dec2to4 ISSIGNAL Enw : STD_LOGIC_VECTOR(2 DOWNTO 0) ;

BEGINEnw <= En & w ;WITH Enw SELECT

y <= "1000" WHEN "100","0100" WHEN "101","0010" WHEN "110","0001" WHEN "111","0000" WHEN OTHERS ;

END dataflow ;

Page 39: Lecture3 combinational blocks

39 ECE 448 – FPGA and ASIC Design with VHDL

Adders

Page 40: Lecture3 combinational blocks

40 ECE 448 – FPGA and ASIC Design with VHDL

16-bit Unsigned Adder

16 16

X Y

16

CinCoutS

Page 41: Lecture3 combinational blocks

41 ECE 448 – FPGA and ASIC Design with VHDL

Arithmetic Operators in VHDL (1)To use basic arithmetic operations involving std_logic_vectors you need to include thefollowing library packages:

LIBRARY ieee;USE ieee.std_logic_1164.all;USE ieee.std_logic_unsigned.all;orUSE ieee.std_logic_signed.all;

Page 42: Lecture3 combinational blocks

42 ECE 448 – FPGA and ASIC Design with VHDL

Arithmetic Operators in VHDL (2)You can use standard +, -, * operatorsto perform addition and subtraction:

signal A : STD_LOGIC_VECTOR(3 downto 0); signal B : STD_LOGIC_VECTOR(3 downto 0); signal C : STD_LOGIC_VECTOR(3 downto 0);

…… C <= A + B;

Page 43: Lecture3 combinational blocks

43 ECE 448 – FPGA and ASIC Design with VHDL

VHDL code for a 16-bit Unsigned Adder

LIBRARY ieee ;USE ieee.std_logic_1164.all ;USE ieee.std_logic_unsigned.all ;

ENTITY adder16 ISPORT ( Cin : IN STD_LOGIC ;

X, Y : IN STD_LOGIC_VECTOR(15 DOWNTO 0) ;S : OUT STD_LOGIC_VECTOR(15 DOWNTO 0) ;Cout : OUT STD_LOGIC ) ;

END adder16 ;

ARCHITECTURE dataflow OF adder16 IS SIGNAL Sum : STD_LOGIC_VECTOR(16 DOWNTO 0) ;

BEGINSum <= ('0' & X) + Y + Cin ;S <= Sum(15 DOWNTO 0) ;Cout <= Sum(16) ;

END dataflow ;

Page 44: Lecture3 combinational blocks

44 ECE 448 – FPGA and ASIC Design with VHDL

Comparators

Page 45: Lecture3 combinational blocks

45 ECE 448 – FPGA and ASIC Design with VHDL

4-bit Number Comparator

4

4

A

B

AeqBAgtB

AltB

Page 46: Lecture3 combinational blocks

46 ECE 448 – FPGA and ASIC Design with VHDL

VHDL code for a 4-bit Unsigned Number Comparator

LIBRARY ieee ;USE ieee.std_logic_1164.all ;USE ieee.std_logic_unsigned.all ;

ENTITY compare ISPORT ( A, B : IN STD_LOGIC_VECTOR(3 DOWNTO 0) ;

AeqB, AgtB, AltB : OUT STD_LOGIC ) ;END compare ;

ARCHITECTURE dataflow OF compare ISBEGIN

AeqB <= '1' WHEN A = B ELSE '0' ;AgtB <= '1' WHEN A > B ELSE '0' ;AltB <= '1' WHEN A < B ELSE '0' ;

END dataflow ;

Page 47: Lecture3 combinational blocks

47 ECE 448 – FPGA and ASIC Design with VHDL

VHDL code for a 4-bit Signed Number Comparator

LIBRARY ieee ;USE ieee.std_logic_1164.all ;USE ieee.std_logic_signed.all ;

ENTITY compare ISPORT ( A, B : IN STD_LOGIC_VECTOR(3 DOWNTO 0) ;

AeqB, AgtB, AltB : OUT STD_LOGIC ) ;END compare ;

ARCHITECTURE dataflow OF compare ISBEGIN

AeqB <= '1' WHEN A = B ELSE '0' ;AgtB <= '1' WHEN A > B ELSE '0' ;AltB <= '1' WHEN A < B ELSE '0' ;

END dataflow ;

Page 48: Lecture3 combinational blocks

48 ECE 448 – FPGA and ASIC Design with VHDL

Buffers

Page 49: Lecture3 combinational blocks

49 ECE 448 – FPGA and ASIC Design with VHDL

(b) Equivalent circuit

(c) Truth table

x f

e

(a) A tri-state buffer

0 0 1 1

0 1 0 1

Z Z 0 1

f e x

x f

e = 0

e = 1x f

Tri-state Buffer

Page 50: Lecture3 combinational blocks

50 ECE 448 – FPGA and ASIC Design with VHDL

x f

e

(b)

x f

e

(a)

x f

e

(c)

x f

e

(d)

Four types of Tri-state Buffers

Page 51: Lecture3 combinational blocks

51 ECE 448 – FPGA and ASIC Design with VHDL

Tri-state Buffer – example (1)

LIBRARY ieee;USE ieee.std_logic_1164.all;

ENTITY tri_state IS PORT ( ena: IN STD_LOGIC;

input: IN STD_LOGIC; output: OUT STD_LOGIC );END tri_state;

Page 52: Lecture3 combinational blocks

52 ECE 448 – FPGA and ASIC Design with VHDL

Tri-state Buffer – example (2)

ARCHITECTURE dataflow OF tri_state ISBEGIN output <= input WHEN (ena = ‘1’) ELSE ‘Z’;END dataflow;

Page 53: Lecture3 combinational blocks

53 ECE 448 – FPGA and ASIC Design with VHDL

Encoders

Page 54: Lecture3 combinational blocks

54 ECE 448 – FPGA and ASIC Design with VHDL

Priority Encoder

w 0

w 3

y 0

y 1

d001

010

w0 y1

d

y0

1 1

01

1

11

z

1xx

0

x

w1

01x

0

x

w2

001

0

x

w3

000

0

1

z

w 1 w 2

Page 55: Lecture3 combinational blocks

55 ECE 448 – FPGA and ASIC Design with VHDL

VHDL code for a Priority EncoderLIBRARY ieee ;USE ieee.std_logic_1164.all ;

ENTITY priority ISPORT ( w : IN STD_LOGIC_VECTOR(3 DOWNTO 0) ;

y : OUT STD_LOGIC_VECTOR(1 DOWNTO 0) ;z : OUT STD_LOGIC ) ;

END priority ;

ARCHITECTURE dataflow OF priority ISBEGIN

y <= "11" WHEN w(3) = '1' ELSE "10" WHEN w(2) = '1' ELSE"01" WHEN w(1) = '1' ELSE"00" ;

z <= '0' WHEN w = "0000" ELSE '1' ;END dataflow ;

Page 56: Lecture3 combinational blocks

56 ECE 448 – FPGA and ASIC Design with VHDL

DescribingCombinational Logic

Using Dataflow Design Style

Page 57: Lecture3 combinational blocks

57 ECE 448 – FPGA and ASIC Design with VHDL

MLU Example

Page 58: Lecture3 combinational blocks

58 ECE 448 – FPGA and ASIC Design with VHDL

MLU: Block Diagram

B

A

NEG_A

NEG_B

IN0

IN1

IN2

IN3 OUTPUT

SEL1

SEL0

MUX_4_1

L0L1

NEG_Y

Y

Y1

A1

B1

MUX_0

MUX_1

MUX_2

MUX_3

Page 59: Lecture3 combinational blocks

59 ECE 448 – FPGA and ASIC Design with VHDL

MLU: Entity Declaration

LIBRARY ieee;USE ieee.std_logic_1164.all;

ENTITY mlu IS PORT(

NEG_A : IN STD_LOGIC; NEG_B : IN STD_LOGIC; NEG_Y : IN STD_LOGIC; A : IN STD_LOGIC; B : IN STD_LOGIC; L1 : IN STD_LOGIC; L0 : IN STD_LOGIC; Y : OUT STD_LOGIC

);END mlu;

Page 60: Lecture3 combinational blocks

60 ECE 448 – FPGA and ASIC Design with VHDL

MLU: Architecture Declarative Section

ARCHITECTURE mlu_dataflow OF mlu IS

SIGNAL A1 : STD_LOGIC;SIGNAL B1 : STD_LOGIC;SIGNAL Y1 : STD_LOGIC;SIGNAL MUX_0 : STD_LOGIC;SIGNAL MUX_1 : STD_LOGIC;SIGNAL MUX_2 : STD_LOGIC;SIGNAL MUX_3 : STD_LOGIC;SIGNAL L: STD_LOGIC_VECTOR(1 DOWNTO 0);

Page 61: Lecture3 combinational blocks

61 ECE 448 – FPGA and ASIC Design with VHDL

MLU - Architecture BodyBEGIN

A1<= NOT A WHEN (NEG_A='1') ELSEA;B1<= NOT B WHEN (NEG_B='1') ELSE B;Y <= NOT Y1 WHEN (NEG_Y='1') ELSEY1;

MUX_0 <= A1 AND B1;MUX_1 <= A1 OR B1;MUX_2 <= A1 XOR B1;MUX_3 <= A1 XNOR B1;

L <= L1 & L0;

with (L) select Y1 <= MUX_0 WHEN "00",

MUX_1 WHEN "01", MUX_2 WHEN "10", MUX_3 WHEN OTHERS;

END mlu_dataflow;

Page 62: Lecture3 combinational blocks

62 ECE 448 – FPGA and ASIC Design with VHDL

Logic Implied Most Often by Conditional and Selected

Concurrent SignalAssignments

Page 63: Lecture3 combinational blocks

63 ECE 448 – FPGA and ASIC Design with VHDL

Data-flow VHDL

• concurrent signal assignment ()• conditional concurrent signal assignment (when-else)• selected concurrent signal assignment (with-select-when)• generate scheme for equations (for-generate)

Major instructions

Concurrent statements

Page 64: Lecture3 combinational blocks

64 ECE 448 – FPGA and ASIC Design with VHDL

Conditional concurrent signal assignment

target_signal <= value1 when condition1 else value2 when condition2 else . . . valueN-1 when conditionN-1 else valueN;

When - Else

Page 65: Lecture3 combinational blocks

65 ECE 448 – FPGA and ASIC Design with VHDL

Most often implied structure

target_signal <= value1 when condition1 else value2 when condition2 else . . . valueN-1 when conditionN-1 else valueN;

When - Else

.…Value N

Value N-1

Condition N-1

Condition 2Condition 1

Value 2Value 1

Target Signal

…01

01

01

Page 66: Lecture3 combinational blocks

66 ECE 448 – FPGA and ASIC Design with VHDL

Data-flow VHDL

• concurrent signal assignment ()• conditional concurrent signal assignment (when-else)• selected concurrent signal assignment (with-select-when)• generate scheme for equations (for-generate)

Major instructions

Concurrent statements

Page 67: Lecture3 combinational blocks

67 ECE 448 – FPGA and ASIC Design with VHDL

Selected concurrent signal assignment

with choice_expression select target_signal <= expression1 when choices_1, expression2 when choices_2, . . . expressionN when choices_N;

With –Select-When

Page 68: Lecture3 combinational blocks

68 ECE 448 – FPGA and ASIC Design with VHDL

Most Often Implied Structure

with choice_expression select target_signal <= expression1 when choices_1, expression2 when choices_2, . . . expressionN when choices_N;

With –Select-When

choices_1

choices_2

choices_N

expression1

target_signal

choice expression

expression2

expressionN

Page 69: Lecture3 combinational blocks

69 ECE 448 – FPGA and ASIC Design with VHDL

Allowed formats of choices_k

WHEN value

WHEN value_1 | value_2 | .... | value N

WHEN OTHERS

Page 70: Lecture3 combinational blocks

70 ECE 448 – FPGA and ASIC Design with VHDL

Allowed formats of choice_k - example

WITH sel SELECTy <= a WHEN "000",

c WHEN "001" | "111", d WHEN OTHERS;