Professional Documents
Culture Documents
DATE:
STUDY ON VERIFICATION OF LOGIC
EXPT. NO: 01
GATES
PAGE NO:
AIM:
To develop the source code for logic gates using VHDL/VERILOG and obtain the
simulation and synthesis report.
ALGORITHM:
AND GATE:
INPUTS OUTPUT
A B Y
Y = A.B 0 0 0
0 1 0
1 0 0
1 1 1
• VHDL CODE:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity ANDGATE_713 is
port (A, B: in STD_LOGIC; Y: out STD_LOGIC);
end ANDGATE_713;
architecture dataflow ANDGATE_713 is
begin
Y <= A AND B;
end dataflow;
• SIMULATED OUTPUT:
41130713_SANJAY.R
OR GATE:
INPUTS OUTPUT
A B Y
Y = A+B
0 0 0
0 1 1
1 0 1
1 1 1
• VHDL CODE:
•
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity ORGATE_713 is
port (A, B: in STD_LOGIC; Y: out STD_LOGIC);
end ORGATE_713;
architecture dataflow ORGATE_713 is
begin
Y <= A OR B;
end dataflow;
• SIMULATED OUTPUT:
41130713_SANJAY.R
NAND GATE:
INPUTS OUTPUT
A B Z
Z = (A.B)’
0 0 1
0 1 1
1 0 1
1 1 0
• VHDL CODE:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity NANDGATE_713 is
port (A, B: in STD_LOGIC; Y: out STD_LOGIC);
end NANDGATE_713;
architecture dataflow NANDGATE_713 is
begin
Z <= A NAND B;
end dataflow;
• SIMULATED OUTPUT:
41130713_SANJAY.R
NOR GATE:
INPUTS OUTPUT
A B Q
Q = (A+B)’
0 0 1
0 1 0
1 0 0
1 1 0
• VHDL CODE:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity NORGATE_713 is
port (A, B: in STD_LOGIC; Y: out STD_LOGIC);
end NORGATE_713;
architecture dataflow NORGATE_713 is
begin
Y <= A NOR B;
end dataflow;
• SIMULATED OUTPUT;
41130713_SANJAY.R
XOR GATE:
INPUTS OUTPUT
A B Y
Y = AB’ + A’B
0 0 0
0 1 1
1 0 1
1 1 0
• VHDL CODE:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity XORGATE_713 is
port (A, B: in STD_LOGIC; Y: out STD_LOGIC);
end XORGATE_713;
architecture dataflow XORGATE_713 is
begin
Y <= A XOR B;
end dataflow;
• SIMULATED OUTPUT:
41130713_SANJAY.R
6. XNOR G ATE:
INPUTS OUTPUT
A B Y
Y = (AB’ + A’B)’ A Y 0 0 1
B
0 1 0
1 0 0
1 1 1
• VHDL CODE:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity XNORGATE_713 is
port (A, B: in STD_LOGIC; Y: out STD_LOGIC);
end XNORGATE_713;
architecture dataflow XNORGATE_713 is
begin
Y <= A XNOR B;
end dataflow;
• SIMULATED OUTPUT:
41130713_SANJAY.R
7. NOT GATE:
INPUT OUTPUT
Y = (X)’ X Y
0 1
1 0
• VHDL CODE:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity NOTGATE_713 is
port (X: in STD_LOGIC; Y: out STD_LOGIC);
end NOTGATE_713;
architecture dataflow NOTGATE_713 is
begin
Y <= NOT X;
end dataflow;
• SIMULATED OUTPUT:
41130713_SANJAY.R
VERILOG CODES:
1. AND GATE:
module and1(a,b,c);
input a,b;
output c;
assign c = a&b;
endmodule
2. OR GATE:
module or1(a,b,c);
input a,b;
output c;
assign c = a|b;
endmodule
3. NAND GATE:
module nand1(a,b,c);
input a,b;
output c;
assign c = ~(a&b);
endmodule
41130713_SANJAY.R
4. NOR GATE:
module nor1(a,b,c);
input a,b;
output c;
assign c = ~(a|b);
endmodule
5. XOR GATE:
module xor1(a,b,c);
input a,b;
output c;
assign c = a^b;
endmodule
6. XNOR GATE:
module xnor1(a,b,c);
input a,b;
output c;
assign c = ~(a^b);
endmodule
41130713_SANJAY.R
7. NOT GATE:
module and1(a,b);
input a;
output b;
assign b = ~a;
endmodule
RESULT:
The output of Logic Gates is verified by stimulating and synthesizing the VHDL
/VERILOG code.
41130713_SANJAY.R
DATE:
AIM:
To develop the source code for adders and subtractors using VHDL/VERILOG and
obtain the simulation and synthesis report.
ALGORITHM:
1. HALF ADDER:
• CIRCUIT DIAGRAM:
41130713_SANJAY.R
41130713_SANJAY.R
•
EXPRESSIONS:
• TRUTH TABLE:
INPUTS OUTPUTS
A B S C
0 0 0 0
0 1 1 0
1 0 1 0
1 1 0 1
• VHDL CODE:
DATAFLOW MODELING:
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity HALFADDER_713 is
port (A, B: in STD_LOGIC; S, C: out STD_LOGIC);
end HALFADDER_713;
architecture dataflow of HALFADDER_713 is
begin
S <= A XOR B;
C <= A AND B;
end dataflow;
STRUCTURAL MODELING:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity HALFADDER_713is
port (A, B: in STD_LOGIC; S, C: out STD_LOGIC);
41130713_SANJAY.R
end HALFADDER_713;
architecture structural of HALFADDER_713 is
component xor1
port (a1, b1: in STD_LOGIC; c1: out STD_LOGIC);
end component;
component and1
port (a2, b2: in STD_LOGIC; c2: out STD_LOGIC);
end component;
begin
ag: and1 port map(A, B, C);
ng: xor1 port map(A, B, S);
end structural;
--COMPONENT SOURCE CODE
--XOR1:
entity xor1 is
port (a1, b1: in STD_LOGIC; c1: out STD_LOGIC);
end xor1;
architecture dataflow of xor1 is
begin
c1 <= a1 XOR b1;
end dataflow;
--AND1:
entity and1 is
port (a2, b2: in STD_LOGIC; c2: out STD_LOGIC);
end and1;
architecture dataflow of and1 is
begin
c2 <= a2 AND b2;
end dataflow;
BEHAVIOURAL MODELING:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity HALFADDER_713 is
port (A, B: in STD_LOGIC; S, C: out STD_LOGIC);
end HALFADDER_713
architecture behavioural of HALFADDER_713 is
begin
process (A, B)
begin
S <= A XOR B;
41130713_SANJAY.R
•
C <= A AND B;
end process;
end behavioural;
SIMULATED OUTPUT:
• VERILOG CODE:
DATAFLOW MODELING:
module ha_d713(a,b,s,c);
input a,b;
output s,c;
assign s = a^b;
assign c = a&b;
endmodule
STRUCTURAL MODELING:
module ha_d713( a,b,s,c);
input a,b;
output s,c;
xor(s,a,b)
and(c,a,b)
endmodule
BEHAVIOURAL MODELING:
module ha_d713(a,b,s,c);
input a,b;
output reg s,c;
always @(*)
begin
s = a+b;
assign c = a&b;
end
endmodule
41130713_SANJAY.R
41130713_SANJAY.R
SIMULATED OUTPUT:
2. FULL ADDER:
• CIRCUIT DIAGRAM:
• EXPRESSIONS:
TRUTH TABLE:
INPUTS OUTPUTS
X Y Cin S Cout
0 0 0 0 0
0 0 1 1 0
0 1 0 1 0
0 1 1 0 1
1 0 0 1 0
1 0 1 0 1
1 1 0 0 1
1 1 1 1 1
• VHDL CODE:
• DATAFLOW MODELING:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity FULLADDER_713 is
port (X, Y, Cin: in std_logic;
S, Cout: out std_logic);
end FULLADDER_713;
architecture dataflow of FULLADDER_713 is
begin
S <= (X XOR Y) XOR Cin;
Cout <= ((X AND Y) OR (Y AND Cin)) OR (Cin
AND X);
end dataflow;
41130713_SANJAY.R
•
• STRUCTURAL MODELLING:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity FULLADDER_713 is
port (X, Y, Cin: in std_logic;
S, Cout: out std_logic);
end FULLADDER_713;
architecture structural of
FULLADDER_713 is
component xor1
port (a1, b1, c1: in std_logic; d1:out
std_logic);
end component;
component and1
port (a2, b2: in std_logic; c2:out
std_logic);
end component;
component or1
port (a3, b3: in std_logic; c3:out
std_logic);
end component;
signal s1, s2, s3: std_logic;
begin
x1: xor1 port map (X, Y, Cin, S);
a1: and1 port map (X, Y, s1);
a2: and1 port map (X, Y, s2);
a3: and1 port map (Cin, X, s3);
o1: or1 port map (s1, s2, s3, Cout);
end structural;
--COMPONENT SOURCE CODE:
--XOR1
entity xor1 is
port (a1, b1, c1: in std_logic;
d1: out std_logic);
end xor1;
architecture dataflow of xor1 is
begin
d1<= <= a1 XOR b1 XOR c1;
end dataflow;
--AND1
entity and1 is begin
41130713_SANJAY.R
• BEHAVIOURAL MODELING:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity FULLADDER_713 is
port (X, Y, Cin: in std_logic;
S, Cout: out std_logic);
end FULLADDER_713;
architecture behavioural of FULLADDER_713 is
begin
process (X, Y, Cin)
begin
S <= (X XOR Y) XOR Cin;
Cout <= ((X AND Y) OR (Y AND Cin)) OR (Cin AND X);
end process;
end behavioural;
• SIMULATED OUTPUT:
• VERILOG CODE:
• DATAFLOW MODELING:
module fa_d713(x,y,z,s,c);
input x,y,z;
output s,c;
assign s=x^y^z;
41130713_SANJAY.R
assign c=(x&y)|(y&z)|(z&x);
endmodule
• STRUCTURAL MODELLING:
module fa_s713(x,y,z,s,c);
input x,y,z;
output s,c;
wire i,j,k;
xor(s,x,y,z);
and
a1(i,x,y),
a2(j,y,z),
a3(k,z,x);
or(c,i,j,k);
endmodule
• BEHAVIOURAL MODELING:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity FULLADDER_713 is
port (X, Y, Cin: in std_logic;
S, Cout: out std_logic);
end FULLADDER_713;
architecture behavioural of FULLADDER_713 is
begin
process (X, Y, Cin)
begin
S <= (X XOR Y) XOR Cin;
Cout <= ((X AND Y) OR (Y AND Cin)) OR (Cin AND X);
end process;
end behavioural;
41130713_SANJAY.R
SIMULATED OUTPUT:
3. HALF SUBTRACTOR:
• CIRCUIT DIAGRAM:
• EXPRESSIONS:
• TRUTH TABLE:
INPUTS OUTPUTS
A B D Bo
0 0 0 0
0 1 1 1
1 0 1 0
1 1 0 0
41130713_SANJAY.R
• VHDL CODE:
DATAFLOW MODELING:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity HALFSUBT_713 is
port (A, B: in std_logic;
D, Bo: out std_logic);
end HALFSUBT_713;
architecture dataflow of HALFSUBT_713 is
begin
D <= A XOR B;
Bo <= (NOT A) AND B;
end dataflow;
• STRUCTURAL MODELING:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity HALFSUBT_713 is
port (A, B: in std_logic;
D, Bo: out std_logic);
end HALFSUBT_713;
architecture structural of HALFSUBT_713 is
component xor1
port (a1, b1: in std_logic; c1: out std_logic);
end component;
component and1
port (a2, b2: in std_logic; c2: out std_logic);
end component;
component not1
port (a3: in std_logic; b3: out std_logic);
end component;
signal s1: std_logic;
begin
a1: and1 port map (s1, B, Bo);
x1: xor1 port map (A, B, D);
n1: not1 port map (A, s1);
end structural;
41130713_SANJAY.R
• BEHAVIOURAL MODELING:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity HALFSUBT_713 is
port (A, B: in std_logic;
D, Bo: out std_logic);
end HALFSUBT_713;
architecture behavioural of HALFSUBT_713 is
begin
process (A, B)
begin
D <= A XOR B;
Bo <= (NOT A) AND B;
end process;
end behavioural;
41130713_SANJAY.R
• SIMULATED OUTPUT:
• VERILOG CODE:
• DATAFLOW MODELING:
module hs_d713(x,y,d,b);
input x,y;
output d,b;
assign d=x^y;
assign b=(~x)&y;
endmodule
• STRUCTURAL MODELING
module
hs_s713(x,y,d,b);;
input x,y;
output d,b;
xor(d,x,y);
and(b,(~x),y);
endmodule
BEHAVIOURAL MODELING:
module
hs_b713(x,y,d,b);
input x,y;
output d,b;
reg d,b;
always @(*)
begin
d=y-x;
assign b=(~x)&y;
endendmodule
SIMULATED OUTPUT:
41130713_SANJAY.R
4. FULL SUBTRACTOR:
• CIRCUIT DIAGRAM:
• EXPRESSIONS:
TRUTH TABLE:
INPUTS OUTPUTS
A B C D Bo
0 0 0 0 0
0 0 1 1 1
0 1 0 1 1
0 1 1 0 1
1 0 0 1 0
1 0 1 0 0
1 1 0 0 0
1 1 1 1 1
• VHDL CODE:
• DATAFLOW MODELING:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity FULLSUBT_713 is
port (A, B, C: in std_logic; D, Bo: out std_logic);
end FULLSUBT_713;
architecture dataflow of FULLSUBT_713 is
begin
D <= (A XOR B) XOR C;
Bo <= ((NOT A) AND B) OR (B AND C) OR (C AND
(NOT A));
end dataflow;
• STRUCTURAL MODELING:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
41130713_SANJAY.R
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity FULLSUBT_713 is
port (A, B, C: in std_logic;
D, Bo: out std_logic);
end FULLSUBT_713;
architecture structural of
FULLSUBT_713 is
component xor1
port (a1, b1: in std_logic; c1:
out: std_logic);
end component;
component and1
port (a2, b2: in std_logic; c2:
out: std_logic);
end component;
component or1
port (a3, b3: in std_logic; c3:
out: std_logic);
end component;
component not1
port (a4: in std_logic; b4:
out: std_logic);
end component;
signal s1, s2, s3, s4, s5:
std_logic;
begin
x1: xor1 port map (A, B, s1);
x2: xor1 port map (s1, C, D);
a1: and1 port map (s2, C, s4);
a2: and1 port map (s3, B, s5);
o1: or1 port map (s4, s5, Bo);
n1: not1 port map (s1, s2);
n2: not1 port map (A, s3);
end structural;
--COMPONENT SOURCE CODE
--XOR1
entity xor1 is
port (a1, b1: in std_logic; c1:
out std_logic);
end xor1;
architecture dataflow of xor1 is
begin
c1 <= a1 XOR b1;
end dataflow;
--AND1
entity and1 is
41130713_SANJAY.R
• BEHAVIOURAL MODELING:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity FULLSUBT_713 is
port (A, B, C: in std_logic; D, Bo: out std_logic);
end FULLSUBT_713;
architecture behavioural of FULLSUBT_713 is
begin
process (A, B, C)
begin
D <= (A XOR B) XOR C;
Bo <= ((NOT A) AND B) OR (B AND C) OR (C AND
(NOT A));
end process;
end behavioural;
41130713_SANJAY.R
• SIMULATED OUTPUT:
• VERILOG CODE:
DATAFLOW MODELING:
module fs_d713(x,y,z,d,b);
input x,y,z;
output d,b;
assign d=x^y^z;
assign b=((~x)&(y))|((~(x^y))&(z));
endmodule
STRUCTURAL MODELING:
module
fs_s713(x,y,z,d,b);
input x,y,z;
output d,b;
wire i,j,k;
xor(d,x,y,z);
and a1(i,(~x),y),
a2(j,(~(x^y)),z);
or(b,i,j);
endmodule
BEHAVIOURAL MODELING:
module fs_b713(x,y,z,d,b);
input x,y,z;
output d,b; reg d,b;
always @(*)
begin
d=z-y-x;
assign b=((~x)&(y))|((~(x^y))&(z));
end
41130713_SANJAY.R
endmodule
41130713_SANJAY.R
•
SIMULATED OUTPUT:
RESULT:
The output of Adders and Subtractors is verified by stimulating and synthesizing the
VHDL/VERILOG code.
41130713_SANJAY.R
DATE:
AIM:
To develop the source code for encoder and decoder using VHDL/VERILOG and obtain
the simulation and synthesis report.
ALGORITHM:
• CIRCUIT DIAGRAM:
Y0
41130713_SANJAY.R
•
TRUTH TABLE:
INPUTS OUTPUTS
Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 A2 A1 A0
0 0 0 0 0 0 0 1 0 0 0
0 0 0 0 0 0 1 0 0 0 1
0 0 0 0 0 1 0 0 0 1 0
0 0 0 0 1 0 0 0 0 1 1
0 0 0 1 0 0 0 0 1 0 0
0 0 1 0 0 0 0 0 1 0 1
0 1 0 0 0 0 0 0 1 1 0
1 0 0 0 0 0 0 0 1 1 1
• VHDL CODE:
• DATAFLOW MODELING:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity ENCODER_713 is
port (Y: in STD_LOGIC_VECTOR (0 to 7);
A2, A1, A0: out STD_LOGIC);
end ENCODER_713;
architecture dataflow of ENCODER_713 is
begin
A0 <= ((Y (1) OR Y (3)) OR Y (5)) OR Y (7);
A1 <= ((Y (2) OR Y (3)) OR Y (6)) OR Y (7);
A2 <= ((Y (4) OR Y (5)) OR Y (6)) OR Y (7);
end dataflow;
• STRUCTURAL MODELING:
41130713_SANJAY.R
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity ENCODER_713 is
port (Y: in STD_LOGIC_VECTOR (0 to 7);
A2, A1, A0: out STD_LOGIC);
end ENCODER_713;
architecture structural of ENCODER_713 is
component or1
port (a, b, c, d: in std_logic;
z: out std_logic);
end component;
begin
o1: or1 port map (Y(7), Y(6), Y(5), Y(4), A2);
o2: or1 port map (Y(7), Y(6), Y(2), Y(3), A1);
o2: or1 port map (Y(7), Y(5), Y(3), Y(1), A0);
end structural;
--COMPONENT SOURCE CODE
--OR GATE
entity or1 is
port (a, b, c, d: in std_logic;
z: out std_logic);
end or1;
architecture dataflow of or1 is
begin
z <= ((a OR b) OR c) OR d;
end dataflow;
• BEHAVIOURAL MODELING:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity ENCODER_713 is
port (Y: in STD_LOGIC_VECTOR (0 to 7);
A2, A1, A0: out STD_LOGIC);
end ENCODER_713;
architecture behavioural of ENCODER_713 is
begin
process (Y)
begin
A0 <= ((Y(1) OR Y(3)) OR Y(5)) OR Y(7);
41130713_SANJAY.R
•
A1 <= ((Y(2) OR Y(3)) OR Y(6)) OR Y(7);
A2 <= ((Y(4) OR Y(5)) OR Y(6)) OR Y(7);
end process;
end dataflow
SIMULATED OUTPUT:
• VERILOG CODE:
DATAFLOW MODELING:
module
encoder_d713(input[7:0]a,output[2:0]y);
assign y[0]= a[1]| a[3]| a[5]| a[7];
assign y[1]= a[3]| a[2]| a[6]| a[7];
assign y[2]= a[4]| a[5]| a[6]| a[7];
endmodule
STRUCTURAL MODELING:
module encoder_s713(input[7:0]a,output[2:0]y);
or(y[0],a[1],a[3],a[5],a[7]);
or(y[1],a[3], a[2], a[6], a[7]);
or(y[2], a[4], a[5], a[6], a[7]);
endmodule
BEHAVIOURAL MODELING:
module encoder_b713(input[7:0]a,output reg[2:0]y);
always @(*)
begin
case(a)
8'b00000000:y=3'd0;
8'b00000001:y=3'd0;
8'b00000010:y=3'd1;
8'b00000100:y=3'd2;
8'b00001000:y=3'd3;
8'b00010000:y=3'd4;
8'b00100000:y=3'd5;
41130713_SANJAY.R
8'b01000000:y=3'd6;
40130713_SHARMILA.V
8'b10000000:y=3'd7;
endcase
end
endmodule
• SIMULATED OUTPUT:
2. 3*8 DECODER:
• CIRCUIT DIAGRAM:
41130713_SANJAY.R
•
TRUTH TABLE:
OUTPUTS INPUTS
Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 A2 A1 A0
0 0 0 0 0 0 0 1 0 0 0
0 0 0 0 0 0 1 0 0 0 1
0 0 0 0 0 1 0 0 0 1 0
0 0 0 0 1 0 0 0 0 1 1
0 0 0 1 0 0 0 0 1 0 0
0 0 1 0 0 0 0 0 1 0 1
0 1 0 0 0 0 0 0 1 1 0
1 0 0 0 0 0 0 0 1 1 1
• VHDL CODE:
• DATAFLOW MODELING:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity DECODER_713 is
port (A: in std_logic_vector (2 downto
0);
Y: out std_logic_vector (7 downto 0));
end DECODER_713;
architecture dataflow of DECODER_713 is
begin
Y(0)<=((not A(2)) and (not A(1))) and
(not A(0));
Y(1)<=((not A(2)) and (not A(1))) and
A(0);
Y(2)<=((not A(2)) and A(1)) and (not
A(0));
41130713_SANJAY.R
STRUCTURAL MODELING:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity DECODER_713 is
port (A: in STD_LOGIC_VECTOR (2
downto 0);
Y: out STD_LOGIC_VECTOR (7 downto
0));
end DECODER_713;
architecture structural of
DECODER_713 is
component not1
port (x1: in STD_LOGIC;
y1: out STD_LOGIC);
end component;
component and1
port (x2, y2, z2: in STD_LOGIC;
a2: out STD_LOGIC);
end component;
begin
n1: not1 port map (A(2), not A(2));
n2: not1 port map (A(1), not A(1));
n3: not1 port map (A(0), not A(0));
i: and1 port map (not A(2), not
A(1), not A(0), Y(0));
j: and1 port map (not A(2), not
A(1), A(0), Y(1));
k: and1 port map (not A(2), A(1),
not A(0), Y(2));
l: and1 port map (not A(2), A(1),
A(0), Y(3));
m: and1 port map (A(2), not A(1),
not A(0), Y(4));
n: and1 port map (A(2), not A(1),
A(0), Y(5));
41130713_SANJAY.R
•
o: and1 port map (A(2), A(1), not
A(0), Y(6));
p: and1 port map (A(2), A(1), A(0),
Y(7));
end structural;
--COMPONENT SOURCE CODE:
--NOT GATE
entity not1 is
port (x1: in STD_LOGIC;
y1: out STD_LOGIC);
end not1;
architecture dataflow of not1 is
begin
y1 <= (not x1);
end dataflow;
--AND GATE
entity and1 is
Port (x2, y2, z2: in STD_LOGIC;
a2: out STD_LOGIC);
end and1;
architecture dataflow of and1 is
begin
a2 <= (x2 and y2) and z2;
end dataflow;
41130713_SANJAY.R
• BEHAVIOURAL MODELING:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use
IEEE.STD_LOGIC_UNSIGNED.ALL;
entity DECODER_713 is
port (A: in std_logic_vector
(2 downto 0);
Y: out std_logic_vector (7
downto 0));
end DECODER_713;
architecture behavioural of
DECODER_713 is
begin
process (A)
begin
Y(0)<=((not A(2)) and (not
A(1))) and (not A(0));
Y(1)<=((not A(2)) and (not
A(1))) and A(0);
Y(2)<=((not A(2)) and A(1))
and (not A(0));
Y(3)<=((not A(2)) and A(1))
and A(0);
Y(4)<=(A(2) and (not A(1)))
and (not A(0));
Y(5)<=(A(2) and (not A(1)))
and A(0);
Y(6)<=(A(2) and A(1)) and (not
A(0));
Y(7)<=(A(2) and A(1)) and
A(0);
end process;
end behavioural;
41130713_SANJAY.R
• SIMULATED OUTPUT:
• VERILOG CODE:
DATAFLOW MODELING:
module
decoder_d713(input[2:0]a,output[7:0]y);
assign y[0]=(~a[2])&(~a[1])&(~a[0]);
assign y[1]=(~a[2])&(~a[1])&(a[0]);
assign y[2]=(~a[2])&(a[1])&(~a[0]);
assign y[3]=(~a[2])&(a[1])&(a[0]);
assign y[4]=(a[2])&(~a[1])&(~a[0]);
assign y[5]=(a[2])&(~a[1])&(a[0]);
assign y[6]=(a[2])&(a[1])&(~a[0]);
assign y[7]=(a[2])&(a[1])&(a[0]);
endmodule
STRUCTURAL MODELING:
module
decoder_s713(input[2:0]a,output[7:0]y);
and(y[0],(~a[2]),(~a[1]),(~a[0]));
and(y[1],(~a[2]),(~a[1]),(a[0]));
and(y[2],(~a[2]),(a[1]),(~a[0]));
and(y[3],(~a[2]),(a[1]),(a[0]));
and(y[4],(a[2]),(~a[1]),(~a[0]));
and(y[5],(a[2]),(~a[1]),(a[0]));
and(y[6],(a[2]),(a[1]),(~a[0]));
and(y[7],(a[2]),(a[1]),(a[0]));
endmodule
41130713_SANJAY.R
BEHAVIOURAL MODELING:
module decoder_b713(input[2:0]a,outputreg[7:0]y);
always @(*)
begin
y=8'd0;
case(a)
3'd0:y[0]=1'b1;
3'd1:y[1]=1'b1;
3'd2:y[2]=1'b1;
3'd3:y[3]=1'b1;
3'd4:y[4]=1'b1;
3'd5:y[5]=1'b1;
3'd6:y[6]=1'b1;
3'd7:y[7]=1'b1;
endcase
end
endmodule
• SIMULATED OUTPUT:
RESULT:
The output of Encoder and Decoder is verified by stimulating and synthesizing the
VHDL/VERILOG code.
41130713_SANJAY.R
DATE:
AIM:
To develop the source code for multiplexer and demultiplexer using VHDL / VERILOG
and obtain the simulation and synthesis report.
ALGORITHM:
1. 8*1 MULTIPLEXER:
CIRCUIT DIAGRAM:
41130713_SANJAY.R
TRUTH TABLE:
S2 S1 S0 Y
0 0 0 A0
0 0 1 A1
0 1 0 A2
0 1 1 A3
1 0 0 A4
1 0 1 A5
1 1 0 A6
1 1 1 A7
• VHDL CODE:
• DATAFLOW MODELING:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity MUX_713 is
port (S:in std_logic_vector (2 downto 0);
A: in std_logic_vector (7 downto 0);
Y: out std_logic);
end MUX_713;
architecture dataflow of MUX_713 is
signal s00,s11,s22,i,j,k,l,m,n,o,p:std_logic;
begin
s00<=(not S(0));
s11<=(not S(1));
s22<=(not S(2));
i<=((A(0) and s22) and s11) and s00;
j<=((A(1) and s22) and s11) and S(0);
k<=((A(2) and s22) and S(1)) and s00;
l<=((A(3) and s22) and S(1)) and S(0);
m<=((A(4) and S(2)) and s11) and s00;
41130713_SANJAY.R
• STRUCTURAL MODELING:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use
IEEE.STD_LOGIC_UNSIGNED.ALL;
entity MUX_713 is
port (S:in std_logic_vector (2
downto 0);
A: in std_logic_vector (7
downto 0);
Y: out std_logic);
end MUX_713;
architecture structural of
MUX_713 is
component not1
port(s1:in std_logic; s2: out
std_logic);
end component;
component and1
port(a1, b1, c1, d1:in
std_logic;
e1: out std_logic);
end component;
component or1
port(a,b,c,d,e,f,g,h:in
std_logic;
z1: out std_logic);
end component;
signal s00, s11, s22,
i,j,k,l,m,n,o,p: std_logic;
begin
s00<=not S(0);
s11<=not S(1);
s22<=not S(2);
i<=((A(0) and s22) and s11)
and s00;
41130713_SANJAY.R
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity MUX_B_713 is
port(S:in std_logic_vector(2 downto 0);
A: in std_logic_vector (7 downto 0); Y: out
std_logic);
end MUX_B_713;
architecture behavioural of MUX_B_713 is
begin
process(S,A)
begin
if (S = "000") then Y<=A(0);
elsif (S = "001") then Y<=A(1);
elsif (S = "010") then Y<=A(2);
elsif (S = "011") then Y<=A(3);
elsif (S = "100") then Y<=A(4);
elsif (S = "101") then Y<=A(5);
elsif (S = "110") then Y<=A(6);
else Y<=A(7);
end if;
end process;
end behavioural;
SIMULATED OUTPUT:
41130713_SANJAY.R
•
VERILOG CODE:
DATAFLOW MODELING:
BEHAVIOURAL MODELING:
•
SIMULATED OUTPUT:
2. 1*8 DEMULTIPLEXER:
• CIRCUIT DIAGRAM:
41130713_SANJAY.R
•
TRUTH TABLE:
OUTPUTS INPUTS
Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 S2 S1 S0 A
0 0 0 0 0 0 0 1 0 0 0 1
0 0 0 0 0 0 1 0 0 0 1 1
0 0 0 0 0 1 0 0 0 1 0 1
0 0 0 0 1 0 0 0 0 1 1 1
0 0 0 1 0 0 0 0 1 0 0 1
0 0 1 0 0 0 0 0 1 0 1 1
0 1 0 0 0 0 0 0 1 1 0 1
1 0 0 0 0 0 0 0 1 1 1 1
• VHDL CODE:
• DATAFLOW MODELING:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity DEMUX_713 is
port(A: in std_logic;
S:in std_logic_vector(2 downto 0);
Y:out std_logic_vector(7 downto 0));
end DEMUX_713;
architecture dataflow of DEMUX_713 is
begin
Y(0)<=((A and (not S(2)))and(not S(1)))and(not S(0));
Y(1)<=((A and (not S(2)))and (not S(1))) and S(0);
Y(2)<=((A and (not S(2))) and S(1)) and (not S(0));
Y(3)<=((A and (not S(2))) and S(1)) and S(0);
Y(4)<=((A and S(2)) and (not S(1))) and (not S(0));
Y(5)<=((A and S(2)) and (not S(1))) and S(0);
Y(6)<=((A and S(2)) and S(1)) and (not S(0));
Y(7)<=((A and S(2)) and S(1)) and S(0);
end dataflow;
41130713_SANJAY.R
•
• STRUCTURAL MODELING:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
40130713_SHARMILA.V
entity DEMUX_713 is
port(A:in std_logic;
S:in std_logic_vector(2
downto 0);
Y:out std_logic_vector(7
downto 0));
end DEMUX_713;
architecture structural of
DEMUX_713 is
component and1
port(a,b,c,d: in std_logic;
e: out std_logic);
end component;
component not1
port(i: in std_logic; j:out
std_logic);
end component;
signal s2,s1,s0:std_logic;
begin
n1:not1 port map(S(2),s2);
n2:not1 port map(S(1),s1);
n3:not1 port map(S(0),s0);
a1:and1 port
map(A,s2,s1,s0,Y(0));
a2:and1 port
map(A,s2,s1,S(0),Y(1));
a3:and1 port
map(A,s2,S(1),s0,Y(2));
a4:and1 port
map(A,s2,S(1),S(0),Y(3));
a5:and1 port
map(A,S(2),s1,s0,Y(4));
a6:and1 port
map(A,S(2),s1,S(0),Y(5));
a7:and1 port
map(A,S(2),S(1),S0,Y(6));
a8:and1 port
map(A,S(2),S(1),S(0),Y(7));
end structural;
--COMPONENT SOURCE CODE
--AND GATE
41130713_SANJAY.R
•
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity and1 is
port(a,b,c,d: in std_logic;
e: out std_logic);
end and1;
architecture dataflow of
and1 is
begin
e<=((a and b)and c)and d;
end dataflow;
--NOT GATE
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity not1 is
port(i:in std_logic; j:out
std_logic);
end not1;
40130713_SHARMILA.V
architecture dataflow of
not1 is
begin
j<= not i;
end dataflow
41130713_SANJAY.R
BEHAVIOURAL MODELING:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity DEMUX_713 is
port(A:in std_logic;
S:in std_logic_vector(2 downto 0);
Y:out std_logic_vector(7 downto 0));
end DEMUX_713;
architecture behavioural of DEMUX_713 is
begin
process(A,S)
begin
Y<= "00000000";
case S is
when "000" => Y(0)<= A;
when "001" => Y(1)<= A;
when "010" => Y(2)<= A;
when "011" => Y(3)<= A;
when "100" => Y(4)<= A;
when "101" => Y(5)<= A;
when "110" => Y(6)<= A;
when "111" => Y(7)<= A;
when others => Y<= "00000000";
end case;
end process;
end behavioural;
• SIMULATED OUTPUT:
41130713_SANJAY.R
• VERILOG CODES:
DATAFLOW MODELING:
module demux_d713(output reg [7:0] Y, input [2:0] A,
input din);
assign Y[0]=din && (~S[2])&&(~S[1])&&(~S[0]);
assign Y[1]=din && (~S[2])&&(~S[1]) && S[0];
assign Y[2]=din && (~S[2])&& S[1] && (~S[0]);
assign Y[3]=din && (~S[2]) && S[1]) && S[0];
assign Y[4]=din && S[2] && (~S[1]) && (~S[0]);
assign Y[5]=din && S[2] && (~S[1]) && S[0];
assign Y[6]=din && S[2] && S[1] && (~S[0]);
assign Y[7]=din && S[2] && S[1] && S[0];
endmodule
STRUCTURAL MODELING:
BEHAVIOURAL MODELING:
SIMULATED OUTPUT
RESULT:
The output of Multiplexer and Demultiplexer is verified by stimulating and
synthesizing the VHDL/VERILOG code.
41130713_SANJAY.R
DATE:
AIM:
To develop the source code for Ripple Carry Adder using VHDL/VERILOG and obtain
the simulation and synthesis report.
ALGORITHM:
CIRCUIT DIAGRAM:
41130713_SANJAY.R
TRUTH TABLE:
INPUTS OUTPUTS
C0 A3 A2 A1 A0 B3 B2 B1 B0 S3 S2 S1 S0 C4
0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 1 0 0 0 1 0 0 1 0 0
0 0 0 1 0 0 0 1 0 0 1 0 0 0
0 0 0 1 1 0 0 1 1 0 1 1 0 0
0 0 1 0 0 0 1 0 0 1 0 0 0 0
0 0 1 0 1 0 1 0 1 1 0 1 0 0
0 0 1 1 0 0 1 1 0 1 1 0 0 0
0 0 1 1 1 0 1 1 1 1 1 1 0 0
0 1 0 0 0 1 0 0 0 0 0 0 0 1
0 1 0 0 1 1 0 0 1 0 0 1 0 1
0 1 0 1 0 1 0 1 0 0 1 0 0 1
0 1 0 1 1 1 0 1 1 0 1 1 0 1
0 1 1 0 0 1 1 0 0 1 0 0 0 1
0 1 1 0 1 1 1 0 1 1 0 1 0 1
0 1 1 1 0 1 1 1 0 1 1 0 0 1
0 1 1 1 1 1 1 1 1 1 1 1 0 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1
41130713_SANJAY.R
VHDL CODES:
• DATAFLOW MODELING:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity RCA_713 is
port(C0: in STD_LOGIC;
A,B: in std_logic_vector(3 downto 0);
C4: out STD_LOGIC;
S: out std_logic_vector(3 downto 0));
end RCA_713;
architecture dataflow of RCA_713 is
signal C1,C2,C3:STD_LOGIC;
begin
C1<=((A(0)and B(0))or (B(0)and C0))or (C0 and
A(0));
C2<=((A(1)and B(1))or (B(1)and C1)) or (C1 and
A(1));
C3<=((A(2)and B(2))or (B(2)and C2)) or (C2 and
A(2));
S(0)<= ((A(0) xor B(0)) xor C0);
S(1)<= ((A(1) xor B(1)) xor C1);
S(2)<= ((A(2) xor B(2))xor C2);
S(3)<= ((A(3) xor B(3))xor C3);
C4<= ((A(3) and B(3))or(B(3) and C3)) or (C3 and
A(3));
end dataflow;
• STRUCTURAL MODELING:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity RCA_713 is
port(C0: in STD_LOGIC;
A,B: in std_logic_vector(3 downto 0);
C4: out STD_LOGIC;
S: out std_logic_vector(3 downto 0));
end RCA_713;
architecture structural of RCA_713 is
component fa
port(x,y,z:in std_logic;
s,c:out std_logic);
end component;
signal C1,C2,C3: std_logic;
begin
41130713_SANJAY.R
• BEHAVIOURAL MODELING:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity RCA_713 is
port(C0: in STD_LOGIC;
A,B: in std_logic_vector(3 downto 0);
C4: out STD_LOGIC;
S: out std_logic_vector(3 downto 0));
end RCA_713;
architecture behavioural of RCA_713 is
begin
process(A,B,C0)
begin
S<=A+B+C0;
if (A > "0111" or B > "0111")then
C4<='1';
else
C4<='0';
end if;
end process;
end behavioural;
41130713_SANJAY.R
SIMULATED OUTPUT:
VERILOG CODE:
DATAFLOW MODELING:
module rca_d713(a,b,c0,c4,s);
input c0;
input [3:0]a,b;
output [3:0]s;
output c4;
wire[3:1]c;
assign c1=(a[0]&b[0])|(b[0]&c0)|(c0&a[0]);
assign c2=(a[1]&b[1])|(b[1]&c[1])|(c[1]&a[1]);
assign c3=(a[2]&b[2])|(b[2]&c[2])|(c[2]&a[2]);
assign s[0]= (a[0] ^ b[0]) ^ c0;
assign s[1]= (a[1] ^ b[1]) ^ c[1];
assign s[2]= (a[2] ^ b[2]) ^ c[2];
assign s[3]= (a[3] ^ b[3]) ^ c[3];
assign c4 = (a[3] & b[3])|(b[3] & c[3])|(c[3] &
a[3]);
endmodule
STRUCTURAL MODELING:
FA_adder1(a[0],b[0],cin,s[0],c[0]),
adder2(a[1],b[1],c[0],s[1],c[1]),
adder3(a[2],b[2],c[1],s[2],c[2]),
adder4(a[3],b[3],c[2],s[3],cout);
endmodule
module FA(input a,b,c, output s,cout);
assign s=a^b^c;
assign cout= (a&b)|(b&c)|(c&a);
endmodule
BEHAVIOURAL MODELING:
SIMULATED OUTPUT:
RESULT
The output of 4-bit Ripple Carry Adder is verified by stimulating and synthesizing the
VHDL/VERILOG code.
41130713_SANJAY.R
DATE:
AIM:
To develop the source code for code converters using VHDL/VERILOG and obtain the
simulation and synthesis report.
ALGORITHM:
Step1: Define specification and initialize the design.
Step2: Declare the name of the entity and architecture by using source code.
Step3: Write the source code in VHDL/VERILOG.
Step4: Check the syntax and debug the error if found, obtain the synthesis report.
Step5: Verify the output by simulating the source code.
Step6: Write all possible combinations of input using the test bench.
Step7: Obtain the synthesis report.
1. BINARY TO GRAY CODE CONVERTER:
CIRCUIT DIAGRAM:
TRUTH TABLE:
B3 B2 B1 B0 G3 G2 G3 G0
0 0 0 0 0 0 0 0
0 0 0 1 0 0 0 1
0 0 1 0 0 0 1 1
0 0 1 1 0 0 1 0
0 1 0 0 0 1 1 0
0 1 0 1 0 1 1 1
0 1 1 0 0 1 0 1
0 1 1 1 0 1 0 0
1 0 0 0 1 1 0 0
1 0 0 1 1 1 0 1
1 0 1 0 1 1 1 1
1 0 1 1 1 1 1 0
1 1 0 0 1 0 1 0
1 1 0 1 1 0 1 1
1 1 1 0 1 0 0 1
1 1 1 1 1 0 0 0
VHDL CODES:
• DATAFLOW MODELING:
library IEEE;
use IEEE.std_logic_1164.ALL;
entity CODECOV_713 is
port(B:in std_logic_vector(3 downto 0);
41130713_SANJAY.R
• STRUCTURAL MODELING:
library IEEE;
use IEEE.std_logic_1164.ALL;
entity CODECOV_713 is
port(B:in std_logic_vector(3 downto 0);
G:out std_logic_vector(3 downto 0));
end CODECOV_713;
architecture structural of CODECOV_713 is
component xor1
port(a,b:in std_logic; c:out std_logic);
end component;
begin
x1:xor1 port map (B(3),'0',G(3));
x2:xor1 port map (B(2),B(3),G(2));
x3:xor1 port map (B(1),B(2),G(1));
x4:xor1 port map (B(0),B(1),G(0));
end structural;
--COMPONENT SOURCE CODE
--XOR GATE
library IEEE;
use IEEE.std_logic_1164.ALL;
entity xor1 is
port(a,b:in std_logic; c:out std_logic);
end xor1;
architecture dataflow of xor1 is
begin
c <= a XOR B;
end dataflow;
•BEHAVIOURAL MODELING:
SIMULATED OUTPUT:
VERILOG CODE:
• DATAFLOW MODELING:
• STRUCTURAL MODELING:
xor(g[2],b[3],b[2]);
xor(g[1],b[2],b[1]);
xor(g[0],b[1],b[0]);
endmodule
• BEHAVIOURAL MODELING:
module codeconv_s713(input [3:0]b,output reg [3:0]g);
always @(*)
begin
g[3] = b[3];
g[2] = b[3]^b[2];
g[1] = b[2]^b[1];
g[0] = b[1]^b[0];
end
endmodule
SIMULATED OUTPUT:
CIRCUIT DIAGRAM:
TRUTH TABLE:
BINARY OUTPUT GRAY INPUT
B3 B2 B1 B0 G3 G2 G3 G0
0 0 0 0 0 0 0 0
0 0 0 1 0 0 0 1
0 0 1 0 0 0 1 1
0 0 1 1 0 0 1 0
0 1 0 0 0 1 1 0
0 1 0 1 0 1 1 1
0 1 1 0 0 1 0 1
0 1 1 1 0 1 0 0
1 0 0 0 1 1 0 0
1 0 0 1 1 1 0 1
1 0 1 0 1 1 1 1
1 0 1 1 1 1 1 0
1 1 0 0 1 0 1 0
1 1 0 1 1 0 1 1
1 1 1 0 1 0 0 1
1 1 1 1 1 0 0 0
VHDL CODES:
• DATAFLOW MODELING:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity CODECONVGTB_713 is
port(G:in std_logic_vector(3 downto 0);
41130713_SANJAY.R
• STRUCTURAL MODELING:
library IEEE;
use IEEE.std_logic_1164.ALL;
entity CODECONVGTB_713 is
port(G:in std_logic_vector(3 downto 0);
B:out std_logic_vector(3 downto 0));
end CODECONVGTB_713;
architecture structural of CODECONVGTB_713 is
component xor1
port(a,b:in std_logic; c:out std_logic);
end component;
begin
x1:xor1 port map (G(3),'0',B(3));
x2:xor1 port map (G(2),G(3),B(2));
x3:xor1 port map (G(1),G(3),G(2),B(1));
x4:xor1 port map (G(0),G(1),G(3),G(2),B(0));
end structural;
--COMPONENT SOURCE CODE
--XOR GATE
library IEEE;
use IEEE.std_logic_1164.ALL;
entity xor1 is
port(a,b:in std_logic; c:out std_logic);
end xor1;
architecture dataflow of xor1 is
begin
c <= a XOR B;
end dataflow;
BEHAVIOURAL MODELING:
library IEEE;
use IEEE.std_logic_1164.ALL;
entity CODECONVGTB_713 is
port(G:in std_logic_vector(3 downto 0);
B:out std_logic_vector(3 downto 0));
end CODECONVGTB_713;
41130713_SANJAY.R
SIMULATED OUTPUT:
VERILOG CODES:
• DATAFLOW MODELING:
b[1] = g[1]^g[3]^g[2];
b[0] = g[0]^g[1]^g[3]^g[2];
end
endmodule
SIMULATED OUTPUT:
RESULT:
The output of Code Converters is verified by stimulating and synthesizing the
VHDL/VERILOG code.
41130713_SANJAY.R
DATE:
AIM:
To develop the source code for flip flops using VHDL /VEROLOG and obtain the simulation
and synthesis report.
ALGORITHM:
1. SR FLIP FLOP:
• CIRCUIT SCHEMATIC:
41130713_SANJAY.R
•
TRUTH TABLE:
RST C S R Q Q1
1 - - - 0 1
0 1 0 0 NO CHANGE NO CHANGE
0 1 0 1 0 1
0 1 1 0 1 0
0 1 1 1 X X
• VHDL CODE:
BEHAVIOUR MODELLING:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity SRFF_B713 is
port(s,r,c,rst:in std_logic;
q,q1:inout std_logic);
end SRFF_B713;
architecture behavioural of SRFF_B713 is
begin
process(s,r,c,rst)
begin
if(rst='1')then
q<='0';q1<='1';
elsif(c='1' and c'event)then
if(s='0' and r='0')then
q<=q; q1<=q1;
elsif(s='0' and r='1')then
q<='0'; q1<='1';
elsif(s='1' and r='0')then
q<='1';q1<='0';
else
q<='X';q1<='X';
end if;
end if;
end process;
end behavioural
41130713_SANJAY.R
•
SIMULATED OUTPUT:
2. JK FLIP FLOP:
• CIRCUIT SCHEMATIC:
• TRUTH TABLE:
RST C J K Q Q1
1 - - - 0 1
0 1 0 0 NO CHANGE NO CHANGE
0 1 0 1 0 1
0 1 1 0 1 0
0 1 1 1 TOGGLE TOGGLE
41130713_SANJAY.R
•
VHDL CODE:
BEHAVIOURAL MODELLING:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity JKFF_713 is
port(j,k,c,rst:in std_logic;
q,q1:inout std_logic);
end JKFF_713;
architecture behavioural of JKFF_713 is
begin
process(j,k,c,rst)
begin
if(rst='1') then
q<='0';q1<='1';
elsif(c='1' and c'event)then
if(j='0' and k='0')then
q<=q;q1<=q1;
elsif(j='0' and k='1')then
q<='0';q1<='1';
elsif(j='1' and k='0')then
q<='1';q1<='0';
else
q<=not q;
q1<=not q1;
end if;
end if;
end process;
end behavioural;
• SIMULATED OUTPUT:
41130713_SANJAY.R
•
41130713_SANJAY.R
3. D FLIP FLOP:
• CIRCUIT SCHEMATIC:
• TRUTH TABLE:
RST C D Q Q1
1 - - 0 1
0 1 0 0 1
0 1 1 1 0
• VHDL CODE:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity DFF_713 is
port(d,c,rst:in std_logic;
q,q1:inout std_logic);
end DFF_713;
architecture behavioural of DFF_713 is
begin
process(d,c,rst)
begin
if(rst='1') then
q<='0';q1<='1';
elsif(c='1' and c'event)then
if(d='0')then
q<='0';q1<='1';
else
q<='1';q1<='0';
end if;
end if;
end process;
41130713_SANJAY.R
end behavioural;
• SIMULATED OUTPUT:
4. T FLIP FLOP:
• CIRCUIT SCHEMATIC:
• TRUTH TABLE:
RST C T Q Q1
1 - - 0 1
NO NO
0 1 0
CHANGE CHANGE
0 1 1 TOGGLE TOGGLE
41130713_SANJAY.R
• VHDL CODE:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity TFF_713 is
port(t,c,rst:in std_logic;
q,q1:inout std_logic);
end TFF_713;
architecture behavioural of TFF_713 is
begin
process(t,c,rst)
begin
if(rst='1') then
q<='0';q1<='1';
elsif(c='1' and c'event)then
if(t='0')then
q<=q;q1<=q1;
else
q<=not q;q1<=not q1;
end if;
end if;
end process;
end behavioural;
• SIMULATED OUTPUT;
41130713_SANJAY.R
VERILOG CODE:
1. SR FLIP FLOP:
2.
JK FLIP FLOP:
3.
D FLIP FLOP:
4.
T FLIP FLOP:
RESULT:
The output of Flip Flops is verified by stimulating and synthesizing the VHDL/
VERILOG code.
41130713_SANJAY.R
DATE:
AIM:
To develop the source code for shift registers using VHDL/VERILOG and obtain the
simulation and synthesis report.
ALGORITHM:
• CIRCUIT SCHEMATIC:
41130713_SANJAY.R
• TRUTH TABLE:
0 1
3 0 1110
4 1 1111
• VHDL CODE:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity SISO_713 is
port(c,d,r:in std_logic;
q: out std_logic);
end SISO_713;
architecture behavioural of SISO_713 is
signal q1: std_logic_vector(3 downto 0);
begin
process(c,d,r)
begin
if (r='1') then
q1<="0000";
elsif(c='1' and c'event) then
q1(3)<=d;
q1(2 downto 0)<=q1(3 downto 1);
q<=q1(1);
end if;
end process;
end behavioural;
• SIMULATED OUTPUT:
41130713_SANJAY.R
• CIRCUIT SCHEMATIC:
• TRUTH TABLE:
0 1
3 0001 1110
4 0000 1111
• VHDL CODE:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity SR_SIPO_713 is
port(c,d,r: in std_logic;
q:out std_logic_vector(3 downto 0));
end SR_SIPO_713;
architecture behavioural of SR_SIPO_713 is
signal q1: std_logic_vector(3 downto 0);
begin
process(c,d,r)
begin
41130713_SANJAY.R
if(r='1')then
q1<="0000";
elsif(c='1' and c'event)then
q1(3)<=d;
q1(2)<=q1(3);
q1(1)<=q1(2);
q1(0)<=q1(1);
end if;
end process;
q<=(not q1);
end behavioural;
• SIMULATED OUTPUT:
41130713_SANJAY.R
• TRUTH TABLE:
• VHDL CODE:
• SIMULATED OUTPUT:
41130713_SANJAY.R
• CIRCUIT SCHEMATIC:
• TRUTH TABLE:
0
5 0001
0010
6 0010
7 0010
0011
8 0011
• VHDL CODE:
41130713_SANJAY.R
VERILOG CODE:
else
begin
q[3] = si;
q[2] = q[3];
q[1] = q[2];
q[0] = q[1];
so = q[1];
end
end
endmodule
module sipo_713(si,rst,clk,po);
input si,rst,clk;
output [0:3]po;
reg [0:3]po;
always@(si,rst,clk)
begin
if(rst == 1)
begin
po = 4'bZ;
end
else
begin
po[0] = si;
po[1] = po[0];
po[2] = po[1];
po[3] = po[2];
end
end
endmodule
41130713_SANJAY.R
module piso_713(pi,rst,clk,so);
input [3:0]pi;
input rst,clk;
output so;
reg so;
reg [3:0]d;
always@(rst,clk)
begin
if(rst == 1)
begin
so = 1'b0;
d = pi;
end
else
begin
d = d>>1'b1;
so = d;
end
end
endmodule
41130713_SANJAY.R
module pipo_713(pi,rst,clk,po);
input[0:3]pi;
input rst,clk;
output reg[0:3]po;
always@(pi,rst,clk)
begin
if (rst==1)
begin
po=4'bZ;
end
else
begin
po=pi;
end
end
endmodule
RESULT:
DATE:
AIM:
To develop the source code for synchronous and asynchronous counters using
VHDL/VERILOG and obtain the simulation and synthesis report.
ALGORITHM:
1. SYNCHRONOUS COUNTER:
• CIRCUIT SCHEMATIC:
41130713_SANJAY.R
• TRUTH TABLE:
1 - 0000 1111
1 0000 1111
2 0001 1110
3 0010 1101
4 0011 1100
0
5 1000 0111
6 0101 0101
7 0110 1001
8 0111 1000
• VHDL CODE:
BEHAVIOURAL MODELING:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity SCOUNTER_713 is
port (clk,reset : in STD_LOGIC;
q,q_bar: out STD_LOGIC_VECTOR (3 downto 0));
end SCOUNTER_713;
architecture Behavioral of SCOUNTER_713 is
begin
process(clk, reset)
variable count : std_logic_vector(3 downto 0);
begin
if (reset = '1') then
count := "0000";
elsif (rising_edge(clk)) then
count := count + 1;
end if;
q <= count;
q_bar <= not count;
end process;
end Behavioral;
41130713_SANJAY.R
STRUCTURAL MODELING:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity SCOUNTER_713 is
port(rst,clk : in std_logic;
q,qbar : inout std_logic_vector(3 downto 1));
end SCOUNTER_713;
architecture structural of SCOUNTER_713 is
component jk_ff
port(j,k,clk,rst : in std_logic;
q,qbar : inout std_logic);
end component;
component and_gate
port(a,b : in std_logic;
c : out std_logic);
end component;
signal p : std_logic;
begin
jk1 : jk_ff port map('1','1',clk,rst,q(1),qbar(1));
jk2 : jk_ff port map(q(1),q(1),clk,rst,q(2),qbar(2));
a1 : and_gate port map(q(1),q(2),p);
jk3 : jk_ff port map(p,p,clk,rst,q(3),qbar(3));
end structural;
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,k,clk,rst : in std_logic;
q,qbar : inout std_logic);
end jk_ff;
architecture behavioural of jk_ff is
begin
process(j,k,clk,rst)
begin
if(rst='1')then
q<='0';
qbar<='1';
elsif(clk='1'and clk'event)then
if(j='0' and k='0')then
q<=q;
qbar<=qbar;
elsif(j='0' and k='1')then
40130713_SHARMILA.V
41130713_SANJAY.R
q<='0';
qbar<='1';
elsif(j='1' and k='0')then
q<='1';
qbar<='0';
else
q<=not q;
qbar<=not qbar;
end if;
end if;
end process;
end behavioural;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity and_gate is
port(a,b : in std_logic;
c : out std_logic);
end and_gate;
architecture dataflow of and_gate is
begin
c <= a and b;
end dataflow;
• SIMULATED OUTPUT:
41130713_SANJAY.R
2. ASYNCHRONOUS COUNTER:
• CIRCUIT SCHEMATIC:
• TRUTH TABLE:
1 - 0000 1111
1 0001 1110
2 0010 1101
3 0011 1100
0 4 1000 0111
5 0101 0101
6 0110 1001
7 0111 1000
. VHDL CODE:
BEHAVIOURAL MODELING:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
41130713_SANJAY.R
entity ASCOUNTER_713 is
port (clk,reset : in STD_LOGIC;
q,q_bar : out STD_LOGIC_VECTOR (3 downto 0));
end ASCOUNTER_713;
architecture Behavioral of ASCOUNTER_713 is
begin
process(clk, reset)
variable count : std_logic_vector(3 downto 0);
begin
if (reset = '1') then
count := "0000";
elsif (clk'event and clk = '1') then
count := count + 1;
end if;
q <= count;
q_bar <= not count;
end process;
end Behavioral;
STRUCTURAL MODELING:
• SIMULATED OUTPUT:
41130713_SANJAY.R
VERILOG CODE:
1. SYNCHRONOUS COUNTER:
BEHAVIOURAL MODELING:
STRUCTURAL MODELING:
module scounter_713rst,clk,q,qbar);
input rst,clk;
output [3:1]q,qbar;
wire p;
jk_ff
JK1(1'b1,1'b1,rst,clk,q[1],qbar[1]),
JK2(q[1],q[1],rst,clk,q[2],qbar[2]);
and_gate1
A1(q[1],q[2],p);
jk_ff
JK3(p,p,rst,clk,q[3],qbar[3]);
endmodule
module jk_ff(j,k,rst,clk,q,qbar);
input j,k,rst,clk;
output q,qbar;
reg q,qbar;
always@(posedge clk)
begin
if(rst==1)
begin
q=1'b0;qbar=1'b1;
end
else if(j==0 && k==0)
40130713_SHARMILA.V
41130713_SANJAY.R
begin
q=q;qbar=qbar;
end
else if(j==0 && k==1)
begin
q=1'b0;qbar=1'b1;
end
else if(j==1 && k==0)
begin
q=1'b1;qbar=1'b0;
end
else
begin
q=~q;qbar=~qbar;
end
end
endmodule
module and_gate1(a,b,p);
input a,b;
output p;
reg p;
always@(a,b)
begin
p = a & b;
end
endmodule
2. ASYNCHRONOUS COUNTER:
BEHAVIOURAL MODELING:
module
acounter_713(clk,rst,count);
input clk,rst; output [3:0]count;
reg [3:0]q;
41130713_SANJAY.R
RESULT:
DATE:
AIM:
To develop the source code for Moore and Mealy FSM in VHDL/VERILOG and obtain
the simulation and synthesis report.
ALGORITHM:
1. MOORE FSM:
• CIRCUIT SCHEMATIC:
41130713_SANJAY.R
• TRUTH TABLE:
IN OUT
PRESENT NEXT
CLK COMMENTS
X Y STATE STATE
1 0 a b
2 0 b c
Transition Occurs
3 1 0 c d
4 1 d a
• VHDL CODE;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity MOOREFSM_713 is
port(x,clk:in std_logic;
y:out std_logic);
end MOOREFSM_713;
architecture behavioural of MOOREFSM_713
is
type state is (a,b,c,d);
signal p_state,n_state: state;
begin
process(clk)
begin
if (clk='1') then
p_state<=n_state;
end if;
end process;
process(clk)
begin
if (clk='1') then
case n_state is
41130713_SANJAY.R
when a=>y<='0';
if x='1' then
y<='0';
n_state<=b;
else
n_state<=a;
end if;
when b=>y<='0';
if x='1' then
n_state<=c;
else
n_state<=b;
end if;
when c=>y<='0';
if x='1' then
n_state<=d;
else
n_state<=c;
end if;
when d=>y<='1';
if x='1' then
n_state<=a;
else
n_state<=d;
end if;
end case;
end if;
end process;
end behavioural;
SIMULATED OUTPUT:
VERILOG CODE:
module moorefsm_713(x,clk,y);
input x,clk;
output y;
reg y;
parameter st0=0,st1=1,st2=2,st3=3;
reg[0:1]moore_state=0;
always @ (posedge clk)
41130713_SANJAY.R
begin
case(moore_state)
st0:
begin
if(x==1'b1)
begin
moore_state=st1;
y=0;
end
end
st1:
begin
if(x==1'b1)
begin
moore_state=st2;
y=0;
end
end
st2:
begin
if(x==1'b1)
begin
y=0;
moore_state=st3;
end
end
st3:
begin
if(x==1'b1)
begin
moore_state=st0;
y=1;
end
end
endcase
end
endmodule
SIMULATED OUTPUT:
41130713_SANJAY.R
2. MEALY FSM:
• CIRCUIT SCHEMATIC:
• TRUTH TABLE:
IN OUT
PRESENT NEXT
CLK COMMENTS
X Y STATE STATE
1 0 a b
2 1 b c
Transition Occurs
3 1 0 c d
4 1 d a
5 0 a a The state transition
stops unless the input
0
6 0 a a is 1 regardless of clk.
• VHDL CODE;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity MEALYFSM_713 is
port(x,clk:in std_logic;
y:out std_logic);
41130713_SANJAY.R
end if;
end case;
end process;
end behavioural;
• SIMULATED OUTPUT:
• VERILOG CODE:
module mealyfsm_713(x,clk,y);
input x,clk;
output reg y;
parameter
st0=0,st1=1,st2=2,st3=3;
reg[0:1]mealy_state=0;
always @(posedge clk)
begin
case(mealy_state)
st0:
begin
if(x==1'b1)
begin
st1:
begin
if(x==1'b1)
begin
mealy_state=st2;
y=1;
end
else
41130713_SANJAY.R
begin
y=0;
end
end
st2
begin
if(x==1'b1)
begin
mealy_state=st3;
y=1;
end
else
begin
y=0;
end
end
st3:
begin
if(x==1'b1)
begin
mealy_state=st0;
y=1;
end
else
begin
y=1;
end
end
endcase
end
endmodule
• SIMULATED OUTPUT:
RESULT:
The output of Mooley and Mealy FSM is verified by stimulating and synthesizing the
VHDL/VERILOG code.
41130713_SANJAY.R
DATE:
AIM:
To develop the source code for Arithmetic and Logic Unit in VHDL/VERILOG and
obtain the simulation and synthesis report.
ALGORITHM:
CIRCUIT SCHEMATIC:
41130713_SANJAY.R
TRUTH TABLE:
001 Logical OR (a OR b)
VHDL CODE:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity ALU_713 is
port(clk: in std_logic;
a,b: in std_logic_vector(7 downto 0);
opr: in std_logic_vector(2 downto 0);
ans: out std_logic_vector(7 downto 0));
end ALU_713;
architecture behavioural of ALU_713 is
begin
process(a,b,opr,clk)
begin
if(clk='1')then
case opr is
when "000" =>ans<= a+b;
when "001" =>ans<= a-b;
when "010" =>ans<= (not a)+1;
when "011" =>ans<= (not b)+1;
when "100" =>ans<= a+1;
when "101" =>ans<= b+1;
when "110" =>ans<= a-1;
when "111" =>ans<= b-1;
when others =>ans<= "00000000";
end case;
elsif(clk='0')then
case opr is
when "000" =>ans<= a and b;
when "001" =>ans<= a or b;
when "010" =>ans<= a nand b;
when "011" =>ans<= a nor b;
when "100" =>ans<= a xor b;
when "101" =>ans<= a xnor b;
when "110" =>ans<= not a;
when "111" =>ans<= not b;
when others =>ans<= "00000000";
end case;
end if;
end process;
end behavioural;
41130713_SANJAY.R
SIMULATED OUTPUT:
VERILOG CODE:
module alu_713(clk,a,b,opr,ans);
input clk;
input [7:0]a,b;
input [2:0]opr;
output reg[7:0]ans;
always@(a,b,opr,clk)
begin
if(clk == 1)
begin
case(opr)
3'b000 : ans = a + b;
3'b001 : ans = a - b;
3'b010 : ans = (~a) + 1;
3'b011 : ans = (~b) + 1;
3'b100 : ans = a + 1;
3'b101 : ans = b + 1;
3'b110 : ans = a - 1;
3'b111 : ans = b - 1;
default : ans = 8'bZ;
endcase
end
else
begin
case(opr)
3'b000 : ans = a & b;
3'b001 : ans = a | b;
40130713_SHARMILA.V
3'b010 : ans = ~(a & b);
3'b011 : ans = ~(a | b);
3'b100 : ans = a ^ b;
3'b101 : ans = ~(a ^ b);
3'b110 : ans = ~a;
41130713_SANJAY.R
3'b111 : ans = ~b;
default : ans = 8'bZ;
endcase
end
end
endmodule
SIMULATED OUTPUT:
RESULT:
The output of 8 – bit Arithmetic and Logic Unit is verified by stimulating and
synthesizing the VHDL/VERILOG code.
41130713_SANJAY.R
DATE:
AIM:
To develop the source code for Barrel Shifter in VHDL/VERILOG and obtain the
simulation and synthesis report.
ALGORITHM:
CIRCUIT SCHEMATIC:
TRANSITION TABLE:
41130713_SANJAY.R
Shift DATA
Shift DATA
S 0 0 0 1
0 0 0 0 1
1 0 0 1 0
2 0 1 0 0
3 1 0 0 0
VHDL CODE:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
entity BARREL_SHIFTER_713 is
port(din: in std_logic_vector(3 downto 0);
s: in integer range 0 to 3;
dout: inout std_logic_vector(3 downto 0));
end BARREL_SHIFTER_713;
architecture behavioural of BARREL_SHIFTER_713 is
begin
process(din,s)
variable a:std_logic_vector(3 downto 0);
begin
a:=din;
for i in 1 to s loop
a:=a(2 downto 0)& a(3);
41130713_SANJAY.R
end loop;
dout<=a;
end process;
end behavioural;
SIMULATED OUTPUT:
VERILOG CODE:
module barrelshifter_713(data, count,
dout);
input [3:0] data;
input [2:0] count;
output [3:0] dout;
reg[3:0]dout,x;
integer k;
always@(data,count)
begin
x=data;
for(k=0;k<count;k=k+1)
begin
x={x[2:0],x[3]};
end
dout=x;
end
endmodule
41130713_SANJAY.R
SIMULATED OUTPUT:
RESULT:
The output of Barrel Shifter is verified by stimulating and synthesizing the VHDL/
VERILOG code.