FPGA Observation
FPGA Observation
LABORATORY MANUAL
SEMESTER: VI
1
Institute Vision & Mission
VISION:
MISSION:
To keep pace with advancements in knowledge and make the students competitive and
capable at the global level.
To create an environment for the students to acquire the right physical, intellectual, emotional,
and moral foundations and shine as torch bearers of tomorrow's society.
To strive to attain ever-higher benchmarks of educational excellence
VISION:
To develop highly skilled and globally competent professionals in the field of Electronics and
Communication Engineering to meet industrial and social requirements with ethical responsibility
MISSION:
2
PROGRAM OUTCOMES (POs)
• To have the capability to understand and adopt to technological advancements with the usage of
modern tool to analyze and design embedded system or processes for variety of applications.
• To work effectively in a group as an independent visionary, team member and leader having the
ability to understand the requirement and develop feasible solutions to emerge as potential core or
electronic engineer.
• To Produce Graduates to excel in the profession, higher education and pursue research exercises in
Electronics and Communication Engineering.
• To create technically able alumni with the capacity to examine, plan, create and execute Electronics
and Communication frameworks thereby involving in deep rooted learning.
4
Introduction to HDL
An HDL is a programming language used to describe electronic circuit essentially digital logic circuits. It
can be used to describe the operation, design and organization of a digital circuit. It can also be used to
verify the behaviour by means of simulations. The principle difference between HDL and other
programming languages is that HDL is a concurrent language whereas the others are procedural i.e. single
threaded. HDL has the ability to model multiple parallel processes like adders, flip-flops etc which execute
automatically and independently of each other. It is like building many circuits that can operate
independently of each other.
The two widely used HDLs are:
VHDL: Very High Speed Integrated Circuits HDL
Verilog HDL
VHDL (VHSIC Hardware Description Language) is a hardware description language used in electronic
design automation to describe digital and mixed-signal systems such as field-programmable gate arrays and
integrated circuits. VHDL can also be used as a general purpose parallel programming language.
Verilog, standardized as IEEE 1364, is a hardware description language (HDL) used to model electronic
systems. It is most commonly used in the design and verification of digital circuits at the register-transfer
level of abstraction. It is also used in the verification of analog circuits and mixed-signal circuits, as well as
in the design of genetic circuits.
2. Design Synthesis – next step in the design process is to transform design specification into a more
suitable representation that can be further processed in the later stages in the design flow. This
representation is called the netlist. Prior to netlist creation synthesis tool checks the model syntax and
analyse the hierarchy of your design which ensures that your design is optimized for the design
architecture you have selected. The resulting netlist is saved to a Native Generic Circuit (NGC) file (for
Xilinx® Synthesis Technology (XST) compiler) or an Electronic Design Interchange Format (EDIF) file
(for Precision, or Synplify/Synplify Pro tools).
3. Design Implementation
Implementation step maps netlist produced by the synthesis tool onto particular device's internal
structure. It consists from three steps:
3.1 Translate step – merges all incoming netlists and constraints into a Xilinx Native Generic
Database (NGD) file.
5
3.2 Map step - maps the design, specified by an NGD file, into available resources on the target FPGA
device, such as LUTs, Flip-Flops, BRAMs,... As a result, an Native Circuit Description (NCD) file is
created.
3.3 Place and Route step - takes a mapped Native Circuit Description (NCD) file, places and routes
the design, and produces an NCD file that is used as input for bit stream generation.
4. Design Verification – is very important step in design process. Verification is comprised of seeking
out problems in the HDL implementation in order to make it compliant with the design specification. A
verification process reduces to extensive simulation of the HDL code. Design Verification is usually
performed using two approaches: Simulation and Static Timing Analysis.
Timing Simulation – allows you to check does the implemented design meet all functional and timing
requirements and behaves as you expected. The timing simulation uses the detailed information about
the signal delays as they pass through various logic and memory components and travel over
connecting wires. Using this information it is possible to accurately simulate the behaviour of the
implemented design. This type of simulation is performed after the design has been placed and routed
for the target PLD, because accurate signal delay information can now be estimated. A process of
relating accurate timing information with simulation model of the implemented design is called Back-
Annotation.
Static Timing Analysis – helps you to perform a detailed timing analysis on mapped, placed only or
placed and routed FPGA design. This analysis can be useful in evaluating timing performance of the
logic paths, especially if your design doesn't meet timing requirements. This method doesn't require any
type of simulation.
5. Generate Programming File – this option runs BitGen, the Xilinx bitstream generation program, to create
a bitstream file that can be downloaded to the device.
6
6. Programming – iMPACT Programmer uses the output from the Generate Programming File process to
configure your target device.
7. Testing – after configuring your device, you can debug your FPGA design using the Xilinx ChipScope Pro
tool or some external logic analyzer.
8. Estimate Power – after implementation, you can use the XPower Analyzer for estimation and power
analysis. XPower Analyzer is delivered with ISE Design Suite. With this tool you can estimate power,
based on the logic and routing resources of the actual design.
Xilinx ISE (Integrated Synthesis Environment) is a software tool produced by Xilinx for synthesis
and analysis of HDL designs, enabling the developer to synthesize ("compile") their designs, perform timing
analysis, examine RTL diagrams, simulate a design's reaction to different stimuli, and configure the target
device with the programmer.
Xilinx ISE is a design environment for FPGA(Field programmable gate arrays) products from
Xilinx, and is tightly-coupled to the architecture of such chips, and cannot be used with FPGA products
from other vendors. The Xilinx ISE is primarily used for circuit synthesis and design, while ISIM or the
ModelSim logic simulator is used for system-level testing
a) Select VERILOG MODULE as the source type in the New Source dialog box.
7
b) Type in the file name for ex: and_gate
d) Click Next.
e) Define the ports for your Verilog source.
In the Port Name column, type the port names on three separate rows: A, B and C.
In the Direction column, indicate whether each port is an input, output, or inout.
For A and B, select in from the list. For C, select out from the list.
6) Click Finish in the New Source Information dialog box to complete the new source file template. Click
Next in the New Project Wizard. Click next again.
ISE creates and displays the new project in the Sources in Project window and adds the and_gate.v file
to the project.
8) Double-click on the and_gate.v file in the Sources in Project window to open the Verilog file in the ISE
Text Editor.
The and_gate.v file contains:
Module name with the inputs and outputs declared.
9) Add the relationship between input and output after the input and output declared in module. Save the
file by selecting File > Save.
10) When the source files are complete, the next step is to check the syntax of the design. Syntax
errors and typos can be found using this step.
a) Select the counter design source in the ISE Sources window to display the related processes
in the Processes for Source window.
b) Click the “+”next to the Synthesize-XST process to expand the hierarchy.
c) Double-click the Check Syntax process.
11) When an ISE process completes, you will see a status indicator next to the process name.
a) If the process completed successfully, a green check mark appears.
b) If there were errors and the process failed, a red X appears.
c) A yellow exclamation point means that the process completed successfully, but some Warnings
occurred.
d) An orange question mark means the process is out of date and should be run again.
e) Look in the Console tab of the Transcript window and read the output and status messages
produced by any process that you run.
Caution! You must correct any errors found in your source files. If you continue without valid
syntax, you will not be able to simulate or synthesize your design.
12) After the successful check syntax in the process Examine RTL diagrams.
13) To Create Testbench waveform, Right click on file name in source window, and_gate.v and add source.
14) Add testbench waveform source with a new file name and click next.
8
15) A timing window pops up. Click on combinatorial and click next.
16) A graphical window of input and output appears. Make changes according to the truth table and save.
19) In process window click on Xilix ISE simulator and RUN. Output window appears. Analyze the
waveforms according to the truth table.
20) Double-click the Assign Package Pins process found in the User Constraints process group. ISE runs the
Synthesis and Translate step and automatically creates a User Constraints File(UCF). You will be prompted
with the following message.
22) Now the Xilinx Pin out and Area Constraints Editor (PACE) opens.
23) You can see your I/O Pins listed in the Design Object List window. Enter a pin location for each pin in
the Loc column as specified below
A: P1, B:P2, C:P3
24) Click on the Package View tab at the bottom of the window to see the pins you just added. Put
your mouse over grid number to verify the pin assignment.
This section provides simple instructions for configuring a Spartan-3 xc3s200 device connected to your PC.
Note: Your board must be connected to your PC before proceeding. If the device on your board does not
match the device assigned to the project, you will get errors. Please refer to the IMPACT Help for more
information. To access the help, select Help > Help Topics
To configure the device:
1. Click the “+” sign to expand the Generate Programming File processes.
5. If you get a message saying that there was one device found, click OK to continue
10
6. The iMPACT will now show the detected device, right click the device and select New Configuration
File.
7. The Assign New Configuration File dialog box appears. Assign a configuration file to each device in the
JTAG chain. Select the andgate.jed file and click Open
8. Right-click on the counter device image, and select Program... to open the Program Options dialog box.
9. Click OK to program the device. ISE programs the device and displays Programming Succeeded if the
operation was successful
10. Close IMPACT without saving
11
12
FPGA Based System design Lab Using Verilog
1. Write a Verilog description for the following combinational logic, verify the design using Verilog
test bench and perform the synthesis by downloading the design on to FPGA device.
a. Structural modeling of Full adder using two half adders and or Gate
b. BCD to Excess-3 code converter
2. Write a Verilog description for the following Sequential Circuits, Verify the design using Verilog
test bench and perform the synthesis by downloading the design on to FPGA device.
a. Mod-N counter
b. Random sequence counter
3. Write a Verilog description for the following Sequential Circuits, Verify the design using Verilog
test bench and perform the synthesis by downloading the design on to FPGA device.
a. SISO and PISO shift register
b. Ring counter
4. Write a Verilog description for the following Digital Circuits, Verify the functionality using Verilog
test bench and perform the synthesis by downloading the design on to FPGA device.
a. 4-Bit Ripple Carry Adder
b. 4-Bit Linear Feedback shift register
5. Write a Verilog description for the following Digital Circuits, Verify the functionality using Verilog
test bench and perform the synthesis by downloading the design on to FPGA device.
a. 4-bit Array Multiplication
b. 4-bit Booth Multiplication@12112024
6. Write a Verilog description to design a clock divider circuit that generates 1/2, 1/3rd and 1/4th clock
from a given input clock. Port the design to FPGA and validate the functionality using output device.
7. Interface a Stepper motor to FPGA and Write a Verilog description to control Stepper motor
rotation.
8. Interface a DAC to FPGA and Write a Verilog description to generate Square wave of frequency F
KHz. Modify the code to down sample the frequency to F/2 KHz. Display the original and down
sampled signals by connecting them to an output device.
9. Write a Verilog description to convert an analog input of a sensor to digital form and to display the
same on a suitable display like set of simple LEDs like 7-Segment display digits.
13
FPGA Based System design Lab Using Verilog
1. Write a Verilog description for the following combinational logic, verify the design using Verilog
test bench and perform the synthesis by downloading the design on to FPGA device.
a. Structural modeling of Full adder using two half adders and or Gate
b. BCD to Excess-3 code converter
2. Write a Verilog description for the following Sequential Circuits, Verify the design using Verilog
test bench and perform the synthesis by downloading the design on to FPGA device.
a. Mod-N counter
b. Random sequence counter
3. Write a Verilog description for the following Sequential Circuits, Verify the design using Verilog
test bench and perform the synthesis by downloading the design on to FPGA device.
a. SISO and PISO shift register
b. Ring counter
Cycle - 2
4. Write a Verilog description for the following Digital Circuits, Verify the functionality using Verilog
test bench and perform the synthesis by downloading the design on to FPGA device.
a. a.4-Bit Ripple Carry Adder
b. 4-Bit Linear Feedback shift register
5. Write a Verilog description for the following Digital Circuits, Verify the functionality using Verilog
test bench and perform the synthesis by downloading the design on to FPGA device.
a. 4-bit Array Multiplication
b. 4-bit Booth Multiplication@12112024
6. Write a Verilog description to design a clock divider circuit that generates 1/2, 1/3rd and 1/4th clock
from a given input clock. Port the design to FPGA and validate the functionality using output device.
Cycle - 3
7. Interface a Stepper motor to FPGA and Write a Verilog description to control Stepper motor
rotation.
8. Interface a DAC to FPGA and Write a Verilog description to generate Square wave of frequency F
KHz. Modify the code to down sample the frequency to F/2 KHz. Display the original and down
sampled signals by connecting them to an output device.
9. Write a Verilog description to convert an analog input of a sensor to digital form and to display the
same on a suitable display like set of simple LEDs like 7-Segment display digits.
14
DETAILS OF ON BOARD CONNECTIONS AND SPARTAN – 3 IC
Signal CN9 Connection XC3S50 - SPARTAN
AN1 PIN 5 PIN 2
AN2 PIN 6 PIN 3
AN3 PIN 7 PIN 7
AN4 PIN 8 PIN 9
Signal CN12 Connection XC3S50 - SPARTAN
AN5 PIN 37 PIN 166
AN6 PIN 38 PIN 167
Signal CN9 Connection XC3S50 - SPARTAN
SEG 1/RS PIN 9 PIN 10
SEG 2/RW PIN 10 PIN 11
SEG 3/EI PIN 11 PIN 12
SEG 4/DT0 PIN 12 PIN 13
SEG 4/DT1 PIN 13 PIN 15
SEG 4/DT2 PIN 14 PIN 16
SEG 4/DT3 PIN 15 PIN 18
SEG 8 PIN 16 PIN 19
IN 1 PIN 20 PIN 21
IN 2 PIN 22 PIN 27
IN 3 PIN 24 PIN 29
IN 4 PIN 26 PIN 35
IN 5 PIN 28 PIN 37
IN 6 PIN 30 PIN 40
IN 7 PIN 32 PIN 43
IN 8 PIN 34 PIN 45
IN 9 PIN 36 PIN 48
IN 10 PIN 38 PIN 52
Signal CN10 Connection XC3S50 - SPARTAN
IN 11 PIN 6 PIN 58
IN 12 PIN 8 PIN 62
IN 13 PIN 10 PIN 64
IN 14 PIN 12 PIN 67
IN 15 PIN 14 PIN 71
IN 16 PIN 16 PIN 74
IN 17 PIN 24 PIN 58
IN 18 PIN 26 PIN 62
IN 19 PIN 28 PIN 64
IN 20 PIN 30 PIN 67
IN 21 PIN 32 PIN 71
IN 22 PIN 34 PIN 74
IN 23 PIN 36 PIN 74
Signal CN11 Connection XC3S50 - SPARTAN
IN 24 PIN 4 PIN 107
IN 25 PIN 6 PIN 113
IN 26 PIN 8 PIN 115
15
IN 27 PIN 10 PIN 117
IN 28 PIN 12 PIN 120
IN 29 PIN 14 PIN 123
IN 30 PIN 16 PIN 125
IN 31 PIN 18 PIN 131
IN 32 PIN 20 PIN 133
Signal CN9 Connection XC3S50 - SPARTAN
OPLED 1 PIN 19 PIN 20
OPLED 2 PIN 21 PIN 26
OPLED 3 PIN 23 PIN 28
OPLED 4 PIN 25 PIN 34
OPLED 5 PIN 27 PIN 36
OPLED 6 PIN 29 PIN 39
OPLED 7 PIN 31 PIN 42
OPLED 8 PIN 33 PIN 44
OPLED 9 PIN 35 PIN 46
OPLED 10 PIN 37 PIN 51
Signal CN10 Connection XC3S50 - SPARTAN
OPLED 11 PIN 5 PIN 57
OPLED 12 PIN 7 PIN 61
OPLED 13 PIN 9 PIN 63
OPLED 14 PIN 11 PIN 65
OPLED 15 PIN 13 PIN 68
OPLED 16 PIN 15 PIN 72
OPLED 17 PIN 23 PIN 78
OPLED 18 PIN 25 PIN 81
OPLED 19 PIN 27 PIN 85
OPLED 20 PIN 29 PIN 87
OPLED 21 PIN 31 PIN 93
OPLED 22 PIN 33 PIN 95
OPLED 23 PIN 35 PIN 101
Signal CN11 Connection XC3S50 - SPARTAN
OPLED 24 PIN 3 PIN 44
OPLED 25 PIN 5 PIN 46
OPLED 26 PIN 7 PIN 51
OPLED 27 PIN 9 PIN 36
OPLED 28 PIN 11 PIN 39
OPLED 29 PIN 13 PIN 42
OPLED 30 PIN 15 PIN 44
OPLED 31 PIN 17 PIN 46
OPLED 32 PIN 19 PIN 51
10MHzCLK PIN 18 PIN 79
CLK1 PIN 19 PIN 76
CLK2 PIN 20 PIN 77
GREEN_E PIN 23 PIN 187
RED_E PIN 24 PIN 185
16
GREEN_S PIN 25 PIN 184
RED_S PIN 27 PIN 183
GREEN_W PIN 28 PIN 194
RED_W PIN 29 PIN 191
Hexa Keypad & Seven Segment
Gnerator of waveform (UCF) Elevator (UCF)
Display (UCF)
NET"clk"LOC="p79" NET"clk"LOC="p79" NET"pclk"LOC="p79"
NET"disp<0>"LOC="p10" NET"rst"LOC="p21" NET"pdspseg<0>"LOC="p176"
NET"disp<1>"LOC="p11" NET"dout<0>"LOC="p187" NET"pdspseg<1>"LOC="p176"
NET"disp<2>"LOC="p12" NET"dout<1>"LOC="p185" NET"pdspseg<2>"LOC="p176"
NET"disp<3>"LOC="p13" NET"dout<2>"LOC="p190" NET"pdspseg<3>"LOC="p176"
NET"disp<4>"LOC="p15" NET"dout<3>"LOC="p189" NET"fircal<0>"LOC="p183"
NET"disp<5>"LOC="p16" NET"dout<4>"LOC="p194" NET"fircal<1>"LOC="p184"
NET"disp<6>"LOC="p18" NET"dout<5>"LOC="p191" NET"fircal<2>"LOC="p181"
NET"disp_ent<0>"LOC="p2" NET"dout<6>"LOC="p197" NET"fircal<3>"LOC="p182"
NET"disp_ent<1>"LOC="p3" NET"dout<7>"LOC="p196" NET"crnt_fir<0>"LOC="p189"
NET"disp_ent<2>"LOC="p7" STEPPER MOTOR (UCF) NET"crnt_fir<1>"LOC="p190"
NET"disp_ent<3>"LOC="p9" NET"clk"LOC="p79" NET"crnt_fir<2>"LOC="p185"
NET"read_1_in<3>"LOC="p147" NET"rst"LOC="p21" NET"crnt_fir<3>"LOC="p187"
NET"read_1_in<2>"LOC="p146" NET"dir"LOC="p29" DC MOTOR (UCF)
NET"read_1_in<1>"LOC="p144" NET"dout<0>"LOC="p169" NET"clk"LOC="p79"
NET"read_1_in<0>"LOC="p143" NET"dout<1>"LOC="p175" NET"pdcm"LOC="p203"
NET"cscan<3>"LOC="p141" NET"dout<2>"LOC="p176" NET"psw<0>"LOC="p21"
NET"cscan<2>"LOC="p140" NET"dout<3>"LOC="p178" NET"psw<1>"LOC="p27"
NET"cscan<1>"LOC="p139" Clock devider NET"psw<2>"LOC="p29"
NET"cscan<0>"LOC="p138" NET"clk"LOC="p79" CN - 10
NET"new_clk"LOC="p57" 5
NET"clk_by_2"LOC="p61" 7
NET"clk_by_3"LOC="p63" 9
NET"clk_by_4"LOC="p65" 11
17
18
Experiment 1a:
Logic Diagram:
Figure 1.1: Logic Diagram for Full Adder Using Two Half Adders
Truth Table:
INPUTS OUTPUTS
19
Date:
Experiment-1: Write a Verilog description for the following combinational logic, verify the design
using Verilog test bench and perform the synthesis by downloading the design on to FPGA device.
a. Structural modeling of Full adder using two half adders and or Gate
b. BCD to Excess-3 code converter
Objective: To verify and synthesize the structural modeling of Full adder and BCD Excess-3 Code
Converter using FPGA
21
.Sum(S),
.Carry(carry2)
);
22
Experiment-1b
Truth Table:
INPUTS OUTPUTS
23
Experiment 1b: BCD To Excess-3 Converter
Outcome:
24
Test Bench Waveform for BCD to Excess 3 Code Converters:
25
26
Experiment-2A:
27
Date:
Exepriment-2: Write a Verilog description for the following Sequential Circuits, Verify the design
using Verilog test bench and perform the synthesis by downloading the design on to FPGA device.
a. Mod-N counter
b. Random sequence counter
Objective: To verify and synthesize the structural modeling of Mod-N Counter and Random Sequence
Counter using FPGA.
module mod_n_counter (
input wire clk, // System clock
input wire reset, // Asynchronous reset
output reg [3:0] count // 4-bit counter output (can be adjusted for higher Mod-N)
);
// Parameter for the modulus (N)
parameter N = 16; // Change this for different Mod-N (e.g., 10 for Mod-10)
// Clock enable
reg clk_1Hz_en;
// Mod-N counter
28
Experiment-2B:
29
always @(posedge clk or posedge reset) begin
if (reset) begin
count <= 0;
end else if (clk_1Hz_en) begin
if (count == (N - 1)) begin
count <= 0; // Reset to 0 when reaching N
end else begin
count <= count + 1; // Increment counter
end
end
end
endmodule
User Constraint File (UCF):
2. module random_sequence_generator (
input wire clk, // System clock (e.g., 50 MHz)
input wire reset, // Asynchronous reset
output reg [3:0] rand_out // 4-bit random output
);
endmodule
Outcome:
32
Experiment-3:
33
Date:
Experiment-3: Write a Verilog description for the following Sequential Circuits, Verify the design
using Verilog test bench and perform the synthesis by downloading the design on to FPGA device.
a. SISO and PISO shift register
b. Ring counter
Objective: To verify and synthesize SISO, PISO and Ring Counter using FPGA Counter.
3A. SISO (Serial in Serial Out) Shift Register
module siso_shift_register (
input clk, // Clock signal
input reset, // Asynchronous reset
input serial_in, // Serial data input
output reg serial_out // Serial data output
);
reg [7:0] shift_reg; // 8-bit shift register (can adjust the size based on requirement)
endmodule
User Constraint File (UCF):
34
Truthtable for Ring Counter:
35
3A. PISO (Parallel in Serial Out) Shift Register
module piso_shift_register (
input clk, // Clock signal
input reset, // Asynchronous reset
input [7:0] parallel_in, // 8-bit parallel data input
input shift_enable, // Enable signal to shift
output reg serial_out // Serial data output
);
reg [7:0] shift_reg; // 8-bit shift register (can adjust the size based on requirement)
endmodule
36
37
3B. Ring Counter
module ring_counter (
input clk, // Clock signal
input reset, // Asynchronous reset
output reg [3:0] q // 4-bit output (can adjust the width as needed)
);
endmodule
Outcome:
38
Experiment-4A
Logic Diagram
39
Date:
Experiment-4: Write a Verilog description for the following Digital Circuits, Verify the functionality
using Verilog test bench and perform the synthesis by downloading the design on to FPGA device.
A. 4-Bit Ripple Carry Adder
B. 4-Bit Linear Feedback shift register
A Ripple Carry Adder (RCA) adds two binary numbers bit by bit, where each sum bit depends on the carry
from the previous stage.
module ripple_carry_adder (
input [3:0] A, // 4-bit input A
input [3:0] B, // 4-bit input B
input Cin, // Carry-in (initial carry)
output [3:0] Sum, // 4-bit sum
output Cout // Carry-out
);
wire c1, c2, c3; // Internal carry signals
// First bit (LSB)
full_adder FA0 (
.A(A[0]),
.B(B[0]),
.Cin(Cin),
.Sum(Sum[0]),
.Cout(c1)
);
// Second bit
full_adder FA1 (
.A(A[1]),
.B(B[1]),
.Cin(c1),
.Sum(Sum[1]),
.Cout(c2)
40
41
);
// Third bit
full_adder FA2 (
.A(A[2]),
.B(B[2]),
.Cin(c2),
.Sum(Sum[2]),
.Cout(c3)
);
42
Experiment-4B
Logic Diagram
43
4B. 4-Bit Linear Feedback Shift Register (LFSR)
module lfsr_4bit (
input clk, // Clock signal
input reset, // Asynchronous reset
output reg [3:0] q // 4-bit LFSR output
);
always @(posedge clk or posedge reset) begin
if (reset) begin
q <= 4b1001; // Initial seed value (non-zero) for LFSR
end else begin
// Feedback polynomial: x^4 + x^3 + 1 (Feedback taps at positions 4 and 3)
q <= {q [2:0], q [3] ^ q [2]}; // Shift left and feedback XOR between bit 3 and bit 2
end
end
endmodule
Outcome
44
Experiment-5A
Logic Diagram:
45
Date
Experiment-5: Write a Verilog description for the following Digital Circuits, Verify the functionality
using Verilog test bench and perform the synthesis by downloading the design on to FPGA device.
A. 4-bit Array Multiplication
B. 4-bit Booth Multiplication
Objective: To verify and Synthesize 4-bit Array multiplier and Booth Multiplier using FPGA.
module array_multiplier (
input [3:0] A, // 4-bit input A
input [3:0] B, // 4-bit input B
output [7:0] Product // 8-bit output product
);
// Internal wires to hold partial products
wire [3:0] p0, p1, p2, p3;
Outcome:
48
Experiment-6:
49
Date:
Experiment-6: Write a Verilog description to design a clock divider circuit that generates 1/2, 1/3rd and
1 th
/4 clock from a given input clock. Port the design to FPGA and validate the functionality using
output device.
module clock_divider (
input clk, // Input clock signal
input reset, // Reset signal
output reg clk_div2, // Output clock divided by 2
output reg clk_div3, // Output clock divided by 3
output reg clk_div4 // Output clock divided by 4
);
50
51
// Dividing the input clock by 4
always @(posedge clk or posedge reset) begin
if (reset) begin
counter4 <= 3b000; // Reset the counter for 1/4 clock
clk_div4 <= 0; // Reset output clock
end else begin
counter4 <= counter4 + 1b1; // Increment counter
if (counter4 == 3b011) begin
clk_div4 <= ~clk_div4; // Toggle output clock when counter reaches 4
end
end
end
endmodule
Outcome:
52
Experiment-7:
53
Experiment-7: Interface a Stepper motor to FPGA and Write a Verilog description to control Stepper
motor rotation.
54
55
end else begin
// Time to move to the next step
counter <= 0;
Outcome:
56
Experiment-8:
57
Date:
Experiment-8: Interface a DAC to FPGA and Write a Verilog description to generate Square wave of
frequency F KHz. Modify the code to down sample the frequency to F/2 KHz. Display the original
and down sampled signals by connecting them to an output device.
Objective: To interface a DAC (Digital-to-Analog Converter) to an FPGA and generate a square wave
signal of frequency F kHz.
module square_wave_generator (
input clk, // Input FPGA clock (high-frequency clock)
input reset, // Reset signal to initialize counters
input [31:0] F_kHz, // Target frequency in kHz (F kHz)
output reg square_wave, // Square wave signal at frequency F kHz
output reg downsampled_square_wave // Downsampled square wave signal at F/2 kHz
);
// Internal counters for square wave generation
reg [31:0] counter; // General purpose counter
reg [31:0] counter_downsampled; // Counter for downsampled signal
// Clock divider values to achieve desired frequencies
parameter FPGA_CLOCK = 50000000; // Example: 50 MHz FPGA clock (replace with your FPGA clock
frequency)
// calculate the division factor for F kHz (based on FPGA clock frequency)
always @(posedge clk or posedge reset) begin
if (reset) begin
counter <= 0;
counter_downsampled <= 0;
square_wave <= 0;
downsampled_square_wave <= 0;
freq_divide_factor <= FPGA_CLOCK / (F_kHz 1000); // Divide FPGA clock by desired square wave
frequency
end else begin
// Generate the square wave at F kHz
if (counter >= (freq_divide_factor / 2)) begin
58
59
square_wave <= ~square_wave; // Toggle square wave signal
counter <= 0; // Reset counter after toggling
end else begin
counter <= counter + 1;
end
module pin_assignment (
input square_wave,
input downsampled_square_wave,
output led_square_wave,
output led_downsampled_square_wave
);
60
61
Date:
Experiment-9: Write a Verilog description to convert an analog input of a sensor to digital form and
to display the same on a suitable display like set of simple LEDs like 7-Segment display digits.
Objective: To interface an ADC to FPGA to convert an analog input of a sensor to digital form and to
display the same on a suitable display
module seven_segment_decoder (
input [3:0] digit, // 4-bit input digit (0-15)
output reg [6:0] seg // 7-segment display output (a-g)
);
always @(digit) begin
case (digit)
4'd0: seg = 7'b1111110; // 0
4'd1: seg = 7'b0110000; // 1
4'd2: seg = 7'b1101101; // 2
4'd3: seg = 7'b1111001; // 3
4'd4: seg = 7'b0110011; // 4
4'd5: seg = 7'b1011011; // 5
4'd6: seg = 7'b1011111; // 6
4'd7: seg = 7'b1110000; // 7
62
4'd8: seg = 7'b1111111; // 8
4'd9: seg = 7'b1111011; // 9
4'd10: seg = 7'b1110111; // A
4'd11: seg = 7'b0011111; // b
4'd12: seg = 7'b1001110; // C
4'd13: seg = 7'b0111101; // d
4'd14: seg = 7'b1001111; // E
4'd15: seg = 7'b1000111; // F
default: seg = 7'b0000000; // Default: Blank
endcase
end
endmodule
// Extract digits from the 10-bit ADC data (divide it into 4 digits)
assign digit1 = adc_data[9:8]; // Most significant digit (MSD)
assign digit2 = adc_data[7:4]; // 2nd digit
assign digit3 = adc_data[3:2]; // 3rd digit
assign digit4 = adc_data[1:0]; // Least significant digit (LSD)
Outcome:
64