Professional Documents
Culture Documents
Department of Electronics Engineering: Experiment No: 1 Title
Department of Electronics Engineering: Experiment No: 1 Title
Department of Electronics Engineering: Experiment No: 1 Title
Experiment No: 1
Title: Study of basic VHDL code: Adder (Dataflow)
To study basic structure of VHDL code and to understand use of test bench for simulation.
To know the process for implementation on CPLD.
COs to be achieved:
CO 1: Use basic Concurrent and Sequential statements in VHDL and write codes for simple
applications
CO 2: Test a VHDL code and verify the circuit model.
CO 3: Synthesize and Implement the designed circuits on CPLD/ FPGA.
Work to be done
Upload VHDL codes for half adder, full adder ( structural) and four-bit adder (structural) and test
bench for half adder and 4-bit adder.
Roll No:2022019
K. J. Somaiya College of Engineering, Mumbai-77
(A Constituent College of Somaiya Vidyavihar University)
Department of Electronics Engineering
VHDL codes-
Half Adder-
library ieee;
use ieee.std_logic_1164.all;
entity halfadd is
port (A,B: in std_logic;
S,C: out std_logic);
end halfadd;
Roll No:2022019
K. J. Somaiya College of Engineering, Mumbai-77
(A Constituent College of Somaiya Vidyavihar University)
Department of Electronics Engineering
Full Adder-
library ieee;
use ieee.std_logic1164.all;
entity full_adder is
port (A, b,Cin: in std_logic;
Sum,Carry: out std_logic;
end full_adder;
end fa_arch;
Roll No:2022019
K. J. Somaiya College of Engineering, Mumbai-77
(A Constituent College of Somaiya Vidyavihar University)
Department of Electronics Engineering
4 bit Adder-
LIBRARY IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity BIT_ADDER is
port( a, b, cin : in STD_LOGIC;
sum, cout : out STD_LOGIC );
end BIT_ADDER;
LIBRARY IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity add4 is
port( a, b : in STD_LOGIC_VECTOR(3 downto 0);
ans : out STD_LOGIC_VECTOR(3 downto 0);
cout : out STD_LOGIC );
end add4;
component BIT_ADDER
port( a, b, cin : in STD_LOGIC;
sum, cout : out STD_LOGIC );
end component;
Test-Bench-
Half Adder-
library ieee;
use ieee.std_logic_1164.all;
entity halfadd_tb is
end halfadd_tb;
component halfadd is
port (A : in std_logic;B : in std_logic;
C : out std_logic;S : out std_logic);
end component;
begin
U1 : halfadd port map(A => A, B => B, C => C, S=> S);
process
Roll No:2022019
K. J. Somaiya College of Engineering, Mumbai-77
(A Constituent College of Somaiya Vidyavihar University)
Department of Electronics Engineering
begin
A<='0'; B<='0'; wait for 10 ns;
A<='0'; B<='1'; wait for 10 ns;
A<='1'; B<='0'; wait for 10 ns;
A<='1'; B<='1'; wait for 10ns;
end process
end halfadd_tb arch;
Full Adder-
library IEEE;
use IEEE.std_logic_1164.ALL;
entity fulladd_tb is
end fulladd_tb;
architecture fulladd_tb_arch of fulladd_tb is
component fulladd is
port(A,B,Cin:IN std_logic;
Sum,Carry : OUT std_logic);
end component;
signal A,B,Cin,Sum,Carry:std_logic;
Roll No:2022019
K. J. Somaiya College of Engineering, Mumbai-77
(A Constituent College of Somaiya Vidyavihar University)
Department of Electronics Engineering
begin
u1: fulladd port map(A=>A,B=>B,Cin=>Cin,Sum=>Sum,Carry=>Carry);
process
begin
A<='0';B<='0';Cin<='0';wait for 10ps;
A<='0';B<='0';Cin<='1';wait for 10ps;
A<='0';B<='1';Cin<='0';wait for 10ps;
A<='0';B<='1';Cin<='1';wait for 10ps;
A<='1';B<='0';Cin<='0';wait for 10ps;
A<='1';B<='0';Cin<='1';wait for 10ps;
A<='1';B<='1';Cin<='0';wait for 10ps;
A<='1';B<='1';Cin<='1';wait for 10ps;
end process;
end fulladd_tb_arch;
Roll No:2022019
K. J. Somaiya College of Engineering, Mumbai-77
(A Constituent College of Somaiya Vidyavihar University)
Department of Electronics Engineering
4 bit Adder-
library IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.STD_LOGIC_unsigned.all;
port(
A: in STD_LOGIC_VECTOR(3 downto 0); B: in
STD_LOGIC_VECTOR(3 downto 0); Carry: out
STD_LOGIC;
Sum: out STD_LOGIC_VECTOR(3 downto 0)
);
end component;
for i in 0 to 15 loop
A<=A+1;
for j in 0 to 15 loop
B<=B+1;
wait for 10ns;end
loop;
end loop; end
process;
end fourbitadder_tb_arch;
Roll No:2022019
K. J. Somaiya College of Engineering, Mumbai-77
(A Constituent College of Somaiya Vidyavihar University)
Department of Electronics Engineering
Roll No:2022019
K. J. Somaiya College of Engineering, Mumbai-77
(A Constituent College of Somaiya Vidyavihar University)
Department of Electronics Engineering
'1';
end arch_xyz;
Ans:
The given code is similar to XOR gate as the output ‘z’ is low (0) if both the inputs ‘x’ and ‘y’ are
same i.e. if both of them are high or if both of them are low at the same time. Output is high if ‘x’
and ‘y’ are different.
library ieee;
use ieee.std_logic_1164.all;
entity xyz_tb is
end xyz_tb;
x <= '0';
y <= '0';
wait for 20ns;
x <= '0';
y <= '1';
wait for 20ns;
x <= '1';
y <= '0';
Roll No:2022019
K. J. Somaiya College of Engineering, Mumbai-77
(A Constituent College of Somaiya Vidyavihar University)
Department of Electronics Engineering
x <= '1';
y <= '1';
wait for 20ns;
end process;
end;
Conclusion:
We learnt how to use Quartus and the basics of VHDL by performing simulations for Half adder,
Full adder and a 4 bit adder. Also, to simulate the waveform output by writing test bench and
using Modelsim.
Roll No:2022019