// One-process version of the Moore 1011 detector. State and output are // both assigned inside a single always_ff. The output assignment must // name the state being entered, which is why this style is easy to get // wrong by one cycle. `timescale 1ns / 1ps module seq_detect_1p ( input logic clk, input logic rst, input logic din, output logic detect ); typedef enum logic [2:0] { S_IDLE, S_1, S_10, S_101, S_1011 } state_t; state_t state; always_ff @(posedge clk) begin if (rst) begin state <= S_IDLE; detect <= 1'b0; end else begin detect <= 1'b0; // default case (state) S_IDLE: if (din) state <= S_1; else state <= S_IDLE; S_1: if (din) state <= S_1; else state <= S_10; S_10: if (din) state <= S_101; else state <= S_IDLE; S_101: if (din) begin state <= S_1011; detect <= 1'b1; // entering the output state end else begin state <= S_10; end S_1011: if (din) state <= S_1; else state <= S_10; default: state <= S_IDLE; endcase end end endmodule