45 lines
924 B
Systemverilog
45 lines
924 B
Systemverilog
module seq_detector_1011 (
|
|
input logic clk,
|
|
input logic rst,
|
|
input logic in,
|
|
output logic detected
|
|
);
|
|
|
|
|
|
typedef enum logic [2:0]
|
|
{
|
|
IDLE,
|
|
S1,
|
|
S10,
|
|
S101,
|
|
S1011
|
|
} state_t;
|
|
|
|
state_t current_state, next_state;
|
|
|
|
always_ff @(posedge clk) begin
|
|
if (rst) begin
|
|
current_state <= IDLE;
|
|
end else begin
|
|
current_state <= next_state;
|
|
end
|
|
end
|
|
|
|
always_comb begin
|
|
next_state = IDLE;
|
|
case (current_state)
|
|
IDLE : if (in) next_state = S1; else next_state = IDLE;
|
|
S1 : if (in) next_state = S1; else next_state = S10;
|
|
S10 : if (in) next_state = S101; else next_state = IDLE;
|
|
S101 : if (in) next_state = S1011; else next_state = S10;
|
|
S1011 : if (in) next_state = S1; else next_state = S10;
|
|
default : next_state = IDLE;
|
|
endcase
|
|
end
|
|
|
|
|
|
|
|
|
|
assign detected = (current_state == S1011);
|
|
|
|
endmodule |