VHDL Vlsi Programming DSD File Modeling
VHDL Vlsi Programming DSD File Modeling
======
1. Design basic gates (AND,OR, NOT, XOR, XNOR, NAND, NOR) using VHDL.
AND X Y Z
0 0 0
0 1 0
1 0 0
1 1 1
OR
X Y Z
0 0 0
0 1 1
1 0 1
1 1 1
NOT
X Z
0 1
1 0
NAND X Y Z
0 0 1
0 1 1
1 0 1
1 1 0
NOR
X Y Z
0 0 1
0 1 0
1 0 0
1 1 0
Prepared by Vinod.gandhi@mail.com
XOR X Y Z
0 0 0
0 1 1
1 0 1
1 1 0
XNOR X Y Z
0 0 1
0 1 0
1 0 0
1 1 1
2
Prepared by Vinod.gandhi@mail.com
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity GATES is
Port ( G1 : in std_logic;
G2 : in std_logic;
N1 : out std_logic;
A1 : out std_logic;
O1 : out std_logic;
X1 : out std_logic;
NA1 : out std_logic;
NO1 : out std_logic;
XN1 : out std_logic);
end GATES;
3
Prepared by Vinod.gandhi@mail.com
x y C S
0 0 0 0
0 1 0 1
1 0 0 1
1 1 1 0
S= X Y
C= X.Y
4
Prepared by Vinod.gandhi@mail.com
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity HALF_ADDER is
Port ( HA1 : in std_logic;
HA2 : in std_logic;
HA_SUM : out std_logic;
HA_CAR : out std_logic);
end HALF_ADDER;
5
Prepared by Vinod.gandhi@mail.com
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity HALF_ADDER_COMP is
Port(HA1 : in std_logic;
HA2 : in std_logic;
HA_SUM : out std_logic;
HA_CRY : out std_logic);
end HALF_ADDER_COMP;
component AND_TWO is
Port( A : in std_logic;
B : in std_logic;
C : out std_logic);
end component AND_TWO;
begin
LB1 : XOR_TWO PORT MAP(HA1,HA2,HA_SUM);
LB2 : AND_TWO PORT MAP(HA1,HA2,HA_CRY);
end Behavioral;
6
Prepared by Vinod.gandhi@mail.com
7
Prepared by Vinod.gandhi@mail.com
x y z C S
0 0 0 0 0
0 0 1 0 1
0 1 0 0 1
0 1 1 1 0
1 0 0 0 1
1 0 1 1 0
1 1 0 1 0
1 1 1 1 1
D= X Y Z
C= X.Y+Z(X Y)
8
Prepared by Vinod.gandhi@mail.com
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity FULL_ADDER_DATA is
Port ( FA1 : in std_logic;
FA2 : in std_logic;
FA3 : in std_logic;
FA_SUM : out std_logic;
FA_CAR : out std_logic);
end FULL_ADDER_DATA;
9
Prepared by Vinod.gandhi@mail.com
HA C
Y
HA
Z S
x y z C S
0 0 0 0 0
0 0 1 0 1
0 1 0 0 1
0 1 1 1 0
1 0 0 0 1
1 0 1 1 0
1 1 0 1 0
1 1 1 1 1
D= X Y Z
C= X.Y+Z(X Y)
10
Prepared by Vinod.gandhi@mail.com
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity FULL_ADDER_COMP is
Port ( FA1 : in std_logic;
FA2 : in std_logic;
FA3 : in std_logic;
FA_SUM : out std_logic;
FA_CAR : out std_logic);
end FULL_ADDER_COMP;
11
Prepared by Vinod.gandhi@mail.com
4. (a) Design a 4-bit adder circuit using the macro of Full adder.
Cout C3 C2 C1 Cin
A3 A2 A1 A0
B3 B2 B1 B0
S3 S2 S1 S0
12
Prepared by Vinod.gandhi@mail.com
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity FULL_ADDER_4BIT is
Port(Ain : in std_logic_vector(3 downto 0);
Bin : in std_logic_vector(3 downto 0);
Cary_in : in std_logic;
Cout : out std_logic_vector(3 downto 0);
Cary_out : out std_logic);
end FULL_ADDER_4BIT;
13
Prepared by Vinod.gandhi@mail.com
4. (b) Design a 4-bit adder circuit using carry look-ahead adder circuit.
14
Prepared by Vinod.gandhi@mail.com
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity CARRY_LOOK_AHEAD_ADDER_4BIT is
port( CAin1 : in std_logic_vector(3 downto 0);
CAin2 : in std_logic_vector(3 downto 0);
CAcarryin : in std_logic;
CAsum : out std_logic_vector(3 downto 0);
CAcarry : out std_logic);
End entity CARRY_LOOK_AHEAD_ADDER_4BIT;
15
Prepared by Vinod.gandhi@mail.com
x y C D
0 0 0 0
0 1 1 1
1 0 0 1
1 1 0 0
D= X Y
C= A.B
16
Prepared by Vinod.gandhi@mail.com
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity half_subtractor is
Port(HS1 : in std_logic;
HS2 : in std_logic;
HS_SUB : out std_logic;
HS_BOR : out std_logic);
end half_subtractor;
17
Prepared by Vinod.gandhi@mail.com
5. (b) Deisgn a full subtractor using a 3:8 Decoder circuit and OR gates.
18
Prepared by Vinod.gandhi@mail.com
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity FULL_SUBTRACTOR_38DECODER is
Port(FS1 : in std_logic;
FS2 : in std_logic;
FS3 : in std_logic;
FS_SUB : out std_logic;
FS_BOR : out std_logic);
end FULL_SUBTRACTOR_38DECODER;
19
Prepared by Vinod.gandhi@mail.com
20
Prepared by Vinod.gandhi@mail.com
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity BCD_ADDER is
Port( BCD1 : in std_logic_vector(3 downto 0);
BCD2 : in std_logic_vector(3 downto 0);
BCD_CIN : in std_logic;
BCD_SUM : out std_logic_vector(3 downto 0);
BCD_COUT : out std_logic);
end BCD_ADDER;
21
Prepared by Vinod.gandhi@mail.com
22
Prepared by Vinod.gandhi@mail.com
Set - II
=====
1. Design a 4-bit adder using generate statement.
Cout C3 C2 C1 Cin
A3 A2 A1 A0
B3 B2 B1 B0
S3 S2 S1 S0
23
Prepared by Vinod.gandhi@mail.com
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity FULLADDER_4BIT_GENERATE is
Port ( FAIN_A : in std_logic_vector(3 downto 0);
FAIN_B : in std_logic_vector(3 downto 0);
FAIN_C : in std_logic;
FA_SM : out std_logic_vector(3 downto 0);
FA_CY : out std_logic);
end FULLADDER_4BIT_GENERATE;
24
Prepared by Vinod.gandhi@mail.com
25
Prepared by Vinod.gandhi@mail.com
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity FULL_ADDER_4_MODE is
Port ( FAIN_A : in std_logic_vector(3 downto 0);
FAIN_B : in std_logic_vector(3 downto 0);
FA_MODE : in std_logic;
FA_SUM : out std_logic_vector(3 downto 0);
FA_CAR : out std_logic;
FA_V : out std_logic);
end FULL_ADDER_4_MODE;
26
Prepared by Vinod.gandhi@mail.com
27
Prepared by Vinod.gandhi@mail.com
28
Prepared by Vinod.gandhi@mail.com
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity MUX4_1_IF_ELSE is
Port( MUXIN_0,MUXIN_1,MUXIN_2,MUXIN_3 : in std_logic;
MUXSEL : in std_logic_vector(1 downto 0);
MUXOUT : out std_logic);
end MUX4_1_IF_ELSE;
29
Prepared by Vinod.gandhi@mail.com
30
Prepared by Vinod.gandhi@mail.com
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity MUX4_1_CASE is
Port( MUXIN_0,MUXIN_1,MUXIN_2,MUXIN_3 : in std_logic;
MUXSEL : in std_logic_vector(1 downto 0);
MUXOUT : out std_logic);
end MUX4_1_CASE;
31
Prepared by Vinod.gandhi@mail.com
32
Prepared by Vinod.gandhi@mail.com
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity DECODER2_4 is
Port ( SE : in std_logic_vector(1 downto 0);
DE : out std_logic_vector(3 downto 0));
end DECODER2_4;
33
Prepared by Vinod.gandhi@mail.com
34
Prepared by Vinod.gandhi@mail.com
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity DECODER_38 is
Port(S : in std_logic_vector(2 downto 0);
D : out std_logic_vector(7 downto 0);
en : in std_logic );
end DECODER_38;
35
Prepared by Vinod.gandhi@mail.com
4. (c) Design a 5:32 decoder using the macro of above two design.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity DECODER5_32_COMP2_4_3_8 is
port( SEL : in std_logic_vector(4 downto 0);
DEC : out std_logic_vector(31 downto 0));
end DECODER5_32_COMP2_4_3_8;
component DECODER_38 is
Port( S : in std_logic_vector(2 downto 0);
D : out std_logic_vector(7 downto 0);
en : in std_logic );
end component DECODER_38;
signal EN_DE : std_logic_vector(3 downto 0);
signal T : std_logic_vector(31 downto 0);
begin
D1 : DECODER2_4 PORT MAP(SEL(4 downto 3),EN_DE);
DEC <= T;
end Behavioral;
36
Prepared by Vinod.gandhi@mail.com
37
Prepared by Vinod.gandhi@mail.com
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity ENCODER4_2 is
Port( ENin : in std_logic_vector(3 downto 0);
ENout : out std_logic_vector(1 downto 0));
end ENCODER4_2;
38
Prepared by Vinod.gandhi@mail.com
39
Prepared by Vinod.gandhi@mail.com
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity PARITY_CHECKER_GENERATOR_8BIT is
Port( Pin : in std_logic_vector(7 downto 0);
Pcheck : out std_logic;
Pgenerate : out std_logic);
end PARITY_CHECKER_GENERATOR_8BIT;
40
Prepared by Vinod.gandhi@mail.com
7. Design a 4-bit by 3-bit binary multiplier circuit using the macro of 4-bit adder
and AND gates.
41
Prepared by Vinod.gandhi@mail.com
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity Mutiplier4_3 is
port( B : in std_logic_vector(3 downto 0);
A : in std_logic_vector(2 downto 0);
O : out std_logic_vector(6 downto 0));
end Mutiplier4_3;
42
Prepared by Vinod.gandhi@mail.com
43
Prepared by Vinod.gandhi@mail.com
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity COMPARATOR_1BIT is
Port ( A, B : in std_logic;
X : out std_logic; -- A > B
Y : out std_logic; -- A < B
Z : out std_logic; -- A = B
EN : in std_logic);
end COMPARATOR_1BIT;
44
Prepared by Vinod.gandhi@mail.com
9. (a) Design a 4-bit comparator using the macro of single bit comparator.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity COMPARATOR_4BIT_COMP is
Port ( P, Q : in std_logic_vector(3 downto 0);
M : out std_logic; -- P > Q
N : out std_logic; -- P < Q
O : out std_logic; -- P = Q
EN : in std_logic);
end COMPARATOR_4BIT_COMP;
45
Prepared by Vinod.gandhi@mail.com
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity COMPARATOR_4BIT_BOOLEAN is
Port ( P, Q : in std_logic_vector(3 downto 0);
M : out std_logic; -- P > Q
N : out std_logic; -- P < Q
O : out std_logic; -- P = Q
EN : in std_logic);
end COMPARATOR_4BIT_BOOLEAN;
46
Prepared by Vinod.gandhi@mail.com
47
Prepared by Vinod.gandhi@mail.com
Set - III
======
1. Design a D-Flip flop with
a. Asynchronous preset and clear inputs.
b. Synchronous reset input.
c. Synchronous set input.
48
Prepared by Vinod.gandhi@mail.com
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity D_F_F is
Port ( rst : in std_logic;
pr : in std_logic;
clr : in std_logic;
clk : in std_logic;
d : in std_logic;
q : out std_logic);
end D_F_F;
49
Prepared by Vinod.gandhi@mail.com
2. Design a negative edge triggered JK flip-flop with asynchronous reset and preset
inputs.
50
Prepared by Vinod.gandhi@mail.com
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity JK_FF is
port( J : in std_logic;
K : in std_logic;
PRESET: in std_logic;
CLEAR: in std_logic;
CLK : in std_logic;
Q: inout std_logic;
QBAR : out std_logic := '1');
end JK_FF;
51
Prepared by Vinod.gandhi@mail.com
3. Write a code to madel a 4-bit shift register with serial input and parallel
output data. The circuit has an active high asynchronous reset, data input
Din, a shift enable input shift_en and 4-bit output shift_out.
52
Prepared by Vinod.gandhi@mail.com
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity ShiftR_4bit_Sin_Pout is
Port(clk : in std_logic;
rst : in std_logic;
d : in std_logic ;
q : out std_logic_vector (3 downto 0);
en : in std_logic);
end ShiftR_4bit_Sin_Pout;
53
Prepared by Vinod.gandhi@mail.com
4.Write a code to model 3-bit counter. The counter has an asynchronous input reset
and synchronous input count_en. The counter start counting when coount_en = 1 on
the rising edge of clock.
54
Prepared by Vinod.gandhi@mail.com
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity COUNTER3_BIT is
Port(rst : in std_logic;
clk : in std_logic;
preset : in std_logic;
count_enable : in std_logic;
aload_enable : in std_logic;
aload : in std_logic_vector(2 downto 0);
op : out std_logic_vector(2 downto 0));
end COUNTER3_BIT;
55
Prepared by Vinod.gandhi@mail.com
5.Develop a model of 4 bit up-down counter. It has asynchrounous reset input and
synchronous inputs count_en and up. When synchronous input up is high, the
counter counts up, when up is low it counts down.
56
Prepared by Vinod.gandhi@mail.com
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity COUNTER_UP_DOWN is
Port( rst : in std_logic;
clk : in std_logic;
count_en : in std_logic;
up_dwn : in std_logic;
op : out std_logic_vector(3 downto 0));
end COUNTER_UP_DOWN;
57
Prepared by Vinod.gandhi@mail.com
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity COUNTER_DACADE is
Port( rst : in std_logic;
clk : in std_logic;
count_en : in std_logic;
op : out std_logic_vector(3 downto 0));
end COUNTER_DACADE;
58
Prepared by Vinod.gandhi@mail.com
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity COUNTER_UP1_DOWN2 is
Port( rst : in std_logic;
clk : in std_logic;
count_en : in std_logic;
up_dwn : in std_logic;
op : out std_logic_vector(3 downto 0));
end COUNTER_UP1_DOWN2;
59
Prepared by Vinod.gandhi@mail.com
8. Write a code to model a parallel to serial converter. The circuit accepts a 4 bit
paralle data (data_in) when the synchronous load input goes high.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity ShiftR_Pin_Sout is
Port(clk : in std_logic;
rst : in std_logic;
d : in std_logic_vector(3 downto 0) ;
q : out std_logic;
en : in std_logic);
end ShiftR_Pin_Sout;
60
Prepared by Vinod.gandhi@mail.com
61