VHDL Logic Gates and Adders Simulation
VHDL Logic Gates and Adders Simulation
COMMUNICATION
Experiment No. 1
Simulation using all the modeling styles and Synthesis of all the
logic gates using VHDL
AIM:
Perform Zero Delay Simulation of all the logic gates written in behavioral,
dataflow and structural modeling style in VHDL using a Test bench. Then,
Synthesize each one of them on Xilinx 8.1 Project Navigator.
Block Diagram:
A And, Nand,
Or, Nor, C
Xor, Xnor
B
Truth table:
And Gate: Or Gate:
A B Y A B Y
0 0 0 0 0 0
0 1 0 0 1 1
1 0 0 1 0 1
1 1 1 1 1 1
Boolean Equation:
library ieee;
use ieee.std_logic_1164.all;
entity andg is
port (a,b : in std_logic;
c : out std_logic
);
end andg;
library ieee;
use ieee.std_logic_1164.all;
entity org is
port (a,b : in std_logic;
c : out std_logic
entity nandg is
port (a,b : in std_logic;
c : out std_logic
);
end nandg;
process(a,b)
variable v : std_logic_vector(1 downto 0);
begin
v := a & b;
case v is
when "00" => c <= '1';
when "01" => c <= '1';
when "10" => c <= '1';
when "11" => c <= '0';
when others => c <= 'Z';
end case;
end process;
end nandg_beh;
entity norg is
port (a,b : in std_logic;
c : out std_logic
);
end norg;
process(a,b)
variable v : std_logic_vector(1 downto 0);
begin
v := a & b;
case v is
when "00" => c <= '1';
when "01" => c <= '0';
when "10" => c <= '0';
when "11" => c <= '0';
when others => c <= 'Z';
library ieee;
use ieee.std_logic_1164.all;
entity xorg is
port (a,b : in std_logic;
c : out std_logic
);
end xorg;
library ieee;
use ieee.std_logic_1164.all;
entity Xnorg is
port (a,b : in std_logic;
process(a,b)
variable v : std_logic_vector(1 downto 0);
begin
v := a & b;
case v is
when “00” => c <= „1‟;
when “01” => c <= „0‟;
when “10” => c <= „0‟;
when “11” => c <= „1‟;
when others => c <= „Z‟;
end case;
end process;
end Xnorg_beh;
begin
Simulation Waveform:
Nand Gate:
Nor Gate:
And Gate:
Or Gate:
Xor Gate:
Xnor Gate:
Simulation Waveform:
Synthesis:
Experiment No. 2
Simulation using all the modeling styles and Synthesis of 1-bit half
adder and 1-bit Full adder using VHDL
AIM:
Perform Zero Delay Simulation of 1-bit half adder and 1-bit Full adder written in
behavioral, dataflow and structural modeling style in VHDL using a Test bench. Then,
Synthesize each one of them on Xilinx 8.1 Project Navigator.
i) Xilinx Project Navigator 8.1 (Includes all the steps in the design flow from
Simulation to Implementation to download onto FPGA).
Block Diagram:
1-bit Half Adder:
A
Full Adder Sum
B (1-bit) Cout
Cin
Truth table:
Half Adder:
A B Sum Carry
0 0 0 0
0 1 1 0
1 0 1 0
1 1 0 1
Boolean Equation:
Half Adder:
Sum = A B
Carry = A.B
Full Adder:
Sum = A B Cin
Cout = A.B + [Link] + [Link]
VHDL Code:
Half Adder (Using dataflow, Behavioral Modeling):
library ieee;
use ieee.std_logic_1164.all;
entity ha_1b is
port ( a, b : in std_logic;
sum, carry : out std_logic
);
end ha_1b;
s <= a & b;
with s select
sum <= '0' when "00",
'1' when "01",
'1' when "10",
'0' when "11",
'Z' when others;
with s select
carry <= '0' when "00",
'0' when "01",
library ieee;
use ieee.std_logic_1164.all;
entity fa_1b is
port ( a, b, cin : in std_logic;
sum, cout : out std_logic
);
end fa_1b;
begin
Half Adder:
library ieee;
use ieee.std_logic_1164.all;
entity ha_1b_tst is -- test bench for a 1-bit Half adder.
end ha_1b_tst;
end ha_1b_tst_a;
Full Adder:
library ieee;
use ieee.std_logic_1164.all;
begin
process
begin
a_i <= '0';
b_i <= '0';
cin_i <= '0';
wait for 100 ns;
a_i <= '0';
b_i <= '0';
cin_i <= '1';
wait for 100 ns;
a_i <= '0';
b_i <= '1';
cin_i <= '0';
wait for 100 ns;
a_i <= '0';
b_i <= '1';
cin_i <= '1';
wait for 100 ns;
a_i <= '1';
b_i <= '0';
cin_i <= '0';
wait for 100 ns;
a_i <= '1';
b_i <= '0';
cin_i <= '1';
wait for 100 ns;
a_i <= '1';
b_i <= '1';
cin_i <= '0';
wait for 100 ns;
a_i <= '1';
b_i <= '1';
cin_i <= '1';
wait for 100 ns;
end process;
end fa_1b_tst_a;
Full Adder:
Synthesis:
Half Adder:
Full Adder:
Full Adder:
Aim:
Perform Zero Delay Simulation of 2:1 Multiplexer and 4:1 Multiplexer written in
behavioral, dataflow and structural modeling style in VHDL using a Test bench. Then,
Synthesize each one of them on Xilinx 8.1 Project Navigator.
i) Xilinx Project Navigator 8.1 (Includes all the steps in the design flow from
Simulation to Implementation to download onto FPGA).
Block Diagram:
2:1 Multiplexer:
A
2:1
Y
B Multiplexer
4:1 Multiplexer:
A
4:1
B
Multiplexer Y
C
S1 S0
S A B Y
0 0 0 0
0 0 1 0
0 1 0 1
0 1 1 1
1 0 0 0
1 0 1 1
1 1 0 0
1 1 1 1
4:1 Multiplexer:
A B Y
0 0 A
0 1 B
1 0 C
1 1 D
Boolean Equation:
2:1 Multiplexer:
Y = A.S‟ + B.S
4:1 Multiplexer:
Y = A.S1‟.S0‟ + B.S1‟.S0 + C.S1.S0‟ + D.S1.S0
VHDL Code:
2:1 Multiplexer ( in dataflow and behavioral modeling style) :
library ieee;
use ieee.std_logic_1164.all;
entity mux21 is
port ( a,b,s : in std_logic;
y : out std_logic
);
end mux21;
begin
y <= (((not s) and a) or (s and b));
end mux21_df;
library ieee;
use ieee.std_logic_1164.all;
entity mux41 is
port ( a,b,c,d,s1,s0 : in std_logic;
y : out std_logic);
end mux41;
process (a,b,c,d,s1,s0)
begin
if (s1 = '0' and s0 = '0') then
y <= a;
elsif (s1 = '0' and s0 = '1') then
y <= b;
elsif (s1 = '1' and s0 = '0') then
y <= c;
elsif (s1 = '1' and s0 = '1') then
y <= d;
else
y<= 'Z';
end if;
end process;
end mux41_beh1;
library ieee;
use ieee.std_logic_1164.all;
entity mux21_tst is
end mux21_tst;
4: 1 Multiplexer:
library ieee;
use ieee.std_logic_1164.all;
entity mux41_tst is
end mux41_tst;
process
begin
a <= '0';
b <= '1';
c <= '1';
d <= '0';
s1 <= '0';
s1 <= '1';
s0 <= '0';
wait for 100 ns;
s1 <= '1';
s0 <= '1';
wait for 100 ns;
end process;
end mux41_tst_a;
Simulation Waveform:
Synthesis:
2 :1 Multiplexer:
4 :1 Multiplexer:
Experiement No. 4
Aim:
Perform Zero Delay Simulation 1:4 Demultiplexer in VHDL using a Test bench. Then,
Synthesize on Xilinx 8.1 Project Navigator.
Block Diagram:
1:4
A Demultiplexer Y
S
Truth Table:
Input Select Output
A 00 Y(0)
B 01 Y(1)
C 10 Y(2)
D 11 Y(3)
Boolean Equation:
Y(3) = A.S.(1)‟.S(0)‟
Y(2) = B.S.(1)‟.S(0)
Y(1) = C.S.(1).S(0)‟
Y(0) = D.S.(1).S(0)
library ieee;
use ieee.std_logic_1164.all;
entity demux14 is
port ( a : in std_logic;
s : in std_logic_vector(1 downto 0);
y : out std_logic_vector(3 downto 0)
);
end demux14;
architecture demux14_beh of demux14 is -- behavioral modeling using case ….. end case
begin
process(a,s)
begin
case s is
when "00" => y <= ( a & '0' & '0' & '0');
when "01" => y <= ('0' & a & '0' & '0');
when "10" => y <= ('0' & '0' & a & '0');
when "11" => y <= ('0' & '0' & '0' & a );
when others => y <= "0000";
end case;
end process;
end demux14_beh;
entity demux14_tst is
end demux14_tst;
Simulation Waveform:
Synthesis:
Aim:
Perform Zero Delay Simulation 2:4 Decoder in VHDL using a Test bench. Then, Synthesize on
Xilinx 8.1 Project Navigator.
Block Diagram:
2:4
A Decoder Y
Truth Table:
A Y
00 0001
01 0010
10 0100
11 1000
Boolean Equation:
library ieee;
use ieee.std_logic_1164.all;
entity decod24 is
port ( a : in std_logic_vector(1 downto 0);
y : out std_logic_vector(3 downto 0)
);
end decod24;
architecture decod24_beh of decod24 is -- behavioral modeling using case … end case begin
process(a)
begin
case a is
when "00" => y <= "0001";
when "01" => y <= "0010";
when "10" => y <= "0100";
when "11" => y <= "1000";
when others => y <= "0000";
end case;
end process;
end decod24_beh;
VHDL Test Bench:
library ieee;
use ieee.std_logic_1164.all;
entity decod24_tst is
end decod24_tst;
begin
process
begin
a1 <= "00";
wait for 100 ns;
Synthesis:
Experiement No. 6
Aim:
Perform Zero Delay Simulation 4:2 Encoder in VHDL using a Test bench. Then, Synthesize on
Xilinx 8.1 Project Navigator.
Block Diagram:
A 4:2 Y
Encoder
Truth Table:
A Y
1000 00
0100 01
0010 10
0001 11
Boolean Equation:
entity encod42 is
port (a : in std_logic_vector(3 downto 0);
y : out std_logic_vector(1 downto 0)
);
end encod42;
entity encod42_tst is
end encod42_tst;
begin
process
begin
a1 <= "0001";
wait for 100 ns;
a1 <= "0010";
wait for 100 ns;
a1 <= "0100";
wait for 100 ns;
a1 <= "1000";
wait for 100 ns;
Department Electronics & Communication
30
end process;
end encod42_tst_a;
Simulation Waveform:
Synthesis:
Aim:
Perform Zero Delay Simulation 4:2 Priority Encoder in VHDL using a Test bench.
Then, Synthesize on Xilinx 8.1 Project Navigator.
Block Diagram:
4:2 Y
A Priority
Encoder
Truth Table:
Boolean Equation:
Y(1) = A(3) + A(2)
Y (0) = A(2)‟.A(1) + A(3).A(2) + A(3).A(0)
VHDL Code:
library ieee;
use ieee.std_logic_1164.all;
entity pri_encod42 is
port (a : in std_logic_vector(3 downto 0);
y : out std_logic_vector(1 downto 0);
valid : out std_logic
);
end pri_encod42;
library ieee;
use ieee.std_logic_1164.all;
entity pri_encod42_tst is
end pri_encod42_tst;
a <= “1101”;
wait for 100 ns;
a <= “1110”;
wait for 100 ns;
a <= “1111”;
wait for 100 ns;
end process;
end pri_encod42_tst_a;
Simulation Waveform:
Synthesis:
Experiement No. 8
Aim:
Perform Zero Delay Simulation of magnitude comparator 1-bit in VHDL using a Test bench.
Then, Synthesize on Xilinx 8.1 Project Navigator.
Block Diagram:
AgtB
A Magnitude
B Comparator AltB
1-bit AeqB
Truth Table:
Boolean Equation:
AgtB = A.B‟
AltB = A‟.B
AeqB = A‟.B‟ + A.B
VHDL Code:
Department Electronics & Communication
36
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity magcomp1 is
port (a,b : in std_logic;
agtb, aeqb, altb : out boolean
);
end magcomp1;
entity magcomp1_tst is
end magcomp1_tst;
Synthesis:
Experiement No. 9
Aim:
Perform Zero Delay Simulation of d latch and d flip flop in VHDL using a Test bench.
Then, Synthesize on Xilinx 8.1 Project Navigator.
VHDL Code:
D-latch:
library ieee;
use ieee.std_logic_1164.all;
entity dlatch is
port (d,en,reset : in std_logic;
q : out std_logic
);
end dlatch;
variable s : std_logic;
begin
if (reset = „1‟) then
s :=‟0‟;
elsif (en = „1‟) then
s := d;
else
s := s;
end if;
q <= s;
end process;
end dlatch_beh1;
library ieee;
use ieee.std_logic_1164.all;
entity dff is
port (d,clk,reset : in std_logic;
q : out std_logic
);
end dff;
entity dlatch_tst is
end dlatch_tst;
process
begin
reset <= '1';
en <= '0';
d <= '0';
wait for 200 ns;
reset <= '0';
en <= '1';
d <= '1';
wait for 50 ns;
d <= '0';
wait for 30 ns;
d <= '1';
wait for 10 ns;
d <= '0';
wait for 10 ns;
en <= '0';
begin
dff_i : dff port map ( d,clk,reset,q);
Aim:
Perform Zero Delay Simulation of JK, T, Flip flop in VHDL using a Test bench. Then,
Synthesize on Xilinx 8.1 Project Navigator.
VHDL Code:
JK-flip flop:
library ieee;
use ieee.std_logic_1164.all;
entity JKff is
port (j,k,clk,reset : in std_logic;
q : out std_logic
);
end JKff;
T-flip flop:
library ieee;
use ieee.std_logic_1164.all;
entity tff is
port (t,clk,reset : in std_logic;
q : out std_logic
);
end tff;
library ieee;
use ieee.std_logic_1164.all;
entity JKff_tst is
end JKff_tst;
process
begin
reset <= '1';
j <= '0';
k <= '0';
wait for 200 ns;
reset <= '0';
j <= '0';
k <= '1';
wait for 100 ns;
j <= '1';
k <= '0';
wait for 100 ns;
j <= '1';
k <= '1';
wait for 100 ns;
end process;
end jkff_tst_a;
library ieee;
use ieee.std_logic_1164.all;
entity tff_tst is
end tff_tst;
Simulation Waveform:
Synthesis: