题解 | #任意小数分频#

任意小数分频

https://www.nowcoder.com/practice/24c56c17ebb0472caf2693d5d965eabb

`timescale 1ns/1ns

module div_M_N(
 input  wire clk_in,
 input  wire rst,
 output wire clk_out
);
    parameter Cycle_out = 87;
    parameter Cycle_in1 = 8;
    parameter Cycle_in2 = 9;
    parameter Switch = 24;
    reg [6:0] cnt_out;
    reg [3:0] cnt_in;
    always@(posedge clk_in or negedge rst) begin
        if(!rst) begin
            cnt_out <= 'd0;
        end
        else begin
            cnt_out <= (cnt_out==Cycle_out-'d1)?'d0:(cnt_out+'d1);
        end
    end
    always@(posedge clk_in or negedge rst) begin
        if(!rst) begin
            cnt_in <= 'd0;
        end
        else begin
            if(cnt_out<=Switch-'d1)
                cnt_in <= (cnt_in==Cycle_in1-'d1)?'d0:(cnt_in+'d1);
            else begin
                    cnt_in <= (cnt_in==Cycle_in2-'d1)?'d0:(cnt_in+'d1);
            end
        end
    end
    reg clk_out_r;
    always@(posedge clk_in or negedge rst) begin
        if(!rst) begin
            clk_out_r <= 1'b0;
        end
        else begin
            clk_out_r <= (cnt_in<='d3);
        end
    end
    assign clk_out = clk_out_r;
endmodule

全部评论

相关推荐

深夜书店vv:腾讯是这样的,去年很多走廊都加桌子当工区
点赞 评论 收藏
分享
湫湫湫不会java:先投着吧,大概率找不到实习,没实习的时候再加个项目,然后把个人评价和荣誉奖项删了,赶紧成为八股战神吧,没实习没学历,秋招机会估计不多,把握机会。或者说秋招时间去冲实习,春招冲offer,但是压力会比较大
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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