题解 | #序列检测器(Moore型)#

序列检测器(Moore型)

https://www.nowcoder.com/practice/d5c5b853b892402ea80d27879b8fbfd6

`timescale 1ns/1ns

module det_moore(
   input                clk   ,
   input                rst_n ,
   input                din   ,
 
   output	reg         Y   
);
parameter s0=3'd0,s1=3'd1,s2=3'd2,s3=3'd3,s4=3'd4;
reg [2:0] current_state,next_state;

always@(*)
begin
case(current_state)
s0: next_state = din ? s1 :s0;
s1: next_state = din ? s2 :s0;
s2: next_state = din ? s1 :s3;
s3: next_state = din ? s4 :s0;
s4: next_state = din ? s1 :s0;
default : next_state = s0;
endcase
end
    always @ (posedge clk or negedge rst_n)
    begin
        if(!rst_n)
        begin
        current_state<=s0;
        end
        else
        begin
        current_state<=next_state;
        end
    end
        always@(posedge clk or negedge rst_n)
        begin
            if(!rst_n)
            begin
            Y<=1'b0;
            end
            else
            begin
            Y<= current_state==s4;
            end
        end
endmodule

全部评论

相关推荐

10-30 23:23
已编辑
中山大学 Web前端
去B座二楼砸水泥地:这无论是个人素质还是专业素质都👇拉满了吧
点赞 评论 收藏
分享
头像
11-07 01:12
重庆大学 Java
精致的小松鼠人狠话不多:签哪了哥
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务