computer-aided digital system design vhdlalum.sharif.ir/~rajaei/lec4.pdf · modeling styles 3...

42
VHDL Ramin Rajaei [email protected] Computer-Aided Digital System Design م حی ر ل ن ا حم ر ل ا م ا بسIran University of Science and Technology Department of Computer Engineering

Upload: others

Post on 30-Apr-2020

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Computer-Aided Digital System Design VHDLalum.sharif.ir/~rajaei/Lec4.pdf · Modeling Styles 3 Sequential vs. Concurrent Statements VHDL provides two different types of execution:

VHDL

Ramin Rajaei

[email protected]

Computer-Aided Digital System Design

بسم اهلل الرحمن الرحیم

Iran University of Science and Technology Department of Computer Engineering

Page 2: Computer-Aided Digital System Design VHDLalum.sharif.ir/~rajaei/Lec4.pdf · Modeling Styles 3 Sequential vs. Concurrent Statements VHDL provides two different types of execution:

Modeling Styles

2

From the level of abstraction systems can be described in there types:

1. Behavioral

2. Dataflow

3. Structural

© Dr. Ramin Rajaei, CAD

VHDL Hierarchy

Page 3: Computer-Aided Digital System Design VHDLalum.sharif.ir/~rajaei/Lec4.pdf · Modeling Styles 3 Sequential vs. Concurrent Statements VHDL provides two different types of execution:

Modeling Styles

3

Sequential vs. Concurrent Statements

VHDL provides two different types of execution: sequential and concurrent.

Different types of execution are useful for modeling of real hardware.

Supports various levels of abstraction.

Sequential statements view hardware from a “programmer” approach.

Concurrent statements are order-independent and asynchronous.

© Dr. Ramin Rajaei, CAD

Page 4: Computer-Aided Digital System Design VHDLalum.sharif.ir/~rajaei/Lec4.pdf · Modeling Styles 3 Sequential vs. Concurrent Statements VHDL provides two different types of execution:

Examples for Architecture Declaration

4 © Dr. Ramin Rajaei, CAD

Sequential (behavioral) Style Data flow Style

Structural Style

Page 5: Computer-Aided Digital System Design VHDLalum.sharif.ir/~rajaei/Lec4.pdf · Modeling Styles 3 Sequential vs. Concurrent Statements VHDL provides two different types of execution:

Behavioral

© Dr. Ramin Rajaei, CAD 5

We can describe a system in terms of processing it performs on its input signals and the type of output it signals it produces.

Example :

LIBRARY ieee; USE ieee.std_logic_1164.ALL; ENTITY eq_comp4 is PORT( a,b : in std_logic_vector(3 downto 0); equals : out std_logic); END ; ARCHITECTURE behvioral OF eq_comp4 IS BEGIN comp: PROCESS (a,b) BEGIN IF (a=b) then equals <= '1'; Else equals <= '0'; END IF; END PROCESS comp; END behvioral;

Page 6: Computer-Aided Digital System Design VHDLalum.sharif.ir/~rajaei/Lec4.pdf · Modeling Styles 3 Sequential vs. Concurrent Statements VHDL provides two different types of execution:

Data Flow

© Dr. Ramin Rajaei, CAD 6

Dataflow architecture specifies how data will be transferred from signal to signal and input to input without the sequential statements.

Primary difference is that behavioral uses processes while dataflow does not.

The other main difference between dataflow and behavioral architectures is that the body of the process statement contains only sequential statements.

Example: library ieee; use ieee.std_logic_1164.all; entity eq_comp4 is port ( a,b : in std_logic_vector(3 downto 0); equals : out std_logic); end eq_comp4; architecture bool of eq_comp4 is begin equals <= not (a(0) xor b(0)) and not (a(1) xor b(1)) and not (a(2) xor b(2)) and not (a(3) xor b(3)); end bool;

Page 7: Computer-Aided Digital System Design VHDLalum.sharif.ir/~rajaei/Lec4.pdf · Modeling Styles 3 Sequential vs. Concurrent Statements VHDL provides two different types of execution:

Structural

© Dr. Ramin Rajaei, CAD 7

One way to describe a system is to describe component chips and the interconnections assuming that the user is familiar with it.

This kind of definition is the structural definition.

library ieee; use ieee.std_logic_1164.all; entity full_adder is port( a,b,ci : in std_logic; sum,co : out std_logic); end full_adder; architecture bool of full_adder is signal s1,s2,s3 : std_ulogic; begin u0: s1 <= (a xor b); u1: s2 <= (ci and s1); u2: s3 <= (a and b); u3: sum <= (s1 xor ci); u4 : co <= (s2 or s3); end bool;

Example:

What circuit this architecture means?

Page 8: Computer-Aided Digital System Design VHDLalum.sharif.ir/~rajaei/Lec4.pdf · Modeling Styles 3 Sequential vs. Concurrent Statements VHDL provides two different types of execution:

Standard VHDL operators

Logical - defined for type BIT

AND, NAND OR, NOR XOR, XNOR NOT

Relational - defined for types BIT, BIT_VECTOR, INTEGER = (equal to) =/ (not equal to) < (less than) <= (less than or equal to) > (greater than) >= (greater than or equal to)

© Dr. Ramin Rajaei, CAD 8

Page 9: Computer-Aided Digital System Design VHDLalum.sharif.ir/~rajaei/Lec4.pdf · Modeling Styles 3 Sequential vs. Concurrent Statements VHDL provides two different types of execution:

Standard VHDL operators

Unary Arithmetic - defined for type INTEGER

- (arithmetic negate)

Arithmetic - defined for type INTEGER

+ (addition)

- (subtraction)

Concatenation - defined for types STRING,

BIT, BIT_VECTOR

&

© Dr. Ramin Rajaei, CAD 9

Page 10: Computer-Aided Digital System Design VHDLalum.sharif.ir/~rajaei/Lec4.pdf · Modeling Styles 3 Sequential vs. Concurrent Statements VHDL provides two different types of execution:

Concurrency

© Dr. Ramin Rajaei, CAD 10

Page 11: Computer-Aided Digital System Design VHDLalum.sharif.ir/~rajaei/Lec4.pdf · Modeling Styles 3 Sequential vs. Concurrent Statements VHDL provides two different types of execution:

Sequential Style Syntax

11 © Dr. Ramin Rajaei, CAD

Assignments are executed sequentially inside processes.

Page 12: Computer-Aided Digital System Design VHDLalum.sharif.ir/~rajaei/Lec4.pdf · Modeling Styles 3 Sequential vs. Concurrent Statements VHDL provides two different types of execution:

A D-Flip Flop

© Dr. Ramin Rajaei, CAD 12

CLK

D Q

DFF CLEAR

Page 13: Computer-Aided Digital System Design VHDLalum.sharif.ir/~rajaei/Lec4.pdf · Modeling Styles 3 Sequential vs. Concurrent Statements VHDL provides two different types of execution:

Sequential Statements

13

• {Signal, Variable} assignments

• Flow control

• if <condition> then <statments>

[elsif <condition> then <statments>]

else <statements>

end if;

• for <range> loop <statments> end loop;

• while <condition> loop <statments> end loop;

• case <condition> is

when <value> => <statements>;

when <value> => <statements>;

when others => <statements>;

• Wait on <signal> until <expression> for <time>;

© Dr. Ramin Rajaei, CAD

Page 14: Computer-Aided Digital System Design VHDLalum.sharif.ir/~rajaei/Lec4.pdf · Modeling Styles 3 Sequential vs. Concurrent Statements VHDL provides two different types of execution:

Data Objects

14

• There are three types of data objects:

• Signals

• Can be considered as wires in a schematic.

• Can have current value and future values.

• Variables and Constants

• Used to model the behavior of a circuit.

• Used in processes, procedures and functions.

© Dr. Ramin Rajaei, CAD

Page 15: Computer-Aided Digital System Design VHDLalum.sharif.ir/~rajaei/Lec4.pdf · Modeling Styles 3 Sequential vs. Concurrent Statements VHDL provides two different types of execution:

Signal Declaration and Assignment

© Dr. Ramin Rajaei, CAD 15

Signals are used for communication between components.

Signals are declared outside the process.

Signals can be seen as real, physical signals.

Some delay must be incurred in a signal assignment.

A key difference between variables and signals is the assignment delay.

Page 16: Computer-Aided Digital System Design VHDLalum.sharif.ir/~rajaei/Lec4.pdf · Modeling Styles 3 Sequential vs. Concurrent Statements VHDL provides two different types of execution:

Variable Declaration and Assignment

16

Variables are used for local storage of data.

Variables are generally not available to multiple components or processes.

All variable assignments take place immediately.

Variables are more convenient than signals for the storage of (temporary) data.

© Dr. Ramin Rajaei, CAD

Page 17: Computer-Aided Digital System Design VHDLalum.sharif.ir/~rajaei/Lec4.pdf · Modeling Styles 3 Sequential vs. Concurrent Statements VHDL provides two different types of execution:

Constant Declaration

© Dr. Ramin Rajaei, CAD 17

A constant can have a single value of a given type.

A constant’s value cannot be changed during the simulation.

Constants declared at the start of an architecture can be used anywhere in the architecture.

Constants declared in a process can only be used inside the specific process.

CONSTANT constant_name : type_name [ : = value]; CONSTANT rise_fall_time : TIME : = 2 ns; CONSTANT data_bus : INTEGER : = 16;

Page 18: Computer-Aided Digital System Design VHDLalum.sharif.ir/~rajaei/Lec4.pdf · Modeling Styles 3 Sequential vs. Concurrent Statements VHDL provides two different types of execution:

Signals vs. Variables

© Dr. Ramin Rajaei, CAD 18

Variable is used when you want to create a serialized code, unlike the normal parallel code.

A variable, can exist only inside a process, and the assignment of values is not parallel. For example, the fallowing code:

Page 19: Computer-Aided Digital System Design VHDLalum.sharif.ir/~rajaei/Lec4.pdf · Modeling Styles 3 Sequential vs. Concurrent Statements VHDL provides two different types of execution:

Signals vs. Variables

© Dr. Ramin Rajaei, CAD 19

entity sig_var is port (In1: in std_logic; In2: in std_logic; out1: out std_logic); end sig_var;

architecture Behavioral of sig_var is begin process(In1, In2) variable a, b: std_logic; begin a := In1 and In2; b := a and In2; out1 <= b and In2; end process; end Behavioral;

Page 20: Computer-Aided Digital System Design VHDLalum.sharif.ir/~rajaei/Lec4.pdf · Modeling Styles 3 Sequential vs. Concurrent Statements VHDL provides two different types of execution:

Signals vs. Variables

© Dr. Ramin Rajaei, CAD 20

entity sig_var is port (In1: in std_logic; In2: in std_logic; out1: out std_logic); end sig_var;

architecture Behavioral of sig_var is signal a, b: std_logic; begin process(In1, In2) begin a <= In1 and In2; b <= a and In2; out1 <= b and In2; end process; end Behavioral;

Page 21: Computer-Aided Digital System Design VHDLalum.sharif.ir/~rajaei/Lec4.pdf · Modeling Styles 3 Sequential vs. Concurrent Statements VHDL provides two different types of execution:

Signals vs. Variables

© Dr. Ramin Rajaei, CAD 21

entity sig_var is port (In1: in std_logic; In2: in std_logic; out1: out std_logic); end sig_var;

architecture Behavioral of sig_var is signal a, b: std_logic; begin a <= In1 and In2; b <= a and In2; out1 <= b and In2; end Behavioral;

Page 22: Computer-Aided Digital System Design VHDLalum.sharif.ir/~rajaei/Lec4.pdf · Modeling Styles 3 Sequential vs. Concurrent Statements VHDL provides two different types of execution:

Signal vs Variable: synthesis

© Dr. Ramin Rajaei, CAD 22

entity sig_var is port (clk: in std_logic; Din: in std_logic_vector (3 downto 0); out1: out std_logic_vector (3 downto 0)); end sig_var;

architecture Behavioral of sig_var is signal a, b: std_logic_vector (3 downto 0); begin process(clk) begin if (rising_edge(clk)) then a <= Din; b <= a; end if; end process; out1 <= b; end Behavioral;

Page 23: Computer-Aided Digital System Design VHDLalum.sharif.ir/~rajaei/Lec4.pdf · Modeling Styles 3 Sequential vs. Concurrent Statements VHDL provides two different types of execution:

Signal vs Variable: synthesis

© Dr. Ramin Rajaei, CAD 23

entity sig_var is port (clk: in std_logic; Din: in std_logic_vector (3 downto 0); out1: out std_logic_vector (3 downto 0)); end sig_var;

architecture Behavioral of sig_var is signal a, b: std_logic_vector (3 downto 0); begin process(clk) begin if (rising_edge(clk)) then a <= Din; b <= a; out1 <= b; end if; end process; end Behavioral;

Page 24: Computer-Aided Digital System Design VHDLalum.sharif.ir/~rajaei/Lec4.pdf · Modeling Styles 3 Sequential vs. Concurrent Statements VHDL provides two different types of execution:

IF – vs. CASE – statement Syntax

© Dr. Ramin Rajaei, CAD 24

Page 25: Computer-Aided Digital System Design VHDLalum.sharif.ir/~rajaei/Lec4.pdf · Modeling Styles 3 Sequential vs. Concurrent Statements VHDL provides two different types of execution:

FOR – vs. WHILE – statement Syntax

© Dr. Ramin Rajaei, CAD 25

For is considered to be a combinational circuit by some synthesis tools. Thus, it cannot have a wait statement to be synthesized.

While is considered to be an FSM by some synthesis tools. Thus, it needs a wait statement to be synthesized.

Page 26: Computer-Aided Digital System Design VHDLalum.sharif.ir/~rajaei/Lec4.pdf · Modeling Styles 3 Sequential vs. Concurrent Statements VHDL provides two different types of execution:

WAIT – statement Syntax

© Dr. Ramin Rajaei, CAD 26

• The wait statement causes the suspension of a process statement or a procedure.

• wait [sensitivity_clause] [condition_clause] [timeout_clause];

• Sensitivity_clause ::= on signal_name

wait on CLOCK;

• Condition_clause ::= until boolean_expression

wait until Clock = ‘1’;

• Timeout_clause ::= for time_expression

wait for 150 ns;

wait until clk’event and clk= ‘1’;

wait until rising_edge(clk);

Page 27: Computer-Aided Digital System Design VHDLalum.sharif.ir/~rajaei/Lec4.pdf · Modeling Styles 3 Sequential vs. Concurrent Statements VHDL provides two different types of execution:

Sensitivity-lists vs Wait-on - statement

© Dr. Ramin Rajaei, CAD 27

Page 28: Computer-Aided Digital System Design VHDLalum.sharif.ir/~rajaei/Lec4.pdf · Modeling Styles 3 Sequential vs. Concurrent Statements VHDL provides two different types of execution:

Example

© Dr. Ramin Rajaei, CAD 28

entity process_example is Port ( clk : in STD_LOGIC; D1, D2: in std_logic; reset: in std_logic; out1 : out STD_LOGIC; out2 : out STD_LOGIC); end process_example; architecture Behavioral of process_example is begin process begin if reset = '1' then out1 <= '0'; else out1 <= D1; end if; if rising_edge(clk) then out2 <= D2; end if; end process; end Behavioral;

Page 29: Computer-Aided Digital System Design VHDLalum.sharif.ir/~rajaei/Lec4.pdf · Modeling Styles 3 Sequential vs. Concurrent Statements VHDL provides two different types of execution:

Example (cont.)

© Dr. Ramin Rajaei, CAD 29

entity process_example is Port ( clk : in STD_LOGIC; D1, D2: in std_logic; reset: in std_logic; out1 : out STD_LOGIC; out2 : out STD_LOGIC); end process_example; architecture Behavioral of process_example is begin process begin wait until rising_edge (clk); if reset = '1' then out1 <= '0'; else out1 <= D1; end if; out2 <= D2; end process; end Behavioral;

Page 30: Computer-Aided Digital System Design VHDLalum.sharif.ir/~rajaei/Lec4.pdf · Modeling Styles 3 Sequential vs. Concurrent Statements VHDL provides two different types of execution:

Example (cont.)

© Dr. Ramin Rajaei, CAD 30

Error message: line 36: Bad condition in wait statement, or only one clock per process.

Page 31: Computer-Aided Digital System Design VHDLalum.sharif.ir/~rajaei/Lec4.pdf · Modeling Styles 3 Sequential vs. Concurrent Statements VHDL provides two different types of execution:

Concurrent Process Equivalents

© Dr. Ramin Rajaei, CAD 31

• All concurrent statements correspond to a process equivalent.

U0: q <= a xor b after 5 ns;

is short hand notation for

U0: process

begin

q <= a xor b after 5 ns;

wait on a, b;

end process;

Page 32: Computer-Aided Digital System Design VHDLalum.sharif.ir/~rajaei/Lec4.pdf · Modeling Styles 3 Sequential vs. Concurrent Statements VHDL provides two different types of execution:

Structural Statements

© Dr. Ramin Rajaei, CAD 32

The component instantiation is one of the building blocks of structural descriptions.

The component instantiation process requires component declarations and component instantiation statements.

Component instantiation declares the interface of the components used in the architecture.

At instantiation, only the interface is visible. The internals of the component are hidden.

Page 33: Computer-Aided Digital System Design VHDLalum.sharif.ir/~rajaei/Lec4.pdf · Modeling Styles 3 Sequential vs. Concurrent Statements VHDL provides two different types of execution:

Component Declaration and Instantiation

33

• The component declaration declares the interface of the component to the architecture.

• Necessary if the component interface is not declared elsewhere (package, library).

The instantiation statement maps the interface of the component to other objects in the architecture.

© Dr. Ramin Rajaei, CAD

Page 34: Computer-Aided Digital System Design VHDLalum.sharif.ir/~rajaei/Lec4.pdf · Modeling Styles 3 Sequential vs. Concurrent Statements VHDL provides two different types of execution:

Component Instantiation Syntax

34

• The instantiation has 3 key parts

• Name

• Component type

• Port map

© Dr. Ramin Rajaei, CAD

Page 35: Computer-Aided Digital System Design VHDLalum.sharif.ir/~rajaei/Lec4.pdf · Modeling Styles 3 Sequential vs. Concurrent Statements VHDL provides two different types of execution:

Examples:

© Dr. Ramin Rajaei, CAD 35

architecture first of add4 is begin s <= a + b; -- works with std_logic_vector or integer end; architecture second of add4 is signal c: std_logic_vector(2 downto 0); begin s(0) <= a(0) XOR b(0); c(0) <= a(0) AND b(0); s(1) <= a(1) XOR (b(1) XOR c(0)); c(1) <= ….. end add4;

Page 36: Computer-Aided Digital System Design VHDLalum.sharif.ir/~rajaei/Lec4.pdf · Modeling Styles 3 Sequential vs. Concurrent Statements VHDL provides two different types of execution:

Example: n-bit Comparator

© Dr. Ramin Rajaei, CAD 36

library ieee;

use ieee.std_logic_1164.all

entity Comparator is

port( A: in std_logic_vector(1 downto 0);

B: in std_logic_vector(1 downto 0);

less: out std_logic;

equal: out std_logic;

greater: out std_logic );

end Comparator;

architecture behv of Comparator is Begin process(A,B) Begin if (A<B) then less <= '1'; equal <= '0'; greater <= '0'; elsif (A=B) then less <= '0'; equal <= '1'; greater <= '0'; else less <= '0'; equal <= '0'; greater <= '1'; end if; end process; end behv;

Page 37: Computer-Aided Digital System Design VHDLalum.sharif.ir/~rajaei/Lec4.pdf · Modeling Styles 3 Sequential vs. Concurrent Statements VHDL provides two different types of execution:

More Examples for Review

37 © Dr. Ramin Rajaei, CAD

Page 38: Computer-Aided Digital System Design VHDLalum.sharif.ir/~rajaei/Lec4.pdf · Modeling Styles 3 Sequential vs. Concurrent Statements VHDL provides two different types of execution:

Example:

38 © Dr. Ramin Rajaei, CAD

Page 39: Computer-Aided Digital System Design VHDLalum.sharif.ir/~rajaei/Lec4.pdf · Modeling Styles 3 Sequential vs. Concurrent Statements VHDL provides two different types of execution:

Synthesis Result

39 © Dr. Ramin Rajaei, CAD

Page 40: Computer-Aided Digital System Design VHDLalum.sharif.ir/~rajaei/Lec4.pdf · Modeling Styles 3 Sequential vs. Concurrent Statements VHDL provides two different types of execution:

Example:

40 © Dr. Ramin Rajaei, CAD

entity reg4 is port (clk, clr : in bit; d : in bit_vector(0 to 3); q : out bit_vector(0 to 3); end entity reg4; architecture struct of reg4 is component flipflop is generic (Tprop, Tsetup, Thold : delay_length); port ( clk, clr, d : in bit; q : out bit); end component flipflop; begin bit0: component flipflop generic map ( Tprop => 2 ns, Tsetup => 2ns, Thold => 1ns) port map ( clk => clk, clr => clr, d => d(0), q => q(0) ); bit1: component flipflop generic map ( Tprop => 2 ns, Tsetup => 2ns, Thold => 1ns) port map ( clk => clk, clr => clr, d => d(1), q => q(1) ); bit2: component flipflop generic map ( Tprop => 2 ns, Tsetup => 2ns, Thold => 1ns) port map ( clk => clk, clr => clr, d => d(2), q => q(2) ); bit3: component flipflop generic map ( Tprop => 2 ns, Tsetup => 2ns, Thold => 1ns) port map ( clk => clk, clr => clr, d => d(3), q => q(3) ); end architecture struct;

Page 41: Computer-Aided Digital System Design VHDLalum.sharif.ir/~rajaei/Lec4.pdf · Modeling Styles 3 Sequential vs. Concurrent Statements VHDL provides two different types of execution:

Example: Array of AND-gates

© Dr. Ramin Rajaei, CAD 41

Page 42: Computer-Aided Digital System Design VHDLalum.sharif.ir/~rajaei/Lec4.pdf · Modeling Styles 3 Sequential vs. Concurrent Statements VHDL provides two different types of execution:

Next Sessions:

© Dr. Ramin Rajaei, CAD 42

In Lec-5, we will have a tutorial for Modelsim.

And also

Exercise 2