Professional Documents
Culture Documents
2 49 PDF
2 49 PDF
2 49 PDF
(1) Assignment 1 :-
(a) Introduction to VHDL
(2) Assignment 2 :-
(a) AND gate
(b) OR gate
(c) NOT gate
(d) NAND gate
(e) NOR gate
(f) XOR gate
(3) Assignment 3 :-
(a) Half Adder
(b) Full Adder
(4) Assignment 4 :-
(a) Half Subtractor
(b) Full Subtractor
(5) Assignment 5 :-
(a) 2x4 Decoder
(b) 4x1 Multiplexer (MUX)
(6) Assignment 6 :-
(a) 4-bit Binary Adder
(7) Assignment 7 :-
(a) 4-bit Composite Unit
(8) Assignment 8 :-
(a) 4-bit Arithmetic Logic Unit (ALU)
(9) Assignment 9 :-
(a) D Flip Flop
(10) Assignment 10 :-
(a) 4-bit Register
INTRODUCTION TO VHDL
VHDL is a programming language that has been designed and optimized for describing the
behaviour of digital circuits and systems.
VHDL has many features appropriate for describing the behaviour of electronic components
ranging from simple logic gates to complete microprocessors and custom chips. Features of
VHDL allow electrical aspects of circuit behaviour to be precisely described. The resulting
VHDL simulation models can then be used as building blocks in larger circuits for the
purpose of simulation.
One of the most important aspects of VHDL is its ability to capture the performance
specification for a circuit, in a form commonly referred to as a test bench. Test benches are
VHDL descriptions of circuit stimulus and corresponding expected outputs that verify the
behaviour of a circuit over time. Test benches should be an integral part of any VHDL
project, and should be created in parallel with other descriptions of the circuit.
AND GATE
The AND gate is a basic digital logic gate that implements AND operation between two or
more binary bits.
Logic diagram Truth table
A B C
0 0 0
0 1 0
1 0 0
1 1 1
Code
testbench.vhd design.vhd
begin
DUT: and_gate port map(a_in, b_in, c_out);
process is
begin
a_in <= '0';
b_in <= '0';
wait for 1 ns;
assert(c_out='0') report "Fail 0/0" severity error;
OUTPUT:
OR GATE
The OR gate is a basic digital logic gate that implements OR operation between two or more
binary bits.
Logic diagram Truth table
A B C
0 0 0
0 1 1
1 0 1
1 1 1
Code
testbench.vhd design.vhd
begin
DUT: or_gate port map(a_in, b_in, c_out);
process is
begin
a_in <= '0';
b_in <= '0';
wait for 1 ns;
assert(c_out='0') report "Fail 0/0" severity error;
OUTPUT:
NOT GATE
The NOT gate is a basic digital logic gate that implements NOT operation or complement
operation on a single binary bit.
Logic diagram Truth table
A B
0 1
1 0
Code
testbench.vhd design.vhd
begin
DUT: not_gate port map(a_in, b_out);
process is
begin
a_in <= '0';
wait for 1 ns;
assert(b_out='1') report "Fail 0" severity error;
OUTPUT:
NAND GATE
The NAND gate is a basic digital logic gate that implements NAND operation or NOT AND
operation between two or more binary bits.
Logic diagram Truth table
A B C
0 0 1
0 1 1
1 0 1
1 1 0
Code
testbench.vhd design.vhd
begin
DUT: nand_gate port map(a_in, b_in, c_out);
process is
begin
a_in <= '0';
b_in <= '0';
wait for 1 ns;
assert(c_out='1') report "Fail 0/0" severity error;
OUTPUT:
NOR GATE
The NOR gate is a basic digital logic gate that implements NOR operation or NOT OR
operation between two or more binary bits.
Logic diagram Truth table
A B C
0 0 1
0 1 0
1 0 0
1 1 0
Code
testbench.vhd design.vhd
begin
DUT: nor_gate port map(a_in, b_in, c_out);
process is
begin
a_in <= '0';
b_in <= '0';
wait for 1 ns;
assert(c_out='1') report "Fail 0/0" severity error;
OUTPUT:
XOR GATE
The XOR gate is a basic digital logic gate that implements XOR operation or Exclusive OR
operation between two or more binary bits.
Logic diagram Truth table
A B C
0 0 0
0 1 1
1 0 1
1 1 0
Code
testbench.vhd design.vhd
begin
DUT: xor_gate port map(a_in, b_in, c_out);
process is
begin
a_in <= '0';
b_in <= '0';
wait for 1 ns;
assert(c_out='0') report "Fail 0/0" severity error;
OUTPUT:
HALF ADDER
The half adder is a digital logic circuit which performs addition of two binary bits and
produces a sum and a carry.
Logic diagram Truth table
A B Sum Cout
0 0 0 0
0 1 1 0
1 0 1 0
1 1 0 1
Logical expression
B = A XOR B Cout = AB = A AND B
Code
testbench.vhd design.vhd
process
begin
a_in <= '0';
b_in <= '0';
wait for 1 ns;
assert(s_out='0') report "Fail 0/0" severity error;
assert(c_out='0') report "Fail 0/0" severity error;
OUTPUT:
FULL ADDER
The full adder is a digital logic circuit which performs addition of three binary bits and
produces a sum and a carry.
Logic diagram Truth table
Logical expression
Sum =
B) + C(A
=A B C = BC + AC + AB
= A XOR B XOR C = AB + AC + BC
= (A AND B) OR (A AND C) OR (B AND C)
Code
testbench.vhd design.vhd
process
begin
a_in <= '0';
b_in <= '0';
c_in <= '0';
wait for 1 ns;
assert(s_out='0') report "Fail 0/0/0" severity error;
assert(c_out='0') report "Fail 0/0/0" severity error;
OUTPUT:
HALF SUBTRACTOR
The half subtractor is a digital logic circuit which performs subtraction of two binary bits
and produces a difference and a borrow.
Logic diagram Truth table
A B Diff Borrow
0 0 0 0
0 1 1 1
1 0 1 0
1 1 0 0
Logical expression
B = A XOR B
Code
testbench.vhd design.vhd
process
begin
a_in <= '0';
b_in <= '0';
wait for 1 ns;
assert(diff_out='0') report "Fail 0/0" severity error;
assert(borrow_out='0') report "Fail 0/0" severity
error;
OUTPUT:
FULL SUBTRACTOR
The full subtractor is a digital logic circuit which performs subtraction of three binary bits
and produces a difference and a borrow.
Logic diagram Truth table
A B C Diff Borrow
0 0 0 0 0
0 0 1 1 1
0 1 0 1 1
0 1 1 0 1
1 0 0 1 0
1 0 1 0 0
1 1 0 0 0
1 1 1 1 1
Logical expression
ABC
B) + C(A
=A B C
= A XOR B XOR C
= ((NOT A) AND B) OR ((NOT A) AND C)
OR (B AND C)
Code
testbench.vhd design.vhd
process
begin
a_in <= '0';
b_in <= '0';
c_in <= '0';
wait for 1 ns;
assert(diff_out='0') report "Fail 0/0/0" severity error;
assert(borrow_out='0') report "Fail 0/0/0" severity
error;
OUTPUT:
DECODER (2 x 4)
A decoder is a combinational logic circuit with n inputs and 2n outputs. A single output line
is turned on based on the given input. A 2x4 decoder decodes 2 inputs into one of the 4
output lines.
Logic diagram Truth table
s0 s1 d0 d1 d2 d3
0 0 1 0 0 0
0 1 0 1 0 0
1 0 0 0 1 0
1 1 0 0 0 1
Logical expression
d3 = (s0)(s1) = s0 AND s1
Code
testbench.vhd design.vhd
process
begin
s0_in <= '0';
s1_in <= '0';
wait for 1 ns;
assert(d0_out='1') report "Fail 0/0" severity error;
assert(d1_out='0') report "Fail 0/0" severity error;
assert(d2_out='0') report "Fail 0/0" severity error;
assert(d3_out='0') report "Fail 0/0" severity error;
OUTPUT:
MULTIPLEXER (4 x 1)
A multiplexer is a combinational logic circuit with n select inputs, 2n data inputs and 1 data
output. A single data input is selected based on the select inputs and is passed to the data
output. A 4x1 multiplexer selects one of the 4 data inputs and passes it to the 1 data output
according to the 2 select lines.
Logic diagram Truth table
s0 s1 output
0 0 i0
0 1 i1
1 0 i2
1 1 i3
Logical expression
output =
= ((NOT s0) AND (NOT s1) AND i0) OR ((NOT s0) AND s1 AND i1) OR
(s0 AND (NOT s1) AND i2) OR (s0 AND s1 AND i3)
Code
testbench.vhd design.vhd
process
begin
Block diagram
Code
testbench.vhd design.vhd
begin ----------------------------------------------------------------
DUT: adder_4_bit port map(a_vector, b_vector,
sum_vector, cout); library IEEE;
use IEEE.std_logic_1164.all;
process
begin entity adder_4_bit is
port(
a_vector <= "1001"; a: in std_logic_vector(3 downto 0);
b_vector <= "0110"; b: in std_logic_vector(3 downto 0);
wait for 1 ns; sum: out std_logic_vector(3 downto 0);
assert(sum_vector="1111") report "Fail" carry: out std_logic);
severity error; end adder_4_bit;
assert(cout='0') report "Fail" severity error;
architecture adder_4_bit_arch of adder_4_bit is
a_vector <= "0000";
b_vector <= "0000"; component full_adder is
assert false report "Test done" severity note; port(
wait; a: in std_logic;
end process; b: in std_logic;
end test_arch; cin: in std_logic;
sum: out std_logic;
cout: out std_logic);
end component;
begin
end adder_4_bit_arch;
OUTPUT:
4-BIT COMPOSITE UNIT
A 4-bit composite unit is a digital logic circuit which performs either addition or subtraction
of 2 4-bit binary numbers depending on a particular input and produces a 4-bit sum or
difference and 1-bit carry or borrow.
Logic diagram
M OUTPUT
0 A+B
1 A-B
Code
testbench.vhd design.vhd
-- Testbench for 4-bit composite unit -- Design for 4-bit composite unit
library IEEE; library IEEE;
use IEEE.std_logic_1164.all; use IEEE.std_logic_1164.all;
OUTPUT:
4-BIT ARITHMETIC LOGIC UNIT (ALU)
A 4-bit ALU is a digital logic circuit which performs different types of arithmetic operations
between either 1 or 2 4-bit binary numbers depending on particular select inputs and
produces a 4-bit sum output and 1-bit carry output. The following ALU is designed to
perform five different operations. They are :-
(a) Addition (ADD) (b) Subtraction (SUB) (c) Increment (INC)
(d) Decrement (DEC) (e) Transfer (TRS)
Logic diagram
Block diagram
Truth table
select0 select1 c_in Operation name Operation Operation
code result
0 0 0 Addition ADD A+B
0 0 1 Addition with carry ADC A+B+1
0 1 0 Subtraction with carry SUC
0 1 1 Subtraction SUB A B
1 0 0 Transfer TRS A
1 0 1 Increment INC A+1
1 1 0 Decrement DEC A 1
1 1 1 Transfer TRS A
Code
testbench.vhd design.vhd
process --------------------------------------------------------------------
begin
--ADD --Design of full adder
s0_in <= '0'; library IEEE;
s1_in <= '0'; use IEEE.std_logic_1164.all;
cin <= '0';
a_vector <= "1001"; entity full_adder is
b_vector <= "0110"; port(
wait for 1 ns; a: in std_logic;
assert(sum_vector="1111") report "Fail ADD" b: in std_logic;
severity error; cin: in std_logic;
assert(cout='0') report "Fail ADD" severity sum: out std_logic;
error; cout: out std_logic);
end full_adder;
--SUB
s0_in <= '0'; architecture full_adder_arch of full_adder is
s1_in <= '1'; begin
cin <= '1'; process(a, b, cin) is
a_vector <= "1010"; begin
b_vector <= "0111"; sum <= a xor b xor cin;
wait for 1 ns; cout <= (a and b) or (a and cin) or (b and cin);
assert(sum_vector="0011") report "Fail SUB" end process;
severity error; end full_adder_arch;
assert(cout='1') report "Fail SUB" severity
error; --------------------------------------------------------------------
end alu_4bit_arch;
OUTPUT:
D-FLIP FLOP
A D-Flip Flop or a Data Flip Flop is a sequential circuit which has one data input D and one
Code
testbench.vhd design.vhd
process
begin
clk_in <= '1';
d_in <= '0';
wait for 1 ns;
assert(q_out='0') report "Fail 1/0" severity
error;
assert(qc_out='1') report "Fail 1/0" severity
error;
-- Clear inputs
d_in <= '0';
clk_in <= '0';
Truth table
CLK Q(t+1)
0 Q(t)
1 D
Code
testbench.vhd design.vhd
end register_arch;
OUTPUT: