Introduction to VHDL #3vvakilian/CourseECE322/LectureNotes/Lecture7,8.pdf · California State...

29
ECE 322 Digital Design with VHDL Introduction to VHDL #3 Lecture 7 & 8

Transcript of Introduction to VHDL #3vvakilian/CourseECE322/LectureNotes/Lecture7,8.pdf · California State...

Page 1: Introduction to VHDL #3vvakilian/CourseECE322/LectureNotes/Lecture7,8.pdf · California State University VHDL Modeling Styles-Dataflow Modeling Dataflow modeling- describes how data

ECE 322

Digital Design with VHDL

Introduction to VHDL #3

Lecture 7 & 8

Page 2: Introduction to VHDL #3vvakilian/CourseECE322/LectureNotes/Lecture7,8.pdf · California State University VHDL Modeling Styles-Dataflow Modeling Dataflow modeling- describes how data

California State University

VHDL Modeling Styles

Components and

interconnects

Structural

VHDL Modeling

Styles

Dataflow

Concurrent

statements

Behavioral

(sequential)

• Registers

• State machines

• Decoders

Sequential statements

Page 3: Introduction to VHDL #3vvakilian/CourseECE322/LectureNotes/Lecture7,8.pdf · California State University VHDL Modeling Styles-Dataflow Modeling Dataflow modeling- describes how data

California State University

VHDL Modeling Styles-Dataflow Modeling

Dataflow modeling- describes how data moves through the system and the various processing steps.

Dataflow uses series of concurrent statements

Dataflow is the most useful style to describe combinational logic

Dataflow code also called “concurrent” code

Concurrent statements are evaluated at the same time; thus, the order of these statements doesn’t matter.

This is not true for sequential/behavioral statements!

Page 4: Introduction to VHDL #3vvakilian/CourseECE322/LectureNotes/Lecture7,8.pdf · California State University VHDL Modeling Styles-Dataflow Modeling Dataflow modeling- describes how data

California State University

VHDL Modeling Styles-Dataflow Modeling

Example: XOR3

U1 <= A XOR B;

Result <= U1 XOR C;

Result <= U1 XOR C;

U1 <= A XOR B;

These two orders are the same

Page 5: Introduction to VHDL #3vvakilian/CourseECE322/LectureNotes/Lecture7,8.pdf · California State University VHDL Modeling Styles-Dataflow Modeling Dataflow modeling- describes how data

California State University

VHDL Modeling Styles-Dataflow Modeling

Example: XOR3

LIBRARY ieee;

USE ieee.std_logic_1164.all;

entity xor3_gate is

port(

A,B,C : in std_logic;

Result : out std_logic);

end xor3_gate;

Architecture dataflow of xor3_gate is

signal U1 : std_logic;

begin

U1 <= A xor B;

Results <= U1 xor C;

end dataflow;

Page 6: Introduction to VHDL #3vvakilian/CourseECE322/LectureNotes/Lecture7,8.pdf · California State University VHDL Modeling Styles-Dataflow Modeling Dataflow modeling- describes how data

California State University

VHDL Modeling Styles-Structural Modeling

Structural design is the simplest to understand. This style is

the closest to schematic capture and utilizes simple building

blocks to compose logic functions.

Components are interconnected in a hierarchical manner.

Structural descriptions may connect simple gates or

complex, abstract components.

Structural style is useful when expressing a design that is

naturally composed of sub-blocks.

Page 7: Introduction to VHDL #3vvakilian/CourseECE322/LectureNotes/Lecture7,8.pdf · California State University VHDL Modeling Styles-Dataflow Modeling Dataflow modeling- describes how data

California State University

VHDL Modeling Styles-Behavioral Modeling

Behavioral modeling describes the function or expected

behavioral of the design in an algorithmic manner

This style is the closest to a natural language description of

the circuit functionality

Usually described using process block statements which

encapsulate collections of actions executed in sequence

Page 8: Introduction to VHDL #3vvakilian/CourseECE322/LectureNotes/Lecture7,8.pdf · California State University VHDL Modeling Styles-Dataflow Modeling Dataflow modeling- describes how data

California State University

VHDL Modeling Styles-Behavioral Modeling

Process block – Syntax

The first line of the process statement includes a label, the

keyword process, and an optional list of signals, known as

the sensitivity list.

Process_label : process (sensitivity list)

-- declarations

Begin

-- sequential statements

end process;

Page 9: Introduction to VHDL #3vvakilian/CourseECE322/LectureNotes/Lecture7,8.pdf · California State University VHDL Modeling Styles-Dataflow Modeling Dataflow modeling- describes how data

California State University

VHDL Modeling Styles-Behavioral Modeling

A process with a sensitivity list is evaluated during simulation

whenever an event occurs on any of the signals in the

sensitivity list (and only then).

If a process has no sensitivity list then it is evaluated when

an event occurs on any signal.

Process_label : process (sensitivity list)

-- declarations

Begin

-- sequential statements

end process;

Page 10: Introduction to VHDL #3vvakilian/CourseECE322/LectureNotes/Lecture7,8.pdf · California State University VHDL Modeling Styles-Dataflow Modeling Dataflow modeling- describes how data

California State University

VHDL Modeling Styles-Behavioral Modeling

Sensitivity lists are only used for speeding up simulations.

They are ignored by synthesis programs.

Why?

Hardware synthesis needs to know about all

signals, not just the active ones. Simulation,

on the other hand, only needs to know about

active signals.

Page 11: Introduction to VHDL #3vvakilian/CourseECE322/LectureNotes/Lecture7,8.pdf · California State University VHDL Modeling Styles-Dataflow Modeling Dataflow modeling- describes how data

California State University

VHDL Modeling Styles-Behavioral Modeling

In a typical circuit application, a process will include in its

sensitivity list –all inputs that have asynchronous behavior.

These asynchronous inputs may include:

clock signal(s)

reset signals

inputs to blocks of combinational logic

Synchronous inputs should not be listed in the sensitivity list!

count or register load enable signals

external control input signals

Page 12: Introduction to VHDL #3vvakilian/CourseECE322/LectureNotes/Lecture7,8.pdf · California State University VHDL Modeling Styles-Dataflow Modeling Dataflow modeling- describes how data

California State University

VHDL Modeling Styles-Behavioral Modeling

Example of a sensitivity list: 3-input AND gate

In purely combinational circuits, all

inputs are considered to be

asynchronous and should therefore

appear in the sensitivity list.

Note: Outputs do not show up in

sensitivity lists.

AND3_1 : process (A,B,C)

Page 13: Introduction to VHDL #3vvakilian/CourseECE322/LectureNotes/Lecture7,8.pdf · California State University VHDL Modeling Styles-Dataflow Modeling Dataflow modeling- describes how data

California State University

VHDL Modeling Styles-Behavioral Modeling

The main part of the process block involves a set of sequential

statements, delimited by begin and end

The order of the sequential statements is important!

Statements inside a process block are evaluated in

sequence from first to last.

Process_label : process (sensitivity list)

-- declarations

Begin

-- sequential statements

end process;

Page 14: Introduction to VHDL #3vvakilian/CourseECE322/LectureNotes/Lecture7,8.pdf · California State University VHDL Modeling Styles-Dataflow Modeling Dataflow modeling- describes how data

California State University

VHDL Modeling Styles-Behavioral Modeling

Types of sequential statements that can be used in process

blocks:

simple signal assignment statements

if/then/else

case

for loop

while loop

Note: the last 4 structures can be used only inside process blocks

Page 15: Introduction to VHDL #3vvakilian/CourseECE322/LectureNotes/Lecture7,8.pdf · California State University VHDL Modeling Styles-Dataflow Modeling Dataflow modeling- describes how data

California State University

VHDL Modeling Styles-Behavioral Modeling

You cannot have

Component instantiations

Selected Signal assignments

Conditional Signal assignments

in process blocks!

NOTE!!!

Page 16: Introduction to VHDL #3vvakilian/CourseECE322/LectureNotes/Lecture7,8.pdf · California State University VHDL Modeling Styles-Dataflow Modeling Dataflow modeling- describes how data

California State University

The elsif and else are optional.

The conditions specified in an if-then-else construct must

evaluate to a Boolean signal type.

If/Then/Else statements

if first_condition then

--statements

elsif second_condition then

--statements

else

--statements

end if;

Page 17: Introduction to VHDL #3vvakilian/CourseECE322/LectureNotes/Lecture7,8.pdf · California State University VHDL Modeling Styles-Dataflow Modeling Dataflow modeling- describes how data

California State University

Example: 3_input OR gate

If/Then/Else statements

OR3_1 : process(A,B,C)

begin

F <= ‘0’; if A = ‘1’ then F <= ‘1’; elsif B = ‘1’ then F <= ‘1’; elsif C = ‘1’ then F <= ‘1’; end if;

end process;

Page 18: Introduction to VHDL #3vvakilian/CourseECE322/LectureNotes/Lecture7,8.pdf · California State University VHDL Modeling Styles-Dataflow Modeling Dataflow modeling- describes how data

California State University

Notice that there are multiple assignments to the signal F.

This is allowed!

If/Then/Else statements

OR3_1 : process(A,B,C)

begin

F <= ‘0’; if A = ‘1’ then F <= ‘1’; elsif B = ‘1’ then F <= ‘1’; elsif C = ‘1’ then F <= ‘1’; end if;

end process;

multiple signal assignments

Page 19: Introduction to VHDL #3vvakilian/CourseECE322/LectureNotes/Lecture7,8.pdf · California State University VHDL Modeling Styles-Dataflow Modeling Dataflow modeling- describes how data

California State University

Multiple signal assignments are permitted within a process

block (and only within a process block)

The last assignment to be evaluated in the sequential

evaluation of the statements in the process block is the one

that takes effect.

If/Then/Else statements

Page 20: Introduction to VHDL #3vvakilian/CourseECE322/LectureNotes/Lecture7,8.pdf · California State University VHDL Modeling Styles-Dataflow Modeling Dataflow modeling- describes how data

California State University

OR3_1 : process(A,B,C)

begin

F <= ‘0’; if A = ‘1’ then F <= ‘1’; elsif B = ‘1’ then F <= ‘1’; elsif C = ‘1’ then F <= ‘1’; end if;

end process;

The first statement in the process block of the example is

there to prevent the occurrence of implied memory.

If/Then/Else statements

if not present, the circuit would

hold the value of F when A=B=C=0

Page 21: Introduction to VHDL #3vvakilian/CourseECE322/LectureNotes/Lecture7,8.pdf · California State University VHDL Modeling Styles-Dataflow Modeling Dataflow modeling- describes how data

California State University

It is better to provide default values for combinational outputs

rather than using an ending else clause as it is easier to read

and less prone to error.

If/Then/Else statements

OR3_1 : process(A,B,C)

begin

if A = ‘1’ then F <= ‘1’; elsif B = ‘1’ then F <= ‘1’; elsif C = ‘1’ then F <= ‘1’; else F <= ‘0’; end if;

end process;

Not a good approach!

Page 22: Introduction to VHDL #3vvakilian/CourseECE322/LectureNotes/Lecture7,8.pdf · California State University VHDL Modeling Styles-Dataflow Modeling Dataflow modeling- describes how data

California State University

You can have multiple process blocks, so -

Divide your circuit into a number of functional blocks (like

components) and use a separate process block to describe

each one.

blk1 blk2 blk3

A

B

C X

Y

Z Q

VHDL Modeling Styles-Behavioral Modeling

Page 23: Introduction to VHDL #3vvakilian/CourseECE322/LectureNotes/Lecture7,8.pdf · California State University VHDL Modeling Styles-Dataflow Modeling Dataflow modeling- describes how data

California State University

VHDL Modeling Styles-Behavioral Modeling

blk1 : process(A,B,C) -- 2 input OR and AND gates

begin

X <= A or B;

Y <= C and B;

end process;

blk2 : process(X,Y,A) -- 3 input OR gate

begin

Z <= X or Y or A;

end process;

blk3 : process(Z,B) -- implement a latch

begin

if Z = ‘1’ then Q <= B; end if; end process;

Page 24: Introduction to VHDL #3vvakilian/CourseECE322/LectureNotes/Lecture7,8.pdf · California State University VHDL Modeling Styles-Dataflow Modeling Dataflow modeling- describes how data

California State University

VHDL Modeling Styles-Behavioral Modeling

Architecture EX1 of DSD is

Signal A,B,X,Y,Z : std_logic;

Begin

process(X,Y,A)

begin

Z <= X or Y or A;

Y <= X and A;

end process;

process(Z,B)

begin

if Z = ‘1’ then Y <= B; end if; end process;

The following VHDL code is incorrect. WHY?

Page 25: Introduction to VHDL #3vvakilian/CourseECE322/LectureNotes/Lecture7,8.pdf · California State University VHDL Modeling Styles-Dataflow Modeling Dataflow modeling- describes how data

California State University

VHDL Modeling Styles-Behavioral Modeling

The code on the previous slide is in error because there is

more than 1 assignment to the signal Y outside of a process

block!

process(X,Y,A)

begin

Z <= X or Y or A;

Y <= X and A;

end process;

blk3 : process(Z,B)

begin

if Z = ‘1’ then Y <= B; end if; end process;

multiple signal assignments

Page 26: Introduction to VHDL #3vvakilian/CourseECE322/LectureNotes/Lecture7,8.pdf · California State University VHDL Modeling Styles-Dataflow Modeling Dataflow modeling- describes how data

California State University

VHDL Modeling Styles-Behavioral Modeling

You can have multiple assignments to a signal within a

process block, since only one assignment actually takes

effect.

This is not true outside of a process block!

In effect, the multiple assignments in a process count as a

single concurrent assignment statement.

Page 27: Introduction to VHDL #3vvakilian/CourseECE322/LectureNotes/Lecture7,8.pdf · California State University VHDL Modeling Styles-Dataflow Modeling Dataflow modeling- describes how data

California State University

Case Statements

Case statements are a type of control statement that can be

used as alternatives to if-then-else constructs.

The two test expressions are allowed to be true at the same time.

Case statements must also include all possible conditions of the

control expression. (The others expression can be used to guarantee

that all conditions are covered.)

case control_expression is

when test_expression1 =>

-- statements

when test_expression2 =>

-- statements

when others

-- statements

end case;

Page 28: Introduction to VHDL #3vvakilian/CourseECE322/LectureNotes/Lecture7,8.pdf · California State University VHDL Modeling Styles-Dataflow Modeling Dataflow modeling- describes how data

California State University

Case Statements

The case statement is much like the selected signal

assignment statement.

Their syntax is different however, so be careful to use the

appropriate one.

Inside process block - case statements

Outside process block - selected assignment

Page 29: Introduction to VHDL #3vvakilian/CourseECE322/LectureNotes/Lecture7,8.pdf · California State University VHDL Modeling Styles-Dataflow Modeling Dataflow modeling- describes how data

California State University

Case Statements

entity MUX4_1 is

port (

i0,i1,i2,i3 : in std_logic;

sel : in std_logic_vector(1 downto 0);

bitout : out std_logic);

end MUX4_1;

architecture Behavioral of MUX4_1 is

begin

process(i0,i1,i2,i3,sel)

begin

case sel is

when "00" => bitout <= i0;

when "01" => bitout <= i1;

when "10" => bitout <= i2;

when others => bitout <= i3;

end case;

end process;

end Behavioral;