E21 Lecture #21

VHDL: VHSIC Hardware Description Language

What is the overall structure of a hardware description language?

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

Other major language elements

Levels of Abstraction (styles)

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.

Highest level that synthesis tools (tools that map VHDL to hardware) can handle

Netlist representation of the circuit

Example

Shifter and comparator

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

Selected Signal Assignment

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