E21 Lecture #21
VHDL: VHSIC Hardware Description Language
What is the overall structure of a hardware description language?
-
At its essence, the HDL consists of methods of describing the two parts of a circuit
-
The input/output characteristics of the circuit (entities)
-
The internal functioning of the circuit (architectures)
-
The other main structures of the language are designed to allow hierachical design
Simple Example 1: A comparator
entity compare is
port(A, B: in bit_vector(0 to 7);
EQ: out bit);
end compare;
architecture compare1 of compare is
begin
EQ <= `1' when (A=B) else `0';
end compare1;
The Entity: Compare
-
The entity describes the input/output behavior of the circuit
-
bit is a data type that describes a single wire carrying a Boolean value
-
bit_vector is a data type that describes a set of wires carrying Boolean values
-
The architecture describes the function of the circuit
-
When the bits on the A and B wire sets are identical, then the circuit outputs a `1'
-
Otherwise, it outputs a `0'
-
The conditional assignment statement is a basic tool of VHDL
-
Note the architecture has to have a unique name, since there can be more than on architecture for a given entity
-
A complete VHDL design must contain at least one entity and at least one architecture for that entity.
Other major language elements
-
Packages
-
Like the class declaration for a C++ class
-
Specify constants, data types, function prototypes, aliases, etc..
-
Tell the rest of the world how to use the functions declared in the related package body
-
Package Body
-
A set of functions/routines/circuits you can put into a library for reuse
-
Configurations
-
Specify which architectures go with which entities, etc.
Levels of Abstraction (styles)
-
Behavioral
-
Performance descriptions
-
Test Benches
-
Sequential Descriptions
-
State machines
You can imply registers and register transfers using behavioral language, but there is no guarantee the circuit will work exactly as you want it to.
-
Dataflow (Register-Transfer Level)
-
State machines
-
Register transfers
-
Selected assignments
-
Arithmetic operators
-
Boolean equations
Highest level that synthesis tools (tools that map VHDL to hardware) can handle
-
Structural
-
Boolean equations
-
Hierarchy
-
Physical Information
Netlist representation of the circuit
Example
Shifter and comparator
-
Block diagram is a hierarchical representation
Comparator
-- Eight-bit comparator
-- this is a comment
--
-- this line includes the ieee library into the program
library ieee
-- this line specifies which part of the library to include
-- library name . package name . specific entities to use
use ieee.std_logic_1164.all
-- begin an entity
-- in Altera, the name of your entity has to be the name of the file
entity compare is
-- the port command specifies the input/output specs
-- std_logic_vector is a Boolean vector data type
-- in specifies that A and B are inputs to the circuit
port (A, B: in std_logic_vector(0 to 7);
-- std_logic is a single Boolean variable
-- out specifies that EQ is an output of the circuit
EQ: out std_logic);
-- end statement closes the entity description
-- note the semicolons at the end of each line
end compare;
-- architecture statement begins the architecture description
-- architecture must have a unique name
-- can have multiple architectures
architecture compare1 of compare is
-- architecture body requires a begin statement
begin
-- conditional assignment statement
-- `1' and `0' are the std_logic representations of hi and lo
EQ <= `1' when (A = B) else `0'
-- end statement (note semi-colon)
end compare1;
Conditional Assignment
-
Can be nested: A when (Sel = "00") else B when (Sel = "01") else C when (Sel = "10")...
-
"XXX" is of the type std_logic_vector and represents a series of Boolean values
Selected Signal Assignment
-
Similar statement is the signal assignment statement (like a case statement in C)
-
with Sel select
-
Y <= A when "00", B when "01", C when "10", D when "11";
-
Note that the conditional assigment can specify priority, while the select statement has to specifiy independent cases of the select variable
Designing a shifter using a Process
A process allows you to specify actions over time (sequential actions)
--Eight-bit shifter
--
library ieee
use ieee.std_logic_1164.all;
entity rotate is
port(Clk, Rst, Load: in std_logic;
Data, in std_logic_vector(0 to 7); -- eight bits
Q: out std_logic_vector(0 to 7); -- eight bits
end rotate
architecture rotate1 of rotate is
-- this line creates an 8-bit register in the design
-- note that signal assignments come before the begin stmt
signal Qreg: std_logic_vector(0 to 7);
begin
-- process activates when either Rst or Clk changes
-- process name in this case is reg
reg:process(Rst, Clk)
begin
if Rst = `1' then -- Asynchronous reset part
-- assign Qreg the zero vector
Qreg <= "0000000";
-- note the spelling of elsif
-- this says if Clk is 1 and it was Clk that changed
elsif (Clk = `1' and Clk'event) then
if(Load = `1') then
Qreg <= Data;
else
-- modifies the order of Q
Qreg <= Qreg(1 to 7) & Qreg(0);
-- need an end if statement (note semi-colon
end if;
end if;
-- need an end process statement
end process;
-- this sets the output of the circuit to Qreg
Q <= Qreg;
end rotate1;
The process will activate any time there is an event on Rst or Clk (sensitivity list)
You can consider a process as executing in zero time (just like conditional boxes in an ASM diagram)
Concurrent v. Sequential statements
-
All statements in an architecture are executed simultaneously.
-
Order within the architecture does not matter.
-
A process is simply a concurrent statement, within which are sequential logic statements.
-
Sequential statements do not imply that sequential logic will result.