Professional Documents
Culture Documents
(ELE654)
LAB REPORT
Prepared by:
Name UiTM NO Group
AMMAR HAFIFFI BIN MOHAMAD ISA 2016479802 EE241E7A
Assessment:
Assessment Marks
Title
Objective
Literature Review
Methodology
Results & Discussion
Conclusion
Appendix
Total Marks
a) To write the testbench’s Verilog code for a sequential module and simulate using
Modelsim.
b) To write the Verilog code of a FSM module and implement the design on FPGA board.
2
INPUT OUTPUT
S R Q ̅Q̅
0 0 Invalid
0 1 0 1
1 0 1 0
1 1 Invalid
Table 1 : Truth Table of SR Latch
S Q
LATCH
̅Q
R
The truth table of half adder above shows all the possible inputs and its resulting
outputs.To avoid having invalid states, the latch can be reconfigured to be a D latch where
R input is replaced with clock. This will enable opaque and transparent states.
b) Flip Flop :
3
There are several different types of flip-flop each with its own uses and
peculiarities. The four main types of flip-flop are : SR, JK, D, and T.
CLK
D FLIP FLOP S
RST
4
3.0 METHODOLOGY :
Start
Specifications
Behaviour
Truth Table
Logic Circuit
Implementation
5
Flowchart above is the Design Flow used to design logic gates or modules such as adders,
demultiplexers, priority decoders, multiplexers from scratch untila verilog code is constructed and
test bench is simulated.This acts as a guideline for us to create, troubleshoot or debug any logic
gate or module.
2. Specification :
o Block Diagram :
6
3. Behavior :
o Tc = 10T, tsetup = 4T and thold = 6T.
o 4 bit inputs at positive clock edge (posedge).
o Data from input changes at every negative clock edge (negedge).
o Asynchronous sequential behaviour.
o If rst = 0, then Y0 = D0, Y1 = D1, Y2 = D2, Y3 = D3.
4. Truth Table :
INPUT OUTPUT
rst clk Y3 Y2 Y1 Y0
0 D3 D2 D1 D0
1 0
5. Implementation :
o Verilog :
7
o Testbench
8
9
Figure 5 : The Verilog code for Testbench
10
o Synthesized RTL viewer.
11
o Testbench model for sequential module
o Timing Diagram
12
o Output waveform generated from Modelsim
13
b) EXPERIMENT 2 : DESIGN AND SIMULATION OF A FSM MODULE
2. Specification :
o Block Diagram :
3. Behavior :
o when SW2(clock) is toggled, data will change.
o when SW3(reset) is toggled, the LEDR0 switch ON. (initial ground position)
o when SW0(down) is toggled, the LEDR0 switch ON. (wait clock toggle)
o when SW1(up) is toggled, the LEDG0 switch ON. (wait clock toggle)
14
4. Truth Table :
15
o State Output Table
CURRENT OUTPUT (LED)
STATE (S)
RED GREEN
Groundfloor ON OFF
Firstfloor OFF ON
5. Expression :
Simplified expressions for Next State Combinational Logic:
So’ = So (Input) + So(Input).
16
6. Logic Circuit :
o Output Combinational Logic
17
7. Implementation :
o Verilog :
18
o Synthesized RTL viewer
o Pin Assignment :
19
5.0 DISCUSSION :
EXPERIMENT 1 :
When reset is not triggered, it is set up in the verilog code that the output will follow the
input values. However, the data from inputs only transferred to outputs in the positive clock edge
of the clock cycle. This is set by the command line “always @ (posedge rst, posedge clk)”. A full
clock cycle is T = 10ns. For positive clock edge is T/2 = 5ns. Next, the Tsetup and Thold is
approximately ±10 % from T at the positive clock edge trigger. At this state the data must be stable.
In the verilog code, a change in data simulation is entered on each clock cycle from “0000” to
“1111”. In a nutshell, experiment 1 is successfully accomplished as generated waveform is
identical with expected timing diagram from design flow.
20
EXPERIMENT 2 :
In Experiment 2, switches which is assigned as input devices and LED as output devices
on FPGA board and are programmed in Quartus Prime Lite software. The Verilog code used for
the DE2-115 board was generated manually by doing the design flow for FSM. The Verilog code
is written into the Quartus software and undergoes compilation to ensure no errors with the code.
Switches SW0 is down, SW1 is up, SW2 is clock, and SW3 is reset. For the output, LEDs LEDR0
is Red 0 for ground floor while LEDG0 is Green 0 for first floor. Each of the pins are individually
assigned in Pin Planner.
Figure 8 : When SW0 = 1, SW1 = 0, SW2 = 1 and SW3 = 0, the LEDR0 is turned ON
Based on the figure above, this is when the ground elevator button (SW0) is pressed. The
data enters and waits for the clock signal (SW2) to produce the output LEDR0 = 1 showing that
the elevator has arrived at ground floor. This is because the data can only be transferred on the
positive clock edge to the outputs.
21
Figure 9: When SW0 = 0, SW1 =1, SW2 = 1 and SW3 = 0, the LEDG0 is turned ON.
Based on the figure above, this is when the first floor elevator button (SW1) is pressed.
The data enters and waits for the clock signal (SW2) to produce the output LEDG0 = 1 showing
that the elevator has arrived at ground floor. This is because the data can only be transferred on
the positive clock edge to the outputs.
22
Figure 10: When SW0 = 0, SW1 =1, SW2 = 1 and SW3 = 1, the LEDR0 is turned ON.
Based on the figure above, this is when the reset elevator button (SW3) is pressed. The data
enters and does not wait for the clock signal (SW2) to produce the output LEDR0 = 1 showing
that the elevator has arrived at ground floor. This is because when the reset button is pressed, the
verilog code resets the current data to LOW, which in this case the initial position of the elevator
(ground floor).
23
6.0 CONCLUSION :
24
7.0 REFERENCES :
[1] Harris , S. L., & Harris, D. M. (2016). Digital Building Blocks. In Digital Design and
Computer Architecture. MA: Elsevier Science & Technology.
[2] Field-programmable gate array (FPGA) – Wikipedia. Retrieved November 10, 2018, from
https://en.wikipedia.org/wiki/Field-programmable_gate_array
25