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

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

https://www.nowcoder.com/practice/455c911bee0741bf8544a75d958425f7

`timescale 1ns/1ns

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

reg [1:0]Q;
reg Y_reg;
assign Y = Y_reg;
always@(posedge clk or negedge rst_n)begin
    if(!rst_n)begin
        Y_reg=1'b0;
        Q =0;
    end
    else if (~A)begin
        Q = Q+1;
        case(Q)
        2'b00: Y_reg=0;
        2'b01: Y_reg=0;
        2'b10: Y_reg=0;
        2'b11: Y_reg=1;
        endcase

    end
    else begin
        Q = Q-1;
        case(Q)
        2'b00: Y_reg=0;
        2'b01: Y_reg=0;
        2'b10: Y_reg=0;
        2'b11: Y_reg=1;
        endcase
    end
end
endmodule

评论区大佬们要么是根据状态转移图,写出Q与A之间的关系,Y与Q之间的关系,要么是用的状态机,好像还没有像我这种

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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