Sequence Detector Verilog
Sequence Detector Verilog
parameter IDLE = 0,
S1 = 1,
S10 = 2,
S101 = 3,
S1011 = 4;
// Output logic
assign out = (cur_state == S1011) ? 1 : 0;
// State register
always @(posedge clk) begin
if (!rst_n)
cur_state <= IDLE;
else
cur_state <= next_state;
end
// Next-state logic
always @(cur_state or in) begin
case (cur_state)
IDLE: begin
if (in)
next_state = S1;
else
next_state = IDLE;
end
S1: begin
if (in)
next_state = IDLE;
else
next_state = S10;
end
S10: begin
if (in)
next_state = S101;
else
next_state = IDLE;
end
S101: begin
if (in)
next_state = S1011;
else
next_state = IDLE;
end
S1011: begin
if (in)
next_state = S1; // Supports overlapping
sequences
else
next_state = S10; // Checks for potential new
start
end
default: next_state = IDLE;
endcase
end
endmodule