Lab2 Digital Design
Lab2 Digital Design
Lab2 Digital Design
OBJECTIVES
➢ Getting to know how to describe finite state machine (FSM) using variety styles of System
Verilog code (logic expressions/ behavioral expressions/ shift registers).
➢ Design and implement digital circuits using FSM.
➢ Download the circuit into the FPGA chip and test its functionality.
REFERENCE
1. Intel FPGA training
Requirement: Implement a FSM that recognizes two specific sequences of applied input symbols,
namely four consecutive 1s or four consecutive 0s. There is an input w and an output z. Whenever
w = 1 or w = 0 for four consecutive clock pulses the value of z has to be 1; otherwise, z = 0.
Overlapping sequences are allowed, so that if w = 1 for five consecutive clock pulses the output z
will be equal to 1 after the fourth and fifth pulses.
Figure 1 illustrates the required relationship between w and z. And the state diagram for this FSM
is shown in Figure 2.
Instruction:
Students derive an FSM circuit that implements this state diagram, including the logic expressions
that feed each of the state flip-flops. Using 9 state flip-flops called y8, …, y0 and the one-hot state
assignment given in Table 1.
Figure 2: A state diagram for the FSM Table 1: One-hot codes for the FSM
Requirement: Implement the FSM given in experiment 1, using another style of System Verilog
code. Use a Verilog CASE statement in a ALWAYS block, and use another ALWAYS block to
instantiate the state flip-flops. You can use a third ALWAYS block or simple assignment
statements to specify the output z. To implement the FSM, use four state flip-flops y3, . . .
, y0 and binary codes, as shown in Table 3.
Instruction:
Examine the circuit produced by Quartus open the RTL Viewer tool. Double-click on the
box shown in the circuit that represents the finite state machine, and determine whether the
state diagram that it shows properly corresponds to the one in Figure 2.
To see the state codes used for your FSM: open the Compilation Report → Analysis and
Synthesis section → State Machines.
5. Download the circuit into the FPGA chip and test its functionality.
6. Change the setting for State Machine Processing from User_Encoded to One-Hot.
Recompile the circuit and then open the report file, select the Analysis and Synthesis
Requirement: Create System Verilog code that instantiates two 4-bit shift registers; one is for
recognizing a sequence of four 0s, and the other for four 1s. Include the appropriate logic
expressions in your design to produce the output z.
Shift Register 1s
w Combinational z
circuit
Shift Register 0s
Instruction:
Requirement: The Morse code uses patterns of short and long pulses to represent a message. Each
letter is represented as a sequence of dots (a short pulse), and dashes (a long pulse). For example,
the first eight letters of the alphabet have the following representation:
A•—
B—•••
C—•—•
D—••
E•
F••—•
G——•
H••••
Design and implement a Morse-code encoder circuit using an FSM. The circuit take as input one
of the first eight letters of the alphabet and display the Morse code for it on LEDs.
A high-level schematic diagram of a possible circuit for the Morse-code encoder is shown in Figure
5.
/******************************************************************/
/**** DECLARATIONS ****/
/******************************************************************/
/* Letter selection */
always @(*)
case (SW)
A_SW: begin morse_code = … ; morse_length = … ; end
…
…
endcase
/* Store the Morse code to be sent in a shift register, and its length in a counter */
always@(posedge CLOCK_50)
begin
/* if Reset = 0 then data = size = 0; otherwise, if load = 1 then data = morse_code and size =
morse_length; if shift = 1 then data[2:0]= data[3:1]) & data[3] = 1'b0 and size = size – 1’b1 */
endmodule
module modulo_counter(…);
…
endmodule