VHDL - Fundamental Concepts
VHDL - Fundamental Concepts
fa
a
sum
b
cout
cin
1
fulladder.vhd
entity FullAdder is
port (a, b, cin : in bit; sum, cout : out bit);
end FullAdder;
architecture FullAdder_eqns of FullAdder is
begin
sum <= a xor b xor cin; -- signal assignment
cout <= (a and b) or (a and cin) or (b and cin);
end FullAdder_eqns;
entity - architecture
Design entity
component of a digital system
Entity declaration
defines the interface
Architecture body
defines functionality, allows different implementations
2
entity
entity entity_name is
port (signal_name : mode signal_type;
…..
);
end entity_name;
architecture body
architecture fa_eqns of fa is
begin
sum <= a xor b xor cin; -- signal assignment
cout <= (a and b) or (a and cin) or (b and cin);
end fa_eqns;
3
Concurrent signal assignment statements
Logical operators
not
and or xor xnor nand nor
Operator precedence
Evaluated left to right
Short circuit operators – and, or, nand, nor
Need for parentheses
4
architecture
As a set of concurrent assignment statements
dataflow
Language organisation
5
Design units
Primary design units
Entity declaration
Package declaration
Configuration declaration
Secondary design units
Architecture body
Package body
6
Structural model of a 4 bit adder
entity Adder4 is
port (A, B: in bit_vector(3 downto 0); Ci: in bit; -- Inputs
S: out bit_vector(3 downto 0); Co: out bit); -- Outputs
end Adder4;
signal
named wire in logic diagram
component declaration
ports declared as in entity
component instantiation
creates an instance of the component
Named association
FA0: FullAdder port map (X => A(0), Y => B(0), Sum
=>S(0), Cin => Ci, Cout => C(1));
7
Behavioral model of adder
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_arith.all;
entity vadd is
port (A, B: in unsigned (3 downto 0); -- Inputs
S: out unsigned (4 downto 0);); -- Outputs
end vadd;
architecture behav of vadd is
begin
add: process (A,B)
S <= (‘0’ & A) + (‘0’ & B);
end process add;
end behav;
8
Mixed Example - multiplier
multiplier multiplicand
shift_reg
control_ shift_
section adder
reg
product
Dept. of E&C, NITKS August 2006
entity multiplier is
port ( clk, reset : in bit;
multiplicand, multiplier : in integer;
product : out integer );
end entity multiplier;
9
…
multiplier_sr : entity work.shift_reg(behavior)
port map ( d => multiplier, q => mult_bit,
load => mult_load, clk => clk );
product <= full_product;
control_section : process is
-- variable declarations for control_section
-- …
begin
-- sequential statements to assign values to control signals
-- …
wait on clk, reset;
end process control_section;
end architecture mixed;
Test Benches
Testing a design by simulation
Use a test bench model
an architecture body that includes an instance of
the design under test
applies sequences of test values to inputs
monitors values on output signals
either using simulator
10
Basic Design Methodology
Requirements
Synthesize
Gate-level
Model Simulate Test Bench
Timing
Model Simulate
Dept. of E&C, NITKS August 2006
Analysis
Check for syntax and semantic errors
syntax: grammar of the language
architecture body
…
11
Elaboration
“Flattening” the design hierarchy
create ports
create signals and processes within architecture body
for each component instance, copy instantiated entity and
architecture body
repeat recursively
bottom out at purely behavioral architecture bodies
Elaboration Example
reg4(struct) bit0
d_latch
d0 q0
d q
clk
bit1
d_latch
d1 q1
d q
clk
bit2
d_latch
d2 q2
d q
clk
bit3
d_latch
d3 q3
d q
gate clk
and2
en int_clk
a y
clk
b
12
Elaboration Example
bit0
reg4(struct)
d_latch(basic)
d0 d q q0
clk
bit1
d_latch(basic)
d1 d q q1
clk
bit2
d_latch(basic)
d2 d q q2
clk
bit3
d_latch(basic)
d3 d q q3
gate clk
and2(basic)
en a y int_clk
clk b
process with variables
and statements
Simulation
Execution of the processes in the elaborated model
Discrete event simulation
time advances in discrete steps
when signal values change—events
A processes is sensitive to events on input signals
specified in wait statements
resumes and schedules new values on output signals
schedules transactions
13
Simulation Algorithm
Initialization phase
each signal is given its initial value
simulation time set to 0
for each process
activate
Simulation Algorithm
Simulation cycle
advance simulation time to time of next transaction
for each transaction at this time
update signal value
14
Synthesis
Translates register-transfer-level (RTL) design
into gate-level netlist
Restrictions on coding style for RTL model
Tool dependent
15