|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区
您需要 登录 才可以下载或查看,没有账号?立即注册
×
module clkgen(rst_n,clk,k,clkk);
input rst_n;
input clk;
input [3:0] k;
reg clk1;
reg clk2;
output clkk;
reg [3:0] k1;
reg [3:0] k2;
always@(negedge rst_n or posedge clk)
begin
if(~rst_n)
begin
k1 <= 4'b0;
clk1 <= 1'b0;
end
else
begin
if(k1==(k-1))
clk1 <= ~clk1;
if(k1==((k>>1)-1'b1))
clk1 <= ~clk1;
if(k1==k-1)
k1 <= 4'b0000;
else
k1 <= k1+4'b0001;
end
end
always@(negedge rst_n or negedge clk)
begin
if(~rst_n)
begin
k2 <= 4'b0;
clk2 <= 1'b0;
end
else
begin
if(k2 == k-1)
k2 <= 4'b0000;
else
k2 <= k2+4'b0001;
if(k2==k-1)
clk2 <= ~clk2;
if(k2==((k>>1)-1'b1))
clk2 <= ~clk2;
end
end
assign clkk = (k%2)?clk1&clk2:clk1;
endmodule
|
|