Monday, 27 August 2018

Half Adder using VHDL

What is adder:
The adder is a device that can add binary numbers, it can use for the addition of binary numbers, binary code decimal, address decoding and table index calculation, There are two types of adders.

  1. Half Adder 
  2. Full Adder

Half adder:
A half adder is a computational circuit which is used to add two binary numbers, it is the made by one XOR and one AND gate, it has two input (A, B) and two output (sum, carry).


Truth Table of half adder:

 INPUTS                    OUTPUTS
A         B                SUM         CARRY
0         0                    0                0
0         1                    1                0
1         0                    1                0
1         1                    0                1




Circuit diagram:




Boolean equation:
Eq.1 sum of product form
Half Adder


Eq.2



VHDL Code :

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

entity Half_adder is
Port(
a: in std_logic;
b: in std_logic;
sum : out std_logic;
carry : out std_logic );
end Half_adder;


architecture Behavioral of Half_adder is
begin

sum <= a xor b;
carry <= a and b;

end Behavioral;

Test Bench:
LIBRARY ieee;

USE ieee.std_logic_1164.ALL;

ENTITY test IS
END test;

ARCHITECTURE behavior OF test IS
-- Component Declaration for the Unit Under Test (UUT)

COMPONENT Half_adder
PORT(
a : IN std_logic;
b : IN std_logic;
sum : OUT std_logic;
carry : OUT std_logic );
END COMPONENT;

--Inputs
signal a : std_logic := '0';
signal b : std_logic := '0';


--Outputs
signal sum : std_logic;
signal carry : std_logic;


BEGIN
-- Instantiate the Unit Under Test (UUT)
uut: Half_adder PORT MAP (
a => a,
b => b,
sum => sum,
carry => carry );




-- Stimulus process
stim_proc: process
begin

-- hold reset state for 100 ns.
wait for 100 ns;
a<='0'; b<='0';
wait for 100 ns;
a<='0'; b<='1';
wait for 100 ns;
a<='1'; b<='0';
wait for 100 ns;
a<='1'; b<='1';
-- insert stimulus here

wait;
end process;
END;


RTL Schematic:
RTL Schematic Half Adder


Outputs:
Half Adder Output
                                                       a = 0      b = 0    sum = 0   carry = 0


Half Adder Output
                                                       a = 0      b = 1    sum = 1   carry = 0



Half Adder Output
                                                       a = 1      b = 0    sum = 1   carry = 0



Half Adder Output
                                                       a = 1      b = 1    sum = 0   carry = 1