Q 1:– Design All Logical Gates Using VHDL. Solution: - AND Gate:- Source Code: - -------------------------------------------------- -- AND gate -- two descriptions provided -------------------------------------------------- library ieee; use ieee.std_logic_1164.all; -------------------------------------------------- entity AND_ent is port( x: in std_logic; y: in std_logic; F: out std_logic ); end AND_ent; -------------------------------------------------- architecture AND_behav1 of AND_ent is begin process(x, y) begin -- compare to truth table if ((x='1') and (y='1')) then F <= '1'; else F <= '0'; end if; end process;
Digital System Design Final Practical File!!!3rd year CSE!!!
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Q 1:– Design All Logical Gates Using VHDL. Solution: - AND Gate:-
Q 5:– Write a VHDL Program for a Comparator and check the simulation. Solution: - COMPARATOR:-
Source Code: -
LIBRARY ieee ;
USE ieee.std_logic_1164.all ;
USE ieee.std_logic_arith.all ;
ENTITY compare IS
PORT ( A, B : IN SIGNED(3 DOWNTO 0) ;
AeqB, AgtB, AltB : OUT STD_LOGIC ) ;
END compare ;
ARCHITECTURE Behavior OF compare IS
BEGIN
AeqB <= '1' WHEN A = B ELSE '0' ;
AgtB <= '1' WHEN A > B ELSE '0' ;
AltB <= '1' WHEN A < B ELSE '0' ;
END Behavior ;
Sample Waveform Output: -
Q 6:– Write a VHDL Program for a Code Convertor and check the simulation. Solution: - BCD to BINARY CODE CONVERTOR:-
Source Code: - library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity BCD2BIN is
Port ( bcd : in STD_LOGIC_VECTOR (4 downto 0);
binary : out STD_LOGIC_VECTOR (3 downto 0));
end BCD2BIN;
architecture Behavioral of BCD2BIN is
begin
process (bcd)
begin
case bcd is
when "00000" => binary <= "0000";
when "00001" => binary <= "0001";
when "00010" => binary <= "0010";
when "00011" => binary <= "0011";
when "00100" => binary <= "0100";
when "00101" => binary <= "0101";
when "00110" => binary <= "0110";
when "00111" => binary <= "0111";
when "01000" => binary <= "1000";
when "01001" => binary <= "1001";
when "10000" => binary <= "1010";
when "10001" => binary <= "1011";
when "10010" => binary <= "1100";
when "10011" => binary <= "1101";
when "10100" => binary <= "1110";
when "10101" => binary <= "1111";
when others => binary <= "XXXX";
end case;
end process;
end Behavioral;
Sample Waveform Output: -
Q 7:– Write a VHDL Program for a Flip-Flop and check the simulation. Solution: - JK FLIP FLOP:-
Source Code: - library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity jk is
Port ( J : in STD_LOGIC;
K : in STD_LOGIC;
clock : in STD_LOGIC;
reset : in STD_LOGIC;
Q : out STD_LOGIC;
Qbar : out STD_LOGIC);
end jk;
architecture Behavioral of jk is
signal state: std_logic;
signal input: std_logic_vector(1 downto 0);
begin
input <= J & K;
p: process(clock, reset) is
begin
if (reset='1') then
state <= '0';
elsif (rising_edge(clock)) then
case (input) is
when "11" =>
state <= not state;
when "10" =>
state <= '1';
when "01" =>
state <= '0';
when others =>
null;
end case;
end if;
end process;
Q <= state;
Qbar <= not state;
end Behavioral;
Sample Waveform Output: -
Q 8:– Write a VHDL Program for a Counter and check the simulation. Solution: - N BIT COUNTER:-
Source Code: - ---------------------------------------------------- -- VHDL code for n-bit counter -- -- this is the behavior description of n-bit counter -- another way can be used is FSM model. ---------------------------------------------------- library ieee ; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; ---------------------------------------------------- entity counter is generic(n: natural :=2); port( clock: in std_logic; clear: in std_logic; count: in std_logic; Q: out std_logic_vector(n-1 downto 0) ); end counter; ---------------------------------------------------- architecture behv of counter is signal Pre_Q: std_logic_vector(n-1 downto 0); begin -- behavior describe the counter process(clock, count, clear) begin if clear = '1' then Pre_Q <= Pre_Q - Pre_Q; elsif (clock='1' and clock'event) then if count = '1' then Pre_Q <= Pre_Q + 1; end if; end if; end process; -- concurrent assignment statement Q <= Pre_Q; end behv;
Sample Waveform Output: -
Q 9:– Write VHDL Programs for the following and check simulation – 1. Register 2. Shift Register Solution: - N-Bit Register:-
Source Code: - --------------------------------------------------- -- n-bit Register (ESD book figure 2.6) -- -- KEY WORD: concurrent, generic and range --------------------------------------------------- library ieee ; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; --------------------------------------------------- entity reg is generic(n: natural :=2); port( I: in std_logic_vector(n-1 downto 0); clock: in std_logic; load: in std_logic; clear: in std_logic; Q: out std_logic_vector(n-1 downto 0) ); end reg; ---------------------------------------------------- architecture behv of reg is signal Q_tmp: std_logic_vector(n-1 downto 0); begin process(I, clock, load, clear) begin if clear = '0' then -- use 'range in signal assigment Q_tmp <= (Q_tmp'range => '0'); elsif (clock='1' and clock'event) then if load = '1' then Q_tmp <= I; end if; end if; end process;
-- concurrent statement Q <= Q_tmp; end behv; ---------------------------------------------------
Sample Waveform Output: -
3-Bit Shift Register:-
Source Code: - --------------------------------------------------- -- 3-bit Shift-Register/Shifter -- -- reset is ignored according to the figure --------------------------------------------------- library ieee ; use ieee.std_logic_1164.all; --------------------------------------------------- entity shift_reg is port( I: in std_logic; clock: in std_logic; shift: in std_logic; Q: out std_logic ); end shift_reg; --------------------------------------------------- architecture behv of shift_reg is -- initialize the declared signal signal S: std_logic_vector(2 downto 0):="111"; begin
process(I, clock, shift, S) begin -- everything happens upon the clock changing if clock'event and clock='1' then if shift = '1' then S <= I & S(2 downto 1); end if; end if; end process; -- concurrent assignment Q <= S(0); end behv;
Sample Waveform Output: -
PRACTICAL FILE
DIGITAL SYSTEMDIGITAL SYSTEMDIGITAL SYSTEMDIGITAL SYSTEM
DESIGN LABDESIGN LABDESIGN LABDESIGN LAB
Softwares Used – 1. Xilinx 13.4 2. ActiveHDL 7.2 SE
Submitted To:- Submitted By:- Mr. Manoj Ahlawat Soumya S. Behera Asst. Professor 1826