下面模块里的两种方式都可以,但是实现方式有所不同
第一种利用输入和输入的异或关系补脉冲的方式
第二种倍频计数方式
module CLK9 (pReset, inClk, outClk);
input pReset; //reset
input inClk; //input clk
output [2:1]outClk; //output clk
reg [2:1]outClk;
////////////////////////////////////
reg [3:0]count1;
wire clkW1 = inClk ^ outClk[1];
always @(posedge pReset or posedge clkW1)
begin
if(pReset)
begin
count1 <= 0;
outClk[1] <= 1'b0;
end
else
begin
if(count1 >= 4)
begin
count1 <= 0;
outClk[1] <= !outClk;
end
else
begin
count1 <= count1 + 1'b1;
end
end
end
reg [4:0]count2;
reg clk2; wire clkW2 = inClk ^ clk2;
always @(posedge pReset or posedge clkW2)
begin
if(pReset)
begin
clk2 <= 1'b0;
count2 <= 0;
outClk[2] <= 1'b0;
end
else
begin
clk2 <= inClk;
if(count2 >= 8)
begin
count2 <= 0;
outClk[2] <= !outClk[2];
end
else
begin
count2 <= count2 + 1'b1;
end
end
end
endmodule |