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

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

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

全部评论

相关推荐

八月份以为是开始没想到是巅峰,九月约面反而少了,每天就是疯狂做测评和AI面试。这周更离谱,一个新的面邀都没有说好的金九银十呢?
牛客58830004...:九月到现在只有一场三七互娱的线下面试,java 无实习能找到工作吗 哥能告诉我客户端有希望吗,怎么转客户端
我的秋招日记
点赞 评论 收藏
分享
09-14 17:23
门头沟学院
故事和酒66:所以说副业很重要,程序员干到40岁,再怎么也赚300万了,吃吃利息也够活下去
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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