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

时钟分频(偶数)

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

写的有点丑,但能运行

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-01 17:13
想去,但是听说加班强度实在难崩,所以拒绝了,现在有点心梗对面hr感觉也是实习生,打电话的时候怪紧张的,但是感觉人很好嘞
水中水之下水道的鼠鼠:哥们这不先去体验一下,不行再跑呗,大不了混个实习经历(有更好的转正offer就当我没说)
点赞 评论 收藏
分享
牛客刘北:如果暑期实习是27届的话,你要晚一年才会毕业,企业为什么会等你呢?要搞清时间逻辑呀!27届现在实习只能是在暑假实习,这是日常实习,不是暑期实习。所以多去投日常实习吧,暑期实习肯定不会要你的
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-01 12:22
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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