DSD Fpga R22 Lab Maual Ok
DSD Fpga R22 Lab Maual Ok
OF ECE
0|Page
MIST DEPT.OF ECE
PSO2
To nurture the students in designing, analyzing and interpreting required in research and
development with exposure in multi disciplinary technologies in order to mould them as successful
industry ready engineers/entrepreneurs
PSO3
To empower students with all round capabilities who will be useful in making nation strong in
technology, education and research domains.
0|Page
MIST DEPT.OF ECE
2. Problem analysis: Identify, formulate, review research literature, and analyze complex
engineering problems reaching substantiated conclusions using first principles of
mathematics, natural sciences, and engineering sciences.
3. Design / development of solutions: Design solutions for complex engineering problems and
design system components or processes that meet the specified needs with appropriate
consideration for the public health and safety, and the cultural, societal, and environmental
considerations.
5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and
modern engineering and IT tools including prediction and modeling to complex engineering
activities with an understanding of the limitations.
6. The engineer and society: Apply reasoning informed by the contextual knowledge to assess
societal, health, safety, legal and cultural issues and the consequent responsibilities relevant
to the professional engineering practice.
8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and
norms of the engineering practice.
9. Individual and team work: Function effectively as an individual, and as a member or leader
in diverse teams, and in multidisciplinary settings.
11. Project management and finance: Demonstrate knowledge and understanding of the
engineering and management principles and apply these to one’s own work, as a member
and leader in a team, to manage projects and in multi disciplinary environments.
12. Life- long learning: Recognize the need for, and have the preparation and ability to engage
in independent and life-long learning in the broadest context of technological change.
0|Page
MIST DEPT.OF ECE
LABORATORY RULES
1. You are expected to arrive on time and not depart before the end of a laboratory.
2. You must not enter a lab unless you have permission from a technician or lecturer.
3. You are expected to comply with instructions, written or oral, that the laboratory
Instructor gives you during the laboratory session.
4. You should behave in an orderly fashion always in the lab.
5. You must not stand on the stools or benches in the laboratory.
6. Keep the workbench tidy and do not place coats and bags on the benches.
7. You must ensure that at the end of the laboratory session all equipment used is
stored away where you found it.
8. You must put all rubbish such as paper outside in the corridor bins. Broken components
should be returned to the lab technician for safe disposal.
9. You must not remove test equipment, test leads or power cables from any lab without
permission.
10. Eating, smoking and drinking in the laboratories are forbidden.
11. The use of mobile phones during laboratory sessions is forbidden.
12. The use of email or messaging software for personal communications during laboratory
sessions is forbidden.
13. Playing computer games in laboratories is forbidden.
0|Page
MIST DEPT.OF ECE
CYCLE-I
PAGE
S.NO. EXPERIMENT NAME
NO.
1 HDL code to realize all the logic gates
7 Design of Multiplexer
0|Page
MIST DEPT.OF ECE
EXPERIMENT: 1
HDL CODE TO REALIZE ALL LOGIC GATES
AIM: To develop the source code for logic gates by using VERILOG and obtain the simulation, synthesis,
place and route and implement into FPGA.
XILINX-VIVADO
LOGIC DIAGRAM:
A B Y=AB
A B Y=A+B
0 0 0
0 0 0
0 1 0
0 1 1
1 0 0
1 0 1
1 1 1
1 1 1
1| P a g e
MIST DEPT.OF ECE
XNOR GATE:
LOGIC DIAGRAM: TRUTH TABLE:
A B
0 0 1
0 1 0
1 0 0
1 1 1
VERILOG SOURCE CODE:
endmodule
Simulation output:
RESULT:
Thus the OUTPUT’s of all logic gates are verified by synthesizing and simulating the VERILOG
code.
1| P a g e
MIST DEPT.OF ECE
EXPERIMENT: 2
FULL ADDER
AIM: To develop the source code for Full adder by using VERILOG and obtain the simulation,
synthesis, place and route and implement into FPGA.
SOFTWARE REQUIRED:
XILINX-VIVADO
THEORY:
A combinational circuit that performs the addition of three bits is called a half-adder. This circuit
needs three binary inputs and produces two binary outputs. One of the input variables designates
the augends and other designates the addend. Mostly, the third input represents the carry from
the previous lower significant position. The output variables produce the sum and the carry.
The simplified Boolean functions of the two outputs can be obtained
as below: Sum S = x y z
Carry C = xy + xz + yz
Where x, y & z are the two input variables.
PROGRAM:
//Gate-level description of Full Adder using two Half
Adder //Description of Half Adder
module halfadder(s,co,x,y);
input x,y;
output s,co;
//Instatiate primitive
gates xor (s,x,y);
and (co,x,y);
endmodule
halfadder ha_1(s1,d1,x,y);
1| P a g e
MIST DEPT.OF ECE
halfadder ha_2(s,d2,s1,ci);
or or_gate(co,d2,d1);
endmodule
Behavioral Modeling:
Dataflow Modeling:
input z;
output sum;
output carry;
assign#2 p=x&y;
assign#2 q=y&z;
assign#2 r=z&x;
assign#4 sum=x^y^z;
assign#4carry =(p | q) | r;
endmodule
LOGIC DIAGRAM:
Circuit diagram:
RESULT:
Thus the logic circuit for the Full adder is designed in Verilog HDL and the output is verified.
DEPT.OF ECE
EXPERIMENT: 3
DESIGN OF 2-TO-4 DECODER
AIM:
To develop the source code for decoder by using VERILOG and obtain the simulation, synthesis, place and
route and implement into FPGA.
XILINX - VIVADO
0 0 1 0 1 1 1
0 1 1 1 0 1 1
1 0 1 1 1 0 1
1 1 1 1 1 1 0
SIMULATION OUTPUT:
RESULT:
Thus the OUTPUT’s of decoder are verified by synthesizing and simulating the VERILOG code.
MIST DEPT.OF ECE
EXPERIMENT: 4
DESIGN OF 8-TO-3 ENCODER
AIM:
To develop the source code for 8-to-3 encoder by using VERILOG
ENCODER:
LOGIC DIAGRAM: TRUTH TABLE:
D0 D1 D2 D3 D4 D5 D6 D7 X Y Z
1 0 0 0 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0 0 1
0 0 1 0 0 0 0 0 0 1 0
0 0 0 1 0 0 0 0 0 1 1
0 0 0 0 1 0 0 0 1 0 0
0 0 0 0 0 1 0 0 1 0 1
0 0 0 0 0 0 1 0 1 1 0
0 0 0 0 0 0 0 1 1 1 1
SIMULATION OUTPUT:
RESULT:
Thus the OUTPUT’s of Encoded are verified by synthesizing and simulating the VERILOG code.
14 | P a g e
DEPT.OF ECE
EXPERIMENT: 5
DESIGN OF 4-BIT BINARY TO GRAY CONVERTER
AIM:
To develop the source code for binary to gray converter by using VERILOG and obtained the simulation,
synthesis, place and route and implement into FPGA.
XILINX-VIVADO
TRUTH TABLE:
BCD GRAY
0000 0000
0001 0001
0010 0011
0011 0010
0100 0110
0101 0111
0110 0101
0111 0100
1000 1100
1001 1101
LOGIC DIAGRAM:
Behavioral Modeling:
reg [3:0] g;
always@(b) 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
Simulation output:
RESULT:
Thus the OUTPUT’s of binary to gray converter are verified by synthesizing and simulating the VERILOG
code.
DEPT.OF ECE
EXPERIMENT: 6
DESIGN OF FLIP FLOPS (SR, JK, D)
AIM:
To develop the source code for FLIP FLOPS by using VERILOG and obtained the simulation, synthesis,
place and route and implement into FPGA.
XILINX-VIVADO
SR FLIPFLOP:
LOGIC DIAGRAM: TRUTH TABLE:
Q(t) S R Q(t+1)
1
S 3 1 0 0 0 0
2 3
2 Q 0 0 1 0
0 1 0 1
CP 0 1 1 X
1 0 0 1
1
1
3
1 0 1 0
32 Q 1 1 0 1
2
R 1 1 1 X
Behavioral Modeling:
end
SIMULATION OUTPUT:
JK FLIPFLOP:
1 Q(t) J K Q(t+1)
K 2 9 1
8
2
3
Q 0 0 0 0
0 0 1 0
CP 0 1 0 1
0 1 1 1
1
1
9
3
2 Q
1 0 0 1
2
J 8
1 0 1 0
1 1 0 1
1 1 1 0
DEPT.OF ECE
Behavioral Modeling:
SIMULATION OUTPUT:
D FLIPFLOP:
LOGIC DIAGRAM: TRUTH TABLE:
1
D
2
3 1
2
3
Q
Q(t) D Q(t+1)
1
CP 0 0 0
1
0 1 1
1 3
3
Q
1 0 0
3
2
2
1 1 1
Behavioral Modeling:
else
begin
q=1'b1;
qbar=1'b0;
end
end
endmodule
SIMULATION OUTPUT:
RESULT:
Thus the OUTPUT’s of Flip flops using three modeling styles are verified by synthesizing and simulating the
VERILOG code.
DEPT.OF ECE
EXPERIMENT: 7
DESIGN OF
MULTIPLEXERS
and n selection lines whose bit combinations determine which input is selected. A multiplexer is
also called a data selector, since it selects one of many inputs and steers the binary information
to the output lines. Multiplexer ICs may have an enable input to control the operation of the
unit. When the enable input is in a given binary state (the disable state), the outputs are
disabled, and when it is in the other state (the enable state), the circuit functions as normal
multiplexer. The enable input (sometimes called strobe) can be used to expand two or more
multiplexer ICs to digital multiplexers with a larger number of inputs.The size of the multiplexer
n n
is specified by the number 2 of its input lines and the single output line. In general, a 2 – to – 1
n n
line multiplexer is constructed from an n – to 2 decoder by adding to it 2 input lines, one to
each AND gate. The outputs of the AND gates are applied to a single OR gate to provide the 1 –
line output.
PROCEDURE:
1) The multiplexer circuit is designed and the Boolean function is found out.
2) The Verilog Module Source for the circuit is written.
3) It is implemented in Model Sim and Simulated.
DEPT.OF ECE
4) Signals are provided and Output Waveforms are viewed.
DEPT.OF ECE
TRUTH TABLE:
INPUT OUTPUT
s[1] s[0] y
0 0 D[0]
0 1 D[1]
1 0 D[2]
1 1 D[3]
module
multiplexer(y,d,s);
output y;
input [3:0] d;
input [1:0] s;
wire a,b,c,e,f,g,h,i;
//Instantiate Primitive gates
not (a,s[1]);
DEPT.OF ECE
not (b,s[0]);
and (c,d[0],b,a);
and (e,d[1],s[0],a);
and (f,d[2],b,s[1]);
and (g,d[3],s[0],s[1]);
or (h,c,e);
or (i,f,g);
or (y,h,i);
endmodule
WAVEFORM OF MULTIPLEXERS:
RESULT: Thus the multiplexer is designed in Verilog HDL and the output is verified.
DEPT.OF ECE
EXPERIMENT: 8
RIPPLE COUNTER REALIZATION IN VERILOG HDL
module
ripplecounter(A0,A1,A2,A3,COUNT,RESET);
output A0,A1,A2,A3;
input COUNT,RESET;
//Instantiate Flip-Flop
DEPT.OF ECE
FF F0(A0,COUNT,RESET);
FF F1(A1,A0,RESET);
FF F2(A2,A1,RESET);
FF F3(A3,A2,RESET);
endmodule
//Description of Flip-Flop
module
FF(Q,CLK,RESET);
output Q;
input CLK,RESET; reg Q;
always @(negedge CLK or negedge RESET) if(~RESET)
Q=1'b0; else
Q=(~Q); endmodule
LOGIC DIAGRAM:
4-BIT RIPPLE COUNTER:
DEPT.OF ECE
TRUTH TABLE:
COUNT A0 A1 A2 A3
0 0 0 0 0
1 1 0 0 0
2 0 1 0 0
3 1 1 0 0
4 0 0 1 0
5 1 0 1 0
6 0 1 1 0
7 1 1 1 0
8 0 0 0 1
9 1 0 0 1
10 0 1 0 1
11 1 1 0 1
12 0 0 1 1
13 1 0 1 1
14 0 1 1 1
15 1 1 1 1
TRUTH TABLE:
COUNT A0 A1 A2 A3
0 0 0 0 0
1 1 0 0 0
2 0 1 0 0
3 1 1 0 0
4 0 0 1 0
5 1 0 1 0
6 0 1 1 0
7 1 1 1 0
8 0 0 0 1
9 1 0 0 1
10 0 0 0 0
//Description of Flip-Flop
module FF(Q,CLK,RESET);
output Q;
input CLK,RESET;
reg Q=1'b0;
always @(negedge CLK or negedge RESET)
if(~RESET)
Q=1'b0;
else
Q=(~Q);
endmodule
31 | P a g e
DEPT.OF ECE
32 | P a g e
DEPT.OF ECE
33 | P a g e
DEPT.OF ECE
TRUTH TABLE:
COUNT A0 A1 A2 A3
0 0 0 0 0
1 1 0 0 0
2 0 1 0 0
3 1 1 0 0
4 0 0 1 0
5 1 0 1 0
6 0 1 1 0
7 1 1 1 0
8 0 0 0 1
9 1 0 0 1
10 0 1 0 1
11 1 1 0 1
12 0 0 0 0
Module
MOD12(A0,A1,A2,A3,COUNT);
output A0,A1,A2,A3;
input COUNT;
wire RESET;
//Instantiate Flip-Flop
FF F0(A0,COUNT,RESET);
FF F1(A1,A0,RESET);
FF F2(A2,A1,RESET);
FF F3(A3,A2,RESET);
//Instantiate Primitive
gates nand (RESET,A2,A3);
endmodule
//Description of Flip-Flop
module FF(Q,CLK,RESET);
output Q;
input CLK,RESET;
reg Q=1'b0;
always @(negedge CLK or negedge RESET) if(~RESET)
Q=1'b0;
34 | P a g e
DEPT.OF ECE
else
Q=(~Q);
endmodule
module simulation;
reg COUNT;
wire A0,A1,A2,A3;
//Instantiate MOD12 Counter
MOD12 MOD12_TEST(A0,A1,A2,A3,COUNT);
always
#10 COUNT=~COUNT;
initial
begin
COUNT=1'b0;
end
endmodule
35 | P a g e
DEPT.OF ECE
RESULT:
Thus the ripple counter is designed in Verilog HDL and the output is verified.
36 | P a g e
DEPT.OF ECE
EXPERIMENT: 9
Sequence Detector (Finite State Machine- Mealy and Moore Machines)
AIM:
To develop the source code for Sequence Detector (Finite State Machine- Mealy and Moore Machines)
by using VERILOG and obtain the simulation, synthesis, place and route and implement into FPGA.
SOFTWARE REQUIRED:
XILINX- VIVADO
MOORE FSM:
LOGIC DIAGRAM:
Behavioral Modeling:
module moorefsm(a,clk,z);
input a;
input clk;
output z;
reg z;
parameter st0=0,st1=1,st2=2,st3=3;
reg[0:1]moore_state;
initial
begin
moore_state=st0;
end
always @ (posedge(clk))
case(moore_state)
st0:
begin
z=1;
if(a)
moore_state=st2;
end
37 | P a g e
DEPT.OF ECE
st1:
begin
z=0;
if(a)
moore_state=st3;
end
st2:
begin
z=0;
if(~a)
moore_state=st1;
else
moore_state=st3;
end
st3:
begin
z=1;
if(a)
moore_state=st0;
end
endcase
endmodule
Simulation output:
MEALY FSM:
38 | P a g e
DEPT.OF ECE
TRUTH TABLE:
Behavioral Modeling:
parameter st0=0,st1=1,st2=2,st3=3;
reg[0:1]mealy_state;
initial
begin
mealy_state=st0;
end
always @ (posedge(clk))
case(mealy_state)
st0:
begin
if(a) begin
z=1;
mealy_state=st3; end
else
z=0;
end
st1:
begin
if(a) begin
z=0;
mealy_state=st0; end
else
39 | P a g e
DEPT.OF ECE
z=1;
end
st2:
begin
if(a) begin
z=1;
mealy_state=st1; end
else
z=0;
end
st3:
begin
z=0;
if(a) begin
mealy_state=st1; end
else
mealy_state=st2;
end
endcase
endmodule
SIMULATION OUTPUT:
RESULT:
Thus the OUTPUT’s of Moore and Mealy FSM is verified by synthesizing and simulating the VHDL
and VERILOG code.
40 | P a g e
DEPT.OF ECE
EXPERIMENT: 10
Design of ALU to Perform – ADD, SUB, AND-OR, 1’s and 2’s Compliment,
AIM: Write a Verilog program for 32-bit ALU shown in figure below and verify the
functionality of ALU by selecting appropriate test patterns. The functionality of the ALU
is presented in Table 1.
a. Write test bench to verify the functionality of the ALU considering all possible input patterns
b. The enable signal will set the output to required functions if enabled, if disabled all the outputs
are set to tri-state
Block Diagram:
41 | P a g e
DEPT.OF ECE
Program:
module ALU32(
input en,
input [0:2] op ,
input [31:0] A,
input [31:0] B,
output reg ack,
output reg [32:0] res
);
always@(en,op,A,B)
begin
if(en)
case(op)
else
3'b000: res= A+B;
3'b001: res= A-B;
3'b010: res= A+1;
3'b011: res= A-1;
3'b100: res= A;
3'b101: res= ~A;
3'b110: res= A|B;
3'b111: res= A&B;
default: res=33'hxxxxxxxx;
endcase
res=33'hzzzzzzzz;
42 | P a g e
DEPT.OF ECE
end
endmodule
module TB_ALU32;
// Inputs
reg en;
reg [31:0] A;
reg [31:0] B;
// Outputs
wire ack;
ALU32 uut (
.en(en),
.op(op),
.A(A),
.B(B),
.ack(ack),
.res(res)
);
initial begin
// Initialize Inputs
en = 0;
op = 02;
43 | P a g e
DEPT.OF ECE
A = 20;
B = 10;
#50;
en = 1;
A = 32'hffff_ffff;
B = 32'h2;
op = 0;
#50; op = 1;
#50; op = 2;
#50; op = 3;
#50; op = 4;
#50; op = 5;
#50; op = 6;
#50; op = 7;
#50; op = 3'b1xx;
#50;
$finish;
end
end module
44 | P a g e
DEPT.OF ECE
Result Waveform:
45 | P a g e
DEPT.OF ECE
46 | P a g e
DEPT.OF ECE
RESULT:
Thus the OUTPUT’s of 32 Bit ALU is verified by synthesizing and simulating the VHDL and
VERILOG code.
47 | P a g e
DEPT.OF ECE
EXPERIMENT: 11
asynchronous decade counter c)ring counter d)Johnson counter using behavioral modelling.
a register that goes through a predetermined sequence of states upon the application of input
pulses. There are two types of counters – Synchronous Counter & Asynchronous Counter.
Synchronous Counter
In a synchronous counter, the input pulses are applied to all clock pulse inputs of all flip
Ring Counter
Asynchronous Counter
In an asynchronous counter, the flip flop output transition serves as a source for triggering
other flip flops. In other words, the clock pulse inputs of all flip flops, except the first, are
triggered not by the incoming pulses, but rather by the transition that occurs in previous flip
flop’s output.. Asynchronous counter is also known as serial sequential circuit. Example of
Up Down Counter
Synchronous counters are faster than asynchronous counter because in synchronous counter
48 | P a g e
DEPT.OF ECE
In synchronous counters, the clock input is connected to all of the flip-flop so that
they are clocked simultaneously. An asynchronous counter is one in which the flip-flop
within the counter do not change states at exactly the same time because they do not have a
common clock pulse.
49 | P a g e
DEPT.OF ECE
PROGRAMME:
module upcount_4bit(q,clk,res);
input clk,res;
output [3:0]q;
reg [3:0]q;
always@(posedge clk)
50 | P a g e
DEPT.OF ECE
begin
if(res==1)
begin
q<=4'b0000;
end
else
begin
q<=q+1;
end
end
endmodule
b) Asynchronous decade counter:
module decadecounter(q,clk,res);
input clk,res;
output [3:0]q;
reg [3:0]q;
always@(posedge clk)
begin
if(res==1)
begin
q<=4'b0000;
end
else if(q>=4'b1001)
begin
q<=4'b0000;
end
else
begin
q<=q+4'b0001;
end
end
endmodule
c) Ring counter:
module ringcounter(q,clk,res);
input clk,res;
output [3:0]q;
reg [3:0]q;
always@(posedge clk)
begin
if(res==1)
begin
51 | P a g e
DEPT.OF ECE
q<=4'b1000;
end
else
begin
q[3]<=q[0];
q[2]<=q[3];
q[1]<=q[2];
q[0]<=q[1];
end
end
endmodule
d) Johnson counter:
module johnsoncounter(q,clk,res);
input clk,res;
output [3:0]q;
reg [3:0]q;
always@(posedge clk)
begin
if(res==1)
begin
q<=4'b0000;
end
else
begin
q[3]<=~q[0];
q[2]<=q[3];
q[1]<=q[2];
q[0]<=q[1];
end
end
end module
52 | P a g e
DEPT.OF ECE
53 | P a g e
DEPT.OF ECE
EXPERIMENT: 12
IMPLEMENTING THE ABOVE DESIGNS ON FPGA KITS.
AIM: To design and Implementation of FPGA kits.
TOOLS: Mentor Graphics: Pyxis Schematic, Pyxis Layout, Eldo, Ezwave, Calibre
Procedure:
1. Connect the Circuit as shown in the circuit diagram using Pyxis Schematic tool
54 | P a g e