时钟分频器:
(1)偶数分频(占空比50%)
(2)奇数分频(占空比50%)
(3)非整数分频(占空比非50%)
(1)偶数分频(假设分频 N=6)
使用计数器创造偶数分频
RTL文件如下:
module pll6 #(parameter N=6)(
input clk,
input rst_n,
output clk_6);
reg [3:0] countl;
always@(posedge clk or negedge rst_n)
begin
if(!rst_n)
countl<=0;
else if (countl<=N-2)
countl<=countl+1'b1;
else
countl<=0;
end
assign clk_6=(countl<=N/2-1'b1)?1:0;
endmodule
tb文件如下:
module tb();
reg clk;
reg rst_n;
wire clk_6;
parameter period=20;//50Mhz
pll6 u1(
.clk(clk),
.rst_n(rst_n),
.clk_6(clk_6));
initial
begin
clk=0;
rst(32'd60);
forever #(period/2) clk=~clk;
end
task rst(
input[31:0] rst_time);
begin
rst_n=0;
#rst_time rst_n=1;
end
endtask
endmodule
(2)奇数分频
1、也可以使用与偶数分频相同的方法,但是无法产生50%占空比的输出(7分频)
2、产生具有50%占空比的奇数分频时钟最简单的方式是以输出频率的一半生成两个正交相位时钟(两个时钟之间有90度相位差),然后将两个波形异或得到输出时钟(以N=3为例)
(1)产生两个6分频且相位差有90度的时钟(一个使用上升沿产生6分频信号