题解 | #根据状态转移图实现时序电路#

根据状态转移图实现时序电路

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

`timescale 1ns/1ns

module seq_circuit(
   input                C   ,
   input                clk ,
   input                rst_n,
 
   output   wire        Y   
);

parameter sta0 = 2'b00;
parameter sta1 = 2'b01;
parameter sta2 = 2'b10;
parameter sta3 = 2'b11;

reg [1:0] stage, next_stage;

always@(posedge clk or negedge rst_n) begin
    if(~rst_n) begin
        stage       <= sta0;
    end else begin
        stage       <= next_stage;
    end
end

always@(*) begin
    case(stage)
    sta0: begin
        if(C)
            next_stage  = sta1;
        else
            next_stage  = sta0;
    end

    sta1: begin
        if(C)
            next_stage  = sta1;
        else
            next_stage  = sta3;
    end

    sta2: begin
        if(C)
            next_stage  = sta2;
        else
            next_stage  = sta0;
    end

    sta3: begin
        if(C)
            next_stage  = sta2;
        else
            next_stage  = sta3;
    end
    endcase
end

assign Y = (((stage==sta2)&C) | (stage==sta3));




endmodule

全部评论

相关推荐

认真搞学习:28小登的建议,投算法岗不要写什么物理竞赛,互联网+,多写点项目,用什么算法做了什么。还有本科算法是不可能的开发你这个也没有项目啊
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务