题解 | #任意小数分频#

任意小数分频

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

`timescale 1ns/1ns

module div_M_N(
 input  wire clk_in,
 input  wire rst,
 output reg 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]cnt;
reg[7:0]cnt_e;
reg[7:0]cnt_o;
always@(posedge clk_in or negedge rst)
begin if(!rst)
 cnt<=0;
else if(cnt==M_N-1)
   cnt<=0;
   else cnt<=cnt+1;
end
always@(posedge clk_in or negedge rst)
begin if(!rst)
   begin 
         cnt_e<=0;
         cnt_o<=0;
   end
else if(cnt<c89)
 if (cnt_e==div_e-1)
     begin  cnt_e<=0; cnt_o<=0;  end 
  else begin  cnt_e<=cnt_e+1; cnt_o<=0; end

else  if(cnt_o==div_o-1)
   begin cnt_o<=0;
cnt_e<=0; end 
  else begin 
    cnt_o<=cnt_o+1; cnt_e<=0; end
end

always@(posedge clk_in or negedge rst)
begin if(!rst)
    clk_out<=0;
    else if(cnt<=c89)
     begin if((cnt_e==0)|(cnt_e==4))
     clk_out<=~clk_out; end
     else if((cnt_o==0)|((cnt_o==4)))
    clk_out<=~clk_out;
     end

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

全部评论
这个分频器的代码写得很简洁明了,很易于理解,谢谢分享!
点赞 回复 分享
发布于 2023-05-25 22:15 陕西
分频器怎么根据实际需求进行调整啊?能说一下不?
点赞 回复 分享
发布于 2023-05-25 22:00 陕西

相关推荐

在改简历的大卫很认真:天天有面试 = 你已经在 offer 门口了。 海投能面成这样,说明你的简历、基础、学历都是过关的,缺的只是一次刚好匹配的缘分。 关于你说的 SQL 恐惧,我帮你捋一下: - 面试里考来考去,真就那几类: 分组、去重、关联、子查询、窗口函数(row_number、rank、sum 开窗) ​ - 面试官要的不是“写得花里胡哨”,而是思路稳、不出错。 你恐惧的本质不是不会, 是怕临场卡壳、怕写错、怕被追问。
点赞 评论 收藏
分享
SHC2:春招先狠狠投递,然后你看看能不能申请香港新加坡的一年制master,花不了多少钱,或者现在赶紧去刷一段实习。HR专业考研没必要
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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