ECAD LAB2 (Master Copy)
ECAD LAB2 (Master Copy)
ECAD LAB2 (Master Copy)
LOGIC GATES
AIM:
I. To verify the truth table of NOT, NOR, AND , OR, NAND, XOR using
their IC’s.
II. Develop VHDL models for 74LSXX Series Gates.
APPARATUS:
BLOCK DIAGRAMS:
Connection Diagram
FUNCTION TABLE
Connection Diagram
FUNCTION TABLE
Connection Diagram
Connection Diagram
FUNCTION TABLE
Connection Diagram
FUNCTION TABLE
Connection Diagram
FUNCTION TABLE
PROCEDURE:
VHDL CODE:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
port ( a : in STD_LOGIC;
b : in STD_LOGIC;
y_nota : out STD_LOGIC;
y_and : out STD_LOGIC;
y_or : out STD_LOGIC;
y_nand : out STD_LOGIC;
y_nor : out STD_LOGIC;
y_xor : out STD_LOGIC;
y_xnor : out STD_LOGIC);
begin
y_nota <= not a;
y_and <= a and b;
y_or <= a or b;
y_nand <= a nand b;
y_nor <= a nor b;
y_xor <= a xor b;
y_xnor <= a xnor b;
end Behavioral;
TEST BENCH:
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY tb_vhd IS
END tb_vhd;
COMPONENT logicgates
PORT( a : IN std_logic;
b : IN std_logic;
--Inputs
--Outputs
BEGIN
END;
SIMULATION OUTPUT:
APPARATUS:
BLOCK DIAGRAM:
Connection Diagram:
PROCEDURE:
9. Similarly by changing two inputs Ao, A1, A2 we get one ouput low
& others high every time.
__
10. When inputs are high , o/p O , will become low and others become
high.
VHDL CODE:
library ieee;
use ieee.std_logic_1164.all;
entity decoder3x8 is
port(G1,G2,C,B,A:in std_logic;
Y:out std_logic_vector(0 to 7));
end decoder3x8;
begin
S<=C&B&A;
process(G1,G2,S)
begin
if G2='1' then Y<="11111111";
elsif G1='0' then Y<="11111111";
elsif G1='1' and G2='0' and S="000" then Y<="01111111";
elsif G1='1' and G2='0' and S="001" then Y<="10111111";
elsif G1='1' and G2='0' and S="010" then Y<="11011111";
elsif G1='1' and G2='0' and S="011" then Y<="11101111";
elsif G1='1' and G2='0' and S="100" then Y<="11110111";
elsif G1='1' and G2='0' and S="101" then Y<="11111011";
elsif G1='1' and G2='0' and S="110" then Y<="11111101";
elsif G1='1' and G2='0' and S="111" then Y<="11111110";
else Y<="UUUUUUUU";
end if;
end process;
TEST BENCH:
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY tb_vhd IS
END tb_vhd;
COMPONENT decoder3x8
PORT(
G1 : IN std_logic;
G2 : IN std_logic;
C : IN std_logic;
B : IN std_logic;
A : IN std_logic;
Y : OUT std_logic_vector(0 to 7)
);
END COMPONENT;
--Inputs
--Outputs
BEGIN
G1<='0','1'after 20 ns;
G2<='1','0' after 20 ns;
C<='0','1' after 60ns;
B<='0','1' after 40 ns,'0' after 60 ns,'1' after 80 ns;
A<='0','1' after 30 ns,'0' after 40 ns,'1' after 50 ns,
'0' after 60 ns,'1' after 70 ns,'0' after 80 ns,
END;
SIMULATION OUTPUT:
AIM:
APPARATUS:
PROCEDURE:
BLOCK DIAGRAM:
Connection Diagram
FUNCTION TABLE:
library ieee;
use ieee.std_logic_1164.all;
entity mux8x1 is
port(C,B,A,G_L:in std_logic;
D:in std_logic_vector(7 downto 0);
Y,W:out std_logic);
end mux8x1;
begin
s<=C&B&A;
process(S,G_L)
begin
end process;
TEST BENCH:
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
USE ieee.std_logic_unsigned.all;
USE ieee.numeric_std.ALL;
ENTITY tb_vhd IS
END tb_vhd;
COMPONENT mux8x1
PORT(
C : IN std_logic;
B : IN std_logic;
A : IN std_logic;
G_L : IN std_logic;
D : IN std_logic_vector(7 downto 0);
Y : OUT std_logic;
W : OUT std_logic
);
END COMPONENT;
--Inputs
--Outputs
SIGNAL Y : std_logic;
BEGIN
END;
SIMULATION OUTPUT:
AIM:
APPARATUS:
BLOCK DIAGRAM:
Connection Diagram
PROCEDURE:
library ieee;
use ieee.std_logic_1164.all;
entity comparator4bit is
end comparator4bit;
begin
process(A,B)
begin
if A(3)>B(3) then AgrB<='1';AeqB<='0';AlsB<='0';
elsif A(3)=B(3) and A(2)>B(2) then AgrB<='1';AeqB<='0';AlsB<='0';
elsif A(3)=B(3) and A(2)<B(2) then AgrB<='0';AeqB<='0';AlsB<='1';
elsif A(3)=B(3) and A(2)=B(2) and A(1)>B(1) then
AgrB<='1';AeqB<='0';AlsB<='0';
elsif A(3)=B(3) and A(2)=B(2) and A(1)<B(1) then
AgrB<='0';AeqB<='0';AlsB<='1';
elsif A(3)=B(3) and A(2)=B(2) and A(1)=B(1) and A(0)>B(0) then
AgrB<='1';AeqB<='0';AlsB<='0';
elsif A(3)=B(3) and A(2)=B(2) and A(1)=B(1) and A(0)<B(0) then
AgrB<='0';AeqB<='0';AlsB<='1';
else AgrB<='0';AeqB<='1';AlsB<='0';
end if;
end comparator4bit;
TEST BENCH:
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
USE ieee.std_logic_unsigned.all;
USE ieee.numeric_std.ALL;
ENTITY tb_vhd IS
END tb_vhd;
COMPONENT comparator4bit
PORT(
A : IN std_logic_vector(3 downto 0);
B : IN std_logic_vector(3 downto 0);
AeqB : OUT std_logic;
AlsB : OUT std_logic;
AgrB : OUT std_logic
);
END COMPONENT;
--Inputs
--Outputs
BEGIN
END;
SIMULATION OUTPUT:
APPARATUS:
BLOCK DIAGRAMS:
PROCEDURE:
VHDL CODE:
library ieee;
use ieee.std_logic_1164.all;
entity dflipflop is
port(PR,CLR,CLK,D:in std_logic;
Q,Q_L:out std_logic);
end dflipflop;
signal tq,tqb:std_logic;
begin
process(PR,CLR,CLK)
begin
end process;
Q<=tq;
Q_L<=tqb;
TEST BENCH:
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
USE ieee.std_logic_unsigned.all;
USE ieee.numeric_std.ALL;
COMPONENT dflipflop
PORT(
PR : IN std_logic;
CLR : IN std_logic;
CLK : IN std_logic;
D : IN std_logic;
Q : OUT std_logic;
Q_L : OUT std_logic
);
END COMPONENT;
--Inputs
--Outputs
SIGNAL Q : std_logic;
SIGNAL Q_L : std_logic;
BEGIN
process
begin
CLK<='1';
wait for 5ns;
END;
SIMULATION OUTPUT:
RESULT: The truth table of D -Flip – Flop using IC 7474 was verified.
APPARATUS:
BLOCK DIAGRAM:
FUNCTION TABLE(74LS90)
PROCEDURE:
VHDLCODE:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity decadecounter is
port(CLK,R,S:in std_logic;
Q:out std_logic_vector(3 downto 0));
end decadecounter;
begin
process(CLK,R,S)
begin
end process;
Q<=count;
end decadecounter;
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
USE ieee.std_logic_unsigned.all;
USE ieee.numeric_std.ALL;
ENTITY tb_vhd IS
END tb_vhd;
COMPONENT decadecounter
PORT(
CLK : IN std_logic;
R : IN std_logic;
S : IN std_logic;
Q : OUT std_logic_vector(3 downto 0)
);
END COMPONENT;
--Inputs
--Outputs
BEGIN
END;
SIMULATION OUTPUT:
APPARATUS:
BLOCK DIAGRAM:
FUNCTION TABLES(74LS93
PROCEDURE:
VHDL CODE:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity binarycounter is
port(CLK,R:in std_logic;
Q:out std_logic_vector(3 downto 0));
end binarycounter;
process(R,CLK)
begin
end process;
Q<=count;
end binarycounter;
TEST BENCH:
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
USE ieee.std_logic_unsigned.all;
USE ieee.numeric_std.ALL;
ENTITY tb_vhd IS
END tb_vhd;
COMPONENT binarycounter
PORT(
CLK : IN std_logic;
R : IN std_logic;
Q : OUT std_logic_vector(3 downto 0)
);
END COMPONENT;
--Inputs
--Outputs
BEGIN
END;
SIMULATION OUTPUT:
RESULT: Thus the operation of 4 – bit counter using IC 7493 was studied.
APPARATUS:
BLOCK DIAGRAM
1.Clearing function:
1.After register has cleared any 4 bit serial no. can be loaded
into the register.
2. set mode CTRL switch to low.
3.set serial input switch to high.
4.Apply clock pulse which shift serial input 1 into reg Qn will be 1.
5.we can load any 4 bit number into reg.
3.Parallel I/P / Parallel O/P:
VHDL CODE:
library ieee;
use ieee.std_logic_1164.all;
entity shif_95r is
port( CLK,MODE, SER : in std_logic;
PALL : in std_logic_vector(3 downto 0);
Q_A,Q_B,Q_C,Q_D : inout std_logic
);
begin
process(CLK,MODE,SER,PALL)
begin
else O:="UUUU";
end if;
end if;
end process;
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
USE ieee.std_logic_unsigned.all;
USE ieee.numeric_std.ALL;
ENTITY tb_vhd IS
END tb_vhd;
COMPONENT shif_95r
PORT(
CLK : IN std_logic;
MODE : IN std_logic;
SER : IN std_logic;
PALL : IN std_logic_vector(3 downto 0);
Q_A : INOUT std_logic;
Q_B : INOUT std_logic;
Q_C : INOUT std_logic;
Q_D : INOUT std_logic
);
END COMPONENT;
--Inputs
--BiDirs
BEGIN
process
begin
CLK <='1';
wait for 10 ns;
CLK <='0';
wait for 10 ns;
end process;
END;
SIMULATION OUTPUT:
AIM:
APPARATUS:
BLOCK DIAGRAM:
VHDL MODEL:
library ieee;
use ieee.std_logic_1164.all;
entity univ_sreg is
port( CLR,CLK,S_L,S_R : in std_logic;
A,B,C,D : in std_logic ;
S : in std_logic_vector(1 downto 0);
Q_A,Q_B,Q_C,Q_D : inout std_logic
);
end entity univ_sreg;
TEST BENCH:
library ieee;
use ieee.std_logic_1164.all;
entity test is
end entity test;
component univ_sreg
port( CLR,CLK,S_L,S_R : in std_logic;
A,B,C,D : in std_logic ;
S : in std_logic_vector(1 downto 0);
Q_A,Q_B,Q_C,Q_D : inout std_logic
);
end component;
signal CLR,CLK,S_L,S_R,A,B,C,D,Q_A,Q_B,Q_C,Q_D : std_logic;
signal S : std_logic_vector(1 downto 0);
begin
U0:univ_sreg port map(CLR,CLK,S_L,S_R,A,B,C,D,S,Q_A,Q_B,Q_C,Q_D);
CLR <= '0','1' after 20 ns;
A <= '1';
B <= '1';
C <= '1';
D <= '1';
process
begin
clk<='1';
wait for 10 ns;
clk<= '0';
wait for 10 ns;
end process;
s<= "11",
"01" after 50 ns,
"10" after 90 ns,
SIMULATION OUTPUT:
AIM:
APPARATUS:
BLOCK DIGRAM:
FUNCTION TABLE:
VHDL CODE:
library ieee;
use ieee.std_logic_1164.all;
entity ram is
port(CLK,RST,CE,WR,RD : in std_logic;
ADD : in integer range 0 to 15;
DATA_IN : in std_logic_vector(3 downto 0);
DATA_OUT : out std_logic_vector(3 downto 0)
);
end ram;
TEST BENCH:
library ieee;
use ieee.std_logic_1164.all;
entity test_ram is
end entity test_ram;
SIMULATION OUTPUT:
AIM:
APPARATUS:
VHDL CODE:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity fifo is
generic (RAMsize: integer :=4);
port ( data_in: in std_logic_vector (7 downto 0);
clk,nrst: in std_logic;
readReq: in std_logic;
writeReq: in std_logic;
data_out: out std_logic_vector(7 downto 0);
empty: out std_logic;
full: out std_logic;
error: out std_logic);
end fifo;
begin
process(clk,nrst)
variable read_ptr, write_ptr : std_logic_vector(7 downto 0) :="00000000"; -- read and write
pointers
variable isempty , isfull : std_logic :='0';
begin
if nrst='0' then
memory <= (others => (others => '0'));
empty <='1';
full <='0';
data_out <= "00000000";
read_ptr := "00000000";
write_ptr := "00000000";
isempty :='1';
isfull :='0';
error <='0';
AIET – ECAD Lab Manual ……………………………………………………………… 45
elsif clk'event and clk='1' then
if readReq='0' and writeReq='0' then
error <='0';
end if;
if readReq='1' then
if isempty='1' then
error <= '1';
else
data_out <= memory(conv_integer(read_ptr));
isfull :='0';
full <='0';
error <='0';
if read_ptr=conv_std_logic_vector(RAMsize-1,8) then
read_ptr := "00000000";
else
read_ptr := read_ptr + '1';
end if;
if read_ptr=write_ptr then
isempty:='1';
empty <='1';
end if;
end if;
end if;
if writeReq='1' then
if isfull='1' then
error <='1';
else
memory(conv_integer(write_ptr)) <= data_in;
error <='0';
isempty :='0';
empty <='0';
if write_ptr=conv_std_logic_vector(RAMsize-1,8) then
write_ptr := "00000000";
else
write_ptr := write_ptr + '1';
end if;
if write_ptr=read_ptr then
isfull :='1';
full <='1';
end if;
end if;
end if;
end if;
end process;
end Behavioral;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
begin
u1: fifo generic map (4) port map
(data_in_t,clk_t,nrst_t,readReq_t,writeReq_t,data_out_t,empty_t,full_t,error_t);
end fifo_tb;
AIM:
APPARATUS:
VHDL CODE:
entity Alu is
port( Clk : in Std_Logic;
MODE,EN: in Std_Logic;
A,B : in Std_Logic_Vector(7 downto 0);
OPCODE : in Std_Logic_Vector(3 downto 0);
Y : out Std_Logic_Vector(7 downto 0));
end Alu;
1. J-K flip-flop
AIM:
APPARATUS:
BLOCK DIGRAM:
VHDL CODE:
library ieee;
use ieee. std_logic_1164.all;
use ieee. std_logic_arith.all;
use ieee. std_logic_unsigned.all;
entity JKFF is
PORT( J,K,CLK,PRST,CLR: in std_logic;
Q, QB: out std_logic);
end JKFF;
elsif(PRST='0')then
x:='1';
end if;
end if;
Q<=x;
QB<=not x;
end PROCESS;
end behavioral;
TEST BENCH:
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
USE ieee.std_logic_unsigned.all;
USE ieee.numeric_std.ALL;
ENTITY jfkejfijeijk_vhd IS
END jfkejfijeijk_vhd;
--Outputs
SIGNAL Q : std_logic;
SIGNAL QB : std_logic;
BEGIN
process
begin
clk<='0';
wait for 5 ns;
clk<='1';
wait for 5 ns;
end process;
END;
SIMULATION OUTPUT:
APPARATUS:
VHDL CODE:
library IEEE;
use IEEE.STD_LOGIC_1164.all;
entity encoder is
port(
d0 : in STD_LOGIC;
d1 : in STD_LOGIC;
d2 : in STD_LOGIC;
d3 : in STD_LOGIC;
a : out STD_LOGIC;
b : out STD_LOGIC
);
end encoder;
end encoder;
TESTBENCH
library ieee;
use ieee.std_logic_1164.all;
entity encoder_tb is
end encoder_tb;
component encoder
port(
d0 : in std_logic;
d1 : in std_logic;
d2 : in std_logic;
d3 : in std_logic;
signal d0 : std_logic;
signal d1 : std_logic;
signal d2 : std_logic;
signal d3 : std_logic;
signal a : std_logic;
signal b : std_logic;
begin
UUT : encoder
port map (
d0 => d0,
d1 => d1,
d2 => d2,
d3 => d3,
a => a,
b => b
);
end TB_ARCHITECTURE;
SIMULATION OUTPUT: