题解 | #任意小数分频#

任意小数分频

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 M_N = 8'd87; 
parameter c89 = 8'd24; // 8/9时钟切换点
parameter div_e = 5'd8; //偶数周期
parameter div_o = 5'd9; //奇数周期
//*************code***********//

reg[7:0]clk_count;
reg[7:0]cnt;

always @(posedge clk_in, negedge rst) begin
    if(rst == 0)begin
        clk_count <= 0;
    end
    else begin
        clk_count <= clk_count==M_N-1 ? 0 : clk_count+1; 
    end
end

wire div_class = clk_count < c89 ? 1 : 0;

always @(posedge clk_in, negedge rst) begin
    if(rst == 0)begin
        cnt <= 0;
    end
    else if(div_class)begin
        cnt <= cnt==(div_e-1) ? 0 : cnt+1;
    end
    else begin
        cnt <= cnt==(div_o-1) ? 0 : cnt+1; 
    end
end

reg clk_out_r;
always @(posedge clk_in, negedge rst) begin
    if(rst == 0)begin
        clk_out_r <= 0;
    end
    else if(div_class)begin
        clk_out_r <= (cnt < div_e>>1) ? 1 : 0;
    end
    else begin
        clk_out_r <= (cnt < div_o>>1) ? 1 : 0;
    end
end
assign clk_out = clk_out_r;

endmodule

全部评论

相关推荐

06-19 14:58
门头沟学院 Java
点赞 评论 收藏
分享
05-29 20:34
门头沟学院 C++
KarlAllen:得做好直接春招的准备。学历差的话,一是面试要求会比学历好的严格不少,二是就算面试通过了也会被排序。总之暑期和秋招对于学历差的就是及其不友好
点赞 评论 收藏
分享
沉淀去了,8月是不是机会会多一点,。打招呼300+,就一个小厂面试,聊了十分钟天就让我去了,暑假继续沉淀了,到八月九月冲了
丰川打工祥:我目前的体感是,双非本+一段小厂实习,基本约不到中厂的面。已经开始第二段小厂了。可能的确是最近hc太少了。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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