59
George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

Embed Size (px)

Citation preview

Page 1: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

George Mason University

Data Flow Modelingin VHDL

ECE 545Lecture 7

Page 2: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

2

Required reading

• P. Chu, RTL Hardware Design using VHDL

Chapter 4, Concurrent Signal Assignment

Statements of VHDL

Page 3: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

3

Components andinterconnects

structural

VHDL Descriptions

dataflow

Concurrent statements

behavioral(sequential)

• Registers• State machines• Instruction decoders

Sequential statements

Subset most suitable for synthesis

• Testbenches

Types of VHDL Description

Page 4: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

4

Synthesizable VHDL

Dataflow VHDL

Description

VHDL code

synthesizable

VHDL code

synthesizable

Dataflow VHDL

Description

Page 5: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

5

Register Transfer Level (RTL) Design Description

Combinational Logic

Combinational Logic

Registers

Today’s Topic

Page 6: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

6

Data-Flow VHDL

• simple concurrent signal assignment ()

• conditional concurrent signal assignment (when-else)

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

Concurrent Statements

Page 7: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

7

Simple concurrent signal assignment

target_signal <= expression;

<=

Page 8: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

8

Conditional concurrent signal assignment

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

When - Else

Page 9: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

9

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 10: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

10

Data-Flow VHDL

• simple concurrent signal assignment ()

• conditional concurrent signal assignment (when-else)

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

Concurrent Statements

Page 11: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

11ECE 448 – FPGA and ASIC Design with VHDL

Wires and Buses

Page 12: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

12

Signals

SIGNAL a : STD_LOGIC;

SIGNAL b : STD_LOGIC_VECTOR(7 DOWNTO 0);

wire

a

bus

b

1

8

Page 13: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

13

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 <=

4

5

10

a

b

cd = a || b || c

Page 14: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

14

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

cd = a || b || c

Page 15: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

15

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 <= b <= c <=

4

5

10

a = d ..

b = d ..

c = d

d

Page 16: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

16

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 = d9..6

b = d5..1

c = d0

d

Page 17: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

17

Data-flow VHDL: Example

x

y

cin

s

cout

Page 18: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

18

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 19: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

19

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 ;

ARCHITECTURE dataflow OF fulladd ISBEGIN

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

END dataflow ;

equivalent to

Page 20: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

20

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

or later

Page 21: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

21

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 22: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

RTL Hardware Design Chapter 4 22

arith_result <= a + b + c – 1;

Page 23: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

RTL Hardware Design Chapter 4 23

Signal assignment statement with a closed feedback loop

• a signal appears in both sides of a concurrent assignment statement

• E.g., q <= ((not q) and (not en)) or (d and en);

• Syntactically correct

• Form a closed feedback loop

• Should be avoided

Page 24: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

24

Data-Flow VHDL

• simple concurrent signal assignment ()

• conditional concurrent signal assignment (when-else)

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

Concurrent Statements

Page 25: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

25

Conditional concurrent signal assignment

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

When - Else

Page 26: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

26

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 2

Condition 1

Value 2

Value 1

Target Signal

…F

T

F

T

F

T

Page 27: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

RTL Hardware Design Chapter 4 27

2-to-1 “abstract” mux• sel has a data type of boolean• If sel is true, the input from “T” port is connected

to output. • If sel is false, the input from “F” port is connected

to output.

Page 28: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

RTL Hardware Design Chapter 4 28

Page 29: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

RTL Hardware Design Chapter 4 29

Page 30: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

RTL Hardware Design Chapter 4 30

Page 31: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

RTL Hardware Design Chapter 4 31

• E.g.,

Page 32: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

RTL Hardware Design Chapter 4 32

• E.g.,

Page 33: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

33

Signed and Unsigned Types

Behave exactly like

STD_LOGIC_VECTOR

plus, they determine whether a given vector

should be treated as a signed or unsigned number.

Require

USE ieee.numeric_std.all;

Page 34: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

34

Operators

• Relational operators

• Logic and relational operators precedence

= /= < <= > >=

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

Highest

Lowest

Page 35: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

35

compare a = bc

Incorrect

… 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 36: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

36

Data-Flow VHDL

• simple concurrent signal assignment ()

• conditional concurrent signal assignment (when-else)

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

Concurrent Statements

Page 37: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

37

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 38: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

38

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 39: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

39

Allowed formats of choices_k

WHEN value

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

WHEN OTHERS

Page 40: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

40

Allowed formats of choice_k - example

WITH sel SELECT

y <= a WHEN "000",

c WHEN "001" | "111",

d WHEN OTHERS;

Page 41: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

RTL Hardware Design Chapter 4 41

Syntax

• Simplified syntax:with select_expression select

signal_name <=

value_expr_1 when choice_1,

value_expr_2 when choice_2,

value_expr_3 when choice_3,

. . .

value_expr_n when choice_n;

Page 42: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

RTL Hardware Design Chapter 4 42

• select_expression – Discrete type or 1-D array– With finite possible values

• choice_i– A value of the data type

• Choices must be– mutually exclusive– all inclusive– others can be used as last choice_i

Page 43: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

RTL Hardware Design Chapter 4 43

E.g., 4-to-1 mux

Page 44: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

RTL Hardware Design Chapter 4 44

• Can “11” be used to replace others?

Page 45: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

RTL Hardware Design Chapter 4 45

E.g., 2-to-22 binary decoder

Page 46: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

RTL Hardware Design Chapter 4 46

E.g., simple ALU

Page 47: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

RTL Hardware Design Chapter 4 47

E.g., Truth table

Page 48: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

RTL Hardware Design Chapter 4 48

Conceptual implementation

• Achieved by a multiplexing circuit

• Abstract (k+1)-to-1 multiplexer– sel is with a data type

of (k+1) values:c0, c1, c2, . . . , ck

Page 49: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

RTL Hardware Design Chapter 4 49

– select_expression is with a data type of 5 values: c0, c1, c2, c3, c4

Page 50: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

RTL Hardware Design Chapter 4 50

Page 51: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

RTL Hardware Design Chapter 4 51

• E.g.,

Page 52: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

RTL Hardware Design Chapter 4 52

3. Conditional vs. selected signal assignment

• Conversion between conditional vs. selected signal assignment

• Comparison

Page 53: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

RTL Hardware Design Chapter 4 53

From selected assignment to conditional assignment

Page 54: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

RTL Hardware Design Chapter 4 54

From conditional assignment to selected assignment

Page 55: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

RTL Hardware Design Chapter 4 55

Comparison

• Selected signal assignment: – good match for a circuit described by a

functional table– E.g., binary decoder, multiplexer– Less effective when an input pattern is given a

preferential treatment

Page 56: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

RTL Hardware Design Chapter 4 56

• Conditional signal assignment: – good match for a circuit that needs to give

preferential treatment for certain conditions or to prioritize the operations

– E.g., priority encoder– Can handle complicated conditions. e.g.,

Page 57: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

RTL Hardware Design Chapter 4 57

– May “over-specify” for a functional table based circuit.

– E.g., mux

Page 58: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

58

when-else vs. with-select-when (1)

"when-else" should be used when:

1) there is only one condition (and thus, only one else), as in the 2-to-1 MUX

2) conditions are independent of each other (e.g., they test values of different signals)

3) conditions reflect priority (as in priority encoder); one with the highest priority need to be tested first.

Page 59: George Mason University Data Flow Modeling in VHDL ECE 545 Lecture 7

59

when-else vs. with-select-when (2)

"with-select-when" should be used when there is

1) more than one condition

2) conditions are closely related to each other (e.g., represent different ranges of values of the same signal)

3) all conditions have the same priority (as in the 4-to-1 MUX).