HDLbits Exams/ece241 2013 q4

2022-07-24 21:23:12 浏览数 (1)

fr1 fr2 fr3 输出完全由输入决定,和状态机其实没关系。

dfr 需要判断一下。

代码语言:javascript复制
module top_module (
    input clk,
    input reset,
    input [3:1] s,
    output fr3,
    output fr2,
    output fr1,
    output dfr
); 
    reg [2:0] state;
    reg [2:0] next;
    reg ndfr;
    
    always@(*)begin
        if(reset)begin
            next = 3'b111;
            ndfr = 1;
        end else begin
            case(s)
                3'b111: next = 3'b000;
                3'b011: next = 3'b001;
                3'b001: next = 3'b011;
                3'b000: next = 3'b111;
            endcase
            case(s)
                3'b000: ndfr = 1;
                default: 
                    ndfr = (state == next) ? dfr : ((state > next) ? 0 : 1);
            endcase
        end
    end
    
    always@(posedge clk)begin
        state <= next;
        dfr <= ndfr;
    end
    
    assign {fr3, fr2, fr1} = state;

endmodule

0 人点赞