Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Session seven
1. http://www.bized.co.uk
Session 7
Prepared by
Alaa Salah Shehata
Mahmoud A. M. Abd El Latif
Mohamed Mohamed Tala’t
Mohamed Salah Mahmoud
Version 02 – October 2011
Copyright 2006 – Biz/ed
3. Session 7
http://www.bized.co.uk
the main objective here is to link
between many blocks to get
general block.
Block_1 Structural
description
Block_3
Block_2
3
Copyright 2006 – Biz/ed
4. Session 7
http://www.bized.co.uk
Structural Description
Structural description allows having multiple levels of
hierarchy in the design
Top- Down Design
define general block that has general
inputs and outputs after that we can write
the collection of the mini blocks inside it.
4
Copyright 2006 – Biz/ed
5. Session 7
http://www.bized.co.uk
Structural Description
1) Component declaration
component <component_name>
port ( <port_names>: <mode> <type>;
<port_names>: <mode> <type>;
.
.
.
);
end component;
Note that the definition of the component is like the definition
of the entity Think as Hardware
5
Copyright 2006 – Biz/ed
6. Session 7
http://www.bized.co.uk
Structural Description
2) Component instantiation and Interconnections
instance_name: component_name
port map (signal1,
signal2,…);
each signal is written in the position that describe which port it belongs to
which means that the first signal written here represent the first port in the
component
very important note:
if you needn't use special output port you can write the key word open (that
mean this port will be unconnected).
Think as Hardware
6
Copyright 2006 – Biz/ed
8. Session 7
http://www.bized.co.uk
entity test is
Port ( a : in STD_LOGIC;
b : in STD_LOGIC;
c :
d :
in
in
STD_LOGIC;
STD_LOGIC;
And
f : out STD_LOGIC); gate
end test;
architecture Behavioral of test is Or gate
component or_gate is
Port ( in1 : in STD_LOGIC;
And
in2 : in STD_LOGIC; gate
out_or : out STD_LOGIC);
end component ;
component and_gate is
Port ( in1 : in STD_LOGIC;
in2 : in STD_LOGIC;
out_and : out STD_LOGIC);
end component;
signal sig1,sig2 : std_logic;
begin
u1:and_gate port map (a,b,sig1);
u2:and_gate port map (c,d,sig2);
u3:or_gate port map (sig1,sig2,f);
end Behavioral;
8
Copyright 2006 – Biz/ed
9. Session 7
http://www.bized.co.uk
Structural Description
2) Component instantiation and Interconnections
<instance_name>: <component_name >
port map(
<port_name> => <sig_name>,
<port_name> => <sig_name>,
.
.
.
<port_name> => <sig_name>
);
very important note:
if you needn't use special output port you can write the key word open (that
mean this port will be unconnected).
Think as Hardware
9
Copyright 2006 – Biz/ed
11. Session 7
http://www.bized.co.uk
Entity test is
Port ( a : in STD_LOGIC;
b : in STD_LOGIC;
c : in STD_LOGIC; begin
d : in STD_LOGIC; u1:and_gate
f : out STD_LOGIC);
end test; port map (in1 => a,
in2 => b,
out_and => sig1);
Architecture Behavioral of test is u2:and_gate
component or_gate is port map (in1 => c,
Port ( in1 : in STD_LOGIC; in2 => d,
in2 : in STD_LOGIC; out_and => sig2);
out_or : out STD_LOGIC);
end component ;
u3:or_gate
component and_gate is port map (in1 => sig1,
Port ( in1 : in STD_LOGIC; in2 => sig2,
in2 : in STD_LOGIC; out_or => f);
out_and : out STD_LOGIC);
end component;
signal sig1,sig2 : std_logic; end Behavioral;
11
Copyright 2006 – Biz/ed
13. Session 7
http://www.bized.co.uk
Entity comp4 is
port ( a , b : in std_logic_vector(3 downto 0);
eq : out std_logic
);
End comp4 ;
Architecture struct of comp4 is
Component xnor_2 is
port ( g , f : in std_logic ;
y : out std_logic );
End component ;
Component and_4 is
port ( in1, in2, in3, in4 : in std_logic ;
out : out std_logic );
End component ;
Signal x : std_logic_vector ( 3 downto 0 ) ;
Begin
U1 : xnor_2 port map ( a(0) , b(0) , x(0) ) ;
U2 : xnor_2 port map ( a(1) , b(1) , x(1) ) ;
U3 : xnor_2 port map ( a(2) , b(2) , x(2) ) ;
U4 : xnor_2 port map ( a(3) , b(3) , x(3) ) ;
U5 : and_4 port map ( x(0) , x(1) , x(2) , x(3) , eq ) ;
End struct ;
13
Copyright 2006 – Biz/ed
15. Session 7
http://www.bized.co.uk
Generic Statement
VHDL provides an easy way to create generic design units that can
be used several times with different properties in the design
hierarchy
4-bit
counter
N-bit
counter 8-bit
counter Hardware
Think as
15
Copyright 2006 – Biz/ed
17. Session 7
http://www.bized.co.uk
• Generic AND Gate
Example
30
17
Copyright 2006 – Biz/ed
18. Session 7
http://www.bized.co.uk
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
Entity generic_and is
generic (N : integer := 4 );
port(A, B: in std_logic_vector (N-1 downto 0);
Z : out std_logic_vector(N-1 downto 0) );
End entity;
Architecture behave of generic_and is
Begin
Z <= A and B;
End architecture
18
Copyright 2006 – Biz/ed
19. Session 7
http://www.bized.co.uk
• N-Bit Full Adder
Example
31
19
Copyright 2006 – Biz/ed
20. Session 7
http://www.bized.co.uk
C_in
A
N bit Sum
Full Adder
B
Entity F_adder is
Generic ( N : integer := 4 );
C_out
Port (
A, B : in std_logic_vector(N-1 downto 0) ;
C_in : in std_logic ;
Sum : out std_logic_vector(N-1 downto 0);
C_out : out std_logic
) ;
End F_adder ;
20
Copyright 2006 – Biz/ed
21. Session 7
http://www.bized.co.uk
Architecture struct of f_adder is
Component n_adder
Generic ( N : integer := 4 );
Port (
A, B : in std_logic_vector(N-1 downto 0) ;
C_in : in std_logic ;
Sum : out std_logic_vector(N-1 downto 0);
C_out : out std_logic
) ; C_in
End component ;
Begin
A
U1 : n_adder generic map (8)
port map ( A => acc , N bit Sum
B => b_reg , Full Adder
c_in => E , B
sum => result ,
c_out => carry_out ) ;
End struct
C_out
21
Copyright 2006 – Biz/ed
23. Session 7
http://www.bized.co.uk
Instead of declaring all components can declare all components in a
PACKAGE, and INCLUDE the package once
1) This makes the top-level entity code cleaner
2) It also allows that complete package to be used by another
designer
A package can contain
1) Components
2) Functions, Procedures
3) Types, Constants
23
Copyright 2006 – Biz/ed
24. Session 7
http://www.bized.co.uk
• Logic circuit
by using package
Example
32
24
Copyright 2006 – Biz/ed
25. Session 7
http://www.bized.co.uk
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
And
package logic_circuit is gate
component or_gate is
Port ( in1 : in STD_LOGIC;
Or gate
in2 : in STD_LOGIC;
out_or : out STD_LOGIC); And
end component ; gate
component and_gate is
Port ( in1 : in STD_LOGIC;
in2 : in STD_LOGIC;
out_and : out STD_LOGIC);
end component;
constant const1: STD_LOGIC_vector (3 downto 0) := "0011"; ---const definition
end logic_circuit;
25
Copyright 2006 – Biz/ed
26. Session 7
http://www.bized.co.uk
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
use work.logic_circuit.all; -----definition of the package
entity test is
Port ( a : in STD_LOGIC;
b : in STD_LOGIC;
c : in STD_LOGIC;
d : in STD_LOGIC;
out1: out STD_LOGIC_vector (3 downto 0); And
f : out STD_LOGIC);
end test; gate
architecture Behavioral of test is
signal sig1,sig2 : std_logic; Or gate
begin
u1:and_gate
port map ( in1 => a, And
in2 => b,
out_and => sig1);
gate
u2:and_gate
port map ( in1 => c,
in2 => d,
out_and => sig2);
u3:or_gate
port map ( in1 => sig1,
in2 => sig2,
out_or => f);
out1<= const1; ------- const using
end Behavioral;
26
Copyright 2006 – Biz/ed
28. Session 7
http://www.bized.co.uk
• The generate statement simplifies description of regular design structures.
Usually it is used to specify a group of identical components using just one
component specification and repeating it using the generate mechanism.
For generate declaration :
Label : for identifier IN range GENERATE
(concurrent assignments)
.
.
.
END GENERATE;
28
Copyright 2006 – Biz/ed
29. Session 7
http://www.bized.co.uk
• SEREIS OF XOR GATES
Example
33
29
Copyright 2006 – Biz/ed
30. Session 7
http://www.bized.co.uk
ENTITY parity IS
PORT(
parity_in : IN STD_LOGIC_VECTOR(7 DOWNTO 0);
parity_out : OUT STD_LOGIC
);
END parity;
30
Copyright 2006 – Biz/ed
33. Session 7
http://www.bized.co.uk
ARCHITECTURE parity_dataflow OF parity IS
SIGNAL xor_out: STD_LOGIC_VECTOR (7 DOWNTO 0);
BEGIN
xor_out(0) <= parity_in(0);
G2: FOR i IN 1 TO 7 GENERATE
xor_out(i) <= xor_out(i-1) XOR parity_in(i);
END GENERATE G2;
parity_out <= xor_out(7);
END parity_dataflow;
33
Copyright 2006 – Biz/ed
34. Session 7
http://www.bized.co.uk
• N- BIT REGISTER
Example
34
34
Copyright 2006 – Biz/ed
35. Session 7
http://www.bized.co.uk
reset
si so
r r r r
d q si q d q d q
z0 clk z1 clk z2 clk z3 clk z4
clock
35
Copyright 2006 – Biz/ed