Introduction to Verilog - Lecture3
Introduction to Verilog - Lecture3
Introduction to Verilog
x IF 110 found on x
Then Z gets ‘1’ z
clk Else z gets ‘0’
Reset End
1
1 1 0
0
Reset got1 got11 got110
Reset /0 /0 /0 /1
0 1
0
FSM Modeling
module moore_110_detector (output reg z, input x, clk, Reset );
localparam reset = 2'b00, got1=2'b01, got11=2'b10, got110=2'b11;
reg [1:0] state, next_state;
always @(posedge clk) //synch reset
if (Reset) state <= reset;
else state <= next_state; // the state transition
always @(state, x) begin //comb. Logic
z = 0; //Default value of z
case (state) //Note the use of blocking assignments with combinational logic
reset: if (x) next_state=got1; else next_state=reset;
got1: if (x) next_state=got11; else next_state=reset;
got11: if (x) next_state=got11; else next_state=got110;
got110: begin z=1; if (x) next_state=got1; else next_state=reset; end
endcase // When we have more than one statement inside a case
end // branch, we use begin..end
endmodule
FSM Modeling: Test benches
To test an FSM (i.e. sequential circuit), the test bench must supply an input
sequence that exercise all state transitions and output combinations