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

时钟分频(偶数)

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
    );
    reg out2,out4,out8;
    reg [2:0]cnt;
    assign clk_out2=out2;
    assign clk_out4=out4;
    assign clk_out8=out8;
//*************code***********//
always@(posedge clk_in or negedge rst)
if(!rst)begin
    out2<=0;
    out4<=0;
    out8<=0;
    cnt<=0;
end else begin
    out2<=~out2;
    cnt<=cnt+1'b1;

    if(cnt==3'b010|cnt==3'b110)begin
        out4<=~out4;
    end else if(cnt==3'b000|cnt==3'b100)begin
        out4<=~out4;
        out8<=~out8;
    end 
end



//*************code***********//
endmodule

全部评论

相关推荐

机械打工仔:我来告诉你原因,是因为sobb有在线简历,有些HR为了快会直接先看在线简历,初步感觉不合适就不会找你要详细的了
投了多少份简历才上岸
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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