Upload
debanjanbulan
View
223
Download
0
Embed Size (px)
Citation preview
8/4/2019 Fsm Using Hdl
http://slidepdf.com/reader/full/fsm-using-hdl 1/12
Finite State Machines using HDL
● Here we will learn:
– What is a FSM
– What are the major types of FSM
– How to represent a FSM
– Writing RTL of FSM in Verilog
8/4/2019 Fsm Using Hdl
http://slidepdf.com/reader/full/fsm-using-hdl 2/12
8/4/2019 Fsm Using Hdl
http://slidepdf.com/reader/full/fsm-using-hdl 3/12
8/4/2019 Fsm Using Hdl
http://slidepdf.com/reader/full/fsm-using-hdl 4/12
8/4/2019 Fsm Using Hdl
http://slidepdf.com/reader/full/fsm-using-hdl 5/12
8/4/2019 Fsm Using Hdl
http://slidepdf.com/reader/full/fsm-using-hdl 6/12
Each transition edge is labeledwith the value of the input
(shown in red) and the value of
the output (shown in blue).
The machine starts in state Si.
In this example, the output isthe exclusive-or of the two
most-recent input values; thus,
the machine implements an
edge detector, outputting a one
every time the input flips and azero otherwise. More complex
Mealy machines can have
multiple inputs as well as
multiple outputs.
State diagram for a simple Mealy machine with
one input and one output
8/4/2019 Fsm Using Hdl
http://slidepdf.com/reader/full/fsm-using-hdl 7/12
8/4/2019 Fsm Using Hdl
http://slidepdf.com/reader/full/fsm-using-hdl 8/12
Input values are in red;
output values are in blue.
The machine starts in state
Si. In this example, the
output is the XOR of the
two most-recent inputvalues; thus, the machine
implements an edge
detector, outputting a one
every time the input flips
and a zero otherwise. Morecomplex Moore machines
can have multiple inputs as
well as multiple outputs.
State diagram for a simple Moore machine with
one input and one output
8/4/2019 Fsm Using Hdl
http://slidepdf.com/reader/full/fsm-using-hdl 9/12
8/4/2019 Fsm Using Hdl
http://slidepdf.com/reader/full/fsm-using-hdl 10/12
module evenOdd(o1, i1, clk, rst);
// Declare unique states
parameter s1 = 0;
parameter s2 = 1;
// Input/Output declarations
output o1;
input i1;
input clk, rst;
reg o1;
// Declare the state variable
reg state;
// Body of the FSM
….
….
endmodule
// Body of the Moore FSM
always @(posedge clk ) begin
// Reset logic
if (rst) begin
state <= s1;
o1 <= 0;end
// State transition and output logic
else begin
case (state)
// 'Even' state
s1: begin
// Output logic
o1 <= 0;
// State transition logic
if (i1) begin
state <= s2;
end
end
// 'Odd' state
s2: begin
// Output logic
o1 <= 1; // State transition logic
if (i1) begin
state <= s1;
end
end
endcase
end
end
8/4/2019 Fsm Using Hdl
http://slidepdf.com/reader/full/fsm-using-hdl 11/12
module evenOdd(o1, i1, clk, rst);
// Declare unique states
parameter s1 = 0;
parameter s2 = 1;
// Input/Output declarations
output o1;
input i1;
input clk, rst;
reg o1;
// Declare the state variable
reg state;
// Body of the FSM
….
….
endmodule
// Body of the Mealy FSM
always @(posedge clk ) begin
// Reset logic
if (rst) begin
state <= s1;
o1 <= 0;end
// State transition and output logic
else begin
case (state)
// 'Even' state
s1: begin
if (i1) begin
// Output logic
o1 <= 1;
// State transition logic
state <= s2;
end
end
// 'Odd' state
s2: begin
if (i1) begin
// Output logico1 <= 0;
// State transition logic
state <= s1;
end
end
endcase
end
end
8/4/2019 Fsm Using Hdl
http://slidepdf.com/reader/full/fsm-using-hdl 12/12
Workshop
1. Express the following FSMs in Verilog RTL.
2. Verify your design by writing a test-bench.