题解 | #序列发生器#

序列发生器

https://www.nowcoder.com/practice/1fe78a981bd640edb35b91d467341061

module sequence_generator(
	input clk,
	input rst_n,
	output reg data
	);


parameter IDLE = 6'b000001,
            S1= 6'b000010,
            S2=6'b000100,
            S3 = 6'b001000,
            S4 =6'b010000,
            S5 = 6'b100000;

reg [5:0] curr_state, next_state;

    always @(posedge clk or negedge rst_n) begin
        if (!rst_n) begin
            curr_state <=IDLE;
        end
        else begin
            curr_state <= next_state;
        end
    end

    always @(*) begin
        case (curr_state)
            IDLE: next_state <= S1;
            S1:next_state <=S2;
            S2:next_state <= S3;
            S3:next_state <=S4;
            S4:next_state<= S5;
            S5:next_state <=IDLE;
            default: next_state <= IDLE;
        endcase
    end

    always @(posedge clk or negedge rst_n) begin
		if(!rst_n)
		data <= 0;
		else
        if (curr_state == S2 || curr_state == S4 || curr_state == S5) begin
            data <= 1;
        end
        else
        data <= 0;
    end
endmodule

全部评论

相关推荐

11-18 15:57
门头沟学院 Java
起一个响亮的妹子吧:虽然但是,确有其人,重邮同届的,没有技巧,纯纯的个人实力。查看图片
点赞 评论 收藏
分享
HNU_fsq:建议直接出国,这简历太6了。自愧不如
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务