Experiment No.1: A Binary To Gray Converter
Experiment No.1: A Binary To Gray Converter
1) 2x4 Decoder
VHDL CODE:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity dec_24 is
Port ( input : in STD_LOGIC_VECTOR (1 downto 0);
output : out STD_LOGIC_VECTOR (3 downto 0));
end dec_24;
begin
output<="0001" when input<="00" else
"0010" when input<="01" else
"0100" when input<="10" else
"1000" when input<="11";
end dec_arch;
SIMULATION
SYNTHESIS
TRUTH TABLE
A B Y0 Y1 Y2 Y3
0 0 1 0 0 0
0 1 0 1 0 0
1 0 0 0 1 0
1 1 0 0 0 1
BLOCK DIAGRAM
2) 4x2 Encoder
VHDL CODE:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity enc_42 is
Port ( input : in STD_LOGIC_VECTOR (3 downto 0);
output : out STD_LOGIC_VECTOR (1 downto 0));
end enc_42;
begin
output<="00" when input<="0001" else
"01" when input<="0010" else
"10" when input<="0100" else
"11" when input<="1000";
end architecture;
SIMULATION
SYNTHESIS
entity converter is
Port ( input : in STD_LOGIC_VECTOR (3 downto 0);
output : out STD_LOGIC_VECTOR (3 downto 0));
end converter;
begin
output(3)<=input(3);
output(2)<=input(3) xor input(2);
output(1)<=input(2) xor input(1);
output(0)<=input(1) xor input(0);
end convert_arch;
EXPERIMENT NO. 2
AIM : Model a flip-flop, register and a latch in VHDL. Implement with
asynchronous and synchronous reset.
a) D flip-flop : Synchronous
VHDL CODE :
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity dff is
port (d,clk,rst : IN std_logic;
q : OUT std_logic);
end dff;
SIMULATION :
RTL SCHEMATIC :
b) D flip-flop : ASYNCHRONOUS
VHDL CODE :
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity DFFASR is
port
(ASR,D,CLK: IN STD_LOGIC;
Q :OUT STD_LOGIC);
end DFFASR;
architecture Behavioral of DFFASR is
begin
process(CLK,ASR)
begin
if(ASR='1') then
Q <= '0';
elsif(CLK'EVENT and CLK ='1') then
Q <= D;
end if;
end process;
end Behavioral;
SIMULATION :
RTL SCHEMATIC :
c) LOADABLE REGISTER : Synchronous
VHDL CODE :
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity LRSR is
port
( Din: in std_logic_vector(7 downto 0);
Qout: out std_logic_vector(7 downto 0);
Load,clk,reset: in std_logic );
end LRSR;
RTL SCHEMATIC :
VHDL CODE :
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity LRASR is
port
( Din: in std_logic_vector(7 downto 0);
Qout: out std_logic_vector(7 downto 0);
Load,clk,reset: in std_logic );
end LRASR;
SIMULATION :
RTL SCHEMATIC :
e) LATCH
VHDL CODE :
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity latch is
port (d,rst : IN std_logic;
q : OUT std_logic);
end latch;
SIMULATION :
RTL SCHEMATIC :
EXPERIMENT NO. 4
AIM : Model a Serial in parallel out (SIPO) shift register using VHDL.
VHDL CODE :
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity SIPO is
port
(clk,x: in std_logic;
q : out std_logic_vector(3 downto 0)
);
end SIPO;
begin
process(clk)
begin
if clk'event and clk='1' then
q1(3)<=q1(2);
q1(2)<=q1(1);
q1(1)<=q1(0);
q1(0)<=x;
end if;
end process;
q<=q1;
end Behavioral;
SIMULATION :
RTL SCHEMATIC :
EXPERIMENT NO. 5
AIM : Model a Binary counter, Ripple counter and BCD counter using VHDL.
1) BINARY COUNTER
VHDL CODE :
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity binarycounter is
Port ( CLK : in STD_LOGIC;
OUTP : out STD_LOGIC_VECTOR (3 downto 0);
DIRECTION : in STD_LOGIC);
end binarycounter;
RTL SCHEMATIC :
(a) RIPPLE COUNTER
VHDL CODE :
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity ripple is
end ripple;
component TFF
port
(T,CLK: IN STD_LOGIC;
Q :out STD_LOGIC
);
end component;
begin
OUTP<= OUTP1;
end STRUCTURAL;
SIMULATION :
RTL SCHEMATIC :
VHDL CODE :
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity bcdcounter is
port
(
CLK : IN STD_LOGIC;
OUTP: OUT STD_LOGIC_VECTOR(3 DOWNTO 0)
);
end bcdcounter;
PROCESS(CLK)
begin
SIMULATION :
RTL SCHEMATIC :
EXPERIMENT NO. 6
AIM : Model an ALU using VHDL.
VHDL CODE :
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity ALU is
Port ( A : in STD_LOGIC_VECTOR (3 downto 0);
B : in STD_LOGIC_VECTOR (3 downto 0);
rst : in STD_LOGIC;
sel : in STD_LOGIC_VECTOR (2 downto 0);
carry : out STD_LOGIC;
o : out STD_LOGIC_VECTOR (3 downto 0);
en : in STD_LOGIC);
end ALU;
SIMULATION :
RTL SCHEMATIC :
Experiment 3
To check whether an input stream of bits is divisble by 5.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity mod5 is
port(num :in std_logic_vector(7 downto 0);
div :out std_logic);
end mod5;
end if;
end loop;
else
div <= '0';
end if;
end process;
end Behavioral;
Output:
Experiment 7
Design of a traffic light controller using VHDL.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity traffic is
port(yellow : out std_logic;
green : out std_logic;
red : out std_logic;
reset : in std_logic;
clock : in std_logic);
end traffic;
process(reset,clock)
variable count :integer range 0 to 10:=0;
variable state :states;
begin
if(reset ='1') then
state := s0;
count := 0;
red<='1';
else
red<= '1';
yellow<='0';
green<='0';
count := count+1;
end if;
else
red<= '0';
yellow<='1';
green<='0';
count := count+1;
end if;
elsif(state =s2) then
if(count = 5) then
state := s3;
count := 0;
else
red<= '0';
yellow<='0';
green<='1';
count := count+1;
end if;
else
red<= '0';
yellow<='1';
green<='0';
count := count+1;
end if;
end if;
end if;
end process;
end Behavioral;
Output: