任意奇数分频器的实现。

从网上找到一段感觉写的很不错的verilog,任意奇数分频器的实现。

//任意奇数分频器,只需要将n改为你想要的奇数即可。
module any_odd_div (clkdiv,clk);
 output clkdiv;  //输出分频信号
 input clk;      //时钟信号
 reg[2:0]cnt1,cnt2;//计数器1,计数器2
 reg clk_temp1,clk_temp2;
 parameter n = 7;  //7分频
 
 always @(posedge clk)
 begin
  if(cnt1 == n-1)
   begin cnt1 <=3'b000; end
  else
   begin cnt1 <= cnt1 +1'b1; end
  if(cnt1 ==3'b000)
   begin clk_temp1 =1'b1; end
  if(cnt1 ==(n-1)/2)
   begin clk_temp1 =0; end
 end
 
 always @(negedge clk)
 begin
  if(cnt2 == n-1)
   begin cnt2 <=3'b000; end
  else
   begin cnt2 <=cnt2 +1'b1; end
  if(cnt2 ==3'b000)
   begin clk_temp2 =1; end
  if(cnt2 ==(n-1)/2)
   begin clk_temp2 =0; end
 end
 
 assign clkdiv = clk_temp1 | clk_temp2;
 
 endmodule
 
 

猜你喜欢

转载自blog.csdn.net/wangyanchao151/article/details/88535661