EGCP 446: Advanced Digital Design: Part One - Moore State Machine On FPGA
EGCP 446: Advanced Digital Design: Part One - Moore State Machine On FPGA
EGCP 446: Advanced Digital Design: Part One - Moore State Machine On FPGA
Introduction
This lab focuses on Finite state machines, Mealy and Moore, and how to verify and prototype them
within Xilinx Vivado. In Lab 4, we take our designs from the previous lab and implement them directly on
the hardware board. We can expect through this lab to implement complex and practical state machines
on FPGAs as well as learn essential Verilog components such as using case statements and if-else blocks.
In a non-exhaustive showcase, I provided the states of the machine at two points of the implementation
below, the first being normal operation (State 3 [0 indexed]) and the second showcasing Reset switch
being toggled setting state back to the first Moore state.
Nate Ruppert 3
I took three pictures for this part of the lab: The first showcases Debouncer toggle with UP not active,
Debouncer toggle with Reset active (sets to state 0), and Debouncer toggle with UP active and reset not
active (moves to next state).
Nate Ruppert 4
Nate Ruppert 5
Conclusion
In completing this lab, both a mealy and moore state machine were created, allowing us to see potential
use cases for both as well as refine our understanding of Verilog with case statements and if-else-else if
blocks. Furthermore, both mealy and moore state machines were implemented on FPGA showcasing
practical implementation and understanding of FPGA IO assignment and live demo capabilities. The
most important takeaway from this lab is furthering our understanding of Verilog and its practical uses
in designing machines in Vivado. As we are now on the third lab, we are improving our understanding of
creating everything required of a Verilog setup, such as a testbench, usage of registers, wires, case
switch, if-else, and many more.
Nate Ruppert 6
References
No references were used for this lab.
Nate Ruppert 7
Appendix
Lab Code
Mealy.v
module mealy(
input CLK,
input RST,
input UP,
output [1:0] Q
);
parameter a = 2'b00;
parameter b = 2'b01;
parameter c = 2'b10;
parameter d = 2'b11;
always @(*)
Nate Ruppert 8
case (STATE)
a:
if (UP) NEXT = b;
else NEXT = d;
b:
if (UP) NEXT = c;
else NEXT = a;
c:
if (UP) NEXT = d;
else NEXT = b;
d:
if (UP) NEXT = a;
else NEXT = c;
endcase
assign Q = STATE;
endmodule
Moore.v
module moore(
input CLK,
input RST,
output [3:0] W
);
parameter S0 = 4'b0001;
Nate Ruppert 9
parameter S1 = 4'b0010;
parameter S2 = 4'b0100;
parameter S3 = 4'b1000;
reg RV;
reg [4:0] STATE, NEXT;
always @(*)
case (STATE)
S0:
NEXT = S1;
S1:
begin
if (RV) NEXT = S0;
else NEXT = S2;
RV = 0;
end
S2:
if (RV) NEXT = S1;
else NEXT = S3;
S3:
begin
NEXT = S2;
RV = 1;
end
endcase
assign W = STATE;
endmodule
Tb_Mealy.v
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module tb_mealy(
);
reg CLK, RST, UP;
wire [1:0] OUT;
mealy UUT(CLK, RST, UP, OUT);
always
begin
CLK = 1;
#20;
CLK = 0;
#20;
end
always
begin
UP = 1;
#200;
UP = 0;
#200;
end
initial
begin
RST = 1;
#60;
RST = 0;
end
endmodule
Tb_Moore.v
// Design Name:
// Module Name: tb_moore
// Project Name:
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module tb_moore(
);
reg CLK, RST;
wire [3:0] OUT;
moore UUT(CLK, RST, OUT);
always
begin
CLK = 1;
#20;
CLK = 0;
#20;
end
initial
begin
RST = 1;
#60;
RST = 0;
end
endmodule
Package
module package(
input Clk,
input Reset,
output [3:0] Q
);
wire clock;
clk_divider div0 (Clk, Reset,clock);
moore moore0 (clock, Reset, Q);
endmodule
Clock_Divider
//////////////////////////////////////////////////////////////////////////////////
module clk_divider(
input Clk,
input Reset,
output reg S_Clk
);
M_Package
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module m_package(
input Clk,
input Btn,
input Reset,
input UP,
output [1:0] Q
);
wire clock;
//clk_divider div0 (Clk, Reset,clock); (test to ensure code works)
Debouncer
module debouncer(
input clk,
input button,
output reg result
);
Constraints