The VHDL Hardware Description Language: CSEE W4840
The VHDL Hardware Description Language: CSEE W4840
Description Language
CSEE W4840
Prof. Stephen A. Edwards
Columbia University
Process
Ports process (Clk)
out Component
out Signal
inout X <= (Y = ’1’) and (X = "110")
Dataflow Expression
entity full_adder is a
sum
port(a, b, c : in std_ulogic; b carry
sum, carry : out std_ulogic); c
end full_adder;
library ieee;
use ieee.std_logic_1164.all;
entity multiplexer_4_1 is
port(in0, in1 : in std_ulogic_vector(15 downto 0);
in2, in3 : in std_ulogic_vector(15 downto 0);
s0, s1 : in std_ulogic;
z : out std_ulogic_vector(15 downto 0));
end multiplexer_4_1;
library ieee;
use ieee.std_logic_1164.all;
entity multiplexer_4_1 is
port(in0, in1 : in std_ulogic_vector(15 downto 0);
in2, in3 : in std_ulogic_vector(15 downto 0);
s0, s1 : in std_ulogic;
z : out std_ulogic_vector(15 downto 0));
end multiplexer_4_1;
architecture usewith of multiplexer_4_1 is
signal sels : std_ulogic_vector(1 downto 0);
begin
sels <= s1 & s0; -- Vector concatenation
with sels select
z <=
in0 when "00",
in1 when "01",
in2 when "10",
in3 when "11",
"XXXXXXXXXXXXXXXX" when others;
end usewith;
The VHDL Hardware Description Language – p. 10/?
Three-to-eight Decoder
library ieee;
use ieee.std_logic_1164.all;
entity dec1_8 is
port (
sel : in std_logic_vector(2 downto 0);
res : out std_logic_vector(7 downto 0));
end dec1_8;
library ieee;
use ieee.std_logic_1164.all;
entity priority is
port (
sel : in std_logic_vector(7 downto 0);
code : out std_logic_vector(2 downto 0));
end priority;
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity adder is
port (
A, B : in std_logic_vector(7 downto 0);
CI : in std_logic;
SUM : out std_logic_vector(7 downto 0);
CO : out std_logic);
end adder;
architecture imp of adder is
signal tmp : std_logic_vector(8 downto 0);
begin
tmp <= conv_std_logic_vector((conv_integer(A) +
conv_integer(B) +
conv_integer(CI)), 9);
SUM <= tmp(7 downto 0);
CO <= tmp(8);
end imp;
The VHDL Hardware Description Language – p. 13/?
A Very Simple ALU
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity alu is
port (
A, B : in std_logic_vector(7 downto 0);
ADD : in std_logic;
RES : out std_logic_vector(7 downto 0));
end alu;
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity comparator is
port (
A, B : in std_logic_vector(7 downto 0);
GE : out std_logic);
end comparator;
library ieee;
use ieee.std_logic_1164.all;
entity rippleadder is
port (a, b : in std_ulogic_vector(3 downto 0);
cin : in std_ulogic;
sum : out std_ulogic_vector(3 downto 0);
cout : out std_ulogic);
end rippleadder;
library ieee;
use ieee.std_logic_1164.all;
entity flipflop is
port (Clk, D : in std_ulogic;
Q : out std_ulogic);
end flipflop;
library ieee;
use ieee.std_logic_1164.all;
entity flipflop_reset is
port (Clk, Reset, D : in std_ulogic;
Q : out std_ulogic);
end flipflop_reset;
Inputs Outputs
Combinational
Logic
State
Clock
cars
This controls a traffic light at
the intersection of a busy highway
cars
and a farm road. Normally,
the highway light is green but if
a sensor detects a car on the farm
road, the highway light turns yellow then red. The
farm road light then turns green until there are no
cars or after a long timeout. Then, the farm road light
turns yellow then red, and the highway light returns to
green. The inputs to the machine are the car sensor,
a short timeout signal, and a long timeout signal. The
outputs are a timer start signal and the colors of the
highway and farm road lights.
Source: Mead and Conway, Introduction to VLSI Systems, 1980, p. 85.
The VHDL Hardware Description Language – p. 25/?
FSM for the Traffic Light Controller
C+L S
CL/T
HG HY
C: Car sensor
S: Short timeout
S/T S/T L: Long timeout
T: Start timer
FY FG St Hwy Farm
C + L/T HG G R
S CL HY Y R
FG R G
FY R Y
The VHDL Hardware Description Language – p. 26/?
Traffic Light Controller in VHDL (1)
library ieee;
use ieee.std_logic_1164.all;
entity tlc is
port (
clk : in std_ulogic;
reset : in std_ulogic;
cars : in std_ulogic;
short : in std_ulogic;
long : in std_ulogic;
highway_yellow : out std_ulogic;
highway_red : out std_ulogic;
farm_yellow : out std_ulogic;
farm_red : out std_ulogic;
start_timer : out std_ulogic);
end tlc;
The VHDL Hardware Description Language – p. 27/?
Traffic Light Controller in VHDL (2)
-- Combinational process
-- Sensitive to input changes, not clock
when FG =>
highway_yellow <= ’0’;
highway_red <= ’1’;
farm_yellow <= ’0’;
farm_red <= ’0’;
if (cars = ’0’ or long = ’1’) then
next_state <= FY;
start_timer <= ’1’;
else
next_state <= FG;
start_timer <= ’0’;
end if;
The VHDL Hardware Description Language – p. 30/?
Traffic Light Controller in VHDL (5)
when FY =>
highway_yellow <= ’0’;
highway_red <= ’1’;
farm_yellow <= ’1’;
farm_red <= ’0’;
if (short = ’1’) then
next_state <= HG;
start_timer <= ’1’;
else
next_state <= FY;
start_timer <= ’0’;
end if;
end imp;
The VHDL Hardware Description Language – p. 31/?