题解 | #时钟分频(偶数)#

时钟分频(偶数)

https://www.nowcoder.com/practice/49a7277c203a4ddd956fa385e687a72e

`timescale 1ns/1ns

module even_div
    (
    input     wire rst ,
    input     wire clk_in,
    output    wire clk_out2,
    output    wire clk_out4,
    output    wire clk_out8
    );
//*************code***********//
reg [2:0]count;
always@(posedge clk_in or negedge rst)begin
    if(!rst)begin
        count<=0;
    end
    else begin
        if(count==3'd7)begin
            count<=0;
        end
        else begin
            count<=count+1;
        end
    end
end

reg out2_reg;
reg out4_reg;
reg out8_reg;
always@(posedge clk_in or negedge rst)begin
    if(!rst)begin
        out2_reg<=0;
    end
    else begin
        case(count)
        3'd0:out2_reg<=1;
        3'd2:out2_reg<=1;
        3'd4:out2_reg<=1;
        3'd6:out2_reg<=1;
        default:out2_reg<=0;
        endcase
    end
end
always@(posedge clk_in or negedge rst)begin
    if(!rst)begin
        out4_reg<=0;
    end
    else begin
        case(count)
        3'd0:out4_reg<=1;
        3'd1:out4_reg<=1;
        3'd4:out4_reg<=1;
        3'd5:out4_reg<=1;
        default:out4_reg<=0;
        endcase
    end
end
always@(posedge clk_in or negedge rst)begin
    if(!rst)begin
        out8_reg<=0;
    end
    else begin
        if(count<4)begin
            out8_reg<=1;
        end
        else begin
            out8_reg<=0;
        end
    end
end

assign clk_out2=out2_reg;
assign clk_out4=out4_reg;
assign clk_out8=out8_reg;
//*************code***********//
endmodule

写的有点丑,但能运行

全部评论

相关推荐

06-19 19:06
门头沟学院 Java
码农索隆:别去东软,真学不到东西,真事
点赞 评论 收藏
分享
机械打工仔:我来告诉你原因,是因为sobb有在线简历,有些HR为了快会直接先看在线简历,初步感觉不合适就不会找你要详细的了
投了多少份简历才上岸
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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