Chapter 7
Chapter 7
ELEC261
Lecture 7 Prof. F Bensaali
Content:
• Synthesis vs. Simulation
• Modelling styles
o Concurrent signal assignments
o Components and instantiation
o The process statement
o Sequential statements
o Behavioural style
o Dataflow style
o Structural style
2
Synthesis vs. Simulation
Modelling styles
VHLD is both, a Synthesis language and a Simulation
language
o Small subset of the language is ‘synthesizable’, i.e., it can be
translated into logic gates, and other ‘hardware’ components
o Another subset of the language includes many features for
‘simulation’ or ‘verification’, features that have NO meaning in
hardware
3
Modelling styles
Modelling styles
Modeling styles
4
Concurrent signal
Concurrent signal assignments
assignments
5
Simple signal
Simple signal assignments
assignments
Solution
entity My_OR3 is
port( A: in std_logic;
B: in std_logic;
C: in std_logic;
F: out std_logic
A
);
B My_OR3 F End My_OR3;
C
architecture behavioral of My_OR3 is
begin
F <= A or B or C;
end behavioral
7
Simple signal
Simple signal assignments
assignments (Cont’d)
(Cont’d)
L M N F
Exercise
0 0 0 0
Write the VHDL code to 0 0 1 1
implement the function 0 1 0 0
expressed in the following 0 1 1 0
truth table using simple 1 0 0 0
signal assignments 1 0 1 0
1 1 0 1
1 1 1 1
L Entity??
M My_F F F = ?? Architecture??
N
Signal Assignment ??
8
Simple signal
Simple signal assignments
assignments (Cont’d)
(Cont’d)
Alternative architecture:
architecture f_2 of my_f is
begin
F <= ((not L) and (not M) and N) or (L and M);
end f_2;
9
Conditional signal
Conditional signal assignment
assignment
2
sel
10
Conditional signal
Conditional signal assignment
assignment (Cont’d)
(Cont’d)
Solution
entity my_4to1_mux is
port ( D3,D2,D1,D0 : in std_logic;
SEL : in std_logic_vector(1 downto 0);
D0 MX_OUT : out std_logic);
end my_4to1_mux;
D1
My_4to1_
mx_out
D2 mux architecture mux4to1 of my_4to1_mux is
D3
begin
MX_OUT <= D3 when (SEL = "11") else
2 D2 when (SEL = "10") else
sel D1 when (SEL = "01") else
D0 when (SEL = "00") else
'0' ;
end mux4to1;
11
Selectedsignal
Selected signalassignments
assignment
These are of the form
with choose_expression select
target <= expression_1 when choices_1,
expression_2 when choices_2,
...
expression_n when choices_n[others];
13
Components &
Components & instantiation
instantiation (Cont’d)
(Cont’d)
entity entity_name is
port( input signals: in type;
Construct one component output signals: out type );
declaration for each unique end entity_name;
architecture arch_name of entity_name is
component that the model will
-- declare components used
use component component1_name is
port( input signals: in type;
o Can be easily constructed output signals: out type );
from the component entity end component;
statement is written using the -- declare all signals used to connect the components
there are ports on the Label1: component1_name port map (port => signal, ...);
Label2: component2_name port map (port => signal, ...);
component end arch_name;
14
Components &
Components & instantiation
instantiation (Cont’d)
(Cont’d)
B
a1 b1
b2 A b5
A a3
a2 b3 b6
b4
A
entity B_entity is
port( b1, b2, b3, b4: in std_logic;
b5, b6: out std_logic
entity A_entity is );
port( a1, a2: in std_logic; end B_entity;
a3: out std_logic architecture B_arch of B_entity is
);
end A_entity;
component
componentA_entity;
A_entity is
architecture A_arch of A_entity is port(
port( a1,
a1,a2:
a2:ininBit;
std_logic;
begin a3:
a3:out
outBit
std_logic
-- architecture description; ););
end A_arch; end
endcomponent;
component;
Begin
B_1: A_entityport
B1: A_entity portmap
map(b1,
(b1,b2,
b2,b5);
b5);
B_2:
B1: A_entity portmap
A_entityport map(b3,
(b3,b3,
b4,b6);
b6);
end B_arch;
15
Components &
Components & instantiation
instantiation (Cont’d)
(Cont’d)
Exercise
X
Y
a W
b c
Z
Entity?? Entity ??
Architecture?? Component ??
Architecture ??
16
Components &
Components & instantiation
instantiation (Cont’d)
(Cont’d)
X a
c
a Y b
b c a
c W
a b
c
Z b
entity my_Circuit is
port( X, Y, Z: in std_logic;
W: out std_logic
entity and_gate is );
port( a, b: in std_logic; end my_Circuit ;
c: out std_logic architecture my_Circuit _arch of my_Circuit is
);
end and_gate; signal g1, g2 : std_logic;
component and_gate is
architecture and_gate_arch of and_gate is port( a,b: in std_logic;
begin c: out std_logic
c <= a and b; );
end and_gate_arch; end component;
Begin
n1: and_gate port map (X, Y, g1);
n2: and_gate port map (Y, Z, g2);
n3: and_gate port map (g1, g2, W);
end my_Circuit _arch;
17
The process
The process statement
statement
18
The The
process statement
process (Cont’d)
statement
A process can be given a unique name using
an optional LABEL
Example
architecture Behavioural of XOR3 is
begin
XOR3_Proc: process (A, B, C)
begin
A if ((A xor B xor C) = '1') then
B D D <= '1';
C else
D <= '0';
end if;
end process XOR3_Proc;
Execution is controlled by end Behavioural;
changes to A, B and C signals
20
Sequential statements
Sequential statements
IF statement
CASE statement
Loops
o FOR
o WHILE (not synthesisable)
o LOOP
21
IF statement
IF statement
Syntax: Example
22
IF statement
IF statement (Cont’d)
(Cont’d)
Solution
entity my_if_ex is
port ( A,B,C : in std_logic;
F: out std_logic);
end my_if_ex;
architecture exercise2 of my_if_ex is
begin
proc: process (A, B, C)
begin
if (A = '0' and B = '0' and C = '1') then
F <= '1'; F ( A, B, C ) = ABC + BC
elsif (B = '1' and C = '1') then
F <= '1';
else
F <= '0';
end if;
end process proc1;
end exercise2;
23
IF statement
IF statement (Cont’d)
(Cont’d)
Exercise
Implement an 8:1 MUX using IF statement
Data_in mux_out
8
Architecture??
3
SEL
entity mux_8to1 is
port ( Data_in : in std_logic_vector (7 downto 0);
SEL : in std_logic_vector (2 downto 0);
mux_out : out std_logic);
end mux_8to1;
24
IF statement
IF statement (Cont’d)
(Cont’d)
Solution
Data_in mux_out
8
25
CASE statement
CASE statement
Syntax: Example
Previous 8:1 MUX using CASE
case <expression> is statement
when <choice(s)> => statements;
architecture my_case_ex of mux_8to1 is
…
when … begin
my_proc: process (Data_in, SEL)
[ when others => statements;]
begin
case (SEL) is
end case; when "000" => mux_out <= Data_in(0);
when "001" => mux_out <= Data_in(1);
when "010" => mux_out <= Data_in(2);
when "011" => mux_out <= Data_in(3);
when "100" => mux_out <= Data_in(4);
when "101" => mux_out <= Data_in(5);
when "110" => mux_out <= Data_in(6);
when "111" => mux_out <= Data_in(7);
when others => mux_out <= '0';
end case;
end process my_proc;
end my_case_ex;
26
CASE
IF & statement
CASE statement
Exercise
Let’s add a chip enable CE signal to the previous 8:1 MUX:
o When CE is ‘1’, the MUX output is as in last example
o When CE is ‘0’ the MUX output is ‘0’
Data_in mux_out
8
Architecture using
3
IF & CASE
SEL CE statements ??
entity mux_8to1 is
port ( Data_in : in std_logic_vector (7 downto 0);
SEL : in std_logic_vector (2 downto 0);
CE: in std_logic;
mux_out : out std_logic);
end mux_8to1;
27
IF &
IF & CASE
CASE statement
statement (Cont’d)
(Cont’d)
28
Loops
Loops
Sequences of statements can be repeated some number of times
under the control of WHILE, FOR or LOOP constructs
[label:] for loop_variable in starting_value to stopping_value loop
sequence of statements
end loop [label];
Example
29
Loop termination
Loop termination statement
statement
Example
variable sum, cnt: integer;
begin
sum := 0; cnt := 0;
first: loop
cnt := cnt + 1;
sum := sum + cnt;
exit when (sum > 100) ;
end loop first;
second: loop
cnt := cnt + 1;
sum := sum + cnt;
if (sum > 100) then exit;
end if
end loop second;
30
Dataflow modelling
Dataflow modelling style
style
31
Behavioural modelling
Behavioural modelling style
style
C
outputs of the black box (no xor2_out
32
Structural modelling
Structural modelling style
style
33
Structural modelling
Structural modelling style
style (Cont’d)
(Cont’d)
xor xor1
xor2
X A xor1_out
Z
Y B C
xor2_out
entity XOR3 is
port( A, B, C: in std_logic;
xor2_out: out std_logic
);
entity XOR2 is end XOR3;
port( x, y: in std_logic; architecture XOR3_arch of XOR3 is
z: out std_logic
); signal xor1_out : std_logic;
end XOR2; component XOR2 is
port( x,y: in std_logic;
architecture XOR2_arch of XOR2 is z: out std_logic
);
begin
end component;
z <= x xor y;
end XOR_arch; Begin
X1: XOR2 port map (A, B, xor1_out);
X2: XOR2 port map (xor1_out, C, xor2_out);
end XOR3_arch;
34