Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Goal: You are able to design circuits with the VHDL We need a way to talk about what hardware should do
language with behavioral, dataflow and structural without actually designing the hardware itself, i.e., need to
modeling. You are familiar with the top down design flow separate functionality from implementation. We need a
and the test-
test-bench methodology. Hardware Description Language
MicroLab, VLSI-21 (1/95) MicroLab, VLSI-21 (2/95)
page 1
The Need for HDLs cont. Hardware Description Languages
page 2
A Tale of Two HDLs Introduction to VHDL & Verilog
VHDL Verilog-
Verilog-HDL
VHSIC HDL, Very High Speed C-like concise syntax
Integrated Circuits. ADA-
ADA-like VHDL Verilog-
Verilog-HDL
verbose syntax, lots of redundancy
rich & powerful simple & efficient
Extensible types and Built-
Built-in types and logic language language
simulation engine. Logic representations. Oddly,
representations are not this has led to slightly data type driven hardware driven
built in and have evolved incompatible simulators language language
with time (IEEE-
(IEEE-1164). from different vendors.
goal: documentation of goal: automatic
Design is composed of Design is composed of
large complex systems synthesis
entities each of which can have modules.
modules.
multiple architectures.
architectures. A
configuration chooses what language structures language structures
architecture is used for a given entity (hierarchy module (blocks or sub-
sub-
instance of an entity. interface) blocks)
architecture (behavior #include (file
Behavioral, structural, Behavioral, structural, of system) structuring)
logic-
logic-level modeling logic-
logic-level modeling
configuration (binding
Synthesizable subset... Synthesizable subset... of entity and
architecture)
Harder to learn and use, Easy to learn and use,
not technology-
technology-specific, fast simulation, good for package (library of
DoD mandate. logic. Gateway Design global types or
Automation blocks)
MicroLab, VLSI-21 (5/95) MicroLab, VLSI-21 (6/95)
page 3
chapter 2 (starter)
VHDL b
sum
carry
time (ns)
5 10 15 20 25 30 35 40
page 4
Signal Values Resolved Signals
it is common for components in a digital system to
signal values are physically associated to wires have multiple sources for the value of an input
VHDL language supports signal type: signal
type: bit, values: ‘0’, ‘1’ many designs use buses:
buses: a group of signals that can
be shared among multiple sources
type: bit_vector, values: “0001”, etc
the values on shared signals will be determined
VHDL package IEEE 1164 supports signal type: upon the type of interconnection, like wired logic
type: std_ulogic and vector std_ulogic_vector the signal values depend on its implementation
std_ulogic is a 9 value logic
the
the VHDL simulator has to resolve the signals value
The
The IEEE 1164 package offers std_logic and
value interpretation std_logic_vector signal types for resolved version
of the signal std_ulogic and std_ulogic_vector
U un-
un-initialized
X forcing unknown
0 forcing 0 resolved signal necessary
1 forcing 1 wired-
wired-or logic
Z high impedance
W weak unknown
L weak 0
H weak 1 unresolved signal
- don’t care
page 5
chapter 3 (starter)
the design entity is a primary programming Ex401 (difficulty: easy): Define the entities of the
abstraction in VHDL following digital components. Use the unresolved 9
entity defines the interface of a component, without value logic of the IEEE 1164 package. Each
giving any information about the component component has to be edited in a separate file with
behavior the components name plus extension “.vhd
“.vhd”
vhd” . The
files have to be analyzed by the Synopsys command:
vhdlan
a sum
sNot
+
b carry i0
Mux4to1 d q
i1 D_ff
z
entity HalfAdder is i2 clk qNot
port (a,b : in bit;
bit i3
sum,carry : out bit);
bit
end HalfAdder; sel rNot
8 bit data
library IEEE; n z
use IEEE.std_logic_1164.all; a
32 bit data Alu32
entity HalfAdder is 6 bit op-
op-code c
port (a,b : in std_ulogic; use first letter of
b component name in capital,
sum,carry : out std_ulogic);
op and first letter of signal
end HalfAdder;
name in small cap
MicroLab, VLSI-21 (11/95) MicroLab, VLSI-21 (12/95)
page 6
Architecture Entity-
Entity-Architecture: Hierarchy
(VHDL vs. Verilog)
Verilog)
the design architecture is a primary programming
abstraction in VHDL +
page 7
Concurrency Dataflow Model #1
5 10 15 20 25 30 35 40
MicroLab, VLSI-21 (15/95) MicroLab, VLSI-21 (16/95)
page 8
Dataflow Model #2 Signal Assignments #1
s1
L1
L4
+ simple signal assignments
L2 s2
L5
L3 s3
sum<=(a xor b) after 5 ns, (a or b) after 10 ns, (not a) after 15 ns;
sig <= ‘0’, ‘1’ after 10 ns, ‘0’ after 20 ns, ‘1’ after 40 ns;
library IEEE;;
use IEEE.std_logic_1164.all; time (ns)
5 10 15 20 25 30 35 40
entity FullAdder is
port (a,b,cIn: in std_logic; clock <= ‘0’, not(clock) after 5 ns;
cOut,sum: out std_logic);
end FullAdder;
time (ns)
architecture architecture dataflow of FullAdder is
declarative signal s1,s2,s3 : std_logic; 5 10 15 20 25 30 35 40
constant gate_delay: Time:=5 ns;ns
segment begin a <= “00000000_00000000”, to_stdlogicvector(x”abcd”) after 5 ns;
L1: s1 <= (a xor b) after gate_delay;
L2: s2 <= (cIn and s1) after gate_delay;
Type conversion from hexadecimal
architecture L3: s3 <= (a and b) after gate_delay; to std_logic_vector is defined in
body L4: sum <= (s1 xor cIn) after gate_delay; package std_logic_1164
L5: cOut <= (s2 or s3) after gate_delay;
end dataflow; goto UNIX directory, where packages are placed:
cd $SYNOPSYS/packages/IEEE/src
MicroLab, VLSI-21 (17/95) MicroLab, VLSI-21 (18/95)
page 9
Conditional Signal Assignment #2 Exercises Ex402: Conditional Signal
Assignment
The right hand value is computed immediately and Ex402 (difficulty: easy): Define the VHDL code of
assigned at some point in the future using the after a 1bit ALU with the operations: AND, OR,
clause FullAdder.
FullAdder. Use the resolved 9 value logic of the
IEEE 1164 package. The Simple1bitALU.vhd file has
library IEEE;; to be analyzed and simulated by the Synopsys
use IEEE.std_logic_1164.all; commands: vhdlan &
entity Mux4to1 is
port (i0,i1,i2,i3: in std_logic_vector(7 downto 0); carry
sel : in std_logic_vector(1 downto 0); a
z : out std_logic_vector(7 downto 0)); ALU
carryIn result
end Mux4to1;
b
architecture dataflow of Mux4to1 is opcode
begin
z <= i0 after 5 ns when sel=“00” else
one single i1 after 5 ns when sel=“01” else
signal i2 after 5 ns when sel=“10” else
assignment i3 after 5 ns when sel=“11” else
“00000000” after 5 ns; ns
end dataflow;
page 10
Delays: Delta Delay Model Delays: Inertial Delay Model
The VHDL language distinguished between tree Digital circuits have a certain amount of inertia.
delay models: For example it takes a finite amount of time and a
Delta delay model certain amount of energy for the output of a gate to
Inertial delay model (default) respond to a change on the input
Transport delay model Inertial
Inertial delay model (default)
Delta
Delta delay model a pulse shorter than the propagation delay will not
If no delay is specified, a delta delay is assumed. A delta propagate to the output
delay is as small as zero delay. It is used by the
simulator which sums delta delays to zero. out1 <= (a xor b) after 8 ns;
out2 <= (a xor b) after 2 ns;
in1 architecture delta_delay of Comb is
signal s1,s2,s3,s4: std_logic:=0;
in2 begin
input
out
z s1 <=not(in1); input
s1 s2 <=not(in2); 8 ns
s2 s3 <=not(s1 and in2); out1 output for delay: 8 ns
s4 <=not(s2 and in1);
s3 z <=not(s3 and s4); 2 ns
s4 end delta_delay;; out2 output for delay: 2 ns
time (ns)
0 10 20 30 40 50 60 70
in2
s2 5 10 15 20 25 30 35 40
s3
z VHDL’93!
sum <=reject 2 ns inertial (a xor b) after 5 ns;
10 ∆ 2∆ 3∆
MicroLab, VLSI-21 (21/95) MicroLab, VLSI-21 (22/95)
page 11
Delays: Transport Delay Model Delay Model in Practice
Accurate delay library IEEE;;
Unlike switching devices, wires have a modeling of wire use IEEE.std_logic_1164.all;
comparatively less inertia, As a result, wires will delays is possible,
although in practice it entity HalfAdder is
propagate signals with very small pulse width. is difficult to obtain port (a,b: in std_logic;
In modern technologies with increasingly small accurate estimates of carry,sum:out
out std_logic);
feature sizes the wire delays dominate. the wire delay without end HalfAdder;
proceeding through
Transport
Transport delay model physical design and architecture transport_delay of HalfAdder is
any pulse will propagate to the output, independent of layout of the circuit. signal s1,s2: std_logic:=‘0’;
the delay begin
s1 <= (a xor b) after 2 ns;
ns
a s1 s2 <= (a and b) after 2 ns;
sum ns
out1 <= transport (a xor b) after 8 ns; b sum <= transport s1 after 4 ns;
ns
carry <= transport s2 after 4 ns;
ns
s2 end transport_delay;
input carry
out
a
input inertial
b
8 ns
output for delay: 8 ns sum
out1
carry transport
time (ns) s1
5 10 15 20 25 30 35 40 s2
time (ns)
0 2 4 6 8 10 12 14
MicroLab, VLSI-21 (23/95) MicroLab, VLSI-21 (24/95)
page 12
chapter 4 (starter)
page 13
Example: Process Statement The Process Construct #2
library IEEE;;
use IEEE.std_logic_1164.all;
The execution of a process is initiated whenever an
use IEEE.std_logic_unsigned.all;
event occurs on any signal in the sensitivity list
entity Memory is Once started the process executes to completion in
port (addr,wrData: in std_logic_vector(31 downto 0); zero (simulation) time.
wr,rd: in std_logic;
rdData :out
out std_logic_vector(31 downto 0)); Processes execute concurrently with other
end Memory; processes and concurrent signal assignments.
architecture behavioral of Memory is Concurrent signal assignments are in fact only
type memArray is array
array(0 to 1024) of std_logic_vector(31 downto 0); special cases of processes.
begin sensitivity list
MemProcess:: process(addr,wr,rd)
process
variable mem: memArray :=(
identical behavior
(x“00000A06“), -- initializing memory data
others => (x“00000000“));
variable addrIndex: integer;
integer
architecture behavior of MyBlock1 is architecture behavior of MyBlock2 is
begin
immediate begin begin
addrIndex:=conv_integer(addr);
variable c <= a and b after 5 ns;
ns process(a,b)
process
if (wr = ‘1‘) then
assignment end behavior; begin
mem(addrIndex):=wrData;
c <= a and b after 5 ns;
ns
elsif (rd = ‘1’) then
end process;
process
rdData <=mem(addrIndex) after 10 ns; ns concurrent end behavior;
end if;
if signal concurrent signal assignment
end process; assignment
process
end behavioral;
MicroLab, VLSI-21 (27/95) MicroLab, VLSI-21 (28/95)
page 14
VHDL vs. Verilog:
Verilog: Events Conditional Programming Constructs
whow!
whow!
everything is
event driven like
in real life
page 15
Example: Condition Statements VHDL vs. Verilog:
Verilog:
library IEEE;; Combinational Logic Example
use IEEE.std_logic_1164.all;
entity Multiplexer4to1 is
entity HalfAdder is port (sel: in std_logic_vector (1 downto 0);
port (a,b: in std_logic; a,b,c,d: in std_logic_vector (15 downto 0);
sum,carry: out std_logic); z:out std_logic_vector (15 downto0));
downto0
end HalfAdder; end Multiplexer4to1;
VHDL
architecture behavioral of HalfAdder is architecture DemoExample of Multiplexer4to1 is
begin begin
If_Process:: process(a,b)
process process (a,b,c,d,sel)
4 to 1 multiplexer
begin begin (no interfered memory)
if (a = b) then case sel is
sum<= ‘ 0‘ after 5 ns;ns when (“00“) => z <= a;
else when (“01“) => z <= b;
sum<= (a or b) after 5 ns; ns when (“10“) => z <= c;
end if;
if when (“11“) => z <= d; module Multiplexer4to1(sel,a,b,c,d,z);
end process; when others => z<=“-------“;input [1:0]] sel;
end case; input [15:0]] a,b,c,d;
Case_Process:: process(a,b)
process end process; output [15:0]] z;
begin end DemoExample;
case a is assign z =(sel == 2’d0) ? a:
when ‘0‘ => carry <= a after 5 ns;
ns (sel == 2’d1) ? b:
when ‘1‘ => carry <= b after 5 ns;
ns (sel == 2’d2) ? c:
when others => carry <= ‘x‘ after 5 ns;
ns (sel == 2’d3) ? d:
end case;
case Verilog-
Verilog-HDL 16’bx;
end process; endmodule
end behavioral; MicroLab, VLSI-21 (31/95) MicroLab, VLSI-21 (32/95)
page 16
Loop Programming Constructs Example: Loop Statements
library IEEE;;
use IEEE.std_logic_1164.all;
loop index has not to be
for loop statement declared but can only be
use IEEE.std_logic_unsigned.all; a
Multiplier
for index in range loop used locally (32 bit)
bit) m
entity Multiplier is b
sequential statements port (a,b: in std_logic_vector(31 downto 0);
m: out std_logic_vector(63 downto 0));
end loop; end Multiplier;
page 17
Exercises vlsi21: Loops More on Processes
Ex405 (difficulty: easy): Write a VHDL code for a Never assign a value to a signal in different
combinational shift logic block with 8 bit data processes (multiple drives).
buses with zero fill. Use the 2 bit signal shiftNum
to indicate the number of bits to be shifted. If a process A conflict
- two drivers!
std_logic_vector has to be converted to an integer y<=‘0‘;
- not synthesis
synthesisable!
type, the conv_integer()
conv_integer() function from the
std_logic_unsigned package can be used. process B
y<=‘1‘;
shiftLeft shiftRight
page 18
The Wait Statement Example: Wait Statements
library IEEE;; library IEEE;;
use IEEE.std_logic_1164.all; use IEEE.std_logic_1164.all;
A more general way to specify when a process
executes is the wait statement. entity Dff1 is entity Dff2 is
port (d,clk: in std_logic; port (d,clk,rst: in std_logic;
Wait statements explicitly specify the conditions q,qBar: out std_logic); q,qBar: out std_logic);
under which a process may resume execution after end Dff1; end Dff2;
being suspended
suspended.
ed.
With wait statements a process can be suspended at architecture behavioral of Dff1 is architecture behavioral of Dff2 is
multiple points. begin begin
process process(clk,rst);
process
begin begin
wait for time expression; wait until (clk‘event
event and clk=‘1‘); if (rst=‘0‘) then
q <=d after 1 ns; ns q <= ‘0‘ after 1 ns; ns
example: wait for 20 ns; qBar<=not not d after 1 ns;
ns qBar<= ‘1‘ after 1 ns;ns
end process; elsif (clk‘event
event and clk=‘1‘) then
end behavioral; q <=d after 1 ns; ns
wait on signal; qBar<=not not d after 1 ns;
ns
example: wait on clk,reset,status; end if;
if
end process;
end behavioral;
wait until condition;
example: wait until (a = ‘1‘);
if a process has no sensitivity list you MUST
use wait statements, otherwise your process
wait;
never suspends and blocks your simulation
MicroLab, VLSI-21 (37/95) MicroLab, VLSI-21 (38/95)
page 19
Latch vs. Flip-
lip-Flop Exercises vlsi21: Synchronous
process(clk,reset,d)
process
begin
if (reset = ‘0’) then d D Q q
q <= ‘0’; Ex406 (difficulty: easy): Write a VHDL code for a
Latch
elsif (clk=‘1’) then clk 16 bit register with an enable and a asynchronous
q <= d; reset input.
end if; Register16
end process;
reset d q
enable
process(clk,reset)
process
begin clk
if (reset = ‘0’) then d D Q q
q <= ‘0’; Flip-
Flip-Flop
elsif (clk’event
event and clk=‘1’) then clk reset
q <= d;
end if;
end process; reset
Ex407
Ex407 (difficulty: easy): Write a VHDL code for a
16 bit counter with an enable a load and a
process(clk,reset)
process
asynchronous reset input.
begin Counter16
if (reset = ‘0‘) then data count
q <= “00000000“; Mux D Q q enable
elsif rising_edge(clk) then d
register load
if (enable = ‘1’) then enable
q <= d; clk clk
end if;
if
end if;
end process; reset reset
MicroLab, VLSI-21 (39/95) MicroLab, VLSI-21 (40/95)
page 20
More on Wait: Inter-
Inter-Process Comm. Exercises vlsi21: Handshake
transmitData
request
acknowledge Ex vlsi408a (difficulty: easy, optional): Write a
VHDL model for communication between an input
receiveData
receiveData time process and an output process using handshaking
protocol. The input process can only read a single
entity Handshake is word (32 bit) at a time. The output device requires
port(inputData:
port in std_logic_vector(31 downto 0)); a reversing byte order, which is performed by the
end Handshake;
input process. Assign a delay of 1 ns to each
architecture behavioral of Handshake is handshake signal.
signal transmitData: std_logic_vector(31 downto 0); AsyncComm
signal request, acknowledge: std_logic;
begin inputData outputData
input process output process
producer:: process consumer:: process
begin variable receiveData:
wait until inputData‘event
event;
event std_logic_vector(31 downto 0);
transmitData<=inputData; begin
request<=‘1‘; wait until request=‘1‘;
wait until acknowledge=‘1‘; receiveData:=transmitData;
request<=‘0‘; acknowledge<=‘1‘; Ex vlsi408b (difficulty: medium, optional):
wait until acknowledge=‘0‘; wait until request=‘0‘; Rewrite the above handshake model by using a clk1,
end process; acknowledge<=‘0‘; clk2 signal for the two synchronous processes as
end process;
well as a rst for initialization, and a start signal to
end behavioral;; initiate one data transfer. Do not use any wait
constructions within the processes.
MicroLab, VLSI-21 (41/95) MicroLab, VLSI-21 (42/95)
page 21
Attributes Generating Periodic Waveforms
library IEEE;
attribute function use IEEE.std_logic_1164.all; Z
time (ns)
signal’event
’event function returning a Boolean value entity Periodic is
signifying a change in value on this signal port(Z:
port out std_logic); 0 10 20 30 40 50
signal’active
’active function returning a Boolean value end Periodic;
signifying an assignment made to this architecture behavioral of Periodic is
signal (may not be a new value) begin
signal’last_event
’last_event function returning the time since the process
begin
last event Z<=‘0’, ‘1’ after 10 ns,
ns ‘0’ after 20 ns,
ns ‘1’ after 40 ns;
ns
signal’last_active
’last_active function returning the time since the wait for 50 ns;
ns
signal was last active end process;
signal’last_value
’last_value function returning the previous value end behavioral;;
of this signal
signal’left
’left returns the leftmost value of signal in library IEEE; reset
its defined range use IEEE.std_logic_1164.all; phi1
signal’right
’right returns the rightmost value of signal phi2
entity TwoPhase is
in its defined range port(phi1,phi2,reset:
port out std_logic);
end twoPhase; 0 10 20 30 40 50 60
signal’hight
’hight returns the highest value of signal
time (ns)
in its defined range architecture behavioral of TwoPhase is
signal’low
’low returns the lowest value of signal begin
in its defined range reset_process: reset<=‘1’, ‘0’ after 10 ns;ns
clock_process: process
signal’ascending
’ascending returns true if signal has an ascending begin
range of values phi1<=‘1’, ‘0’ after 10 ns;
ns
signal’length
’length returns the number of elements in the phi2<=‘0’, ‘1’ after 12 ns,
ns ‘0’ after 18 ns;
ns
wait for 20 ns;
ns
array signal end process;
MicroLab, VLSI-21 (43/95) MicroLab, VLSI-21 (44/95)
end behavioral;;
JMM v1.5 JMM v1.5
page 22
Modeling Finite State Machines Exercises vlsi21: FSM
reset
outputData
inputData state state
transition register output
process enable process outSig0 Ex409 (difficulty: easy): Write a VHDL model for
outSig1 a traffic light controller. Use a Moore type FSM.
outSig2
clk The signal carPresent indicates cars running on the
main street which always have priority. If no cars
architecture behavioral of MooreFSM is
are present on the main street, the secondary street
type StateType is (MyState,YourState,InitState); gets green lights.
signal state : StateType;
signal outputData: std_logic_vector(5 downto 0);
begin output_process: process(state)
process OrangeState
begin
orange
carPresent
green
transition_process: process(reset,clk)
process case state is
red
begin when MyState => main 0 1 0
second 1 0 0
if (reset = ‘0’) then outputData<=“01—00”; carPresent
state <= InitState; when YourState =>
GreenState RedState1
elsif rising_edge(clk) then outputData<=“00100-”;
orange
orange
green
green
case state is when InitState =>
red
red
when MyState => outputData<= “100100”; main 0 0 1 main 1 0 0
state<=YourState; when others => second 1 0 0 second 0 0 1
when YourState => outputData<=“000000”; carPresent
if (inputDataSignal = ‘1’) then end case;
case
state<=MyState; end process;
process RedState2
orange
end if;
if
green
carPresent
red
when others => null;
null outSig0<=outputData(0); reset main 1 0 0
end case;
case outSig1 <=outputData(1); second 0 1 0
end if;
if outSig2<=outputData(2);
end process;
process
end behavioral;
MicroLab, VLSI-21 (45/95) MicroLab, VLSI-21 (46/95)
page 23
chapter 5 (starter)
page 24
Exercises vlsi21: Structural Model VHDL vs. Verilog:
Verilog:
library IEEE;
use IEEE.std_logic_1164.all;
Structural
entity FullAdder4 is Description
Ex410 (difficulty: medium): Write a VHDL code port (a,b,cIn:in
in std_logic;
for the structural model of the FullAdder3 cOut,sum:out
out std_logic);
described in the previous transparency. Assume a end FullAdder4;
delay of 1 ns for all logic gates architecture flatStructure of FullAdder4 is
a) Write the structural VHDL code for a HalfAdder.
HalfAdder. component XOR
port(a,b:
port in std_logic; z:out
out std_logic); VHDL
b) Write the VHDL codes for the necessary logic end component;
component
gates like OR2 and others in one file component AND2
(logicgates.vhd)
logicgates.vhd) port(a,b:
port in std_logic; z:out
out std_logic);
end component;
component
b) Write the VHDL code for FullAdder3 component OR3
c) Analyze and simulate the whole circuit. Be aware port(a,b,c:
port in std_logic; z:out
out std_logic);
module FullAdder4
of the correct sequence of analyzing. end component;
component (a,b,cIn,cOut,sum);
signal net1,net2,net3,net4:std_logic; input a,b,cIn;
begin output cOut,sum;
u1: XOR port map (a,b,net1); wire net1,net2,net3,net4;
u2: XOR port map (cIn,net1,sum);
u3: AND2 port map (cIn,a,net2); XOR u1(net1,a,b);
u4: AND2 port map (cIn,b,net3); XOR u2(sum,cIn,net1);
u5: AND2 port map (a,b,net4); AND2 u3(net2,cIn,a);
u6: OR3 port map (net2,net3,net4,cOut); AND2 u4(net3,cIn,a);
end flatStructure; AND2 u5(net4,a,b);
OR3u6(cOut,net2,net3,net4);
endmodule
Verilog-
Verilog-HDL
MicroLab, VLSI-21 (49/95) MicroLab, VLSI-21 (50/95)
page 25
VHDL vs. Verilog:
Verilog: Hierarchy, Abstraction, and Accuracy
Data Flow Description
Structural models simply describe interconnections
library IEEE;
Structural models do not describe any form of
use IEEE.std_logic_1164.all; behavior
use IEEE.std_logic_unsigned.all; Hierarchy expresses different levels of detail
entity FullAdder5 is Structural models are a way to manage large,
port (a,b,cIn:in
in std_logi;
VHDL complex designs
sum,cOut:out
out std_logic);
end FullAdder5; Modern designs have several 10 millions of gates
Simulation time: the more detailed a design is
architecture dataFlow of FullAdder5 is
described, the more events are generated and thus
signal tmp: std_logic_vector(1 downto 0);
begin the larger the simulation time will be needed.
tmp <= ‘0‘ & a + b + cIn;
cOut <= tmp(1); top level
sum <= tmp(0); FullAdder3
end behavior; module FullAdder5 (a,b,cIn,sum,cOut);
input a,b,cIn;
output cOut,sum; HalfAdder3
OR2
Verilog-
Verilog-HDL
assign {cOut,sum} = a + b + cIn;
endmodule
AND2 XOR2 bottom level
MicroLab, VLSI-21 (51/95) MicroLab, VLSI-21 (52/95)
page 26
Generics More on Generics
Within a structural model there are two ways in
The VHDL language provides the ability to construct which the values of generic constants of lower level
parameterized models using the concept of generics components can be specified:
in the component declaration
entity AND2 is in the component instantiation
generic(andDelay:
generic Time);
Time
library
libraryIEEE;
IEEE;
port(a,b
port : in std_logic; z: out std_logic; If both are specified, then the value provided by the
use end AND2; generic map() takes precedence.
useIEEE.std_logic_1164.all;
IEEE.std_logic_1164.all;
entity
entityHalfAdder4
HalfAdder4isis
architecture genericDelay of AND2 is If neither is specified, then the default value
begin
generic(adderDelay:
generic
generic(adderDelay:
generic Time:=3
Time ns);
Time
Time:=3 nsns);
ns z<=a and b after andDelay;
defined in the model is used.
port(a,b
port : :ininstd_logic;
port
port(a,b std_logic;
sum,carry: end genericDelay;
sum,carry:out
outstd_logic;
std_logic; library IEEE;
end
endHalfAdder4;
HalfAdder4; use IEEE.std_logic_1164.all;
entity GenericOR is
architecture
architecturegenericDelay
genericDelayofofHalfAdder4
HalfAdder4isis generic(n:
generic positive:=2);
positive
component
componentAND2
AND2isis port(in1:
port in std_logic_vector((n-1) downto 0); z: out std_logic);
generic(andDelay:
generic
generic(andDelay:
generic Time);
Time
Time);
Time end GenericOR;
port(a,b
port : :ininstd_logic;
port
port(a,b std_logic;z:z:out
outstd_logic;
std_logic;
end
endcomponent;
component; values to generics architecture behavioral of GenericOR is
can be assigned at begin
component
componentXOR2 XOR2isis different locations process(in1)
process
generic(xorDelay:
generic
generic(xorDelay:
generic Time);
Time
Time);
Time variable sum: std_logic:=‘0‘;
port(a,b
port
port(a,b
port : : in std_logic;z:z:out
in std_logic; outstd_logic;
std_logic; begin
end
endcomponent;
component; sum:=‘0‘;
for i in 0 to (n-1) loop
begin
begin no semi column sum:=sum or in1(i);
C1:
C1:XOR2
XOR2generic map(12
map(12ns)
genericmap
map ns port
nsns) map(a,b,sum);
portmap
map(a,b,sum);
map needed end loop;
loop
C2:
C2:AND2
AND2generic map(adderDelay)
map(adderDelay)port
genericmap
map map(a,b,carry);
portmap
map(a,b,carry);
map z<=sum;
end
endgenericDelay;
genericDelay; end process;
process
end behavioral;
MicroLab, VLSI-21 (53/95) MicroLab, VLSI-21 (54/95)
page 27
Exercises vlsi21: Hierarchy, Generic Configuration
Ex411 (difficulty: medium): Write a VHDL code Structural models may employ different levels of
of an 8 bit ALU based on the definitions made in abstraction
Ex402 with the Simple1BitALU.
Each component in a structural model may be
a) Write a behavioral VHDL code for ALU8b.vhd described as a behavioral or a structural model
b) Write the structural VHDL code for ALU8 in one
file ALU8s.vhd. Assume a delay of 1 ns for all Configuration allows stepwise refinement in a
logic gates. What is the worst case delay of the design cycle
ALU8. Configuration represents resource binding
Description-
Description-synthesis design method
Ex412 (difficulty: easy): Write a VHDL code of
an n bit register with reset and enable inputs
(NbitRegister.vhd).
NbitRegister.vhd). Configuration associates
an architecture
description to each
FullAdder3 component:
- behavioral or
- structural for
OR2 HalfAdder3
FullAdder3
AND2 XOR2
page 28
Configuration: Component Binding Configuration: Default Binding Rules
reset
architecture behavioral of Comb is
- - -
page 29
Example: Configuration Exercises vlsi21: Configuration
C1 highSpeed
in1 Comb
Ex 413 (difficulty: easy): Write a VHDL code of
sum
in2 (combinational the bit-
bit-serial adder shown in the previous
logic) transparency SerialAdder.vhd
carryIn carry
C2 MyDff
a) Construct a model for the two components Comb
q d and MyDff and place them both in your WORK
clk
rst clock
library (don‘t use the library MyLibrary yet).
configuration name behavioral b) Adapt the configuration, compile and simulate it.
it.
reset entity name
(used for simulation)
library name
Ex414 (difficulty: medium): Consider the circuit
configuration CFG_HighSpeed of SerialAdder is entity name shown below (ConfigExample
(ConfigExample).
ConfigExample). Construct a
for structural
architecture name structural model comprised of three components.
for C1: Comb use entity WORK.Comb(highSpeed); However in the configuration use only two
end for;
for components by using a n-
n-input AND gate.
for C2: Dff use entity MyLibrary.MyDff(behavioral)
generic map(gateDelay=>5
map ns)
port map(my_clk=>clk,
map my_d=>d,
my_q=>q, my_rst=>rst); if different component i1
end for;
for than described in i2 &
entity is used, then i3
end for;
for I/O mapping must ≥1 o1
be declared.
end CFG_HighSpeed; &
page 30
chapter 6 (starter)
page 31
Example: Type Conversion Function Procedures
with Functions Procedures are subprograms that can modify one or
more of the input parameters. Example of procedure
As VHDL is a type sensitive language, type declaration reading from a file f:
conversions are quite often necessary.
procedure read_v1d (variable
variable f: in text; v: out std_logic_vector);
note: size is not declared
if the class of the procedure parameters is not
function to_bitvector(svalue: std_logic_vector) return bit_vector is
explicitly declared, then the following rules apply:
variable outvalue: bit_vector(svalue‘length
‘length-1
‘length downto 0); parameters of mode in are assumed to be of class constant
begin parameters of mode out or inout are assumed to be of class
for i in svalue‘range
‘range loop
case svalue i is
variable
when ‘0‘ => outvalue i:=‘0‘; Variables declared within a procedure are initialized
when ‘1‘ => outvalue i:=‘1‘;
when others => outvalue i:=‘0‘; on each call to the procedure and their values do not
end case;
case persists across invocations of the procedure.
end loop;
loop
end to_bitvector; Signals cannot be declared within procedures
Poor programming: Procedures declared within
process can make assignments to signals
corresponding to the ports of the encompassing
Many conversion procedures as well as resolution entity.
functions can be found in std_logic_1164 or
std_logic_arith libraries and others. Have a look at Procedure call:
$SYNOPSYS/packages/IEEE/src
$SYNOPSYS/packages/IEEE/src/ src/ Dff(clk=>clk,reset=>reset,d=>s2,q=>s1,qbar=>open
open);
open
MicroLab, VLSI-21 (63/95) MicroLab, VLSI-21 (64/95)
page 32
Example: Procedure Overloading
library IEEE;
IEEE
use IEEE.std_logic_1164.all;
entity CPU is A very useful feature of the VHDL language is the
port(di:
port out std_logic_vector(31 downto );
addr: out std_logic_vector(2 downto 0);
ability to overload a subprogram or an operator.
r,w: out std_logic; Imagine writing different Flip-
Flip-Flop models with no
do: in std_logic_vector(31 downto 0); and with asynchronous inputs and with different
s: in std_logic);
end CPU;
argument types. With the overloading feature only
one single Flip-
Flip-Flop name can be used.
architecture behavioral of CPU is Example for Dff calls:
procedure Mread(address: in std_logic_vector(2 downto 0);
signal r: out std_logic;
signal s: in std_logic; Dff(
Dff(clk,d,q,qbar);
signal addr: out std_logic_vector(2 downto 0);
signal data: out std_logic_vector(31 downto 0)) is Dff(
Dff(clk,d,q,qbar,
clk,d,q,qbar,reset,
reset,clear);
begin
addr<=address; procedure Mwrite(address: in std_logic_vector(2 downto 0); From the type and number of arguments we can tell
r<=‘1‘; signal data: in std_logic_vector(31 downto 0); which procedure we meant to use.
wait until s=‘1‘; signal addr: out std_logic_vector(2 downto 0);
data <= do; Note that in std_logic_1164.vhd the boolean
signal w: out std_logic;
r<=‘0‘; signal di: out std_logic_vector(31 downto 0)) is functions and, or, etc have been defined for
end Mread; begin std_logic types, the functions +,*, etc have been
addr<=address; defined for certain predefined types of the language
w<=‘1‘; such as integer. See also std_logic_arith package.
wait until s=‘1‘;
begin
di <= data; function “*“(arg1,ar2: std_logic_vector) return std_logic_vector;
std_logic_vector;
w<=‘0‘;
-- CPU behavioral end Mwrite;
-- description function “+“(arg1,ar2: singed) return signed;
end behavioral;
MicroLab, VLSI-21 (65/95) MicroLab, VLSI-21 (66/95)
page 33
Packages Example: Package Declaration
Locally related functions and procedures can be
package std_logic_1164 is
grouped into packages, and thus easily be shared
among designs and people. type std_ulogic is (‘U‘, -- uninitialized
‘X‘, -- forcing unknown
package MyLibraryPackage is ‘0‘, -- forcing 0
-- ‘1‘, -- forcing 1
-- type declarations
package declaration ‘Z‘, -- high impedance
-- function declarations ‘W‘, -- weak unknown
-- procedure declarations similar to VHDL entity ‘L‘, -- weak 0
-- defines interfaces ‘H‘, -- weak 1
end MyLibraryPackage; ‘-‘ -- don‘t care);
type std_ulogic_vector is array (natural
natural range <>) of std_ulogic;
subtype std_logic is resolved std_ulogic;
package body MyLibraryPackage is
-- package body type std_logic_vector is array (natural
natural range <>) of std_logic;
-- functions
-- procedures similar to VHDL architecture function “and“ (l,r: std_logic_vector) return std_logic_vector;
-- defines behavior function “and“ (l,r: std_ulogic_vector) return std_ulogic_vector;
end MyLibraryPackage;
-- rest of package declaration
end std_logic_1164;
package declaration needs to be analyzed first, and
then package body can be analyzed.
Packages are used as libraries and referenced within
VHDL design units via the use clause.
page 34
Synopsys tools on unix workstations
page 35
Exercises vlsi21: Libraries & Packages Exercises vlsi21: Packages
Ex415 (difficulty: medium): The small circuit Ex417 (difficulty: medium): The bit-
bit-serial adder of
ConfigExample from exercise Ex414 shall be exercise Ex413 shall we rewritten using a
rewritten by using the components OR2 and ANDn procedure call for the Dff instead of a component
from the library MyLibrary. (SerialAdder2.vhd). Place the procedure into a
a) Write the VHDL file MyComponents.vhd holding package MyPackage and analyze it into the library
the two components OR2 and ANDn and compile it MyLibrary. Verify the functionality.
into the library MyLibrary.
b) Rewrite the ConfigExample circuit using only
library elements and call it LibraryExample.vhd, C1 highSpeed
compile and simulate it.
in1 Comb sum
i1 ANDn in2 (combinational
i2 & OR2 logic)
logic)
i3 carry
ANDn ≥1 o1 carryIn
Dff
q d
& library
clk
rst clock MyLibrary
Ex416 (difficulty: medium): Write the VHDL behavioral
reset
package MyPackage with the functions OneCounter
(counting ‚1‘) and ParityGenerator should accept
std_logic_vectors or bit_vectors of any size),
size), and
analyze it into the library MyLibrary. Use the
defined functions in your design PackageExample to
show its functionality.
page 36
VHDL vs. Verilog:
Verilog: Data Types VHDL vs. Verilog:
Verilog: Operators
VHDL Verilog-
Verilog-HDL Operator type function VHDL Verilog
arithmetic a+b + +
type driven language arrays a-b - -
a*b * *
predefined data types run-
run-time constants: a/b / /
in packages: parameter
a- b*n a div b mod %
character, integer, real, continuous driven
bit, std_logic, textio,
textio, ... a- (a/b)*b rem
nets: wire, tri, ... logical a and b and &
enumerate types
triggered assignments: a or b or ¦
arrays reg,
reg, integer, real, ... not(a and b) nand ~&
records a exor b xor ^
shift logic srl,sll >>
pointers
shift arith. sra,sla
rotate ror, rol
reduction, & {a,b}
concatenation
replication {4{a}}
relational > > >
>= >= >=
/=
page 37
VHDL vs. Verilog:
Verilog: VHDL vs. Verilog:
Verilog:
Sequential Structures Parallel Structures
-- in an architecture
-- inside an architecture ...
... variable inp: std_logic_vector (7 downto 0);
);
signal outp,cout:std_logic_vector (7 downto 0);
);
variable inp: std_logic_vector (7 downto 0);
); VHDL
variable outp,cout:std_logic_vector (7 downto 0);
);
VHDL p1: process (clk)
process (clk) begin parallel executed
begin if (clk’even
’event
’even and clk = ‘1’) then statements
if (clk’even
( ’event
’even and clk = ‘1’) then outp <= outp + inp;
outp := outp + inp; cout <= outp + 1;
cout := outp + 1; end if;
end process; /* in a module */
end if;
...
end process;
p2: process (reset) wire [7:0]] inp;
...
/* inside a module */ begin reg [7:0]] outp, cou;
... if (reset = ‘0’) then ...
wire [7:0]] inp; outp <= “00000000“; always @(@(posedge
posedge clk))
reg [7:0]] outp, cou; end if; fork
sequentially executed statements end process; outp = outp + inp;
...
always @(@(posedge
posedge clk)) ... cout = outp + 1;
begin join
outp = oupt + inp;
parallel
cout = outp + 1; executed blocks always @(reset)
@( )
end two drivers if (!!reset)
Verilog-
Verilog-HDL ...
Verilog-
Verilog-HDL outp = 8’b0;
...
page 38
VHDL vs. Verilog:
Verilog: Assignments VHDL vs. Verilog:
Verilog:
architecture ex1 of AssignExample is Sequential Logic
signal x1, y1, y2, z1, z2:
std_logic_vector (7 downto 0);
); VHDL
variable x2: std_logic_vector (7 downto 0);
); library IEEE; register with
... use IEEE.std_logic_1164.all;
begin package MyDefinition is asynchronous reset
p1: process (clk) type vector16 is array (15 downto 0) of
begin signal assignment std_logic;
end MyDefinition; VHDL
if (clk’even
( ’event
’even and clk = ‘0’) then variable assignment
x1 <= y1;
library IEEE;
y1 <= x1;
use IEEE.std_logic_1164.all;
z1 <= y1 after 12ns;
ns; Verilog-
Verilog-HDL use work.MyDefinition.all;
end if;
end process; module AssignExample
entity AsynRegister is
wire [7:0]] v,y2,z2;
port (clk,rst: in std_logic;
p2: process (y2) reg [7:0]] x1,y1,z1,x2; Verilog-
Verilog-HDL
a: in vector16; z: out vector16);
begin ...
end AsynRegister;
x2 := y2; always @(
@(posedge
posedge clk)) module AsynRegister(clk,rst,a,z);
y2 <= x2; fork input clk,rst;
architecture DemoExample of AsynRegister is
z2 <= y2 after 12ns; x1 = y1; input [15:0]] a;
begin
end process; y1 = x1; output [15:0]] z;
process (clk, rst);
end ex1; z1 #(12) = y1;
begin
join always @(
@(posedge
posedge clk))
if (rst = ‘0’) then
before the falling edge of clk:
clk: z <= vector16’(others
others => ‘0‘); if (rst == 1’b0)
assign x2 = y2; z = 16’b0;
x=1, y=2, z=3 assign y2 = x2;
elsif (clk’even
’event
’even and clk = ‘1’) then
else
12ns after falling edge of clk:
clk: assign #(12) z2 = y2;
z <= a;
z = a;
x= y= z= ? end if;
endmodule endmodule
end process;
MicroLab, VLSI-21 (77/95) end DemoExample; MicroLab, VLSI-21 (78/95)
page 39
“Dataflow” Modeling VHDL Example: Behavioral Modeling
library IEEE;
use IEEE.std_logic_1164.all; library IEEE;
use IEEE.std_logic_1164.all;
entity Demux
Demux2x4
emux2x4 is port( use IEEE.std_logic_arith.all;
IEEE.std_logic_arith.all;
a,b,enable: in std_logic;
z: out std_logic_vector(0 to 3);); entity Demux2x4 is port(
end Demux
Demux2x4;
emux2x4; a,b,enable: in std_logic;
z: out std_logic_vector(0 to 3););
architecture dataflowof
dataflowof Demux
Demux2x4
emux2x4 is end Demux2x4;
signal abar,bbar:
abar,bbar: std_logic;
begin architecture behavioral of Demux2x4 is
z(3) <= not(a and b and enable); begin
z(0) <= not(abar and bbar and enable); process(a,b,enable)
abar <= not a; variable abar,bbar:
abar,bbar: std_logic;
z(2) <= not(a and bbar and enable); begin
abar <= not a; abar := not a; local variables (separate
z(1) <= not(abar and b and enable); bbar := not b; copies for each instance
end dataflow;
dataflow; if (enable = ‘1’) then of Demux
Demux2x4)
emux2x4)
z(3) <= not(a and b);
Process statements z(2) <= not(a and bbar);
bbar);
can be compiled so z(1) <= not(abar and b);
behavioral simulations z(0) <= not(abar and bbar);
bbar);
All the signal assignment statements (“<=“) happen can be quite fast.
concurrently after some specified delay which defaults else
z <= “1111”;
to 1 “delta”, an infinitesimally small delay. Note that end if;
concurrent statements are always “running” so whenever end process;
A, B or ENABLE change then ABAR, BBAR, and Z(0 to 3) end behavioral; vector constant
will also change after some delay.
The delay in assigning a signal its new value means that Statements within a process are executed sequentially,
the following statement is meaningful (it generates a like a program. The process is scheduled for execution
periodic waveform): after any events are processed for variables on its
CLK <= not CLK after 10 ns; sensitivity list. Values of local variables are maintained
between executions.
MicroLab, VLSI-21 (79/95) MicroLab, VLSI-21 (80/95)
page 40
Logic Synthesis
Synthesis
Z <= (A and B) or C; if (SEL = ‘1’) then Z <= B;
else Z <= A;
A end if;
Idea:
Idea: once an behavioral model has been finished why not B
use it to automatically synthesize a logic implementation in C Z B 1
Z
0
much the same was as a compiler generates executable code A
A
from a source program? B SEL
C Z
a.k.a. “silicon compilers” B
Synthesis programs process the HDL then SEL Z
A
page 41
Further Reading Test Bench /1
page 42
Test Bench /2 Test Bench in Design Flow
design of
compare a test bench with MicroLab-
MicroLab-I3S: VHDL model
there are chips and PCBs needed to be tested
simulation of test bench
there is a nice measurement equipment
VHDL model inp VHDL out
there are skilled and hard working people FPGA synthesis model
there are no signals coming or going to the outside of the place & route
lab
FPGA test
(debugger)
Test Bench test bench synthesis of
test machine logic model
inp FPGA out test bench
chip simulation of
control response logic model inp out
and generation
stimulus and place & route
generation verification physical design
page 43
VHDL Test Bench Test Bench - Test Cycle
use IEEE.std_logic_1164.all
entity TestBench is test bench has
end TestBench; no inputs, no outputs
architecture sample of TestBench is design strictly synchronous circuits
signal clk, a: bit;
signal b: bit;
cycle
cycle based test benches
component MyCircuit
port(clk,a:in
port in bit; b: out bit);
end component;
component
begin test cycle
call of device under test
DUT: MyCircuit port map (clk,a,b); (DUT)
process apply input patterns capture output response
begin clk generation
clk <= ‘0’, ‘1‘ after 20 ns, ‘0‘ after 70 ns;
wait for 100 ns;
end process;
TestPatternGenerator: block clock
begin test pattern generation
process on a cycle by cycle basis
begin
a <= ‘0’; -- test cycle 1 input valid
wait for 100 ns;
ns
a <= ‘1’; -- test cycle 2
wait for 100 ns;
ns response pattern output stable stable stable
... verification not
end process; yet implemented!
end block;
end sample;
MicroLab, VLSI-21 (87/95) MicroLab, VLSI-21 (88/95)
page 44
ProTest Test Machine Conclusions
test bench controls CAD simulator and test machine HDLs are very useful for behavioral hardware
low cost rapid prototyping and test system system descriptions
abstract models do not precisely reflect the reality
restriction to synthesizable coding is necessary
technology independency opens the possibility to
fast FPGA prototyping
test benches increase chip quality and highly
decrease simulation time
page 45
Coming Up...
Exercises: VLSI-
VLSI-21: Test-
Test-Bench
page 46
Project 1: De-
De-Bounce Circuit Project 2: Traffic Light
CAD Ex440_1: De- De-Bounce Project (difficulty: CAD Ex440_2: Traffic Light (difficulty: easy;
easy; time: medium): Design of a push button de-de- time: medium): Redesign and implement your
bounce circuit. Start with a FSM design and traffic light design from exercise Ex409 into an
synthesize the logic manually (only 1 flip-
flip-flip is FPGA on the GECKO main board. Use the push
necessary). Code and simulate the VHDL design. buttons and LEDs from the GECKO I/O Expansion
For example, on the GECKO I/O Expansion board board. The clock oscillator frequency of the GECKO
are different switches and push buttons available. main board is 13.56 MHz. The time between a
The push buttons schematic is as follows. De-
De- change of the traffic lights is 1.5 seconds. The
bounce the push-
push-buttons. main street has a minimum green phase time of 6
seconds.
draw the timing diagram of the signals SWx and
main secondary
SWx_inverted when switching
street street
develop the finite state machine to generate the signal
button
develop the schematic of the circuitry
carPresent
simulate your VHDL code including the push button SW
Vdd Traffic Light
Circuitry 3
SWx reset 3
SWx_inverted
de-
de-bounce clock
button
SWx circuitry
SWx button
released ‘0‘
pressed ‘1‘
MicroLab, VLSI-21 (93/95) MicroLab, VLSI-21 (94/95)
page 47
Project 3: Stop Watch
CAD Ex440_3: Stop Watch (difficulty: easy; time:
medium): Design an implement a stop watch into an
FPGA on the GECKO main board. Use the push
buttons and 7-
7-segment LCD from the GECKO I/O
Expansion board. The clock oscillator frequency of
the GECKO main board is 13.56 MHz. The stop
watch resolution is 1/100 seconds, its maximum
value is 99.99 seconds for the 4 digit display.
Show the value “End” on the display when the
watch exceeds 99.99 seconds. Use only one single
push button for “start” and “stop”.
start/stop
Stop Watch 29
reset Circuitry
clock
JMM v1.5
page 48