`timescale 1ns/1ns module sequence_test1( input wire clk , input wire rst , input wire data , output reg flag ); //*************code***********// parameter IDLE = 6'b000001; parameter S0 = 6'b000010; parameter S1 = 6'b000100; parameter S2 = 6'b001000; parameter S3 = 6'b010000; parameter S4 = 6'b100000; // one step reg [5:0] cs; reg [5:0] ns; always @ (posedge clk or negedge rst) begin if(~rst) begin cs <= IDLE; end else begin cs <= ns; end end // two step always @ (*) begin case(cs) IDLE : ns = (data == 1'b1) ? S0 : IDLE; S0 : ns = (data == 1'b0) ? S1 : S0; S1 : ns = (data == 1'b1) ? S2 : IDLE; S2 : ns = (data == 1'b1) ? S3 : S1; S3 : ns = (data == 1'b1) ? S4 : S1; S4 : ns = (data == 1'b1) ? S0 : IDLE; default : ns = IDLE; endcase end //three step always @ (posedge clk or negedge rst) begin if(~rst) begin flag <= 1'b0; end else begin //if(ns == S4) begin if(cs == S3 && data == 1'b1) begin flag <= 1'b1; end else begin flag <= 1'b0; end end end //*************code***********// endmodule
关键在于状态机的绘制